<?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>caustik&#039;s blog &#187; assembly</title>
	<atom:link href="http://blog.caustik.com/tag/assembly/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.caustik.com</link>
	<description>gnireenigne</description>
	<lastBuildDate>Sat, 21 Jan 2012 09:04:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Function Hijacking via Export Directory</title>
		<link>http://blog.caustik.com/2007/08/20/function-hijacking-via-export-directory/</link>
		<comments>http://blog.caustik.com/2007/08/20/function-hijacking-via-export-directory/#comments</comments>
		<pubDate>Tue, 21 Aug 2007 00:52:14 +0000</pubDate>
		<dc:creator>caustik</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[Detours]]></category>

		<guid isPermaLink="false">http://caustik.wordpress.com/2007/08/20/function-hijacking-via-export-directory/</guid>
		<description><![CDATA[I have been working on a contract that has necessitated the use of function hooking. Basically, I need to intercept an arbitrary program&#8217;s usage of a system dll library in order to interject my own logic, and interact with the objects produced by that binary. There is a nice tool created by Microsoft Research, called [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on a contract that has necessitated the use of function hooking. Basically, I need to intercept an arbitrary program&#8217;s usage of a system dll library in order to interject my own logic, and interact with the objects produced by that binary.</p>
<p>There is a nice tool created by <a href="http://research.microsoft.com/" target="_blank">Microsoft Research</a>, called <a href="http://research.microsoft.com/sn/detours/" target="_blank">Detours</a>. This is basically an API which helps you to perform binary function interception and instrumentation. This API is fairly robust and well thought out, and I use it in this project. However, there is certainly a fair amount of missing functionality.</p>
<p>While testing my application against a popular product that uses the &#8220;<a href="http://msdn.microsoft.com/msdnmag/issues/01/10/MSLU/" target="_blank">unicows</a>&#8221; library, I stumbled across a very interesting situation during which the Detours method of function interception will not apply.</p>
<p>Basically, unicows has it&#8217;s own custom version of <a href="http://msdn2.microsoft.com/en-us/library/ms683212.aspx" target="_blank">GetProcAddress</a> build in. This custom code crawls through the in memory PE header and obtains function offsets by hand. This means that, for dynamically loaded function addresses, using the Detours functionality I am unable to intercept functions loaded at run-time.</p>
<p>So,  in order to properly intercept these functions, it was necessary to create an additional API from within Detours. This function needs to crawl through the PE header, and replace the Export Directory entry for a given API with the virtual address of the function you wish to be called, instead. The function will also return the original virtual address, so that you can call that function within your intercepted version.</p>
<p>The new code is here: <a href="http://www.caustik.com/blog/DetourReplaceExport.txt" target="_blank">DetourReplaceExport.txt</a></p>
<p>So, now I have a working solution for hijacking an API which is linked dynamically using a non-standard GetProcAddress. Yays!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caustik.com/2007/08/20/function-hijacking-via-export-directory/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>DOS &quot;debug&quot; fun</title>
		<link>http://blog.caustik.com/2006/08/20/dos-debug-fun/</link>
		<comments>http://blog.caustik.com/2006/08/20/dos-debug-fun/#comments</comments>
		<pubDate>Sun, 20 Aug 2006 22:00:06 +0000</pubDate>
		<dc:creator>caustik</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[assembly]]></category>

		<guid isPermaLink="false">https://caustik.wordpress.com/2006/08/20/dos-debug-fun/</guid>
		<description><![CDATA[Sometimes you get the urge to do some programming, but you don&#8217;t have access to a compiler. Luckily, virtually every Windows PC in the world has a utility called &#8220;debug&#8221; installed. This little program lets you input 16-bit x86 assembly language, and allows you to write it out to create a .com file. This file [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you get the urge to do some programming, but you don&#8217;t have access to a compiler. Luckily, virtually every Windows PC in the world has a utility called &#8220;debug&#8221; installed. This little program lets you input 16-bit x86 assembly language, and allows you to write it out to create a .com file. This file can then be executed inside of a DOS shell.</p>
<p>The following is an example of something simple but cool you can do with this program. I will be using some basic DOS interrupts in order to do console input and output. (Lookup &#8216;DOS interrupt 21h&#8217; on google to find out more).</p>
<p>I&#8217;ll highlight everything i&#8217;m typing in green so you can try this at home. You won&#8217;t need to type the optional comments (anything after the semicolon is ignored), and they get lost when you write the file anyway.</p>
<pre><code><font face="lucida console, courier new">C:&gt;<font color="#00aa00">debug kthx.com</font>

-<font color="#00aa00">a 100</font>
1476:0100 <font color="#00aa00">mov cl, d7 ; default cl to character 'd7'</font>
1476:0102 <font color="#00aa00">mov ah, 6  ; ah:6 is console input/output</font>
1476:0104 <font color="#00aa00">mov dl, ff ; dl:ff specifies input</font>
1476:0106 <font color="#00aa00">int 21     ; interrupt 21 call</font>
1476:0108 <font color="#00aa00">jz 10c     ; skip next instruction if failure</font>
1476:010A <font color="#00aa00">mov cl, al ; save result of console input</font>
1476:010C <font color="#00aa00">mov dl, cl ; load current character as output</font>
1476:010E <font color="#00aa00">int 21     ; interrupt 21 call</font>
1476:0110 <font color="#00aa00">jmp 102    ; loop forever!</font>
1476:0112
-<font color="#00aa00">r cx</font>
CX 0012
:<font color="#00aa00">12</font>
-<font color="#00aa00">w</font>
Writing 00012 bytes
-<font color="#00aa00">q</font>
C:&gt;
</font></code></pre>
<p>Now, when you execute &#8220;kthx.com&#8221;, you will see the screen swamped with the funky &#8216;d7&#8242; ASCII character.</p>
<p><a href="http://www.caustik.com/blog/kthx-01.jpg" target="_blank"><img src="http://www.caustik.com/blog/kthx-01-s.jpg" height="243" width="430" /></a></p>
<p>Whenever you type a character, the screen with update to display that character. Try alternating between visible characters and not visible characters (like space). For more fun, try to as quickly as possible type &#8220;\|/-\|/-&#8221; (animates like a little progress bar).</p>
<p>Note that you cant really exit the program. Pressing ctrl+c will actually just display a little heart character. It would be easy to modify the code to accept a character (like escape or control+c) to exit, but i&#8217;ll leave that up to you :].</p>
<p><a href="http://www.caustik.com/blog/kthx-02.jpg" target="_blank"><img src="http://www.caustik.com/blog/kthx-02-s.jpg" height="243" width="430" /></a></p>
<p>This is just one basic thing you can make a .com file do. For a cooler example, check out <a href="http://www.caustik.com/neetro/" target="_blank" title="neetro">neetro</a>. Neetro is a little bit more complex than the program above, so it would have been a pain to write using &#8220;debug&#8221;. The source is instead compiled using <a href="http://sourceforge.net/projects/nasm" target="_blank" title="nasm">nasm</a>.</p>
<p><code></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caustik.com/2006/08/20/dos-debug-fun/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

