Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import re
- from datetime import datetime
- #from intrusion import *
- seed = "--------------------"
- limit = 22
- class string(object):
- def __init__(self, string):
- self.string = string
- def strip(self):
- test = re.findall(r"[\\\n\t\r]", self.string)
- for i in test:
- self.string = self.string.replace(i, "")
- return self.string
- def safe():
- from sys import modules
- modules.clear()
- del modules
- global input, compile, execfile, globals, vars, open, file, reload, __import__, locals, dir
- input, compile, execfile, globals, vars, locals, open, file, reload, __import__, dir = None, None, None, None, None, None, None, None, None, None, None
- __builtins__.dir = None
- def Option():
- print "[Open] - To create a new token"
- print "[Revoke] - To Revoke a token"
- opt = raw_input("Type the option: ")
- return opt
- def validation(input):
- err = int()
- input = str(input)
- nochrs = '[&*+-/34689?\<_>!@#`|$%;{}]'
- if re.findall(nochrs, input): err = 1
- else: err = 0
- if not err: return 1
- else: return 0
- def gentoken(dic, seed, date):
- pt1 = pow(dic.values()[0], 2)
- pt2 = int(date[2:4]) * int(date[4:]) + ~int(date[:2])
- pt3 = [ord(x) for x in seed if ord(x) % 2 == 0] * 4
- pt3 = pt3[1] * pt3[3] * pt3[3] * pt3[7] + pt3[-1] + pt3[-3] + pt3[-3] + pt3[-7] + sum(pt3[13:37])
- return abs(pt1-(pt2+pt3))
- def notify():
- # Send intrusion infos to Counterintelligence
- notifyCI()
- def notfound():
- print "Name not found, notification raised!"
- #notify()
- exit()
- def verify(regex):
- try:
- lista = open("names.txt").read()
- lista = eval(lista)
- if len(regex) > limit:
- print "What kind of name is yours?"
- exit()
- tmp = re.findall("[^A-z+]", regex)
- tmp1 = re.findall("[\[\]]", regex)
- if tmp or tmp1:
- print "Weird name!"
- exit()
- for num, i in enumerate(lista):
- tmp = re.findall(regex, lista.keys()[num].decode("utf-8"))
- print tmp
- if unicode("".join(tmp)) == unicode(lista.keys()[num].decode("utf-8")):
- global role
- role = lista.values()[num]
- return 1
- notfound()
- except:
- notfound()
- def gen():
- safe()
- print "\nUsage:"
- print "gen 'token serial number'\n"
- print "E.g.:"
- print "gen 2017\n"
- while 1:
- try:
- var = raw_input(">>> ")
- if validation(var):
- tmp = var.split()
- cmd = tmp[0]
- serial = tmp[1]
- if cmd == "gen":
- tmp = eval("{" + "cmd" + ":" + serial + "}")
- if type(tmp.values()[0]) == int and len(str(tmp.values()[0])) == 4:
- now = datetime.now()
- date = "%02d%02d%02d" % (now.day, now.hour, now.minute)
- date = str(date)
- final = gentoken(tmp, seed, date)
- print "\nToken: %s" % final
- print "Valid until: %s:%s:59\n" % (now.hour, now.minute)
- else: continue
- except (KeyboardInterrupt, SystemExit): exit()
- except: continue
- try:
- print "Hello! Log on to the Token Generation System"
- print "If your name is not on the authorized list, a notification will be generated!"
- print "For security reasons, NEVER type your literal name."
- regex = raw_input("Type your regex-name to identify ([^\[\]][A-z+]): ")
- if verify(regex): pass
- print "\nHello, " + role + "!\n"
- option = Option()
- if role == "President" and "Open" in option or "Revoke" in option:
- authorized = 1
- else:
- print "For now, only the president is allowed to generate tokens."
- exit()
- if authorized:
- print "\nFor security reasons, confirme your option!"
- option = Option()
- option_test = re.findall('[\w]+', option)
- for s in option_test:
- if s == "Open":
- print "Mr. President, enable the option to generate tokens on the server."
- exit()
- elif s == "Revoke":
- token = raw_input("Type your token serial: ").strip()
- if len(token) > 4 or token.isdigit() != True:
- print "Revise your token!"
- exit()
- else:
- open = file("canceled-tokens.txt", "a")
- time = datetime.now()
- open.writelines("\nToken canceled at: %02d/%02d/%02d %02d:%02d:%02d:\n" % (time.month, time.day, time.year, time.hour, time.minute, time.second))
- open.writelines(token)
- open.close()
- print "This will go through by a manual inspection, thank you Mr. " + role + "!"
- exit()
- else:
- print "Incorrect option, please, try again!"
- option = string(option)
- if option.strip() == "Open":
- gen()
- except (KeyboardInterrupt, SystemExit): exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement