플밍_ASP
개선된 SQL 인젝션 탐지 함수
잠수콩
2024. 8. 22. 10:38
정상적인 SQL 쿼리를 감지하지 않으면서도 SQL 인젝션 공격을 탐지할 수 있도록 패턴을 더욱 구체화하겠습니다.
<% Function IsSQLInjection(userInput) Dim lowerInput, suspiciousPatterns, pattern, i ' 입력을 소문자로 변환하여 대소문자 무시 lowerInput = LCase(Trim(userInput)) ' SQL 인젝션에서 자주 사용되는 패턴을 구체적으로 정의 suspiciousPatterns = Array( _ "union select", _ "or 1=1", _ "--", _ "/*", _ "*/", _ ";", _ "drop table", _ "exec xp_", _ "cast(", _ "convert(", _ "select count(*)", _ "select * from information_schema.tables", _ "select * from mysql.user" _ ) ' 각 패턴에 대해 검사 For i = 0 To UBound(suspiciousPatterns) pattern = suspiciousPatterns(i) ' 패턴이 입력에 포함되어 있는지 검사 If InStr(lowerInput, pattern) > 0 Then IsSQLInjection = True Exit Function End If Next IsSQLInjection = False End Function ' 사용 예시 Dim userInput userInput = "SELECT * FROM users WHERE username = 'admin'" If IsSQLInjection(userInput) Then Response.Write("SQL Injection detected!") Else Response.Write("Input is safe.") End If %>
출처 : 나