大模型在安全分析中的简单应用

信息安全不简单鸭 2024-09-08 01:45:36

大模型在安全分析中的简单应用场景是根据HTTP请求和HTTP响应,判断攻击是否成功,如果攻击成功,则需要推动安全仔去排查,否则,直接忽略告警,非常适合SOAR预案编排,实现自动化告警分析、研判和处置。

这里演示一下暂时免费的通义千问API接口调用,其他大模型也都类似,需要自己先在阿里云上申请API-KEY,python语言限制了版本必须大于等于3.7,所以我选择的是python3.8,返回结果如下,还是很靠谱的。

攻击结果:攻击失败原因:返回状态码为400,说明请求被服务器拒绝,可能是由于请求参数错误或者请求方法不支持等原因引起的# python3.8import randomfrom http import HTTPStatusimport dashscopedashscope.api_key="sk-*****************" #填写你自己的API-KEYhttp_req = """GET /webshell.php HTTP/1.1Accept: */*Connection: keep-aliveHost: ctf.hackbiji.topUpgrade-Insecure-Requests: 1User-Agent: Custom-AsyncHttpClient"""http_res = """HTTP/1.1 400 Bad RequestServer: nginx/1.15.9Date: Sun, 24 Dec 2023 21:14:03 GMTContent-Type: text/htmlContent-Length: 157Connection: close<html><head><title>400 Bad Request</title></head><body><center><h1>400 Bad Request</h1></center><hr><center>nginx/1.15.9</center></body></html>"""promt = f"收到一段安全设备的告警日志,包含HTTP请求和HTTP响应,请判断【攻击成功,攻击失败】,如果攻击成功,则需要推动安全服务同事上机排除,否则忽略告警,回答内容示例{{'攻击结果':'攻击失败','原因':''}} 请严格遵守示例的JSON返回格式。"question = f"{promt} 待判断的告警日志如下: {http_req} {http_res}"def call_with_messages(): messages = [{'role': 'system', 'content': 'You are a helpful assistant.'}, {'role': 'user', 'content': f'{question}'}] response = dashscope.Generation.call( dashscope.Generation.Models.qwen_turbo, messages=messages, # set the random seed, optional, default to 1234 if not set seed=random.randint(1, 10000), result_format='message', # set the result to be "message" format. ) if response.status_code == HTTPStatus.OK: message = response["output"]["choices"][0]["message"] content = message["content"] print(content) else: print('Request id: %s, Status code: %s, error code: %s, error message: %s' % ( response.request_id, response.status_code, response.code, response.message ))if __name__ == '__main__': call_with_messages()# {'攻击结果': '攻击失败', '原因': '返回状态码为400,说明请求被服务器拒绝,可能是由于请求参数错误或者请求方法不支持等原因引起的'}

需要注意:免费额度策略

限流策略:如果调用频率太高,会导致HTTP请求失败,所以最好不要用异步请求

0 阅读:3