def segement_cfg_similarity_process(vuln_name, patch_name, neo4jdb, worksheet): start_time = time.time() print "[%s] processing %s" % (datetime.datetime.now().strftime( "%y-%m-%d %H:%M:%S"), vuln_name + " vs " + patch_name) #检查数据库里面是否可以找到该函数,找不到相似度为0 vuln_func = get_function_node(neo4jdb, vuln_name) if vuln_func is None: line = (vuln_name, patch_name, "vuln_func_not_found", 0.00, 0) worksheet.append(line) return #检查数据库里面是否可以找到该函数,找不到相似度为0 patch_func = get_function_node(neo4jdb, patch_name) if patch_func is None: line = (vuln_name, patch_name, "patch_func_not_found", 0.00, 0) worksheet.append(line) return #计算是否匹配和相似度 match, simi = func_cfg_similarity(vuln_func, neo4jdb, patch_func, neo4jdb) #u"success" end_time = time.time() cost = round(end_time - start_time, 2) line = (vuln_name, patch_name, match, simi, cost) worksheet.append(line)
def segement_cfg_similarity_process(vuln_name, patch_name, neo4jdb, worksheet): start_time = time.time() print "[%s] processing %s" % (datetime.datetime.now().strftime("%y-%m-%d %H:%M:%S"), vuln_name + " vs " + patch_name) #检查数据库里面是否可以找到该函数,找不到相似度为0 vuln_func = get_function_node(neo4jdb, vuln_name) if vuln_func is None: line = (vuln_name, patch_name, "vuln_func_not_found", 0.00, 0) worksheet.append(line) return #检查数据库里面是否可以找到该函数,找不到相似度为0 patch_func = get_function_node(neo4jdb, patch_name) if patch_func is None: line = (vuln_name, patch_name, "patch_func_not_found", 0.00, 0) worksheet.append(line) return #计算是否匹配和相似度 match, simi = func_cfg_similarity(vuln_func, neo4jdb, patch_func, neo4jdb) #u"success" end_time = time.time() cost = round(end_time - start_time, 2) line = (vuln_name, patch_name, match, simi, cost) worksheet.append(line)
def func_cfg_similarity_process(vuln_info, conn, neo4jdb, worksheet): start_time = time.time() cve_info = vuln_info.get_cve_info(conn) soft = cve_info.get_soft(conn) print "[%s] processing %s" % (datetime.datetime.now().strftime("%y-%m-%d %H:%M:%S"), cve_info.cveid) vuln_name = cve_info.cveid.replace(u"-", u"_").upper() + u"_VULN_" + vuln_info.vuln_func patch_name = cve_info.cveid.replace(u"-", u"_").upper() + u"_PATCHED_" + vuln_info.vuln_func vuln_func = get_function_node(neo4jdb, vuln_name) if vuln_func is None: line = ( cve_info.cveid, soft.software_name + "-" + soft.software_version, vuln_info.vuln_func, vuln_info.vuln_file[41:], "vuln_func_not_found", 0.00, 0, ) worksheet.append(line) return patch_func = get_function_node(neo4jdb, patch_name) if patch_func is None: line = ( cve_info.cveid, soft.software_name + "-" + soft.software_version, vuln_info.vuln_func, vuln_info.vuln_file[41:], "patch_func_not_found", 0.00, 0, ) worksheet.append(line) return match, simi = func_cfg_similarity(vuln_func, neo4jdb, patch_func, neo4jdb) # u"success" end_time = time.time() cost = round(end_time - start_time, 2) line = ( cve_info.cveid, soft.software_name + "-" + soft.software_version, vuln_info.vuln_func, vuln_info.vuln_file[41:], match, simi, cost, ) worksheet.append(line)
def func_similarity_cfg_level(soft_db, funcs, character_db, func_name, worksheet): # @db1 待比对数据库 # @db2 漏洞特征数据库 # @func_name 目标函数名 #过滤一下 ast_root = get_function_ast_root(character_db, func_name) if ast_root is None: print "no function found" return return_type = get_function_return_type(character_db, ast_root) # 获取目标函数返回值类型 param_list = get_function_param_list(character_db, ast_root) # 获取目标函数参数类型列表 filter_funcs = filter_functions(soft_db, funcs, return_type, param_list) # 过滤待比较函数 tar_func = get_function_node(character_db, func_name) for ast_root in filter_funcs: src_func = get_function_node_by_ast_root(soft_db, ast_root) match, simi = func_cfg_similarity(src_func, soft_db, tar_func, character_db) if match: file = get_function_file(soft_db, src_func.properties[u'name'])[41:] worksheet.append( (func_name, file, src_func.properties[u'name'],match, round(simi,4) )) elif simi == -1: print u"节点太多,未进行比较 "
def func_pdg_similarity_process(vuln_info, conn, neo4jdb, worksheet): start_time = time.time() cve_info = vuln_info.get_cve_info(conn) soft = cve_info.get_soft(conn) print "[%s] processing %s" % ( datetime.datetime.now().strftime("%y-%m-%d %H:%M:%S"), cve_info.cveid) vuln_name = cve_info.cveid.replace( u"-", u"_").upper() + u"_VULN_" + vuln_info.vuln_func patch_name = cve_info.cveid.replace( u"-", u"_").upper() + u"_PATCHED_" + vuln_info.vuln_func vuln_func = get_function_node(neo4jdb, vuln_name) if vuln_func is None: line = (cve_info.cveid, soft.software_name + "-" + soft.software_version, vuln_info.vuln_func, vuln_info.vuln_file[41:], "vuln_func_not_found", 0.00, 0) ws.append(line) return patch_func = get_function_node(neo4jdb, patch_name) if patch_func is None: line = (cve_info.cveid, soft.software_name + "-" + soft.software_version, vuln_info.vuln_func, vuln_info.vuln_file[41:], "patch_func_not_found", 0.00, 0) ws.append(line) return match, simi = func_pdg_similarity(vuln_func, neo4jdb, patch_func, neo4jdb) #u"success" end_time = time.time() cost = round(end_time - start_time, 2) line = (cve_info.cveid, soft.software_name + "-" + soft.software_version, vuln_info.vuln_func, vuln_info.vuln_file[41:], match, simi, cost) ws.append(line)
def func_similarity_segement_level(db1, funcs, db2, func_name, worksheet): # @db1 待比对数据库 # @db2 漏洞特征数据库 # @func_name 目标函数名 tar_func = get_function_node(db2, func_name) for src_func in funcs: match, simi = func_cfg_similarity(src_func, db1, tar_func, db2) if match: file = get_function_file(db1, src_func.properties[u'name'])[41:] worksheet.append( (func_name, file, src_func.properties[u'name'], match, round(simi, 4))) elif simi == -1: print u"节点太多,未进行比较 "
def func_similarity_segement_level(db1, funcs, db2, func_name, worksheet): # @db1 待比对数据库 # @db2 漏洞特征数据库 # @func_name 目标函数名 tar_func = get_function_node(db2, func_name) for src_func in funcs: match, simi = func_cfg_similarity(src_func, db1, tar_func, db2) if match: file = get_function_file(db1, src_func.properties[u'name'])[41:] worksheet.append( (func_name, file, src_func.properties[u'name'],match, round(simi,4) )) elif simi == -1: print u"节点太多,未进行比较 "
import sys sys.path.append("..") from algorithm.graph import translate_cfg from openpyxl import load_workbook, Workbook from algorithm.ast import get_function_node from py2neo import Graph if __name__ == "__main__": wb = load_workbook("test3.xlsx", read_only=True) ws = wb[u'Sheet3'] neo4jdb = Graph("http://localhost:7475/db/data/") for row in ws.rows: src_func_node = get_function_node(neo4jdb, row[0].value) if src_func_node is None: print "vuln_segement not found" continue src_cfg = translate_cfg(neo4jdb, src_func_node) tar_func_node = get_function_node(neo4jdb, row[1].value) if src_func_node is None: print "patch_segement not found" continue tar_cfg = translate_cfg(neo4jdb, tar_func_node) node = len(src_cfg.vs) * len(tar_cfg.vs) edge = len(src_cfg.es) * len(tar_cfg.es) print node, edge
''' import sys sys.path.append("..") from algorithm.ast import get_function_node from openpyxl import load_workbook from py2neo import Graph if __name__ == "__main__": db = Graph("http://127.0.0.1:7476/db/data/") #wireshark diff ws1 = load_workbook("/home/bert/Documents/data/wireshark.xlsx")['Sheet3'] for row in ws1.rows: try: n = get_function_node(db, row[0].value) except Exception as e: try: n = get_function_node(db, row[2].value) except: print "%s and %s not found" % (row[0].value, row[2].value) #wireshark patch Function for row in ws1.rows: try: n = get_function_node(db, row[1].value) except Exception as e: print "%s not found" % row[1].value #ffmpeg diff ws2 = load_workbook("/home/bert/Documents/data/ffmpeg.xlsx")['Sheet3']
''' import sys sys.path.append("..") from algorithm.ast import get_function_node from openpyxl import load_workbook from py2neo import Graph if __name__ == "__main__": db = Graph("http://127.0.0.1:7476/db/data/") #wireshark diff ws1 = load_workbook("/home/bert/Documents/data/wireshark.xlsx")['Sheet3'] for row in ws1.rows: try: n = get_function_node(db, row[0].value) except Exception as e: try: n = get_function_node(db, row[2].value) except: print "%s and %s not found" % (row[0].value, row[2].value) #wireshark patch Function for row in ws1.rows: try: n = get_function_node(db, row[1].value) except Exception as e: print "%s not found" % row[1].value #ffmpeg diff ws2= load_workbook("/home/bert/Documents/data/ffmpeg.xlsx")['Sheet3']