SlideShare a Scribd company logo
Join the conversation
#DevSecCon
By Simon Bennetts
Scripting OWASP ZAP
●
Session 1 : 2pm
– Introduction
– Standard Scripts (JavaScript, Python, Ruby)
– Proxy and Http Sender Scripts
– Passive and Active Scan rule Scripts
●
Session 2 : 3pm
– Zest Scripts
– Standalone and Targeted Scripts
The Plan
●
Session 3 : 4pm
– How to use scripts in automation
– How to add scripting support in add-ons (overview)
– Authentication Scripts
– More chance to write any or all of the above types
●
Session 4 : 5pm
– Optional – keep writing scripts, ask more questions...
The Plan
●
We want more script examples
● Submit PRs to https://github.com/zaproxy/community-scripts
●
Can be anything useful – eg copies of existing scripts in different
languages :)
●
Anything useful will earn a ZAP Contributor sticker (max one per
person)
●
Lots of useful scripts will earn a ZAP T-shirt!
●
Only valid for this workshop
Competition Time!
●
Advantages:
– Quick to write and test
– Full access to ZAP classes and data structures
– No need for separate development environment
●
Disadvantages
– Documentation could be (much) better
– No auto complete
– No sandbox – only run scripts you trust!
Introduction – why do we need scripts?
●
JavaScript – built in
●
Python – optional add-on
●
Ruby – optional add-on
●
Zest – built in, macro language on steroids
●
JSR 223 languages relatively easy to add
●
Beanshell – optional, no longer really maintained
Introduction – What languages are supported?
●
Stand Alone
– Run manually
●
Targeted
– Run manually against a specified requests
●
Proxy
– Change proxied browser requests on the fly
●
HTTP Sender
– Change any request on the fly (proxy, spider, active scanner ...)
Script types (built in)
●
Passive Scan Rule
– Detect potential issues just by looking
●
Active Scan Rule
– Detect potential issues by attacking
●
Authentication
– Automatically login to sites
●
Script Input Vector
– Define exactly what ZAP will attack
Script types (built in)
●
Fuzzer HTTP Processor
– Called before and after HTTP messages are fuzzed
●
Fuzzer Websocket Processor
– Called before and after Websocket messages are fuzzed
●
Payload Generator
– Generate attacks to be used in the fuzzer
●
Payload Processor
– Change fuzzer payloads before they are used
●
Sequence
– Define sequences of requests to be attacked (alpha)
Script types (add-ons)
●
All roughly equivalent
●
All have good Java integration
●
JavaScript (ECMAScript)
– Java 7 – Rhino
– Java 8 – Nashhorn
– Can write to local filestore via Java classes
– Use load("nashorn:mozilla_compat.js"); for Rhino scripts in Nashorn
●
JavaScript Nashhorn – supports loading scripts from files
– https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions
●
Python – supports modules path
‘Standard’ Script languages
● Scripts group: https://groups.google.com/group/zaproxy-scripts
● Dev group: https://groups.google.com/group/zaproxy-develop
● Community Scripts: https://github.com/zaproxy/community-scripts
● JavaDocs: https://javadoc.io/doc/org.zaproxy/zap/2.6.0
Useful links
●
Fire up ZAP
●
Check for Updates (Help / Check for Updates...)
●
Update everything
●
Install Community Scripts
●
Optionally install Python / Ruby Scripting
●
Demo: “Hello world”
Getting started
●
Scripts tab
– Shows all of the scripts an templates
– Allows you to select, add, remove, duplicate, enable, disable and save scripts
– Icons show state – enabled / disabled, error and not saved
●
Script Console tab
– Top pane – edit scripts
– Bottom pane – output and error messages
– Run and Stop buttons – enabled when appropriate
– Output pane buttons – control that pane
– Right click for lots more options!
The tabs
●
Proxy Scripts
– Only affect requests and responses proxied via a browser
●
HTTP Sender Scripts
– Affect all requests and responses (proxy active scan, spider …)
– Initiator param gives the component that initiated the request
– Provides helper to make new requests
●
Both
– Must enable scripts before they will take effect
– Will be disabled on error
Proxy and HTTP Sender scripts
●
Key ZAP class: org/parosproxy/paros/network/HttpMessage.html
●
Provides methods like
– getRequestBody()
– getRequestHeader()
– getResponseBody()
– getResponseHeader()
● See JavaDocs: https://javadoc.io/doc/org.zaproxy/zap/2.6.0
● Or the code: https://github.com/zaproxy/zaproxy
Script parameter: HttpMessage - msg
●
Proxy Scripts
– Replace in request or response body.js
– Drop requests not in scope.js
– Return fake response.js
●
HTTP Sender Scripts
– Alert in HTTP Response Code Errors.js
– Alert on Unexpected Content Types.js
– Capture and Replace Anti CSRF Token.js
Proxy and HTTP Sender scripts - examples
Suggestions:
●
Replace headers
●
Auto redirect from one page to another
●
Do different things based on content, eg:
– Replace different content
– Redirect to different pages
Exercise – write Proxy &/ HTTP Sender scripts
●
Passive Rule Scripts
– Can only view requests and responses (should not change anything)
●
Active Rule Scripts
– Attack nodes or specific parameters
– Can do pretty much anything you like :)
– Must Enable Script Input Vectors
●
Both
– Can raise alerts
– Must enable scripts before they will take effect
– Will be disabled on error
Passive and Active Rule scripts
●
Passive Rule Scripts
– Server Header Disclosure.js
– Find emails.js
●
Active Rule Scripts
– User defined attacks.js
– gof_lite.js
●
Demo: testing passive and active rule scripts
Passive and Active Rule scripts - examples
●
Hacking ZAP Blog posts
– https://zaproxy.blogspot.com/2014/04/hacking-zap-3-passive-scan-rules.html
– https://zaproxy.blogspot.com/2014/04/hacking-zap-4-active-scan-rules.html
●
Java code
– https://github.com/zaproxy/zap-extensions
– master branch – org/zaproxy/zap/extension/ascanrules and pscanrules
– beta branch – org/zaproxy/zap/extension/ascanrulesBeta and pscanrulesBeta
– alpha branch – org/zaproxy/zap/extension/ascanrulesAlpha and pscanrulesAlpha
Passive and Active Rule links
●
Global Variables
– Variables can be shared between all scripts
org.zaproxy.zap.extension.script.ScriptVars.setGlobalVar("var.name","value")
org.zaproxy.zap.extension.script.ScriptVars.getGlobalVar("var.name")
●
Script Variables
– Variables can be shared between separate invocations of the same script
org.zaproxy.zap.extension.script.ScriptVars.setScriptVar(
this.context, "var.name","value")
org.zaproxy.zap.extension.script.ScriptVars.getScriptVar(
this.context, "var.name")
Variables (all script types)
Suggestions:
●
Rewrite existing java rules (see previous links)
●
Alert on anything that ZAP doesn’t currently find :)
Exercise – write Passive &/ Active Rule scripts
●
Domain Specific Language (DSL)
●
Its domain is security and automation
●
Closer to a macro language .. on steroids :)
●
Format – JSON :O
●
Intended to be ‘written’ graphically
●
Its tool independent (no access to ZAP internals)
●
Demo: “Hello world”
Zest Scripts
●
Creating from templates
●
Duplicating existing script
●
Recording
●
Selecting and adding requests
●
Manually
●
Demo: playing with BodgeIt
Zest Scripts - creating
●
Double click to edit nodes
●
Right click:
– Add and delete nodes
– Delete nodes
– Surround with loops, conditionals
– Cut, copy and paste
– Comment
– Move up / down
●
Drag and drop
●
Selecting and adding requests
Zest Scripts - editing
●
Request – make requests (and make assertions)
●
Action – scan, script, print, fail, sleep
●
Assignment – assign things to variables
●
Client – launch and control browsers
●
Conditions – and, or, equals, length, etc ...
●
Loop – though strings, files, integers, regexes, client elements
●
Comment – comment :)
●
Controls – return, break, next
Zest Scripts – statement types
●
Paste Zest variables (right click in Zest text boxes)
●
Parameterize strings (right click in requests)
●
Redact strings (right click in requests)
●
Drag and drop
●
Change prefix – applies to all requests
●
Anti CSRF tokens – automatically handled
●
Generate Zest script from alert
Zest Scripts – hidden extras
●
You have to start by launching a browser in Zest
●
No record option at the moment :(
●
Browser - View source / Inspect is your friend
●
Demo: Persona video …
Zest Scripts – client side
DevSecCon London 2017: zap scripting workshop by Simon Bennetts
Suggestions:
●
Passive script – alert on the presence of 2 strings
●
Rewrite a script you’ve just written in another language
●
Rewrite one of the existing a/pscan rules
●
Record a script and start changing it
Exercise – write Zest scripts
●
Both run ‘on-demand’ only
●
Standalone – run from the console
●
Targeted – right click on requests
●
Standard scripts (not Zest) – can access ZAP internals, eg:
– Sites tree
– History
– Other extensions
Standalone and Targeted scripts
●
Standalone Scripts
– loop through history table.js
– traverse sites tree.js
– domainFinder.js
– window_creation_template.js
●
Targeted Scripts
– Resend as a GET request.zst
– Find HTML comments.js
Standalone and Targeted scripts - examples
Suggestions:
●
Count number of static vs dynamic pages
●
Detect authentication, registration and password changing?
(1 2 and 3 password fields)
Exercise – Standalone and Targeted scripts
-config script.scripts(0).name="Remove STS"
-config script.scripts(0).engine="Mozilla Zest"
-config script.scripts(0).type=proxy
-config script.scripts(0).enabled=true
-config script.scripts(0).file="/scripts/Remove STS.zst"
-config script.scripts(1).name="Another one..."
Scripts in Automation – set via cmd line
zap.script.load("Remove STS", “proxy”, "Mozilla Zest",
"/scripts/Remove STS.zst")
zap.script.enable("Remove STS")
●
Pro Tip: Configure in the UI, look at whats set in config.xml ;)
Scripts in Automation – set via API
●
Implement a script interface
●
Implement one or more templates / examples which implement
the interface
●
Register a new script type:
ExtensionScript extensionScript = Control.getSingleton().
getExtensionLoader().getExtension(ExtensionScript.class);
extensionScript.registerScriptType(new ScriptType(
"newname", "i18nKey", icon, true, true));
Adding script support in add-ons
●
Use the enabled scripts:
ExtensionScript extensionScript = Control.getSingleton().
getExtensionLoader().getExtension(ExtensionScript.class);
List<ScriptWrapper> scripts = extension.getScripts("newname");
for (ScriptWrapper script : scripts) {
try {
if (script.isEnabled()) {
MyScript s = extension.getInterface(
script, MyScript.class);
// Do something with it...
}
Adding script support in add-ons
●
For when simple form based auth isnt enough
●
Need to configure context
●
Demo: BodgeIt authentication
● https://github.com/zaproxy/zaproxy/wiki/FAQformauth - auth FAQ
Authentication Scripts
Suggestions:
●
Authenticate against any vulnerable app you have installed
Exercise – Authentication scripts
Join the conversation
#DevSecCon
Many thanks
PRs always appreciated ;)

More Related Content

PDF
The Seven Habits of Highly Effective Puppet Users - PuppetConf 2014
PDF
Analysis of-quality-of-pkgs-in-packagist-univ-20171024
PDF
Php Dependency Management with Composer ZendCon 2017
PDF
Karim Fanadka
PDF
Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)
PDF
Automating Compliance with InSpec - Chef Singapore Meetup
PPT
Jenkins Scriptler in 90mins
PDF
JUC Europe 2015: Jenkins-Based Continuous Integration for Heterogeneous Hardw...
The Seven Habits of Highly Effective Puppet Users - PuppetConf 2014
Analysis of-quality-of-pkgs-in-packagist-univ-20171024
Php Dependency Management with Composer ZendCon 2017
Karim Fanadka
Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)
Automating Compliance with InSpec - Chef Singapore Meetup
Jenkins Scriptler in 90mins
JUC Europe 2015: Jenkins-Based Continuous Integration for Heterogeneous Hardw...

What's hot (18)

PPTX
Drupal Continuous Integration with Jenkins - The Basics
PDF
London Hashicorp Meetup #8 - Testing Programmable Infrastructure By Matt Long
PDF
What's new with Apache Camel 3? | DevNation Tech Talk
PPTX
Grooving with Jenkins
PPTX
Using Chef InSpec for Infrastructure Security
PPTX
Automated Infrastructure Testing
PDF
ContainerCon - Test Driven Infrastructure
ODP
OWASP 2013 APPSEC USA ZAP Hackathon
PDF
JUC Europe 2015: Scaling of Jenkins Pipeline Creation and Maintenance
PDF
Codifying the Build and Release Process with a Jenkins Pipeline Shared Library
PPT
Getting Started With Jenkins And Drupal
PPTX
Adding Security to Your Workflow With InSpec - SCaLE17x
PDF
Expressive Microservice Framework Blastoff
PDF
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
PDF
2013 10-28 php ug presentation - ci using phing and hudson
KEY
Continuous Integration & Drupal
PPTX
Continuous Integration With Jenkins Docker SQL Server
PDF
In graph we trust: Microservices, GraphQL and security challenges
Drupal Continuous Integration with Jenkins - The Basics
London Hashicorp Meetup #8 - Testing Programmable Infrastructure By Matt Long
What's new with Apache Camel 3? | DevNation Tech Talk
Grooving with Jenkins
Using Chef InSpec for Infrastructure Security
Automated Infrastructure Testing
ContainerCon - Test Driven Infrastructure
OWASP 2013 APPSEC USA ZAP Hackathon
JUC Europe 2015: Scaling of Jenkins Pipeline Creation and Maintenance
Codifying the Build and Release Process with a Jenkins Pipeline Shared Library
Getting Started With Jenkins And Drupal
Adding Security to Your Workflow With InSpec - SCaLE17x
Expressive Microservice Framework Blastoff
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
2013 10-28 php ug presentation - ci using phing and hudson
Continuous Integration & Drupal
Continuous Integration With Jenkins Docker SQL Server
In graph we trust: Microservices, GraphQL and security challenges
Ad

Similar to DevSecCon London 2017: zap scripting workshop by Simon Bennetts (20)

ODP
OWASP 2013 APPSEC USA Talk - OWASP ZAP
PPTX
Zap api and scripting - @iprav33nk
PDF
N Different Strategies to Automate OWASP ZAP - OWASP APPSec BUCHAREST - Oct 1...
ODP
2017 Codemotion OWASP ZAP in CI/CD
ODP
AllDayDevOps ZAP automation in CI
PDF
Security Testing with OWASP ZAP in CI/CD - Simon Bennetts - Codemotion Amster...
ODP
Simon Bennetts - Automating ZAP
ODP
Automating OWASP ZAP - DevCSecCon talk
PDF
N Different Strategies to Automate OWASP ZAP - Cybersecurity WithTheBest - Oc...
ODP
BSides Manchester 2014 ZAP Advanced Features
ODP
OWASP 2013 AppSec EU Hamburg - ZAP Innovations
ODP
JavaOne 2014 Security Testing for Developers using OWASP ZAP
ODP
OWASP 2014 AppSec EU ZAP Advanced Features
ODP
OWASP Zed Attack Proxy Demonstration - OWASP Bangalore Nov 22 2014
ODP
OWASP 2013 Limerick - ZAP: Whats even newer
ODP
2014 ZAP Workshop 1: Getting Started
ODP
OWASP 2013 EU Tour Amsterdam ZAP Intro
PDF
Automated Security Testing
PDF
PPTX
ZAP @FOSSASIA2015
OWASP 2013 APPSEC USA Talk - OWASP ZAP
Zap api and scripting - @iprav33nk
N Different Strategies to Automate OWASP ZAP - OWASP APPSec BUCHAREST - Oct 1...
2017 Codemotion OWASP ZAP in CI/CD
AllDayDevOps ZAP automation in CI
Security Testing with OWASP ZAP in CI/CD - Simon Bennetts - Codemotion Amster...
Simon Bennetts - Automating ZAP
Automating OWASP ZAP - DevCSecCon talk
N Different Strategies to Automate OWASP ZAP - Cybersecurity WithTheBest - Oc...
BSides Manchester 2014 ZAP Advanced Features
OWASP 2013 AppSec EU Hamburg - ZAP Innovations
JavaOne 2014 Security Testing for Developers using OWASP ZAP
OWASP 2014 AppSec EU ZAP Advanced Features
OWASP Zed Attack Proxy Demonstration - OWASP Bangalore Nov 22 2014
OWASP 2013 Limerick - ZAP: Whats even newer
2014 ZAP Workshop 1: Getting Started
OWASP 2013 EU Tour Amsterdam ZAP Intro
Automated Security Testing
ZAP @FOSSASIA2015
Ad

More from DevSecCon (20)

PDF
DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
PDF
DevSecCon London 2019: Are Open Source Developers Security’s New Front Line?
PDF
DevSecCon London 2019: How to Secure OpenShift Environments and What Happens ...
PDF
DevSecCon London 2019: A Kernel of Truth: Intrusion Detection and Attestation...
PPTX
DevSecCon Seattle 2019: Containerizing IT Security Knowledge
PPTX
DevSecCon Seattle 2019: Decentralized Authorization - Implementing Fine Grain...
PPTX
DevSecCon Seattle 2019: Liquid Software as the real solution for the Sec in D...
PPTX
DevSecCon Seattle 2019: Fully Automated production deployments with HIPAA/HIT...
PDF
DevSecCon Singapore 2019: Four years of reflection: How (not) to secure Web A...
PPTX
DevSecCon Singapore 2019: crypto jacking: An evolving threat for cloud contai...
PDF
DevSecCon Singapore 2019: Can "dev", "sec" and "ops" really coexist in the wi...
PDF
DevSecCon Singapore 2019: Workshop - Burp extension writing workshop
PDF
DevSecCon Singapore 2019: Embracing Security - A changing DevOps landscape
PDF
DevSecCon Singapore 2019: Web Services aren’t as secure as we think
PDF
DevSecCon Singapore 2019: An attacker's view of Serverless and GraphQL apps S...
PDF
DevSecCon Singapore 2019: The journey of digital transformation through DevSe...
PDF
DevSecCon Singapore 2019: Preventative Security for Kubernetes
PPTX
DevSecCon London 2018: Is your supply chain your achille's heel
PPTX
DevSecCon London 2018: Get rid of these TLS certificates
PDF
DevSecCon London 2018: Open DevSecOps
DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
DevSecCon London 2019: Are Open Source Developers Security’s New Front Line?
DevSecCon London 2019: How to Secure OpenShift Environments and What Happens ...
DevSecCon London 2019: A Kernel of Truth: Intrusion Detection and Attestation...
DevSecCon Seattle 2019: Containerizing IT Security Knowledge
DevSecCon Seattle 2019: Decentralized Authorization - Implementing Fine Grain...
DevSecCon Seattle 2019: Liquid Software as the real solution for the Sec in D...
DevSecCon Seattle 2019: Fully Automated production deployments with HIPAA/HIT...
DevSecCon Singapore 2019: Four years of reflection: How (not) to secure Web A...
DevSecCon Singapore 2019: crypto jacking: An evolving threat for cloud contai...
DevSecCon Singapore 2019: Can "dev", "sec" and "ops" really coexist in the wi...
DevSecCon Singapore 2019: Workshop - Burp extension writing workshop
DevSecCon Singapore 2019: Embracing Security - A changing DevOps landscape
DevSecCon Singapore 2019: Web Services aren’t as secure as we think
DevSecCon Singapore 2019: An attacker's view of Serverless and GraphQL apps S...
DevSecCon Singapore 2019: The journey of digital transformation through DevSe...
DevSecCon Singapore 2019: Preventative Security for Kubernetes
DevSecCon London 2018: Is your supply chain your achille's heel
DevSecCon London 2018: Get rid of these TLS certificates
DevSecCon London 2018: Open DevSecOps

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
KodekX | Application Modernization Development
PPT
Teaching material agriculture food technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Spectral efficient network and resource selection model in 5G networks
Review of recent advances in non-invasive hemoglobin estimation
Chapter 3 Spatial Domain Image Processing.pdf
Empathic Computing: Creating Shared Understanding
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Electronic commerce courselecture one. Pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Digital-Transformation-Roadmap-for-Companies.pptx
Understanding_Digital_Forensics_Presentation.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KodekX | Application Modernization Development
Teaching material agriculture food technology
MIND Revenue Release Quarter 2 2025 Press Release
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
sap open course for s4hana steps from ECC to s4
Dropbox Q2 2025 Financial Results & Investor Presentation
MYSQL Presentation for SQL database connectivity
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation_ Review paper, used for researhc scholars
Spectral efficient network and resource selection model in 5G networks

DevSecCon London 2017: zap scripting workshop by Simon Bennetts

  • 1. Join the conversation #DevSecCon By Simon Bennetts Scripting OWASP ZAP
  • 2. ● Session 1 : 2pm – Introduction – Standard Scripts (JavaScript, Python, Ruby) – Proxy and Http Sender Scripts – Passive and Active Scan rule Scripts ● Session 2 : 3pm – Zest Scripts – Standalone and Targeted Scripts The Plan
  • 3. ● Session 3 : 4pm – How to use scripts in automation – How to add scripting support in add-ons (overview) – Authentication Scripts – More chance to write any or all of the above types ● Session 4 : 5pm – Optional – keep writing scripts, ask more questions... The Plan
  • 4. ● We want more script examples ● Submit PRs to https://github.com/zaproxy/community-scripts ● Can be anything useful – eg copies of existing scripts in different languages :) ● Anything useful will earn a ZAP Contributor sticker (max one per person) ● Lots of useful scripts will earn a ZAP T-shirt! ● Only valid for this workshop Competition Time!
  • 5. ● Advantages: – Quick to write and test – Full access to ZAP classes and data structures – No need for separate development environment ● Disadvantages – Documentation could be (much) better – No auto complete – No sandbox – only run scripts you trust! Introduction – why do we need scripts?
  • 6. ● JavaScript – built in ● Python – optional add-on ● Ruby – optional add-on ● Zest – built in, macro language on steroids ● JSR 223 languages relatively easy to add ● Beanshell – optional, no longer really maintained Introduction – What languages are supported?
  • 7. ● Stand Alone – Run manually ● Targeted – Run manually against a specified requests ● Proxy – Change proxied browser requests on the fly ● HTTP Sender – Change any request on the fly (proxy, spider, active scanner ...) Script types (built in)
  • 8. ● Passive Scan Rule – Detect potential issues just by looking ● Active Scan Rule – Detect potential issues by attacking ● Authentication – Automatically login to sites ● Script Input Vector – Define exactly what ZAP will attack Script types (built in)
  • 9. ● Fuzzer HTTP Processor – Called before and after HTTP messages are fuzzed ● Fuzzer Websocket Processor – Called before and after Websocket messages are fuzzed ● Payload Generator – Generate attacks to be used in the fuzzer ● Payload Processor – Change fuzzer payloads before they are used ● Sequence – Define sequences of requests to be attacked (alpha) Script types (add-ons)
  • 10. ● All roughly equivalent ● All have good Java integration ● JavaScript (ECMAScript) – Java 7 – Rhino – Java 8 – Nashhorn – Can write to local filestore via Java classes – Use load("nashorn:mozilla_compat.js"); for Rhino scripts in Nashorn ● JavaScript Nashhorn – supports loading scripts from files – https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions ● Python – supports modules path ‘Standard’ Script languages
  • 11. ● Scripts group: https://groups.google.com/group/zaproxy-scripts ● Dev group: https://groups.google.com/group/zaproxy-develop ● Community Scripts: https://github.com/zaproxy/community-scripts ● JavaDocs: https://javadoc.io/doc/org.zaproxy/zap/2.6.0 Useful links
  • 12. ● Fire up ZAP ● Check for Updates (Help / Check for Updates...) ● Update everything ● Install Community Scripts ● Optionally install Python / Ruby Scripting ● Demo: “Hello world” Getting started
  • 13. ● Scripts tab – Shows all of the scripts an templates – Allows you to select, add, remove, duplicate, enable, disable and save scripts – Icons show state – enabled / disabled, error and not saved ● Script Console tab – Top pane – edit scripts – Bottom pane – output and error messages – Run and Stop buttons – enabled when appropriate – Output pane buttons – control that pane – Right click for lots more options! The tabs
  • 14. ● Proxy Scripts – Only affect requests and responses proxied via a browser ● HTTP Sender Scripts – Affect all requests and responses (proxy active scan, spider …) – Initiator param gives the component that initiated the request – Provides helper to make new requests ● Both – Must enable scripts before they will take effect – Will be disabled on error Proxy and HTTP Sender scripts
  • 15. ● Key ZAP class: org/parosproxy/paros/network/HttpMessage.html ● Provides methods like – getRequestBody() – getRequestHeader() – getResponseBody() – getResponseHeader() ● See JavaDocs: https://javadoc.io/doc/org.zaproxy/zap/2.6.0 ● Or the code: https://github.com/zaproxy/zaproxy Script parameter: HttpMessage - msg
  • 16. ● Proxy Scripts – Replace in request or response body.js – Drop requests not in scope.js – Return fake response.js ● HTTP Sender Scripts – Alert in HTTP Response Code Errors.js – Alert on Unexpected Content Types.js – Capture and Replace Anti CSRF Token.js Proxy and HTTP Sender scripts - examples
  • 17. Suggestions: ● Replace headers ● Auto redirect from one page to another ● Do different things based on content, eg: – Replace different content – Redirect to different pages Exercise – write Proxy &/ HTTP Sender scripts
  • 18. ● Passive Rule Scripts – Can only view requests and responses (should not change anything) ● Active Rule Scripts – Attack nodes or specific parameters – Can do pretty much anything you like :) – Must Enable Script Input Vectors ● Both – Can raise alerts – Must enable scripts before they will take effect – Will be disabled on error Passive and Active Rule scripts
  • 19. ● Passive Rule Scripts – Server Header Disclosure.js – Find emails.js ● Active Rule Scripts – User defined attacks.js – gof_lite.js ● Demo: testing passive and active rule scripts Passive and Active Rule scripts - examples
  • 20. ● Hacking ZAP Blog posts – https://zaproxy.blogspot.com/2014/04/hacking-zap-3-passive-scan-rules.html – https://zaproxy.blogspot.com/2014/04/hacking-zap-4-active-scan-rules.html ● Java code – https://github.com/zaproxy/zap-extensions – master branch – org/zaproxy/zap/extension/ascanrules and pscanrules – beta branch – org/zaproxy/zap/extension/ascanrulesBeta and pscanrulesBeta – alpha branch – org/zaproxy/zap/extension/ascanrulesAlpha and pscanrulesAlpha Passive and Active Rule links
  • 21. ● Global Variables – Variables can be shared between all scripts org.zaproxy.zap.extension.script.ScriptVars.setGlobalVar("var.name","value") org.zaproxy.zap.extension.script.ScriptVars.getGlobalVar("var.name") ● Script Variables – Variables can be shared between separate invocations of the same script org.zaproxy.zap.extension.script.ScriptVars.setScriptVar( this.context, "var.name","value") org.zaproxy.zap.extension.script.ScriptVars.getScriptVar( this.context, "var.name") Variables (all script types)
  • 22. Suggestions: ● Rewrite existing java rules (see previous links) ● Alert on anything that ZAP doesn’t currently find :) Exercise – write Passive &/ Active Rule scripts
  • 23. ● Domain Specific Language (DSL) ● Its domain is security and automation ● Closer to a macro language .. on steroids :) ● Format – JSON :O ● Intended to be ‘written’ graphically ● Its tool independent (no access to ZAP internals) ● Demo: “Hello world” Zest Scripts
  • 24. ● Creating from templates ● Duplicating existing script ● Recording ● Selecting and adding requests ● Manually ● Demo: playing with BodgeIt Zest Scripts - creating
  • 25. ● Double click to edit nodes ● Right click: – Add and delete nodes – Delete nodes – Surround with loops, conditionals – Cut, copy and paste – Comment – Move up / down ● Drag and drop ● Selecting and adding requests Zest Scripts - editing
  • 26. ● Request – make requests (and make assertions) ● Action – scan, script, print, fail, sleep ● Assignment – assign things to variables ● Client – launch and control browsers ● Conditions – and, or, equals, length, etc ... ● Loop – though strings, files, integers, regexes, client elements ● Comment – comment :) ● Controls – return, break, next Zest Scripts – statement types
  • 27. ● Paste Zest variables (right click in Zest text boxes) ● Parameterize strings (right click in requests) ● Redact strings (right click in requests) ● Drag and drop ● Change prefix – applies to all requests ● Anti CSRF tokens – automatically handled ● Generate Zest script from alert Zest Scripts – hidden extras
  • 28. ● You have to start by launching a browser in Zest ● No record option at the moment :( ● Browser - View source / Inspect is your friend ● Demo: Persona video … Zest Scripts – client side
  • 30. Suggestions: ● Passive script – alert on the presence of 2 strings ● Rewrite a script you’ve just written in another language ● Rewrite one of the existing a/pscan rules ● Record a script and start changing it Exercise – write Zest scripts
  • 31. ● Both run ‘on-demand’ only ● Standalone – run from the console ● Targeted – right click on requests ● Standard scripts (not Zest) – can access ZAP internals, eg: – Sites tree – History – Other extensions Standalone and Targeted scripts
  • 32. ● Standalone Scripts – loop through history table.js – traverse sites tree.js – domainFinder.js – window_creation_template.js ● Targeted Scripts – Resend as a GET request.zst – Find HTML comments.js Standalone and Targeted scripts - examples
  • 33. Suggestions: ● Count number of static vs dynamic pages ● Detect authentication, registration and password changing? (1 2 and 3 password fields) Exercise – Standalone and Targeted scripts
  • 34. -config script.scripts(0).name="Remove STS" -config script.scripts(0).engine="Mozilla Zest" -config script.scripts(0).type=proxy -config script.scripts(0).enabled=true -config script.scripts(0).file="/scripts/Remove STS.zst" -config script.scripts(1).name="Another one..." Scripts in Automation – set via cmd line
  • 35. zap.script.load("Remove STS", “proxy”, "Mozilla Zest", "/scripts/Remove STS.zst") zap.script.enable("Remove STS") ● Pro Tip: Configure in the UI, look at whats set in config.xml ;) Scripts in Automation – set via API
  • 36. ● Implement a script interface ● Implement one or more templates / examples which implement the interface ● Register a new script type: ExtensionScript extensionScript = Control.getSingleton(). getExtensionLoader().getExtension(ExtensionScript.class); extensionScript.registerScriptType(new ScriptType( "newname", "i18nKey", icon, true, true)); Adding script support in add-ons
  • 37. ● Use the enabled scripts: ExtensionScript extensionScript = Control.getSingleton(). getExtensionLoader().getExtension(ExtensionScript.class); List<ScriptWrapper> scripts = extension.getScripts("newname"); for (ScriptWrapper script : scripts) { try { if (script.isEnabled()) { MyScript s = extension.getInterface( script, MyScript.class); // Do something with it... } Adding script support in add-ons
  • 38. ● For when simple form based auth isnt enough ● Need to configure context ● Demo: BodgeIt authentication ● https://github.com/zaproxy/zaproxy/wiki/FAQformauth - auth FAQ Authentication Scripts
  • 39. Suggestions: ● Authenticate against any vulnerable app you have installed Exercise – Authentication scripts
  • 40. Join the conversation #DevSecCon Many thanks PRs always appreciated ;)

Editor's Notes

  • #2: &amp;lt;number&amp;gt;