Beispiel #1
0
from os import environ, execl as exec
from sys import argv, exit
from getpass import getpass

import totp

try:
  if len(argv) > 1:
    myFile = argv[1]
  else:
    myFile = '~/.2fa'

  myTOTP = totp.Config(myFile)

  totp.setCatch(myTOTP.options['timer'])

  while True:
    myCode = getpass('Challenge: ')
    if len(myCode):
      break

  if myTOTP.authenticate(myCode):
    myShell = environ['SHELL']
    with open('/etc/shells') as handle:
      goodShell = False
      for line in handle:
        if line.rstrip() == myShell:
          goodShell = True
          break
      if not goodShell:
Beispiel #2
0
import totp

try:
  setresuid(getuid(environ['PAM_USER'])[2], getuid(environ['PAM_USER'])[2], 0)

  if len(argv) > 1:
    myFile = argv[1]
  else:
    myFile = '~/.2fa'

  myConf = totp.Config(myFile)
  myTTY = '/dev/' + environ['PAM_TTY']

  setresuid(0,0,0)

  totp.setCatch(myConf.options['timer'])

  with open(myTTY, 'w') as handle:
    handle.write('Challenge: ')
  with open(myTTY) as handle:
    old = tcgetattr(handle.fileno())
    new = tcgetattr(handle.fileno())
    new[3] = new[3] & ~ECHO
    try:
      tcsetattr(handle.fileno(), DRAIN, new)
      while True:
        myCode = handle.readline().rstrip()
        if len(myCode):
          break
    finally:
      tcsetattr(handle.fileno(), DRAIN, old)
Beispiel #3
0
try:
    setresuid(
        getuid(environ['PAM_USER'])[2],
        getuid(environ['PAM_USER'])[2], 0)

    if len(argv) > 1:
        myFile = argv[1]
    else:
        myFile = '~/.2fa'

    myConf = totp.Config(myFile)
    myTTY = '/dev/' + environ['PAM_TTY']

    setresuid(0, 0, 0)

    totp.setCatch(myConf.options['timer'])

    with open(myTTY, 'w') as handle:
        handle.write('Challenge: ')
    with open(myTTY) as handle:
        old = tcgetattr(handle.fileno())
        new = tcgetattr(handle.fileno())
        new[3] = new[3] & ~ECHO
        try:
            tcsetattr(handle.fileno(), DRAIN, new)
            while True:
                myCode = handle.readline().rstrip()
                if len(myCode):
                    break
        finally:
            tcsetattr(handle.fileno(), DRAIN, old)