Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os
- import gnupg
- import paramiko
- import sys
- import time
- decrypted_pass = ''
- chan = ''
- host = sys.argv[1]
- #userfile = sys.argv[3]
- user = sys.argv[2]
- def decryptPass():
- global decrypted_pass
- home = os.getenv('HOME')
- gpg = gnupg.GPG(gnupghome='%s/.gnupg/' % home)
- encrypted_pass = ''
- for x in open('%s/.ssh/passtext.gpg' % home,'r').readlines():
- encrypted_pass += x
- decrypted_pass = gpg.decrypt(encrypted_pass).data
- decrypted_pass = decrypted_pass.strip('\n')
- def establishPty():
- global chan
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(host,username=user,password=decrypted_pass)
- chan = ssh.invoke_shell()
- while not chan.recv_ready():
- print "Connecting..."
- time.sleep(2)
- print(chan.recv(1024))
- chan.send('sudo su -\n')
- time.sleep(1)
- chan.send('%s\n' % decrypted_pass)
- print(chan.recv(1024))
- print "Sudo invocation command exit status was: %s" % (int(chan.exit_status_ready()))
- while not chan.recv_ready():
- time.sleep(2)
- chan.send('pwd\n')
- print(chan.recv(1024))
- print(chan.recv(1024))
- print "Exit status of last command was: %s" % (int(chan.exit_status_ready()))
- def main():
- decryptPass()
- establishPty()
- if __name__ == "__main__":
- sys.exit(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement