remove temporary notebook

This commit is contained in:
Marek Wolan
2024-09-25 16:50:01 +01:00
parent f1b911bc65
commit c3eb093144

View File

@@ -1,157 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import yaml\n",
"\n",
"from primaite.game.game import PrimaiteGame\n",
"from primaite.session.environment import PrimaiteGymEnv\n",
"from primaite.simulator.network.hardware.nodes.host.computer import Computer\n",
"from primaite.simulator.network.hardware.nodes.host.server import Server\n",
"from primaite.simulator.system.applications.database_client import DatabaseClient, DatabaseClientConnection\n",
"from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot\n",
"from primaite.simulator.system.services.database.database_service import DatabaseService\n",
"from primaite import getLogger, PRIMAITE_PATHS"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"with open(PRIMAITE_PATHS.user_config_path / \"example_config\" / \"data_manipulation.yaml\") as f:\n",
" cfg = yaml.safe_load(f)\n",
"game = PrimaiteGame.from_config(cfg)\n",
"uc2_network = game.simulation.network"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"client_1: Computer = uc2_network.get_node_by_hostname(\"client_1\")\n",
"db_manipulation_bot: DataManipulationBot = client_1.software_manager.software.get(\"DataManipulationBot\")\n",
"\n",
"database_server: Server = uc2_network.get_node_by_hostname(\"database_server\")\n",
"db_service: DatabaseService = database_server.software_manager.software.get(\"DatabaseService\")\n",
"\n",
"web_server: Server = uc2_network.get_node_by_hostname(\"web_server\")\n",
"db_client: DatabaseClient = web_server.software_manager.software.get(\"DatabaseClient\")\n",
"db_connection: DatabaseClientConnection = db_client.get_new_connection()\n",
"db_service.backup_database()\n",
"\n",
"# First check that the DB client on the web_server can successfully query the users table on the database\n",
"assert db_connection.query(\"SELECT\")\n",
"\n",
"db_manipulation_bot.data_manipulation_p_of_success = 1.0\n",
"db_manipulation_bot.port_scan_p_of_success = 1.0\n",
"\n",
"# Now we run the DataManipulationBot\n",
"db_manipulation_bot.attack()\n",
"\n",
"# Now check that the DB client on the web_server cannot query the users table on the database\n",
"assert not db_connection.query(\"SELECT\")\n",
"\n",
"# Now restore the database\n",
"db_service.restore_backup()\n",
"\n",
"# Now check that the DB client on the web_server can successfully query the users table on the database\n",
"assert db_connection.query(\"SELECT\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"router = uc2_network.get_node_by_hostname(\"router_1\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"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",
"| 18 | PERMIT | ANY | ANY | ANY | 5432 (5432) | ANY | ANY | 5432 (5432) | 4 |\n",
"| 19 | PERMIT | ANY | ANY | ANY | 53 (53) | ANY | ANY | 53 (53) | 0 |\n",
"| 20 | PERMIT | ANY | ANY | ANY | 21 (21) | ANY | ANY | 21 (21) | 0 |\n",
"| 21 | PERMIT | ANY | ANY | ANY | 80 (80) | ANY | ANY | 80 (80) | 0 |\n",
"| 22 | PERMIT | ANY | ANY | ANY | 219 (219) | ANY | ANY | 219 (219) | 9 |\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": [
"router.acl.show()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "AccessControlList.is_permitted() missing 1 required positional argument: 'frame'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[6], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mrouter\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43macl\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mis_permitted\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;31mTypeError\u001b[0m: AccessControlList.is_permitted() missing 1 required positional argument: 'frame'"
]
}
],
"source": [
"router.acl.is_permitted()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}