Commit 90677d7a by 文周繁

feat: add vulnerability validation

parent f1150a83
...@@ -2,16 +2,17 @@ import sys ...@@ -2,16 +2,17 @@ import sys
import subprocess import subprocess
import os import os
import re import re
# pymongo==3.13.0
import pymongo import pymongo
from bson.objectid import ObjectId from bson.objectid import ObjectId
from gridfs import GridFS from gridfs import GridFS
# 二进制程序保存的路径 # 二进制程序保存的路径
binary_file_path = "/home/hunter/Documents/validate_script/" binary_file_path = "/home/fuzz_dir/validate_script/"
# asan编译的二进制程序保存的路径 # asan编译的二进制程序保存的路径
asan_file_path = "/home/hunter/Documents/validate_script/asan_software" asan_file_path = "/home/fuzz_dir/validate_script/asan_software"
# crash的种子保存的路径 # crash的种子保存的路径
crashes_file_path = "/home/hunter/Documents/validate_script/crashes/" crashes_file_path = "/home/fuzz_dir/validate_script/crashes/"
pattern_valgrind_head = re.compile(r'==\d+==') pattern_valgrind_head = re.compile(r'==\d+==')
pattern_valgrind_tail = re.compile(r'==\d+== ERROR SUMMARY: [1-9]+') pattern_valgrind_tail = re.compile(r'==\d+== ERROR SUMMARY: [1-9]+')
...@@ -97,17 +98,19 @@ def exec_command(crashes_collection, usage, command, seed_id: ObjectId): ...@@ -97,17 +98,19 @@ def exec_command(crashes_collection, usage, command, seed_id: ObjectId):
def main(argv): def main(argv):
mongo_address = argv[0] mongo_address = argv[0]
mongo_port = argv[1] mongo_port = argv[1]
db_name = argv[3] db_name = argv[2]
default_db_name = argv[4] default_db_name = argv[3]
parameter = argv[5] parameter = argv[4]
software_id = argv[6] software_id = argv[5]
task_id = argv[7] task_id = argv[6]
host_node_id = argv[7]
fs_name = "fs" fs_name = "fs"
mongo_client = pymongo.MongoClient(f"mongodb://{mongo_address}:{mongo_port}/") mongo_client = pymongo.MongoClient(f"mongodb://{mongo_address}:{mongo_port}/")
db = mongo_client[db_name] db = mongo_client[db_name]
default_db = mongo_client[default_db_name] default_db = mongo_client[default_db_name]
task_collection = default_db["task"]
host_node_collection = default_db["host_node"]
# 获取产生crash的种子 # 获取产生crash的种子
crashes_collection = db["crashes"] crashes_collection = db["crashes"]
...@@ -120,6 +123,11 @@ def main(argv): ...@@ -120,6 +123,11 @@ def main(argv):
crashes_file_paths = search_file(crashes_file_path) crashes_file_paths = search_file(crashes_file_path)
try: try:
task_collection.update_one({"_id": ObjectId(task_id)}, {"$set": {"verification": "VERIFYING"}})
host_node = host_node_collection.find_one({"_id": ObjectId(host_node_id)})
used_cpu = host_node["used_cpu"]
host_node_collection.update_one({"_id": ObjectId(host_node_id)}, {"$set": {"used_cpu": int(used_cpu) + 1}})
# 获取二进制程序 # 获取二进制程序
binary_collection = db["binary"] binary_collection = db["binary"]
binary_ret = binary_collection.find_one() binary_ret = binary_collection.find_one()
...@@ -128,6 +136,7 @@ def main(argv): ...@@ -128,6 +136,7 @@ def main(argv):
binary_software_file.write(binary_ret["code"]) binary_software_file.write(binary_ret["code"])
binary_software_file.close() binary_software_file.close()
os.system(f"chmod +x {binary_software}") os.system(f"chmod +x {binary_software}")
print("binary donwload successfully")
generation_command(crashes_collection, binary_software, parameter, crashes_file_paths, "valgrind") generation_command(crashes_collection, binary_software, parameter, crashes_file_paths, "valgrind")
# 获取asan编译的二进制程序 # 获取asan编译的二进制程序
...@@ -135,6 +144,7 @@ def main(argv): ...@@ -135,6 +144,7 @@ def main(argv):
software = software_collection.find_one({"_id": ObjectId(software_id)}) software = software_collection.find_one({"_id": ObjectId(software_id)})
fs = GridFS(default_db, fs_name) fs = GridFS(default_db, fs_name)
# 根据ObjectId查找文件 # 根据ObjectId查找文件
print(software["asan_file"])
asan_file_data = fs.get(software["asan_file"]) asan_file_data = fs.get(software["asan_file"])
if asan_file_data: if asan_file_data:
# 确保下载目录存在 # 确保下载目录存在
...@@ -143,10 +153,14 @@ def main(argv): ...@@ -143,10 +153,14 @@ def main(argv):
with open(asan_file_path, "wb") as f: with open(asan_file_path, "wb") as f:
f.write(asan_file_data.read()) f.write(asan_file_data.read())
os.system(f"chmod +x {asan_file_path}") os.system(f"chmod +x {asan_file_path}")
print("asan_file download successfully")
generation_command(crashes_collection, asan_file_path, parameter, crashes_file_paths, "") generation_command(crashes_collection, asan_file_path, parameter, crashes_file_paths, "")
finally: finally:
task_collection = default_db["task"]
task_collection.update_one({"_id": ObjectId(task_id)}, {"$set": {"verification": "VERIFIED"}}) task_collection.update_one({"_id": ObjectId(task_id)}, {"$set": {"verification": "VERIFIED"}})
host_node = host_node_collection.find_one({"_id": ObjectId(host_node_id)})
used_cpu = host_node["used_cpu"]
if int(used_cpu) >= 1:
host_node_collection.update_one({"_id": ObjectId(host_node_id)}, {"$set": {"used_cpu": int(used_cpu) - 1}})
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment