def server_to_defend(ip): if APP_DEBUG: Log.info('CALLED: Add.server_to_defend(' + str(ip) + ')') if not validators.is_ip(ip): Log.error(str(ip) + ' is not a valid ip address') return False return Add.__add__(keys.SERVER_TO_DEFEND, ip)
def game_server(ip): if APP_DEBUG: Log.info('CALLED: Set.game_server(' + str(ip) + ')') if not validators.is_ip(ip): Log.error(str(ip) + ' is not a valid ip address') return False return Set.__set__(keys.GAME_SERVER, ip)
def team_player(ip='*'): if APP_DEBUG: Log.info('CALLED: Remove.team_player(' + str(ip) + ')') if ip != '*' and not validators.is_ip(ip): Log.error(str(ip) + ' is not a valid ip address') return False return Remove.__remove__(keys.TEAM_PLAYER, ip)
def __init__(self, host='0.0.0.0', port=8775): self.host = host self.port = port # Start the sqlmap-api server in a parallel thread Log.info("Starting sqlmap-api server in a parallel thread") multithread(sqlmap_server, (self.host, self.port), True, 1) Log.success("Sqlmap-api server started!")
def regex_in_string(regex, string): if APP_DEBUG: Log.info('CALLED: regex_in_string(' + str(regex) + ', ' + str(string) + ')') reg = re.compile(regex) matches = re.findall(reg, string) return len(matches) > 0
def server_to_defend(ip='*'): if APP_DEBUG: Log.info('CALLED: Remove.server_to_defend(' + str(ip) + ')') if ip != '*' and not validators.is_ip(ip): Log.error(str(ip) + ' is not a valid ip address') return False return Remove.__remove__(keys.SERVER_TO_DEFEND, ip)
def team_player(ip): if APP_DEBUG: Log.info('CALLED: Add.team_player(' + str(ip) + ')') if not validators.is_ip(ip): Log.error(str(ip) + ' is not a valid ip address') return False return Add.__add__(keys.TEAM_PLAYER, ip)
def submit_url(url): if APP_DEBUG: Log.info('CALLED: Set.submit_url(' + str(url) + ')') if not validators.is_url(url): Log.error(str(url) + ' is not a valid url') return False return Set.__set__(keys.SUBMIT_URL, url)
def my_ip(ip): if APP_DEBUG: Log.info('CALLED: Set.my_ip(' + str(ip) + ')') if not validators.is_ip(ip): Log.error(str(ip) + ' is not a valid ip address') return False return Set.__set__(keys.MY_IP, ip)
def try_inject(forms, cookies=''): """ Try injection in all provided forms :param forms: dict A dictionary of { "<url>": [ <parsed_form_1>, <parsed_form_2>, ... ], ... } :param cookies: str the request cookies """ if SqlmapClient._client is None: SqlmapClient._client = SqlmapClient() pprint(forms) Log.info('Trying injection with cookies: ' + str(cookies)) Log.error("try_inject: Not Implemented")
def multi_request(urls, request_type=Type.GET, data=None, headers=None): if APP_DEBUG: Log.info('CALLED: multi_request(' + str(urls) + ', ' + str(request_type) + ', ' + str(data) + ')') request_type = request_type.lower() for url in urls: r = request(url, request_type, data, headers) if r is None: continue if APP_DEBUG: try: print(r.json()) except json.decoder.JSONDecodeError or simplejson.errors.JSONDecodeError: print(r.text)
def deep_inject_form(url, max_depth): """ Search a form in the page returned by url. If it doesn't find a form, or the injection can't be done, it visit the website in search for other forms :param url: str The url to visit :param max_depth: int The max depth during the visit :return A dictionary of parsed forms like { '<visited_url>': [ form_1, form_2, ... } """ base_url = urlparse(url).netloc parsed_forms = dict() out_file = APP_STORAGE_OUT + '/' + now() + '_DEEP_FORMS_' + base_url + '.json' def _deep_inject_form(href, depth=1): # Check the domain if href in parsed_forms or urlparse(href).netloc != base_url or (max_depth is not None and depth > max_depth): return '' # Visit the current href parsed_relevant, request_cookies = relevant_parse(href) parsed_forms[href] = find_forms(parsed_relevant, href) # Find adjacent links links = find_links(parsed_relevant) if len(parsed_forms) % 10 == 0: Log.info('Writing result in ' + out_file + '...') set_json(parsed_forms, out_file) # Visit adjacent links for link in links: # print('link: '+link) child_request_cookies = _deep_inject_form(link, depth+1) if len(child_request_cookies) > len(request_cookies): request_cookies = child_request_cookies return request_cookies cookies = _deep_inject_form(url) Log.info('Writing result in ' + out_file + '...') set_json(parsed_forms, out_file) Log.success('Result wrote in ' + out_file) Log.success('Website crawled! Found '+str(len(parsed_forms))+' pages') SqlmapClient.try_inject(parsed_forms, cookies) return parsed_forms
def _deep_inject_form(href, depth=1): # Check the domain if href in parsed_forms or urlparse(href).netloc != base_url or (max_depth is not None and depth > max_depth): return '' # Visit the current href parsed_relevant, request_cookies = relevant_parse(href) parsed_forms[href] = find_forms(parsed_relevant, href) # Find adjacent links links = find_links(parsed_relevant) if len(parsed_forms) % 10 == 0: Log.info('Writing result in ' + out_file + '...') set_json(parsed_forms, out_file) # Visit adjacent links for link in links: # print('link: '+link) child_request_cookies = _deep_inject_form(link, depth+1) if len(child_request_cookies) > len(request_cookies): request_cookies = child_request_cookies return request_cookies
def print_request(_request, limit=1000): Log.info(str(_request.url)) Log.info(' |--- status_code: ' + str(_request.status_code)) Log.info(' |--- encoding: ' + str(_request.encoding)) Log.info(' |--- headers:') for key, value in _request.headers.items(): Log.info(' | |--- ' + str(key) + ': ' + str(value)) Log.info(' |') try: json_body = _request.json() Log.info(' |-- data: ' + str(json_body)) except ValueError: data = str(_request.text) if len(data) > limit: data = '[truncated]' + data[0:limit] Log.info(' |-- data: ' + data)
def flag_regex(): if APP_DEBUG: Log.info('CALLED: Remove.flag_regex()') return Set.__set__(keys.FLAG_REGEX, None)
def django_gui(): sys.path.insert(0, os.path.dirname(__file__)) bind_host = _get_bind_socket() Log.info("Starting " + str(APP_NAME) + ' GUI') sys.argv = [sys.argv[0], 'web.wsgi', '-b', bind_host] gunicorn_run()
def pexec(*args): if APP_DEBUG: Log.info('CALLED: pexec' + str(args)) """
def all(): if APP_DEBUG: Log.info('CALLED: Get.all()') return Get.__get__()
def my_ip(): if APP_DEBUG: Log.info('CALLED: Get.my_ip()') return Get.__get__(keys.MY_IP)
def my_interface(): if APP_DEBUG: Log.info('CALLED: Get.my_interface()') return Get.__get__(keys.MY_INTERFACE)
def team_token(): if APP_DEBUG: Log.info('CALLED: Get.team_token()') return Get.__get__(keys.TEAM_TOKEN)
def flag_regex(regex): if APP_DEBUG: Log.info('CALLED: Set.flag_regex(' + str(regex) + ')') return Set.__set__(keys.FLAG_REGEX, regex)
def game_server(): if APP_DEBUG: Log.info('CALLED: Get.game_server()') return Get.__get__(keys.GAME_SERVER)
def submit_url(): if APP_DEBUG: Log.info('CALLED: Get.submit_url()') return Get.__get__(keys.SUBMIT_URL)
def team_token(token): if APP_DEBUG: Log.info('CALLED: Set.team_token(' + str(token) + ')') return Set.__set__(keys.TEAM_TOKEN, token)
def start(self, target, args, asynchronous, cpu): self.tasks = [] def task_target(*arguments): result = None if self.tasks_type == MultiTask.MULTI_PROCESSING: curr_task = multiprocessing.process.current_process() Log.info(self.tag + 'started (PID=' + str(curr_task.pid) + ')') else: curr_task = threading.current_thread() Log.info(self.tag + 'started') if target is not None: result = target(*arguments) if result is not None: Log.success("Result: " + str(result)) # Scrivo il risultato nel file Log.info('Writing result in ' + str(self.resfile)) storage.overwrite_file(str(result), self.resfile) # Termino tutti gli altri threads/processi if self.tasks_type == MultiTask.MULTI_PROCESSING: Log.info('Killing other processes') running_pids = storage.read_file(self.pidfile).split(', ') for pid in running_pids: pid = int(pid) if pid == curr_task.pid: continue try: os.kill(pid, signal.SIGKILL) Log.info('Process ' + str(pid) + ' killed!') except Exception as e: Log.error(str(e)) Log.info(self.tag + 'end') else: Log.info('Ignoring other threads') # Killa se stesso pid = multiprocessing.process.current_process().pid Log.info(self.tag + 'end') os.kill(pid, signal.SIGKILL) for i in range(0, cpu): task_args = () for arg in args: Log.info('Argument type: ' + str(type(arg))) if is_listable(arg): # Divido gli elementi in 1/cpu parti p_list_len = (len(arg) / cpu) + (len(arg) % cpu) if type(arg) == dict: iterator = iter(arg.items()) task_args += ( dict(itertools.islice(iterator, int((i * p_list_len)), int((i + 1) * p_list_len))), ) else: task_args += (arg[int((i * p_list_len)):int(((i + 1) * p_list_len))],) else: task_args += (arg,) task = self.Multitask(target=task_target, args=task_args) self.tasks.append(task) if self.tasks_type == MultiTask.MULTI_PROCESSING: pids = [] for task in self.tasks: task.start() # noinspection PyUnresolvedReferences pids.append(task.pid) storage.overwrite_file(str(pids).strip('[]'), self.pidfile) else: for task in self.tasks: task.start() if not asynchronous: # Attende la fine dell'esecuzione di tutti i tasks for task in self.tasks: task.join() Log.info('Task ' + str(task.name) + ' joined') Log.info('Reading result in ' + str(self.resfile)) # Prendo il risultato dal file res = storage.read_file(self.resfile) # Elimino l'eventuale file con i pid storage.delete(self.pidfile) # Elimino il file con il risultato storage.delete(self.resfile) Log.success('MultiTask -> result: ' + str(res)) return res return None
def flag_regex(): if APP_DEBUG: Log.info('CALLED: Get.flag_regex()') return Get.__get__(keys.FLAG_REGEX)
def server_to_attack(): if APP_DEBUG: Log.info('CALLED: Get.server_to_attack()') return Get.__get__(keys.SERVER_TO_ATTACK)
def task_target(*arguments): result = None if self.tasks_type == MultiTask.MULTI_PROCESSING: curr_task = multiprocessing.process.current_process() Log.info(self.tag + 'started (PID=' + str(curr_task.pid) + ')') else: curr_task = threading.current_thread() Log.info(self.tag + 'started') if target is not None: result = target(*arguments) if result is not None: Log.success("Result: " + str(result)) # Scrivo il risultato nel file Log.info('Writing result in ' + str(self.resfile)) storage.overwrite_file(str(result), self.resfile) # Termino tutti gli altri threads/processi if self.tasks_type == MultiTask.MULTI_PROCESSING: Log.info('Killing other processes') running_pids = storage.read_file(self.pidfile).split(', ') for pid in running_pids: pid = int(pid) if pid == curr_task.pid: continue try: os.kill(pid, signal.SIGKILL) Log.info('Process ' + str(pid) + ' killed!') except Exception as e: Log.error(str(e)) Log.info(self.tag + 'end') else: Log.info('Ignoring other threads') # Killa se stesso pid = multiprocessing.process.current_process().pid Log.info(self.tag + 'end') os.kill(pid, signal.SIGKILL)
def my_interface(interface): if APP_DEBUG: Log.info('CALLED: Set.my_interface(' + str(interface) + ')') return Set.__set__(keys.MY_INTERFACE, interface)