{"id":169,"date":"2022-06-02T13:57:48","date_gmt":"2022-06-02T07:57:48","guid":{"rendered":"https:\/\/murat.one\/?p=169"},"modified":"2022-06-02T14:00:06","modified_gmt":"2022-06-02T08:00:06","slug":"multiple-vulnerabilities-in-librehealth-ehr-2-0-0-part-2","status":"publish","type":"post","link":"https:\/\/murat.one\/?p=169","title":{"rendered":"Multiple vulnerabilities in LibreHealth EHR 2.0.0\u00a0part 2"},"content":{"rendered":"\n<p class=\"justifier\">During an internship at <a rel=\"noreferrer noopener\" href=\"https:\/\/nitroteam.kz\" data-type=\"URL\" data-id=\"https:\/\/nitroteam.kz\" target=\"_blank\">NitroTeam.kz<\/a>, my students found several vulnerabilities in LibreHealth: Broken Access Control (CVE-2022-31496), Cross-Site Scripting (CVE-2022-31492, CVE-2022-31493, CVE-2022-31494, CVE-2022-31495, CVE-2022-31497, CVE-2022-31498).<\/p>\n\n\n\n<p class=\"justifier\">I think these CVE&#8217;s are good achievement in their CV. They even not finished their bachelor degree, but already contributed to the safety of internet. The names of our heroes: Alibek Akhmetov, Bakdaulet Zhaksylyk, Daniyar Absadykov, Amir Askarov, Gaukhar Uzakbay.<\/p>\n\n\n\n<p>All these vulnerabilities needs an authorization.<\/p>\n\n\n\n<p><strong>1. Broken Access Control (CVE-2022-31496)<\/strong><\/p>\n\n\n\n<p class=\"justifier\">Any user or admin can access to the functionality for super admin page and change some files, that leads to <strong>remote code execution<\/strong>.<\/p>\n\n\n\n<p>Vulnerable endpoint: librehealth_host\/interface\/super\/manage_site_files.php<\/p>\n\n\n\n<p class=\"justifier\">Example of files, that can be changed using <strong>manage_site_files.php<\/strong> functionality:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"284\" height=\"201\" src=\"https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/list.png\" alt=\"\" class=\"wp-image-170\"\/><\/figure>\n\n\n\n<p>The best choice to change is <strong>custom_pdf.php<\/strong> file, because in case of other files, the site can be broken. Then to the custom_pdf.php file malicious code can be injected:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large justifier\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"315\" src=\"https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/shell-1024x315.jpg\" alt=\"\" class=\"wp-image-171\" srcset=\"https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/shell-1024x315.jpg 1024w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/shell-300x92.jpg 300w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/shell-768x237.jpg 768w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/shell-1536x473.jpg 1536w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/shell-1568x483.jpg 1568w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/shell.jpg 1831w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>After saving the code, web shell can be accessed using URL: librehealth_host\/sites\/default\/letter_templates\/custom_pdf.php<\/p>\n\n\n\n<figure class=\"wp-block-image size-large justifier\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"309\" src=\"https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/shell-1-1024x309.jpg\" alt=\"\" class=\"wp-image-173\" srcset=\"https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/shell-1-1024x309.jpg 1024w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/shell-1-300x91.jpg 300w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/shell-1-768x232.jpg 768w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/shell-1-1536x464.jpg 1536w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/shell-1-1568x473.jpg 1568w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/shell-1.jpg 1918w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>2. Cross-Site Scripting (XSS) attack via GET-param patient (CVE-2022-31497)<\/strong><\/p>\n\n\n\n<p>Proof-of-concept:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large justifier\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"175\" src=\"https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-1024x175.jpg\" alt=\"\" class=\"wp-image-174\" srcset=\"https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-1024x175.jpg 1024w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-300x51.jpg 300w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-768x132.jpg 768w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss.jpg 1535w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>librehealth_host\/interface\/main\/finder\/finder_navigation.php?patient=1%22%3E%3Cscript%3Ealert(%27xss%27);%3C\/script%3E%3C!--<\/code><\/pre>\n\n\n\n<p><strong>3. Cross-Site Scripting (XSS) attack via POST-param username (CVE-2022-31492)<\/strong><\/p>\n\n\n\n<p>Web form for adding new users suffers from XSS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>librehealth_host\/interface\/usergroup\/usergroup_admin_add.php<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large justifier\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"555\" src=\"https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-1-1024x555.jpg\" alt=\"\" class=\"wp-image-175\" srcset=\"https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-1-1024x555.jpg 1024w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-1-300x162.jpg 300w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-1-768x416.jpg 768w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-1.jpg 1252w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Field <strong>username <\/strong>is not filtered and leads to XSS in users list page:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large justifier\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"503\" src=\"https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-2-1024x503.jpg\" alt=\"\" class=\"wp-image-176\" srcset=\"https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-2-1024x503.jpg 1024w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-2-300x147.jpg 300w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-2-768x377.jpg 768w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-2.jpg 1231w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>4. Cross-Site Scripting (XSS) via GET-param key (CVE-2022-31498)<\/strong><\/p>\n\n\n\n<p>Proof-of-concept:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>librehealth_host\/orders\/patient_match_dialog.php?key=%3C\/script%3E%3Cscript%3Ealert(document.cookie)%3C\/script%3E<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large justifier\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"423\" src=\"https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-3-1024x423.jpg\" alt=\"\" class=\"wp-image-177\" srcset=\"https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-3-1024x423.jpg 1024w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-3-300x124.jpg 300w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-3-768x317.jpg 768w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-3.jpg 1131w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>5. Cross-Site Scripting (XSS) via GET-params action, return_page, acl_id (CVE-2022-31493, CVE-2022-31494, CVE-2022-31495)<\/strong><\/p>\n\n\n\n<p>Proof-of-concept:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>librehealth_host\/gacl\/admin\/acl_admin.php?acl_id=\\%22%3E%3Cscript%3Ealert(%27XSS%27)%3C\/script%3E\nlibrehealth_host\/gacl\/admin\/acl_admin.php?return_page=\\%22%3E%3Cscript%3Ealert(%27XSS%27)%3C\/script%3E\nlibrehealth_host\/gacl\/admin\/acl_admin.php?action=\\%22%3E%3Cscript%3Ealert(%27XSS%27)%3C\/script%3E<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full justifier\"><img decoding=\"async\" loading=\"lazy\" width=\"899\" height=\"476\" src=\"https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-4.jpg\" alt=\"\" class=\"wp-image-178\" srcset=\"https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-4.jpg 899w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-4-300x159.jpg 300w, https:\/\/murat.one\/wp-content\/uploads\/2022\/06\/xss-4-768x407.jpg 768w\" sizes=\"(max-width: 899px) 100vw, 899px\" \/><\/figure>\n\n\n\n<p><strong>Remediation<\/strong><\/p>\n\n\n\n<p class=\"justifier\">There is no patch for this vulnerabilities because of migration to more stable framework. Never trust data from the client. Add htmlspecialchars() before printing values. To fix broken access control, super admin checking condition should be added. Or if there is no need to this functionality, file can be just deleted.<\/p>\n\n\n\n<p><strong>Timeline of the vulnerabilities<\/strong>:<\/p>\n\n\n\n<p>05\/13\/2022 &#8211; initial discover<br>05\/22\/2022 &#8211; requesting CVE id&#8217;s from MITRE<br>05\/24\/2022 &#8211; MITRE was assigned CVE id&#8217;s<br>05\/26\/2022 &#8211; notification to vendor<br>06\/02\/2022 &#8211; vendor confirmed and allowed to publish write-up<br>06\/02\/2022 &#8211; published<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>During an internship at NitroTeam.kz, my students found several vulnerabilities in LibreHealth: Broken Access Control (CVE-2022-31496), Cross-Site Scripting (CVE-2022-31492, CVE-2022-31493, CVE-2022-31494, CVE-2022-31495, CVE-2022-31497, CVE-2022-31498).<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[10,14],"tags":[29,18,11,17,24],"_links":{"self":[{"href":"https:\/\/murat.one\/index.php?rest_route=\/wp\/v2\/posts\/169"}],"collection":[{"href":"https:\/\/murat.one\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/murat.one\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/murat.one\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/murat.one\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=169"}],"version-history":[{"count":3,"href":"https:\/\/murat.one\/index.php?rest_route=\/wp\/v2\/posts\/169\/revisions"}],"predecessor-version":[{"id":180,"href":"https:\/\/murat.one\/index.php?rest_route=\/wp\/v2\/posts\/169\/revisions\/180"}],"wp:attachment":[{"href":"https:\/\/murat.one\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/murat.one\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/murat.one\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}