Author Topic: password protect terminal in python+windows  (Read 2411 times)

0 Members and 4 Guests are viewing this topic.

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: password protect terminal in python+windows
« Reply #15 on: May 31, 2013, 09:12:35 am »
A ctrl-c can easily be caught with a try/except.

For example:

Code: [Select]
def inf(secret):
           try:
                      attempt = 0
                      while secret != attempt:
                               attempt = raw_input(">")
                      return 0
           except:
                      inf('secret')

def main():
        inf('abc')


Its not a clean solution but it catches the ctrl-c .
The only thing im still strugling with is how to catch the ctrl-z background thingy.
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline str0be

  • Serf
  • *
  • Posts: 42
  • Cookies: 8
  • <!-- hi
    • View Profile
Re: password protect terminal in python+windows
« Reply #16 on: May 31, 2013, 03:36:59 pm »
Use exec to replace the shell process with the python one. The python script will have to replace itself with a new shell process when the right password is input.

kbint.py
Code: (python) [Select]
#!/usr/bin/env python
import os

def inf(secret):
    try:
        attempt = 0
        while secret != attempt:
            attempt = raw_input(">")
        os.execv("/bin/sh", ["sh"])
    except:
        inf(secret)

inf("abc")

Code: [Select]
$ exec ./kbint.py

Not sure about the windows equivalent...
« Last Edit: May 31, 2013, 04:28:28 pm by str0be »

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: password protect terminal in python+windows
« Reply #17 on: May 31, 2013, 06:16:12 pm »
Quote
Not sure about the windows equivalent...

Lol dont know , dont care.
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage