Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
SSH Upload and Execute Script
#!/usr/bin/env python
Author: Vivek Ramachandran
Online Infosec Training:
import paramiko
import sys
def UploadFileAndExecute(sshConnection, fileName) :
sftpClient = ssh.open_sftp()
sftpClient.put(fileName, "/tmp/" +fileName)
ssh.exec_command("chmod a+x /tmp/" +fileName)
ssh.exec_command("nohup /tmp/" +fileName+ " &")
if __name__ == "__main__" :
ssh = paramiko.SSHClient()
ssh.connect(sys.argv[1], username=sys.argv[2], password=sys.argv[3])
UploadFileAndExecute(ssh, sys.argv[4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment