Advertisement
furas

Python - getpass - pexpect/expect

May 14th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. #-------------------------------
  2. # poc.py
  3. #-------------------------------
  4.  
  5. #!/usr/bin/env python3
  6.  
  7. import getpass
  8.  
  9. normal = input('Normal input: ')
  10. hidden = getpass.getpass('Hidden input: ')
  11. print('Normal is {0}'.format(normal))
  12. print('Hidden is {0}'.format(hidden))
  13.  
  14. #-------------------------------
  15. # poc-test.py
  16. #-------------------------------
  17.  
  18. #!/usr/bin/env python3
  19.  
  20. import pexpect
  21.  
  22. child = pexpect.spawn('python3 poc.py')
  23.  
  24. #child.expect('Normal input: ')
  25. child.sendline('Hello')
  26.  
  27. #child.expect('Hidden input: ')
  28. child.sendline('World')
  29.  
  30. for line in child.readlines():
  31.     print(line.decode('utf-8'), end='')
  32.  
  33. #-------------------------------
  34. # poc.exp
  35. #-------------------------------
  36.  
  37. #!/usr/bin/expect -df
  38.  
  39. set timeout -1
  40. spawn ./poc.py
  41.  
  42. ## normal
  43. send -- "NORMAL\r"
  44.  
  45. ## hidden
  46. sleep 0.05 # getpass needs some time - 0.04 doesn't work
  47. send -- "HIDDEN\r"
  48.  
  49. expect eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement