def request_task(): # signature and communication key =cf.get("current","key_signature") #'123456' msg = str(random.uniform(1,100)) sign = hmac.new(key,msg).hexdigest() #url = 'http://localhost/test999.php' url = cf.get("current","url_request")# 'http://wtf.zbj.com/index.php?m=index&c=tools&a=scanport' values = {'msg':msg,'sign':sign} data = urllib.urlencode(values) req = urllib2.Request(url,data) res = urllib2.urlopen(req).read() b = re.findall('\n\n(.*?)\n\n',res) print 'response form web:' +res # print 'len(b) = ' +str(len(b)) # print b if res == 'none': print 'no task is running,waiting for task' elif b[2] != 'none': insert_a_task(b[0],'0') confirm(b[0]) path = cf.get("current","root_path") + 'wyportmap/wyportmap.py ' cmd = 'python '+' ' + path + ' '+ b[1] +' ' + b[0] + ' ' + b[2] os.system(cmd) get_and_send_result(b[0]) # delete_a_task(b[0]) elif b[2] == 'none': insert_a_task(b[0],'0') confirm(b[0]) cmd = 'python' + ' ' + path +' ' + b[1] +' ' + b[0] os.system(cmd) get_and_send_result(b[0]) # delete_a_task(b[0]) else: print 'the form of the task is not right,or other problem see request_task.py'
def pull_cfgs(args): redirect = [] auditcreeper = False commands = initialize.configuration argument_node = args.node output = False argument_node = args.node remediation = False with_remediation = False ### NODE_OBJECT IS A LIST OF ALL THE NODES IN THE DATABASE WITH ALL ATTRIBUTES node_object = process_nodes() ### MATCH_NODE IS A LIST OF NODES THAT MATCHES THE ARGUEMENTS PASSED IN BY USER match_node = search_node(argument_node,node_object) if(len(match_node) == 0): print("[+] [NO MATCHING NODES AGAINST DATABASE]") print("") else: node_element(match_node,node_object) node_create(match_node,node_object) for index in initialize.element: redirect.append('pull_cfgs') confirm(redirect,commands) print("")
def request_task(): # signature and communication key = '123456' msg = str(random.uniform(1,100)) sign = hmac.new(key,msg).hexdigest() #url = 'http://localhost/test999.php' url = 'http://wtf.thinkphp.com/index.php?m=index&c=tools&a=scanport' values = {'msg':msg,'sign':sign} data = urllib.urlencode(values) req = urllib2.Request(url,data) res = urllib2.urlopen(req).read() b = re.findall('\n\n(.*?)\n\n',res) print 'response form web:' +res print 'len(b) = ' +str(len(b)) # print b if res == 'none': print 'passed' elif b[2] != 'none': insert_a_task(b[0],'0') confirm(b[0]) cmd = 'python /root/workspace/test/fireEye/wyportmap/wyportmap.py ' + b[1] +' ' + b[0] + ' ' + b[2] os.system(cmd) get_and_send_result(b[0]) # delete_a_task(b[0]) elif b[2] == 'none': insert_a_task(b[0],'0') confirm(b[0]) #run_wyportmap(b[1],b[0]) cmd = 'python /root/workspace/test/fireEye/wyportmap/wyportmap.py ' + b[1] +' ' + b[0] os.system(cmd) get_and_send_result(b[0]) # delete_a_task(b[0]) else: print 'the form of the task is not right,or other problem see request_task.py'
def auditdiff(args): redirect = [] redirect.append('exec_cmd') index = 0 ext = '.jinja2' auditcreeper_flag = False output = True commands = initialize.configuration argument_node = args.node remediation = False if (args.file is None): # print("ARGS.FILE IS NONE") template_list = [] auditcreeper_flag = True else: # print("ARGS.FILE IS VALID") template = args.file + ext template_list = [] template_list.append(template) ### NODE_OBJECT IS A LIST OF ALL THE NODES IN THE DATABASE WITH ALL ATTRIBUTES node_object = process_nodes() ### NODE_TEMPLATE IS A LIST OF ALL THE TEMPLATES BASED ON PLATFORMS AND DEVICE TYPE node_template = process_templates() ### MATCH_NODE IS A LIST OF NODES THAT MATCHES THE ARGUEMENTS PASSED IN BY USER match_node = search_node(argument_node, node_object) ### MATCH_TEMPLATE IS A LIST OF 'MATCH' AND/OR 'NO MATCH' IT WILL USE THE MATCH_NODE ### RESULT, RUN IT AGAINST THE NODE_OBJECT AND COMPARES IT WITH NODE_TEMPLATE DATABASE ### TO SEE IF THERE IS A TEMPLATE FOR THE SPECIFIC PLATFORM AND TYPE. match_template = search_template(template_list, match_node, node_template, node_object, auditcreeper_flag) ### THIS WILL PARSE OUT THE GENERATED CONFIGS FROM THE *.JINJA2 FILE TO A LIST if (len(match_node) == 0): print("[+] [INVALID MATCHING NODES AGAINST DATABASE]") print("") elif ('NO MATCH' in match_template): # print("+ [NO MATCHING TEMPLATE AGAINST DATABASE]") print("") else: node_create(match_node, node_object) auditdiff_engine(template_list, node_object, auditcreeper_flag, output, remediation) # print ("THESE ARE THE COMMANDS: {}".format(commands)) if (len(initialize.configuration) == 0): pass else: if (remediation): confirm(redirect, commands) # multithread_engine(initialize.ntw_device,controller,commands) print("")
def pull_cfgs(args): argument_confirm = args.confirm argument_node = args.node commands = initialize.configuration output = False redirect = [] authentication = True """ :param argument_configm: Argument accepted as boolean :type augument_confirm: bool :param argument_node: Argument accepted as regular expression. :type augument_node: str :param commands: Referenced to global variable commands which keeps track of all commands per node. :type commands: list :param output: Flag to output to stdout. :type ext: bool :param redirect: A list of which method superloop will access. This variable is sent to the multithread_engine. Each element is a redirect per node. :type alt_key_file: list """ try: if argument_confirm is None or argument_confirm.lower() == 'true': confirm_flag = True elif argument_confirm.lower() == 'false': confirm_flag = False else: raise argparse.ArgumentTypeError('Boolean value expected.') node_object = process_nodes() match_node = search_node(argument_node, node_object) """ :param node_object: All node(s) in the database with all attributes. :type node_object: list :param match_node: Nodes that matches the arguements passed in by user. :type match_node: list """ if len(match_node) == 0: print('+ No matching node(s) found in database.') print('') else: node_element(match_node, node_object) node_create(match_node, node_object) for index in initialize.element: redirect.append('pull_cfgs') if (confirm_flag): confirm(redirect, commands, authentication) else: multithread_engine(initialize.ntw_device, redirect, commands, authentication) print('') except Exception as error: print('ExceptionError: an exception occured') print(error) return None
def push_cfgs(args): redirect = [] ext = '.jinja2' commands = initialize.configuration auditcreeper_flag = False output = False argument_node = args.node remediation = True with_remediation = True if(args.file is None): # print("ARGS.FILE IS NONE") template_list = [] auditcreeper_flag = True else: # print("ARGS.FILE IS VALID") template = args.file + ext template_list = [] template_list.append(template) ### NODE_OBJECT IS A LIST OF ALL THE NODES IN THE DATABASE WITH ALL ATTRIBUTES node_object = process_nodes() ### NODE_TEMPLATE IS A LIST OF ALL THE TEMPLATES BASED ON PLATFORMS AND DEVICE TYPE node_template = process_templates() ### MATCH_NODE IS A LIST OF NODES THAT MATCHES THE ARGUEMENTS PASSED IN BY USER match_node = search_node(argument_node,node_object) ### MATCH_TEMPLATE IS A LIST OF 'MATCH' AND/OR 'NO MATCH' IT WILL USE THE MATCH_NODE ### RESULT, RUN IT AGAINST THE NODE_OBJECT AND COMPARES IT WITH NODE_TEMPLATE DATABASE ### TO SEE IF THERE IS A TEMPLATE FOR THE SPECIFIC PLATFORM AND TYPE. match_template = search_template(template_list,match_node,node_template,node_object,auditcreeper_flag) ### THIS WILL PARSE OUT THE GENERATED CONFIGS FROM THE *.JINJA2 FILE TO A LIST if(len(match_node) == 0): print("+ [NO MATCHING NODES AGAINST DATABASE]") print("") elif('NO MATCH' in match_template): print("+ [NO MATCHING TEMPLATE AGAINST DATABASE]") print("") else: node_create(match_node,node_object) render(template_list,node_object,auditcreeper_flag,output,with_remediation) for index in initialize.element: redirect.append('push_cfgs') confirm(redirect,commands) print("")
def check_last_update(): """ Checks when the system was last updated. If the system was not updated for the last 2 days, updates system. """ update_path = os.getcwd() + "/Text_Files/prev_update.txt" f_update = open(update_path, 'r+') prev_date = f_update.read().strip().split("/") current_date = time.strftime("%d/%m/%Y") date = current_date.strip().split("/") if (int(date[0])-int(prev_date[0]) > 2) or \ (int(date[1])-int(prev_date[1]) > 0) or \ (int(date[2])-int(prev_date[2]) > 0): if ping() == 1: speak("Hey, I just realised that it's been a while that " \ "your system has been updated.") speak("Would you like to update system now?") reply = raw_input('\033[1m' + 'Username: '******'\033[0m') #modify if confirm(reply) == 1: speak("Please input password to update system.") os.system("sudo apt-get update && apt-get upgrade") f_update.seek(0) f_update.write(current_date) f_update.truncate() speak("System successfully updated.") else: speak("It's been a while since your system has been updated. " \ "I can't update it now, since Internet is down.") f_update.close()
def check_reminder(): """ Checks if you have any reminder set for today. """ current_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') c_year = current_date[0:4] c_month = current_date[5:7] c_date = current_date[8:10] to_del = '' reminder_path = os.getcwd() + "/Text_Files/reminder.txt" f_reminder = open(reminder_path, "r+") for line in f_reminder: r_date = line[0:2] if r_date == c_date: r_month = line[3:5] if r_month == c_month: r_year = line[6:10] if r_year == c_year: speak("You have a reminder set for today." \ "This is what it says: \n" + line[11:]) speak("Would you like me to delete the reminder now?") reply = raw_input('\033[1m' + 'Username ' + '\033[0m') #modify if confirm(reply) == 1: to_del = line #TO FINISH f_reminder.close()
def save_tag(self, val): if not CONFIRM_NEW_TAGS: return True elif confirm('Do you want to add "%s" to your tag list ?' % val, 'Confirm new tag', self): return True else: return False
def push_local(args): argument_filename = args.filename argument_node = args.node commands = initialize.configuration redirect = [] authentication = True """ :param argument_filename: Argument accepted as template name. :type augument_filename: str :param argument_node: Argument accepted as regular expression. :type augument_node: str :param commands: Referenced to global variable commands which keeps track of all commands per node. :type commands: list :param redirect: A list of which method superloop will access. This variable is sent to the multithread_engine. Each element is a redirect per node. :type alt_key_file: list """ node_object = process_nodes() match_node = search_node(argument_node, node_object) """ :param node_object: All node(s) in the database with all attributes. :type node_object: list :param match_node: Nodes that matches the arguements passed in by user. :type match_node: list """ if len(match_node) == 0: print('+ No matching node(s) found in database.') print('') else: node_element(match_node, node_object) node_create(match_node, node_object) for index in initialize.element: redirect.append('push_cfgs') for index in initialize.element: config_list = [] with open('{}/{}'.format(get_home_directory(), argument_filename), 'r') as file: init_config = file.readlines() parse_commands(node_object[index], init_config, set_notation=True) confirm(redirect, commands, authentication) return None
def fn_close_tab(): """ Closes a firefox tab. """ speak('Do you want me to close the current tab?') reply = raw_input('\033[1m' + 'Username: '******'\033[0m') #modify: Change "Username" if confirm(reply) == 1: os.system('wmctrl -a firefox; xdotool key Ctrl+w;') else: speak('Ok') return
def movienamer(movie): directory = '/'.join(movie.split('/')[:-1]) filename, extension = os.path.splitext(os.path.basename(movie)) results = identify(filename, directory) if len(results) == 0: print 'No results found. Skipping movie file\n' return False action = confirm(results, filename, extension) if action == 'SKIP': print 'Skipping movie file\n' return False elif action == 'QUIT': print 'Exiting movienamer' sys.exit() else: i = int(action) result = results[i-1] if directory == '': directory = '.' dest = (directory + '/' + result['title'] + ' [' + result['year'] + ']' + extension) if os.path.isfile(dest): print 'File already exists: ' + dest print 'Overwrite?' final_confirmation = raw_input('([y]/n/q)'.encode('utf-8')).lower() if final_confirmation == '': final_confirmation = 'y' if final_confirmation not in ['y', 'n', 'q']: final_confirmation = raw_input( '([y]/n/q)'.encode('utf-8')).lower() if final_confirmation == '': final_confirmation = 'y' if final_confirmation == 'n': print 'Skipping movie file\n' return False elif final_confirmation == 'q': print 'Exiting movienamer' sys.exit() return movie, dest
def movienamer(movie): directory = '/'.join(movie.split('/')[:-1]) filename, extension = os.path.splitext(os.path.basename(movie)) results = identify(filename, directory) if len(results) == 0: print movie + ': No results found. Skipping movie file\n' return False action = confirm(results, filename, extension) if action == 'SKIP': print 'Skipping movie file\n' return False elif action == 'QUIT': print 'Exiting movienamer' sys.exit() else: i = int(action) result = results[i - 1] if directory == '': directory = '.' title = makeValidFilename(result['title'], False, True, "", "_") dest = (directory + '/' + title + ' (' + result['year'] + ')' + extension) if os.path.isfile(dest): print 'File already exists: ' + dest print 'Overwrite?' final_confirmation = raw_input('([y]/n/q)'.encode('utf-8')).lower() if final_confirmation == '': final_confirmation = 'y' if final_confirmation not in ['y', 'n', 'q']: final_confirmation = raw_input( '([y]/n/q)'.encode('utf-8')).lower() if final_confirmation == '': final_confirmation = 'y' if final_confirmation == 'n': print 'Skipping movie file\n' return False elif final_confirmation == 'q': print 'Exiting movienamer' sys.exit() return movie, dest
def push_local(args): redirect = [] commands = initialize.configuration argument_node = args.node filename = args.filename ### NODE_OBJECT IS A LIST OF ALL THE NODES IN THE DATABASE WITH ALL ATTRIBUTES node_object = process_nodes() ### MATCH_NODE IS A LIST OF NODES THAT MATCHES THE ARGUEMENTS PASSED IN BY USER match_node = search_node(argument_node, node_object) if (len(match_node) == 0): print("+ [NO MATCHING NODES AGAINST DATABASE]") print("") else: node_element(match_node, node_object) node_create(match_node, node_object) for index in initialize.element: redirect.append('push_cfgs') home_directory = os.path.expanduser('~') for index in initialize.element: config_list = [] f = open("{}/{}".format(home_directory, filename), "r") init_config = f.readlines() parse_commands(node_object[index], init_config) confirm(redirect, commands)
def fn_write_mail(name): """ If an Internet connection is there: Checks if the given name exists in directory. If it does, asks user to write the mail, then send. Else, asks for a valid email-id. Then asks the user to write. Else quits. """ if ping() == 0: speak("Sorry. The Internet is down currently.") return counter = 0 email_path = os.getcwd() + "/Text_Files/email_id.txt" f_email = open(email_path) for line in f_email: print line name_list = line.strip().split("-") if name.lower() == ''.join(name_list[0:1]).lower(): counter = 1 email_id = ''.join(name_list[1:2]) speak("Now write the mail. Press Control+D when you are done.") os.system('mail ' + email_id) speak("The mail has been sent.") break f_email.close() if counter == 0: speak("Sorry. The name doesn't exist in the directory." "You'll have to give me the person's email address" " for me to mail him. Would you like to do that?") reply = raw_input('\033[1m' + 'Username: '******'\033[0m') #modify: Change "Username" if confirm(reply) == 1: speak("Ok. Now please enter a valid email address.") email_id = raw_input('\033[1m' + 'Username: '******'\033[0m') #modify: Change "Username" speak("Now write the mail. " "Press Control+D when you are done.") os.system('mail ' + email_id) speak("The mail has been sent.") else: speak("As you wish.")
def fn_search(word): """ Calls ping(). If success: Searches for the given sentence. """ if ping() == 0: return speak('Would you like me to search for "' + word + '"?') reply = raw_input('\033[1m' + 'Username: '******'\033[0m') #modify: Change "Username" if confirm(reply) == 1: word = word.replace(" ", "+") search_link = "www.google.co.in/#q=" + word speak('Cool. Here are the results.') os.system('guake -n CUR_DIR -e "firefox "' + search_link + '" & >/dev/null"') os.system("guake -s 1") os.system("guake -s 2 -e exit") return else: speak("As you wish.") return
# SERVERSIDE SCRIPT from confirm import confirm confirm() import pandas as pd import numpy as np from ratelimiter import RateLimiter from pymongo import MongoClient from bson.objectid import ObjectId import boto3 import pprint p = lambda x: pprint.PrettyPrinter(depth=6).pprint(x) db = MongoClient('mongodb://@54.183.229.143', 27017) # Creating DB reviews = db.project.reviews.find({}, { '_id': 1, 'review_id': 1, 'title': 1, 'content': 1 }) df = pd.DataFrame(reviews) df = df[['_id', 'review_id', 'title', 'content']]
def auditdiff(args): argument_node = args.node auditcreeper = False commands = initialize.configuration ext = '.jinja2' output = True redirect = [] with_remediation = False """ :param argument_node: Argument accepted as regular expression. :type augument_node: str :param auditcreeper: When auditcreeper is active/non-active. :type auditcreeper: bool :param commands: Referenced to global variable commands which keeps track of all commands per node. :type commands: list :param ext: File extention :type ext: str :param output: Flag to output to stdout. :type ext: bool :param redirect: A list of which method superloop will access. This variable is sent to the multithread_engine. Each element is a redirect per node. :type alt_key_file: list :param with_remediation: Current function to remediate or not remediate. :type ext: bool """ redirect.append('exec_cmd') if args.file is None: template_list = [] auditcreeper = True else: template = args.file + ext template_list = [] template_list.append(template) node_object = process_nodes() node_template = process_templates() match_node = search_node(argument_node,node_object) match_template = search_template(template_list,match_node,node_template,node_object,auditcreeper) """ :param node_object: All node(s) in the database with all attributes. :type node_object: list :param node_template: All templates based on hardware_vendor and device type. :type node_template: list :param match_node: Nodes that matches the arguements passed in by user. :type match_node: list :param match_template: Return a list of 'match' and/or 'no match'. :type match_template: list """ if len(match_node) == 0: print('+ No matching nodes found in database.') print() elif 'NO MATCH' in match_template: print() else: node_create(match_node,node_object) mediator(template_list,node_object,auditcreeper,output,with_remediation) if(len(initialize.configuration) == 0): pass else: if(remediation): confirm(redirect,commands) return None
if 'read' in filtered_sentence or \ 'unread' in filtered_sentence or \ 'check' in filtered_sentence or \ 'see' in filtered_sentence: firefox.fn_read_mail() elif filtered_sentence[-1] != 'mail': pos = filtered_sentence.index('mail') + 1 firefox.fn_write_mail(filtered_sentence[pos]) elif filtered_sentence[-1] == 'mail': speak("Whom would you like to mail?") reply = raw_input('\033[1m' + 'Username: '******'\033[0m') #modify firefox.fn_write_mail(reply) else: speak("Do you want to mail somebody?" " Then type: 'mail person's_name'") speak("Or do you want to read your emails?" "Then simply type: 'read mail'") elif 'shutdown' in filtered_sentence: speak("Would you like me to shutdown the system?") reply = raw_input('\033[1m' + 'Username: '******'\033[0m') #modify if confirm(reply) == 1: speak("Shutting down system now. Goodbye!") os.system("sudo shutdown -h now") else: speak("As you wish.") else: speak(converse(string)) return None
def tzara(string): """ Searches the input string for keywords, or commands. If keywords are found, it calls appropriate function. List of functions: (1) Open (website, pdf, folder, terminal, reminder) (2) Play (movies, songs) (3) Tell the time. (4) Google, or search for a string online. (5) Close (tab, song, movie, pdf) (6) Mail (read, send) (7) Shutdown (8) Reminder """ #Splitting each sentence in a list of words. word_list = word_tokenize(string) #Setting up stop_words: words that are redundant. stop_words = set(stopwords.words('english')) #Creating space for a list of sentences without stop_words. if "search" not in word_list and "google" not in word_list: filtered_sentence = [w for w in word_list if not w in stop_words] else: filtered_sentence = [w for w in word_list] if 'open' in filtered_sentence: #OPEN WEBSITE if 'site' in filtered_sentence: print "in function" filtered_sentence = [w for w in filtered_sentence \ if w != "called" and w != "named"] firefox.fn_open_site( \ filtered_sentence[filtered_sentence.index('site') + 1]) elif 'website' in filtered_sentence and \ filtered_sentence.index('open') \ < filtered_sentence.index('website'): firefox.fn_open_site( \ filtered_sentence[filtered_sentence.index('website') + 1]) #OPEN PDF elif 'pdf' in filtered_sentence and \ filtered_sentence.index('open') \ < filtered_sentence.index('pdf'): filtered_sentence = \ [w for w in filtered_sentence \ if w != "called" and w != "named"] fn_open_pdf(filtered_sentence[filtered_sentence.index('pdf') + 1]) #OPEN FOLDER elif 'folder' in filtered_sentence and \ filtered_sentence.index('open') \ < filtered_sentence.index('folder'): if "called" in string: pos = string.index("called") + 7 string = string[pos:] elif "named" in string: pos = string.index("named") + 6 string = string[pos:] else: pos = string.index("folder")+7 string = string[pos:] open_folder(string) #OPEN TERMINAL elif 'terminal' in filtered_sentence and \ filtered_sentence.index('open') \ < filtered_sentence.index('terminal'): terminal.terminal() #OPEN REMINDER elif 'reminder' in filtered_sentence: reminder.reminder() elif len(filtered_sentence) > 1: sites_path = os.getcwd() + "/Text_Files/comn_sites.txt" f_sites = open(sites_path, "r") for line in f_sites: name_list = line.strip().split("-") #if (n.lower()==''.join(name_list[0:1]).lower()): # counter=1 # email_id=''.join(name_list[1:2]) pos = filtered_sentence.index('open')+1 if ''.join(filtered_sentence[pos]).lower() \ in ''.join(name_list[0:1]).lower(): print ''.join(name_list[1:2]) firefox.fn_open_site(''.join(name_list[1:2])) f_sites.close() else: speak("You want me to open something," "but I'm not sure what. Could you please repeat?") elif 'terminal' in filtered_sentence: speak("Would you like me to open the terminal for you?") reply = raw_input('\033[1m'+'Username: '******'\033[0m') #modify if confirm(reply) == 1: terminal.terminal() else: speak("As you wish.") elif 'movie' in filtered_sentence: #PLAY MOVIE filtered_sentence = [w for w in filtered_sentence \ if w != "called" and w != "named" and w != "titled"] pos = filtered_sentence.index('movie') + 1 fn_movie(filtered_sentence[pos]) #PLAY SONG elif 'song' in filtered_sentence and filtered_sentence.index('play') \ < filtered_sentence.index('song'): filtered_sentence = [w for w in filtered_sentence \ if w != "called" and w != "named" and w != "titled"] pos = filtered_sentence.index('song') + 1 fn_play_song(filtered_sentence[pos]) elif 'time' in filtered_sentence: speak(time.strftime("%A") + " " \ + str(datetime.datetime.now())[:16]) elif 'google' in filtered_sentence: if len(filtered_sentence) > 1: pos = filtered_sentence.index('google') + 1 if 'word' in filtered_sentence \ and filtered_sentence[-1] != 'word': filtered_sentence = \ [w for w in filtered_sentence if w != "word"] search_string = ''.join(filtered_sentence[pos:]) firefox.fn_search(search_string) else: speak("If you want me to open google, say 'open google'") speak("If you want me to search for a word," "say 'google <word>'") elif 'search' in filtered_sentence: if filtered_sentence[-1] == "search": speak("Enter the word you would like me to search.") search_string = raw_input('\033[1m' + 'Username: '******'\033[0m') #modify firefox.fn_search(search_string) return pos = filtered_sentence.index('search') + 1 search_string = " ".join(filtered_sentence[pos:]) firefox.fn_search(search_string) elif 'reminder' in filtered_sentence: speak("Opening reminder") reminder.reminder() elif 'close' in filtered_sentence: if 'tab' in filtered_sentence: firefox.fn_close_tab() speak('There you go!') if 'song' in filtered_sentence: fn_close_song() if 'movie' in filtered_sentence: fn_close_movie() if 'pdf' in filtered_sentence: fn_close_pdf() else: speak("I figure you want me to close something," "but I'm not sure what!") elif 'ping' in filtered_sentence: firefox.ping() elif 'mail' in filtered_sentence: if 'read' in filtered_sentence or \ 'unread' in filtered_sentence or \ 'check' in filtered_sentence or \ 'see' in filtered_sentence: firefox.fn_read_mail() elif filtered_sentence[-1] != 'mail': pos = filtered_sentence.index('mail') + 1 firefox.fn_write_mail(filtered_sentence[pos]) elif filtered_sentence[-1] == 'mail': speak("Whom would you like to mail?") reply = raw_input('\033[1m' + 'Username: '******'\033[0m') #modify firefox.fn_write_mail(reply) else: speak("Do you want to mail somebody?" " Then type: 'mail person's_name'") speak("Or do you want to read your emails?" "Then simply type: 'read mail'") elif 'shutdown' in filtered_sentence: speak("Would you like me to shutdown the system?") reply = raw_input('\033[1m' + 'Username: '******'\033[0m') #modify if confirm(reply) == 1: speak("Shutting down system now. Goodbye!") os.system("sudo shutdown -h now") else: speak("As you wish.") else: speak(converse(string)) return None
def confirmed_move(self,ra,dec): self.x += ra self.y += dec self.move(ra,dec) while confirm('Is position at %d,%d'%(self.x,self.y),resp=True) == False: self.move(ra,dec)
def main(): curve = ellipticCurve( q= 0x01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409, a= 0x01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC, b= 0x0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00, p=2**521 - 1) ''' curve = ellipticCurve(a=0x340E7BE2A280EB74E2BE61BADA745D97E8F7C300,b=0x1E589A8595423412134FAA2DBDEC95C8D8675E58,p=0xE95E4A5F737059DC60DFC7AD95B3D8139515620F , q=0xE95E4A5F737059DC60DF5991D45029409E60FC09) ''' temp = 'D4-6D-6D-A0-96-B4'.replace('-', '') alice = binascii.unhexlify(temp) print(alice) temp = '00-FF-F4-EF-53-FE'.replace('-', '') bob = binascii.unhexlify(temp) print(bob) password = '******'.encode() print(password) PE = hunting_and_pecking_with_ecc(curve, alice, bob, password) alice_scalar, alice_element, alice_private = createPrivateAndMask(PE) bob_scalar, bob_element, bob_private = createPrivateAndMask(PE) #ellipticCurvePoint(10, 13, curve) #ここから鍵交換プロトコルを使う temp1 = PE.mul(bob_scalar) temp2 = temp1.add(bob_element) temp3 = temp2.mul(alice_private) #print(temp1, temp2, temp3) #print("temp3.x =",temp3.x) alice_ss = (temp3.x).to_bytes(math.ceil(math.log2(temp3.x) / 8), 'big') #alice_ss = hex((PE.mul(bob_scalar).add(bob_element).mul(alice_private)).x) print("alice_ss =", alice_ss) temp1 = PE.mul(alice_scalar) temp2 = temp1.add(alice_element) temp3 = temp2.mul(bob_private) #print(temp1, temp2, temp3) #print("temp3.x =",temp3.x) bob_ss = (temp3.x).to_bytes(math.ceil(math.log2(temp3.x) / 8), 'big') print("bob_ss = ", bob_ss) # commit ## alice n = len(list(map(int, format(PE.curve.p, "b")))) * 2 temp = hashlib.shake_256(alice_ss + b'Dragonfly Key Derivation').hexdigest(512) alice_kck = temp[0:256] alice_mk = temp[256:512] print("alice_kck =", alice_kck) print("alice_mk =", alice_mk) ## bob temp = hashlib.shake_256(bob_ss + b"Dragonfly Key Derivation").hexdigest(512) bob_kck = temp[0:256] bob_mk = temp[256:512] print("bob_kck =", bob_kck) print("bob_mk =", bob_mk) assert (alice_kck == bob_kck) #交換する前に自分のconfirmの値を求める ##alice側 alice_confirm = confirm(alice_scalar, bob_scalar, alice_element, bob_element, alice_kck, alice) ##bob側 bob_confirm = confirm(bob_scalar, alice_scalar, bob_element, alice_element, bob_kck, bob) #交換して,相手のconfirmの値が正しいか検証する ##alice側 bob_confirm_expected = confirm(bob_scalar, alice_scalar, bob_element, alice_element, bob_kck, bob) ##bob側 alice_confirm_expected = confirm(alice_scalar, bob_scalar, alice_element, bob_element, alice_kck, alice) #それぞれで計算結果と送られてきた結果を比較 ##alice側 if bob_confirm == bob_confirm_expected: print("alice: confirm successed") ##bob側 if alice_confirm == alice_confirm_expected: print("bob: confirm successed") data = "@elliptic_shiho" print("data =", data) #bob側 ciphertext, iv = encrypt(bob_mk[0:32].encode(), data) #alice側 plaintext = decrypt(alice_mk[0:32].encode(), ciphertext, iv) print("enc_data =", plaintext.decode()) data = "㍾㍽㍼㍻㋿(⋈◍>◡<◍)。✧♡💗😻💑💕🌠🌟🔥" print("data =", data) #alice側 ciphertext, iv = encrypt(alice_mk[0:32].encode(), data) #bob側 plaintext = decrypt(bob_mk[0:32].encode(), ciphertext, iv) print("enc_data =", plaintext.decode())
def push_cfgs(args): argument_node = args.node auditcreeper = False commands = initialize.configuration ext = '.jinja2' output = False redirect = [] push_cfgs = False with_remediation = True authentication = False """ :param argument_node: Argument accepted as regular expression. :type augument_node: str :param auditcreeper: When auditcreeper is active/non-active. :type auditcreeper: bool :param commands: Referenced to global variable commands which keeps track of all commands per node. :type commands: list :param ext: File extention :type ext: str :param output: Flag to output to stdout. :type ext: bool :param redirect: A list of which method superloop will access. This variable is sent to the multithread_engine. Each element is a redirect per node. :type alt_key_file: list :param push_cfgs: This flag is to determine if a push is required for Cisco like platforms. Juniper will continue to push configs no matter if there are no diffs. :type ext: bool :param with_remediation: Current function to remediate or not remediate. :type ext: bool """ if(args.file is None): template_list = [] auditcreeper = True else: template = args.file + ext template_list = [] template_list.append(template) node_object = process_nodes() node_template = process_templates() match_node = search_node(argument_node,node_object) match_template = search_template(template_list,match_node,node_template,node_object,auditcreeper) """ :param node_object: All node(s) in the database with all attributes. :type node_object: list :param node_template: All templates based on hardware_vendor and device type. :type node_template: list :param match_node: Nodes that matches the arguements passed in by user. :type match_node: list :param match_template: Return a list of 'match' and/or 'no match'. :type match_template: list """ if len(match_node) == 0: print('+ No matching node(s) found in database.') print('') elif 'NO MATCH' in match_template: print('+ No matching template(s) found in database.') print('') else: node_create(match_node,node_object) for index in initialize.element: if node_object[index]['hardware_vendor'] == 'cisco': get_diff = True break if get_diff: mediator(template_list,node_object,auditcreeper,output,with_remediation) else: render(template_list,node_object,auditcreeper,output,with_remediation) for index in initialize.element: redirect.append('push_cfgs') for index in range(len(initialize.element)): if len(commands[index]) != 0: push_cfgs = True break else: push_cfgs = False if push_cfgs: confirm(redirect,commands,authentication) print('') return None
caseCluster = clus # Get cluster object clusterRequest = requests.get(caseCluster, headers=headers) parsedCluster = clusterRequest.json() # Get cluster year caseDate = parsedCluster['date_filed'] caseYear = datetime.datetime.strptime(caseDate, '%Y-%m-%d') caseYear = caseYear.year caseYear = str(caseYear) # Display citation output = '\nThe following information will be added to Google Sheets:' output += '\n\npdf#:\n' + pdf_id output += '\n\nDocket #:\n' + caseDocket output += '\n\nYear:\n' + caseYear output += '\n\nCase citation (Bluebook):\n' + caseName output += '\n\nFull Case Name:\n' + caseFull output += '\n' print(output) if confirm() is False: print('\nNo data was added to Google Sheets\n') exit() else: gSheets(pdf_id, caseDocket, caseYear, caseName, caseFull) print('\nThe data was added to Google Sheets\n') exit()