def _get_ips(org_id, domain_address, ip_address, port, content, iplocation, port_status, color_tag, memo_content): '''获取IP ''' ip_table = Ip() aip = AssertInfoParser() ip_list = [] ips = ip_table.gets_by_search(org_id=org_id, domain=domain_address, ip=ip_address, port=port, content=content, iplocation=iplocation, port_status=port_status, color_tag=color_tag, memo_content=memo_content, page=1, rows_per_page=100000) if ips: for i, ip_row in enumerate(ips): ip_info = aip.get_ip_info(ip_row['id']) ip_info.update(index=i + 1) ip_list.append(ip_info) return ip_list
def statistics_ip(self, org_id=None, domain_address=None, ip_address=None, port=None, content=None, iplocation=None, port_status=None, color_tag=None, memo_content=None): '''根据查询条件,统计IP、IP的C段地址和相关的所有端口 ''' ip_table = Ip() port_table = Port() ip_list = [] ip_port_list = [] ip_c_set = set() port_set = set() # 统计每个端口出现的次数 port_count_dict = defaultdict(lambda: 0) ips = ip_table.gets_by_search(org_id=org_id, domain=domain_address, ip=ip_address, port=port, content=content, iplocation=iplocation, port_status=port_status, color_tag=color_tag, memo_content=memo_content, page=1, rows_per_page=100000) if ips: for ip_row in ips: # ip ip_list.append(ip_row['ip']) # C段 ip_c = ip_row['ip'].split('.')[0:3] ip_c.append('0/24') ip_c_set.add('.'.join(ip_c)) # port ports_obj = port_table.gets(query={'ip_id': ip_row['id']}) for port_obj in ports_obj: port_set.add(port_obj['port']) port_count_dict[str(port_obj['port'])] += 1 ip_port_list.append('{}:{}'.format(ip_row['ip'], port_obj['port'])) return ip_list, ip_c_set, port_set, port_count_dict, ip_port_list
def export_ip_memo(self, org_id=None, domain_address=None, ip_address=None, port=None, content=None, iplocation=None, port_status=None, color_tag=None, memo_content=None, date_delta=None): '''导出ip相关的备忘录信息 ''' ip_table = Ip() memo_table = IpMemo() memo_list = [] ips = ip_table.gets_by_search(org_id=org_id, domain=domain_address, ip=ip_address, port=port, content=content, iplocation=iplocation, port_status=port_status, color_tag=color_tag, memo_content=memo_content, date_delta=date_delta, page=1, rows_per_page=100000) if ips: for ip_row in ips: memo_obj = memo_table.get(ip_row['id']) if memo_obj: memo_list.append('[+]{}'.format(ip_row['ip'])) memo_list.append(memo_obj['content']) memo_list.append("") return memo_list
def ip_asset_view(): '''IP资产列表展示 ''' if request.method == 'GET': org_table = Organization() org_list = org_table.gets() if not org_list: org_list = [] org_list.insert(0, {'id': '', 'org_name': '--组织机构--'}) data = {'org_list': org_list, 'ip_address_ip': session.get('ip_address_ip', default=''), 'domain_address': session.get('domain_address', default=''), 'port': session.get('port', default=''), 'session_org_id': session.get('session_org_id', default='')} return render_template('ip-list.html', data=data) ip_table = Ip() org_table = Organization() aip = AssertInfoParser() ip_list = [] json_data = {} index = 1 try: draw = int(request.form.get('draw')) start = int(request.form.get('start')) length = int(request.form.get('length')) org_id = request.form.get('org_id') ip_address = request.form.get('ip_address') domain_address = request.form.get('domain_address') port = request.form.get('port') content = request.form.get('content') iplocation = request.form.get('iplocation') session['ip_address_ip'] = ip_address session['domain_address'] = domain_address session['port'] = port session['session_org_id'] = org_id count = 0 ips = ip_table.gets_by_search(org_id=org_id, domain=domain_address, ip=ip_address, port=port, content=content, iplocation=iplocation, page=(start//length)+1, rows_per_page=length) if ips: for ip_row in ips: port_list, title_set, banner_set, ports_attr_info = aip.get_ip_port_info( ip_row['ip'], ip_row['id']) ip_list.append({ 'id': ip_row['id'], "index": index+start, "org_name": org_table.get(int(ip_row['org_id']))['org_name'] if ip_row['org_id'] else '', "ip": ip_row['ip'], "status": ip_row['status'], "location": ip_row['location'].split(',')[0] if ip_row['location'] else '', "create_time": str(ip_row['create_datetime']), "update_time": str(ip_row['update_datetime']), "port": port_list, "title": ', '.join(list(title_set)), "banner": ', '.join(list(banner_set)) }) index += 1 count = ip_table.count_by_search(org_id=org_id, domain=domain_address, ip=ip_address, port=port, content=content, iplocation=iplocation) json_data = { 'draw': draw, 'recordsTotal': count, 'recordsFiltered': count, 'data': ip_list } except Exception as e: logger.error(traceback.format_exc()) print(e) return jsonify(json_data)
def ip_asset_view(): '''IP资产列表展示 ''' if request.method == 'GET': org_table = Organization() org_list = org_table.gets() if not org_list: org_list = [] org_list.insert(0, {'id': '', 'org_name': '--全部--'}) data = { 'org_list': org_list, 'ip_address_ip': session.get('ip_address_ip', default=''), 'domain_address': session.get('domain_address', default=''), 'port': session.get('port', default=''), 'session_org_id': session.get('session_org_id', default=''), 'pocsuite3_poc_files': Pocsuite3().load_poc_files(), 'xray_poc_files': XRay().load_poc_files() } return render_template('ip-list.html', data=data) ip_table = Ip() org_table = Organization() ip_color_tag_table = IpColorTag() ip_memo_table = IpMemo() aip = AssertInfoParser() ip_list = [] json_data = {} index = 1 try: draw = int(request.form.get('draw')) start = int(request.form.get('start')) length = int(request.form.get('length')) org_id = request.form.get('org_id') ip_address = request.form.get('ip_address') domain_address = request.form.get('domain_address') port = request.form.get('port') content = request.form.get('content') iplocation = request.form.get('iplocation') port_status = request.form.get('port_status') color_tag = request.form.get('color_tag') memo_content = request.form.get('memo_content') date_delta = request.form.get('date_delta') session['ip_address_ip'] = ip_address session['domain_address'] = domain_address session['port'] = port session['session_org_id'] = org_id count = 0 ips = ip_table.gets_by_search(org_id=org_id, domain=domain_address, ip=ip_address, port=port, content=content, iplocation=iplocation, port_status=port_status, color_tag=color_tag, memo_content=memo_content, date_delta=date_delta, page=(start // length) + 1, rows_per_page=length) if ips: for ip_row in ips: # 查询每一个IP的详细属性 port_list, title_set, banner_set, _, port_status_dict = aip.get_ip_port_info( ip_row['ip'], ip_row['id']) # 端口+HTTP状态码 port_with_status_list = [] for p in port_list: if str(p) in port_status_dict and re.match( r'^\d{3}$', port_status_dict[str(p)]): port_with_status_list.append("{}[{}]".format( p, port_status_dict[str(p)])) else: port_with_status_list.append(str(p)) # 获取颜色标记 color_tag_obj = ip_color_tag_table.get(ip_row['id']) # 获取备忘录信息 memo_obj = ip_memo_table.get(ip_row['id']) # 获取IP关联的漏洞信息: vul_info = [] vul_results = Vulnerability().gets({'target': ip_row['ip']}) if vul_results and len(vul_results) > 0: for v in vul_results: vul_info.append('{}/{}'.format(v['poc_file'], v['source'])) # 显示的数据 ip_list.append({ 'id': ip_row['id'], "index": index + start, 'color_tag': color_tag_obj['color'] if color_tag_obj else '', 'memo_content': memo_obj['content'] if memo_obj else '', 'vulnerability': '\r\n'.join(vul_info), "org_name": org_table.get(int(ip_row['org_id']))['org_name'] if ip_row['org_id'] else '', "ip": ip_row['ip'], "status": ip_row['status'], "location": ip_row['location'].split(',')[0] if ip_row['location'] else '', "create_time": str(ip_row['create_datetime']), "update_time": str(ip_row['update_datetime']), "port": port_with_status_list, "title": ', '.join(list(title_set)), "banner": ', '.join(list(banner_set)) }) index += 1 # 查询的记录数量 count = ip_table.count_by_search(org_id=org_id, domain=domain_address, ip=ip_address, port=port, content=content, iplocation=iplocation, port_status=port_status, color_tag=color_tag, memo_content=memo_content, date_delta=date_delta) json_data = { 'draw': draw, 'recordsTotal': count, 'recordsFiltered': count, 'data': ip_list } except Exception as e: logger.error(traceback.format_exc()) print(e) return jsonify(json_data)