<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>windows &#8211; Adwiteeya Agrawal | Home</title>
	<atom:link href="https://adwiteeya.com/tag/windows/feed/" rel="self" type="application/rss+xml" />
	<link>https://adwiteeya.com</link>
	<description>Security fanatic. Reverse Engineer and Web App Specialist.</description>
	<lastBuildDate>Wed, 18 Sep 2013 08:06:19 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.7</generator>
	<item>
		<title>Trolling func1()</title>
		<link>https://adwiteeya.com/trolling-func1/</link>
					<comments>https://adwiteeya.com/trolling-func1/#comments</comments>
		
		<dc:creator><![CDATA[Adwiteeya Agrawal]]></dc:creator>
		<pubDate>Wed, 18 Sep 2013 05:44:28 +0000</pubDate>
				<category><![CDATA[Information Security]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[breakpoint]]></category>
		<category><![CDATA[Loader]]></category>
		<category><![CDATA[OllyDbg]]></category>
		<category><![CDATA[openprocess]]></category>
		<category><![CDATA[Return Address]]></category>
		<category><![CDATA[Reverse Engineering]]></category>
		<category><![CDATA[Reversing]]></category>
		<category><![CDATA[stack]]></category>
		<category><![CDATA[waitfordebugevent]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[windows debugging]]></category>
		<guid isPermaLink="false">http://adwiteeya.com/blog/?p=418</guid>

					<description><![CDATA[A note to the technical reader : This is basically a custom loader I wrote so that i could edit the return address of functions on the stack. Hi, non technical reader. Introduction So basically this is the small program I wrote, which we are going to play with. In this program there are two [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><strong>A note to the technical reader</strong> : This is basically a custom loader I wrote so that i could edit the return address of functions on the stack.</p>
<p>Hi, non technical reader.<span id="more-418"></span></p>
<p><span style="text-decoration: underline;"><strong>Introduction</strong></span></p>
<p>So basically this is the small program I wrote, which we are going to play with. In this program there are two functions : func1() and func2(). func1() is called from main, but func2() is never called.</p>
<p><script type="text/javascript" src="https://gist.github.com/adwiteeya/6605006.js"></script>So our aim is to execute func2 at run time.Here is the first run :</p>
<p><a href="http://adwiteeya.com/wp-content/uploads/2013/09/first-run.png"><img decoding="async" class="size-full wp-image-423 aligncenter" alt="first run" src="http://adwiteeya.com/wp-content/uploads/2013/09/first-run.png" width="401" height="111" srcset="https://adwiteeya.com/wp-content/uploads/2013/09/first-run.png 401w, https://adwiteeya.com/wp-content/uploads/2013/09/first-run-300x83.png 300w" sizes="(max-width: 401px) 100vw, 401px" /></a></p>
<p>As you can see we do not go inside func2.</p>
<p><span style="text-decoration: underline;"><strong>Reverse Engineering solution</strong></span> The first and the lot easier approach to this is, a RE solution. In this solution i just change some return addresses on the stack and we are done. Lets go step by step.</p>
<p><strong>Step1</strong> : Loading the program in OllyDbg</p>
<p><a href="http://adwiteeya.com/wp-content/uploads/2013/09/print2-in-olly.png"><img fetchpriority="high" decoding="async" class="size-full wp-image-424 aligncenter" alt="print2 in olly" src="http://adwiteeya.com/wp-content/uploads/2013/09/print2-in-olly.png" width="663" height="328" srcset="https://adwiteeya.com/wp-content/uploads/2013/09/print2-in-olly.png 663w, https://adwiteeya.com/wp-content/uploads/2013/09/print2-in-olly-300x148.png 300w, https://adwiteeya.com/wp-content/uploads/2013/09/print2-in-olly-624x308.png 624w" sizes="(max-width: 663px) 100vw, 663px" /></a></p>
<p>As can be seen there are three functions main, func1 and func2. These are indicated by the square brackets. The order of these functions is func1, func2 and lastly main.</p>
<p><strong>Step2</strong> : Now I am going to put a breakpoint on func1 and then observe the stack.</p>
<p><a href="http://adwiteeya.com/wp-content/uploads/2013/09/print2-hit-breakpoint.png"><img decoding="async" class="aligncenter size-full wp-image-425" alt="print2 hit breakpoint" src="http://adwiteeya.com/wp-content/uploads/2013/09/print2-hit-breakpoint.png" width="734" height="528" srcset="https://adwiteeya.com/wp-content/uploads/2013/09/print2-hit-breakpoint.png 734w, https://adwiteeya.com/wp-content/uploads/2013/09/print2-hit-breakpoint-300x215.png 300w, https://adwiteeya.com/wp-content/uploads/2013/09/print2-hit-breakpoint-624x448.png 624w" sizes="(max-width: 734px) 100vw, 734px" /></a></p>
<p>We have two images here the first one represents the assembly view of print2.cpp when i hitthe breakpoint and the second one represents the stack when I hit the breakpoint. In figure 1 it can be seen that the func1 starts at 401334 and it(the address) is in read with black background. Which indicates that we have hit the breakpoint. In figure two we can see that the return address for func1() is 0040139A. If we look up this address in the assembly dump, it is the one just after func1() is called that is 401395. Hence, things are fine here, the function always returns to the immediate expression after a call to it. So we have two deductions from here. First that the return address is 40139A which can be changed to make the func1() jump somewhere else. and secondly that this address is placed on the memory address starting 28FF0C. <strong> </strong></p>
<p><strong>Step3</strong> : Now we are going to edit 40139A to 401359 so that we can jump over to func2().</p>
<p><a href="http://adwiteeya.com/wp-content/uploads/2013/09/stck-modified.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-427" alt="stck modified" src="http://adwiteeya.com/wp-content/uploads/2013/09/stck-modified.png" width="457" height="148" srcset="https://adwiteeya.com/wp-content/uploads/2013/09/stck-modified.png 457w, https://adwiteeya.com/wp-content/uploads/2013/09/stck-modified-300x97.png 300w" sizes="auto, (max-width: 457px) 100vw, 457px" /></a></p>
<p>After the modification even the comment changes to print2.00401359, which suggests that it is call. And as expected we enter the func2().</p>
<p><a href="http://adwiteeya.com/wp-content/uploads/2013/09/func2-entered.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-428" alt="func2 entered" src="http://adwiteeya.com/wp-content/uploads/2013/09/func2-entered.png" width="712" height="328" srcset="https://adwiteeya.com/wp-content/uploads/2013/09/func2-entered.png 712w, https://adwiteeya.com/wp-content/uploads/2013/09/func2-entered-300x138.png 300w, https://adwiteeya.com/wp-content/uploads/2013/09/func2-entered-624x287.png 624w" sizes="auto, (max-width: 712px) 100vw, 712px" /></a></p>
<p>However this is not enough. In a similar way we have to edit the return address of func2 to 40139A which was the original return address of func1. Now to be able to identify where is the return address of func2, we single step through func2 till we reach RETN.</p>
<p><strong>Step4</strong> : Here the top address on the stack is the return address for the stack. We need to change this address. In order to return and exit normally.</p>
<p><a href="http://adwiteeya.com/wp-content/uploads/2013/09/func2-return.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-431" alt="func2 return" src="http://adwiteeya.com/wp-content/uploads/2013/09/func2-return.png" width="570" height="296" srcset="https://adwiteeya.com/wp-content/uploads/2013/09/func2-return.png 570w, https://adwiteeya.com/wp-content/uploads/2013/09/func2-return-300x155.png 300w" sizes="auto, (max-width: 570px) 100vw, 570px" /></a></p>
<p>As can be seen on the stack 0028FF10 is the address where the return address 00403050 is stored. We modify this and then run the program.</p>
<p><a href="http://adwiteeya.com/wp-content/uploads/2013/09/re-success.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-432" alt="re success" src="http://adwiteeya.com/wp-content/uploads/2013/09/re-success.png" width="457" height="161" srcset="https://adwiteeya.com/wp-content/uploads/2013/09/re-success.png 457w, https://adwiteeya.com/wp-content/uploads/2013/09/re-success-300x105.png 300w" sizes="auto, (max-width: 457px) 100vw, 457px" /></a></p>
<p>We are able to do it neatly. :)</p>
<p><span style="text-decoration: underline;"><strong>Program Solution</strong></span></p>
<p>Now the RE solution was though easy, it wasn&#8217;t automated, and i had no fuckin idea about how do i make a permanent modification. What i mean here is like if you want to completely change an instruction you can do that and simply save changes to the new executable. But the stack is a dynamic memory region, it is not a part of the exe file that you save. So there was something more, some workaround that was needed. And thanks to Atul Alex Cherian, who told me about loader. So a loader is basically a program that lets the entire exe load in memory and then plays around with it. I first thought about using a tool for this, but then why not just code this shit out. So here is the algorithm that i followed for this. <strong></strong></p>
<p><strong>Step1</strong>. Use fread to read the bytes of print2.exe to an array.</p>
<p><strong>Step2</strong>. In this array modify the byte that represents beginning of func1 to CC (breakpoint).</p>
<p><strong>Step3.</strong> Save this array to a new myf.exe</p>
<p><strong>Step4</strong>. Detach pointer to myf.exe and open process myf.exe as a DEBUG_PROCESS <strong></strong></p>
<p><strong>Step5</strong>. Waitforadebugevent and use a simple condition to check that it orignates from the one that you forced.</p>
<p><strong>Step6</strong>. On receiving the EXCEPTION_BREAKPOINT DEBUG_EVENT suspend the thread using process information of myf.exe</p>
<p><strong>Step7</strong>, Now change the CC that you placed to the original byte</p>
<p><strong>Step8</strong>. Getthreadcontext of this thread and access the context structure to decrement EIP.</p>
<p><strong>Step9</strong>. Now change return addresses of func1 and func2. For func1 only one byte is edited and for func2 one has to edit 2 bytes.</p>
<p><strong>Step10</strong>. Resume thread. Myf.exe should exit after you press the first enter, then loader.exe should exit after you press the second enter. Here is the code :<script type="text/javascript" src="https://gist.github.com/adwiteeya/6605021.js"></script></p>
<p>Here is the screen shot showing its execution.</p>
<p><a href="http://adwiteeya.com/wp-content/uploads/2013/09/program-success.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-434" alt="program success" src="http://adwiteeya.com/wp-content/uploads/2013/09/program-success.png" width="671" height="338" srcset="https://adwiteeya.com/wp-content/uploads/2013/09/program-success.png 671w, https://adwiteeya.com/wp-content/uploads/2013/09/program-success-300x151.png 300w, https://adwiteeya.com/wp-content/uploads/2013/09/program-success-624x314.png 624w" sizes="auto, (max-width: 671px) 100vw, 671px" /></a></p>
<p>And special thanks to Dhanesh sir. :)</p>
<p>H3LL Y34H! :)</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://adwiteeya.com/trolling-func1/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>CheckRemoteDebuggerPresent API</title>
		<link>https://adwiteeya.com/checkremotedebuggerpresent-api/</link>
					<comments>https://adwiteeya.com/checkremotedebuggerpresent-api/#comments</comments>
		
		<dc:creator><![CDATA[Adwiteeya Agrawal]]></dc:creator>
		<pubDate>Thu, 11 Jul 2013 18:21:26 +0000</pubDate>
				<category><![CDATA[Information Security]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Anti-debugging]]></category>
		<category><![CDATA[RE]]></category>
		<category><![CDATA[summer project]]></category>
		<category><![CDATA[win32 api]]></category>
		<category><![CDATA[windows]]></category>
		<guid isPermaLink="false">http://adwiteeya.com/blog/?p=346</guid>

					<description><![CDATA[Hi, I am currently working on anti-debugging techniques which will also be my project for this year in college.Though i know for a fact  most basic anti-debug techniques are  API based techniques, but i am still doing this post because firstly i did not find any working code and whatever non-working code was present was [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Hi,</p>
<p>I am currently working on anti-debugging techniques which will also be my project for this year in college.Though i know for a fact  most basic anti-debug techniques are  API based techniques, but i am still doing this post because firstly i did not find any working code and whatever non-working code was present was also implemented locally&#8230; By the way I am really impressed by the work compiled by Tyler Shields in 2009 and he has put up some of the best resources out there!</p>
<p>This post is basically about one of those standard API&#8217;s &gt; CheckRemoteDebuggerPresent function. <span id="more-346"></span>Now there is enough stuff on msdn and other websites that you can find about its implementations and about the working of the function however for some reason they did not work for me! So here is what finally worked. And I have done a remote process example too.</p>
<p><strong>Implementation for process locally </strong></p>
<p><span style="color: #339966;">#ifndef _WIN32_WINNT</span><br />
<span style="color: #339966;">#define _WIN32_WINNT 0x0601</span><br />
<span style="color: #339966;">#endif</span><br />
<span style="color: #339966;">#include&lt;windows.h&gt;</span><br />
<span style="color: #339966;">#include&lt;stdio.h&gt;</span><br />
<span style="color: #339966;">#include&lt;conio.h&gt;</span></p>
<p>int main()<br />
{<br />
BOOL pblsPresent = FALSE;<br />
HANDLE hndle = NULL;</p>
<p>CheckRemoteDebuggerPresent(GetCurrentProcess(),&amp;pblsPresent);<br />
if(pblsPresent){<br />
printf(&#8220;<span style="color: #3366ff;">Being Debugged\n</span>&#8220;);<br />
}<br />
else{<br />
printf(&#8220;<span style="color: #3366ff;">Not being debugged\n</span>&#8220;);<br />
}<br />
getch();<br />
return 0;<br />
}</p>
<p><strong>Implementation For Remote Process (</strong>with PID 2800<strong>)</strong></p>
<p><span style="color: #339966;">#ifndef _WIN32_WINNT</span><br />
<span style="color: #339966;">#define _WIN32_WINNT 0x0601</span><br />
<span style="color: #339966;">#endif</span><br />
<span style="color: #339966;">#include&lt;windows.h&gt;</span><br />
<span style="color: #339966;">#include&lt;stdio.h&gt;</span><br />
<span style="color: #339966;">#include&lt;conio.h&gt;</span></p>
<p>int main()<br />
{<br />
BOOL pblsPresent = FALSE;<br />
HANDLE hndle = NULL;</p>
<p>hndle=OpenProcess(PROCESS_ALL_ACCESS,FALSE,2800);</p>
<p>if(hndle){<br />
printf(&#8220;<span style="color: #3366ff;">Done getting a handle \n</span>&#8220;);<br />
}else {<br />
printf(&#8220;<span style="color: #3366ff;">Invalid PID \n</span>&#8220;);<br />
}<br />
CheckRemoteDebuggerPresent(hndle,&amp;pblsPresent);<br />
if(pblsPresent){<br />
printf(&#8220;<span style="color: #3366ff;">Being Debugged\n</span>&#8220;);<br />
}<br />
else{<br />
printf(&#8220;<span style="color: #3366ff;">Not being debugged\n</span>&#8220;);<br />
}<br />
getch();<br />
return 0;<br />
}</p>
]]></content:encoded>
					
					<wfw:commentRss>https://adwiteeya.com/checkremotedebuggerpresent-api/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>That&#8217;s what i learned</title>
		<link>https://adwiteeya.com/thats-what-i-learned/</link>
					<comments>https://adwiteeya.com/thats-what-i-learned/#comments</comments>
		
		<dc:creator><![CDATA[Adwiteeya Agrawal]]></dc:creator>
		<pubDate>Wed, 09 May 2012 09:07:28 +0000</pubDate>
				<category><![CDATA[Information Security]]></category>
		<category><![CDATA[adwiteeya]]></category>
		<category><![CDATA[adwiteeya agrawal]]></category>
		<category><![CDATA[adwiteeya.com]]></category>
		<category><![CDATA[adwiteeya.com/blog]]></category>
		<category><![CDATA[adwiteeya.com/board]]></category>
		<category><![CDATA[attack]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[metasploit]]></category>
		<category><![CDATA[neighbor]]></category>
		<category><![CDATA[payload silent]]></category>
		<category><![CDATA[wifi]]></category>
		<category><![CDATA[windows]]></category>
		<guid isPermaLink="false">http://adwiteeya.com/blog/?p=58</guid>

					<description><![CDATA[Ohkay so there is this software called the metasploit, for hackers its what a wand is for a wizard. The metasploit is a framework, a library of all the exploits and payloads. What happens is basically, that an application may be vulnerable to a certain code..that is for a particular input the application might crash, [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Ohkay so there is this software called the metasploit, for hackers its what a wand is for a wizard. The metasploit is a framework, a library of all the exploits and payloads. What happens is basically, that an application may be vulnerable to a certain code..that is for a particular input the application might crash, if that input is converted into a file such that it can attack the application then it is called an exploit. Also there is something that is called as the &#8220;PAYLOAD&#8221; it is generally the malicious code that is added to the exploit code so that after the exploit has executed the control passes to the payload and a malicious code gets executed, it can act like a trojan and fully compromise your pc or can execute arbitrary shell commands, perhaps it can do pretty much anything you can think of&#8230;.</p>
<p><span id="more-58"></span>Now I recently hacked one of my neighbor&#8217;s wifi and then scanned the network i found out that he was using a couple of devices&#8230; an Iphone(i came to know that it was an iphone during a conversation with my neighbor&#8230; as such the OS fingerprints were not detected on nmap.) &#8230;some nokia phone and a desktop&#8230;.the desktop was a windows machine(with the ip 192.168.1.11) &#8230;windows xp sp2. But the problem was he had his firewall on &#8230; So one day he came online on facebook..so I asked him to switch off his firewall as that can create problems on a computer&#8230;and people tend to fall for things like this&#8230;so did he. :P</p>
<p>So the very next day I was online on facebook and i saw that he too was online at around 6:30 pm&#8230; so i quickly ran the metasploit loaded the exploit and attacked his machine&#8230; i did not expect that this would be successful but it was. :D  i had the meterpreter session running in less than a minute&#8230;.i was in his machine with the power to do anything. :D<br />
And just for fun i promptly sent a message box to his pc saying &#8220;You have been hacked&#8221;&#8230; aaaahhhh :( that was the mistake&#8230; this is the reason i am writing this post.. Whenever&#8230;mind my words WHENEVER&#8230;you hack something&#8230;stay silent dude :D &#8230;.</p>
<p>When he received this message box he came to know it was me&#8230; had a clue atleast(as he told the same later)&#8230; i quickly took screenshots of his desktop as is my habit.. then in around less than 5 second my phone was ringing and it was him calling :D Now that made me laugh! i was caught by the obvious proof!. so i had to tell him to switch on his firewall to stay protected.. But had i not sent that message box&#8230; and rather installed a telnet server on his computer and maintained a life long access to his pc&#8230; that would have been so much better&#8230; but aah! you learn from your mistakes&#8230; i learned to stay silent.</p>
<p>Now i cannot go into his pc anymore&#8230; there were millions of things i could have done&#8230;played around in so many ways if i had not made that mistake&#8230;. but never mind&#8230;mistake done&#8230;lesson learned.. :)</p>
]]></content:encoded>
					
					<wfw:commentRss>https://adwiteeya.com/thats-what-i-learned/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
