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

0 Members and 3 Guests are viewing this topic.

Offline 3vilp4wn

  • Serf
  • *
  • Posts: 46
  • Cookies: 11
  • :D
    • View Profile
    • Evil Ninja Hackers
password protect terminal in python+windows
« on: May 26, 2013, 10:49:37 pm »
Hello!
I just password protected my terminal in python+windows, and someone asked how I did it on irc, so I figured I'd post it here.

Step 1: make the python script:
somefile.py
Code: [Select]
import time
passwd = raw_input('C:\Documents and Settings\yourname>')  #you can have it ask for a password as well, but I prefer this.

if passwd == 'somepassword':
    print 'password accepted.  Welcome, hacker.'
else:
    print 'Fuck off, n00b.'
    print 'You have been locked out of this terminal.'
    time.sleep(42)
    print "Jesus, just *fuck off*, ok?"
    time.sleep(42)
    print "Still waiting?"
    time.sleep(42)
    print "'Cause, I'm not gonna let you get at the terminal."
    while True:
        time.sleep(42)

Step 2: create the batch file that will run the python file.  it's just one line:
somefile.bat
Code: [Select]
python C:\path\to\password\program.py
step 3: set the batch file to run when the terminal is started up.
open the run menu.  Windows key+R or start -> run
type "regedit"
Navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor in the side bar.  right click and edit the "Autorun" property.
Type in the path to the batch file from step 2.


Now open the command prompt!
it should look normal, but if you don't type in the right password,  it gets mad at you  :)
Note that removing python from the classpath or pressing ctrl+C will bypass this, but it's useful for weeding out the skids.
Shooting is not  too good for my enemies.

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: password protect terminal in python+windows
« Reply #1 on: May 26, 2013, 11:23:38 pm »
Try putting the function in a thread with a highly long time.sleep() value.

That should effectively disable the KeyboardInterrupt exception and make this script useful.
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: password protect terminal in python+windows
« Reply #2 on: May 26, 2013, 11:50:13 pm »
Try putting the function in a thread with a highly long time.sleep() value.

That should effectively disable the KeyboardInterrupt exception and make this script useful.

Unless the thread is run as daemon, the interrupt will work.
>>>import this
-----------------------------

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: password protect terminal in python+windows
« Reply #3 on: May 27, 2013, 12:03:49 am »
Hold on, in that case you can directly disable the signals using Python's built-in module.

Here's your script modified, so that it rejects all KeyboardInterrupt (Ctrl+C) and Stop (Ctrl+Z) exceptions: (*nix-only, I'm afraid)

Code: [Select]
import signal, sys

while True:

    def anti_stop(arg1, arg2):
        print 'DENIED'

    def anti_interrupt(arg1, arg2):
        print 'DENIED'

    signal.signal(signal.SIGINT, anti_interrupt) # disable KeyboardInterrupt
    signal.signal(signal.SIGTSTP, anti_stop) # disable Stop

    passwd = raw_input('Enter password: ')

    if passwd == 'shotgundebugging':
           print 'Password accepted.'
           sys.exit()

EDIT: Damn, it fails upon incorrect password. Let me think of a workaround...

EDIT 2: OK, I wrapped it around a while loop. Now it works.
« Last Edit: May 27, 2013, 01:07:01 am by vezzy »
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline pyte

  • Peasant
  • *
  • Posts: 79
  • Cookies: -7
    • View Profile
Re: password protect terminal in python+windows
« Reply #4 on: May 27, 2013, 06:54:37 am »

Hello!
I just password protected my terminal in python+windows, and someone asked how I did it on irc, so I figured I'd post it here.

Step 1: make the python script:
somefile.py
Code: [Select]
import time
passwd = raw_input('C:\Documents and Settings\yourname>')  #you can have it ask for a password as well, but I prefer this.

if passwd == 'somepassword':
    print 'password accepted.  Welcome, hacker.'
else:
    print 'Fuck off, n00b.'
    print 'You have been locked out of this terminal.'
    time.sleep(42)
    print "Jesus, just *fuck off*, ok?"
    time.sleep(42)
    print "Still waiting?"
    time.sleep(42)
    print "'Cause, I'm not gonna let you get at the terminal."
    while True:
        time.sleep(42)

Step 2: create the batch file that will run the python file.  it's just one line:
somefile.bat
Code: [Select]
python C:\path\to\password\program.py
step 3: set the batch file to run when the terminal is started up.
open the run menu.  Windows key+R or start -> run
type "regedit"
Navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor in the side bar.  right click and edit the "Autorun" property.
Type in the path to the batch file from step 2.


Now open the command prompt!
it should look normal, but if you don't type in the right password,  it gets mad at you  :)
Note that removing python from the classpath or pressing ctrl+C will bypass this, but it's useful for weeding out the skids.

I think this is a good one. how can it be implemented in Unix??
took the code tho  ;)
If you don't go into the tiger's cave, how will you get the cub?

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: password protect terminal in python+windows
« Reply #5 on: May 27, 2013, 08:26:52 am »
I think this is a good one. how can it be implemented in Unix??
took the code tho  ;)

Its pretty portable and useless :P
Well as this isnt gonna offer any protection at all but if you want it to "password protect" a terminal under linux you could just add it to the .bashrc file.
Indeed you should catch the interupts such as ctrl-c ,ctrl-x,ctrl-z.

Quote
Welcome hacker
LMFAO
« Last Edit: May 27, 2013, 08:28:07 am by proxx »
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline pyte

  • Peasant
  • *
  • Posts: 79
  • Cookies: -7
    • View Profile
Re: password protect terminal in python+windows
« Reply #6 on: May 27, 2013, 08:34:00 am »
Its pretty portable and useless :P
Well as this isnt gonna offer any protection at all but if you want it to "password protect" a terminal under linux you could just add it to the .bashrc file.
Indeed you should catch the interupts such as ctrl-c ,ctrl-x,ctrl-z.
LMFAO


Already done.i like the deception it offers. no one will tamper with my terminal unless he knows its useless.
he has to come from EZ. ;D
If you don't go into the tiger's cave, how will you get the cub?

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: password protect terminal in python+windows
« Reply #7 on: May 27, 2013, 08:44:40 am »
Why not just use the unix login if you want a login.
You can setup it up in such a way that every new virtual terminal requires a login.
That way you actually have a decent protection.

Coding stuff yourself is always more fun , I understand that part.
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: password protect terminal in python+windows
« Reply #8 on: May 27, 2013, 04:11:00 pm »

Already done.i like the deception it offers. no one will tamper with my terminal unless he knows its useless.
he has to come from EZ. ;D

Since you're on a Unix-like machine, why don't you use the signals module to escape interrupts, so as to make it actually useful and not just a placebo (as in my code snippet above)?

But hey, have fun.
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline pyte

  • Peasant
  • *
  • Posts: 79
  • Cookies: -7
    • View Profile
Re: password protect terminal in python+windows
« Reply #9 on: May 28, 2013, 07:18:46 am »
Since you're on a Unix-like machine, why don't you use the signals module to escape interrupts, so as to make it actually useful and not just a placebo (as in my code snippet above)?

But hey, have fun.


I have tried editing the keyboard interapt part but aint working in my way. i know i didnt use the signal module(which i think is silly) but still wanted to see if my way would work.
here is the code, any errors?


Code: [Select]

import time
import pyttsx
import datetime
import os


saa = time.ctime()
passwd = raw_input("-- ")
if passwd == '':
    try:
      passwd = raw_input("-- ")
      if passwd =='****':
        print '                                       welcome Hacker, its',saa
                                                       
   
    except KeyboardInterrupt:
       print'that wont work here!'
else:
    print'Not really!'
    time.sleep(20)
    print 'You have been locked out of this terminal.'
    time.sleep(42)
    print "Damn!Just get lost, ok?"
    time.sleep(42)
    print "Still waiting?"
    time.sleep(42)
    print "ill still be here and wount let you in..Think about that!"
    while True:
        time.sleep(42)

If you don't go into the tiger's cave, how will you get the cub?

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: password protect terminal in python+windows
« Reply #10 on: May 28, 2013, 09:13:10 am »

I have tried editing the keyboard interapt part but aint working in my way. i know i didnt use the signal module(which i think is silly) but still wanted to see if my way would work.
here is the code, any errors?


Code: [Select]

import time
import pyttsx
import datetime
import os


saa = time.ctime()
passwd = raw_input("-- ")
if passwd == '':
    try:
      passwd = raw_input("-- ")
      if passwd =='****':
        print '                                       welcome Hacker, its',saa
                                                       
   
    except KeyboardInterrupt:
       print'that wont work here!'
else:
    print'Not really!'
    time.sleep(20)
    print 'You have been locked out of this terminal.'
    time.sleep(42)
    print "Damn!Just get lost, ok?"
    time.sleep(42)
    print "Still waiting?"
    time.sleep(42)
    print "ill still be here and wount let you in..Think about that!"
    while True:
        time.sleep(42)


Yes you should stuff the code inside a loop.
With the except statement your breaking out in this case.

Just do a while succes != True:
Only when the correct password is given change the succes to True or whatever.
« Last Edit: May 28, 2013, 09:14:15 am by proxx »
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: password protect terminal in python+windows
« Reply #11 on: May 29, 2013, 08:04:39 pm »
Here's a further improvement with Python's getpass module to hide output while the password being typed in:

Code: [Select]
import signal, sys, getpass

while True:

    def anti_stop(arg1, arg2):
        print 'DENIED'

    def anti_interrupt(arg1, arg2):
        print 'DENIED'

    signal.signal(signal.SIGINT, anti_interrupt) # disable KeyboardInterrupt
    signal.signal(signal.SIGTSTP, anti_stop) # disable Stop

    passwd = getpass.getpass("Enter password: ")

    if passwd == 'shotgundebugging':
           print 'Password accepted.'
           sys.exit()
I'd say it's somewhat useful now.
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: password protect terminal in python+windows
« Reply #12 on: May 29, 2013, 08:36:13 pm »
Here's a further improvement with Python's getpass module to hide output while the password being typed in:

Code: [Select]
import signal, sys, getpass

while True:

    def anti_stop(arg1, arg2):
        print 'DENIED'

    def anti_interrupt(arg1, arg2):
        print 'DENIED'

    signal.signal(signal.SIGINT, anti_interrupt) # disable KeyboardInterrupt
    signal.signal(signal.SIGTSTP, anti_stop) # disable Stop

    passwd = getpass.getpass("Enter password: ")

    if passwd == 'shotgundebugging':
           print 'Password accepted.'
           sys.exit()
I'd say it's somewhat useful now.

Yeah something like that already looks better.
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline 3vilp4wn

  • Serf
  • *
  • Posts: 46
  • Cookies: 11
  • :D
    • View Profile
    • Evil Ninja Hackers
Re: password protect terminal in python+windows
« Reply #13 on: May 31, 2013, 01:33:31 am »
Looking at things other people have posted, here's an updated version:

Code: [Select]
import sys, getpass, ctypes

fail = True
failcount = 0

while fail:
    try:
        if failcount == 3:
            user32 = ctypes.cdll.LoadLibrary("user32.dll")
            user32.LockWorkStation()

        passwd = getpass.getpass("Enter password: \n")

        if passwd == 'foobar':
            print 'Password accepted.'
            fail = False
        else:
            failcount = failcount + 1
    except:
        pass

In the interest of making this even more windows only, it uses user32.dll to lock the computer after 3 failed password attempts.  Good security would be one failed attempt, but whatever.

I couldn't get the signal module to work, so I just used a giant try/except block.
Shooting is not  too good for my enemies.

Offline pyte

  • Peasant
  • *
  • Posts: 79
  • Cookies: -7
    • View Profile
Re: password protect terminal in python+windows
« Reply #14 on: May 31, 2013, 07:50:58 am »
There is one thing with this code. when i run it and throw in a keyboardinterrupt it really doesn't flow .
i don't know how to deal with this coz what i really am thinking of a way to leave anyone out even if you press the ctrl +c.

If you don't go into the tiger's cave, how will you get the cub?