Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.42 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import re
  5. from datetime import datetime
  6. #from intrusion import *
  7.  
  8. seed = "--------------------"
  9.  
  10. limit = 22
  11.  
  12. class string(object):
  13.  
  14.     def __init__(self, string):
  15.         self.string = string
  16.        
  17.     def strip(self):
  18.         test = re.findall(r"[\\\n\t\r]", self.string)
  19.         for i in test:
  20.             self.string = self.string.replace(i, "")
  21.        
  22.         return self.string
  23.  
  24. def safe():
  25.     from sys import modules
  26.     modules.clear()
  27.     del modules
  28.     global input, compile, execfile, globals, vars, open, file, reload, __import__, locals, dir
  29.     input, compile, execfile, globals, vars, locals, open, file, reload, __import__, dir = None, None, None, None, None, None, None, None, None, None, None
  30.     __builtins__.dir = None
  31.    
  32.    
  33. def Option():
  34.     print "[Open] - To create a new token"
  35.     print "[Revoke] - To Revoke a token"
  36.     opt = raw_input("Type the option: ")
  37.     return opt
  38.    
  39. def validation(input):
  40.     err = int()
  41.     input = str(input)
  42.     nochrs = '[&*+-/34689?\<_>!@#`|$%;{}]'
  43.     if re.findall(nochrs, input): err = 1
  44.     else: err = 0
  45.        
  46.     if not err: return 1
  47.     else: return 0
  48.  
  49. def gentoken(dic, seed, date):
  50.     pt1 = pow(dic.values()[0], 2)
  51.     pt2 = int(date[2:4]) * int(date[4:]) + ~int(date[:2])
  52.     pt3 = [ord(x) for x in seed if ord(x) % 2 == 0] * 4
  53.     pt3 = pt3[1] * pt3[3] * pt3[3] * pt3[7] + pt3[-1] + pt3[-3] + pt3[-3] + pt3[-7] + sum(pt3[13:37])
  54.     return abs(pt1-(pt2+pt3))  
  55.  
  56. def notify():
  57.     # Send intrusion infos to Counterintelligence
  58.     notifyCI()
  59.  
  60. def notfound():
  61.     print "Name not found, notification raised!"
  62.     #notify()
  63.     exit()
  64.  
  65. def verify(regex):
  66.  
  67.     try:
  68.  
  69.         lista = open("names.txt").read()
  70.         lista = eval(lista)
  71.         if len(regex) > limit:
  72.             print "What kind of name is yours?"
  73.             exit()
  74.    
  75.         tmp = re.findall("[^A-z+]", regex)
  76.         tmp1 = re.findall("[\[\]]", regex)
  77.         if tmp or tmp1:
  78.             print "Weird name!"
  79.             exit()
  80.         for num, i in enumerate(lista):
  81.             tmp = re.findall(regex, lista.keys()[num].decode("utf-8"))
  82.             print tmp
  83.            
  84.             if unicode("".join(tmp)) == unicode(lista.keys()[num].decode("utf-8")):
  85.                 global role
  86.                 role = lista.values()[num]
  87.                 return 1
  88.  
  89.         notfound()
  90.        
  91.     except:
  92.         notfound()
  93.  
  94. def gen():
  95.     safe()
  96.     print "\nUsage:"
  97.     print "gen 'token serial number'\n"
  98.     print "E.g.:"
  99.     print "gen 2017\n"
  100.  
  101.     while 1:
  102.         try:
  103.             var = raw_input(">>> ")
  104.             if validation(var):
  105.                 tmp = var.split()
  106.                 cmd = tmp[0]
  107.                 serial = tmp[1]
  108.                 if cmd == "gen":
  109.                     tmp = eval("{" + "cmd" + ":" + serial + "}")
  110.                     if type(tmp.values()[0]) == int and len(str(tmp.values()[0])) == 4:
  111.                         now = datetime.now()
  112.                         date = "%02d%02d%02d" % (now.day, now.hour, now.minute)
  113.                         date = str(date)
  114.                         final = gentoken(tmp, seed, date)
  115.                         print "\nToken: %s" % final
  116.                         print "Valid until: %s:%s:59\n" % (now.hour, now.minute)
  117.                     else: continue
  118.                    
  119.         except (KeyboardInterrupt, SystemExit): exit()
  120.         except: continue   
  121.  
  122. try:       
  123.  
  124.     print "Hello! Log on to the Token Generation System"
  125.     print "If your name is not on the authorized list, a notification will be generated!"
  126.     print "For security reasons, NEVER type your literal name."
  127.  
  128.     regex = raw_input("Type your regex-name to identify ([^\[\]][A-z+]): ")
  129.    
  130.     if verify(regex): pass
  131.  
  132.     print "\nHello, " + role + "!\n"
  133.  
  134.     option = Option()
  135.  
  136.     if role == "President" and "Open" in option or "Revoke" in option:
  137.         authorized = 1
  138.     else:
  139.         print "For now, only the president is allowed to generate tokens."
  140.         exit()
  141.  
  142.     if authorized:
  143.         print "\nFor security reasons, confirme your option!"
  144.         option = Option()
  145.         option_test = re.findall('[\w]+', option)
  146.         for s in option_test:
  147.             if s == "Open":
  148.                 print "Mr. President, enable the option to generate tokens on the server."
  149.                 exit()
  150.             elif s == "Revoke":
  151.                 token = raw_input("Type your token serial: ").strip()
  152.                 if len(token) > 4 or token.isdigit() != True:
  153.                     print "Revise your token!"
  154.                     exit()
  155.                 else:
  156.                     open = file("canceled-tokens.txt", "a")
  157.                     time = datetime.now()
  158.                     open.writelines("\nToken canceled at: %02d/%02d/%02d %02d:%02d:%02d:\n" % (time.month, time.day, time.year, time.hour, time.minute, time.second))
  159.                     open.writelines(token)
  160.                     open.close()
  161.                     print "This will go through by a manual inspection, thank you Mr. " + role + "!"
  162.                     exit()
  163.             else:
  164.                 print "Incorrect option, please, try again!"   
  165.            
  166.         option = string(option)
  167.        
  168.  
  169.     if option.strip() == "Open":
  170.         gen()
  171.  
  172. except (KeyboardInterrupt, SystemExit): exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement