개발

[asp] sql 인젝션

지승준 2015. 3. 11. 09:15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<%
Function set_sql_injection(query_string)
 
' SQL injection 공격 단어가 들어오면 막아준다.
if InStr(query_string,"--, #"> 0 Then
inj_flag  = True
elseif InStr(query_string,"/* */"> 0 Then
inj_flag  = True
elseif InStr(query_string,"' or 1=1--"> 0 Then
inj_flag  = True
elseif InStr(query_string,"union"> 0 Then
inj_flag  = True
elseif InStr(query_string,"script"> 0 Then
inj_flag  = True
elseif InStr(query_string,"select"> 0 Then
inj_flag  = True
elseif InStr(query_string,"delete"> 0 Then
inj_flag  = True
elseif InStr(query_string,"update"> 0 Then
inj_flag  = True
elseif InStr(query_string,"drop"> 0 Then
inj_flag  = True
elseif InStr(query_string,"on error resume"> 0 Then
inj_flag  = True
elseif InStr(query_string,"execute"> 0 Then
inj_flag  = True
elseif InStr(query_string,"windows"> 0 Then
inj_flag  = True
elseif InStr(query_string,"-1 or"> 0 Then
inj_flag  = True
elseif InStr(query_string,"-1' or"> 0 Then
inj_flag  = True
elseif InStr(query_string,"../"> 0 Then
inj_flag  = True
elseif InStr(query_string,"unexisting"> 0 Then
inj_flag  = True
elseif InStr(query_string,"win.ini"> 0 Then
inj_flag  = True
else 
inj_flag  = false
end if 
 
if inj_flag = True then
%>        
    <script>
alert("등록할수 없는 단어가 발견되었습니다. 관리자에게 문의를 바랍니다.");
history.go(-1);
</script>    
<%
response.End
 
else
 
' SQL injection 관련 특수문자가 접근하면 변환하여 준다.
query_string = replace(query_string, "(""&#40;" )
query_string = replace(query_string, ")""&#41;" )
query_string = replace(query_string, "'""&#39;" )
query_string = replace(query_string, "\", "&#34;" )
query_string = replace(query_string, "/""&#47;" )
query_string = replace(query_string, "<""&lt;" )
query_string = replace(query_string, ">""&gt;" )    
query_string = replace(query_string, "'""''" )
 
end if 
 
set_sql_injection = query_string
 
End function
 
Function get_sql_injection(query_string)
 
' SQL injection 관련 특수문자를 사용자가 사용 할 수 있는 특수문자로 변환하여 준다.
query_string = replace(query_string, "&#40;""(" )
query_string = replace(query_string, "&#41;"")" )
query_string = replace(query_string, "&#39;""'" )
query_string = replace(query_string, "&#34;""\" )
query_string = replace(query_string, "&#47;", "/" )
query_string = replace(query_string, "&lt;""<" )
query_string = replace(query_string, "&gt;"">" )
 
get_sql_injection = query_string
 
End function
%>
cs