def scan_arbitrary_ip(): ip = NumpadIPAddressInput(i, o, message="IP to scan:", debug=True).activate() if ip is None: return #Cancelled valid_ip = False while not valid_ip: #Validating the IP in a loop try: ip = cleanup_validate_ip(ip) except ValueError as e: #If not valid, giving an opportunity to either fix it or cancel the scan Printer( ffs("Invalid ip: {}! Reason: {}".format(ip, e.message), o.cols), i, o, 3) ip = NumpadIPAddressInput(i, o, message="Fix the IP", value=ip, debug=True).activate() if ip is None: return #Cancelled #To the next loop iteration else: valid_ip = True if "/" in ip: #Network address with a netmask, interpreting it as a network address and just calling nmap quick_scan_network_by_ip(ip) elif "*" in ip: Printer( ffs( "Wildcards without a netmask are not yet supported by the interface, sorry", o.cols), i, o, 3) return else: scan_ip(ip)
def call_external(script_list, shell=False): if shell == True: script_path = script_list.split(' ')[0] else: script_path = os.path.split(script_list[0])[1] Printer("Calling {}".format(script_path), i, o, 1) try: output = check_output(script_list, stderr=STDOUT, shell=shell) except OSError as e: if e.errno == 2: Printer("File not found!", i, o, 1) elif e.errno == 13: Printer(["Permission", "denied!"], i, o, 1) elif e.errno == 8: Printer(["Unknown format,", "forgot header?"], i, o, 1) else: error_data = ["Unknown error", ""] error_data += ffs(repr(e), o.cols) Printer(error_data, i, o, 1) output = "" except CalledProcessError as e: Printer(["Failed with", "code {}".format(e.returncode)], i, o, 1) output = e.output else: Printer("Success!", i, o, 1) finally: if not output: return answer = DialogBox("yn", i, o, message="Show output?").activate() if answer == True: Printer(ffs(output, o.cols, False), i, o, 5, True)
def smart_scan(): #First, getting all available interfaces networks = [] interface_data = get_ip_addr() for interface_name in interface_data.keys(): #Autofiltering unsuitable interfaces interface_info = interface_data[interface_name] state = interface_info["state"] ip = interface_info["addr"] if interface_info["addr"] else None if state == "up" and ip is not None: #Only using interface if it's up and has an IP #Automatically filters out localhost networks.append(["{}:{}".format(interface_name, ip), ip]) if not networks: #No suitable interfaces found after filtering Printer(ffs("No suitable network interfaces found!", o.cols), i, o, 3) return None if len(networks) == 1: #Only one good interface, using it automatically network_ip = networks[0][1] else: #Allowing user to pick an interface network_ip = Listbox(networks, i, o).activate() if network_ip is None: #Listbox exited without making a choice return None network_ip = get_network_from_ip(network_ip) chosen_ports = Checkbox(heuristic_ports, i, o, name="NMap: select port types", final_button_name="Run scan").activate() if chosen_ports is None: return None chosen_port_list = [ port_choice for port_choice in chosen_ports if chosen_ports[port_choice] == True ] port_string = ",".join(chosen_port_list) #So the library I'm using is silently failing. I launch the scan from command-line and see: # #WARNING: Duplicate port number(s) specified. Are you alert enough to be using Nmap? Have some coffee or Jolt(tm). # #Well, thank you, but it's a script and f**k off. port_string = ",".join(list(set(port_string.split(",")))) #De-duplicated and ready to go. print(port_string) Printer(ffs("Scanning {}".format(network_ip), o.cols), i, o, 0) nm = nmap.PortScanner() nm.scan(network_ip, arguments="-n -p {}".format(port_string)) print(nm) show_quick_scan_results_for_network(network_ip, nm)
def call(number): Printer("Calling {}".format(number), i, o, 0) try: phone.call(number) except ATError as e: Printer(ffs("Calling fail! "+repr(e), o.cols), i, o, 0) print("Function stopped executing")
def init_app(input, output): global callback, i, o i = input o = output lsusb_output = check_output(['lsusb']) callback = lambda: Printer( ffs(lsusb_output, o.cols), i, o, sleep_time=5, skippable=True)
def callback(): if not check_modem_connection(): Printer(ffs("Modem connection failed. Try again in 10 seconds.", o.cols), i, o) return contents = [["Status", status_refresher], ["Call", call_view]] Menu(contents, i, o).activate()
def call_external(script_list, shell=False): if shell == True: script_path = script_list.split(' ')[0] else: script_path = os.path.split(script_list[0])[1] Printer("Calling {}".format(script_path), i, o, 1) try: output = check_output(script_list, stderr=STDOUT, shell=shell) except OSError as e: if e.errno == 2: Printer("File not found!", i, o, 1) elif e.errno == 13: Printer(["Permission", "denied!"], i, o, 1) else: Printer("Unknown error!", i, o, 1) output = "" except CalledProcessError as e: Printer(["Failed with", "code {}".format(e.returncode)], i, o, 1) output = e.output else: Printer("Success!", i, o, 1) finally: if not output: return answer = DialogBox("yn", i, o, message="Show output?").activate() if answer == True: Printer(ffs(output, o.cols, False), i, o, 5, True)
def adjust_timeout(): global config timeout = IntegerAdjustInput(config["timeout"], i, o, message="Socket timeout:").activate() if timeout is not None and timeout > 0: config["timeout"] = timeout write_config(config, config_path) elif not timeout > 0: Printer(ffs("Timeout has to be larger than 0!", o.cols), i, o)
def callback(): """A function that's called when the app is selected in the menu""" Printer(ffs( "Hello and welcome to Aperture Science computer aided enrichment center", o.cols), i, o, sleep_time=5, skippable=True)
def callback(): #Check if we have all the software necessary for the app to work #If not, show error messages and exit if nmap is None: Printer(ffs("nmap Python module not found!", o.cols), i, o, 3) return False try: nm = nmap.PortScanner() except nmap.nmap.PortScannerError: Printer(ffs("nmap not installed!", o.cols), i, o, 3) return False #Dump function support i.set_maskable_callback("KEY_F5", dump_current_scan_to_file) #Constructing and loading app main menu menu_contents = [["Smart scan", smart_scan], ["Scan a network", scan_network_menu], ["Scan arbitrary IP", scan_arbitrary_ip], ["Scan localhost", scan_localhost]] Menu(menu_contents, i, o).activate() #Have to remove the dump function callback because once application exits it isn't removed automatically i.remove_maskable_callback("KEY_F5")
def check_modem_connection(bg=False): global modem, phone, connecting if not bg: Printer(ffs("Connecting to modem", o.cols), i, o, 0) if connecting.isSet(): return False if phone.modem is not None: return True connecting.set() try: modem = Modem() modem.init_modem() modem.start_monitoring() phone.attach_modem(modem) connecting.clear() return True except ValueError as e: print(repr(e)) #Rollback if not bg: Printer(ffs("Modem connection failed", o.cols), i, o) modem.stop_monitoring() modem.deinit_modem() modem = None connecting.clear() return False
def pylprint(phrase): Printer(ffs(phrase, o.cols, break_words=False), i, o, 3, skippable=True)
def read_info(ip_str, data): Printer(ffs("[+] {}\n{}".format(ip_str, data), o.cols), i, o, 5)
def usb_read(): """Gets the report data from SJM-marked partitions""" unfiltered_partitions = get_partitions() #Raspberry Pi-specific filtering partitions = filter(lambda p: not p["path"].startswith("/dev/mmcblk0"), unfiltered_partitions) possible_parts = [] for partition in partitions: if not partition["mounted"]: continue path = partition["mountpoint"] if libmerlin.has_merlin_files(path) or libmerlin.has_fs_dump(path): possible_parts.append(partition) if not possible_parts: pylprint("No drives with data found!") return elif len(possible_parts) > 1: pylprint("Select source drive") lb_contents = [[pretty_part_name(part), part] for part in possible_parts] current_partition = Listbox(lb_contents, i, o, "Partition selection listbox").activate() if not current_partition: pylprint("Aborting!") return else: current_partition = possible_parts[0] pylprint("A drive with data found!") #Now working on the partition found current_path = current_partition["mountpoint"] partitions.remove(current_partition) mounted_partitions = [ partition for partition in partitions if partition["mounted"] ] if not mounted_partitions: pylprint("No partitions to transfer data to found!") return Printer(ffs("Choose transfer destination", o.cols, break_words=False), i, o, 1) lb_contents = [[pretty_part_name(part), part] for part in mounted_partitions] selected_partition = Listbox(lb_contents, i, o, "").activate() if not selected_partition: Printer("Aborted", i, o, 1) return selected_path = selected_partition["mountpoint"] if libmerlin.has_merlin_files(current_path): pylprint("Transferring report files") #"Transfer or copy" feature not implemented until requested #answer = DialogBox([["Copy", True], ["Transfer", False]], i, o, "Transfer or copy?").activate() #if answer is None: Printer("Aborted", i, o, 1, skippable=True); return report_path = libmerlin.transfer_reports(current_path, selected_path) #if answer == True: # libmerlin.copy_reports(current_path, selected_path) print(report_path) report_folder = os.path.basename(report_path) print(report_folder) pylprint("Folder: {}".format(report_folder)) if not config["never_send_reports"]: pylprint("Agree to share report files with ICeeData?") answer = Dialog( [["Yes", True], ["No", False], ["Never", "fuckno"]], i, o, "Share files?").activate() if answer is True: Printer("Sending files...", i, o, 0.1) libmerlin.share_reports(report_path) elif answer == "fuckno": config["never_send_reports"] = True write_config() pylprint("Successfully transferred_reports!") if libmerlin.has_fs_dump(current_path): #I decided to send FS dumps automatically. If they're there, that means user has agreed to help dump them while preparing the flash drive and software placed a dumping script. #pylprint("Filesystem image found! Agree to send it to ICeeData?") #answer = DialogBox("yn", i, o, "Send image?").activate() #if answer == True: try: libmerlin.send_fs_dump(current_path) except IOError: libmerlin.store_fs_dump(current_path)
def test_ffs(self): """Tests format_for_screen""" assert (ffs("Hello", 16) == ["Hello "]) assert (ffs("may I have some loops brother", 16) == ['may I have some ', 'loops brother '])
def init_app(input, output): global callback, i, o i = input; o = output lsusb_output = check_output(['lsusb']) callback = lambda: Printer(ffs(lsusb_output, o.cols), i, o, sleep_time=5, skippable=True)
def terms_conditions(): with open('terms_and_conditions.txt', 'r') as f: text = ''.join(f.readlines()) formatted_text = ffs(text, o.cols, break_words=False) Printer(formatted_text, i, o, 5)
def privacy_policy(): with open('privacy_policy.txt', 'r') as f: text = ''.join(f.readlines()) formatted_text = ffs(text, o.cols, break_words=False) Printer(formatted_text, i, o, 5)