{"id":172,"date":"2021-05-03T00:41:18","date_gmt":"2021-05-03T00:41:18","guid":{"rendered":"https:\/\/cpearson.icu\/?p=172"},"modified":"2021-05-03T00:41:19","modified_gmt":"2021-05-03T00:41:19","slug":"cve-2021-3429-cloud-init-exposed-credentials-under-certain-conditions","status":"publish","type":"post","link":"https:\/\/cpearson.icu\/?p=172","title":{"rendered":"CVE-2021-3429 cloud-init exposed credentials under certain conditions"},"content":{"rendered":"\n<p><strong>Vendor:<\/strong> Canonical<br><strong>Product: <\/strong>cloud-init<br><strong>Category: <\/strong>CWE-200 Information Exposure<br><strong>Version:<\/strong> v21.1 and below<br><strong>Fixed:<\/strong> v21.1.19<br><strong>CVE:<\/strong> CVE-2021-3429<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>Cloud-init enables engineers to automate operating system configuration, primarily within different cloud environments. Cloud-init can also function as a standalone configuration tool independent of any cloud provider.<\/p>\n\n\n\n<p>Cloud-init includes an optional configuration module, chpasswd, which sets passwords for accounts on the underlying host system. Administrators can instruct cloud-init to set an administrator-defined password or to generate a random password at runtime. The module runs on the first system boot only (technically, the first boot which cloud-init is aware of) and does not run on subsequent boots.<\/p>\n\n\n\n<p>The chpassword functionality is controlled by creating or modifying a cloud-init configuration file, located by default in the <code>\/etc\/cloud\/cloud.cfg.d\/<\/code> directory. Cloud-init reads all files in this directory and applies configs in order of file read. For example, a configuration file with the following stanza would set the password &#8220;P@ssword!&#8221; for account bob:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chpasswd:\n  accounts: |\n    bob:P@ssword!<\/code><\/pre>\n\n\n\n<p>To generate a random password at runtime instead of a static password, the &#8216;R&#8217; or &#8216;RANDOM&#8217; keywords are used in place of a password value. The following sample configuration creates a random password for bob:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chpasswd:\n  accounts: |\n    bob:RANDOM<\/code><\/pre>\n\n\n\n<p>With a random password applied, we must have some way of knowing what it was or the account becomes inaccessible for legitimate use! To solve this problem, cloud-init wrote all randomly generated passwords in cleartext to stderr, which sent them to the console during boot. Administrators could find and retrieve passwords from console output.<\/p>\n\n\n\n<p>Here&#8217;s where the vulnerability popped up: cloud-init&#8217;s default logging configuration also redirected stdout and stderr to a world readable log file, <code>\/var\/log\/cloud-init-output.log<\/code> . Any unauthorized, unprivileged user could view the cleartext password for any account which had a random password generated at runtime. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"636\" height=\"55\" src=\"https:\/\/cpearson.icu\/wp-content\/uploads\/2021\/05\/file-permissions.png\" alt=\"\" class=\"wp-image-184\" srcset=\"https:\/\/cpearson.icu\/wp-content\/uploads\/2021\/05\/file-permissions.png 636w, https:\/\/cpearson.icu\/wp-content\/uploads\/2021\/05\/file-permissions-300x26.png 300w\" sizes=\"auto, (max-width: 636px) 100vw, 636px\" \/><figcaption>root is file owner, but world has read permission<\/figcaption><\/figure>\n\n\n\n<p>Grepping the log file for &#8220;password&#8221; as a non-root user and checking for lines surrounding keyword hits revealed any credentials:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"784\" height=\"288\" src=\"https:\/\/cpearson.icu\/wp-content\/uploads\/2021\/05\/output-log-file-higlighted.jpg\" alt=\"\" class=\"wp-image-187\" srcset=\"https:\/\/cpearson.icu\/wp-content\/uploads\/2021\/05\/output-log-file-higlighted.jpg 784w, https:\/\/cpearson.icu\/wp-content\/uploads\/2021\/05\/output-log-file-higlighted-300x110.jpg 300w, https:\/\/cpearson.icu\/wp-content\/uploads\/2021\/05\/output-log-file-higlighted-768x282.jpg 768w\" sizes=\"auto, (max-width: 784px) 100vw, 784px\" \/><\/figure>\n\n\n\n<p>With credentials in hand, a malicious user could then move laterally on the local system. Only randomly generated passwords were leaked. Statically assigned passwords were not.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Patch<\/h2>\n\n\n\n<p>The change password configuration was updated to write randomly generated passwords to <code>\/dev\/console<\/code> instead of stderr. The change preserves printing passwords to console for administrator access, but without also writing the passwords to disk.<\/p>\n\n\n\n<p>In addition, access to cloud-init-output.log is now restricted. Unprivileged users now cannot read the file. File permissions are changed on cloud-init upgrade; when you update cloud-init, the <code>\/var\/log\/cloud-init-output.log<\/code> file permissions are modified.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Misc<\/h2>\n\n\n\n<p>Previously exposed passwords are partially protected with the permission change to the cloud-init-output.log file. However, if the file is copied anywhere, such as inside a system backup, anyone with access to the backup could potentially read the passwords. <\/p>\n\n\n\n<p>If your cloud-init chpasswd config sets random passwords and also does not force password change on next login (by setting the &#8216;expire: false&#8221; option), then you really need to review your log file and accounts. In other words, if your chpasswd config looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chpasswd:\n  expire: false\n  accounts: |\n    alice:RANDOM\n    bob:RANDOM<\/code><\/pre>\n\n\n\n<p>\u2026then I highly recommend rotating each credential, or at least check if any leaked credentials grant access.<\/p>\n\n\n\n<p>Finally, cloud-init is installed by default on some operating systems, including Ubuntu Server. While the vulnerable install base is therefore quite large, if  chpassword functionality isn&#8217;t used, then the risk is effectively eliminated. You can&#8217;t leak passwords you&#8217;re not creating&#8230;<\/p>\n\n\n\n<p>Kudos and thank you to the cloud-init team for promptly addressing the vulnerability and issuing a patch!<\/p>\n\n\n\n<p>Thanks for reading! John 3:16<\/p>\n\n\n\n<p>Reference:<br><a href=\"https:\/\/ubuntu.com\/security\/CVE-2021-3429\">https:\/\/ubuntu.com\/security\/CVE-2021-3429<\/a><br><a href=\"https:\/\/bugs.launchpad.net\/cloud-init\/+bug\/1918303\">https:\/\/bugs.launchpad.net\/cloud-init\/+bug\/1918303<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Vendor: CanonicalProduct: cloud-initCategory: CWE-200 Information ExposureVersion: v21.1 and belowFixed: v21.1.19CVE: CVE-2021-3429 Summary Cloud-init enables engineers to automate operating system configuration, primarily within different cloud environments. Cloud-init can also function as a standalone configuration tool independent of any cloud provider. Cloud-init includes an optional configuration module, chpasswd, which sets passwords for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,6],"tags":[],"class_list":["post-172","post","type-post","status-publish","format-standard","hentry","category-advisory","category-write-up"],"_links":{"self":[{"href":"https:\/\/cpearson.icu\/index.php?rest_route=\/wp\/v2\/posts\/172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cpearson.icu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cpearson.icu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cpearson.icu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cpearson.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=172"}],"version-history":[{"count":30,"href":"https:\/\/cpearson.icu\/index.php?rest_route=\/wp\/v2\/posts\/172\/revisions"}],"predecessor-version":[{"id":207,"href":"https:\/\/cpearson.icu\/index.php?rest_route=\/wp\/v2\/posts\/172\/revisions\/207"}],"wp:attachment":[{"href":"https:\/\/cpearson.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cpearson.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cpearson.icu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}