2017-06-05 127 views
-2

我想先說說我喜歡這個工具,如果你熟悉Zap,那麼API是以非常容易遵循的方式編寫的。我遇到的唯一困難是我無法在python API上找到很多文檔,所以我已經離開了源代碼並驗證它如何對付應用程序。我已經能夠掃描並設置上下文,但我似乎無法正確調用身份驗證模塊中的任何內容。我相信,我的一個問題是,在調用函數時,我不完全確定要使用的確切變量或它們各自的格式。下面是我一起報廢的一些示例代碼。以下認證功能的每一次使用都使我失敗。即使有人要看這個,並告訴我去哪裏或自己解決這個問題,我會非常感激。OWASP zap python api身份驗證

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) 
+0

也感謝編輯建議。我第一次在這裏問一個問題。 – jeannotteb

回答

0

該項目的開發人員能夠回答我的問題,所以我想我也會把它放在這裏。實質上,身份驗證功能將contextid和userid用作參數,並且我傳遞了上下文名稱和用戶名。我還從源代碼中解讀了一些其他錯誤。希望這可以幫助其他人開始使用API​​,因爲沒有太多的文檔。來自github頁面的 zaproxy;用戶名thc202 - 「

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)