Name | backdoor-io JSON |
Version |
0.0.13
JSON |
| download |
home_page | https://github.com/Shahaf-F-S/backdoor |
Summary | A framework for designing, orchestrating and executing backdoor systems, with short and long term memory, dynamic execution, data delivery, multithreading live communication and more. |
upload_time | 2024-07-06 09:58:14 |
maintainer | None |
docs_url | None |
author | Shahaf Frank-Shapir |
requires_python | None |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# backdoor
> A framework for designing, orchestrating and executing backdoor systems, with short and long term memory, dynamic execution, data delivery, multithreading live communication and more.
Installation
-----------
````
pip install backdoor-io
````
example
-----------
Simple commands to execute one by one.
````python
from backdoor import (
Executor, Command, Data, Actions, Action, DELETE, WRITE, READ, SEARCH
)
commands = [
Command(request=Data(payload='text', name='value', action=WRITE)),
Command(request=Data(name='value', action=READ)),
Command(
action=Action(type=Actions.EXECUTION.TYPE, name=Actions.EXECUTION.PYTHON),
request=Data(payload='print(value); result = value * 2;')
),
Command(request=Data(name='value', action=DELETE)),
Command(request=Data(name='value', action=SEARCH)),
Command(request=Data(name='result', action=READ)),
Command(
action=Action(type=Actions.EXECUTION.TYPE, name=Actions.EXECUTION.CMD),
request=Data(payload='dir')
)
]
executor = Executor()
for command in commands:
print(executor.execute(command), "\n")
````
output
````python
Command(
id='793f1d0d-641e-45b4-ba2f-dad801c35a3f',
action=Action(type='data', name='write', repetitions=1, timeout=None, thread=False, wait=True),
request=Data(payload='text', format='text', name='value', action='write', timestamp=1710051829.9969397),
response=Data(payload="'value' was written to memory in memory.", format='text', name=None, action=None, timestamp=1710051829.9969397),
memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None
)
Command(
id='b5985414-1d9f-4a0e-966b-445b2be92a40',
action=Action(type='data', name='read', repetitions=1, timeout=None, thread=False, wait=True),
request=Data(payload='text', format='text', name='value', action='read', timestamp=1710051829.9969397),
response=Data(payload='text', format='text', name=None, action=None, timestamp=1710051829.9969397),
memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None
)
Command(
id='958f80d4-e74e-45e6-bf08-0ab6c89ab771',
action=Action(type='execution', name='python', repetitions=1, timeout=None, thread=False, wait=True),
request=Data(payload='print(value); result = value * 2;', format='text', name=None, action=None, timestamp=1710051829.9969397),
response=Data(payload={'stdout': '', 'stderr': ''}, format='json', name=None, action=None, timestamp=1710051829.9969397),
memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None
)
Command(
action=Action(type='data', name='delete', repetitions=1, timeout=None, thread=False, wait=True),
id='b91c39ca-d19f-4322-a209-b5ca4c06dfe5',
request=Data(payload=None, format=None, name='value', action=None, timestamp=1710051829.9969397),
response=Data(payload="'value' was deleted from memory.", format='text', name=None, action=None, timestamp=1710051829.99794),
memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None
)
Command(
id='a9d47fcf-5266-4a47-b102-ed267b9bbba4',
action=Action(type='data', name='search', repetitions=1, timeout=None, thread=False, wait=True),
request=Data(payload=None, format=None, name='value', action=None, timestamp=1710051829.9969397),
response=Data(payload=False, format='json', name=None, action=None, timestamp=1710051829.99794),
memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None
)
Command(
id='d9ec5d45-e214-4a36-8d72-f52adb605da3',
action=Action(type='data', name='read', repetitions=1, timeout=None, thread=False, wait=True),
request=Data(payload=None, format=None, name='result', action=None, timestamp=1710051829.9969397),
response=Data(payload='texttext', format='text', name=None, action=None, timestamp=1710051829.99794),
memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None
)
Command(
id='d5093ce2-0cbf-4d5e-8195-850c27d46e54',
action=Action(type='execution', name='cmd', repetitions=1, timeout=None, thread=False, wait=True),
request=Data(payload='dir', format='text', name=None, action=None, timestamp=1710051829.9969397),
response=Data(payload={'stdout': ' Volume in drive C is Windows-SSD\n Volume Serial Number is 0C65-337C\n\n Directory of ...', 'stderr': ''}, format='json', name=None, action=None, timestamp=1710051830.0080411),
memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None
)
````
Complex commands to run in the background, with timeout and threading.
````python
import time
from backdoor import (
Executor, Command, Data, Actions, Action, WRITE, File, TEXT, READ
)
c1 = Command(
action=Action(
type=Actions.EXECUTION.TYPE,
name=Actions.EXECUTION.PYTHON,
wait=False,
thread=True,
# timeout=dt.timedelta(seconds=5)
),
request=Data(payload='import time\nfor _ in range(10):\n\ttime.sleep(1)')
)
c2 = Command(
action=Action(
type=Actions.MANAGEMENT.TYPE,
name=Actions.MANAGEMENT.COMMAND,
),
request=Data(name=c1.id)
)
c3 = Command(
action=Action(
type=Actions.MANAGEMENT.TYPE,
name=Actions.MANAGEMENT.STOP,
),
request=Data(name=c1.id)
)
c4 = Command(
request=File(
payload="hello world", name="hello.txt",
action=WRITE
)
)
c5 = Command(request=File(name="hello.txt", format=TEXT, action=READ))
executor = Executor()
print(executor.execute(c1), "\n")
print("waiting for 3 seconds...")
time.sleep(3)
print(executor.execute(c2), "\n")
print("waiting for 3 seconds...")
time.sleep(3)
print(executor.execute(c3), "\n")
print(executor.execute(c2), "\n")
print('written a file named "hello.txt" with content "hello world"')
print(executor.execute(c4), "\n")
print(executor.execute(c5))
````
output
````python
Command(
id='3c9da903-028c-4dd0-b583-f15ccaed1280',
action=Action(type='execution', name='python', repetitions=1, timeout=None, thread=True, wait=False),
request=Data(payload='import time\nfor _ in range(10):\n\ttime.sleep(1)', format='text', name=None, action=None, timestamp=1710052480.8686686),
response=Data(payload={}, format='json', name=None, action=None, timestamp=1710052480.8705611),
memory=None, complete=False, running=True, forget=False, keep_request=True, message=None, error=None
)
waiting for 3 seconds...
Command(
id='df96ff69-16d2-4c42-a5a9-f16c390f15ee',
action=Action(type='management', name='command', repetitions=1, timeout=None, thread=False, wait=True),
request=Data(payload='3c9da903-028c-4dd0-b583-f15ccaed1280', format='text', name=None, action=None, timestamp=1710052480.8686686),
response=Data(payload={'id': '3c9da903-028c-4dd0-b583-f15ccaed1280', 'action': {'type': 'execution', 'name': 'python', 'repetitions': 1, 'timeout': None, 'thread': True, 'wait': False}, 'request': {'payload': 'import time\nfor _ in range(10):\n\ttime.sleep(1)', 'format': 'text', 'name': None, 'action': None, 'timestamp': 1710052480.8686686}, 'response': {'payload': {}, 'format': 'json', 'name': None, 'action': None, 'timestamp': 1710052480.8705611}, 'memory': None, 'complete': False, 'running': True, 'error': None}, format='json', name=None, action=None, timestamp=1710052483.8717408),
memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None
)
waiting for 3 seconds...
Command(
id='d6e7faea-6c1a-410e-89b7-3652ca914cc0',
action=Action(type='management', name='stop', repetitions=1, timeout=None, thread=False, wait=True),
request=Data(payload='3c9da903-028c-4dd0-b583-f15ccaed1280', format='text', name=None, action=None, timestamp=1710052480.8686686),
response=Data(payload='Command was stopped.', format='text', name=None, read=False, write=False, timestamp=1710052486.8754737),
memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None
)
Command(
id='df96ff69-16d2-4c42-a5a9-f16c390f15ee',
action=Action(type='management', name='command', repetitions=1, timeout=None, thread=False, wait=True),
request=Data(payload='3c9da903-028c-4dd0-b583-f15ccaed1280', format='text', name=None, action=None, timestamp=1710052480.8686686),
response=Data(payload={'id': '3c9da903-028c-4dd0-b583-f15ccaed1280', 'action': {'type': 'execution', 'name': 'python', 'repetitions': 1, 'timeout': None, 'thread': True, 'wait': False}, 'request': {'payload': 'import time\nfor _ in range(10):\n\ttime.sleep(1)', 'format': 'text', 'name': None, 'action': None, 'timestamp': 1710052480.8686686}, 'response': {'payload': {}, 'format': 'json', 'name': None, 'action': None, 'timestamp': 1710052480.8705611}, 'memory': None, 'complete': False, 'running': False, 'error': None}, format='json', name=None, action=None, timestamp=1710052486.8764887),
memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None
)
written a file named "hello.txt" with content "hello world"
Command(
id='f45da0d9-feee-41b8-8686-1024bfb70fc0',
action=Action(type='file', name='write', repetitions=1, timeout=None, thread=False, wait=True),
request=File(payload='hello world', format='text', name='hello.txt', action='write', timestamp=1710090057.4463112, position=11, size=11, buffer=None),
response=Data(payload="Data was added to the end of file: 'hello.txt'.", format='text', name=None, action=None, timestamp=1710090064.4521823),
memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None
)
Command(
id='2d5a4f9a-6467-41e2-88ab-119626ef0fb1',
action=Action(type='file', name='read', repetitions=1, timeout=None, thread=False, wait=True),
request=File(payload=None, format='text', name='hello.txt', action='read', timestamp=1710147070.8170629, position=11, size=11, buffer=None),
response=Data(payload='hello world', format='text', name=None, action=None, timestamp=1710147070.8180661),
memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None
)
````
Constructing a Command object:
````python
# The id of the command, can also be a plaintext name.
id: str = str(uuid4())
# Describes the type and name of action to preform.
action: Action | None = None
# Describes the input (request) data and output (response) data,
# and what to do with them.
request: Data = Data()
response: Data = Data()
# a dedicated memory dictionary for the command,
# rather than using the shared memory of the executor's.
memory: dict[str, JsonValue] = None
````
Additional attributes:
````python
# Id the command is still running: complete: False, running: True.
complete: bool = False
running: bool = False
# When an error is raised, it is saved here.
error: str | None = None
````
Constructing an Action object:
````python
# The type of action, from the Actions class.
type: str
# The name of the action from the type from the Actions class.
name: str
# The amount of times to commit the action in a row.
repetitions: int = 1
# A timeout to stop the action.
timeout: dt.timedelta = None
# A value to specify that the action is to be executed in a different thread.
# This means that the action will return back the command as usual,
# but will specify that the command is not complete and still running.
thread: bool = False
# A value to make the executor wait to the action to finish.
wait: bool = True
````
Constructing a Data object:
````python
# The bytes | json valid payload to contain.
payload: JsonValue = None
# The format of the data. Can be inferred automatically.
format: str | Literal['text', 'bytes', 'json'] | None = None
# The name of the data, with which the data can be
# saved to or read from the memory of the command/executor.
name: str | None = None
# The memory action to take with the data: read/write/delete/search
action: Literal['read', 'write', 'delete', 'search'] | None = None
````
Additional attributes:
````python
# The timestamp of creation of the object.
timestamp: float = time.time()
````
Simple Json-valid I/O:
````python
from backdoor import Command, Action, Data
c1 = Command(
id='793f1d0d-641e-45b4-ba2f-dad801c35a3f',
action=Action(type='data', name='write', repetitions=1, timeout=None, thread=False, wait=True),
request=Data(payload='text', format='text', name='value', action='write', timestamp=1710051829.9969397),
response=Data(payload="'value' was written to memory in memory.", format='text', name=None, action=None, timestamp=1710051829.9969397),
memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None
)
print(c1.dump())
print("same data:", c1 == Command.load(c1.dump()))
````
output:
````python
{
'id': '793f1d0d-641e-45b4-ba2f-dad801c35a3f',
'action': {'type': 'data', 'name': 'write', 'repetitions': 1, 'timeout': None, 'thread': False, 'wait': True},
'request': {'payload': 'text', 'format': 'text', 'name': 'value', 'action': 'write', 'timestamp': 1710051829.9969397},
'response': {'payload': "'value' was written to memory in memory.", 'format': 'text', 'name': None, 'action': None, 'timestamp': 1710051829.9969397},
'memory': None, 'complete': True, 'running': False, 'forget': False, 'keep_request': True, 'message': None, 'error': None
}
same data: True
````
Executor Construction:
````python
# Saves the id of the commands executed.
history: list[str] = []
# Saves the id of the commands being executed.
running: list[str] = []
# Contains all command object.
commands: dict[str, Command] = {}
# Shared memory of data and variables from and for the execution of commands.
memory: dict[str, ...] = {}
# Contains custom command objects.
custom: dict[str, Command | None] = {}
# Specifies the initial and current locations of the system to execute in.
root_location: str = os.getcwd
current_location: str = os.getcwd
# Callables to save/load/delete command data/objects.
save: Callable[[Command], str] = None
load: Callable[[str], Command] = None
delete: Callable[[str], ...] = None
````
Executor Interface:
````python
from backdoor import Executor, Command
executor = Executor()
# simple execution
c1 = Command(...)
c1_copy = c1.copy()
c1_return = executor.execute(c1)
assert c1 is c1_return
assert c1_copy != c1_return
# adding a custom command
custom_command = Command(...)
# method 1:
executor.add(custom_command)
# method 2:
from backdoor import Action, Data, Actions
custom_command_adder = Command(
action=Action(type=Actions.MANAGEMENT.TYPE, name=Actions.MANAGEMENT.ADD),
request=Data(payload=custom_command.dump())
)
executor.execute(custom_command_adder)
# running the custom command
custom_command_return = executor.execute(
Command(
action=Action(type=Actions.EXECUTION.TYPE, name=Actions.MANAGEMENT.CLEAN),
request=Data(payload=custom_command.id)
)
)
````
Raw data
{
"_id": null,
"home_page": "https://github.com/Shahaf-F-S/backdoor",
"name": "backdoor-io",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Shahaf Frank-Shapir",
"author_email": "shahaffrs@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/c9/5b/96595e4416c1d7c021fd5e3271d02288ed55f2a520fcc53cb92135082088/backdoor-io-0.0.13.tar.gz",
"platform": null,
"description": "# backdoor\r\n\r\n> A framework for designing, orchestrating and executing backdoor systems, with short and long term memory, dynamic execution, data delivery, multithreading live communication and more.\r\n\r\nInstallation\r\n-----------\r\n````\r\npip install backdoor-io\r\n````\r\n\r\nexample\r\n-----------\r\n\r\nSimple commands to execute one by one.\r\n````python\r\nfrom backdoor import (\r\n Executor, Command, Data, Actions, Action, DELETE, WRITE, READ, SEARCH\r\n)\r\n\r\ncommands = [\r\n Command(request=Data(payload='text', name='value', action=WRITE)),\r\n Command(request=Data(name='value', action=READ)),\r\n Command(\r\n action=Action(type=Actions.EXECUTION.TYPE, name=Actions.EXECUTION.PYTHON),\r\n request=Data(payload='print(value); result = value * 2;')\r\n ),\r\n Command(request=Data(name='value', action=DELETE)),\r\n Command(request=Data(name='value', action=SEARCH)),\r\n Command(request=Data(name='result', action=READ)),\r\n Command(\r\n action=Action(type=Actions.EXECUTION.TYPE, name=Actions.EXECUTION.CMD),\r\n request=Data(payload='dir')\r\n )\r\n]\r\n\r\nexecutor = Executor()\r\n\r\nfor command in commands:\r\n print(executor.execute(command), \"\\n\")\r\n````\r\n\r\noutput\r\n````python\r\nCommand(\r\n id='793f1d0d-641e-45b4-ba2f-dad801c35a3f',\r\n action=Action(type='data', name='write', repetitions=1, timeout=None, thread=False, wait=True), \r\n request=Data(payload='text', format='text', name='value', action='write', timestamp=1710051829.9969397), \r\n response=Data(payload=\"'value' was written to memory in memory.\", format='text', name=None, action=None, timestamp=1710051829.9969397), \r\n memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None\r\n)\r\n\r\nCommand(\r\n id='b5985414-1d9f-4a0e-966b-445b2be92a40',\r\n action=Action(type='data', name='read', repetitions=1, timeout=None, thread=False, wait=True), \r\n request=Data(payload='text', format='text', name='value', action='read', timestamp=1710051829.9969397), \r\n response=Data(payload='text', format='text', name=None, action=None, timestamp=1710051829.9969397), \r\n memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None\r\n)\r\n\r\nCommand(\r\n id='958f80d4-e74e-45e6-bf08-0ab6c89ab771',\r\n action=Action(type='execution', name='python', repetitions=1, timeout=None, thread=False, wait=True), \r\n request=Data(payload='print(value); result = value * 2;', format='text', name=None, action=None, timestamp=1710051829.9969397), \r\n response=Data(payload={'stdout': '', 'stderr': ''}, format='json', name=None, action=None, timestamp=1710051829.9969397), \r\n memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None\r\n)\r\n\r\nCommand(\r\n action=Action(type='data', name='delete', repetitions=1, timeout=None, thread=False, wait=True), \r\n id='b91c39ca-d19f-4322-a209-b5ca4c06dfe5', \r\n request=Data(payload=None, format=None, name='value', action=None, timestamp=1710051829.9969397), \r\n response=Data(payload=\"'value' was deleted from memory.\", format='text', name=None, action=None, timestamp=1710051829.99794), \r\n memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None\r\n)\r\n\r\nCommand(\r\n id='a9d47fcf-5266-4a47-b102-ed267b9bbba4',\r\n action=Action(type='data', name='search', repetitions=1, timeout=None, thread=False, wait=True), \r\n request=Data(payload=None, format=None, name='value', action=None, timestamp=1710051829.9969397), \r\n response=Data(payload=False, format='json', name=None, action=None, timestamp=1710051829.99794), \r\n memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None\r\n)\r\n\r\nCommand(\r\n id='d9ec5d45-e214-4a36-8d72-f52adb605da3',\r\n action=Action(type='data', name='read', repetitions=1, timeout=None, thread=False, wait=True), \r\n request=Data(payload=None, format=None, name='result', action=None, timestamp=1710051829.9969397), \r\n response=Data(payload='texttext', format='text', name=None, action=None, timestamp=1710051829.99794), \r\n memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None\r\n)\r\n\r\nCommand(\r\n id='d5093ce2-0cbf-4d5e-8195-850c27d46e54',\r\n action=Action(type='execution', name='cmd', repetitions=1, timeout=None, thread=False, wait=True), \r\n request=Data(payload='dir', format='text', name=None, action=None, timestamp=1710051829.9969397), \r\n response=Data(payload={'stdout': ' Volume in drive C is Windows-SSD\\n Volume Serial Number is 0C65-337C\\n\\n Directory of ...', 'stderr': ''}, format='json', name=None, action=None, timestamp=1710051830.0080411), \r\n memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None\r\n)\r\n````\r\n\r\nComplex commands to run in the background, with timeout and threading.\r\n````python\r\nimport time\r\n\r\nfrom backdoor import (\r\n Executor, Command, Data, Actions, Action, WRITE, File, TEXT, READ\r\n)\r\n\r\nc1 = Command(\r\n action=Action(\r\n type=Actions.EXECUTION.TYPE,\r\n name=Actions.EXECUTION.PYTHON,\r\n wait=False,\r\n thread=True,\r\n # timeout=dt.timedelta(seconds=5)\r\n ),\r\n request=Data(payload='import time\\nfor _ in range(10):\\n\\ttime.sleep(1)')\r\n)\r\nc2 = Command(\r\n action=Action(\r\n type=Actions.MANAGEMENT.TYPE,\r\n name=Actions.MANAGEMENT.COMMAND,\r\n ),\r\n request=Data(name=c1.id)\r\n)\r\n\r\nc3 = Command(\r\n action=Action(\r\n type=Actions.MANAGEMENT.TYPE,\r\n name=Actions.MANAGEMENT.STOP,\r\n ),\r\n request=Data(name=c1.id)\r\n)\r\n\r\nc4 = Command(\r\n request=File(\r\n payload=\"hello world\", name=\"hello.txt\",\r\n action=WRITE\r\n )\r\n)\r\nc5 = Command(request=File(name=\"hello.txt\", format=TEXT, action=READ))\r\n\r\nexecutor = Executor()\r\n\r\nprint(executor.execute(c1), \"\\n\")\r\nprint(\"waiting for 3 seconds...\")\r\n\r\ntime.sleep(3)\r\n\r\nprint(executor.execute(c2), \"\\n\")\r\nprint(\"waiting for 3 seconds...\")\r\n\r\ntime.sleep(3)\r\n\r\nprint(executor.execute(c3), \"\\n\")\r\nprint(executor.execute(c2), \"\\n\")\r\n\r\nprint('written a file named \"hello.txt\" with content \"hello world\"')\r\n\r\nprint(executor.execute(c4), \"\\n\")\r\nprint(executor.execute(c5))\r\n````\r\n\r\noutput\r\n````python\r\nCommand(\r\n id='3c9da903-028c-4dd0-b583-f15ccaed1280', \r\n action=Action(type='execution', name='python', repetitions=1, timeout=None, thread=True, wait=False), \r\n request=Data(payload='import time\\nfor _ in range(10):\\n\\ttime.sleep(1)', format='text', name=None, action=None, timestamp=1710052480.8686686), \r\n response=Data(payload={}, format='json', name=None, action=None, timestamp=1710052480.8705611), \r\n memory=None, complete=False, running=True, forget=False, keep_request=True, message=None, error=None\r\n)\r\n\r\nwaiting for 3 seconds...\r\n\r\nCommand(\r\n id='df96ff69-16d2-4c42-a5a9-f16c390f15ee', \r\n action=Action(type='management', name='command', repetitions=1, timeout=None, thread=False, wait=True), \r\n request=Data(payload='3c9da903-028c-4dd0-b583-f15ccaed1280', format='text', name=None, action=None, timestamp=1710052480.8686686), \r\n response=Data(payload={'id': '3c9da903-028c-4dd0-b583-f15ccaed1280', 'action': {'type': 'execution', 'name': 'python', 'repetitions': 1, 'timeout': None, 'thread': True, 'wait': False}, 'request': {'payload': 'import time\\nfor _ in range(10):\\n\\ttime.sleep(1)', 'format': 'text', 'name': None, 'action': None, 'timestamp': 1710052480.8686686}, 'response': {'payload': {}, 'format': 'json', 'name': None, 'action': None, 'timestamp': 1710052480.8705611}, 'memory': None, 'complete': False, 'running': True, 'error': None}, format='json', name=None, action=None, timestamp=1710052483.8717408), \r\n memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None\r\n)\r\n\r\nwaiting for 3 seconds...\r\n\r\nCommand(\r\n id='d6e7faea-6c1a-410e-89b7-3652ca914cc0', \r\n action=Action(type='management', name='stop', repetitions=1, timeout=None, thread=False, wait=True), \r\n request=Data(payload='3c9da903-028c-4dd0-b583-f15ccaed1280', format='text', name=None, action=None, timestamp=1710052480.8686686), \r\n response=Data(payload='Command was stopped.', format='text', name=None, read=False, write=False, timestamp=1710052486.8754737), \r\n memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None\r\n)\r\n\r\nCommand(\r\n id='df96ff69-16d2-4c42-a5a9-f16c390f15ee', \r\n action=Action(type='management', name='command', repetitions=1, timeout=None, thread=False, wait=True), \r\n request=Data(payload='3c9da903-028c-4dd0-b583-f15ccaed1280', format='text', name=None, action=None, timestamp=1710052480.8686686), \r\n response=Data(payload={'id': '3c9da903-028c-4dd0-b583-f15ccaed1280', 'action': {'type': 'execution', 'name': 'python', 'repetitions': 1, 'timeout': None, 'thread': True, 'wait': False}, 'request': {'payload': 'import time\\nfor _ in range(10):\\n\\ttime.sleep(1)', 'format': 'text', 'name': None, 'action': None, 'timestamp': 1710052480.8686686}, 'response': {'payload': {}, 'format': 'json', 'name': None, 'action': None, 'timestamp': 1710052480.8705611}, 'memory': None, 'complete': False, 'running': False, 'error': None}, format='json', name=None, action=None, timestamp=1710052486.8764887),\r\n memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None\r\n)\r\n\r\nwritten a file named \"hello.txt\" with content \"hello world\"\r\n\r\nCommand(\r\n id='f45da0d9-feee-41b8-8686-1024bfb70fc0', \r\n action=Action(type='file', name='write', repetitions=1, timeout=None, thread=False, wait=True), \r\n request=File(payload='hello world', format='text', name='hello.txt', action='write', timestamp=1710090057.4463112, position=11, size=11, buffer=None), \r\n response=Data(payload=\"Data was added to the end of file: 'hello.txt'.\", format='text', name=None, action=None, timestamp=1710090064.4521823), \r\n memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None\r\n)\r\n\r\nCommand(\r\n id='2d5a4f9a-6467-41e2-88ab-119626ef0fb1', \r\n action=Action(type='file', name='read', repetitions=1, timeout=None, thread=False, wait=True), \r\n request=File(payload=None, format='text', name='hello.txt', action='read', timestamp=1710147070.8170629, position=11, size=11, buffer=None), \r\n response=Data(payload='hello world', format='text', name=None, action=None, timestamp=1710147070.8180661), \r\n memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None\r\n)\r\n````\r\n\r\nConstructing a Command object:\r\n````python\r\n# The id of the command, can also be a plaintext name.\r\nid: str = str(uuid4())\r\n# Describes the type and name of action to preform.\r\naction: Action | None = None\r\n# Describes the input (request) data and output (response) data,\r\n# and what to do with them.\r\nrequest: Data = Data()\r\nresponse: Data = Data()\r\n# a dedicated memory dictionary for the command, \r\n# rather than using the shared memory of the executor's.\r\nmemory: dict[str, JsonValue] = None\r\n````\r\n\r\nAdditional attributes:\r\n````python\r\n# Id the command is still running: complete: False, running: True.\r\ncomplete: bool = False\r\nrunning: bool = False\r\n# When an error is raised, it is saved here.\r\nerror: str | None = None\r\n````\r\n\r\nConstructing an Action object:\r\n````python\r\n# The type of action, from the Actions class.\r\ntype: str\r\n# The name of the action from the type from the Actions class.\r\nname: str\r\n# The amount of times to commit the action in a row.\r\nrepetitions: int = 1\r\n# A timeout to stop the action.\r\ntimeout: dt.timedelta = None\r\n# A value to specify that the action is to be executed in a different thread.\r\n# This means that the action will return back the command as usual, \r\n# but will specify that the command is not complete and still running.\r\nthread: bool = False\r\n# A value to make the executor wait to the action to finish.\r\nwait: bool = True\r\n````\r\n\r\nConstructing a Data object:\r\n````python\r\n# The bytes | json valid payload to contain.\r\npayload: JsonValue = None\r\n# The format of the data. Can be inferred automatically.\r\nformat: str | Literal['text', 'bytes', 'json'] | None = None\r\n# The name of the data, with which the data can be \r\n# saved to or read from the memory of the command/executor.\r\nname: str | None = None\r\n# The memory action to take with the data: read/write/delete/search\r\naction: Literal['read', 'write', 'delete', 'search'] | None = None\r\n````\r\n\r\nAdditional attributes:\r\n````python\r\n# The timestamp of creation of the object.\r\ntimestamp: float = time.time()\r\n````\r\n\r\nSimple Json-valid I/O:\r\n````python\r\nfrom backdoor import Command, Action, Data\r\n\r\nc1 = Command(\r\n id='793f1d0d-641e-45b4-ba2f-dad801c35a3f',\r\n action=Action(type='data', name='write', repetitions=1, timeout=None, thread=False, wait=True),\r\n request=Data(payload='text', format='text', name='value', action='write', timestamp=1710051829.9969397),\r\n response=Data(payload=\"'value' was written to memory in memory.\", format='text', name=None, action=None, timestamp=1710051829.9969397),\r\n memory=None, complete=True, running=False, forget=False, keep_request=True, message=None, error=None\r\n)\r\n\r\nprint(c1.dump())\r\nprint(\"same data:\", c1 == Command.load(c1.dump()))\r\n````\r\n\r\noutput:\r\n````python\r\n{\r\n 'id': '793f1d0d-641e-45b4-ba2f-dad801c35a3f', \r\n 'action': {'type': 'data', 'name': 'write', 'repetitions': 1, 'timeout': None, 'thread': False, 'wait': True}, \r\n 'request': {'payload': 'text', 'format': 'text', 'name': 'value', 'action': 'write', 'timestamp': 1710051829.9969397}, \r\n 'response': {'payload': \"'value' was written to memory in memory.\", 'format': 'text', 'name': None, 'action': None, 'timestamp': 1710051829.9969397}, \r\n 'memory': None, 'complete': True, 'running': False, 'forget': False, 'keep_request': True, 'message': None, 'error': None\r\n}\r\nsame data: True\r\n````\r\n\r\nExecutor Construction:\r\n````python\r\n# Saves the id of the commands executed.\r\nhistory: list[str] = []\r\n# Saves the id of the commands being executed.\r\nrunning: list[str] = []\r\n# Contains all command object.\r\ncommands: dict[str, Command] = {}\r\n# Shared memory of data and variables from and for the execution of commands.\r\nmemory: dict[str, ...] = {}\r\n# Contains custom command objects.\r\ncustom: dict[str, Command | None] = {}\r\n# Specifies the initial and current locations of the system to execute in.\r\nroot_location: str = os.getcwd\r\ncurrent_location: str = os.getcwd\r\n# Callables to save/load/delete command data/objects.\r\nsave: Callable[[Command], str] = None\r\nload: Callable[[str], Command] = None\r\ndelete: Callable[[str], ...] = None\r\n````\r\n\r\nExecutor Interface:\r\n````python\r\nfrom backdoor import Executor, Command\r\n\r\nexecutor = Executor()\r\n\r\n# simple execution\r\n\r\nc1 = Command(...)\r\n\r\nc1_copy = c1.copy()\r\n\r\nc1_return = executor.execute(c1)\r\n\r\nassert c1 is c1_return\r\nassert c1_copy != c1_return\r\n\r\n# adding a custom command\r\n\r\ncustom_command = Command(...)\r\n\r\n# method 1:\r\nexecutor.add(custom_command)\r\n\r\n# method 2:\r\nfrom backdoor import Action, Data, Actions\r\n\r\ncustom_command_adder = Command(\r\n action=Action(type=Actions.MANAGEMENT.TYPE, name=Actions.MANAGEMENT.ADD),\r\n request=Data(payload=custom_command.dump())\r\n)\r\n\r\nexecutor.execute(custom_command_adder)\r\n\r\n# running the custom command\r\n\r\ncustom_command_return = executor.execute(\r\n Command(\r\n action=Action(type=Actions.EXECUTION.TYPE, name=Actions.MANAGEMENT.CLEAN),\r\n request=Data(payload=custom_command.id)\r\n )\r\n)\r\n````\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A framework for designing, orchestrating and executing backdoor systems, with short and long term memory, dynamic execution, data delivery, multithreading live communication and more.",
"version": "0.0.13",
"project_urls": {
"Homepage": "https://github.com/Shahaf-F-S/backdoor"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c95b96595e4416c1d7c021fd5e3271d02288ed55f2a520fcc53cb92135082088",
"md5": "a780309388b91ff730d674191332864a",
"sha256": "33eddfe1a3802095a27aa1b7e01b8276c9cab3ce5f6dddcfb638396df43ffec3"
},
"downloads": -1,
"filename": "backdoor-io-0.0.13.tar.gz",
"has_sig": false,
"md5_digest": "a780309388b91ff730d674191332864a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 20684,
"upload_time": "2024-07-06T09:58:14",
"upload_time_iso_8601": "2024-07-06T09:58:14.735749Z",
"url": "https://files.pythonhosted.org/packages/c9/5b/96595e4416c1d7c021fd5e3271d02288ed55f2a520fcc53cb92135082088/backdoor-io-0.0.13.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-06 09:58:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Shahaf-F-S",
"github_project": "backdoor",
"github_not_found": true,
"lcname": "backdoor-io"
}