OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 ''' |
| 3 PEXPECT LICENSE |
| 4 |
| 5 This license is approved by the OSI and FSF as GPL-compatible. |
| 6 http://opensource.org/licenses/isc-license.txt |
| 7 |
| 8 Copyright (c) 2012, Noah Spurrier <noah@noah.org> |
| 9 PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY |
| 10 PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE |
| 11 COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. |
| 12 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 13 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 14 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 15 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 19 |
| 20 ''' |
| 21 import time |
| 22 import termios |
| 23 import sys |
| 24 |
| 25 # a dumb PAM will print the password prompt first then set ECHO |
| 26 # False. What it should do it set ECHO False first then print the |
| 27 # prompt. Otherwise, if we see the password prompt and type out |
| 28 # password real fast before it turns off ECHO then some or all of |
| 29 # our password might be visibly echod back to us. Sounds unlikely? |
| 30 # It happens. |
| 31 |
| 32 print("fake password:") |
| 33 sys.stdout.flush() |
| 34 time.sleep(3) |
| 35 attr = termios.tcgetattr(sys.stdout) |
| 36 attr[3] = attr[3] & ~termios.ECHO |
| 37 termios.tcsetattr(sys.stdout, termios.TCSANOW, attr) |
| 38 time.sleep(12) |
| 39 attr[3] = attr[3] | termios.ECHO |
| 40 termios.tcsetattr(sys.stdout, termios.TCSANOW, attr) |
| 41 time.sleep(2) |
OLD | NEW |