OWASP ZAP API 根元素缺失错误

问题描述

我正在使用 Owasp ZAP API 在 Windows 上编写程序,以自动化针对目标 URL 运行 ZAP 的过程。到目前为止,我能够使用 zap.bat 文件和参数 -daemon -config api.disablekey=true 成功启动应用程序。启动应用程序,ZAP 能够监听 localhost:8080。我还创建了传入这些参数的 ClientAPi 对象:

ClientApi zaproxy = new ClientApi("127.0.0.1",8080,null);

我现在尝试使用 Context 类中的 includeInContext(string contextname,string regex) 方法设置上下文,但出现错误

System.Exception: 'System.Xml.XmlException: Root element is missing.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlLoader.Load(XmlDocument doc,XmlReader reader,Boolean preserveWhitespace)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at System.Xml.XmlDocument.LoadXml(String xml)
   at OwaspZAPDotNetAPI.ClientApi.CallApiRaw(String component,String operationType,String operationName,Dictionary 2 parameters)
   at OwaspZAPDotNetAPI.ClientApi.CallApi(String component,Dictionary 2 parameters)
   at OwaspZAPDotNetAPI.Generated.Context.includeInContext(String contextname,String regex)

但是,当我在后台启动 ZAP GUI,然后运行守护程序并设置上下文时,它似乎可以工作。有人可以让我知道如何解决上述错误吗?谢谢!

解决方法

看看 https://www.zaproxy.org/docs/automate/ - 这列出了您可以自动化 ZAP 的方法。 我怀疑其中一种打包扫描对您来说可能更容易使用。