DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Application Security in Technical Product Management
  • Combatting the OpenSSH Vulnerability
  • Penetration Testing: A Comprehensive Guide
  • What Is Pen Testing?

Trending

  • How To Build Resilient Microservices Using Circuit Breakers and Retries: A Developer’s Guide To Surviving
  • Developers Beware: Slopsquatting and Vibe Coding Can Increase Risk of AI-Powered Attacks
  • Enforcing Architecture With ArchUnit in Java
  • Chat With Your Knowledge Base: A Hands-On Java and LangChain4j Guide
  1. DZone
  2. Software Design and Architecture
  3. Security
  4. Scripting Authenticated Login Within ZAP Vulnerability Scanner

Scripting Authenticated Login Within ZAP Vulnerability Scanner

Learn how to use the ZAP scripting language Zest to create authenticated logins and incorporate automated security testing in your web application.

By 
Ben Pick user avatar
Ben Pick
·
Mar. 23, 17 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
22.8K Views

Join the DZone community and get the full member experience.

Join For Free

OWASP Zed Attack Proxy (ZAP) is one of my favorite tools for scanning and performing vulnerability tests on a web application. It has a simple GUI to get started, with a large capability for customization to tailor scans as needed.

Recently, I was faced with the problem of logging in and then scanning the authenticated segments of a web application. Seems easy: pass in the username and password fields and define their parameters. Except that the post request also required a token parameter for added security. This token is obtained from the Javascript header on the landing page.

Below is an excerpt of the code:

If the token is not included with the login script as a POST parameter, the request will be rejected. A sample request header is shown, with the POST parameters included under the Form Data. To not be rejected, causing a custom 500 error page return, the _token must equal the value of the csrf-token.

This presented a challenge beyond ZAP’s Basic Authentication scripting capabilities. Simply getting ZAP to enter the username and password, as prompted by the application was unsuccessful, as it was unable to automatically extract the token value. In cases where it was able to obtain a token, it was not refreshing the page, so the token obtained was from a previous session. Attempting to spider or access pages requiring authentication resulted in 500 or 405 errors. The application returned a custom 500 error when failing to access a given page. These error codes indicated that ZAP failed to load the correct page.

ZAP scanned only a limited portion of the application, as most of the pages and features required authentication.

ZAP Scripting With Zest

Enter Zest, the ZAP scripting language. This language is built around accomplishing tasks, such as fuzzing data, traversal through a website, or authentication.

As the authenticated login for my target website was a bit complicated, a custom script was needed. There were several different methods of constructing the Zest scripts to perform the scan. By far the easiest was to Record a new Zest Script.

Clicking the button, shown below, in the top navigation bar brings up a popup menu to record all of the actions performed.

Image title


For this script, I began the recording on the landing page of the web application. When ZAP recorded this page, it gathered the token and learned to serve it with the login parameters. This recording extracted the token and automated the login process.

After creating these scripts with Zest, be sure to remove extra steps or page calls to simplify the repeatable process.

In my case, the login steps required only 3 steps: start at the landing page, submit the login, and redirect to the authenticated landing page. Along the way, there were dozens of pages and files accessed to help visually display the page. These page loads were unnecessary for login, so they were removed from the script.

The end result is the script containing the 3 requests shown:

Image title

Test the Zest script by pressing the Run button. This executes the script. A 200 HTTP response on the authenticated page indicates the script successfully logged in.

Image title


A custom Context is used to apply the Login Script from Zest to run the recorded tasks.

Image title

To get the best results, spider the site first using the Context to find all of the authenticated pages that are available. Then an Active Scan is performed on each page identified.

One tip I discovered was to ensure that the Forced User Mode button is not selected.

Image title

The locked icon needed to be set to unlocked, otherwise, the token became fixated on the value used when creating the Zest script and not renewed with each test execution. This was very frustrating to overlook as it caused the script to succeed, but the login attempts to fail.

Another problem was that the login URL for the Zest script needed to begin at the starting homepage, and not the login page, to work properly. For this web application, the token was set the first time the user accesses the homepage. Therefore, the scripts needed to start at that page to obtain a new token before moving to the login.

To do this, set the LoginURL to the starting page within the Context settings. In this case, I needed to use the LoginURL of the homepage, https://[myapp], instead of the login page at https://[myapp]/auth/login.

With these steps applied, automated security testing was incorporated into the application's DevOps process and tools. These fast automated scans were able to run after each code change to identify common security issues, which can then be addressed by the development team.   

500 error page return

application Vulnerability

Published at DZone with permission of Ben Pick. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Application Security in Technical Product Management
  • Combatting the OpenSSH Vulnerability
  • Penetration Testing: A Comprehensive Guide
  • What Is Pen Testing?

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!