반응형
SMALL

1. 디렉터리 리스팅 취약점 (디렉터리)

 

/bWAPP/directory_traversal_2.php. irectory=passwords 
192.168.171.187 
an ex+remely buqqy web app . 
Bugs Chanqe Password Crea+e user 
Sef Securi+y Level Rese+ Credi+s 
/ Direc+ory Traversal - Direc+ories / 
heroes.xml 
wp-config.bak 
web.config.bak 
accounts.txt

[그림 1-1] 디렉터리 리스팅

Directory_traversal_2.php 페이지는 HTTP 연결 요청에 GET 메소드를 사용하기 때문에 URL 변수를 노출한다. directory 변수에 입력된 documents 대신 passwords 입력한 실행하면 passwords 디렉터리 안에 내용을 출력한다. account.txt 계정 정보가 있다고 추측할 있다.

 

C O | 192.168.171.187 
/bWAPP/directory_traversal_2.php. 
timezone 
defoma 
gre.d 
debconf.conf 
ConsoleKit 
rc6.d 
rc.local 
adjtime 
python2.5 
belocs 
cron.d 
devfs 
mysql 
passwd 
aliases 
protocols 
irectory 
=../../../etc

[그림 1-2] etc 파일 목록

directory 변수에 ../ 사용해 서버에 있는 디렉터리 정보를 확인한다. etc 디렉터리에 있는 passwd 파일에 계정 비밀번호가 있다고 추측해볼 있다.

 

C O | 192.168.171.187 
/bWAPP/directory_traversal_2.php?directory=../../../etc/passwd 
bW App 
an ex+remely buqqy web app . 
Bugs Chanqe Password Crea+e user 
Sef Securi+y Level Rese+ 
/ Direc+ory Traversal - Direc+ories 
Warning: opendir(../../../etc/passwd) 
[function.opendir]: 
failed to open dir: Not 
/var/www/bWAPP/directory_traversaI_2.php on line 143 
readdir0: 
Warning: 
supplied 
/var/www/bWAPP/directory_traversaI_2.php on line 145 
is 
argument 
not 
a 
valid 
Directory 
Credi+s 
a directory 
resource 
in 
in

[그림 1-3] passwd 파일 접근 실패

../../../../etc/passwd를 입력한 실행하면 접근에 실패한다. 이는 passwd 파일이어서 directory 변수에 passwd 파일의 접근이 제한되기 때문이다.

 

2. 대응 방안

 

case "2" 
$directory traversal error 
= directory traversal check 3($directory, 
/documents" ) ; 
!$directory traversal error) 
show directory($directory); 
else 
echo $directory traversal error; 
break; 
default 
show directory($directory); 
break; 
$base path

 

[그림 2-1] 소스코드 - 1

난이도 high에선 directory 변수에 상대경로를 입력하거나 존재하는 디렉터리를 입력해도 다른 디렉터리로 이동되지 않는다. 소스코드를 보면 기본 경로는 변수를 사용해서 documents 디렉터리로 한정하고 있어 다른 디렉토리로 이동이 불가능하다.

 

function directory traversal check 3($user path,$base path 
$directory traversal error = 
$real base path 
= realpath($base path); 
// echo "base path: 
$base path . 
$real user path 
= realpath($user path); 
// echo "user path: 
$user path . 
real 
real 
base 
user 
path: 
path: 
. $real 
. $real 
base 
user 
path 
path 
. "<br 
. "<br 
// int strpos ( string $haystack , mixed $needle 
[ , int $offset 
// URL: http://php.net/manual/en/function.strpos.php 
if(strpos($real user path, $real base path) 
false) 
$directory traversal error 
= "<font error occurred, 
please try again.</font>";

 

[그림 2-2] 소스코드 - 2

Directory_traversal_check_3 함수에서 사용자가 입력한 경로가 관리자가 지정한 경로와 다를 경우엔 오류 메시지를 출력한다.

 

3. 디렉터리 리스팅 취약점 (파일)

 

/bWAPP/directory_traversal_1.php page=../../../../etc/passwd 
192.168.171.187 
/ Direc+ory Traversal - Files / 
root:x:0:0:root:/root:/bin/bash 
daemon:x:l :1 :daemon:/usr/sbin:/bin/sh 
bin:x:2:2:bin:/bin:/bin/sh 
sys:x:3:3:sys:/dev:/bin/sh 
sync:x:4:65534:sync:/bin:/bin/sync 
games:x:5:60:games:/usr/games:/bin/sh 
man:x:6:12:man:/var/cache/man:/bin/sh 
Ip:x:7:7:lp:/var/spool/lpd:/bin/sh 
mail:x:8:8:mail:/var/mail:/bin/sh 
news:x:9:9:news:/var/spool/news:/bin/sh 
uucp:x: 1 0: 10:uucp:/var/spool/uucp:/bin/sh 
proxy:x: 1 3:13: proxy:/bin:/bin/sh 
www-data:x:33:33:www-data:/var/www:/bin/sh 
backup:x:34:34:backup:/var/backups:/bin/sh 
list:x:38:38:Mailing List Manager:/var/list:/bin/sh 
irc:x:39:39:ircd:/var/run/ircd:/bin/sh 
gnats:x:41 :41 :Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh 
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh 
Iibuuid:x: 1 00:101 ::/var/lib/libuuid:/bin/sh 
dhcp:x:101 : 102::/nonexistent:/bin/false 
syslog:x: 1 02:103: :/home/syslog:/bin/false

[그림 3-1] password 파일 접근

Page 변수에 상위 경로로 가는 상대경로를 입력해서 directory 변수로 접근하지 못한 passwd 내용을 확인한다. 내용을 확인해보면 passwd 비박스 서버에 접근 가능한 아이디, 접근 권한을 기록한 파일이다.

 

c 
Bugs 
/bWAPP/directory_traversal_1.php. page-passwords/heroes.xml 
192.168.171.187 
Change Password Crea+e user 
Set Securi+y Level Rese+ 
/ Direc+ory Traversal - Files / 
1 
neo 
trinity 
Oh why didn't I took that BLACK pill? 
The Matrix 
action sci-fi 
2 
alice 
loveZombies 
There's a cure! 
Resident Evil 
action horror sci-fi

[그림 3-2] heroes.xml 파일 접근

Page 변수에 passwords 디렉터리 안에 있는 heroes.xml 파일을 URL 넣고 실행하면 파일의 내용을 출력한다.

 

4. 대응 방안

 

case "2" 
$directory traversal error = directory traversal check 3($file); 
!$directory traversal error) 
show file($file); 
else 
echo $directory traversal error; 
// Debugging 
// echo "<br . 
break; 
default 
show file($file); 
// Debugging 
// echo "<br . 
break; 
$ GET ["page"];

[그림 4-1] 소스 코드 - 1

소스 코드를 확인하면 directory_traversal_check 3 함수를 사용해 변수에 입력한 데이터가 올바른 데이터인지 검사한다.

 

function directory traversal check 3($user path,$base path 
$directory traversal error = 
$real base path 
= realpath($base path); 
// echo "base path: 
$base path . 
$real user path 
= realpath($user path); 
// echo "user path: 
$user path . 
real 
real 
base 
user 
path: 
path: 
. $real 
. $real 
base 
user 
path 
path 
. "<br 
. "<br 
// int strpos ( string $haystack , mixed $needle 
[ , int $offset 
// URL: http://php.net/manual/en/function.strpos.php 
if(strpos($real user path, $real base path) 
false) 
$directory traversal error 
= "<font error occurred, 
please try again.</font>"; 
else 
echo 
"Good path!" 
return $directory traversal error;

[그림 4-2] 소스 코드 - 2

directory_traversal_check 3 함수는 realpath 함수를 호출해 상대 경로를 절대경로로 바꾼 strpos 함수로 기본 경로에 사용자가 입력한 경로가 포함되는지 검증한다. 포함되지 않는 경로면 오류 메시지를 출력한다.


반응형
LIST
블로그 이미지

만년필석사

,