본문 바로가기
IT 정보

OWASP ZAP automated scan

by 망고노트 2025. 6. 22.
728x90
반응형

 

OWASP ZAP automated scan
 

아래는 OWASP ZAP의 자동화 스캔(Automated Scan)을 핵심 개념부터 CLI/자동화 예시까지 쉽게 정리한 안내입니다. 빠르게 자동 점검 흐름을 설정하고, CI/CD에 통합하는 데 유용해요. ⚙️


✅ 1. 자동 스캔 개요 (Quick Start)

장점: 설치 후 바로 실행 가능하며, UI 기반으로 직관적
주의: 권한 없는 대상에 실행 시 실제 공격이 될 수 있으니 사전 허가 필수


🧰 2. 명령줄 자동 스캔

A. Quick Start Command Line

zap.sh -cmd -quickurl https://example.com -quickprogress -quickout report.html

B. Docker 기반 패키지 스캔

  • baseline: 크롤링 + 기본 스캔
  • full-scan: 추가 테스트 및 리포트까지 일괄 수행 stackoverflow.com

🛠 3. 자동화 프레임워크 (YAML 기반)

예시 흐름 구성 YAML

jobs:
  - type: spider
    config: { url: https://example.com }
  - type: ajaxSpider
  - type: activeScan
    config: { recurse: true }
  - type: report
    config: { template: risk-html, reportFile: zap_report.html }
  • 스파이더 → AJAX 스파이더 → 액티브 스캔 → 리포트 생성 흐름
  • Authentication, API 정의(OpenAPI/HAR) 포함된 애플리케이션도 스캔 가능 jit.iodzone.com

🧪 4. CI/CD 연동

  • 명령행 방식 실행 예시:
  • bash
     
    zap.sh -cmd -autorun ./zap-plan.yaml
  • Docker 연계:→ 로컬 스캔 계획 파일을 컨테이너에서 실행
  • bash
     
    docker run -v $(pwd):/zap/wrk/:rw -t owasp/zap2docker-stable \
      zap.sh -cmd -addonupdate; zap.sh -cmd -autorun /zap/wrk/plan.yaml

→ GitHub Actions, Jenkins, Azure DevOps 등 CI 파이프라인에 포함 가능


🎥 자동 스캔 데모 영상

 

📌 요약 한눈에

방식 설명
UI 기반 빠르게 테스트, 직관적 사용
CLI/d…ocker 스크립트 통합 가능, CI에 최적
YAML 자동화 세밀한 스캔 구성 및 리포팅 가능
CI/CD 연동 정기 스캔, 리포트 자동화, 경고 알림
 

 


🔧 1. YAML 기반 스캔 플랜 예시

env:
  contexts:
  - name: "AppContext"
    urls:
    - "https://example.com"
    includePaths:
    - "https://example.com.*"
    authentication:
      method: "manual"
      parameters: {}
    sessionManagement:
      method: "cookie"
      parameters: {}
    parameters:
      failOnError: true
      failOnWarning: false
      progressToStdout: true

jobs:
- type: spider
- type: ajaxSpider
- type: activeScan
  config:
    recurse: true
    scanPolicyName: "Default Policy"
- type: report
  config:
    template: "traditional-html"
    reportFile: "zap_report.html"
- type: exitStatus
  config:
    alertThreshold: "Medium"
    failureThreshold: "High"

이 플랜은 스파이더 → AJAX 스파이더 → 액티브 스캔 → 리포트 → 종료 상태 평가까지 자동으로 수행합니다 zaproxy.org+15zaproxy.org+15sam-alizadeh.medium.com+15github.com.


🔄 2. CI/CD에 ZAP 통합 샘플 스크립트

✅ Docker + GitHub Actions 예제

name: OWASP ZAP Scan
on:
  push:
    branches: [main]

jobs:
  zap-scan:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Start web app
        run: ./start_app.sh & sleep 10

      - name: Run ZAP Baseline Scan
        uses: zaproxy/action-baseline@v0.4.0
        with:
          target: 'http://localhost:8080'
          format: 'HTML'
          fail-on-high: true

      - name: Upload report
        uses: actions/upload-artifact@v3
        with:
          name: zap-report
          path: zap_report.html

✅ Jenkins + Docker 예제

pipeline {
  agent any
  stages {
    stage('ZAP Scan') {
      steps {
        sh 'docker run -v $(pwd):/zap/wrk/:rw -t owasp/zap2docker-stable \
          zap-baseline.py -t http://app:8080 -r zap_report.html'
      }
    }
    stage('Archive Report') {
      steps {
        archiveArtifacts artifacts: 'zap_report.html'
      }
    }
  }
}

Jenkins는 Docker 컨테이너로 실행하고, GitHub Actions는 공식 액션을 사용하여 스캔 및 리포트 업로드를 처리합니다 .


🛡️ 3. 인증 설정 포함 자동 스캔 구성 가이드

✅ YAML 예시 (Form 기반 로그인)

env:
  contexts:
  - name: "AuthContext"
    urls:
    - "https://example.com/login"
    authentication:
      method: "form"
      parameters:
        loginUrl: "https://example.com/login"
        loginRequestData: "username=admin&password=secret"
        loggedInIndicator: "Welcome, admin"
        loggedOutIndicator: "Login"
    sessionManagement:
      method: "cookie"
      parameters: {}
...

✅ 스크립트 인증 예시 (JavaScript)

authentication:
  method: "script"
  parameters:
    script: "/zap/wrk/login.js"
    scriptEngine: "ECMAScript : Oracle Nashorn"
    usernameField: "user"
    passwordField: "pass"
    loginUrl: "https://app.com/login"
    loggedInRegex: "HTTP/1.1 200 OK"
    loggedOutRegex: "HTTP/1.1 401 Unauthorized"
users:
- name: "testUser"
  credentials:
    username: "admin"
    password: "secret"

이 방식은 Form 기반 뿐 아니라 스크립트 기반 인증도 지원하며, API 토큰 방식도 대응 가능합니다 zaproxy.org.


✅ 요약 📋

항목 내용
YAML 플랜 spider→ajaxSpider→activeScan→report 자동 흐름
CI/CD 통합 GitHub Actions, Jenkins 예제 포함
인증 처리 Form 및 Script 방식 로그인 자동화
 

 

1️⃣ login.js 스크립트 예시 (ZAP 자동 인증)

form-based 로그인 자동화용 스크립트 예시 (Nashorn 엔진)

function getRequiredParamsNames(){
  return ["loginUrl","usernameField","passwordField"];
}
function getOptionalParamsNames(){ return []; }
function getCredentialsParamsNames(){ return ["username","password"]; }

function authenticate(helper, paramsValues, credentials){
  var msg = helper.prepareMessage();
  msg.getRequestHeader().setURI(paramsValues.get("loginUrl"));
  msg.getRequestHeader().setMethod("POST");
  var body = paramsValues.get("usernameField") + "=" + encodeURIComponent(credentials.get("username"))
           + "&" + paramsValues.get("passwordField") + "=" + encodeURIComponent(credentials.get("password"));
  msg.getRequestHeader().setHeader("Content-Type","application/x-www-form-urlencoded");
  msg.setRequestBody(body);
  helper.sendAndReceive(msg);
  return msg;
}

2️⃣ GitHub Actions 전체 워크플로우 샘플

name: ZAP Authenticated Scan

on: [push]

jobs:
  zap_scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Start app
        run: ./start_app.sh & sleep 15

      - name: Run ZAP Authenticated Scan
        uses: zaproxy/action-af@v0.2.0
        with:
          plan: '.github/zap/scan-plan.yml'
          docker_name: 'owasp/zap2docker-stable'
          docker_env_vars: |
            TARGET_URL
            ZAP_AUTH_HEADER
            ZAP_AUTH_HEADER_SITE

      - name: Archive report
        uses: actions/upload-artifact@v3
        with:
          name: zap-report
          path: '**/zap_report.html'

3️⃣ Jenkins 인증 + 자동 스캔 구성

pipeline {
  agent any
  stages {
    stage('Build & Deploy'){
      steps {
        sh './build.sh && ./start_app.sh & sleep 15'
      }
    }
    stage('ZAP Auth Scan') {
      steps {
        sh '''
        docker run -v $(pwd)/.github/zap:/zap/wrk/:rw \
          -t owasp/zap2docker-stable \
          zap.sh -cmd -autorun /zap/wrk/scan-plan.yml
        '''
      }
    }
    stage('Archive Report'){
      steps {
        archiveArtifacts artifacts: '**/zap_report.html'
      }
    }
  }
}
  • Docker 컨테이너 내에서 인증 + 액티브 스캔 + 리포트 생성까지 자동 실행 후 출력 저장 방식입니다 .

✅ 요약

항목 내용
✅ login.js form 인증 자동 실행을 위한 스크립트
✅ GitHub Actions YAML action-af 사용, 승인된 CI 연동
✅ Jenkins 스크립트 인증 및 자동 스캔 → 리포트 수집

 

이 글이 도움이 되셨다면
🔔 구독❤️ 좋아요  꾸우욱 눌러 주세요!🙏

그리고 💖커피 ☕, 💚차 🍵, 💛맥주 🍺, ❤️와인 🍷  중 마음에 드시는 한 잔으로 💰 후원해 주시면 큰 힘이 됩니다.

                                                                             👇 지금 바로 아래 🔘버튼을 꾸욱 눌러 📣 응원해 주세요! 👇  

728x90
반응형

 

이 글이 도움이 되셨다면
🔔 구독❤️ 좋아요 꾸우욱 눌러 주세요!🙏

그리고 💖커피 ☕, 💚차 🍵, 💛맥주 🍺, ❤️와인 🍷 중 마음에 드시는 한 잔으로 💰 후원해 주시면 큰 힘이 됩니다.

👇 지금 바로 아래 🔘버튼을 꾸욱 눌러 📣 응원해 주세요! 👇