Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature hex commands #67

Merged
merged 2 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/attackmate/executors/ssh/interactfeature.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import logging
import binascii
from datetime import datetime
from paramiko.client import SSHClient
from attackmate.schemas.ssh import SSHCommand
from attackmate.execexception import ExecException
from attackmate.executors.ssh.sessionstore import SessionStore


Expand Down Expand Up @@ -54,7 +56,13 @@ def exec_interactive_command(self, command: SSHCommand, client: SSHClient, sessi
stderr = channel.makefile_stderr('rb')

if stdin.channel.send_ready():
stdin.write(str.encode(command.cmd))
if command.bin:
try:
stdin.write(binascii.unhexlify(command.cmd))
except binascii.Error:
raise ExecException(f"only hex characters are allowed in binary mode: \"{command.cmd}\"")
else:
stdin.write(str.encode(command.cmd))
stdin.flush()

return (None, stdout, stderr)
Empty file.
1 change: 1 addition & 0 deletions src/attackmate/schemas/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SSHCommand(SSHBase):
validate_prompt: bool = True
command_timeout: StringNumber = '15'
prompts: List[str] = ['$ ', '# ', '> ']
bin: bool = False


class SFTPCommand(SSHBase):
Expand Down
Loading