Advertisement
Guest User

Untitled

a guest
Jun 17th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import paramiko
  4.  
  5.  
  6. def get_remote_user_info(host, user, password):
  7. shell = {}
  8. ssh = paramiko.SSHClient()
  9. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  10. ssh.connect(host, username=user, password=password, timeout=9.0)
  11. sftp_client = ssh.open_sftp()
  12. remote_file = sftp_client.open('/etc/passwd')
  13.  
  14. try:
  15. for line in remote_file:
  16. if len(line.rstrip("\n").split(":")) >= 6 and \
  17. line.rstrip("\n").split(":")[6] in ["/bin/sh", "/bin/bash"]:
  18. fields = line.rstrip().split(":")
  19. shell[fields[0]] = fields[-1]
  20. finally:
  21. remote_file.close()
  22. print shell
  23. return shell
  24. # for user in shell.keys():
  25. # print user
  26.  
  27.  
  28. if __name__ == '__main__':
  29. get_remote_user_info('host', 'user', 'pass')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement