Example #1
0
 def __do_js(self, event):
     self.__vertexes.clear()
     self.__canvas.delete("all")
     self.__draw_points()
     if len(self.__points) < 3:
         return
     js = Jarvis(self.__points, self.__canvas.winfo_height())
     self.__vertexes = js.solver()
     self.__draw_lines()
Example #2
0
	def __init__(self):
		self.arpmode = "rep"
		self.Jarvis = Jarvis()
		self.targets = None
		self.file = None
		self.interface = None
		self.gateway = None
		self.status = 0
Example #3
0
    def start_server(self):
        print("Starting a thread for home server!")

        from main import build_plugin_manager
        plugin_manager = build_plugin_manager()
        language_parser = snips.LanguageParser()
        jarvis_server = JarvisServer()
        self.io = ServerIO()

        self.jarvis = Jarvis(language_parser, plugin_manager, jarvis_server)
        self.jarvis.register_io(self.io)

        self.server_app.run(host=self.host_name,
                            port=self.port,
                            threaded=True,
                            debug=True,
                            use_reloader=False)
Example #4
0
    def __init__(self):
        super(UI, self).__init__()
        self.pepper = None
        self.stop_words = []
        self.top_k = 5

        # Initialize Jarvis
        self.jarvis = Jarvis(stop_words = self.stop_words)
Example #5
0
def run_loop():   #function looped that recognizes speech
    r = sr.Recognizer()   # r is the recognizer object
    with sr.Microphone() as source:   # while there is a microphone source listen for input
        while True:
            logger.debug("Waiting for user input.")
            audio = r.listen(source) #gets speech and stores it in audio object

            logger.debug("Performing Speach to text.")

            try:
                result = r.recognize_google(audio,key=None)  # speech recognition result
                Jarvis.handle(result) #sends result to Jarvis.py for handling
            except sr.UnknownValueError:  # Error handling
                logger.debug("Could not understand audio")
            except sr.RequestError as e:  # Error with api
                logger.warn("Could not fetch results from speech to text: " + str(e))
            except Exception as e: # Error Handling
                logger.error("Error processing: " + str(e))
Example #6
0
class Main(object):
    def __init__(self, gid=TEST_GROUP_ID):
        data = json.load(open("creds.json", 'r'))
        self.jarvis = Jarvis(data['id'], data['password'], gid)

    def get_movers(self):
        url = "https://apidojo-yahoo-finance-v1.p.rapidapi.com/market/v2/get-movers"
        resp = requests.request("GET", url, headers=HEADERS, params=QUERRY_STRING).json()
        gainers = resp["finance"]["result"][0]["quotes"]
        string = "TOP Gainers: \n"
        for item in gainers:
            string += "%s\n" % item["symbol"]

        losers = resp["finance"]["result"][1]["quotes"]
        string += "-------------------\n"
        string += "TOP Losers: \n"
        for item in losers:
            string += "%s\n" % item["symbol"]
        print("Sending notification about top movers")
        self.jarvis.send_message(string)
Example #7
0
def main_cli():
    from ui.cmd_interpreter import CmdInterpreter
    from language import snips

    language_parser = snips.LanguageParser()
    plugin_manager = build_plugin_manager()
    jarvis_server = server.JarvisServer()
    jarvis = Jarvis(language_parser, plugin_manager, jarvis_server)
    cmd_interpreter = CmdInterpreter(jarvis)

    command = " ".join(sys.argv[1:]).strip()
    cmd_interpreter.executor(command)
Example #8
0
def run_transcription_loop():
    # Most of this code taken from https://github.com/Uberi/speech_recognition/blob/master/examples/microphone_recognition.py.
    r = sr.Recognizer()
    with sr.Microphone() as source:

        while True:
            logger.debug("Awaiting user input.")
            audio = r.listen(source)

            logger.debug("Attempting to transcribe user input.")

            try:
                result = r.recognize_google(audio,
                                            key=GOOGLE_SPEECH_RECOGNITION_API_KEY)
                Jarvis.handle_action(result)
            except sr.UnknownValueError:
                logger.debug("Google Speech Recognition could not understand audio")
            except sr.RequestError as e:
                logger.warn("Could not request results from Google Speech Recognition service: %s", e)
            except Exception as e:
                logger.error("Could not process text: %s", e)
Example #9
0
    def __init__(self):
        #Jarvis
        self.Jarvis = Jarvis()

        #Variables
        self.targets = None
        self.file = None
        self.interface = None
        self.gateway = None
        self.port = 80
        self.domain = None
        self.redirect = None
        self.script = None
        self.filter = None
        self.arpmode = "rep"

        #Status manager
        self.jarvis_status = 0
        self.arpspoof_status = False
        self.inject_status = False
        self.dnsspoof_status = False
        self.mitmdrop_status = 0
Example #10
0
def main():
    """
    Basic loop, listen and execute.
    """
    bot = Jarvis()
    bot.say(f"Hello, {parameters.NAME}.")

    is_running = True
    while is_running:
        phrase = bot.listen()
        bot.process(phrase.lower())
Example #11
0
	def __init__(self):
		self.arpmode = "rep"
		self.Jarvis = Jarvis()
		self.targets = None
		self.file = None
		self.interface = None
		self.gateway = None
		self.status = 0
		self.dnsstat = 0
		#will need to add a set and print, utils and wiki commands reference too
		self.port = 80
		self.domain = None
		self.redirect = None
		self.script = None
Example #12
0
def run_transcription_loop():
    # Most of this code taken from https://github.com/Uberi/speech_recognition/blob/master/examples/microphone_recognition.py.
    r = sr.Recognizer()
    with sr.Microphone() as source:
        
        while True:
            logger.debug("Awaiting user input.")
            r.adjust_for_ambient_noise(source)
            audio = r.listen(source)

            logger.debug("Attempting to transcribe user input.")

            try:
                """result = r.recognize_sphinx(audio)"""
                result = r.recognize_google(audio,
                                            key=GOOGLE_SPEECH_RECOGNITION_API_KEY)
                Jarvis.handle_action(result)
            except sr.UnknownValueError:
                logger.debug("Google Speech Recognition could not understand audio")
            except sr.RequestError as e:
                logger.warn("Could not request results from Google Speech Recognition service: %s", e)
            except Exception as e:
                logger.error("Could not process text: %s", e)
Example #13
0
def main_gui():
    from ui.gui.application import JarvisApp
    from kivy.utils import platform

    if platform == 'android':
        import ui.gui.android_plugins
        plugin_manager = ui.gui.android_plugins.build_plugin_manager()
    else:
        plugin_manager = build_plugin_manager()

    language_parser = default.DefaultLanguageParser()
    jarvis_server = server.JarvisServer()
    jarvis = Jarvis(language_parser, plugin_manager, jarvis_server)
    jarvis_gui = JarvisApp(jarvis)

    jarvis_gui.run()
Example #14
0
	def __init__(self):
		#Jarvis
		self.Jarvis = Jarvis()

		#Variables
		self.targets = None
		self.file = None
		self.interface = None
		self.gateway = None
		self.port = 80
		self.domain = None
		self.redirect = None
		self.script = None
		self.arpmode = "rep"

		#Status manager
		self.jarvis_status = 0
		self.arpspoof_status = False
		self.inject_status = False
		self.dnsspoof_status = False
		self.mitmdrop_status = 0
Example #15
0
class Processor(object):

	def __init__(self):
		self.Jarvis = Jarvis()

	def start(self):
		try:
			self.Jarvis.ser.open()

		except Exception as e:
			print "[!] Arduino Leonardo not found, features that use keyboard will not work."

		try:
			self.Jarvis.Say(self.Jarvis.random('greetings'))
			while 1:
				try:
					self.command = self.Jarvis.Listen()
       		        		self.message = self.command.split()
        			        self.input_list = [str(a) for a in self.message]
					if self.input_list[0] == "exit" or self.input_list[0] == "quit":
						self.Jarvis.Say(self.Jarvis.random('salutes'))
						exit()

					elif self.input_list[0] == "sleep" or self.input_list[0] == "stop" or self.input_list[0] == "wait":
						self.Jarvis.Say("Call me if you need me sir.")
						while 1:
							self.wait = self.Jarvis.Listen()
							if self.wait == "Jarvis":
								self.Jarvis.Say(self.Jarvis.random('affirmative'))
								break

					elif self.input_list[0] == "newspaper" or self.input_list[0] == "news":
						self.Jarvis.Say("Here are the news sir.")
						self.titles = self.Jarvis.GetNews()
						self.Jarvis.SpeakNews(self.titles)

					elif self.input_list[0] == "browser":
						try:
							webbrowser.open("https://www.google.com")
							self.Jarvis.Say(self.Jarvis.random('affirmative'))
						except Exception as e:
							print "[!] Exception caught: {}".format(e)
							pass

					elif self.input_list[0] == "terminal":
						try:
							os.system("gnome-terminal")
							self.Jarvis.Say(self.Jarvis.random('affirmative'))
						except Exception as e:
							print "[!] Exception caught: {}".format(e)
							pass

					elif self.input_list[0] == "search":
						try:
							search = self.input_list[1:]
							real = "".join(search)
							url = "https://www.google.com/search?q={}".format(real)
							webbrowser.open(url)
							self.Jarvis.Say(self.Jarvis.random('affirmative'))
						except Exception as e:
							print "[!] Exception caught: {}".format(e)
							pass

					elif self.input_list[0] == "say" or self.input_list[0] == "speak":
						self.Jarvis.Say(self.input_list[1:])

					elif self.input_list[0] == "run":
						self.Jarvis.Say(self.Jarvis.random('affirmative'))
						os.system("./scripts/{}.sh".format(self.input_list[1]))

					elif self.input_list[0] == "input":
                                                try:
                                                        self.Jarvis.SerialWrite(self.input_list[1])
                                                        self.Jarvis.Say(self.Jarvis.random('affirmative'))
                                                except:
                                                        self.Jarvis.Say("Feature not working master, plug your Arduino Leonardo then restart the program.")
                                                        pass

					elif self.input_list[0] == "editor":
						self.Jarvis.Say("Starting edition mode sir.")
                                	        while 1:
                                     			self.editmode = self.Jarvis.Listen()
                                     	 		self.mesg = self.editmode
                                       	 	        #self.msg = "".join(self.mesg)

                                       	        	if self.mesg is not None:
								try:
									self.Jarvis.SerialWrite(self.mesg)
                                       	        			self.Jarvis.Say(self.Jarvis.random('affirmative'))
								except:
									self.Jarvis.Say("Feature not working, plug you Arduino Leonardo then restart the program.")
									break
                                                	else:
								pass
							if self.editmode == "exit":
                                                        	self.Jarvis.Say("Stoping edition mode sir.")
								break

					else:
                       				print '[!] Input a valid option, enter "help" to see valid commands.'
						self.Jarvis.Say("i heard, {}".format(self.command))
						self.Jarvis.Say(self.Jarvis.random('dntunderstand'))


				except IndexError:
					pass
				except AttributeError:
					pass


		except KeyboardInterrupt:
			print "\n[*] User requested shutdown"
			self.Jarvis.Say(self.Jarvis.random('salutes'))
			exit()
		except Exception as e:
			print "[!] Exception caught: {}".format(e)
Example #16
0
    def setUp(self):
        from jarvis import Jarvis

        self.he = Jarvis()
Example #17
0
class Processor(object):

	def __init__(self, version):
		self.version = version
		self.arpmode = "rep"
		self.Jarvis = Jarvis()
		self.targets = None
		self.file = None
		self.interface = None
		self.gateway = None
		self.status = 0

	def start(self):
		try:
			while 1:
				self.command = raw_input("pythem> ")
				self.argv = self.command.split()
				self.input_list = [str(a) for a in self.argv]
				try:


					if self.command == "help":
						print_help(self.version)

					elif self.command == "jarvis-help":
						jarvis_help(self.Jarvis.version)

					elif self.command == "jarvis":
						self.Jarvis.start('core/processor.py')
						self.status = 1

					elif self.input_list[0] == "jarvis-log":
						try:
							jarvislog = self.input_list[1]
							try:
								os.system("tail -f log/jarvis{}.txt".format(jarvislog))
							except Exception as e:
								print "[!] Exception caught: {}".format(e)
								pass

						except IndexError:
							print "[+] Jarvis log system."
							print "[.] Error log  - type: err"
							print "[.] Output log - type: out"
							jarvislog = raw_input("[+] Select: ")
							try:
								os.system("tail -f log/jarvis{}.txt".format(jarvislog))
							except Exception as e:
								print "[!] Exception caught: {}".format(e)
								pass

					elif self.command == "exit" or self.command == "quit":
						if self.status == 1:
							self.Jarvis.Say(self.Jarvis.random('salutes'))
							self.Jarvis.stop()
							exit()
						else:
							exit()

					elif self.input_list[0] == "jarvis-say":
						try:
							message = self.input_list[1]
							all_msg = " ".join(self.input_list[1:])
							self.Jarvis.Say(all_msg)
						except IndexError:
							message = raw_input("[+] Jarvis speaker: ")
							self.Jarvis.Say(message)
						except KeyboardInterrupt:
							pass
						except Exception as e:
							print "[!] Exception caught: {}".format(e)

					elif self.input_list[0] == "jarvis-read":
						try:
							file = self.input_list[1]
							self.Jarvis.Read(file)
						except IndexError:
							if self.file is not None:
								self.Jarvis.Read(self.file)
							else:
								file = "[+] Set file path:"
								pass
                                                except TypeError:
                                                	print "[!] You probably forgot to set a wordlist file path."
                                                        pass
						except KeyboardInterrupt:
							pass
						except Exception as e:
							print "[!] Exception caught: {}".format(e)

					elif self.input_list[0] == "set" or self.input_list[0] == "SET":
						if self.input_list[1] == "interface":
							try:
								self.interface = self.input_list[2]
							except IndexError:
								try:
									self.interface = raw_input("[+] Enter the interface: ")
								except KeyboardInterrupt:
									pass
						elif self.input_list[1] == "gateway":
							try:
								self.gateway = self.input_list[2]
							except IndexError:
								try:
									self.gateway = raw_input("[+] Enter the gateway: ")
								except KeyboardInterrupt:
									pass
						elif self.input_list[1] == "target":
							try:
								self.targets = self.input_list[2]
							except IndexError:
								try:
									self.targets = raw_input("[+] Enter the target(s): ")
								except KeyboardInterrupt:
									pass
						elif self.input_list[1] == "file":
							try:
								self.file = self.input_list[2]
							except IndexError:
								try:
									self.file = raw_input("[+] Enter the path to the file: ")
								except KeyboardInterrupt:
									pass
						elif self.input_list[1] == "arpmode":
							try:
								self.arpmode = self.input_list[2]
							except IndexError:
								try:
									self.arpmode = raw_input("[+] Enter the arpmode:")
								except KeyboardInterrupt:
									pass


					elif self.input_list[0] == "print":
						if self.input_list[1] == "interface":
							print "[+] Network Interface: {}".format(self.interface)
						elif self.input_list[1] == "gateway":
							print "[+] Gateway IP Address: {}".format(self.gateway)
						elif self.input_list[1] == "target":
							print "[+] Target(s): {}".format(self.targets)
						elif self.input_list[1] == "file":
							print "[+] File path: {}".format(self.file)
						elif self.input_list[1] == "arpmode":
							print "[+] ARP spoofing mode: {}".format(self.arpmode)
						else:
							print "[-] Select a valid variable name."

					elif self.input_list[0] == "scan":
						try:
							mode = self.input_list[1]
							if self.targets is not None and self.interface is not None:
								from modules.scanner import Scanner
								self.scan = Scanner(self.targets, self.interface, mode)
								self.scan.start()
							else:
								print "[!] You probably forgot to set the interface or a valid IP address/range."


						except IndexError:
							print "[*] Select one scan mode, options = tcp/arp/manual"
							mode = raw_input("[+] Scan mode: ")
							if self.targets is not None and self.interface is not None:
								from modules.scanner import Scanner
								self.scan = Scanner(self.targets, self.interface, mode)
								self.scan.start()
							else:
								print "[!] You probably forgot to set the interface or a valid IP address/range."
								pass
						except KeyboardInterrupt:
							pass
						except Exception as e:
							print "[!] Exception caught: {}".format(e)
							pass

					elif self.input_list[0] == "arpspoof":
                                        	try:
							myip = get_myip(self.interface)
                                                	mymac = get_mymac(self.interface)
                                                	from modules.arpoisoner import ARPspoof
							self.spoof = ARPspoof(self.gateway, self.targets, self.interface,self.arpmode ,myip, mymac)

							if self.input_list[1] == "start":
								self.spoof.start()
								print "[+] ARP spoofing initialized."

							elif self.input_list[1] == "stop":
								self.spoof.stop()
								print "[+] ARP spoofing finalized."

							else:
								print "[!] Select a valid option, call help to check syntax."
						
						except TypeError:
							print "[!] You probably forgot to set interface or gateway."
						except IndexError:
							print "[!] You probably forgot to type start or stop after arpspoof."
						except AttributeError:
							pass
						except Exception as e:
							print "[!] Exception caught: {}".format(e)

					elif self.input_list[0] == "dnsspoof":
						try:

							if self.input_list[1] == "start":
								domain = raw_input("[+] Domain to be spoofed: ")
								redirect = raw_input("[+] IP address to be redirected: ")
								from modules.dnspoisoner import DNSspoof
								self.dnsspoof = DNSspoof(domain, redirect)
								self.dnsspoof.start()
								print "[+] DNS spoofing initialized"

							elif self.input_list[1] == "stop":
								self.dnsspoof.stop()
								print "[+] DNS spoofing finalized"
							else:
								print "[!] Select a valid option, call help to check syntax."
						except IndexError:
							print "[!] You probably forgot to type start or stop after dnsspoof."
						except Exception as e:
							print "[!] Exception caught: {}".format(e)

					elif self.input_list[0] == "sniff":
						from modules.sniffer import Sniffer
						try:
							filter = self.input_list[1:]
							self.sniff = Sniffer(self.interface, filter)
							self.sniff.start()
						except IndexError:
							filter = raw_input("[+] Enter the filter: ")
                                                	self.sniff = Sniffer(self.interface, filter)
                                                	self.sniff.start()
						except KeyboardInterrupt:
                                                	pass

					elif self.command == "pforensic":
						try:
							from modules.pforensic import PcapReader
							self.pcapread = PcapReader(self.file)
							self.pcapread.start()
						except KeyboardInterrupt:
							pass
						except TypeError:
							print "[!] You probably forgot to set the .pcap file"
							pass
						except Exception as e:
							print "[!] Exception caught: {}".format(e)
							pass

					elif self.input_list[0] == "fuzz":
						try:
							from modules.fuzzer import SimpleFuzz
							if self.targets is not None and self.file is None:
								self.fuzz = SimpleFuzz(self.targets,self.input_list[1])
							elif self.file is not None and self.targets is None:
								self.fuzz = SimpleFuzz(self.file,self.input_list[1])
							else:
								print "[!] You need to specify after fuzz with a argument:"
								print "[.] tcp (remember to set target) or stdin (remember to set file path with ./)"
						except KeyboardInterrupt:
							pass

					elif self.command == "cookiedecode":
						try:
							cookiedecode()
						except KeyboardInterrupt:
							pass
						except Exception as e:
							print "[!] Exception caught: {}".format(e)
							pass



					elif self.input_list[0] == "decode":
						try:
							print decode(self.input_list[1])
						except KeyboardInterrupt:
							pass


					elif self.input_list[0] == "encode":
						try:
							print encode(self.input_list[1])
						except KeyboardInterrupt:
							pass


					elif self.input_list[0] == "geoip":
						try:
							self.targets = self.input_list[1]
							from modules.geoip import Geoip
							path = "config/GeoLiteCity.dat"
							iptracker = Geoip(self.targets,path)

						except IndexError:
							if self.targets is not None:
								from modules.geoip import Geoip
								path = "config/GeoLiteCity.dat"
								iptracker = Geoip(self.targets,path)
							else:
								print "[!] You probably forgot to set a target"

						except Exception as e:
								print "[!] Exception caught: {}".format(e)
								pass

					elif self.input_list[0] == "brute-force":
							if self.input_list[1] == "ssh":
								try:
									username = raw_input("[+] Enter the username to bruteforce: ")
									from modules.ssh_bruter import SSHbrutus
									brutus = SSHbrutus(self.targets, username, self.file)
									brutus.start()
                                                		except KeyboardInterrupt:
                                                        		brutus.stop()
									pass
                                                		except TypeError:
                                                        		print "[!] You probably forgot to set the wordlist file path."
                                                       			pass
							elif self.input_list[1] == "url":
								try:
									url = 'url'
									from modules.web_bruter import WEBbrutus
									brutus = WEBbrutus(self.targets, self.file)
									brutus.start(url)
								except KeyboardInterrupt:
									brutus.stop(url)
									pass
								except TypeError:
			                                      		print "[!] You probably forgot to set the wordlist file path."
									pass
							elif self.input_list[1] == "webform":
								try:
									form = 'form'
									from modules.web_bruter import WEBbrutus
									brutus = WEBbrutus(self.targets, self.file)
									brutus.start(form)
								except KeyboardInterrupt:
									brutus.stop(form)
									pass
								except TypeError:
		                                            		print "[!] You probably forgot to set the wordlist file path."
									pass
							else:
								print "[!] Select a valid type of brute-force type help to check."
					else:
						try:
							os.system("{}".format(self.command))
							pass
						except Exception as e:
							print "[!] Select a valid option, type help to check sintax."
							pass
				except IndexError:
					pass

				except Exception as e:
					print "Exception caught: {}".format(e)



		except KeyboardInterrupt:
			print "\n[*] User requested shutdown."
			exit()
Example #18
0
def run(mother):
    category = mother.categories['Study']
    all_studies = set()
    status = {}
    has_status = set()
    missing_status = set()
    missing_jarvis = set()
    jarvis_ids = set()

    for page in category:
        logging.debug("Checking study", page.name)
        all_studies.add(page.name)
        text = page.text()
        p = mwparserfromhell.parse(text)
        template = study_template(p)
        if template:
            if template.has("Study Status"):
                s = template.get("Study Status").value.strip()
                if s == "": continue
                words = re.split(r',\s*', s)
                for c in words:
                    status[c] = status.get(c, set())
                    status[c].add(page.name)
                    has_status.add(page.name)

            if not template.has("JARVIS ID") or \
                template.get("JARVIS ID").value.strip() == "":
                missing_jarvis.add(page.name)
            else:
                jarvis_ids.add(int(template.get("JARVIS ID").value.strip()))

        if not page.name in has_status:
            missing_status.add(page.name)

    logging.debug("Got status: ", status)

    # Now statuses contains a hash of construct -> list of pages.
    # NOTE: This re-uses MediaWiki's category CSS classes to get three-column display. Maybe weird to do that?
    oldtext = category.text()
    cat = mwparserfromhell.parse(oldtext)
    sections = cat.get_sections()
    title = "== Sorted by Study Status =="
    newtext = title + "\n\nPlease note: this section is created automatically based on the status in each study's infobox. To edit, go to the study's page and choose 'Edit with form'.\n\n"
    newtext += "<div class='mw-category'>"

    # Build up an index by status
    # Sort by certain rules
    sort_order = [
        "In Development", "Piloting", "Collecting", "Data Collection Complete",
        "Analyzing", "Publishing", "IRB Closed"
    ]
    for k in sort_order:
        if not k in status:
            continue
        newtext += "<div class='mw-category-group'><h3>" + k + "</h3>\n"
        for study in sorted(list(status[k])):
            newtext += "* [[" + study + "]]\n"
        newtext += "</div>"

    # List out things that are missing statuses
    newtext += "<div class='mw-category-group'><h3>No statuses listed</h3>\n"
    for m in missing_status:
        newtext += "* [[" + m + "]]\n"
    newtext += "</div>"

    newtext += "</div>\n\n"

    # Replace the "Sorted by Study Status" section with our new text
    old_section = cat.get_sections(matches="Sorted by Study Status")[0]
    cat.replace(old_section, newtext)
    newpage = str(cat)

    if oldtext != newpage:
        logging.warning("Updating study category page, change detected")
        category.save(
            newpage,
            "Automated edit to build status categories on study library")

    # Now we use the statuses and dates we pulled to edit the "missing Jarvis" and "studies not edited for the longest"
    missing = mother.pages['Study pages missing JARVIS IDs']
    oldtext = missing.text()
    newpage = "This page is automatically generated. See also [[JARVIS IDs missing study pages]]\n\n"
    newpage += "== Pages missing JARVIS IDs ==\n\n"
    for page in sorted(missing_jarvis):
        newpage += f"* [[{page}]]\n"

    if oldtext != newpage:
        logging.warning("Updating missing JARVIS IDs page, change detected")
        missing.save(newpage, "Automated edit")

    # Now we build the opposite thing
    missing = mother.pages['JARVIS IDs missing study pages']
    oldtext = missing.text()
    newpage = "This page is automatically generated and only includes more recent entries in JARVIS. See also [[Study pages missing JARVIS IDs]]\n\n"
    newpage += "== JARVIS IDs missing study pages ==\n\n"

    j = Jarvis()
    all_studies = j.select(
        "SELECT id, folder, name, created_at FROM studies ORDER BY created_at DESC LIMIT 30"
    )
    for s in all_studies:
        jarvis_id, folder, name, created_at = s
        if not jarvis_id in jarvis_ids:
            newpage += f"* ID {jarvis_id} in /study/{folder}: \"{name}\" (created at {created_at})\n"

    if oldtext != newpage:
        logging.warning("Updating missing study pages page, change detected")
        missing.save(newpage, "Automated edit")
Example #19
0
class JarvisTest(unittest.TestCase):
    def setUp(self):
        from jarvis import Jarvis

        self.he = Jarvis()

    def _word_database_builder(self):
        from database import WordDataBaseBuilder

        db_builder = WordDataBaseBuilder()
        db_builder.addTxtFile("sample.txt")

        return db_builder

    def _traning_database_builder(self):
        from database import TrainingDataBaseBuilder

        builder = TrainingDataBaseBuilder()
        builder.addTxtFile("traning_sample.txt")

        return builder

    def _abilities_builder(self):
        from database import AbilitiesDataBaseBuilder

        return AbilitiesDataBaseBuilder()

    def _innervoice_builder(self):
        from database import InnerVoiceDataBaseBuilder

        return InnerVoiceDataBaseBuilder()

    def test_dictionary(self):
        self.he.createWordsDataBase(self._word_database_builder())

    def test_respond_exception(self):
        from jarvis import JarvisException

        with self.assertRaises(JarvisException):
            self.he.respond("aaa bbb ccc")

    def test_respond_exception2(self):
        from jarvis import JarvisException

        self.he.createWordsDataBase(self._word_database_builder())

        with self.assertRaises(JarvisException):
            self.he.respond("aaa bbb ccc www")

    def test_createAbilitiesDataBase(self):
        self.he.createAbilitiesDataBase(self._abilities_builder())

    def test_train_exception(self):
        from jarvis import JarvisException

        with self.assertRaises(JarvisException):
            self.he.train()

    def test_train(self):
        self.he.createWordsDataBase(self._word_database_builder())
        self.he.createTrainingDataBase(self._traning_database_builder())
        self.he.train()

    def test_respond(self):
        self.he.createWordsDataBase(self._word_database_builder())
        self.he.createTrainingDataBase(self._traning_database_builder())
        self.he.createAbilitiesDataBase(self._abilities_builder())
        self.he.train()

        answer = self.he.respond("aaa bbb_1 ccc")
        self.assertEqual(answer,"abc abc zzz") #Neural network sometimes does not answer correctly

        answer = self.he.respond("abc abc")
        self.assertEqual(answer,"abc test")

    def test_start_stop(self):
        import threading
        import time

        self.he.createInnerVoiceDatabase(self._innervoice_builder())
        self.he.createWordsDataBase(self._word_database_builder())
        self.he.createTrainingDataBase(self._traning_database_builder())
        self.he.createAbilitiesDataBase(self._abilities_builder())
        self.he.train()

        start_thread = threading.Thread(target=self.he.start,name=self.he.start.func_name)
        start_thread.start()
        time.sleep(0.5)
        self.he.stop()
        start_thread.join()
        self.assertFalse(start_thread.isAlive())
Example #20
0
    def __init__(self):

        # Config File
        os.path.abspath("config/NetGUARD.cfg")
        self.config = ConfigParser.ConfigParser()
        self.config.read("config/netguard.cfg")

        # Call Jarvis
        self.Jarvis = Jarvis()

        # Log file
        os.path.abspath("log/NetGUARD.log")

        # Jail
        self.jail = []

        try:
            # Network Interface from config
            self.interface = self.configmap("NetworkSettings")['interface']

            # Gateway IP address from config
            self.gateway_ip = self.configmap("NetworkSettings")['gateway_ip']

            # Gateway MAC address from config
            self.gateway_mac = self.configmap("NetworkSettings")['gateway_mac']

        except Exception as e:
            print "[-] Check your config file in NetGUARD/config/netguard.cfg"
            print "[!] Exception caught: ".format(e)
            exit(0)

            # My Network Interface MAC_Address
        self.mymac = get_mymac(self.interface)

        # My LAN IP Address
        self.myip = get_myip(self.interface)

        # If we are ARP spoofing status
        self.myspoof_status = False

        # If someone is ARP spoofing status
        self.spoof_status = False

        # ICMP request for this host - DDoS avoid.
        self.icmp_count = 0
        # Network ICMP sources in 5s
        self.icmpsenders = {}

        # TCP != from gateway connections - DDoS avoid.
        self.tcp_count = 0
        # Network UDP sources in 5s
        self.tcpsenders = {}

        # UDP != from gateway connections - DDoS avoid.
        self.udp_count = 0
        # Network UDP sources in 5s
        self.udpsenders = {}

        # SSH client attempts and brute status
        self.ssh_count = 0
        self.ssh_brute = False

        # MySQL client attempts and brute status
        self.sql_count = 0
        self.sql_brute = False

        # FTP client attempts and brute status
        self.ftp_count = 0
        self.ftp_brute = False

        # Time variables
        self.start_time = time.time()
        self.current_time = 0

        #ICMP time auxiliary
        self.itt = 0
        self.itt2 = 0

        #TCP time auxiliary
        self.ttt = 0
        self.ttt2 = 0

        #UDP time auxiliary
        self.utt = 0
        self.utt2 = 0

        #SSH time auxiliary
        self.sst = 0
        self.sst2 = 0

        #SQL time auxiliary
        self.sqt = 0
        self.sqt2 = 0

        #FTP time auxiliary
        self.ftt = 0
        self.ftt2 = 0
Example #21
0
class NetGUARD(object):

    name = "Network Guardian"
    desc = "Defend host, give warnings to sysadmin and log to txt file."
    version = "0.9"

    # Initialize, create NetGUARD global variables and parse config file
    def __init__(self):

        # Config File
        os.path.abspath("config/NetGUARD.cfg")
        self.config = ConfigParser.ConfigParser()
        self.config.read("config/netguard.cfg")

        # Call Jarvis
        self.Jarvis = Jarvis()

        # Log file
        os.path.abspath("log/NetGUARD.log")

        # Jail
        self.jail = []

        try:
            # Network Interface from config
            self.interface = self.configmap("NetworkSettings")['interface']

            # Gateway IP address from config
            self.gateway_ip = self.configmap("NetworkSettings")['gateway_ip']

            # Gateway MAC address from config
            self.gateway_mac = self.configmap("NetworkSettings")['gateway_mac']

        except Exception as e:
            print "[-] Check your config file in NetGUARD/config/netguard.cfg"
            print "[!] Exception caught: ".format(e)
            exit(0)

            # My Network Interface MAC_Address
        self.mymac = get_mymac(self.interface)

        # My LAN IP Address
        self.myip = get_myip(self.interface)

        # If we are ARP spoofing status
        self.myspoof_status = False

        # If someone is ARP spoofing status
        self.spoof_status = False

        # ICMP request for this host - DDoS avoid.
        self.icmp_count = 0
        # Network ICMP sources in 5s
        self.icmpsenders = {}

        # TCP != from gateway connections - DDoS avoid.
        self.tcp_count = 0
        # Network UDP sources in 5s
        self.tcpsenders = {}

        # UDP != from gateway connections - DDoS avoid.
        self.udp_count = 0
        # Network UDP sources in 5s
        self.udpsenders = {}

        # SSH client attempts and brute status
        self.ssh_count = 0
        self.ssh_brute = False

        # MySQL client attempts and brute status
        self.sql_count = 0
        self.sql_brute = False

        # FTP client attempts and brute status
        self.ftp_count = 0
        self.ftp_brute = False

        # Time variables
        self.start_time = time.time()
        self.current_time = 0

        #ICMP time auxiliary
        self.itt = 0
        self.itt2 = 0

        #TCP time auxiliary
        self.ttt = 0
        self.ttt2 = 0

        #UDP time auxiliary
        self.utt = 0
        self.utt2 = 0

        #SSH time auxiliary
        self.sst = 0
        self.sst2 = 0

        #SQL time auxiliary
        self.sqt = 0
        self.sqt2 = 0

        #FTP time auxiliary
        self.ftt = 0
        self.ftt2 = 0

        # Configuration file mapping
    def configmap(self, section):
        dict = {}
        options = self.config.options(section)
        for option in options:
            try:
                dict[option] = self.config.get(section, option)
                if dict[option] == -1:
                    DebugPrint("[!] Skip: {}".format(option))
            except:
                print "[!] Exception on: %s".format(s)
                dict[option] = None
        return dict

        # Main routine
    def main(self, p):

        # Ethernet Frame
        if p.haslayer(Ether):
            # Media Access Control destination
            mac_dst = str(p[Ether].dst)
            # Media Acess Control source
            mac_src = str(p[Ether].src)

            # ARP Layer Protection
        if p.haslayer(ARP):

            # is-at
            if p[ARP].op == 2:
                # Sender Hardware Address
                hardware_src = p[ARP].hwsrc
                # Sender Protocol Address
                protocol_src = p[ARP].psrc
                # Target Hardware Address
                hardware_dst = p[ARP].hwdst
                # Target Protocol Address
                protocol_dst = p[ARP].pdst

                # If gateway ARP is-at is normal
                if protocol_src == self.gateway_ip and hardware_src == self.gateway_mac:
                    if self.spoof_status == True:
                        self.log("Gateway returned to original mac address.")
                        self.Jarvis.Say(
                            "The gateway has returned to the original mac.")
                        self.spoof_status = False
                    if self.myspoof_status == True:
                        self.log("This host stop to arp spoof the gateway. \n")
                        self.Jarvis.Say(
                            "You stopped to arp spoof the gateway sir.")
                        self.myspoof_status = False
                    return

                    # If the op is: gateway is at and the hardware source diverges from original gateway MAC.
                if protocol_src == self.gateway_ip and hardware_src != self.gateway_mac:

                    # If the person that are doing the ARP spoof is me."
                    if hardware_src == self.mymac:

                        if self.myspoof_status == False:
                            # Log
                            self.log(
                                "This host start to arp spoof the gateway. \n")

                            self.Jarvis.Say(
                                "You are arp spoofing the gateway sir.")

                            # Status
                            self.myspoof_status = True

                        else:
                            return

                        # If the person is not you
                    else:
                        if self.spoof_status == False:

                            for i in range(0, 3):
                                self.Jarvis.Say(
                                    "the mac {} is trying to arp spoof the network."
                                    .format(hardware_src.replace(":", " ")))
                                #os.system("iptables -A INPUT -m mac --mac-source {} -j REJECT".format(hardware_src))
                                time.sleep(2)

                                # Log
                            self.log(
                                "{} are trying to arp spoof the network. \n".
                                format(hardware_src))

                            # Status
                            self.spoof_status = True

                        else:
                            return

# IP Layer Protection
        if p.haslayer(IP):
            ip_src = str(p[IP].src)
            ip_dst = str(p[IP].dst)
            ip_chk = p[IP].chksum
            ip_len = p[IP].len

            #DDoS ICMP Layer Protection
            if p.haslayer(ICMP):
                type = p[ICMP].type
                if ip_src != self.myip and ip_dst == self.myip and type == 8:
                    if ip_dst not in self.icmpsenders:
                        # Append new ICMP sender on network
                        self.icmpsenders.update({ip_src: self.tcp_count})
                    self.icmp_count += 1

                    # First time value from 5s delay
                if self.icmp_count == 1:
                    self.itt = time.time()
                else:
                    self.itt2 = time.time()

                for ip, count in self.icmpsenders.iteritems():

                    if count > 500 and ip not in self.jail:
                        self.log(
                            "IP - {}/MAC - {} start to perform a ICMP denial of service attack against this host."
                            .format(ip, mac_dst))
                        self.Jarvis.Say(
                            "The IP address {} is performing a ICMP denial of service attack against this host."
                            .format(ip.replace(".", " ")))
                        os.system(
                            "iptables -A INPUT -p icmp -s {} -j DROP".format(
                                ip, str(dport)))
                        self.Jarvis.Say(
                            "Raising the packet shield for the attacker")
                        self.jail.append(ip)

                interval = self.itt2 - self.itt
                if interval >= 5:
                    self.icmp_count = 0
                    self.icmpsenders.clear()

                # DDoS TCP Layer Protection
            if p.haslayer(TCP):
                sport = p[TCP].sport
                dport = p[TCP].dport
                if ip_src != self.gateway_ip and ip_src != self.myip and ip_dst == self.myip:
                    if ip_dst not in self.tcpsenders:
                        # Append new TCP sender on network
                        self.tcpsenders.update({ip_src: self.tcp_count})
                    self.tcp_count += 1

                    # First time value from 5s delay
                if self.tcp_count == 1:
                    self.ttt = time.time()
                else:
                    # Other time values from 5s delay
                    self.ttt2 = time.time()

                for ip, count in self.tcpsenders.iteritems():

                    if count > 500 and ip not in self.jail:
                        self.log(
                            "IP - {}/MAC - {} start to perform a TCP denial of service attack against this host."
                            .format(ip, mac_dst))
                        self.Jarvis.Say(
                            "The IP address {} is performing a TCP denial of service attack against this host."
                            .format(ip.replace(".", " ")))
                        os.system(
                            "iptables -A INPUT -p tcp -s {} -j DROP".format(
                                ip, str(dport)))
                        self.log("Raising the packet shield for the attacker")
                        self.Jarvis.Say(
                            "Raising the packet shield for the attacker")
                        self.jail.append(ip)

                interval = self.ttt2 - self.ttt
                if interval >= 5:
                    self.tcp_count = 0
                    self.tcpsenders.clear()

# DDoS UDP Layer Protection
            if p.haslayer(UDP):
                sport = p[UDP].sport

                if ip_src != self.gateway_ip and ip_src != self.myip and ip_dst == self.myip:
                    if ip_dst not in self.udpsenders:
                        self.udpsenders.update({ip_src: self.udp_count})
                    self.udp_count += 1

                if self.tcp_count == 1:
                    self.utt = time.time()
                else:
                    self.utt2 = time.time()

                for ip, count in self.udpsenders.iteritems():

                    if count > 500 and ip not in self.jail:
                        self.log(
                            "IP - {}/MAC - {} start to perform a UDP denial of service attack against this host."
                            .format(ip_src, mac_dst))
                        self.Jarvis.Say(
                            "The IP address {} is performing a UDP denial of service attack against this host."
                            .format(ip_src.replace(".", " ")))
                        os.system(
                            "iptables -A INPUT -p udp -s {} -j DROP".format(
                                ip_src, str(dport)))
                        self.log("Raising the packet shield for the attacker")
                        self.Jarvis.Say(
                            "Raising the packet shield for the attacker")
                        self.jail.append(ip)

                interval = self.utt2 - self.utt
                if interval >= 5:
                    self.udp_count = 0
                    self.udpsenders.clear()

            # Brute-Force TCP Layer Protection
            if p.haslayer(TCP) and p.haslayer(Raw):
                flags = {
                    'F': 'FIN',
                    'S': 'SYN',
                    'R': 'RST',
                    'P': 'PSH',
                    'A': 'ACK',
                    'U': 'URG',
                    'E': 'ECE',
                    'C': 'CWR'
                }
                dport = p[TCP].dport
                sport = p[TCP].sport
                ack = p[TCP].ack
                seq = p[TCP].seq
                preflag = [flags[x] for x in p.sprintf('%TCP.flags%')]
                flag = "/".join(preflag)
                chksum = str(p[TCP].chksum)
                load = p[Raw].load

                # FTP Protection
                if sport == 21 and "530" in load and ip_src == self.myip:

                    if self.ftp_brute == False:
                        self.log(
                            "IP - {}/MAC - {} tried to connect with the FTP server with a wrong password."
                            .format(ip_dst, mac_dst))
                        self.Jarvis.Say(
                            "The IP address {} tried to connect with the FTP server with a wrong password."
                            .format(ip_dst.replace(".", " ")))

                    self.ftp_count += 1

                    if self.ftp_count == 1:
                        # Live minutes
                        self.ftt = time.time()
                    else:
                        self.ftt2 = time.time()

                        # If 4 ftp_client packets and 4º count time - 1º count time >= 1
                    if self.ftp_count >= 4:

                        interval = self.ftt2 - self.ftt
                        if interval >= 360:
                            self.ftp_count = 0
                        else:
                            self.ftp_brute = True
                            os.system(
                                "iptables -A INPUT -p tcp -s {} --dport {} -j REJECT"
                                .format(ip_dst, str(sport)))
                            # Log
                            self.log(
                                "! IP - {}/MAC - {} is brute forcing the FTP server."
                                .format(ip_dst, mac_dst))
                            self.log(
                                "Raising the packet shield for the attacker")

                            self.Jarvis.Say(
                                "The IP {} is brute forcing the FTP server.".
                                format(ip_dst.replace(".", " ")))
                            self.Jarvis.Say(
                                "Raising the packet shield for the attacker")

                            # Status
                            self.ftp_count = 0

            # MySQL Protection
                if sport == 3306 and "denied" in load and ip_src == self.myip:

                    if self.sql_brute == False:
                        self.log(
                            "IP - {}/MAC - {} tried to connect with the SQL server with a wrong password."
                            .format(ip_dst, mac_dst))
                        self.Jarvis.Say(
                            "The IP address {} tried to connect with the SQL server with a wrong password."
                            .format(ip_dst.replace(".", " ")))

                    self.sql_count += 1

                    if self.sql_count == 1:
                        # Live minutes
                        self.sqt = time.time()
                    else:
                        self.sqt2 = time.time()

                        # If 4 sql_client packets and 4º count time - 1º count time >= 1
                    if self.sql_count >= 4:

                        interval = self.sqt2 - self.sqt
                        if interval >= 360:
                            self.sql_count = 0
                        else:
                            self.sql_brute = True
                            os.system(
                                "iptables -A INPUT -p tcp -s {} --dport {} -j REJECT"
                                .format(ip_dst, str(sport)))
                            # Log
                            self.log(
                                "! IP - {}/MAC - {} is brute forcing the SQL server."
                                .format(ip_dst, mac_dst))
                            self.log(
                                "Raising the packet shield for the attacker")

                            self.Jarvis.Say(
                                "The IP {} is brute forcing the SQL server.".
                                format(ip_dst.replace(".", " ")))
                            self.Jarvis.Say(
                                "Raising the packet shield for the attacker")

                            # Status
                            self.sql_count = 0

                    # SSH Protection
                if "SSH" in load and ip_src != self.myip and ip_dst == self.myip:

                    if self.ssh_brute == False:
                        self.log(
                            "IP - {}/MAC - {} open a socket with the SSH server."
                            .format(ip_src, mac_src))
                        self.Jarvis.Say(
                            "The IP address {} open a socket with the SSH server."
                            .format(ip_dst.replace(".", " ")))

                    self.ssh_count += 1

                    if self.ssh_count == 1:
                        # Live minutes
                        self.sst = time.time()
                    else:
                        self.sst2 = time.time()

                        # If 4 ssh_client packets and 4º count time - 1º count time >= 1
                    if self.ssh_count >= 3:

                        interval = self.sst2 - self.sst
                        if interval >= 360:
                            self.ssh_count = 0
                            self.sst = 0
                        else:
                            self.ssh_brute = True
                            os.system(
                                "iptables -A INPUT -p tcp -s {} --dport {} -j REJECT"
                                .format(ip_src, str(dport)))
                            # Log
                            self.log(
                                "! IP - {}/MAC - {} is brute forcing the SSH server."
                                .format(ip_src, mac_src))
                            self.log(
                                "Raising the packet shield for the attacker")

                            self.Jarvis.Say(
                                "The IP {} is brute forcing the SSH server.".
                                format(ip_dst.replace(".", " ")))
                            self.Jarvis.Say(
                                "Raising the packet shield for the attacker")

                            # Status
                            self.ssh_count = 0
                            self.sst = 0

        # Logger
    def log(self, message):
        file = open("log/NetGUARD.log", "a+")
        file.write("\n")
        time = datetime.now().strftime('%Y-%m-%d_%H:%M:%S')
        file.write(time + ": ")
        file.write(message)
        file.close()

        # Start
    def start(self):
        try:
            pid = os.getpid()
            self.log("NetGUARD started")
            self.Jarvis.Say(
                "Network guardian initialized on process {}.".format(pid))

            # Set static ARP with the gateway.
            os.system("arp -s {} {}".format(self.gateway_ip, self.gateway_mac))
            self.log("Static ARP set with gateway.")
            self.Jarvis.Say("Setting static arp with gateway.")

            self.Jarvis.Say("I will warn you if i find any threat")

            # Start the sniffer.
            p = sniff(iface=self.interface, prn=self.main)
            time = datetime.now().strftime('%Y-%m-%d_%H:%M:%S')
            wrpcap("NetGUARD_{}.pcap".format(time), p)

        except Exception as e:
            self.log("Problem starting the network monitor")
            self.log("Exception: {}".format(e))
            self.Jarvis.Say("Problem starting the network monitor")

        # Start the sniffer as subprocess.
    def backgroundstart(self):
        try:
            with open("log/NetGUARD.log", "a+") as stdout:
                self.p = subprocess.Popen(["python core/NetGUARD.py"],
                                          shell=True,
                                          stdout=stdout,
                                          stderr=stdout)
            self.log("NetGUARD in background started.")
            return
        except Exception as e:
            self.log("Problem starting NetGUARD in background")
            self.Jarvis.Say(
                "Problem starting the network monitor in background")
Example #22
0
	def __init__(self):
		self.Jarvis = Jarvis()
Example #23
0
from flask import Flask, request, jsonify
from jarvis import Jarvis
import json

jarvis = Jarvis()

app = Flask(__name__)

# Create URL route in our application for "/"
@app.route('/v1')
def home():
    """
    This is the main page. 
    """
    
    return "This is a rest service for Jarvis. Jarvis is a AI text classification agent. He will try to predict the correct queue for the email you pass to it."

@app.route('/v1/predict',methods = ['POST', 'GET'])
def predict():
    """
    This fuction is to create the post and get method for prediction
    """
    if request.method == 'POST':
        data = request.get_json()
        query = data["email"]
        result = jarvis.predict(query)
        return jsonify(result)
    else:
        query = request.args.get('email')
        result = jarvis.predict(query)
        return jsonify(result)
Example #24
0
    from database import WordDataBaseBuilder
    from database import TrainingDataBaseBuilder
    from database import AbilitiesDataBaseBuilder
    from database import InnerVoiceDataBaseBuilder
    from interfaces import Console

    wd_builder = WordDataBaseBuilder()
    wd_builder.addTxtFile("learning_material/traning.txt")

    td_builder = TrainingDataBaseBuilder()
    td_builder.addTxtFile("learning_material/traning.txt")

    iv_builder = InnerVoiceDataBaseBuilder()
    iv_builder.addTxtFile("learning_material/inner_voices.txt")

    ab_builder = AbilitiesDataBaseBuilder()

    he = Jarvis()
    he.createWordsDataBase(wd_builder)
    he.createTrainingDataBase(td_builder)
    he.createAbilitiesDataBase(ab_builder)
    he.createInnerVoiceDatabase(iv_builder)
    he.train()

    console = Console()
    console.jarvis(he)
    console.start()

    he.start()

Example #25
0
class Processor(object):
    name = "Interface-Processor"
    desc = "Console to process commands"
    version = "0.5"

    def __init__(self):
        #Jarvis
        self.Jarvis = Jarvis()

        #Variables
        self.targets = None
        self.file = None
        self.interface = None
        self.gateway = None
        self.port = 80
        self.domain = None
        self.redirect = None
        self.script = None
        self.filter = None
        self.arpmode = "rep"

        #Status manager
        self.jarvis_status = 0
        self.arpspoof_status = False
        self.inject_status = False
        self.dnsspoof_status = False
        self.mitmdrop_status = 0

    def start(self):
        try:
            while 1:
                completer = Completer("pythem")
                console = termcolor.colored("pythem>", "red", attrs=["bold"])
                self.command = raw_input("{} ".format(console))
                self.argv = self.command.split()
                self.input_list = [str(a) for a in self.argv]
                try:

                    if self.input_list[0] == "help":
                        print_help()

                    elif self.command == "jarvis":
                        self.Jarvis.start('core/processor.py')
                        self.jarvis_status = 1

                    elif self.input_list[0] == "jarvis":
                        if self.input_list[1] == "log":
                            try:
                                jarvislog = self.input_list[2]
                                try:
                                    os.system(
                                        "tail -f log/jarvis{}.txt".format(
                                            jarvislog))
                                except Exception as e:
                                    print "[!] Exception caught: {}".format(e)
                                    pass

                            except IndexError:
                                print "[+] Jarvis log system."
                                print "[.] Error log  - type: err"
                                print "[.] Output log - type: out"
                                try:
                                    jarvislog = raw_input("[+] Select: ")
                                    os.system(
                                        "tail -f log/jarvis{}.txt".format(
                                            jarvislog))
                                except KeyboardInterrupt:
                                    pass
                                except Exception as e:
                                    print "[!] Exception caught: {}".format(e)
                                    pass

                        elif self.input_list[1] == "help":
                            jarvis_help(self.Jarvis.version)

                        elif self.input_list[1] == "say":
                            try:
                                message = self.input_list[2]
                                all_msg = " ".join(self.input_list[2:])
                                self.Jarvis.Say(all_msg)
                            except IndexError:
                                try:
                                    message = raw_input("[+] Jarvis speaker: ")
                                    self.Jarvis.Say(message)
                                except KeyboardInterrupt:
                                    pass
                            except Exception as e:
                                print "[!] Exception caught: {}".format(e)

                        elif self.input_list[1] == "read":
                            try:
                                file = self.input_list[2]
                                self.Jarvis.Read(file)
                            except IndexError:
                                if self.file is not None:
                                    self.Jarvis.Read(self.file)
                                else:
                                    file = "[+] Set file path:"
                                    pass
                            except TypeError:
                                print "[!] You probably forgot to set a wordlist file path."
                                pass
                            except KeyboardInterrupt:
                                pass
                            except Exception as e:
                                print "[!] Exception caught: {}".format(e)

                        else:
                            self.Jarvis.start('core/processor.py')
                            self.jarvis_status = 1

                    elif self.command == "exit" or self.command == "quit":
                        if self.jarvis_status == 1:
                            self.Jarvis.Say(self.Jarvis.random('salutes'))
                            self.Jarvis.stop()
                            exit()
                        else:
                            exit()

                    elif self.input_list[0] == "set" or self.input_list[
                            0] == "SET":
                        if self.input_list[1] == "interface":
                            try:
                                self.interface = self.input_list[2]
                            except IndexError:
                                try:
                                    self.interface = raw_input(
                                        "[+] Enter the interface: ")
                                except KeyboardInterrupt:
                                    pass
                        elif self.input_list[1] == "port":
                            try:
                                self.port = int(self.input_list[2])
                            except IndexError:
                                try:
                                    self.port = input(
                                        "[+] Enter the default port: ")
                                except KeyboardInterrupt:
                                    pass

                        elif self.input_list[1] == "domain":
                            try:
                                self.domain = self.input_list[2]
                            except IndexError:
                                try:
                                    self.domain = raw_input(
                                        "[+] Domain to be spoofed: ")
                                except KeyboardInterrupt:
                                    pass

                        elif self.input_list[1] == "redirect":
                            try:
                                self.redirect = self.input_list[2]
                            except IndexError:
                                try:
                                    self.redirect = raw_input(
                                        "[+] IP address to redirect DNS queries: "
                                    )
                                except KeyboardInterrupt:
                                    pass

                        elif self.input_list[1] == "script":
                            try:
                                self.script = self.input_list[2]
                            except IndexError:
                                try:
                                    self.script = raw_input(
                                        "[+]Script url/path: ")
                                except KeyboardInterrupt:
                                    pass

                        elif self.input_list[1] == "gateway":
                            try:
                                self.gateway = self.input_list[2]
                            except IndexError:
                                try:
                                    self.gateway = raw_input(
                                        "[+] Enter the gateway: ")
                                except KeyboardInterrupt:
                                    pass
                        elif self.input_list[1] == "target":
                            try:
                                self.targets = self.input_list[2]
                            except IndexError:
                                try:
                                    self.targets = raw_input(
                                        "[+] Enter the target(s): ")
                                except KeyboardInterrupt:
                                    pass
                        elif self.input_list[1] == "file":
                            try:
                                self.file = self.input_list[2]
                            except IndexError:
                                try:
                                    self.file = raw_input(
                                        "[+] Enter the path to the file: ")
                                except KeyboardInterrupt:
                                    pass
                        elif self.input_list[1] == "arpmode":
                            try:
                                self.arpmode = self.input_list[2]
                            except IndexError:
                                try:
                                    self.arpmode = raw_input(
                                        "[+] Enter the arpmode: ")
                                except KeyboardInterrupt:
                                    pass

                        elif self.input_list[1] == "filter":
                            try:
                                self.filter = self.input_list[2]
                            except IndexError:
                                try:
                                    self.filter = raw_input(
                                        "[+] Enter the sniffer filter: ")
                                except KeyboardInterrupt:
                                    pass
                        else:
                            print "[!] Select a valid variable to set."

                    elif self.input_list[0] == "print":
                        if self.input_list[1] == "interface":
                            print "[+] Network Interface: {}".format(
                                self.interface)
                        elif self.input_list[1] == "port":
                            print "[+] Default port: {}".format(self.port)
                        elif self.input_list[1] == "domain":
                            print "[+] Domain: {}".format(self.domain)
                        elif self.input_list[1] == "redirect":
                            print "[+] Redirecting to: {}".format(
                                self.redirect)
                        elif self.input_list[1] == "script":
                            print "[+] Script url/path: {}".format(self.script)
                        elif self.input_list[1] == "gateway":
                            print "[+] Gateway IP Address: {}".format(
                                self.gateway)
                        elif self.input_list[1] == "target":
                            print "[+] Target(s): {}".format(self.targets)
                        elif self.input_list[1] == "file":
                            print "[+] File path: {}".format(self.file)
                        elif self.input_list[1] == "arpmode":
                            print "[+] ARP spoofing mode: {}".format(
                                self.arpmode)
                        else:
                            print "[-] Select a valid variable name."

                    elif self.input_list[0] == "scan":
                        try:
                            mode = self.input_list[1]
                            if self.targets is not None and self.interface is not None:
                                from modules.scanner import Scanner
                                self.scan = Scanner(self.targets,
                                                    self.interface, mode)
                                self.scan.start()
                            else:
                                print "[!] You probably forgot to set the interface or a valid IP address/range."
                        except IndexError:
                            try:
                                print "[*] Select one scan mode, options = tcp/arp/manual"
                                mode = raw_input("[+] Scan mode: ")
                            except KeyboardInterrupt:
                                pass
                            if self.targets is not None and self.interface is not None:
                                from modules.scanner import Scanner
                                self.scan = Scanner(self.targets,
                                                    self.interface, mode)
                                self.scan.start()
                            else:
                                print "[!] You probably forgot to set the interface or a valid IP address/range."
                                pass

                        except KeyboardInterrupt:
                            pass
                        except Exception as e:
                            print "[!] Exception caught: {}".format(e)
                            pass

                    elif self.input_list[0] == "arpspoof":
                        try:
                            if self.input_list[1] == "start":
                                from modules.arpoisoner import ARPspoof
                                myip = get_myip(self.interface)
                                mymac = get_mymac(self.interface)
                                self.arpspoof_status = True
                                self.spoof = ARPspoof(self.gateway,
                                                      self.targets,
                                                      self.interface,
                                                      self.arpmode, myip,
                                                      mymac)
                                self.spoof.start()
                                print "[+] ARP spoofing initialized."

                            elif self.input_list[1] == "stop":
                                self.spoof.stop()
                                self.arpspoof_status = False
                                print "[+] ARP spoofing finalized."

                            elif self.input_list[1] == "status":
                                if self.arpspoof_status:
                                    stat = "running"
                                else:
                                    stat = "down"
                                print "[*] ARP spoofing status: {}".format(
                                    stat)

                            else:
                                print "[!] Select a valid option, call help to check syntax."

                        except TypeError:
                            print "[!] You probably forgot to set interface or gateway."
                        except IndexError:
                            print "[!] You probably forgot to type start or stop after arpspoof."
                        except AttributeError:
                            pass
                        except Exception as e:
                            print "[!] Exception caught: {}".format(e)

                    elif self.input_list[0] == "dnsspoof":
                        try:

                            if self.input_list[1] == "start":
                                if not self.arpspoof_status:
                                    print "[!] You probably forgot to start an ARP spoofing."
                                    continue
                                if self.domain != None:
                                    domain = self.domain
                                else:
                                    try:
                                        domain = raw_input(
                                            "[!] Type all to spoof all domains\n[+] Domain to be spoofed: "
                                        )
                                        self.domain = domain
                                    except KeyboardInterrupt:
                                        pass

                                if self.redirect != None:
                                    redirect = self.redirect
                                else:
                                    myip = get_myip(self.interface)
                                    opt = raw_input(
                                        "[+] Default address to redirect is:{} do you want to change?[y/n]"
                                        .format(myip))
                                    if opt == "y" or opt == "Y" or opt == "yes" or opt == "YES":
                                        try:
                                            redirect = raw_input(
                                                "[+] IP address to be redirected: "
                                            )
                                        except KeyboardInterrupt:
                                            pass
                                    else:
                                        redirect = myip

                                from modules.dnspoisoner import DNSspoof
                                self.dnsspoof = DNSspoof(redirect)
                                self.dnsspoof.start(domain, None)
                                print "[+] DNS spoofing initialized"
                                self.dnsspoof_status = True

                            elif self.input_list[1] == "stop":
                                self.dnsspoof.stop()
                                print "[+] DNS spoofing finalized"

                            elif self.input_list[1] == "status":
                                if self.dnsspoof_status:
                                    stat = "running"
                                else:
                                    stat = "down"
                                print "[*] DNS spoofing status: {}".format(
                                    stat)

                            else:
                                print "[!] Select a valid option, call help to check syntax."
                        except IndexError:
                            print "[!] You probably forgot to type start or stop after dnsspoof."
                        except Exception as e:
                            print "[!] Exception caught: {}".format(e)

                    elif self.input_list[0] == "inject":
                        try:
                            if self.input_list[1] == "start":
                                myip = get_myip(self.interface)
                                try:
                                    from modules.inject import Inject
                                    self.inject = Inject(
                                        myip, self.port, self.script)
                                    self.inject_status = True
                                    self.inject.server()
                                except AttributeError:
                                    print "\n[!] Select a valid script source path or url."
                                except Exception as e:
                                    print "[!] Exception caught: {}".format(e)

                            elif self.input_list[1] == "stop":
                                try:
                                    self.inject.stop()
                                    self.inject_status = False
                                except Exception as e:
                                    print "[!] Exception caught: {}".format(e)

                            elif self.input_list[1] == "status":
                                if self.inject_status:
                                    stat = "running"
                                else:
                                    stat = "down"
                                print "[*] Script injection status: {}".format(
                                    stat)

                            else:
                                print "[!] You need to specify  start, stop or status after the inject module call."
                        except IndexError:
                            print "[!] You probably forgot to start or stop the inject module."
                        except TypeError:
                            print "[!] You probably forgot to start an arpspoof attack ."
                        except Exception as e:
                            print "[!] Exception caught: {}".format(e)

                    elif self.input_list[0] == "dos":
                        from modules.jammer import Jam
                        self.dos = Jam()
                        try:
                            if self.input_list[1] == "mitmdrop":
                                if self.arpspoof_status:
                                    try:
                                        myip = get_myip(self.interface)
                                        self.dos.mitmdropstart(myip)
                                        self.mitmdrop_status = 1
                                    except Exception as e:
                                        print "[!] Exception caught: {}".format(
                                            e)
                                else:
                                    print "[!] You need to start a arpspoof on a target (IP/Range) to start mitmdrop."

                            elif self.input_list[1] == "stop":
                                if self.mitmdrop_status == 1:
                                    self.dos.mitmdropstop()
                                else:
                                    print "[!] You need to start a DoS attack before call stop."
                            else:
                                print "[!] Select a valid option, type help to check syntax."

                        except IndexError:
                            print "[!] You probably forgot to specify the type of DoS to use."

                    elif self.input_list[0] == "sniff":
                        from modules.sniffer import Sniffer
                        try:
                            hasfilter = self.input_list[1]
                            self.filter = " ".join(self.input_list[1:])
                            if self.filter == "http":
                                self.filter = "port 80"
                            elif self.filter == "dns":
                                self.filter = "port 53"
                            self.sniff = Sniffer(self.interface, self.filter)
                            self.sniff.start()

                        except IndexError:
                            try:
                                self.filter = raw_input(
                                    "[+] Enter the filter: ")
                                if self.filter == "http":
                                    self.filter = "port 80"
                                elif self.filter == "dns":
                                    self.filter = "port 53"
                                if not self.filter:
                                    self.filter = None
                                self.sniff = Sniffer(self.interface,
                                                     self.filter)
                                self.sniff.start()
                            except KeyboardInterrupt:
                                pass

                    elif self.command == "pforensic":
                        try:
                            completer = None
                            completer = Completer("pforensic")
                            from modules.pforensic import PcapReader
                            self.pcapread = PcapReader(self.file)
                            self.pcapread.start()
                        except KeyboardInterrupt:
                            pass
                        except TypeError:
                            print "[!] You probably forgot to set the .pcap file"
                            pass
                        except Exception as e:
                            print "[!] Exception caught: {}".format(e)
                            pass

                    elif self.input_list[0] == "xploit":
                        try:
                            from modules.exploit import Exploit
                            if self.targets is not None and self.input_list[
                                    1] == "tcp":
                                self.xploit = Exploit(self.targets,
                                                      self.input_list[1])
                                self.xploit.start()
                            elif self.file is not None and self.input_list[
                                    1] == "stdin":
                                self.xploit = Exploit(self.file,
                                                      self.input_list[1])
                                self.xploit.start()
                            else:
                                print "[!] You need to set or stdin or tcp as argument."
                                print "[!] You need to set or a file or a target to xploit."
                        except IndexError:
                            try:
                                print "[*] Select one xploit mode, options = stdin/tcp"
                                mode = raw_input("[+] Exploit mode: ")
                                if mode == "stdin" or mode == "tcp":
                                    from modules.exploit import Exploit
                                    if self.targets is not None:
                                        self.xploit = Exploit(
                                            self.targets, mode)
                                        self.xploit.start()
                                    elif self.file is not None:
                                        self.xploit = Exploit(self.file, mode)
                                        self.xploit.start()
                                    else:
                                        print "[!] You need to set or a file or a target to xploit."
                                else:
                                    print "[!] Select a valid xploit mode, stdin or tcp"
                            except KeyboardInterrupt:
                                pass
                        except TypeError:
                            print "[!] You probably forgot to set the file"
                            pass
                        except KeyboardInterrupt:
                            pass
                        except Exception as e:
                            print "[!] Exception caught: {}".format(e)
                            pass

                    elif self.command == "cookiedecode":
                        try:
                            cookiedecode()
                        except KeyboardInterrupt:
                            pass
                        except Exception as e:
                            print "[!] Exception caught: {}".format(e)
                            pass

                    elif self.input_list[0] == "decode":
                        try:
                            print decode(self.input_list[1])
                        except KeyboardInterrupt:
                            pass

                    elif self.input_list[0] == "encode":
                        try:
                            print encode(self.input_list[1])
                        except KeyboardInterrupt:
                            pass

                    elif self.input_list[0] == "geoip":
                        try:
                            self.targets = self.input_list[1]
                            from modules.geoip import Geoip
                            path = "config/GeoLiteCity.dat"
                            iptracker = Geoip(self.targets, path)

                        except IndexError:
                            if self.targets is not None:
                                from modules.geoip import Geoip
                                path = "config/GeoLiteCity.dat"
                                iptracker = Geoip(self.targets, path)
                            else:
                                print "[!] You probably forgot to set a target"

                        except Exception as e:
                            print "[!] Exception caught: {}".format(e)
                            pass

                    elif self.input_list[0] == "brute":
                        if self.input_list[1] == "ssh":
                            try:
                                username = raw_input(
                                    "[+] Enter the username to bruteforce: ")
                                from modules.ssh_bruter import SSHbrutus
                                brutus = SSHbrutus(self.targets, username,
                                                   self.file)
                                brutus.start()
                            except KeyboardInterrupt:
                                brutus.stop()
                                pass
                            except TypeError:
                                print "[!] You probably forgot to set the wordlist file path."
                                pass
                        elif self.input_list[1] == "url":
                            try:
                                url = 'url'
                                from modules.web_bruter import WEBbrutus
                                brutus = WEBbrutus(self.targets, self.file)
                                brutus.start(url)
                            except KeyboardInterrupt:
                                brutus.stop(url)
                                pass
                            except TypeError:
                                print "[!] You probably forgot to set the wordlist file path."
                                pass
                        elif self.input_list[1] == "form":
                            try:
                                form = 'form'
                                from modules.web_bruter import WEBbrutus
                                brutus = WEBbrutus(self.targets, self.file)
                                brutus.start(form)
                            except KeyboardInterrupt:
                                brutus.stop(form)
                                pass
                            except TypeError:
                                print "[!] You probably forgot to set the wordlist file path."
                                pass
                        else:
                            print "[!] Select a valid type of brute-force type help to check."
                    else:
                        try:
                            os.system("{}".format(self.command))
                            pass
                        except Exception as e:
                            print "[!] Select a valid option, type help to check syntax."
                            pass
                except IndexError:
                    pass

                except Exception as e:
                    print "Exception caught: {}".format(e)

        except KeyboardInterrupt:
            print "\n[*] User requested shutdown."
            exit()
Example #26
0
 def __init__(self):
     self.Jarvis = Jarvis()
Example #27
0
class Processor(object):

    name = "Jarvis-Processor"
    desc = "Console to process voice commands"
    version = "0.2"

    def __init__(self):
        self.Jarvis = Jarvis()

    def start(self):
        try:
            self.Jarvis.ser.open()

        except Exception as e:
            print "[!] Arduino Leonardo not found, features that use keyboard will not work."

        try:
            self.Jarvis.Say(self.Jarvis.random('greetings'))
            while 1:
                try:
                    self.command = self.Jarvis.Listen()
                    self.message = self.command.split()
                    self.input_list = [str(a) for a in self.message]
                    if self.input_list[0] == "exit" or self.input_list[
                            0] == "quit":
                        self.Jarvis.Say(self.Jarvis.random('salutes'))
                        exit()

                    elif self.input_list[0] == "sleep" or self.input_list[
                            0] == "stop" or self.input_list[0] == "wait":
                        self.Jarvis.Say("Call me if you need me sir.")
                        while 1:
                            self.wait = self.Jarvis.Listen()
                            if self.wait == "Jarvis":
                                self.Jarvis.Say(
                                    self.Jarvis.random('affirmative'))
                                break

                    elif self.input_list[0] == "newspaper" or self.input_list[
                            0] == "news":
                        self.Jarvis.Say("Here are the news sir.")
                        self.titles = self.Jarvis.GetNews()
                        self.Jarvis.SpeakNews(self.titles)

                    elif self.input_list[0] == "browser":
                        try:
                            webbrowser.open("https://www.google.com")
                            self.Jarvis.Say(self.Jarvis.random('affirmative'))
                        except Exception as e:
                            print "[!] Exception caught: {}".format(e)
                            pass

                    elif self.input_list[0] == "terminal":
                        try:
                            os.system("gnome-terminal")
                            self.Jarvis.Say(self.Jarvis.random('affirmative'))
                        except Exception as e:
                            print "[!] Exception caught: {}".format(e)
                            pass

                    elif self.input_list[0] == "search":
                        try:
                            search = self.input_list[1:]
                            real = "".join(search)
                            url = "https://www.google.com/search?q={}".format(
                                real)
                            webbrowser.open(url)
                            self.Jarvis.Say(self.Jarvis.random('affirmative'))
                        except Exception as e:
                            print "[!] Exception caught: {}".format(e)
                            pass

                    elif self.input_list[0] == "say" or self.input_list[
                            0] == "speak":
                        self.Jarvis.Say(self.input_list[1:])

                    elif self.input_list[0] == "run":
                        self.Jarvis.Say(self.Jarvis.random('affirmative'))
                        os.system("./scripts/{}.sh".format(self.input_list[1]))

                    elif self.input_list[0] == "input":
                        try:
                            self.Jarvis.SerialWrite(self.input_list[1])
                            self.Jarvis.Say(self.Jarvis.random('affirmative'))
                        except:
                            self.Jarvis.Say(
                                "Feature not working master, plug your Arduino Leonardo then restart the program."
                            )
                            pass

                    elif self.input_list[0] == "editor":
                        self.Jarvis.Say("Starting edition mode sir.")
                        while 1:
                            self.editmode = self.Jarvis.Listen()
                            self.mesg = self.editmode
                            #self.msg = "".join(self.mesg)

                            if self.mesg is not None:
                                try:
                                    self.Jarvis.SerialWrite(self.mesg)
                                    self.Jarvis.Say(
                                        self.Jarvis.random('affirmative'))
                                except:
                                    self.Jarvis.Say(
                                        "Feature not working, plug you Arduino Leonardo then restart the program."
                                    )
                                    break
                            else:
                                pass
                            if self.editmode == "exit":
                                self.Jarvis.Say("Stoping edition mode sir.")
                                break

                    else:
                        print '[!] Input a valid option, enter "help" to see valid commands.'
                        self.Jarvis.Say("i heard, {}".format(self.command))
                        self.Jarvis.Say(self.Jarvis.random('dntunderstand'))

                except IndexError:
                    pass
                except AttributeError:
                    pass

        except KeyboardInterrupt:
            print "\n[*] User requested shutdown"
            self.Jarvis.Say(self.Jarvis.random('salutes'))
            exit()
        except Exception as e:
            print "[!] Exception caught: {}".format(e)
Example #28
0
import sys
from colorama import Fore, Back

from features.calendar_feature import Calendar
from jarvis import Jarvis

features = ["calendar", "weather", "wiki"]

if __name__ == "__main__":
    j = Jarvis()
    while True:
        typed = input("What do you want to do?: ").lower()

        cmd = typed.split(' ')[0]

        if cmd.strip() == 'list':
            j.say("Features available:")
            for feature in features:
                j.say("\t{}".format(feature), Fore.LIGHTBLUE_EX)
        elif cmd.strip() == 'exit' or cmd.strip() == 'close':
            j.say("G O O D B Y E")
            exit(0)

        elif j.cal.valid_inputs.get(cmd, 0) > 0:
            action = j.cal.do_action(typed)
        elif j.weather.valid_inputs.get(cmd, 0) > 0:
            if any(typed.strip('weather ')):
                j.weather.get_weather(typed.replace('weather ', ''))
            else:
                j.weather.get_weather()
        elif j.wiki.valid_inputs.get(cmd, 0) > 0:
Example #29
0
class JarvisServer:
    def __init__(self):

        self.server_app = Flask(__name__)
        self.host_name = "0.0.0.0"
        self.port = 8008
        self.auth_string = "new String that I created just so I could access this just for myself"
        self.routes = [
            dict(route="/health", endpoint="/health", func=self._health)
        ]

    def start_server(self):
        print("Starting a thread for home server!")

        from main import build_plugin_manager
        plugin_manager = build_plugin_manager()
        language_parser = snips.LanguageParser()
        jarvis_server = JarvisServer()
        self.io = ServerIO()

        self.jarvis = Jarvis(language_parser, plugin_manager, jarvis_server)
        self.jarvis.register_io(self.io)

        self.server_app.run(host=self.host_name,
                            port=self.port,
                            threaded=True,
                            debug=True,
                            use_reloader=False)

    def check_running(self) -> bool:
        pass

    def init_server_endpoints(self, jarvis_plugins):

        self._get_all_routes(jarvis_plugins)

        for route in self.routes:
            try:
                self.server_app.add_url_rule(route["route"], route["endpoint"],
                                             route["func"])
            except Exception as e:
                print(e)

    def _wrap_plugin(self, plugin):
        def _run():
            plugin.run(self.jarvis.jarvis_api, '')
            _text = self.io.fetch_recorded_texts()
            print(_text)
            return '\n'.join(_text)

        return _run

    def _get_all_routes(self, jarvis_plugins):
        for plugin in jarvis_plugins:
            route = dict()
            endpoint_string = "/" + '_'.join(
                re.findall(r"[\w']+", plugin.get_name()))

            if len(plugin.get_plugins().values()) != 0:
                self._get_all_routes(plugin.get_plugins().values())
            else:
                route["route"] = endpoint_string
                route["endpoint"] = endpoint_string
                _plug = plugin
                route["func"] = self._wrap_plugin(plugin)
                self.routes.append(route)

    def _health(self):
        return "Healthy"
Example #30
0
class Processor(object):
	name = "Interface-Processor"
	desc = "Console to process commands"
	version = "0.4"


	def __init__(self):
		#Jarvis
		self.Jarvis = Jarvis()

		#Variables
		self.targets = None
		self.file = None
		self.interface = None
		self.gateway = None
		self.port = 80
		self.domain = None
		self.redirect = None
		self.script = None
		self.arpmode = "rep"

		#Status manager
		self.jarvis_status = 0
		self.arpspoof_status = False
		self.inject_status = False
		self.dnsspoof_status = False
		self.mitmdrop_status = 0



	def start(self):
		try:
			while 1:
				completer = Completer("pythem")
				console = termcolor.colored("pythem>","red", attrs=["bold"])
				self.command = raw_input("{} ".format(console))
				self.argv = self.command.split()
				self.input_list = [str(a) for a in self.argv]
				try:

					if self.input_list[0] == "help":
						print_help()

					elif self.command == "jarvis":
						self.Jarvis.start('core/processor.py')
	                                        self.jarvis_status = 1

					elif self.input_list[0] == "jarvis":
						if self.input_list[1] == "log":
							try:
								jarvislog = self.input_list[2]
								try:
									os.system("tail -f log/jarvis{}.txt".format(jarvislog))
								except Exception as e:
									print "[!] Exception caught: {}".format(e)
									pass

							except IndexError:
								print "[+] Jarvis log system."
								print "[.] Error log  - type: err"
								print "[.] Output log - type: out"
								try:
									jarvislog = raw_input("[+] Select: ")
									os.system("tail -f log/jarvis{}.txt".format(jarvislog))
								except KeyboardInterrupt:
									pass
								except Exception as e:
									print "[!] Exception caught: {}".format(e)
									pass

						elif self.input_list[1] == "help":
							jarvis_help(self.Jarvis.version)

						elif self.input_list[1] == "say":
							try:
								message = self.input_list[2]
								all_msg = " ".join(self.input_list[2:])
								self.Jarvis.Say(all_msg)
							except IndexError:
								try:
									message = raw_input("[+] Jarvis speaker: ")
									self.Jarvis.Say(message)
								except KeyboardInterrupt:
									pass
							except Exception as e:
								print "[!] Exception caught: {}".format(e)

						elif self.input_list[1] == "read":
							try:
								file = self.input_list[2]
								self.Jarvis.Read(file)
							except IndexError:
								if self.file is not None:
									self.Jarvis.Read(self.file)
								else:
									file = "[+] Set file path:"
									pass
                                                	except TypeError:
                                                		print "[!] You probably forgot to set a wordlist file path."
                                                	        pass
							except KeyboardInterrupt:
								pass
							except Exception as e:
								print "[!] Exception caught: {}".format(e)
	
						else:
							self.Jarvis.start('core/processor.py')
	                                                self.jarvis_status = 1

					elif self.command == "exit" or self.command == "quit":
						if self.jarvis_status == 1:
							self.Jarvis.Say(self.Jarvis.random('salutes'))
							self.Jarvis.stop()
							exit()
						else:
							exit()

					
					elif self.input_list[0] == "set" or self.input_list[0] == "SET":
						if self.input_list[1] == "interface":
							try:
								self.interface = self.input_list[2]
							except IndexError:
								try:
									self.interface = raw_input("[+] Enter the interface: ")
								except KeyboardInterrupt:
									pass
						elif self.input_list[1] == "port":
							try:
								self.port = int(self.input_list[2])
							except IndexError:
								try:
									self.port = input("[+] Enter the default port: ")
								except KeyboardInterrupt:
									pass

						elif self.input_list[1] == "domain":
							try:
								self.domain = self.input_list[2]
							except IndexError:
								try:
									self.domain = raw_input("[+] Domain to be spoofed: ")
								except KeyboardInterrupt:
									pass

						elif self.input_list[1] == "redirect":
							try:
								self.redirect = self.input_list[2]
							except IndexError:
								try:
									self.redirect = raw_input("[+] IP address to redirect DNS queries: ")
								except KeyboardInterrupt:
									pass

						elif self.input_list[1] == "script":
							try:
								self.script = self.input_list[2]
							except IndexError:
								try:
									self.script = raw_input("[+]Script url/path: ")
								except KeyboardInterrupt:
									pass


						elif self.input_list[1] == "gateway":
							try:
								self.gateway = self.input_list[2]
							except IndexError:
								try:
									self.gateway = raw_input("[+] Enter the gateway: ")
								except KeyboardInterrupt:
									pass
						elif self.input_list[1] == "target":
							try:
								self.targets = self.input_list[2]
							except IndexError:
								try:
									self.targets = raw_input("[+] Enter the target(s): ")
								except KeyboardInterrupt:
									pass
						elif self.input_list[1] == "file":
							try:
								self.file = self.input_list[2]
							except IndexError:
								try:
									self.file = raw_input("[+] Enter the path to the file: ")
								except KeyboardInterrupt:
									pass
						elif self.input_list[1] == "arpmode":
							try:
								self.arpmode = self.input_list[2]
							except IndexError:
								try:
									self.arpmode = raw_input("[+] Enter the arpmode:")
								except KeyboardInterrupt:
									pass

						else:
							print "[!] Select a valid variable to set."


					elif self.input_list[0] == "print":
						if self.input_list[1] == "interface":
							print "[+] Network Interface: {}".format(self.interface)
						elif self.input_list[1] == "port":
							print "[+] Default port: {}".format(self.port)
						elif self.input_list[1] == "domain":
							print "[+] Domain: {}".format(self.domain)
						elif self.input_list[1] == "redirect":
							print "[+] Redirecting to: {}".format(self.redirect)
						elif self.input_list[1] == "script":
							print "[+] Script url/path: {}".format(self.script)
						elif self.input_list[1] == "gateway":
							print "[+] Gateway IP Address: {}".format(self.gateway)
						elif self.input_list[1] == "target":
							print "[+] Target(s): {}".format(self.targets)
						elif self.input_list[1] == "file":
							print "[+] File path: {}".format(self.file)
						elif self.input_list[1] == "arpmode":
							print "[+] ARP spoofing mode: {}".format(self.arpmode)
						else:
							print "[-] Select a valid variable name."

					elif self.input_list[0] == "scan":
						try:
							mode = self.input_list[1]
							if self.targets is not None and self.interface is not None:
								from modules.scanner import Scanner
								self.scan = Scanner(self.targets, self.interface, mode)
								self.scan.start()
							else:
								print "[!] You probably forgot to set the interface or a valid IP address/range."
						except IndexError:
							try:
								print "[*] Select one scan mode, options = tcp/arp/manual"
								mode = raw_input("[+] Scan mode: ")
							except KeyboardInterrupt:
								pass
							if self.targets is not None and self.interface is not None:
								from modules.scanner import Scanner
								self.scan = Scanner(self.targets, self.interface, mode)
								self.scan.start()
							else:
								print "[!] You probably forgot to set the interface or a valid IP address/range."
								pass

						except KeyboardInterrupt:
							pass
						except Exception as e:
							print "[!] Exception caught: {}".format(e)
							pass

					elif self.input_list[0] == "arpspoof":
                                        	try:
							if self.input_list[1] == "start":
	                                                	from modules.arpoisoner import ARPspoof
						                myip = get_myip(self.interface)
	                					mymac = get_mymac(self.interface)
								self.arpspoof_status = True
								self.spoof = ARPspoof(self.gateway, self.targets, self.interface,self.arpmode ,myip, mymac)
								self.spoof.start()
								print "[+] ARP spoofing initialized."

							elif self.input_list[1] == "stop":
								self.spoof.stop()
								self.arpspoof_status = False
								print "[+] ARP spoofing finalized."

                                                        elif self.input_list[1] == "status":
                                                                if self.arpspoof_status:
                                                                        stat = "running"
                                                                else:
                                                                        stat = "down"
                                                                print "[*] ARP spoofing status: {}".format(stat)



							else:
								print "[!] Select a valid option, call help to check syntax."
						
						except TypeError:
							print "[!] You probably forgot to set interface or gateway."
						except IndexError:
							print "[!] You probably forgot to type start or stop after arpspoof."
						except AttributeError:
							pass
						except Exception as e:
							print "[!] Exception caught: {}".format(e)

					elif self.input_list[0] == "dnsspoof":
						try:

							if self.input_list[1] == "start":
								if self.domain != None :
									domain = self.domain
								else:
									try: 
										domain = raw_input("[+] Domain to be spoofed: ")
										self.domain = domain
									except KeyboardInterrupt: pass

								if self.redirect != None:
									redirect = self.redirect
								else:
									myip = get_myip(self.interface)
									opt = raw_input("[+] Default address to redirect is:{} do you want to change?[y/n]".format(myip))
									if opt == "y" or opt == "Y" or opt == "yes" or opt == "YES": 
										try:redirect = raw_input("[+] IP address to be redirected: ")
										except KeyboardInterrupt: pass
									else:
										redirect = myip

								from modules.dnspoisoner import DNSspoof
								self.dnsspoof = DNSspoof(redirect)
								self.dnsspoof.start(domain,None)
								print "[+] DNS spoofing initialized"
								self.dnsspoof_status = True

							elif self.input_list[1] == "stop":
								self.dnsspoof.stop()
								print "[+] DNS spoofing finalized"

                                                        elif self.input_list[1] == "status":
                                                                if self.dnsspoof_status:
                                                                        stat = "running"
                                                                else:
                                                                        stat = "down"
                                                                print "[*] DNS spoofing status: {}".format(stat)


							else:
								print "[!] Select a valid option, call help to check syntax."
						except IndexError:
							print "[!] You probably forgot to type start or stop after dnsspoof."
						except Exception as e:
							print "[!] Exception caught: {}".format(e)

					elif self.input_list[0] == "inject":
						try:
							if self.input_list[1] == "start":
								myip = get_myip(self.interface)
								try:
									from modules.inject import Inject
									self.inject = Inject(myip,self.port,self.script)
									self.inject_status = True
									self.inject.server()
								except AttributeError:
									print "\n[!] Select a valid script source path or url."
								except Exception as e:
									print "[!] Exception caught: {}".format(e)

							elif self.input_list[1] == "stop":
								try:
									self.inject.stop()
									self.inject_status = False
								except Exception as e:
									print "[!] Exception caught: {}".format(e)

							elif self.input_list[1] == "status":
								if self.inject_status:
									stat = "running"
								else:
									stat = "down"
								print "[*] Script injection status: {}".format(stat)

							else:
								print "[!] You need to specify  start, stop or status after the inject module call."
						except IndexError:
							print "[!] You probably forgot to start or stop the inject module."
						except TypeError:
							print "[!] You probably forgot to start an arpspoof attack ."
						except Exception as e:
							print "[!] Exception caught: {}".format(e)

					elif self.input_list[0] == "dos":
						from modules.jammer import Jam
						self.dos = Jam()
						try:
							if self.input_list[1] == "mitmdrop":
								if self.arpspoof_status:
									try:
										myip = get_myip(self.interface)
										self.dos.mitmdropstart(myip)
										self.mitmdrop_status = 1
									except Exception as e:
										print "[!] Exception caught: {}".format(e)
								else:
									print "[!] You need to start a arpspoof on a target (IP/Range) to start mitmdrop."

							elif self.input_list[1] == "stop":
								if self.mitmdrop_status == 1:
									self.dos.mitmdropstop()
								else:
									print "[!] You need to start a DoS attack before call stop."
							else:
								print "[!] Select a valid option, type help to check syntax."


						except IndexError:
							print "[!] You probably forgot to specify the type of DoS to use."


					elif self.input_list[0] == "sniff":
						from modules.sniffer import Sniffer
						try:
							filter = " ".join(self.input_list[1:])
							self.sniff = Sniffer(self.interface, filter)
							self.sniff.start()
						except IndexError:
							filter = raw_input("[+] Enter the filter: ")
                                                	self.sniff = Sniffer(self.interface, filter)
                                                	self.sniff.start()
						except KeyboardInterrupt:
                                                	pass

					elif self.command == "pforensic":
						try:
							completer = None
							completer = Completer("pforensic")
							from modules.pforensic import PcapReader
							self.pcapread = PcapReader(self.file)
							self.pcapread.start()
						except KeyboardInterrupt:
							pass
						except TypeError:
							print "[!] You probably forgot to set the .pcap file"
							pass
						except Exception as e:
							print "[!] Exception caught: {}".format(e)
							pass

					elif self.input_list[0] == "xploit":
						try:
							completer = None
							completer = Completer("xploit")
							from modules.exploit import Exploit
							if self.targets is not None and self.input_list[1] == "tcp":
								self.xploit = Exploit(self.targets, self.input_list[1])
								self.xploit.start()
							elif self.file is not None and self.input_list[1] == "stdin":
								self.xploit = Exploit(self.file, self.input_list[1])
								self.xploit.start()
							else:
								print "[!] You need to set or stdin or tcp as argument."
								print "[!] You need to set or a file or a target to xploit."
						except IndexError:
							try:
								print "[*] Select one xploit mode, options = stdin/tcp"
								mode = raw_input("[+] Exploit mode: ")
								if mode == "stdin" or mode == "tcp":
									from modules.exploit import Exploit
									if self.targets is not None:
										self.xploit = Exploit(self.targets, mode)
										self.xploit.start()
									elif self.file is not None:
										self.xploit = Exploit(self.file, mode)
										self.xploit.start()
									else:
										print "[!] You need to set or a file or a target to xploit."
								else:
									print "[!] Select a valid xploit mode, stdin or tcp"
							except KeyboardInterrupt:
								pass
                                                except TypeError:
                                                        print "[!] You probably forgot to set the file"
                                                        pass
                                                except KeyboardInterrupt:
                                                        pass
                                                except Exception as e:
                                                        print "[!] Exception caught: {}".format(e)
                                                        pass

					elif self.command == "cookiedecode":
						try:
							cookiedecode()
						except KeyboardInterrupt:
							pass
						except Exception as e:
							print "[!] Exception caught: {}".format(e)
							pass



					elif self.input_list[0] == "decode":
						try:
							print decode(self.input_list[1])
						except KeyboardInterrupt:
							pass


					elif self.input_list[0] == "encode":
						try:
							print encode(self.input_list[1])
						except KeyboardInterrupt:
							pass


					elif self.input_list[0] == "geoip":
						try:
							self.targets = self.input_list[1]
							from modules.geoip import Geoip
							path = "config/GeoLiteCity.dat"
							iptracker = Geoip(self.targets,path)

						except IndexError:
							if self.targets is not None:
								from modules.geoip import Geoip
								path = "config/GeoLiteCity.dat"
								iptracker = Geoip(self.targets,path)
							else:
								print "[!] You probably forgot to set a target"

						except Exception as e:
								print "[!] Exception caught: {}".format(e)
								pass

					elif self.input_list[0] == "brute":
							if self.input_list[1] == "ssh":
								try:
									username = raw_input("[+] Enter the username to bruteforce: ")
									from modules.ssh_bruter import SSHbrutus
									brutus = SSHbrutus(self.targets, username, self.file)
									brutus.start()
                                                		except KeyboardInterrupt:
                                                        		brutus.stop()
									pass
                                                		except TypeError:
                                                        		print "[!] You probably forgot to set the wordlist file path."
                                                       			pass
							elif self.input_list[1] == "url":
								try:
									url = 'url'
									from modules.web_bruter import WEBbrutus
									brutus = WEBbrutus(self.targets, self.file)
									brutus.start(url)
								except KeyboardInterrupt:
									brutus.stop(url)
									pass
								except TypeError:
			                                      		print "[!] You probably forgot to set the wordlist file path."
									pass
							elif self.input_list[1] == "form":
								try:
									form = 'form'
									from modules.web_bruter import WEBbrutus
									brutus = WEBbrutus(self.targets, self.file)
									brutus.start(form)
								except KeyboardInterrupt:
									brutus.stop(form)
									pass
								except TypeError:
		                                            		print "[!] You probably forgot to set the wordlist file path."
									pass
							else:
								print "[!] Select a valid type of brute-force type help to check."
					else:
						try:
							os.system("{}".format(self.command))
							pass
						except Exception as e:
							print "[!] Select a valid option, type help to check syntax."
							pass
				except IndexError:
					pass

				except Exception as e:
					print "Exception caught: {}".format(e)



		except KeyboardInterrupt:
			print "\n[*] User requested shutdown."
			exit()
Example #31
0
class UI(object):

    def __init__(self):
        super(UI, self).__init__()
        self.pepper = None
        self.stop_words = []
        self.top_k = 5

        # Initialize Jarvis
        self.jarvis = Jarvis(stop_words = self.stop_words)

    def run(self):
        try:
            while(True):
                cmd = ""
                args = []
                raw = raw_input(">")
                try:
                    cmd_and_args = raw.split()
                    if len(cmd_and_args) == 0: continue
                    cmd, args = (cmd_and_args[0], cmd_and_args[1:])
                    if cmd not in self.whiteListedMethods():
                        print "No command %s" % cmd
                        cmd = "help"
                    f = operator.methodcaller(cmd, *args)
                except ValueError:
                    cmd = raw
                    if cmd not in self.whiteListedMethods():
                        print "No command %s" % cmd
                        cmd = "help"
                    f = operator.methodcaller(cmd)
                try:
                    f(self)
                except TypeError as e:
                    # TODO print help doc string for method in cmd.
                    print "Wrong arguments for %s" % cmd
                    self.help(cmd)
        except (UIQuitException, EOFError, KeyboardInterrupt) as e:
            print
            return

    def help(self, cmd=None):
        """Print out helpful information about available commands
            @usage help [command]
            @param command, optional, if present it will output only the help
            text for that command; default is to print out all commands' help
            text.
        """
        if cmd and str(cmd) in self.whiteListedMethods():
            print "{}:".format(cmd)
            doc_string = getdoc(getattr(self, cmd))
            if doc_string:
                help_text = doc_string.split('\n')
                for block in help_text:
                    print '\t{:<60}'.format(block.strip())
        else:
            # if a command was passed
            if cmd: print "No command: '%s'" % cmd
            for method in self.whiteListedMethods():
                print "{}:".format(method)
                doc_string = getdoc(getattr(self, method))
                if doc_string:
                    help_text = doc_string.split('\n')
                    for block in help_text:
                        print '\t{:<60}'.format(block.strip())


    def loadStopWords(self, stop_words_file_path):
        """Load the specified file of stop words
            @usage loadStopWords stop_words_file
            @param stop_words_file, required, the path to a file of stop words
        """
        try:
            with open(stop_words_file_path, 'r') as stop_words_file:
                self.stop_words = [word.strip() for word in stop_words_file.readlines()]
            self.jarvis.stop_words = self.stop_words
        except IOError:
            print "No file found at '%s'" % stop_words_file_path

    def quit(self):
        """Exit the interactive session"""
        raise UIQuitException()

    def buildIndex(self, target_url=None, treat_as_root=False, limit=500):
        """Build or add to the Index.
            @usage buildIndex [target_url] [treat_as_root] [limit]
            @param target_url, optional, a full URL (e.g. http://www.smu.edu)
            default is http://lyle.smu.edu/~fmoore/
            @param treat_as_root, optional signifier to treat the given URL as a
            root URL. e.g. treat a URL like, http://lyle.smu.edu/~fmoore/, as
            the root instead of the server instead of http://lyle.smu.edu/
            @param limit, optional limit the underlying crawler to N requests
        """
        # Use ~fmoore as the default target URL.
        if target_url is None:
            target_url = "http://lyle.smu.edu/~fmoore/"
            treat_as_root = True

        # Guard against invalid URLs.
        if not urlparse(target_url).scheme:
            print "Invalid URL: %s" % target_url
            print "HINT: Did you include the scheme? (e.g. http://)"
            return

        # Ensure boolean value safely
        treat_as_root = str(treat_as_root).lower() in ["yes", "y", "true", "t", "1"]

        # Ensure and force Integer value
        try:
            limit = int(limit)
        except ValueError:
            print "Invalid integer value for limit: '%s'" % limit
            print "Using 500 as default"
            limit = 500

        # Start the run
        self.jarvis.run(target_url, treat_as_root, limit)

        # After the run, grab all the necessary objects and output some basic stats
        fe = self.jarvis.ironman
        index = self.jarvis.index
        parser = self.jarvis.parser
        calculator = self.jarvis.calculator
        documents = self.jarvis.documents()

        print "\033[95mCrawl Results\033[0m"
        for category, results in fe.report.iteritems():
            print "\033[94m\t%s:\033[0m" % category
            for crawl in results:
                print"\t%s" % str(crawl)
        print

        # Print out number of unique documents encountered
        print "Encountered %i unique documents" % len(documents)
        print "Removed %i duplicates" % parser.num_duplicates
        print

        # Initialize Pepper to handle queries
        self.pepper = Pepper(documents, calculator, self.stop_words)

    def query(self, *user_query):
        """Run a query against the index
            @usage query query_word [more_query_words...]
            @param query_word, a string query of 1 or more words to search
            within the index.
            @example query foo bar hello world
        """
        if self.pepper is None:
            print "Index has not been built! Run `buildIndex` first."
            return
        if len(user_query) == 0:
            print "No query given!"
            return
        else:
            user_query = " ".join(user_query)

        index = self.jarvis.index
        calculator = self.jarvis.calculator

        print "| {0:>15} | {1:>15} | {2:>15} | {3:>14} |".format("Term", "DF", "IDF", "F")
        for term in self.pepper.p.stemText(user_query, self.stop_words).encode('utf_8', 'ignore').split():
            if not index.word_document_frequency.has_key(term): continue
            if not calculator.term_idfs.has_key(term): continue
            if not index.word_freq.has_key(term): continue

            df = index.word_document_frequency[term]
            idf = calculator.term_idfs[term]
            wf = index.word_freq[term]

            print "| {0:>15} | {1:>15d} | {2:>15f} | {3:>14d} |".format(term, df, idf, wf)
        print

        ranked_docs = self.pepper.handleQuery(user_query)
        i = 1
        for score, doc in ranked_docs:
            if score == 0: break
            if i == 1:
                print "{0:>15} | {1:>15} | {2:>15} | {3:>14}".format("Rank", "Score", "Document", "ID")
            print "{0:>15} | {1:15f} | {2:15s} | {3:14s}".format(i, score, doc.url, doc.id)
            i += 1
            if i > self.top_k: break
        print
        if i == 1:
            print "No results found for that query :("
        else:
            if i < self.top_k:
                print "NOTE: Only outputted top {:d} documents, as all other "\
                "documents had zero scores".format(i-1)
            top_doc = ranked_docs[0][1]
            print "First 20 words of top ranked document: %s" % top_doc.url
            print "%s..." % " ".join(top_doc.full_text.split()[0:20])


    def setK(self, k=5):
        """Set the maximum number of K results to show in a query (default is 5)
            @usage setK [k]
            @param k, optional, an integer value representing the number of
            results to show from queries. If left blank, it is set to 5.
        """
        # Ensure and force Integer value
        try:
            k = int(k)
            self.top_k = k
        except ValueError:
            print "Invalid integer value for k: '%s'" % k

    def showDoc(self, docID):
        """Show the document with the given ID
            @usage showDoc bef194481a024c4cf9178e5e421529b4
            @param docID, required, the hash ID of the document (partials are
            matched, but may return multiples if not enough of the hash is
            given).
        """
        id_re = re.compile(re.escape(docID))
        matches = []
        for doc in self.pepper.documents:
            if id_re.match(doc.id):
                matches.append(doc)
        if len(matches) > 0:
            if len(matches) != 1:
                print "Warning, more than one document found matching that id."
            for doc in matches:
                print "Document ID: {}".format(doc.id)
                print "Document URL: {}".format(doc.url)
                print "Word Frequencies:"
                pprint(doc.word_vector)
                print "Normalized Document Vector:"
                pprint(doc.normalized_tf)
                print doc.full_text
        else:
            print "No document found with ID = {}".format(docID)

    def whiteListedMethods(self):
        return ["help", "setK", "buildIndex", "query", "loadStopWords", "quit", "showDoc"]

    def completer(self, text, state):
        matches = []
        p = re.compile(re.escape(text))
        for m in self.whiteListedMethods():
            if p.match(m):
                matches.append(m)
        try:
            return matches[state]
        except IndexError:
            return None
Example #32
0
def run(mother):
    category = mother.categories['Study']
    for page in category:
        oldtext = page.text()
        p = mwparserfromhell.parse(oldtext)
        template = study_template(p)
        if template:
            logging.debug(
                "Page {} has template {} with these params: {}".format(
                    page.name, template.name.rstrip(), template.params))

            try:
                jarvis_id = template.get("JARVIS ID").value.rstrip()
            except ValueError:
                # Skip JARVIS integration if there's no id
                logging.warning("No JARVIS ID on study page %s" % page.name)
                pass
            else:
                try:
                    # Pull stuff out of JARVIS and put it into the template params
                    j = Jarvis()

                    logging.info("JARVIS id for %s is %s" %
                                 (page.name, jarvis_id))
                    irb_exp = j.irb_expirations(jarvis_id)
                    if irb_exp:
                        template.add("JARVIS IRB Expiration", irb_exp)
                    quota = j.total_active_quota(jarvis_id)
                    if quota:
                        template.add("JARVIS Study Drive Quota", quota)

                    # Personnel is a different section of the document, so replace that
                    personnel = j.personnel(jarvis_id)
                    old_sections = p.get_sections(matches="JARVIS Personnel")
                    if len(old_sections) > 0:
                        old_personnel = old_sections[0]
                        p.replace(old_personnel, personnel)

                except Exception as e:
                    # Print the error and keep going
                    logging.error(
                        f"Problem fetching from JARVIS on study page {page.name}: {traceback.print_exc()}"
                    )
                    pass

            try:
                nih_id = template.get("NIH RePORTER ID").value.rstrip()
            except ValueError:
                # We just skip NIH integration if there's no id or we fail in any way
                logging.warning("No NIH ID on study page %s" % page.name)
                pass
            else:
                # award date, NIH start / end dates, break out official NIH title
                logging.info("NIH id for %s is %s" % (page.name, nih_id))
                nih_url = "https://api.federalreporter.nih.gov/v1/Projects?nihApplId=" + nih_id
                resp = requests.get(nih_url)

                if resp.status_code != 200:
                    logging.warning("GET {} {}".format(nih_url,
                                                       resp.status_code))
                else:
                    data = resp.json()
                    template.add("NIH Title", data['title'])
                    template.add("NIH Fiscal Year", data['fy'])
                    template.add("NIH Budget Start Date",
                                 jsondate_to_str(data['budgetStartDate']))
                    template.add("NIH Budget End Date",
                                 jsondate_to_str(data['budgetEndDate']))
                    template.add("NIH Project Start Date",
                                 jsondate_to_str(data['projectStartDate']))
                    template.add("NIH Project End Date",
                                 jsondate_to_str(data['projectEndDate']))

        newtext = str(p)
        newtext = newtext.replace(
            "<noinclude>NOTE: This is prefab content inserted in new study pages</noinclude>",
            "")

        if oldtext.strip() != newtext.strip():
            logging.warning("Updating study page %s, change detected",
                            page.name)
            page.save(
                newtext,
                "Automated edit to update study values from JARVIS and NIH")
        else:
            logging.info("Not updating study page %s, text identical",
                         page.name)
Example #33
0
from jarvis import Jarvis

jarvis_speech_assitant = Jarvis()
jarvis_speech_assitant.get_user_name()
jarvis_speech_assitant.vocal_assistant()
Example #34
0
 def __init__(self, gid=TEST_GROUP_ID):
     data = json.load(open("creds.json", 'r'))
     self.jarvis = Jarvis(data['id'], data['password'], gid)