{"id":16661,"date":"2021-07-08T11:48:27","date_gmt":"2021-07-08T09:48:27","guid":{"rendered":"https:\/\/herolab-usd.formwandler.rocks\/security-advisories\/usd-2020-0003\/"},"modified":"2021-07-19T14:14:27","modified_gmt":"2021-07-19T12:14:27","slug":"usd-2020-0003","status":"publish","type":"page","link":"https:\/\/herolab.usd.de\/en\/security-advisories\/usd-2020-0003\/","title":{"rendered":"usd-2020-0003"},"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-0003 | Nagios NRPE v.3.2.1<\/span><\/h1>\n<p><span><\/span><br \/><strong>Advisory ID<\/strong><span>: usd-2020-0003<\/span><br \/><strong>Affected Product<\/strong><span>: Nagios NRPE<\/span><br \/><strong>Affected Version<\/strong><span>: v.3.2.1<\/span><br \/><strong>Vulnerability Type<\/strong><span>: Wrong Packet Size Computation<\/span><br \/><strong>Security Risk<\/strong><span>: Low<\/span><br \/><strong>Vendor URL<\/strong><span>: <a href=\"https:\/\/www.nagios.org\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.nagios.org\/<\/a><\/span><br \/><strong>Vendor Status<\/strong><span>: Fixed in v4.0.0 (not verified)<\/span><\/p>\n<h3><\/h3>\n<h3>Proof of Concept (PoC)<\/h3>\n<div class=\"x-text\">\n<p>NRPE currently allows two different packet versions that can be used to communicate with the NRPE server: v2 and v3. The v3 packet structure is defined like this:<\/p>\n<\/div>\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\"]  typedef struct _v3_packet {<br \/>\nint16_t                              packet_version;<br \/>\nint16_t                              packet_type;<br \/>\nu_int32_t                            crc32_value;<br \/>\nint16_t                              result_code;<br \/>\nint16_t                              alignment;<br \/>\nint32_t                              buffer_length;<br \/>\nchar                                 buffer[1];<br \/>\n} v3_packet;<\/code><\/pre>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"cc5ac6f4-ebbd-4b3f-bc92-4dfc1f15fe2c\"]<\/p>\n<p><span>The member <\/span><strong>buffer<\/strong><span>\u00a0is only a placeholder that gets replaced by the actual packet contents during processing. Therefore, only a length of<\/span><br \/><span>1 byte is assigned to it, since it has not to carry any meaningful data. The NRPE source code calculates the length of a v3 packet like this:<\/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\"]  int32_t   pkt_size = sizeof(v3_packet) - 1 + buffer_length;<\/code><\/pre>\n<p>[\/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>As one can see, the previously used length of the placeholder <\/span><strong>buffer<\/strong><span>\u00a0is substracted from the size of the structure, since it will be replaced<\/span><br \/><span>by the real payload. However, the code does not respect the padding length that is applied by the compiler. Structures that do not end on a boundary<\/span><br \/><span>of 4 bytes are usually padded to match that requirement. Therefore, the size of the <\/span><strong>buffer<\/strong><span>\u00a0member will actually be 4, not 1. One can easily confirm this<\/span><br \/><span>by using the following C code:<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"9e260d37-0be2-4a12-a10e-3ed7e27b6ac6\" custom_margin=\"||27px||false|false\" hover_enabled=\"0\" sticky_enabled=\"0\"]  #include<br \/>\n#include<\/p>\n<p>typedef struct _v3_packet {<br \/>\nint16_t     packet_version;<br \/>\nint16_t     packet_type;<br \/>\nu_int32_t   crc32_value;<br \/>\nint16_t     result_code;<br \/>\nint16_t     alignment;<br \/>\nint32_t     buffer_length;<br \/>\nchar        buffer[1];<br \/>\n} v3_packet;<\/p>\n<p>int main() {<br \/>\nv3_packet test;<br \/>\nprintf(\"%d\\n\", sizeof(test));<br \/>\n}<\/code><\/pre>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"cc5ac6f4-ebbd-4b3f-bc92-4dfc1f15fe2c\" custom_margin=\"||27px||false|false\"]The output will be 20, since the structure contains the following lengths:[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"9e260d37-0be2-4a12-a10e-3ed7e27b6ac6\" custom_margin=\"||27px||false|false\" hover_enabled=\"0\" sticky_enabled=\"0\"]typedef struct _v3_packet {<br \/>\nint16_t     packet_version;         \/\/ 2<br \/>\nint16_t     packet_type;            \/\/ 2<br \/>\nu_int32_t   crc32_value;            \/\/ 4<br \/>\nint16_t     result_code;            \/\/ 2<br \/>\nint16_t     alignment;              \/\/ 2<br \/>\nint32_t     buffer_length;          \/\/ 4<br \/>\nchar        buffer[1];              \/\/ 4<br \/>\n} v3_packet;   <\/code><\/pre>\n<p>[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"default\" custom_margin=\"||27px||false|false\"]One can also observe this wrong calculation of the packet size when communicating with the NRPE server. Messages transmitted over the network often contain three additional null bytes, since the buffer size is three bytes longer than the actual packet. Hexdump of a NRPE server response:[\/et_pb_text][et_pb_text _builder_version=\"4.9.4\" _module_preset=\"9e260d37-0be2-4a12-a10e-3ed7e27b6ac6\" custom_margin=\"||27px||false|false\" hover_enabled=\"0\" sticky_enabled=\"0\"]    00000000  00 03 00 02 34 22 6d cc  00 00 00 00 00 00 00 10   ....4\"m. ........<br \/>\n00000010  5b 2b 5d 20 50 4f 43 20  66 69 6e 69 73 68 65 64   [+] POC  finished<br \/>\n00000020  00 00 00     <\/code><\/pre>\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<p><span>Our short research did not identify a vulnerability resulting from this incorrect length calculation. However, such bugs often<\/span><br \/><span>lead to security relevant issues and should be fixed.<\/span><\/p>\n<h3><\/h3>\n<h3>Fix<\/h3>\n<p><span>Respect structure padding during packet length calculations.<\/span><\/p>\n<h3><\/h3>\n<h3>Timeline<\/h3>\n<ul>\n<li>2020-01-06 Tobias Neitzel found this vulnerability by manual code review of Nagios NRPE<\/li>\n<li>2020-01-08 Initial Contact<\/li>\n<li>2020-01-15 Nagios NRPE v4.0.0 is released: <a href=\"https:\/\/github.com\/NagiosEnterprises\/nrpe\/releases\/tag\/nrpe-4.0.0\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/NagiosEnterprises\/nrpe\/releases\/tag\/nrpe-4.0.0<\/a><\/li>\n<li>2020-03-04 security advisory released<\/li>\n<\/ul>\n<h3><\/h3>\n<h3>Credits<\/h3>\n<p><span>This security vulnerability was discovered 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-0003 | Nagios NRPE v.3.2.1 Advisory ID: usd-2020-0003Affected Product: Nagios NRPEAffected Version: v.3.2.1Vulnerability Type: Wrong Packet Size ComputationSecurity Risk: LowVendor URL: https:\/\/www.nagios.org\/Vendor Status: Fixed in v4.0.0 (not verified) Proof of Concept (PoC) NRPE currently allows two different packet versions that can be used to communicate with the NRPE server: v2 and v3. The v3 packet [&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-16661","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages\/16661","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=16661"}],"version-history":[{"count":0,"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages\/16661\/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=16661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}