Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. cat<<EOF >/tmp/fooz
  4. #!/bin/bash
  5.  
  6. while true; do sleep 0.1; done
  7. EOF
  8.  
  9. chmod 755 /tmp/fooz
  10.  
  11. cat<<EOF >/tmp/test.py
  12. import getpass
  13. import paramiko
  14. import os
  15. import time
  16.  
  17. client = paramiko.SSHClient()
  18. client.load_system_host_keys()
  19. client.connect("127.0.0.1", password=getpass.getpass())
  20. client.get_transport().set_keepalive(1)
  21.  
  22. chan = client.get_transport().open_session()
  23. chan.get_pty()
  24. chan.exec_command("/tmp/fooz")
  25. chan.close()
  26. time.sleep(3)
  27. print "Looking for fooz with pty"
  28. os.system("ps ax | grep 'bash.*fooz' | grep -v grep")
  29.  
  30. chan = client.get_transport().open_session()
  31. chan.exec_command("/tmp/fooz")
  32. chan.close()
  33. time.sleep(3)
  34. print "Looking for fooz without pty"
  35. os.system("ps ax | grep 'bash.*fooz' | grep -v grep")
  36.  
  37. os.system("ps ax | grep 'bash.*fooz' | grep -v grep | awk '{print \$1}' | xargs kill -9")
  38. EOF
  39.  
  40. python /tmp/test.py
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement