iT邦幫忙

2025 iThome 鐵人賽

DAY 15
0

大家好!我目前正在就讀資訊類科系,平常以接觸程式撰寫居多,對於資安領域的技術沒有太多了解/images/emoticon/emoticon16.gif因此希望藉由這30天的機會,以OWASP ZAP作為主要工具,從實際操作和分析,從環境架設、基本掃描到進階弱點發掘,一步步建立資安思維。
  我將學習如何利用ZAP自動化及主動/被動掃描常見的資安漏洞,並理解其背後的原理,以及該如何修復,例如SQL Injection、XSS等,讓我從「資安小白」進化成具備基本滲透測試技能的「資安入門者」。


今日內容概要:

  1. 啟用ZAP Daemon Mode
  2. 用API啟動掃描並取得結果(REST API介面)

以CLI啟動ZAP(daemon 模式)並設定API key

  1. 由於ZAP一開始是用終端機進行下載的,所以用在終端機輸入locate zap.sh,尋找zap.sh的存放位置。
  2. 啟用ZAP Daemon模式:
    輸入:/usr/share/zaproxy/zap.sh -daemon -host 127.0.0.1 -port 8080 -config api.key=changeme
    顯示:key=changeme Found Java version 21.0.8 Available memory: 1973 MB Using JVM args: -Xmx493m The home directory is already in use. Ensure no other ZAP instances are running with the same home directory: /home/kali/.ZAP/
    • 因為本身是學習用途,故直接使用ChatGPT提供的範例API Key值進行測試。
  3. 用curl啟動Spider:
    輸入:curl "http://127.0.0.1:8080/JSON/spider/action/scan/?apikey=changeme&url=http://127.0.0.1/DVWA/index.php&recurse=true"
    顯示:{"scan":"1"}
  4. 輪詢Spider狀態
    輸入:curl "http://127.0.0.1:8080/JSON/spider/view/status/?apikey=changeme&scanId=0"
    顯示:{"status":"100"}
  5. 啟動Active Scan
    輸入:curl "http://127.0.0.1:8080/JSON/ascan/action/scan/?apikey=changeme&url=http://127.0.0.1/DVWA/index.php&recurse=true&inScopeOnly=false"
    顯示:{"scan":"0"}
  6. 列出spider抓到的URL列表
    輸入:curl "http://127.0.0.1:8080/JSON/spider/view/results/?apikey=changeme&scanId=0"
    顯示:{"results":["http://127.0.0.1/DVWA/login.php","http://127.0.0.1/DVWA/index.php","http://127.0.0.1/sitemap.xml","http://127.0.0.1/DVWA/dvwa/css/login.css","http://127.0.0.1/robots.txt","http://127.0.0.1/DVWA/dvwa/images/login_logo.png"]}
  7. 開始Active Scan:
    輸入:curl "http://127.0.0.1:8080/JSON/ascan/action/scan/?apikey=changeme&url=http://127.0.0.1/DVWA/index.php"
    顯示:{"scan":"1"}
  8. 查看Active Scan狀態
    輸入:curl "http://127.0.0.1:8080/JSON/ascan/view/status/?apikey=changeme&scanId=0"
    顯示:{"status":"100"}
  9. 產生HTML漏洞報告
    輸入:curl "http://127.0.0.1:8080/OTHER/core/other/htmlreport/?apikey=changeme" > zap-report_20250929.html
    顯示:https://ithelp.ithome.com.tw/upload/images/20250929/20169022oIcM5E4oZ7.pnghttps://ithelp.ithome.com.tw/upload/images/20250929/20169022YGGDYkKVCv.png

ZAP的Python client自動化

  1. 建立venv虛擬環境
    輸入:
    sudo apt update
    sudo apt install -y python3-venv python3-pip
  2. 建一個venv並啟動
    python3 -m venv ~/zapenv
    source ~/zapenv/bin/activate
  3. 升級pip、安裝ZAP client
    pip install --upgrade pip
    pip install python-owasp-zap-v2.4
  4. 請ChatGPT生成一個腳本(自動迴圈輪詢直到100%)
  5. 建立一個檔案:nano zap_auto.py
    https://ithelp.ithome.com.tw/upload/images/20250929/20169022TSFgusMSRp.png
  • 存檔並退出(在nano裡按Ctrl+O → Enter → Ctrl+X)
  1. 執行測試腳本檔案: python zap_auto.py
    https://ithelp.ithome.com.tw/upload/images/20250929/20169022VkaIGQatFZ.png
  2. 離開虛擬環境: deactivate

漏洞報告書:

https://ithelp.ithome.com.tw/upload/images/20250929/20169022bxOVGrmC2d.png


上一篇
Day14—Fuzzer進階挑戰(測試XSS Stored漏洞)
下一篇
Day16—Java與ZAP API自動化基礎
系列文
資安小白—30天學習滲透測試with OWASP ZAP (Zed Attack Proxy)30
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言