Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

의미없는 블로그

[CVE-2022-22947] Spring Cloud Gateway RCE 본문

# 나/exploit CVE

[CVE-2022-22947] Spring Cloud Gateway RCE

SaltLee 2023. 2. 27. 18:18

#sudo service docker restart

 

Spring Cloud Gateway 에서 발생하는 원격코드 실행 취약점

 

spring 에서 API Gateway 만드는 라이브러리인데

Code Injection 으로 인한 RCE 포인트가 있나봄

 

취약 버전은 3.1.1 이전 버전, 3.0.7 이전 버전 (prior to 3.1.1+ and 3.0.7+)

대응 방안은 3.1.2 이상 버전, 3.0.8 이상 버전으로 업뎃하면 되겠지

 

https://github.com/spring-cloud/spring-cloud-gateway

> 이건 소스코드인데 들가보면 mvc, sample, server, webflux, gateway... 뭐 이렇게 또 나뉘네

> 취약 코드는 spring-cloud-gateway-server 쪽인거 같고..

https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-gateway

> 이건 spring cloud starter gateway 버전들인데 걍 spring cloud 버전이라고 생각해도 될듯

 

버전 확인방법은 pom.xml 에서 spring-cloud-gateway 로 확인

 

PoC : https://github.com/twseptian/cve-2022-22947

> 아니 이거 왜안됨?

> 흠.. 잘 안날라감

 

참고 : https://wya.pl/2022/02/26/cve-2022-22947-spel-casting-and-evil-beans/

> 여기 블로그 소스 분석 잘 되어있음

 

아래 java 에서 취약점 발생하고

spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/support/ShortcutConfigurable.java

 

getValue() 에 보면

StandardEvaluationContext context = new StandardEvaluationContext(); 라고 있는데

얘가 SpEL 이라고 스프링 익스프레스 랭귀지를 다루는 객체인가본데

얘가 세팅된 그대로 value = expression.getValue(context); 에서 처리되는게 문제인가보다

(취약한 java : https://github.com/spring-cloud/spring-cloud-gateway/blob/2.2.x/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/support/ShortcutConfigurable.java)

그래서 GatewayEvaluationContext 로 받아서 처리하는걸로 바뀜

(바뀐 java : https://github.com/spring-cloud/spring-cloud-gateway/blob/main/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/support/ShortcutConfigurable.java)

 

https://github.com/wdahlenburg/spring-gateway-demo

> 저 블로그는 이거 PoC 얘기하넹.. 이거로 다시 해봄

 

안날라가넹.. 왜지?

무튼 이거 날리면 test123 라우터 생성되고

그 담에 GET 으로 다시 날리면 응답값에 RCE 결과 출력되는건데

 

버전 조회할때 변수 존재..

지겨와

https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies/Hoxton.RELEASE

 

그 밖에 이런것들도 존재

https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies/Greenwich.SR2

https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies/2020.0.4

Comments