<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Posts on Adin&#39;s Site</title>
        <link>https://adinjura.com/posts/</link>
        <description>Recent content in Posts on Adin&#39;s Site</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en</language>
        <copyright>&lt;a href=&#34;https://creativecommons.org/licenses/by-nc/4.0/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CC BY-NC 4.0&lt;/a&gt;</copyright>
        <lastBuildDate>Wed, 23 Oct 2024 00:00:00 +0000</lastBuildDate>
        <atom:link href="https://adinjura.com/posts/index.xml" rel="self" type="application/rss+xml" />
        
        <item>
            <title>Pwn Adventure  3 Noclip Hack</title>
            <link>https://adinjura.com/posts/2024/10/pwn-adventure-3-noclip-hack/</link>
            <pubDate>Wed, 23 Oct 2024 00:00:00 +0000</pubDate>
            
            <guid>https://adinjura.com/posts/2024/10/pwn-adventure-3-noclip-hack/</guid>
            <description>&lt;h2 id=&#34;overview&#34;&gt;Overview&lt;/h2&gt;
&lt;p&gt;In this post, I will be going over the basics of writing game cheats. We will be messing with the game &lt;a href=&#34;https://www.pwnadventure.com/&#34;&gt;Pwn Adventure 3&lt;/a&gt;. This game was made to be a part of a CTF, so this game was made to be hacked. This makes it the perfect target to start learning this stuff!&lt;/p&gt;
&lt;p&gt;The project that is referenced in this post is on my GitHub &lt;a href=&#34;https://github.com/TapPineapple/pwn-adventure-fun&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We will go over the following:&lt;/p&gt;</description>
            <content type="html"><![CDATA[<h2 id="overview">Overview</h2>
<p>In this post, I will be going over the basics of writing game cheats. We will be messing with the game <a href="https://www.pwnadventure.com/">Pwn Adventure 3</a>. This game was made to be a part of a CTF, so this game was made to be hacked. This makes it the perfect target to start learning this stuff!</p>
<p>The project that is referenced in this post is on my GitHub <a href="https://github.com/TapPineapple/pwn-adventure-fun">here</a>.</p>
<p>We will go over the following:</p>
<ul>
<li>Hooking</li>
<li>Noclip Math</li>
<li>Throwing this all together in Code</li>
</ul>
<p>Let&rsquo;s jump into it!</p>
<h2 id="whats-our-goal">What&rsquo;s our goal?</h2>
<p>Our goal in this project will be to create a functioning noclip hack for the game Pwn Adventure 3. We will do this by taking the player&rsquo;s position cordinates and overwriting them with new values based on the logic in our noclip code.</p>
<p>The game&rsquo;s physics engine will also be fighting our noclip hack, this means that we need to also overwrite the player&rsquo;s movement velocity variables. If we don&rsquo;t do this our character will teleport around when the noclip hack is in effect.</p>
<p>This will hopefully all make more sense when we get to actually coding up the program.</p>
<h2 id="finding-the-players-position--velocity-variables">Finding the players position &amp; velocity variables</h2>
<p>There are likely many different ways to to find these values but I will be going over the method that I used.</p>
<p>I used floating point scans in cheat engine to find the value for the players position on the vertical axis. Once I found that, it was right after the X,Y values for the player&rsquo;s position in memory. Next I opened up the memory view and looked around for values that could resemble the players velocity address.</p>
<p>Once I found these two memory locations, I attached the cheat engine debugger and clicked &ldquo;find out what accesses this address&rdquo;. My goal in doing this is to find a good function to use that references these variables in the registers. This is useful to know because we need to be able to find these addresses somehow in our cheat. We will be able to copy the address out of the registers in the game&rsquo;s code into a variable in our noclip code.</p>
<p>Hopefully this will make more sense when we look at it in the actual source code.</p>
<h2 id="digging-into-the-source-code">Digging into the source code</h2>
<p>Now that we kind know what&rsquo;s going on behind the scenes, lets get into the actual source code.</p>
<p>This is an internal cheat which means we are writing this in the context of a windows dynamic link library (dll). Since we are writing a DLL we will need to inject this into the games process using some sort of external dll injector. <a href="https://github.com/master131/ExtremeInjector">Master131&rsquo;s injector</a> works well for this.</p>
<p>First we will go over the first bit of the code in the &lsquo;main&rsquo; function</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>uintptr_t gameLogicBA <span style="color:#f92672">=</span> (uintptr_t)GetModuleHandle(<span style="color:#e6db74">L</span><span style="color:#e6db74">&#34;GameLogic.dll&#34;</span>);
</span></span><span style="display:flex;"><span>uintptr_t pwnAdventure3BA <span style="color:#f92672">=</span> (uintptr_t)GetModuleHandle(<span style="color:#e6db74">L</span><span style="color:#e6db74">&#34;PwnAdventure3-Win32-Shipping.exe&#34;</span>);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>cout <span style="color:#f92672">&lt;&lt;</span> <span style="color:#e6db74">&#34;GameLogic.dll base address: 0x&#34;</span> <span style="color:#f92672">&lt;&lt;</span> std<span style="color:#f92672">::</span>hex <span style="color:#f92672">&lt;&lt;</span> gameLogicBA <span style="color:#f92672">&lt;&lt;</span> std<span style="color:#f92672">::</span>endl;
</span></span><span style="display:flex;"><span>std<span style="color:#f92672">::</span>cout <span style="color:#f92672">&lt;&lt;</span> <span style="color:#e6db74">&#34;PwnAdventure3-Win32-Shipping.exe base address: 0x&#34;</span> <span style="color:#f92672">&lt;&lt;</span> std<span style="color:#f92672">::</span>hex <span style="color:#f92672">&lt;&lt;</span> pwnAdventure3BA <span style="color:#f92672">&lt;&lt;</span> std<span style="color:#f92672">::</span>endl;
</span></span></code></pre></div><p>In the above code snippit, we are obtaining the beginning addresses of each &lsquo;module&rsquo;. This is a needed step because these address are randomized each time the program restarts. This is a product of a security feature in the OS called <a href="https://en.wikipedia.org/wiki/Address_space_layout_randomization">ASLR</a>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>pHookManager <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> Utility<span style="color:#f92672">::</span>HookManager();
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>uintptr_t hPlayerPosition <span style="color:#f92672">=</span> pwnAdventure3BA <span style="color:#f92672">+</span> <span style="color:#ae81ff">0xC0087</span>; <span style="color:#75715e">//the functions we will be hooking
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>uintptr_t hPlayerVelocity <span style="color:#f92672">=</span> pwnAdventure3BA <span style="color:#f92672">+</span> <span style="color:#ae81ff">0x8926A4</span>;
</span></span><span style="display:flex;"><span>pHookManager<span style="color:#f92672">-&gt;</span>HookFunctionExt(hPlayerPosition, (uintptr_t)getPlayerPosition, <span style="color:#ae81ff">7</span>, false); <span style="color:#75715e">// hook player position
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>pHookManager<span style="color:#f92672">-&gt;</span>HookFunctionExt(hPlayerVelocity, (uintptr_t)getPlayerVelocity, <span style="color:#ae81ff">6</span>, false); <span style="color:#75715e">// hook player velocity
</span></span></span></code></pre></div><p>The code above is where we initialize the hooks at the code locations found earlier in cheat engine. We use these hooks to &lsquo;rip out&rsquo; the content of specific registers and store their values in some global variables in the source code of our DLL.</p>
<p>The hooking library that I&rsquo;m using is <a href="https://bitbucket.org/mambda/hook_lib/src/master/">mambda&rsquo;s hooking library</a> which I found somewhere on guidedhacking a while back.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">getPlayerPosition</span>(Utility<span style="color:#f92672">::</span>x86Registers<span style="color:#f92672">*</span> pRegs)
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>    uintptr_t playerPosition <span style="color:#f92672">=</span> pRegs<span style="color:#f92672">-&gt;</span>ecx <span style="color:#f92672">+</span> <span style="color:#ae81ff">0x90</span>;
</span></span><span style="display:flex;"><span>    pPlayerPosition <span style="color:#f92672">=</span> (vec3<span style="color:#f92672">*</span>)playerPosition;
</span></span><span style="display:flex;"><span>    uintptr_t playerYaw <span style="color:#f92672">=</span> pRegs<span style="color:#f92672">-&gt;</span>ecx <span style="color:#f92672">+</span> <span style="color:#ae81ff">0xFC</span>;
</span></span><span style="display:flex;"><span>    pPlayerYaw <span style="color:#f92672">=</span> (<span style="color:#66d9ef">float</span><span style="color:#f92672">*</span>)playerYaw;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>	<span style="color:#75715e">// Return the original function
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>	<span style="color:#66d9ef">return</span> Utility<span style="color:#f92672">::</span>HookManager<span style="color:#f92672">::</span>EXECUTE_TARGET_FUNCTION;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">getPlayerVelocity</span>(Utility<span style="color:#f92672">::</span>x86Registers<span style="color:#f92672">*</span> pRegs)
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>    uintptr_t playerVelocity <span style="color:#f92672">=</span> pRegs<span style="color:#f92672">-&gt;</span>ecx <span style="color:#f92672">+</span> <span style="color:#ae81ff">0x7C</span>;
</span></span><span style="display:flex;"><span>	pPlayerVelocity <span style="color:#f92672">=</span> (vec3<span style="color:#f92672">*</span>)playerVelocity;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>	<span style="color:#75715e">// Return the original function
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>	<span style="color:#66d9ef">return</span> Utility<span style="color:#f92672">::</span>HookManager<span style="color:#f92672">::</span>EXECUTE_TARGET_FUNCTION;
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>The code above is the where the hooks are directed to, you can see that we manage to save the players position in the <code>pPlayerPosition</code> variable which was stored at <code>ecx + 0x90</code>. The same goes for <code>pPlayerVelocity</code> which was stored at <code>ecx + 0x7C</code>. It&rsquo;s also worth noting that the player yaw was stored in a similar location as the player&rsquo;s position. This is good to know because we will use it for the noclip code.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">while</span> (<span style="color:#f92672">!</span>GetAsyncKeyState(VK_ESCAPE))
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">//toggles when you press the &#39;F&#39; key
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>    <span style="color:#66d9ef">if</span> (GetAsyncKeyState(<span style="color:#ae81ff">0x46</span>) <span style="color:#f92672">&amp;</span> <span style="color:#ae81ff">1</span>)
</span></span><span style="display:flex;"><span>	{
</span></span><span style="display:flex;"><span>		bFlyHack <span style="color:#f92672">=</span> <span style="color:#f92672">!</span>bFlyHack;
</span></span><span style="display:flex;"><span>	}
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> (bFlyHack <span style="color:#f92672">&amp;&amp;</span> pPlayerPosition <span style="color:#f92672">&amp;&amp;</span> pPlayerVelocity <span style="color:#f92672">&amp;&amp;</span> pPlayerYaw)
</span></span><span style="display:flex;"><span>    {
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        pPlayerVelocity<span style="color:#f92672">-&gt;</span>x <span style="color:#f92672">=</span> <span style="color:#ae81ff">0.0f</span>;
</span></span><span style="display:flex;"><span>        pPlayerVelocity<span style="color:#f92672">-&gt;</span>y <span style="color:#f92672">=</span> <span style="color:#ae81ff">0.0f</span>;
</span></span><span style="display:flex;"><span>        pPlayerVelocity<span style="color:#f92672">-&gt;</span>z <span style="color:#f92672">=</span> <span style="color:#ae81ff">0.0f</span>;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">float</span> speed <span style="color:#f92672">=</span> <span style="color:#ae81ff">175.0f</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">float</span> radYaw <span style="color:#f92672">=</span> (<span style="color:#f92672">*</span>pPlayerYaw <span style="color:#f92672">*</span> (PI <span style="color:#f92672">/</span> <span style="color:#ae81ff">180</span> ));
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (GetAsyncKeyState(<span style="color:#ae81ff">0x57</span>)) <span style="color:#75715e">//w
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        {
</span></span><span style="display:flex;"><span>            pPlayerPosition<span style="color:#f92672">-&gt;</span>x <span style="color:#f92672">=</span> pPlayerPosition<span style="color:#f92672">-&gt;</span>x <span style="color:#f92672">+</span> cos(radYaw) <span style="color:#f92672">*</span> speed;
</span></span><span style="display:flex;"><span>            pPlayerPosition<span style="color:#f92672">-&gt;</span>y <span style="color:#f92672">=</span> pPlayerPosition<span style="color:#f92672">-&gt;</span>y <span style="color:#f92672">+</span> sin(radYaw) <span style="color:#f92672">*</span> speed;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (GetAsyncKeyState(<span style="color:#ae81ff">0x53</span>)) <span style="color:#75715e">//s
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        {
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>            pPlayerPosition<span style="color:#f92672">-&gt;</span>x <span style="color:#f92672">=</span> pPlayerPosition<span style="color:#f92672">-&gt;</span>x <span style="color:#f92672">-</span> cos(radYaw) <span style="color:#f92672">*</span> speed;
</span></span><span style="display:flex;"><span>            pPlayerPosition<span style="color:#f92672">-&gt;</span>y <span style="color:#f92672">=</span> pPlayerPosition<span style="color:#f92672">-&gt;</span>y <span style="color:#f92672">-</span> sin(radYaw) <span style="color:#f92672">*</span> speed;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (GetAsyncKeyState(<span style="color:#ae81ff">0x51</span>)) <span style="color:#75715e">//q
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        {
</span></span><span style="display:flex;"><span>            pPlayerPosition<span style="color:#f92672">-&gt;</span>z <span style="color:#f92672">-=</span> speed;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (GetAsyncKeyState(<span style="color:#ae81ff">0x45</span>)) <span style="color:#75715e">//e
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        {
</span></span><span style="display:flex;"><span>            pPlayerPosition<span style="color:#f92672">-&gt;</span>z <span style="color:#f92672">+=</span> speed;
</span></span><span style="display:flex;"><span>        }    
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    Sleep(<span style="color:#ae81ff">25</span>);
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>The above code contains the actual logic for the noclip. We use the winapi function <code>GetAsyncKeyState()</code> to determine what keys are currently being pressed.</p>
<p>All we are doing in this code is taking the current players position and doing some vector math to determine what we should change the position to. We only take into account the current Yaw of the player character (which way we are looking). This way you can hold <code>W</code> and you will move in the direction you are looking.</p>
<p>Here&rsquo;s a fun picture of it in action!
<img src="/img/pwnfly.png" alt="pwnfly"></p>
<h2 id="summary">Summary</h2>
<p>Welp that just about wraps up this little project. I made this project for a different presentation that was intended to be an Intro to Game Hacking, but I figured that this code is still fun enough to do a little writeup about it. Hopefully someone found this interesting, if you have any advice or anything else you can contact me on discord @ <code>tappineapple</code></p>
]]></content>
        </item>
        
        <item>
            <title>Easy Crackme</title>
            <link>https://adinjura.com/posts/2023/04/easy-crackme/</link>
            <pubDate>Sun, 09 Apr 2023 00:00:00 +0000</pubDate>
            
            <guid>https://adinjura.com/posts/2023/04/easy-crackme/</guid>
            <description>&lt;h2 id=&#34;easy-crackme-tutorial&#34;&gt;Easy Crackme Tutorial&lt;/h2&gt;
&lt;p&gt;In this video we will be using IDA to reverse an &amp;rsquo;easy&amp;rsquo; crackme that we found.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a list of tools that we used in the video:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Detect It Easy (Die)&lt;/li&gt;
&lt;li&gt;Ida Pro&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;video&#34;&gt;Video&lt;/h2&gt;
&lt;div style=&#34;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&#34;&gt;
      &lt;iframe allow=&#34;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen&#34; loading=&#34;eager&#34; referrerpolicy=&#34;strict-origin-when-cross-origin&#34; src=&#34;https://www.youtube.com/embed/RltVSsTkBto?autoplay=0&amp;amp;controls=1&amp;amp;end=0&amp;amp;loop=0&amp;amp;mute=0&amp;amp;start=0&#34; style=&#34;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;&#34; title=&#34;YouTube video&#34;&gt;&lt;/iframe&gt;
    &lt;/div&gt;</description>
            <content type="html"><![CDATA[<h2 id="easy-crackme-tutorial">Easy Crackme Tutorial</h2>
<p>In this video we will be using IDA to reverse an &rsquo;easy&rsquo; crackme that we found.</p>
<p>Here&rsquo;s a list of tools that we used in the video:</p>
<ul>
<li>Detect It Easy (Die)</li>
<li>Ida Pro</li>
</ul>
<h2 id="video">Video</h2>
<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;">
      <iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen" loading="eager" referrerpolicy="strict-origin-when-cross-origin" src="https://www.youtube.com/embed/RltVSsTkBto?autoplay=0&amp;controls=1&amp;end=0&amp;loop=0&amp;mute=0&amp;start=0" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" title="YouTube video"></iframe>
    </div>

]]></content>
        </item>
        
    </channel>
</rss>
