iT邦幫忙

2025 iThome 鐵人賽

DAY 17
0
Security

資安小白—30天學習滲透測試with OWASP ZAP (Zed Attack Proxy)系列 第 17

Day17—自動化登入流程(Form-Based Auth)

  • 分享至 

  • xImage
  •  

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


今日內容概要:

  1. 什麼是Form-Based Authentication?
  2. 建立Context
  3. 設定Authentication方法
  4. 設定Logged In/Logged Out Indicator
  5. 建立使用者帳號
  6. 設定 Session Management
  7. 使用ZAP API自動化登入(Java)

什麼是Form-Based Authentication?

我們(使用者)透過網頁上的登入表單(<form action="/login.php" method="POST">)傳送帳號密碼,而當網站驗證成功後,通常會回傳一個登入成功頁面、設定Session Cookie,或導向(302 redirect)到登入後的主頁。

ZAP可以模擬這個流程,在掃描時自動帶入帳號密碼進行登入,避免掃描結果被「未登入狀態」限制。

建立Context

先在ZAP主頁面左側的Sites樹狀結構中,右鍵點擊DVWA網站,選擇
Include in Context -> Default Context。
https://ithelp.ithome.com.tw/upload/images/20251008/20169022PROgEG3PZw.png

  • Context用來儲存一組設定,包含登入、登出、使用者、Session管理等。

設定Authentication方法 & 設定Logged In/Logged Out Indicator

先用瀏覽器實際走訪一次登入流程(我用http://[localhost]/DVWA/login.php),在ZAP History中找到那個POST的 login request ,滑鼠右鍵該request,選擇Flag as Context -> Form-based Auth Login Request,就會打開Authentication的設定視窗,如下圖。
https://ithelp.ithome.com.tw/upload/images/20251008/20169022aeCjbMBjUs.png
因為我的ZAP沒有自動帶入目標url與參數,所以有問了ChatGPT,收到的回覆是我需要手動設定數值,以下是欄位及設定數值:

  • Authentication視窗
    Login URL:http://127.0.0.1/DVWA/login.php
    Login Request Data:username={%username%}&password={%password%}&Login=Login

(設定Logged-in indicator,例如頁面出現Logout或Welcome的字串)
Regex pattern used to identify Logged In message: Welcome
Regex pattern used to identify Logged Out message: Logout

建立使用者帳號

  • Users視窗(左側切換到「Users」),如下圖。
    Name: adminUser
    Username: admin
    Password: password
    https://ithelp.ithome.com.tw/upload/images/20251008/20169022W0AB3Sq4U7.png

最後按下OK~

設定 Session Management

在左側切換到「Session Management Method」,並選擇
Cookie-based session management。

這樣ZAP就會自動儲存並重用登入 Cookie。

使用ZAP API自動化登入DVWA(Java)

在測試ChatGPT提供的範例腳本時,一直出現Error,尤其是時常編譯成功了,卻無法執行,嘗試很多次都是差不多的結果,之後有空再回來解決....../images/emoticon/emoticon46.gif


上一篇
Day16—Java與ZAP API自動化基礎
下一篇
Day18—自動化登入(JWT / Token-Based Auth)
系列文
資安小白—30天學習滲透測試with OWASP ZAP (Zed Attack Proxy)30
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言