前言
关注公众号,并设置精选,第一时间推送文章
最开始,我只是想测试这个AI的深度分析能力到底有多强。
用过AI写代码的师傅们可能都知道,让AI完整的给你去写一个小程序,哪怕特别简单,也需要分析调整很多次才能写出完整的代码
特别是在进行客户端GUI开发的时候,往往设计的洁面都不是特别好看,功能和美化只能二选一。
不只是GUI开发的时候,如果你写一些其他的脚本,多多少少都要解决各种AI给你的代码的bug。
我抱着怀疑的态度尝试了一下深度分析。
没想到真让我大开眼界了。。。。
这是我问的问题:
他只回答了一次!!!仅仅只有一次,就达到了这个效果!!!我并没有做代码的微调。
我让他做的是通过调用DeekSeek的API接口,使用AI对流量进行研判分析
恶意流量效果:
正常流量效果
这是我对他说的
你好,DeepSeep是很好的一款AI,我想调用它的API做AI流量研判分析,请你帮我用Python写一个GUI洁面,并且对接DeepSeek,给合适的提示词,用户将会输入HTTP数据包,通过AI判断这个流量是否为攻击流量。python的洁面一定要美观科技感。不要使用TK模块,因为macOS会出问题
深度分析。。。。真的很强大。。。
对比其他家
openai
某国产AI
然后DeepSeek写完之后,再让他继续加功能,在此期间人工不参与代码的修改调整
增加AI解码功能
最终效果
代码展示
import sysimport osimport jsonimport requestsfrom PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,QTextEdit, QPushButton, QLabel, QHBoxLayout,QSplitter, QScrollArea)from PyQt5.QtCore import Qt, QSize, QThread, pyqtSignalfrom PyQt5.QtGui import QFont, QColor, QPalette, QLinearGradient# 配置参数(需要用户自行修改)DEEPSEEK_API_KEY ="自己去申请key"API_ENDPOINT ="https://api.deepseek.com/v1/chat/completions"os.environ["QT_IM_MODULE"] ="none"classAnalysisThread(QThread):analysis_complete = pyqtSignal(str, bool)def__init__(self, http_data, parent=None):super().init(parent)self.http_data = http_datadefrun(self):try:headers = {"Authorization": f"Bearer {DEEPSEEK_API_KEY}","Content-Type":"application/json"}prompt = f"""请进行网络安全分析。请严格按照以下步骤执行:1. 分析以下HTTP请求的各个组成部分2. 识别是否存在SQL注入、XSS、CSRF、反序列化、文件上传、路径遍历、OWASPTop10、等常见攻击特征3. 检查User-Agent等头部信息是否可疑4. 最终结论:是否为攻击流量(是/否)请用中文按以下格式响应:【分析结果】是/否【依据】简明扼要列出技术依据HTTP请求数据:{self.http_data}"""payload = {"model":"deepseek-chat","messages": [{"role":"user","content": prompt}],"temperature":0.3}response = requests.post(API_ENDPOINT, headers=headers, json=payload)response.raise_for_status()result = response.json()['choices'][0]['message']['content']is_attack ="【分析结果】是"inresultself.analysis_complete.emit(result, is_attack)except Exception ase:self.analysis_complete.emit(f"错误发生: {str(e)}", False)classDecodingThread(QThread):decoding_complete = pyqtSignal(str)def__init__(self, encoded_str, parent=None):super().init(parent)self.encoded_str = encoded_strdefrun(self):try:headers = {"Authorization": f"Bearer {DEEPSEEK_API_KEY}","Content-Type":"application/json"}prompt = f"""请完整分析并解码以下字符串,要求:1. 识别所有可能的编码方式(包括嵌套编码)2. 通过自己重新编码,确认自己解码正确3. 展示完整的解码过程4. 输出最终解码结果原始字符串:{self.encoded_str}请用中文按以下格式响应:【编码分析】列出检测到的编码类型及层级【解码过程】逐步展示解码步骤【最终结果】解码后的明文内容"""payload = {"model":"deepseek-chat","messages": [{"role":"user","content": prompt}],"temperature":0.3}response = requests.post(API_ENDPOINT, headers=headers, json=payload)result = response.json()['choices'][0]['message']['content']self.decoding_complete.emit(result)except Exception ase:self.decoding_complete.emit(f"解码错误: {str(e)}")classCyberSecurityApp(QMainWindow):def__init__(self):super().init()self.initUI()self.setStyleSheet(self.get_stylesheet())definitUI(self):self.setWindowTitle('DeepSeek 安全分析平台')self.setGeometry(300,300,1000,600)self.setMinimumSize(QSize(1000,600))main_widget = QWidget()self.setCentralWidget(main_widget)splitter = QSplitter(Qt.Horizontal)main_layout = QHBoxLayout(main_widget)main_layout.addWidget(splitter)# 左侧主功能区域left_panel = QWidget()left_layout = QVBoxLayout(left_panel)title = QLabel("网络流量智能分析系统")title.setFont(QFont(".SF NS Text",20, QFont.Bold))title.setAlignment(Qt.AlignCenter)left_layout.addWidget(title)input_label = QLabel("请输入HTTP请求数据:")input_label.setFont(QFont(".SF NS Text",12))left_layout.addWidget(input_label)self.input_text = QTextEdit()self.input_text.setPlaceholderText("粘贴HTTP请求数据...")self.input_text.setMinimumHeight(150)left_layout.addWidget(self.input_text)self.analyze_btn = QPushButton("开始智能分析")self.analyze_btn.clicked.connect(self.analyze)self.analyze_btn.setCursor(Qt.PointingHandCursor)left_layout.addWidget(self.analyze_btn)result_label = QLabel("AI分析结果:")result_label.setFont(QFont(".SF NS Text",12))left_layout.addWidget(result_label)self.result_text = QTextEdit()self.result_text.setReadOnly(True)self.result_text.setMinimumHeight(200)left_layout.addWidget(self.result_text)# 右侧解码区域right_panel = QScrollArea()right_widget = QWidget()right_layout = QVBoxLayout(right_widget)right_panel.setWidget(right_widget)right_panel.setWidgetResizable(True)decode_title = QLabel("AI全智能解码")decode_title.setFont(QFont(".SF NS Text",14, QFont.Bold))right_layout.addWidget(decode_title)self.decode_input = QTextEdit()self.decode_input.setPlaceholderText("输入需要解码的字符串...")self.decode_input.setMaximumHeight(100)right_layout.addWidget(self.decode_input)self.decode_btn = QPushButton("AI智能解码")self.decode_btn.clicked.connect(self.start_decode)right_layout.addWidget(self.decode_btn)self.decode_result = QTextEdit()self.decode_result.setReadOnly(True)self.decode_result.setMinimumHeight(200)right_layout.addWidget(self.decode_result)splitter.addWidget(left_panel)splitter.addWidget(right_panel)splitter.setSizes([600,400])self.status_bar =self.statusBar()defget_stylesheet(self):return"""QMainWindow {background-color: #1a1a2e;}QLabel {color: #e94560;padding: 5px;}QTextEdit {background-color: #16213e;color: #e6e6e6;border: 2px solid #0f3460;border-radius: 5px;padding: 10px;font-family: 'Menlo';}QPushButton {background-color: #e94560;color: white;border: none;padding: 12px 24px;border-radius: 5px;font-size: 14px;font-weight: bold;}QPushButton:hover {background-color: #ff6b6b;}QPushButton:pressed {background-color: #ff4757;}QScrollArea {background-color: #16213e;border: 1px solid #0f3460;border-radius: 5px;}"""defanalyze(self):http_data =self.input_text.toPlainText().strip()ifnothttp_data:self.show_status("请输入有效的HTTP请求数据","red")returnself.show_status("分析中...","#e94560")self.analyze_btn.setEnabled(False)self.thread = AnalysisThread(http_data)self.thread.analysis_complete.connect(self.show_result)self.thread.start()defshow_result(self, result, is_attack):self.analyze_btn.setEnabled(True)bg_color ="#ff4757"ifis_attackelse"#2ed573"border_color ="#e94560"ifis_attackelse"#7bed9f"self.result_text.setStyleSheet(f"""QTextEdit {{background-color: {bg_color};color: white;border: 2px solid {border_color};border-radius: 5px;padding: 15px;}}""")self.result_text.setHtml(f"
{result}")status ="检测到恶意流量!"ifis_attackelse"流量正常"self.show_status(status,"#e94560"ifis_attackelse"#2ed573")defstart_decode(self):text =self.decode_input.toPlainText().strip()ifnottext:returnself.decode_btn.setEnabled(False)self.decode_result.setStyleSheet("background-color: #16213e;")self.decode_result.setPlainText("AI解码中...")self.decode_thread = DecodingThread(text)self.decode_thread.decoding_complete.connect(self.show_decode_result)self.decode_thread.start()defshow_decode_result(self, result):self.decode_btn.setEnabled(True)self.decode_result.setStyleSheet("""QTextEdit {background-color: #1e3799;color: white;border: 2px solid #4a69bd;}""")self.decode_result.setPlainText(result)defshow_status(self, message, color):self.status_bar.showMessage(message)self.status_bar.setStyleSheet(f"color: {color}; font-weight: bold;")if__name__=='main':sys.argv += ['-platform','cocoa']app = QApplication(sys.argv)app.setStyle('Fusion')palette = app.palette()gradient = QLinearGradient(0,0,0,400)gradient.setColorAt(0, QColor(22,33,62))gradient.setColorAt(1, QColor(26,26,46))palette.setBrush(QPalette.Window, gradient)app.setPalette(palette)window = CyberSecurityApp()window.show()sys.exit(app.exec_())