{"id":32386,"date":"2023-01-29T10:28:41","date_gmt":"2023-01-29T04:58:41","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/"},"modified":"2023-01-29T10:28:41","modified_gmt":"2023-01-29T04:58:41","slug":"solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/","title":{"rendered":"[Solved] what is The poisoned NUL byte, in 1998 and 2014 editions?"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-31285219\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"31285219\" data-parentid=\"31277019\" data-score=\"3\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>To even begin to understand how this attack works, you will need at least a basic understanding of how a CPU works, how memory works, what the &#8220;heap&#8221; and &#8220;stack&#8221; of a process are, what pointers are, what libc is, what linked lists are, how function calls are implemented at the machine level (including calls to function pointers), what the <code>malloc<\/code> and <code>free<\/code> functions from the C library do, and so on. Hopefully you at least have some basic knowledge of C programming? (If not, you will probably not be able to complete this assignment in time.)<\/p>\n<p>If you have a couple &#8220;gaps&#8221; in your knowledge of the basic topics mentioned above, hit the books and fill them in as quickly as you can. Talk to others if you need to, to make sure you understand them. Then read the following very carefully. This will not explain everything in the article you linked to, but will give you a good start. OK, ready? Let&#8217;s start&#8230;<\/p>\n<p>C strings are &#8220;null-terminated&#8221;. That means the end of a string is marked by a zero byte. So for example, the string <code>\"abc\"<\/code> is represented in memory as (hex): <code>0x61 0x62 0x63 0x00<\/code>. Notice, that 3-character string actually takes <strong>4<\/strong> bytes, due to the terminating null.<\/p>\n<p>Now if you do something like this:<\/p>\n<pre><code>char *buffer = malloc(3); \/\/ not checking for error, this is just an example\nstrcpy(buffer, \"abc\");\n<\/code><\/pre>\n<p>&#8230;then that terminating null (zero byte) will go <em>past the end of the buffer<\/em> and overwrite something. We allocated a 3-byte buffer, but copied <strong>4<\/strong> bytes into it. So whatever was stored in the byte right after the end of the buffer will be replaced by a zero byte.<\/p>\n<p>That was what happened in <code>__gconv_translit_find<\/code>. They had a buffer, which had been allocated with enough space to append <code>\".so\"<\/code>, including the terminating null byte, onto the end of a string. But they copied <code>\".so\"<\/code> in <em>starting from the wrong position<\/em>. They started the copy operation one byte too far to the &#8220;right&#8221;, so the terminating null byte went past the end of the buffer and overwrote something.<\/p>\n<p>Now, when you call <code>malloc<\/code> to get back a dynamically allocated buffer, most implementations of <code>malloc<\/code> actually store some housekeeping data right <em>before<\/em> the buffer. For example, they might store the size of the buffer. Later, when you pass that buffer to <code>free<\/code> to release the memory, so it can be reused for something else, it will find that &#8220;hidden&#8221; data right before the beginning of the buffer, and will know how many bytes of memory you are actually <code>free<\/code>ing. <code>malloc<\/code> may also &#8220;hide&#8221; other housekeeping data in the same location. (In the 2014 article you referred to, the implementation of <code>malloc<\/code> used also stored some &#8220;flag&#8221; bits there.)<\/p>\n<p>The attack described in the article passed carefully crafted arguments to a command-line program, designed to trigger the buffer overflow error in <code>__gconv_translit_find<\/code>, in such a way that the terminating null byte would wipe out the &#8220;flag&#8221; bits stored by <code>malloc<\/code> &#8212; not the flag bits for <em>the buffer which overflowed<\/em>, but those for <em>another<\/em> buffer which was allocated <em>right after<\/em> the one which overflowed. (Since <code>malloc<\/code> stores that extra housekeeping data <em>before<\/em> the beginning of an allocated buffer, and we are overrunning the <em>previous<\/em> buffer. You follow?)<\/p>\n<p>The article shows a diagram, where <code>0x00000201<\/code> is stored right after the buffer which overflows. The overflowing null byte wipes out the bottom <code>1<\/code> and changes that into <code>0x00000200<\/code>. That might not make sense at first, until you remember that x86 CPUs are little-endian &#8212; if you don&#8217;t understand what &#8220;little-endian&#8221; and &#8220;big-endian&#8221; CPUs are, look it up.<\/p>\n<p>Later, the buffer whose flag bit was wiped out is passed to <code>free<\/code>. As it turns out, wiping out that one flag bit &#8220;confuses&#8221; <code>free<\/code> and makes it, in turn, also overwrite some other memory. (You will have to understand the implementation of <code>malloc<\/code> and <code>free<\/code> which are used by GNU libc, in order to understand why this is so.)<\/p>\n<p>By carefully choosing the input arguments to the original program, you can set things up so that the memory overwritten by the &#8220;confused&#8221; <code>free<\/code> is that used for something called <code>tls_dtor_list<\/code>. This is a linked list maintained by GNU libc, which holds pointers to certain functions which it must call when the main program is exiting.<\/p>\n<p>So <code>tls_dtor_list<\/code> is overwritten. The attacker has set things up just right, so that the function pointers in the overwritten <code>tls_dtor_list<\/code> will point to some code which they want to run. When the main program is exiting, some code in libc iterates over that list and calls each of the function pointers. Result: the attacker&#8217;s code is executed!<\/p>\n<p>Now, in this case, the attacker already has access to the target system. If all they can do is run some code with the privilege level of their own account, that doesn&#8217;t get them anywhere. They want to run code with <strong>root<\/strong> (administrator) privileges. How is that possible? It is possible because the buggy program is a <strong>setuid<\/strong> program, owned by root. If you don&#8217;t know what &#8220;setuid&#8221; programs in Unix are, look it up and make sure you understand it, because that is also a key to the whole exploit.<\/p>\n<p>This is all about the 2014 article &#8212; I didn&#8217;t look at the one from 1998. Good luck!<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">1<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved what is The poisoned NUL byte, in 1998 and 2014 editions? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] To even begin to understand how this attack works, you will need at least a basic understanding of how a CPU works, how memory works, what the &#8220;heap&#8221; and &#8220;stack&#8221; of a process are, what pointers are, what libc is, what linked lists are, how function calls are implemented at the machine level (including &#8230; <a title=\"[Solved] what is The poisoned NUL byte, in 1998 and 2014 editions?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/\" aria-label=\"More on [Solved] what is The poisoned NUL byte, in 1998 and 2014 editions?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[1384,3665,424,1551,1543],"class_list":["post-32386","post","type-post","status-publish","format-standard","hentry","category-solved","tag-cpu","tag-elevated-privileges","tag-linux","tag-linux-kernel","tag-process"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] what is The poisoned NUL byte, in 1998 and 2014 editions? - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] what is The poisoned NUL byte, in 1998 and 2014 editions? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] To even begin to understand how this attack works, you will need at least a basic understanding of how a CPU works, how memory works, what the &#8220;heap&#8221; and &#8220;stack&#8221; of a process are, what pointers are, what libc is, what linked lists are, how function calls are implemented at the machine level (including ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-29T04:58:41+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] what is The poisoned NUL byte, in 1998 and 2014 editions?\",\"datePublished\":\"2023-01-29T04:58:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/\"},\"wordCount\":867,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"cpu\",\"elevated-privileges\",\"linux\",\"linux-kernel\",\"process\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/\",\"name\":\"[Solved] what is The poisoned NUL byte, in 1998 and 2014 editions? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2023-01-29T04:58:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] what is The poisoned NUL byte, in 1998 and 2014 editions?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] what is The poisoned NUL byte, in 1998 and 2014 editions? - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] what is The poisoned NUL byte, in 1998 and 2014 editions? - JassWeb","og_description":"[ad_1] To even begin to understand how this attack works, you will need at least a basic understanding of how a CPU works, how memory works, what the &#8220;heap&#8221; and &#8220;stack&#8221; of a process are, what pointers are, what libc is, what linked lists are, how function calls are implemented at the machine level (including ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/","og_site_name":"JassWeb","article_published_time":"2023-01-29T04:58:41+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] what is The poisoned NUL byte, in 1998 and 2014 editions?","datePublished":"2023-01-29T04:58:41+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/"},"wordCount":867,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["cpu","elevated-privileges","linux","linux-kernel","process"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/","url":"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/","name":"[Solved] what is The poisoned NUL byte, in 1998 and 2014 editions? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2023-01-29T04:58:41+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-what-is-the-poisoned-nul-byte-in-1998-and-2014-editions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] what is The poisoned NUL byte, in 1998 and 2014 editions?"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/32386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=32386"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/32386\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=32386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=32386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=32386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}