1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| import os import requests from bs4 import BeautifulSoup import re from volcenginesdkarkruntime import Ark
def format_with_api(text): api_key = "" client = Ark( api_key=api_key, base_url="https://ark.cn-beijing.volces.com/api/v3" )
data = { "model": "ep-20250309161157-ng6kn", "messages": [ {"role": "system", "content": "你是人工智能助手"}, {"role": "user", "content": f"请将以下漏洞信息整理成标准格式:\n{text}\n\n格式为:\nPHPYun代码注入漏洞(CVE-2024-54724)\n发布日期:2025-01-09\n更新日期:2025-03-07\n受影响系统:PHPYun PHPYun < 7.0.2\n描述:CVE(CAN) ID: CVE-2024-54724\n\nPHPYun是中国鑫潮(PHPYun)公司的一个基于PHP和MySQL数据库的人才和企业招聘和就业的高效解决方案。PHPYun 7.0.2之前版本存在代码注入漏洞,攻击者可利用该漏洞通过写入并添加任意文件执行代码。\n\n建议:\n厂商补丁:\n\nPHPYun\n------\n厂商尚未提供漏洞修复方案,请关注厂商主页更新:\nhttps://github.com/la12138la/detail/blob/main/1.md"}, ] }
response = client.chat.completions.create(**data)
print(response)
if response and hasattr(response, 'choices') and len(response.choices) > 0: choice = response.choices[0] print("Choice内容:", choice)
if hasattr(choice, 'message') and hasattr(choice.message, 'content'): return choice.message.content else: return "格式化失败" else: print("API请求失败或响应格式不正确") return "格式化失败"
url = 'http://www.nsfocus.net/vulndb/112604' response = requests.get(url) response.encoding = 'utf-8'
soup = BeautifulSoup(response.text, 'html.parser')
vulbar_div = soup.find('div', class_='vulbar')
if vulbar_div: text = str(vulbar_div)
text = re.sub(r'<!--.*?-->', '', text, flags=re.DOTALL) text = re.sub(r'浏览次数:\d+', '', text)
text = re.sub(r'<.*?>', '', text) text = re.sub(r'<', '<', text) text = re.sub(r'>', '>', text) text = re.sub(r'&', '&', text) text = re.sub(r'"', '"', text) text = re.sub(r' ', ' ', text)
match = re.search(r'([^\d]*CVE-\d{4}-\d{5,})', text) if match: cve_title = match.group(1).strip()
cve_title = re.sub(r'[<>:"/\\|?*\n]', '', cve_title)
url_match = re.search(r'/vulndb/(\d+)', url) if url_match: file_name = f"{url_match.group(1)}_{cve_title}"
file_name = file_name + ')'
file_path = os.path.join('C:\\Users\\111\\Desktop\\爬虫', f'{file_name}.txt')
os.makedirs(os.path.dirname(file_path), exist_ok=True)
formatted_content = format_with_api(text) print("格式化后的内容:") print(formatted_content)
with open(file_path, 'w', encoding='utf-8') as f: f.write(formatted_content)
print(f"文件已保存:{file_path}") else: print('未找到URL中的数字部分') else: print('未找到标题或CVE编号,无法保存文件') else: print('未找到目标内容')
|