Penetration Test a dotnet Core Web API with OWASP ZAP

Saturday, July 22, 2023

Penetration Test a dotnet Core Web API with OWASP ZAP

#active-scan #docker #dotnet-core #entity-framework-core #mssql #owasp-zap #web-api

This article is published at GitHub.You can raise issues, create pull requests or even fork the content...its open source.

In this article, you will learn how to penetration test a dotnet Core Web API project with OWASP ZAP.

Prerequisites

The following prerequisites will be required to complete this tutorial:

Create an Open API definition

  1. Create a new folder name zap in the deploy folder which is in the root of the MonitoringDockerStack solution.

    Visual Studio Folder View Create New Folder

  2. Add a new json file named monitoredapidefinition with the following contents.

    {
    "openapi": "3.0.1",
    "info": {
        "title": "Monitored.API",
        "version": "1.0"
    },
    "servers": [
        {
        "url" : "https://localhost:5021"
        }
    ],
    "paths": {
        "/WeatherForecast": {
        "get": {
            "tags": [
            "WeatherForecast"
            ],
            "operationId": "GetWeatherForecast",
            "parameters": [
            {
                "name": "take",
                "in": "query",
                "schema": {
                "type": "integer",
                "format": "int32",
                "default": 10
                }
            },
            {
                "name": "skip",
                "in": "query",
                "schema": {
                "type": "integer",
                "format": "int32",
                "default": 0
                }
            }
            ],
            "responses": {
            "200": {
                "description": "Success"
            }
            }
        }
        }
    },
    "components": { }
    }
    

Run ZAP API Scan in Docker via Powershell

  1. In Visual Studio, right click on the MonitoringDockerStack solution, and select Open in Terminal.

    Visual Studio Folder View Create New Folder

  2. run the following command to navigate into the zap folder.

    cd deploy/zap
    
  3. Ensure the MonitoringDockerStack in running in Docker and then execute the following command.

    docker run -i -t --network=host --rm -v "$(pwd):/zap/wrk/:rw" -t owasp/zap2docker-weekly
    

    OWASP Zap Run Docker Container

  4. Once in the container, run the zap api scan with the following command.

    ./zap-api-scan.py -g api-scan.conf -t monitoredapidefinition.json -f openapi -r api-scan-report.html
    

    OWASP Zap API Scan CMD Report

View OWASP ZAP API Scan Report

  1. In Visual Studio, right click on the MonitoringDockerStack solution, and select Open in Terminal.

  2. Run the following command to get the name of the running zap container and make a copy of the container name.

    docker ps
    

    OWASP Zap Running Container

  3. Run the following command to copy the api-scan-report.html in the container onto your device. Replace {ZapContainerName} with your zap container and {FolderOnYourDevice} to a folder on your device.

    docker cp {ZapContainerName}:/zap/wrk/api-scan-report.html "C:\{FolderOnYourDevice}\zap\api-scan-report.html"
    

    OWASP ZAP Copy Scan Report From Container To Device

  4. To view the report, navigate to the api-scan-report.html on your device and open it in a browser.

    OWASP Zap API Scan Report

Got a comment?

All my articles are written and managed as Markdown files on GitHub.

Please add an issue or submit a pull request if something is not right on this article or you have a comment.

If you'd like to simply say "thanks", then please send me a so the rest of Twitter can see how awesome my work is.

An unhandled error has occurred. Reload