#2706 - Initial refactor of Terminal Class following review discussion on Friday. Terminal will now return a TerminalConnection/RemoteTerminalConnection object on login.
The new connection object can then be used to pass commands to the target node, without needing to form a full payload item.
This commit is contained in:
@@ -26,7 +26,8 @@
|
||||
"source": [
|
||||
"from primaite.simulator.system.services.terminal.terminal import Terminal\n",
|
||||
"from primaite.simulator.network.container import Network\n",
|
||||
"from primaite.simulator.network.hardware.nodes.host.computer import Computer"
|
||||
"from primaite.simulator.network.hardware.nodes.host.computer import Computer\n",
|
||||
"from primaite.simulator.system.applications.red_applications.ransomware_script import RansomwareScript"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -83,7 +84,38 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Login to the remote (node_b) from local (node_a)\n",
|
||||
"terminal_a.login(username=\"admin\", password=\"Admin123!\", ip_address=computer_b.network_interface[1].ip_address)"
|
||||
"from primaite.simulator.system.services.terminal.terminal import RemoteTerminalConnection\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"term_a_term_b_remote_connection: RemoteTerminalConnection = terminal_a.login(username=\"admin\", password=\"Admin123!\", ip_address=computer_b.network_interface[1].ip_address)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"computer_b.software_manager.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(type(term_a_term_b_remote_connection))\n",
|
||||
"term_a_term_b_remote_connection.execute([\"software_manager\", \"application\", \"install\", \"RansomwareScript\"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"computer_b.software_manager.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -109,45 +141,6 @@
|
||||
"The Terminal can be used to send requests to install new software. The code block below demonstrates how the Terminal class allows the user of `terminal_a`, on `computer_a`, to send a command to `computer_b` to install the `RansomwareScript` application. \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from primaite.simulator.network.protocols.ssh import SSHConnectionMessage, SSHPacket, SSHTransportMessage\n",
|
||||
"from primaite.simulator.system.applications.red_applications.ransomware_script import RansomwareScript\n",
|
||||
"\n",
|
||||
"computer_b.software_manager.show()\n",
|
||||
"\n",
|
||||
"payload: SSHPacket = SSHPacket(\n",
|
||||
" payload=[\"software_manager\", \"application\", \"install\", \"RansomwareScript\"],\n",
|
||||
" transport_message=SSHTransportMessage.SSH_MSG_SERVICE_REQUEST,\n",
|
||||
" connection_message=SSHConnectionMessage.SSH_MSG_CHANNEL_OPEN,\n",
|
||||
" sender_ip_address=computer_a.network_interface[1].ip_address,\n",
|
||||
" target_ip_address=computer_b.network_interface[1].ip_address,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Send command to install RansomwareScript\n",
|
||||
"terminal_a.send(payload=payload, dest_ip_address=computer_b.network_interface[1].ip_address)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The `RansomwareScript` can then be seen in the list of applications on the `node_b Software Manager`. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"computer_b.software_manager.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -157,27 +150,6 @@
|
||||
"Here, we send a command to `computer_b` to create a new folder titled \"Downloads\"."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"computer_b.file_system.show()\n",
|
||||
"\n",
|
||||
"payload: SSHPacket = SSHPacket(\n",
|
||||
" payload=[\"file_system\", \"create\", \"folder\", \"Downloads\"],\n",
|
||||
" transport_message=SSHTransportMessage.SSH_MSG_SERVICE_REQUEST,\n",
|
||||
" connection_message=SSHConnectionMessage.SSH_MSG_CHANNEL_OPEN,\n",
|
||||
" sender_ip_address=computer_a.network_interface[1].ip_address,\n",
|
||||
" target_ip_address=computer_b.network_interface[1].ip_address,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"terminal_a.send(payload=payload, dest_ip_address=computer_b.network_interface[1].ip_address)\n",
|
||||
"\n",
|
||||
"computer_b.file_system.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
||||
Reference in New Issue
Block a user