Create interactivewebpentest.py

init
This commit is contained in:
AiShell 2025-03-06 19:18:00 +08:00 committed by GitHub
parent 8b4915e20c
commit cccf3512ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,54 @@
import asyncio
import os
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from pydantic import SecretStr
from browser_use import Agent, Browser
from aioconsole import ainput # 需要安装 aioconsole
# dotenv
load_dotenv()
api_key = os.getenv('api_key', '')
if not api_key:
raise ValueError('DEEPSEEK_API_KEY is not set')
async def run_pentest():
browser = Browser()
llm=ChatOpenAI(
base_url='https://api.deepseek.com/v1',
model='deepseek-chat',
api_key=SecretStr(api_key))
async with await browser.new_context() as context:
agent = Agent(
task=(
'1. 连接http://192.168.65.97/dvwa/index.php '
'2. 这是一个DVWA的靶机使用默认密码登录'
),
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()
if __name__ == '__main__':
asyncio.run(run_pentest())