Hi,
I'm using Zaproxy 2.5 and trying to automate spidering and active scan through context importation.
The
spidering is done with "ZAP" username and password, even though
imported context specifies right login and password, forced user,
includes and excludes, login and logoff context and right login form
replacements and method.
It was written elsewhere that this
behavior would be normal if ZAP wouldn't know how to replace defined
username and password, but that context was exported from a working
session.
So I suppose I'm not respecting the right steps for it to
use the context, username and passwords and login with the right
credentials, even though I followed
the guideI
tried a bunch of stuff, including forcing the user manually, using
zap.spider.scan_as_user, etc, which are commented out in the provided
code, which was based on
this post.
Any hints of what i'm not doing right?
Thanks a bunch!
Scanner.py
:
#!/usr/bin/env python
import time
from pprint import pprint
from zapv2 import ZAPv2
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
target = 'https://172.20.120.25:1443/'
zapHostIp = '172.20.20.235'
zap = ZAPv2(proxies={'http': 'http://' + zapHostIp + ':8090', 'https': 'http://' + zapHostIp + ':8090'})
apikey = 'apikey!'
#new session
zap.core.new_session(apikey = apikey)
#print 'Accessing target %s' % target
#zap.urlopen(target)
# Give the sites tree a chance to get updated
#time.sleep(2)
# ConnectID.importContext
print "Importing Context"
contextId = zap.context.import_context('/root/.ZAP/contexts/PF2.context', apikey = apikey)
print "contextID = " + contextId
#zap.context.set_context_in_scope(contextId, True, apikey = apikey)
zap.context.set_context_in_scope('PF2', True, apikey = apikey)
#zap.context.context('PF2')
time.sleep(5)
userId = zap.forcedUser.get_forced_user(contextId)
print "Forced userId = " + userId
print "isForcedUserModeEnabled = " + zap.forcedUser.is_forced_user_mode_enabled
zap.forcedUser.set_forced_user_mode_enabled(True, apikey= apikey)
print "isForcedUserModeEnabled = " + zap.forcedUser.is_forced_user_mode_enabled
time.sleep(5)
#TODO: Update scripts before going further
print 'Accessing target %s' % target
# try have a unique enough session...
zap.urlopen(target)
# Give the sites tree a chance to get updated
time.sleep(2)
print 'Spidering target %s' % target
zap.spider.set_option_max_depth(10, apikey=apikey)
#zap.spider.scan_as_user (contextId, userId, target, recurse = True, apikey = apikey)
zap.spider.scan(url=target, contextname='PF2', apikey=apikey)
#zap.spider.scan_as_user (contextId, userId, target, apikey = apikey)
# Give the Spider a chance to start
time.sleep(5)
while (int(zap.spider.status()) < 100):
print 'Spider progress %: ' + zap.spider.status()
time.sleep(2)
print 'Spider completed'
# Give the passive scanner a chance to finish
time.sleep(10)
print 'Scanning target %s' % target
#zap.ascan.scan_as_user(target, 2, 2, recurse=True)
#zap.ascan.scan(target, recurse=True, inscopeonly=True)
zap.ascan.scan(target, recurse=True, apikey=apikey)
while (int(zap.ascan.status()) < 100):
print 'Scan progress %: ' + zap.ascan.status()
time.sleep(5)
print 'Scan completed'
# Report the results
print 'Hosts: ' + ', '.join(zap.core.hosts)
print 'Alerts: '
pprint (zap.core.alerts())
PF2.context:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<configuration>
<context>
<name>PF2</name>
<desc/>
<inscope>true</inscope>
<incregexes>https://172.20.120.25:1443.*</incregexes>
<incregexes>.*172.20.120.25:1443.*</incregexes>
<excregexes>https://172.20.120.25:1443/admin/logout</excregexes>
<tech>
<include>Db.MySQL</include>
<include>Db.Oracle</include>
<include>Db.SQLite</include>
<include>Language.C</include>
<include>Language.XML</include>
<include>OS.Linux</include>
<include>SCM.Git</include>
<include>WS.Apache</include>
<exclude>Db</exclude>
<exclude>Db.Firebird</exclude>
<exclude>Db.HypersonicSQL</exclude>
<exclude>Db.IBM DB2</exclude>
<exclude>Db.Microsoft Access</exclude>
<exclude>Db.Microsoft SQL Server</exclude>
<exclude>Db.PostgreSQL</exclude>
<exclude>Db.SAP MaxDB</exclude>
<exclude>Db.Sybase</exclude>
<exclude>Language</exclude>
<exclude>Language.ASP</exclude>
<exclude>Language.PHP</exclude>
<exclude>OS</exclude>
<exclude>OS.MacOS</exclude>
<exclude>OS.Windows</exclude>
<exclude>SCM</exclude>
<exclude>SCM.SVN</exclude>
<exclude>WS</exclude>
<exclude>WS.IIS</exclude>
<exclude>WS.Tomcat</exclude>
</tech>
<urlparser>
<class>org.zaproxy.zap.model.StandardParameterParser</class>
<config>{"kvps":"&","kvs":"=","struct":[]}</config>
</urlparser>
<postparser>
<class>org.zaproxy.zap.model.StandardParameterParser</class>
<config>{"kvps":"&","kvs":"=","struct":[]}</config>
</postparser>
<authentication>
<type>2</type>
<loggedin>\Q Log out\E</loggedin>
<loggedout>\QYour session has expired.\E</loggedout>
<form>
<loginurl>https://172.20.120.25:1443/admin/login</loginurl>
<loginbody>redirect_url=https%3A%2F%2F172.20.120.25%3A1443%2Fadmin%2Fconfiguration&username={%username%}&password={%password%}</loginbody>
</form>
</authentication>
<users>
<user>1;true;YWRtaW4=
;2;YWRtaW4=
~dGVzdA==
~</user>
</users>
<forceduser>1</forceduser>
<session>
<type>0</type>
</session>
<authorization>
<type>0</type>
<basic>
<header/>
<body/>
<logic>AND</logic>
<code>401</code>
</basic>
</authorization>
</context>
</configuration>