OWASP-zap python-api身份验证

2024-09-30 22:13:32 发布

您现在位置:Python中文网/ 问答频道 /正文

首先,我想说我喜欢这个工具,如果你熟悉Zap的话,API是以一种非常容易理解的方式编写的。我遇到的唯一问题是我找不到关于pythonapi的很多文档,所以我放弃了源代码,并在应用程序上验证了它是如何工作的。我已经能够提取扫描和设置上下文,但我似乎无法正确调用身份验证模块中的任何内容。我认为,我的一个问题是,在调用函数时,我不完全确定要使用的确切变量或它们各自的格式。下面是一些我一起废弃的示例代码。以下认证功能的每次使用都让我失望。即使有人看到这件事,告诉我该去哪里,或者自己去解决这个问题,我也会非常感激的。在

from zapv2 import ZAPv2

context = 'new_attack'

authmethodname = 'formBasedAuthentication'

authmethodconfigparams = "".join('loginUrl=someloginpage' 'loginRequestData=username%3D%7B%25user1%25%7D%26' 'password%3D%7B%25password%25%7D')

target = 'some target but I cant put more than 2 links in this question'

apikey = 'password'

zap = ZAPv2(apikey=apikey)

print zap.context.new_context('new_attack')

print zap.context.include_in_context(context, 'https://192.168.0.1.*')

print zap.context.context(context)

#anything below here gives me 'Missing Params' an error from zap
print zap.authentication.set_logged_in_indicator(context, loggedinindicatorregex='Logged in')

print zap.authentication.set_logged_out_indicator(context, 'Sorry, the username or password you entered is incorrect')


print zap.authentication.set_authentication_method(context, authmethodname, authmethodconfigparams)

Tags: infromtargetnewauthenticationcontextpasswordzap
1条回答
网友
1楼 · 发布于 2024-09-30 22:13:32

项目中的一个开发人员成员能够回答我的问题,所以我想我也会把它放在这里。本质上,身份验证函数将contextid和userid作为参数,我传递的是上下文名称和用户名。我在源代码中也解释了其他一些错误。希望这也能帮助其他刚开始使用API的人,因为没有太多的文档。 从github页面zaproxy;用户名thc02-

from zapv2 import ZAPv2
context = 'new_attack'
authmethodname = 'formBasedAuthentication'
authmethodconfigparams = "".join('loginUrl=https://192.168.0.1/dologin.html' '&loginRequestData=username%3D%7B%25username%25%7D%26' 'password%3D%7B%25password%25%7D')
target = 'https://192.168.0.1'
apikey = 'password'
zap = ZAPv2(proxies={'http': 'http://127.0.0.1:8119', 'https': 'http://127.0.0.1:8119'}, apikey=apikey)

contextid = zap.context.new_context(context)
print contextid
print zap.context.include_in_context(context, 'https://192.168.0.1.*')

print zap.context.context(context)

print zap.authentication.set_authentication_method(contextid, authmethodname, authmethodconfigparams)
# The indicators should be set after setting the authentication method.
print zap.authentication.set_logged_in_indicator(contextid, loggedinindicatorregex='Logged in')
print zap.authentication.set_logged_out_indicator(contextid, 'Sorry, the username or password you entered is incorrect')

userid = zap.users.new_user(contextid, 'User 1')
print userid
print zap.users.set_authentication_credentials(contextid, userid, 'username=MyUserName&password=MySecretPassword')
print zap.users.set_user_enabled(contextid, userid, True)

print zap.spider.scan_as_user(contextid, userid, target)

““

相关问题 更多 >