Answer
stringlengths
38
29k
Id
stringlengths
1
5
CreationDate
stringlengths
23
23
Body
stringlengths
55
28.6k
Title
stringlengths
15
145
Tags
stringlengths
3
68
<p>This is probably P-code compiled file, not native code. Try WKT Debugger:</p> <p><a href="http://www.woodmann.com/collaborative/tools/index.php/Whiskey_Kon_Tequilla_VB_P-Code_Debugger" rel="nofollow">http://www.woodmann.com/collaborative/tools/index.php/Whiskey_Kon_Tequilla_VB_P-Code_Debugger</a></p>
2662
2013-08-21T03:25:13.687
<p>I'm reverse engineering a Visual Basic application and I've run into a big of a sticky situation, so I was hoping that someone might have an opinion on a way to approach it. It's basically a crackme but I haven't been able to nail down where the callback code is for the function I'm looking for. I've found the labels and captions but I was hoping for an intelligent way to start looking at the binary instead of crawling through it from top to bottom until I find the right comparison.</p> <p>I've taken a look at the output of VB Decompiler but the output isn't matching up to what I'm used to.</p> <p><img src="https://i31.photobucket.com/albums/c367/Fewmitz/decomp_zpsc874945f.png" alt="here&#39;s the output from VB Decompiler"></p> <p>In other VB apps it seems like the locations given there is enough to get started and find the callbacks, but not with this one: <img src="https://i31.photobucket.com/albums/c367/Fewmitz/nocodes_zpsc79f980d.png" alt="this is what I get when trying to find any of the actual code">. </p> <p>I thought at first the code was just being rendered poorly in the debugger but after playing around with it I don't think that location is correct at all. So I'm looking for ideas on where to go from here.</p> <p>Thanks.</p>
Complications reverse engineering a Visual Basic application
|crackme|visual-basic|
<p>you can use hteditor by seppel if disassembly is ok <a href="http://hte.sourceforge.net/" rel="nofollow">http://hte.sourceforge.net/</a></p> <p>copy the .so file from linux machine with say samba</p> <p>and feed the so file to hteditor </p> <p>a sample using libc.so.6 from a damn small linux </p> <p>assuming samba is up and running in vm and a shared folder in windows host is created say <code>c:\sharedwithvm</code></p> <pre><code>from the linux machine </code></pre> <p>cp ../..../lib/libc.so.6 /mnt//sharedwithvm </p> <pre><code>in the windows machine C:\&gt;cd sharedwithvm C:\sharedwithvm&gt;dir /b libc.so.6 C:\sharedwithvm&gt;f:\hteditor\2022\ht-2.0.22-win32.exe libc.so.6 </code></pre> <p>hteditor will open with hex view </p> <pre><code>f6 select elf\image f8 symbols type fo 60490 │ func │ fopen ▲ </code></pre> <p>double click to view the disassembly</p> <pre><code>&lt;.text&gt; @00060490 push ebp fopen+0 ..... ! ;******************************************************** ..... ! ; function fopen (global) ..... ! ;******************************************************** ..... ! fopen: ;xref c189a7 c262da c74722 ..... ! ;xref c93c74 c94cd5 cd23c4 ..... ! ;xref cd3617 cd37c6 cd3a1a ..... ! ;xref cd7061 cd717f cd729f ..... ! ;xref ce50e3 ce67e6 ce7581 ..... ! ;xref cef095 cf0302 ..... ! push ebp 60491 ! mov ebp, esp 60493 ! sub esp, 18h 60496 ! mov [ebp-4], ebx 60499 ! mov eax, [ebp+0ch] 6049c ! call sub_15c8d 604a1 ! add ebx, offset_cab57 604a7 ! mov dword ptr [esp+8], 1 604af ! mov [esp+4], eax 604b3 ! mov eax, [ebp+8] </code></pre>
2664
2013-08-21T08:12:37.187
<p>I would like to decompile the Linux <code>.so</code> files.</p> <ul> <li>Any tool to decompile <code>.so</code> files in MS-Windows based operating system ?</li> <li>Any tools/methods to decompile <code>.so</code> files ?</li> </ul>
How to decompile Linux .so library files from a MS-Windows OS?
|tools|decompilation|decompile|
<p>if you <code>really</code> ask me i will say <code>dump pydbg</code> and start using <code>logged ollydbg conditional break points</code> it will give you the function's arguments cleanly formatted into its components or even windbg</p> <p>you asked pydbg here is how you can do it in pydbg</p> <pre><code>from pydbg import * from pydbg.defines import * def handler_breakpoint (pydbg): if pydbg.first_breakpoint: return DBG_CONTINUE arg1 = dbg.get_arg(1,dbg.context) arg2 = dbg.get_arg(2,dbg.context) arg3 = dbg.get_arg(3,dbg.context) arg4 = dbg.get_arg(4,dbg.context) arg5 = dbg.get_arg(5,dbg.context) text = dbg.read_process_memory(arg2,0x20) lprect = dbg.read_process_memory(arg4,0x10) print "hDc = %08x\nText = %08x %s\nCount = %08x\nlpRect = %08x %s\nuFormat = %08x\n" % (arg1,arg2,pydbg.get_unicode_string(text),arg3,arg4,lprect,arg5) return DBG_CONTINUE dbg = pydbg() dbg.set_callback(EXCEPTION_BREAKPOINT, handler_breakpoint) dbg.attach(2708) DrawTextW = dbg.func_resolve("user32", "DrawTextW") dbg.bp_set(DrawTextW) pydbg.debug_event_loop(dbg) </code></pre> <p>and an output for calc.exe (uses DrawTextW not A)</p> <p>C:\Python27\Lib\site-packages>python calc.py</p> <pre><code>hDc = 48010f0d Text = 000b85fe Sta Count = ffffffff lpRect = 0007fa7c $ ↔ uFormat = 00000025 hDc = 4b010f0d Text = 000b85fe Sta Count = ffffffff lpRect = 0007fa7c $ ↔ uFormat = 00000025 hDc = 6c010ea9 Text = 000b8668 tan Count = ffffffff lpRect = 0007fa7c $ ↔ uFormat = 00000025 hDc = 79010ea9 Text = 000b8668 tan Count = ffffffff lpRect = 0007fa7c $ ↔ uFormat = 00000025 hDc = 7c010f0d Text = 000b8688 x^2 Count = ffffffff lpRect = 0007fa7c $ ↔ uFormat = 00000025 hDc = 8e010f0d Text = 000b8688 x^2 Count = ffffffff lpRect = 0007fa7c $ ↔ uFormat = 00000025 hDc = ab010ea9 Text = 000b869e 1/x Count = ffffffff lpRect = 0007fa7c $ ↔ uFormat = 00000025 hDc = bf010ea9 Text = 000b869e 1/x Count = ffffffff lpRect = 0007fa7c $ ↔ uFormat = 00000025 </code></pre> <p>if you want to change to ollydbg </p> <p>c:> ollydbg.exe calc.exe</p> <pre><code>alt+e -&gt; select calc.exe -&gt; ctrl+N -&gt;Start typing Draw-&gt;select and rightclick -&gt;follow import in disassembler -&gt;shift + f4-&gt; enable radio log function arguments to always leave all else to default and hit ok and f9 to run the exe </code></pre> <p>ollydbg will log all the arguments (you can selectively log only args you want also) like log only if hDc = XXX and Text == X^2 and Uformat != y </p> <p>a sample output from ollydbg running calc.ex and loggging function arguments to DrawTextW</p> <pre><code>7E42D7E2 CALL to DrawTextW from calc.010061F1 hDC = DA011041 Text = "Sta" Count = FFFFFFFF (-1.) pRect = 0007FA28 {0.,0.,36.,29.} Flags = DT_CENTER|DT_VCENTER|DT_SINGLELINE 7E42D7E2 CALL to DrawTextW from calc.010061F1 hDC = DB010B34 Text = "Ave" Count = FFFFFFFF (-1.) pRect = 0007FA28 {0.,0.,36.,29.} Flags = DT_CENTER|DT_VCENTER|DT_SINGLELINE 7E42D7E2 CALL to DrawTextW from calc.010061F1 hDC = A0010D69 Text = "Sum" Count = FFFFFFFF (-1.) pRect = 0007FA28 {0.,0.,36.,29.} Flags = DT_CENTER|DT_VCENTER|DT_SINGLELINE 7E42D7E2 CALL to DrawTextW from calc.010061F1 </code></pre> <p>With windbg do this </p> <pre><code>bp USER32!DrawTextW ".printf \"Text=%mu\\nRect.L=%x\\nRect.R=%x\\n\",poi(esp+8),poi(poi(esp+10)+8),poi(poi(esp+10)+c);gc" </code></pre> <p>windbg conditinal bp output</p> <pre><code>0:001&gt; g Text=F-E Rect.L=24 Rect.R=1d Text=dms Rect.L=24 Rect.R=1d Text=sin Rect.L=24 Rect.R=1d Text=cos Rect.L=24 Rect.R=1d Text=tan Rect.L=24 Rect.R=1d Text=( Rect.L=24 </code></pre>
2668
2013-08-21T17:42:30.590
<p>Using <a href="http://www.rohitab.com/apimonitor" rel="nofollow noreferrer">APIMonitor</a> from Rohitab I found that DrawTextA has some additional arguments I would like to log using Python and <a href="https://github.com/OpenRCE/pydbg" rel="nofollow noreferrer">Pydbg</a> (I'm currently logging lpchText, se below).</p> <p><img src="https://i.stack.imgur.com/wBbN6.png" alt="DrawTextA"></p> <p>My current hooking code looks something like this:</p> <pre><code>def DrawTextHook(dbg, args): # Log lpchText text = dbg.get_ascii_string(incremental_read(dbg, args[1], 255)) </code></pre> <p>The argument I would like to log is <strong>lpRect</strong> and <strong>uFormat</strong>. How do I extend my currrent code to log these two arguments?</p>
Logging lpRect and uFormat from DrawTextA
|python|
<p>There is no "official" calling convention that works like that. What you're seeing is most likely the result of <a href="http://msdn.microsoft.com/en-us/magazine/cc301698.aspx">Link-time Code Generation</a>, also known as LTO (Link-time optimization) or WPO (<a href="http://msdn.microsoft.com/en-us//library/0zza0de8.aspx">Whole program optimization</a>).</p> <p>When it is enabled, the optimization and code generation is done at link time, when the compiler has access to the code of whole program and all compile units, and can use this information for the more extreme optimizations.</p> <p>From <a href="http://msdn.microsoft.com/en-us/library/xbf3tbeh.aspx">MSDN</a>:</p> <blockquote> <p>When /LTCG is used to link modules compiled by using /Og, /O1, /O2, or /Ox, the following optimizations are performed: </p> <ul> <li><p>Cross-module inlining</p></li> <li><p>Interprocedural register allocation (64-bit operating systems only)</p></li> <li><p><strong>Custom calling convention</strong> (x86 only)</p></li> <li><p>Small TLS displacement (x86 only)</p></li> <li><p>Stack double alignment (x86 only)</p></li> <li><p>Improved memory disambiguation (better interference information for global variables and input parameters)</p></li> </ul> </blockquote> <p>In the code snippet you quoted the compiler detected that the function <code>FOO</code> is not called from outside of the program, so it could customize the calling convention to something that uses register values already set up at the place of call, or otherwise improve register allocation. With heavily templated code you can even get several copies of often-used functions that accept arguments in different sets of registers and/or stack.</p>
2673
2013-08-22T15:37:52.227
<p>I am looking at some x86 code, which I believe was built using a Microsoft tool chain, and am trying to figure out the calling convention used during this call:</p> <pre><code> push esi ; save ESI (it gets restored later) lea esi, [ebp-0xC] ; set param 1 for call to FOO call FOO test eax, eax ; test return value jz somelabel </code></pre> <p>The function FOO starts like this:</p> <pre><code> FOO: mov edi, edi push ebx xor ebx, ebx push ebx ; null push esi ; pass ESI in as second param to upcoming call, which has been set by caller push ptr blah mov [esi+0x8], ebx mov [esi+0x4], ebx mov [esi], ebx call InterlockedCompareExchange ; known stdcall func which takes 3 params test eax, eax ... </code></pre> <p>as ESI is not initialized in the body of FOO, I have assumed it is passed in as a param by the caller.</p> <p>What is this calling convention? It looks to be a variant of fastcall. Is there a name for this convention?</p>
What x86 calling convention passes first parameter via ESI?
|x86|calling-conventions|
<p>There are several online tools providing a disassembling service. Here is a (non-exhaustive) list:</p> <ul> <li><a href="http://www.onlinedisassembler.com/odaweb/" rel="nofollow">ODAweb</a> (probably the most known);</li> <li><a href="http://pyms86.appspot.com/" rel="nofollow">Pym's online disassembler</a>;</li> <li><a href="http://code.google.com/p/pvphp/" rel="nofollow">PVPHP</a>;</li> <li><a href="http://udis86.sourceforge.net/" rel="nofollow">Udis86</a>;</li> <li><a href="https://defuse.ca/online-x86-assembler.htm" rel="nofollow">Defuse online x86 assembler</a> (a bit out-of-topic, but we never know).</li> </ul>
2677
2013-08-23T14:22:42.517
<p>Does anyone know if there exists an online service which provides the same functionalities as the <a href="https://github.com/Rendered79/metasploit/blob/master/tools/nasm_shell.rb" rel="noreferrer">Metasploit NASM shell</a> ?</p> <p>Probably the above script can be ported to a standalone tool but I'm not very confident with Ruby, so if someone knows something already implemented, it will be helpful.</p>
Is there an online service which provides the same functionalities as the Metasploit NASM shell?
|shellcode|metasploit|nasm|
<p>Strictly speaking it's not an instruction. It's the segment override prefix (prefixes are considered to be part of the instruction).</p> <p>Most memory accesses use <code>DS</code> segment selector by default except those involving <code>ESP</code> or <code>EBP</code> register (they default to <code>SS</code>) and some "string" instructions (<code>movs</code>, <code>scas</code> etc). Segment override prefixes allow you to use another segment selector to access your data. E.g. in DOS times the <code>CS</code> override was commonly used to access data stored in the code segment (such as jump tables):</p> <pre><code>seg001:00EA shl bx, 1 ; SWITCH seg001:00EC jmp cs:off_13158[bx] ; switch jump ... seg001:0588 off_13158 dw offset loc_12DD7 ; DATA XREF: _main+E6r seg001:0588 dw offset loc_12DE5 ; jump table for switch statement seg001:0588 dw offset loc_12DE5 seg001:0588 dw offset loc_12DE5 </code></pre> <p>The 80386 added two extra segment registers (<code>GS</code> and <code>FS</code>) and the corresponding prefixes.</p> <p>Since the <code>GS</code> prefix does not actually affect the following instruction (<code>insb</code>) in the code snipped above, GAS opted out for printing it on a separate line.</p> <p>In some of the following instructions you can see how it affects the disassembly:</p> <pre><code>64 21 0a -&gt; and %ecx, %fs:(%edx) ^^ ^^^ 67 65 20 54 68 -&gt; and %dl, %gs:0x68(%si) ^^ ^^^ </code></pre> <p>BTW, 67 is another prefix, this time the <em>address size</em> override. It is why the instruction uses the 16-bit <code>SI</code> register and not the full <code>ESI</code>.</p>
2678
2013-08-23T15:01:18.240
<p>I encountered a strange x86-32 instruction (opcode <code>0x65</code>) decoded by <code>objdump</code> as <code>gs</code> (not <code>%gs</code> but <code>gs</code>). I found it while a full linear sweep of a binary (<code>objdump -D</code>), so the decoding was surely incorrect. But, still, <code>objdump</code> didn't decode it as a <code>(bad)</code> instruction, so it means that it can be encountered and I would like to know what does it means.</p> <p>Here is an example of this instruction:</p> <pre><code>080484fc &lt;_IO_stdin_used&gt;: 80484fc: 01 00 add %eax,(%eax) 80484fe: 02 00 add (%eax),%al 8048500: 48 dec %eax 8048501: 65 gs &lt;======================= Here!!! 8048502: 6c insb (%dx),%es:(%edi) 8048503: 6c insb (%dx),%es:(%edi) 8048504: 6f outsl %ds:(%esi),(%dx) 8048505: 20 57 6f and %dl,0x6f(%edi) 8048508: 72 6c jb 8048576 &lt;_IO_stdin_used+0x7a&gt; 804850a: 64 21 0a and %ecx,%fs:(%edx) 804850d: 00 44 6f 64 add %al,0x64(%edi,%ebp,2) 8048511: 67 65 20 54 68 and %dl,%gs:0x68(%si) 8048516: 69 .byte 0x69 8048517: 73 21 jae 804853a &lt;_IO_stdin_used+0x3e&gt; </code></pre> <p>Note that searching for this instruction on the Web is quite difficult because of the <code>%gs</code> register which mask all other possible hit.</p> <p>So, is it a real "instruction" or is it glitch produced by <code>gas</code> ?</p>
GAS/x86 disassembled a bare gs register as an instruction, is it a bug?
|disassembly|x86|objdump|
<p>For testing shellcode on windows and in general, it's good idea to wrap it in a small program that executes it. </p> <p>What you could do is write a small program that would read the shellcode, say , from a file into malloc()-ed buffer and then jump to it. </p> <p>On windows, you'd probably want to use <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366898%28v=vs.85%29.aspx">VirtualProtect</a> to set PAGE_EXECUTE_READWRITE permissions on that memory area before jumping to it. </p> <p>After reading shellcode into malloced memory and setting the execute permissions, you can simply use function pointer to call/jump to it. </p> <p>This will produce the executable binary which you can run in any debugger, set the breakpoint just before the function pointer call and then debug the shellcode as you wish.</p> <p>EDIT:</p> <p>A quick search reveals just a program like that in an article about <a href="http://mcdermottcybersecurity.com/articles/windows-x64-shellcode#testing">Windows x64 Shellcode</a>. The same code can be applied on 32bit Windows.</p>
2685
2013-08-24T20:46:46.823
<p>I am using the Local Bochs Debugger along with IDA Pro to debug a shellcode. This shellcode disassembles properly in IDA Pro, however, now I want to debug it.</p> <p>I tried debugging but since the configuration of Bochs is bare metal, it will not be able to execute some code properly, for instance:</p> <pre><code>xor eax, eax mov eax, dword ptr fs:[eax+0x30] // PEB </code></pre> <p>Since PEB is a structure defined in the Windows Operating System, Bochs does not execute this code properly (does not load the PEB address in eax).</p> <p>Simiarly, other sections of code which parse the kernel32.dll structure to find various API addresses also does not work.</p> <p>How can I debug the shellcode with IDA Pro and Bochs Debugger?</p> <p>I also have the following:</p> <pre><code>Windows XP SP3 Guest OS running in VMWare workstation. IDA Pro running on the host OS. </code></pre> <p>Is it possible to place the shellcode.txt file inside the Guest OS and then debug it using IDA Pro on the host OS? I think in this case, the Windows Debugger, windbg's engine can be used.</p> <p>What will be the configuration? In the following article:</p> <p><a href="https://www.hex-rays.com/products/ida/support/tutorials/debugging_windbg.pdf">https://www.hex-rays.com/products/ida/support/tutorials/debugging_windbg.pdf</a></p> <p>It describes how to debug a remote process running on Windows. But in my case, it is not a process but a shellcode loaded from a text file.</p>
Debugging Shellcode with Bochs and IDA Pro
|ida|
<p>To build off of what the last user said, either Reflector or IlSpy will do the job. However that being said I'd recommend IlSpy over Reflector. Both of them will decompile the program into the intermediate language to roughly the same results but I've had better experiences (i.e. smoother, easier) parsing variable values using IlSpy.</p> <p>But if it's your own code and you remember what all of your variable values are then either one will work fine. Just my two cents.</p>
2688
2013-08-25T10:31:10.710
<p>I was working on a <code>C#.NET</code> application on windows platform, I was just testing the code and I don't know somehow I messed it up and after making too much efforts on <strong>undoing</strong>, I am still not able to <strong>recover</strong> my code. I don't want to write the whole code again.</p> <p>I only left with its .EXE file that executes well here, I want to know about some techniques or tools so that I can decompile my <code>EXE</code> code into its source code, Is it possible if it is, then please tell me some good decompilers. Any help will be appreciated, Thanks.</p>
How can I decompile my (dot)NET .EXE file into its source code
|decompilation|executable|
<p>Assuming the you are speaking about strong encryption, most of the algorithms are supposed to be <a href="http://en.wikipedia.org/wiki/Ciphertext_indistinguishability" rel="nofollow">indistinguishable</a> even if you provided either the key or the clear text. So, it should not be possible to know that a given key is used just by looking at the result. </p> <p>One example of this is the field of <a href="http://en.wikipedia.org/wiki/Kleptography" rel="nofollow">Kleptography</a> where:</p> <blockquote> <p>[...] the outputs of the infected cryptosystem are computationally indistinguishable from the outputs of the corresponding uninfected cryptosystem. Hence, in black-box implementations (e.g., smartcards) the attack is likely to go entirely unnoticed.</p> </blockquote> <p>As you may have noticed, the Kleptography is safe only on black-box implementations, so there indeed room for detection in white-box attacks.</p> <p>But, I have not enough experience in this topic to give you general advices about it. Except the fact that you should start to look at real World implementation of cryptographic backdoors before trying to detect it. You may want to explore some of these links:</p> <ul> <li><a href="http://www.infosecurity-magazine.com/view/30852/the-dark-side-of-cryptography-kleptography-in-blackbox-implementations/" rel="nofollow">The Dark Side of Cryptography: Kleptography in Black-Box Implementations</a>, by Bernhard Esslinger and Patrick Vacek.</li> <li><a href="http://eprint.iacr.org/2002/183" rel="nofollow">Simple backdoors to RSA key generation</a>, by Claude Crépeau and Alain Slakmon.</li> <li><a href="http://www.cryptovirology.com/cryptovfiles/research.html" rel="nofollow">Papers about Cryptovirology</a></li> <li><a href="http://www.iis.sinica.edu.tw/papers/mn/8101-F.pdf" rel="nofollow">A Comprehensive Study of Backdoors for RSA Key Generation</a>, by Ting-Yu Lin, Hung-Min Sun and Mu-En Wu.</li> </ul> <p>And so on...</p>
2698
2013-08-27T12:45:00.983
<p>Assume I use a software to encrypt data. How would I go about to find out with IDA or other RCE tools as to whether there is more than one key used during the encryption?</p> <p>I am talking asymmetric encryption here, and it is possible that the software in question hides one or more master keys (or makes use of some already elsewhere on the system) and I want to find that out. How can I approach that task?</p> <p>NB: you may assume I have determined the various algorithms in use.</p>
Find out whether additional keys are being used when encrypting data
|disassembly|encryption|
<p>Either there is a check somewhere before, or the compiler knows otherwise that <code>edx</code> is not less than 41 (0x29). 0x3B is probably handled by a single switch label, so the compiler added this check to avoid the double memory lookup (or maybe there's an actual <code>if</code> before <code>switch</code> in the source).</p> <p>The table at 0x1009E7D4 is used to retrieve the jump table entry index - Visual C++ compiler always puts the indirect table after the jumps. 0x1009E7AB is likely a part of the previous switch's indirect table. And <code>8B FF</code> is <code>mov edi, edi</code>, used here for alignment.</p> <p>This specific optimization (no subtraction for zero-indexing) seems to be pretty rare; I think I've only seen it in Windows DLLs which often use PGO and other tricks to achieve the last few percents of performance.</p>
2699
2013-08-27T13:56:28.000
<p>I have come across the following x86 (Built with some version of Visual Studio AFAIK) switch statement:</p> <pre><code>0x1009E476 cmp edx, 0x3B 0x1009E479 jnz switch_statement switch_statement: 0x1009E591 movzx ecx, byte [indirect_table+edx] 0x1009E598 jmp dword [table1+ecx*4] indirect_table: 0x1009E7AB db 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07 db 0x07, 0x07, 0x06, 0x8B, 0xFF table1: 0x1009E7B8 dd ptr code1 dd ptr code2 dd ptr code3 dd ptr code4 dd ptr code5 dd ptr code6 dd 0x00000000 0x1009E7D4 dd 0x01060600, 0x06020606, 0x06060306, 0x06060606 ; Note: nothing directly references this data. dd 0x06040606, 0x06060606, 0x06060606, 0x06060606 dd 0x06060606, 0x06060606, 0x06060606, 0x06060606 dd 0x06060606, 0x06060606, 0x06060606, 0x06060606 dd 0x06060606 </code></pre> <p>No index in the <code>indirect_table</code> will end up referencing any of the 6 pointers in <code>table1</code>. Index 6 will dereference a null pointer, index 7 will dereference <code>0x01060600</code> and indexes <code>0x8B</code> and <code>0xFF</code> will end up dereferencing garbage. So everything will end up access violating.</p> <p>So perhaps this is a compiler optimization, the data at table1 following the 6 code pointers and 1 null pointer looks like an indirect table, and coincidentally all indexes are suitable for this switch statement (0-6). While the binary has no references to this data, if <code>EBX</code> was known to be <code>0x29</code> or upwards, it would reference into this. The compiler may have decided <code>EBX</code> will not be <code>0</code>-<code>0x29</code> so moved the indirect table location backwards to line things up correctly. What then is the role of <code>cmp edx, 0x3B</code> in this?</p> <p><strong>Is this a compiler code gen issue, a compiler optimization, or have I grossly misunderstood the code?</strong> </p> <p>If an optimization, any supporting reading material would be greatly appreciated.</p>
Unusual x86 switch statement?
|x86|
<p>I know this is an older question now, but I just want to add some updated information to the discussion for future answer-seekers.</p> <p>I'm also experimenting with this. Newer versions of binwalk have an automatic extract feature. Simply run: </p> <pre><code>binwalk -e ./firmwarefile.bin </code></pre> <p>It will extract and split up the different partitions into separate folders. This is much, much easier than using <code>dd</code>, where if you get the values wrong then <code>squashfs</code>/<code>gzip</code>/... will only see it as corrupted. </p> <p>Also, grab a copy of Kali or Backtrack linux (Backtrack might be depreciated now. I think, Kali is preferred) They have <code>binwalk</code> and firmware mod utils either installed or in the apt package manager repo for easy install. </p> <p>As for repackaging a firmware for uploading, I haven't gotten that far yet, myself. With the firmware I am using, <code>binwalk</code> also extracts the file with the signatures, as well. This contains the MD5 data for verifying the firmware on the device. </p>
2704
2013-08-28T14:14:31.663
<p>I'm trying to analyse the firmware image of a NAS device.</p> <p>I used various tools to help the analysis (binwalk, deezee, signsrch, firmware-mod-kit which uses binwalk AFAIK), but all of them have been unsuccessful so far.</p> <p>For example binwalk seems to generate false positive regarding gzip compressed data and Cisco IOS experimental microcode.</p> <pre><code>Scan Time: 2013-08-27 14:52:15 Signatures: 196 Target File: firmware.img MD5 Checksum: 4d34d45db310bf599b62370f92d0a425 DECIMAL HEX DESCRIPTION ------------------------------------------------------------------------------------------------------------------- 80558935 0x4CD3B57 gzip compressed data, ASCII, has CRC, last modified: Fri Oct 4 17:37:33 2019 82433954 0x4E9D7A2 Cisco IOS experimental microcode 145038048 0x8A51AE0 gzip compressed data, ASCII, extra field, last modified: Mon May 26 20:11:40 2014 </code></pre> <p>When trying to decompress the data I got the following error using gunzip/gzip</p> <pre><code>gzip: 4CD3B57.gz is a multi-part gzip file -- not supported </code></pre> <p>According to gzip FAQ (<a href="http://www.gzip.org/#faq2">http://www.gzip.org/#faq2</a>) this is due to a transfer not made in binary mode which has corrupted the gzip header.</p> <p>It looks more like a false positive from binwalk to me mostly because the magic number used to identify gzip data can easily trigger false positive and the dates are wrong.</p> <p>I also ran strings and hexdump command in order to have an idea of the contents of the file and try to identify known pattern but it didn't help much so far (I probably lack experience in that type of thing here).</p> <p>The only non-gibberish/identifiable strings are located at the end of the firmware image.</p> <pre><code>00000000 f5 7b 47 03 d5 08 bf 64 ba e9 99 d8 48 cf 81 18 |.{G....d....H...| 00000010 b1 69 1e 2c c2 f3 46 6b 53 2b b7 63 e8 ce 78 c9 |.i.,..FkS+.c..x.| 00000020 87 fd b8 68 41 4d b2 61 71 cb cc 75 eb 8c e0 75 |...hAM.aq..u...u| 00000030 25 d1 ec bd 6d 46 e8 16 37 c6 f5 2e 2a e0 dc 07 |%...mF..7...*...| 00000040 65 b1 ce 7f 20 57 7c d7 cb 1d 91 fc 05 25 ad af |e... W|......%..| 00000050 58 56 ff 13 4d 03 95 7f ad 58 0e 84 85 2f 73 5c |XV..M....X.../s\| 00000060 d9 19 d4 d4 2c 27 be c6 45 f2 9f a4 b1 e1 04 f1 |....,'..E.......| 00000070 c1 28 17 9c e1 f7 9d 2b 63 c3 7d e1 95 56 06 05 |.(.....+c.}..V..| [...] 09ec9d60 4b 29 75 20 46 6e fb e3 0f 14 d4 93 54 8e 4f bb |K)u Fn......T.O.| 09ec9d70 4b ab 91 bf e7 8a b9 4e c8 ff 87 17 93 19 e9 3f |K......N.......?| 09ec9d80 70 fe a6 9f d3 36 48 83 34 48 83 34 48 83 34 48 |p....6H.4H.4H.4H| 09ec9d90 83 34 48 83 34 48 83 34 48 83 34 48 83 34 48 83 |.4H.4H.4H.4H.4H.| 09ec9da0 34 48 83 34 48 83 34 48 83 34 48 83 34 48 83 34 |4H.4H.4H.4H.4H.4| 09ec9db0 48 83 34 48 83 34 48 83 34 48 83 34 48 83 24 a7 |H.4H.4H.4H.4H.$.| 09ec9dc0 ff 07 e9 0d 37 73 00 20 08 0a 69 63 70 6e 61 73 |....7s. ..icpnas| 09ec9dd0 00 00 10 00 54 53 2d 35 36 39 00 00 00 00 00 00 |....TS-569......| 09ec9de0 00 00 00 00 33 2e 38 2e 33 00 00 00 00 00 00 00 |....3.8.3.......| 09ec9df0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 09ec9e14 </code></pre> <p>It is the first time I'm going through that type of exercise and I'm not sure what I should do next. The image seems to be obfuscated somehow (that might be a wrong assumption).</p> <p>Do you have suggestions/tricks that could help me make some progress?</p>
Firmware analysis and file system extraction?
|obfuscation|file-format|firmware|embedded|
<p>Try getting code inspiration from process hollowing.</p> <p>Here's one that remotely runs it on a new space: <a href="https://github.com/hasherezade/libpeconv/tree/master/run_pe" rel="nofollow noreferrer">https://github.com/hasherezade/libpeconv/tree/master/run_pe</a> <a href="https://github.com/m0n0ph1/Process-Hollowing" rel="nofollow noreferrer">https://github.com/m0n0ph1/Process-Hollowing</a></p> <p>Try:</p> <ol> <li>run the packer loader from a newly allocated memory (copy loader shellcode to and run from RWX allocated mem.)</li> <li>unmap loader PE image, realloc, and replace it with new PE image</li> <li>dynamically import functions from new PE image</li> <li>jump to entry point of new PE image</li> </ol> <p>I haven't dug deep about resource loading yet. But if the new PE image uses LoadResource, it might read the loader's instead. Not sure about this.</p> <p>You can get more ideas from debugging a UPX packed sample.</p>
2708
2013-08-29T00:05:38.870
<p>I am toying with writing a basic PE packer, whose job is simply to execute the attached target PE in memory. I have spent a couple of days getting intimate with the format, and I think that I have grasped it well enough for the purpose. These are the methods I use:</p> <ol> <li>Firstly, the target is bundled with the loader by being inserted into the <code>.data</code> section of a <a href="http://www.nasm.us/" rel="noreferrer">nasm</a> generated object file, which is later compiled together with the loader.</li> <li>Upon execution, the Image Data Directory is examined, and the Import Address Table properly bound by loading the needed libraries and functions.</li> <li>The PE and all of its sections need to be properly laid out in memory, hence <code>ImageBase</code> and <code>SizeOfImage</code> are read, and sufficient virtual memory is allocated for the next two operations.</li> <li>PE headers are written into the new location.</li> <li>Section data is gathered via section headers, and every section gets written into the new memory space, each into its designated virtual address. Proper permissions via <code>VirtualProtect()</code> are also set.</li> <li>Finally, <code>OptionalHeader.AddressOfEntryPoint</code> gets called.</li> </ol> <p>The loader, of course, has an exotic image base, as to not conflict with the standard <code>0x00400000</code> base. My problems lies somewhere along there. Almost every <code>.exe</code> has its relocations table stripped, so there's no way to do a base relocation if the desired base address is unavailable. The loader having a non-standard image base solves the problem to an extent. The target's desired base is only available in about 50% of runs. I've tried to find out what might occupy the memory in the other 50%, and have found out that it's almost always a <a href="http://msdn.microsoft.com/en-us/library/windows/hardware/ff563684%28v=vs.85%29.aspx" rel="noreferrer">section view</a>. Of what, or whose, I don't know. I've tried to use both <code>NtUnmapViewOfSection</code> and <code>NtFreeVirtualMemory</code>, but they don't solve the problem. The first seems to introduce memory corruption and the second does nothing. Is there any way of claiming that memory? Here's a screenshot from ProcessHacker: <img src="https://i.stack.imgur.com/sfrwq.png" alt="">.</p> <p>All ideas are welcome.</p>
A PE packer: issues with the packed image base address
|pe|packers|
<p>You can find the toolchain in Western Digital N900's <a href="http://support.wdc.com/product/download.asp?groupid=1703&amp;sid=179&amp;lang=en" rel="nofollow">GPL source code</a>.</p>
2720
2013-08-31T11:21:52.703
<p>I am currently reversing firmware for some device. Without any issues I was able to reach deep into its core and extract the file-system. Now I was trying to reverse some of the special applications on this device. After checking the file format I noticed the following: It is an ELF 32-bit MSB (big-endian) on the Ubicom32 platform. </p> <p>After googling, checking woodmann and tinkering with it a bit I couldn't find too much information about this format expect the fact that "it exist".</p> <p>Are there tools (or plug-ins) that handle this file format? Can I just regard this as ARM or MIPS? I did find <a href="https://dev.openwrt.org/browser/trunk/target/linux/ubicom32?rev=19815&amp;order=name#files/arch/ubicom32" rel="nofollow">OpenWRT - Ubicom32 Kernel</a> but no toolchain.</p>
What is the Ubicom32 toolchain and where can I find it?
|firmware|ubicon32|
<p>In OllyDBG and ImmunityDbg, in Options->Debugging Options-> Events you have an option "Break on new module". If this option is set, whenever a new DLL is loaded, Olly/Immdbg will break and let you do your business. </p> <p>In Windbg follow Debug-> Event Filters, in the list you will find Load module, on the side set the options to "Enabled" and "Handeled" which will achieve the same result as above.</p> <p>If on the other hand you want to break on the specific function, you can check the DLL exports which lists all the functions exported by DLL. After the DLL is loaded, and the debugger breaks as per previously mentioned settings, you can then proceed to set the breakpoints on individual functions. </p>
2728
2013-09-02T21:06:44.127
<p>I want to debug a DLL when it is called from an application. For example, when Firefox calls <code>nss3.dll</code> "<em>NSS Builtin Trusted Root CAs</em>" to check HTTPS Certificates, I want to catch the <code>nss3.dll</code> and debug all its transactions with a known debugger like OllyDBG or any other. </p> <p>How to trace threads created and debug them ?</p>
How to debug DLL imported from an application?
|debuggers|debugging|
<p>I found the solution. Double click the variable name (<code>configSpaceBuffer</code> in this case) which brings up the stack window for the method where you can undefine the invalid variables and then define it as an array.</p> <p>Here is the output after this change:</p> <pre><code> _this-&gt;ConfigSpace1 = configSpaceBuffer[1]; _this-&gt;ConfigSpace0 = configSpaceBuffer[0]; _this-&gt;ConfigSpace4 = LOBYTE(configSpaceBuffer[4]); _this-&gt;ConfigSpace23 = configSpaceBuffer[23]; _this-&gt;ConfigSpace22 = configSpaceBuffer[22]; </code></pre>
2752
2013-09-05T07:14:52.263
<p>I am currently reversing a windows driver in order to write a Linux compatible driver for a DVB card, but I have come up against a small issue that I can work around, but if it is possible I would like to make it correct.</p> <p>There is a function that part of which reads the 256 byte PCI config space into a local buffer that has been allocated on the stack. The decompilation shows the output as:</p> <pre><code>unsigned __int16 configSpaceBuffer[128]; .... SNIP ... configSpace-&gt;vtable-&gt;tmRegisterAccess_ConfigSpace__tmIGetReg( configSpace, &amp;address, 4, configSpaceBuffer, 256u, 0) _this-&gt;field_4A = v74; _this-&gt;field_4C = *(unsigned __int16 *)configSpaceBuffer; _this-&gt;field_4E = v75; _this-&gt;field_50 = v77; _this-&gt;field_52 = v76; </code></pre> <p>Is it possible to fix the detected function variables to show the following instead?</p> <pre><code> _this-&gt;field_4A = configSpaceBuffer[0]; _this-&gt;field_4C = configSpaceBuffer[1]; _this-&gt;field_4E = configSpaceBuffer[2]; _this-&gt;field_50 = configSpaceBuffer[6]; _this-&gt;field_52 = configSpaceBuffer[8]; </code></pre>
Hex-Rays Decompiler: Buffer on the stack
|ida|hardware|decompiler|driver|hexrays|
<p>If you use the windbg sos extension you can step into the internal calls - which are unmanaged code. The documentation for using sos is a bit tricky to sort out IMO. This link is helpful for learning the sos commands: <a href="http://msdn.microsoft.com/en-us/library/bb190764(v=vs.110).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/bb190764(v=vs.110).aspx</a>. To load SOS I use:</p> <pre><code>.loadby sos clr ; for .NET 4 and higher .loadby sos mscorwks ; for .NET 2 </code></pre> <p>However you have to wait until the .NET DLLs have been loaded before those commands work, so you either have to set a breakpoint or make sure the managed code has some kind of wait (for input or something else) to allow the process to load the .NET DLLs.</p>
2759
2013-09-06T12:49:29.167
<p>I have a .NET method which is marked as an "Internal Call", meaning that it is implemented within the CLR itself. Is there any way to locate the code for and/or decompile such a method?</p>
Decompile "Internal Call"
|decompilation|.net|
<p>You can have a look at <a href="http://www.woodmann.com/collaborative/" rel="nofollow noreferrer">Woodmann</a> or <a href="http://tuts4you.com/" rel="nofollow noreferrer">tuts4you</a> if you need tutorials. And if you want to see what is writes you will have to have where the pointers are stored for the function in question.</p> <p>This has a lot to do with calling conventions, <a href="https://stackoverflow.com/questions/6511096/cdecl-or-stdcall-on-windows">cdecl and stdcall</a> and knowing about them is important for this..</p> <p>I am going to try to explain using the writeFile function.</p> <h2>How does WriteFile Work</h2> <p>First we look at the WriteFile declaration (taken from <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa365747(v=vs.85).aspx" rel="nofollow noreferrer">MSDN</a>)</p> <pre><code>BOOL WINAPI WriteFile( _In_ HANDLE hFile, _In_ LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Out_opt_ LPDWORD lpNumberOfBytesWritten, _Inout_opt_ LPOVERLAPPED lpOverlapped ); </code></pre> <p>Now when we assume that Windows has stdcall (win32api has). We can figure out where we can find the variables. (for more about the stdcall see <a href="http://en.wikipedia.org/wiki/X86_calling_conventions#stdcall" rel="nofollow noreferrer">Wikipedia</a>).</p> <p>Due to our wikipedia article we a few things:</p> <ul> <li>The parameters are pushed onto the stack in right-to-left order</li> <li>Registers EAX, ECX, and EDX are designated for use within the function. </li> <li>Return values are stored in the EAX register.</li> <li>stdcall is the standard calling convention for the Microsoft Win32 API.</li> </ul> <h2>This is great</h2> <p>Now we have everything we need to figure out where we can find the location of the information you need. When a breakpoint is placed on the function call you'll know that all the variables are stored on the stsck. LPCVOID is a Pointer, all that is left is to follow it and read the data.</p>
2761
2013-09-06T21:52:23.350
<p>I've got a process that writes to a file (database). In process monitor I see <code>WriteFile</code>. After this I see the file is about to be either written or updated (offset:length).</p> <p>How can I reveal the content that is about to be written or updated in this file using Ollydbg? Is there a tutorial or something similar? And how to specify the function on Ollydbg? </p> <p>In process monitor, I see <code>WriteFile</code>, but in Ollydbg, what is the function?</p>
How to view the content of a file before it is written?
|windows|debuggers|
<p>I know this is an old thread, but I just wanted to add that your Hauwei E586 is probably based on the HiSierrra Chipset and Firmware. (That is, Huawei firmwares starting with "21." when using the <a href="http://forum.gsmhosting.com/vbb/f804/huawei-modem-universal-flasher-1495518/" rel="nofollow">Huawei Modem Flasher</a>. ) This is using an embedded linux server, unlike those MiFi's based on the Qualcomm chips with firmwares strting with "11.". <a href="http://forum.xda-developers.com/showthread.php?t=2396752" rel="nofollow">Here</a> is another interesting thread on reversing the firmware on one of these (E589). </p> <p>My question is, did you also have to deal with a checksum for the entire binary? (Do you know how to calculate it, and where it's located?)</p> <p><sub>PS. This was meant as a comment, but I still don't have the required Rep. to do that.</sub></p>
2765
2013-09-07T10:57:26.763
<p>I'm working on unpacking Hauwei E586 MiFi firmware. I downloaded firmware update pack which is available as Windows EXE, then used Hauwei Modem Flasher to unpack real firmware from installer.</p> <p>I've got 4 files:</p> <pre><code>01.bin: data 02.bin: ELF 32-bit LSB executable, ARM, version 1, statically linked, not stripped 03.bin: data 04.bin: ELF 32-bit LSB executable, ARM, version 1, statically linked, not stripped </code></pre> <p>As we can see <code>02</code> and <code>04</code> are executable files. <code>01</code> is probably some kind of bootloader (I assume it from string analysis). <code>03</code> is some kind of pseudo FS.</p> <p>I started from analyzing <code>03</code> (I posted it <a href="http://czlug.icis.pcz.pl/~pbm/03.bin" rel="noreferrer">here</a>):</p> <p>There is header part</p> <pre><code>02 00 EE EE 50 BA 6E 00 20 00 00 00 D0 A2 02 00 7B 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 </code></pre> <p><code>7B 02</code> as 16 bits gives 635 which is number of files in binary (verified using <code>strings</code>). Then there are 635 parts describing each file (call it directory) and at the end there is content of files.</p> <p>There is directory entry for first GIF file which I found. I choosed GIF because it's easy to identify (there is header GIF8X and footer 0x3B).</p> <pre><code>77 77 77 5C 75 6D 5C 70 75 62 6C 69 63 5F 73 79 73 2D 72 65 73 6F 75 72 63 65 73 5C 42 75 74 74 75 6E 5F 43 75 72 72 65 6E 74 2E 67 69 66 00 00 lot of zeros 18 22 11 00 10 02 00 00 00 00 00 00 00 00 FF EE </code></pre> <p>We can see its name: <code>www\um\public_sys-resources\Buttun_Current.gif</code> and in last line there is offset of file in binary and file size, but I'm not really sure how to interpret this values.</p> <p>I found first GIF after directory and extracted it manually (from header to footer) which gives me file of size 528 bytes, so reading <code>10 02</code> as 16 bit unsigned gives me that number. I tried to treat <code>18 22</code> as 16 bit unsigned to get offset, but it was different from offset that I manually read from file. Bu there was constant difference between offset and real offset of file of <code>1286864</code>. So I created script for unpacking this binary (I'm getting offset and adding to it <code>1286864</code>).</p> <p>Script worked only partially. It recreated directory structure, but was able only to extract files in one particular directory (directory with GIF which I was using as reference). After check on different part of file it seems that offset of offset in different subdirectories is another that in this GIF directory. So, my guess is that I'm interpreting offset wrong (but treating it as 32 bits gives nothing useful).</p> <p>There is unpack script:</p> <pre><code>import sys, struct, os def main(args): outdir = args[1] f = open(args[0], 'rb') f2 = open(args[0], 'rb') header = f.read(32) print(len(header[16:])) number_of_files = struct.unpack("h", header[16:18])[0] print(number_of_files) for i in range(number_of_files): body = f.read(272) file_, rest = body.split(b'\x00', 1) offset = struct.unpack("H", body[256:258])[0] + 1286864 size = struct.unpack("H", body[260:262])[0] file_ = file_.decode(encoding='UTF-8').replace('\\', '/') dirname = os.path.join(outdir, os.path.dirname(file_)) filename = os.path.basename(file_) print(filename, size, offset, dirname) try: os.makedirs(dirname) except OSError: pass outfile = open(os.path.join(dirname, filename), "wb") f2.seek(offset) outfile.write(f2.read(size)) outfile.close() if __name__=='__main__': sys.exit(main(sys.argv[1:])) </code></pre> <p>Usage: <code>./script.py 03.bin output_directory</code></p> <p>So my question is: what I'm doing wrong? Maybe I should read some another data type as offset/size? Which one?</p>
Hauwei E586 firmware
|file-format|firmware|embedded|
<p>As far as I know there are no tools for exploring and interacting with .IPA files like Androguard for.APK files, but since the .IPA is essentially a zip, you can unzip and analyze the key components individually.</p> <p>Key components of the file and associated tools include:</p> <p><strong>Mach-O</strong></p> <p>The Mach-O file contains the executable code. This executable is encrypted inside the .ipa file unless it has been dumped and rebuilt from a rooted device. Once dumped and rebuilt the functions, strings, etc. can be viewed with IDA Pro. Objective C can be hard to follow so plug-ins like <a href="https://github.com/zynamics/objc-helper-plugin-ida" rel="nofollow">https://github.com/zynamics/objc-helper-plugin-ida</a> can be helpful. Also, check out otool and class-dump <a href="http://www.codethecode.com/projects/class-dump/" rel="nofollow">http://www.codethecode.com/projects/class-dump/</a> .</p> <p><strong>Plists</strong></p> <p>For gathering interesting information I have found the plists (especially iTunesMetadata.plist and the Info.plist). Plists found in the .ipa will either be in a readable XML format or a binary format. To convert binary to readable XML use Apple's plutil(1) or plutil.pl.</p>
2766
2013-09-07T20:34:50.727
<p>I am doing a research project where I want to look at apps that create or extends certain classes. For Android I am using the Androguard project which provide a large set of great tools for inspecting APK files and also comes with an API which I can use to extend it with my own code.</p> <p>I was wondering if there's anything similar available for iOS apps?</p>
AndroGuard equivalent for iOS
|tools|ios|
<p>I believe <kbd>ctrl</kbd>+<kbd>R</kbd> should be what you're looking for (highlight aSomeString before you press the key combo).</p> <p>Alternatively you can use the menu <code>Edit</code>-><code>Operand type</code>-><code>Offset</code>-><code>Offset user defined</code></p>
2770
2013-09-08T19:18:10.763
<p>IDA autodetected some kind of offset like this:</p> <pre><code>mov bx, word ptr (aSomeString+8)[di] </code></pre> <p>I want to set the base address to something else, like for example:</p> <pre><code>mov bx, word ptr (glb_AnArray-6)[di] </code></pre> <p>because the pointer is actually a pointer to an array (of elements with size 6) that is indexed starting from 1. Bonus points if it's possible to transform it to something like this:</p> <pre><code>mov bx, word ptr glb_AnArray[di+6] </code></pre> <p>So the question is: How can I tell IDA to take a specific address as base?</p>
How to manually set the base address of a pointer in IDA?
|ida|
<p>The <code>SCAS</code> instruction is used to scan a string (<code>SCAS</code> = SCan A String). It compares the content of the accumulator (<code>AL</code>, <code>AX</code>, or <code>EAX</code>) against the current value pointed at by <code>ES:[EDI]</code>.</p> <p>When used together with the <code>REPNE</code> prefix (<em>REPeat while Not Equal</em>), <code>SCAS</code> scans the string searching for the first string element which is equal to the value in the accumulator. </p> <p>The Intel manual (Vol. 1, p.231) says:</p> <blockquote> <p>The SCAS instruction subtracts the destination string element from the contents of the EAX, AX, or AL register (depending on operand length) and updates the status flags according to the results. The string element and register contents are not modified. The following “short forms” of the SCAS instruction specify the operand length: SCASB (scan byte string), SCASW (scan word string), and SCASD (scan doubleword string).</p> </blockquote> <p>So, basically, this instruction scan a string and look for the same character than the one stored in <code>EAX</code>. It won't touch any registers other than ECX (counter) and EDI (address) but the status flags according to the results.</p>
2774
2013-09-09T19:50:13.730
<p>I disassembled a file with OllyDbg and it had the following instruction:</p> <pre><code>REPNE SCAS BYTE PTR ES:[EDI] </code></pre> <p>What does that exactly mean ?</p>
What does the assembly instruction 'REPNE SCAS BYTE PTR ES:[EDI]'?
|assembly|ollydbg|
<p>Peter Ferrie has written a nice paper on this: <a href="http://pferrie.host22.com/papers/antidebug.pdf" rel="nofollow">The "Ultimate" Anti-Debugger Reference</a>. A lot of techniques exist, like timing, checking if a process is running named OllyDBG for example. Sometimes people come up with new ideas. Step though your program and try to detect yourself if the program acts differently due to your debugging / olly or vmware (if this is the case).</p>
2778
2013-09-10T09:12:17.270
<p>How can I detect whether an application is using anti-debug techniques? I'm using OllyDbg (2.01beta).</p>
How can I tell if an app is using anti-debug techniques?
|ollydbg|anti-debugging|
<p>This approach (function call followed by data) is very often used to implement switches/table jumps, especially on platforms with limited flash space (so they prefer to not inline switch code but use a helper routine). I've seen it done on ARM, 8051 and some other CPUs. Since the switch data (values and offsets) is not going to change, it makes sense to put it into the code flash space.</p> <p><strong>EDIT</strong>: thanks for the full listing. So apparently that value is used to decrement SP, then 12 bytes of saved registers are copied there, then something else happens in <code>sub 461H</code>.</p> <p>At a guess, this sets up the caller's function frame (allocates space for local vars). As to why it's a code byte and not a direct argument, I have only one theory: to save flash space because only one byte is necessary as opposed to the <code>MOV</code> (at least 2 bytes) or <code>MOV + PUSH</code> (at least 3 bytes) instructions.</p> <p>I'd suggest finding out which compiler was used for this code (Renesas? KPIT?) and searching for this function in runtime libraries. The symbols should help here.</p> <p><strong>EDIT2</strong>: sub 461 seems to be <code>memmove(DE, HL, BC)</code> with copy direction detection. So it's copying N bytes from FE20 into the newly allocated stack space. Weird stuff.</p>
2787
2013-09-13T10:19:30.487
<p>I am working on some disassembly from an NEC 78K0R. Most functions have parameters passed in registers, but there are some functions that have compile time defined parameters passed using a method I have not seen before.</p> <p>Execution of instructions is from flash.</p> <p>The function, 0x4c4, is called as follows:</p> <pre><code>027d9 fdc404 CALL !4C4H 027dc 02 ? ? 027dd 75 MOV D,A </code></pre> <p>The return address is set to 0x27dc and put into the stack.</p> <p>The function itself is as follows:</p> <pre><code>// Entry point from call 004c4 c1 PUSH AX 004c5 c3 PUSH BC 004c6 c5 PUSH DE 004c7 c7 PUSH HL // Get the stack pointer into HL 004c8 aef8 MOVW AX,SP 004ca 16 MOVW HL,AX 004cb c7 PUSH HL // Preserve the ES (extended segment) register used for addressing 004cc 8efd MOV A,ES 004ce c1 PUSH AX // Retreive SP + 0x0A - this is the ES part of the return address 004cf 8c0a MOV A,[HL+0AH] 004d1 9efd MOV ES,A // Retreive SP + 0x8 - this is the lower two bytes of return address 004d3 ac08 MOVW AX,[HL+8H] 004d5 16 MOVW HL,AX // Take the contents of memory from the return address into A 004d6 118b MOV A,ES:[HL] // Not relevant to question 004d8 74 MOV E,A 004d9 c0 POP AX 004da 9efd MOV ES,A 004dc 5500 MOV D,#0H // HL is the original return address - shift up one to skip to instruction and store back into stack 004de a7 INCW HL 004df 17 MOVW AX,HL 004e0 c6 POP HL 004e1 bc08 MOVW [HL+8H],AX </code></pre> <p>So, in short - the parameter 02 is stored in the flash memory in the next address. This is retrieved by using the return address from the stack, and then the return address in the stack in incremented by one so that we get to the next real instruction.</p> <p>The function shifts about the contents of the stack, but I do not think this is material to the problem.</p> <p>I've not seen this method used before - it's rather curious. I can't work out why it would be done - that's a lot of instructions required, as compared to doing:</p> <pre><code>MOV A,#2 CALL !4c4H &lt;use A as parameter&gt; </code></pre> <p>Has anyone got any insights to why this has been done like this?</p> <p><strong>Edit</strong></p> <p>As requested, the entire function:</p> <pre><code>004c4 c1 PUSH AX 004c5 c3 PUSH BC 004c6 c5 PUSH DE 004c7 c7 PUSH HL 004c8 aef8 MOVW AX,SP 004ca 16 MOVW HL,AX 004cb c7 PUSH HL 004cc 8efd MOV A,ES 004ce c1 PUSH AX 004cf 8c0a MOV A,[HL+0AH] 004d1 9efd MOV ES,A 004d3 ac08 MOVW AX,[HL+8H] 004d5 16 MOVW HL,AX 004d6 118b MOV A,ES:[HL] 004d8 74 MOV E,A 004d9 c0 POP AX 004da 9efd MOV ES,A 004dc 5500 MOV D,#0H 004de a7 INCW HL 004df 17 MOVW AX,HL 004e0 c6 POP HL 004e1 bc08 MOVW [HL+8H],AX 004e3 17 MOVW AX,HL 004e4 25 SUBW AX,DE 004e5 bef8 MOVW SP,AX 004e7 c5 PUSH DE 004e8 14 MOVW DE,AX 004e9 320c00 MOVW BC,#0CH 004ec 8b MOV A,[HL] 004ed 99 MOV [DE],A 004ee a7 INCW HL 004ef a5 INCW DE 004f0 b3 DECW BC 004f1 6171 XOR A,A 004f3 616a OR A,C 004f5 616b OR A,B 004f7 dff3 BNZ $4ECH 004f9 c2 POP BC 004fa aef8 MOVW AX,SP 004fc 040c00 ADDW AX,#0CH 004ff 14 MOVW DE,AX 00500 3620fe MOVW HL,#0FE20H 00503 fd6104 CALL !461H 00506 c6 POP HL 00507 c4 POP DE 00508 c2 POP BC 00509 c0 POP AX 0050a d7 RET </code></pre> <p>Sub 461 called from above:</p> <pre><code> 00461 c1 PUSH AX 00462 c3 PUSH BC 00463 61dd PUSH PSW 00465 17 MOVW AX,HL 00466 25 SUBW AX,DE 00467 de18 BNC $481H 00469 37 XCHW AX,HL 0046a 03 ADDW AX,BC 0046b 37 XCHW AX,HL 0046c 35 XCHW AX,DE 0046d 03 ADDW AX,BC 0046e 35 XCHW AX,DE 0046f 61cd POP PSW 00471 b7 DECW HL 00472 b5 DECW DE 00473 8b MOV A,[HL] 00474 99 MOV [DE],A 00475 b3 DECW BC 00476 6171 XOR A,A 00478 616a OR A,C 0047a 616b OR A,B 0047c dff3 BNZ $471H 0047e ee1000 BR $!491H 00481 61cd POP PSW 00483 c5 PUSH DE 00484 c7 PUSH HL 00485 8b MOV A,[HL] 00486 99 MOV [DE],A 00487 a7 INCW HL 00488 a5 INCW DE 00489 b3 DECW BC 0048a 13 MOVW AX,BC 0048b 6168 OR A,X 0048d dff6 BNZ $485H 0048f c6 POP HL 00490 c4 POP DE 00491 c2 POP BC 00492 c0 POP AX 00493 d7 RET </code></pre> <p>And also the pre/post of the call:</p> <pre><code>024fe c5 PUSH DE 024ff fdc404 CALL !4C4H 02502 06 02503 9d24 MOV 0FFE24H,A 02505 33 XCHW AX,BC 02506 bd20 MOVW 0FFE20H,AX </code></pre>
Passing parameter using data at return address (read from stack) in NEC 78K0R
|disassembly|nec-78k0r|
<p>You should rather ask your questions with some kind of example output so that answers are not based on guesswork. </p> <p>Does <em>iam loading the struct</em> mean </p> <ul> <li>I wrote a program where I am employing OpenProcess() ReadProcessMemory() </li> </ul> <p>or does it mean</p> <ul> <li>i am opening the raw file with FILE * fp ; fopen("c:\XXX","wb") fread(fp); or load it in say ollydbg or in a hexeditor</li> </ul> <p>Assuming you use <code>ReadProcessMemory</code> the buffer you provided will be filled with bytes. It is up to you to cast it to proper type for accessing various members of the struct (yes you need a valid prototype of the structure beforehand).</p> <p>A pseudo form could be like this</p> <pre><code>type result; BYTE foo[0x100]; Mystruct *blah; int s1; PSTR s2; result = ReadProcessMemory(where,howmuch,destination,VerifiactionPointer) blah = (MyStruct *)destination; s1 = blah-&gt;someint; s2 = blah-&gt;somestring; </code></pre> <p>Memory you see will always contain hex bytes that are indistinguishable from one another. It is like clay in the hands of a potter. </p> <p>Only the artisan can give it form. Clay by itself can never become a statue or a finely crafted teapot.</p>
2789
2013-09-14T06:29:39.870
<p>I'm trying to load a struct defined in a program that i'm reading the memory of, so I can use it to define objects in my python debugger (in windows).</p> <p>What format do structs take in memory, and what information can i get from finding the struct. Is it possible to find the offsets for all attributes, and all objects linking to the struct?</p> <p>I'd prefer to be able to do this without using breakpoints, but I can use them if there is no other way.</p>
Read a struct from memory
|windows|python|c|struct|
<p>It is not that easy, or it is rather error prone. If you are going to insert 3 bytes in place of 2 bytes, you would be better off if you do a <code>trampoline</code>: jump to some other place, do what you want, then jump back to the next instruction. By employing trampolining, you can also save the registers.</p> <p>A small sample could be like this:</p> <pre><code>jmp SomePlace &lt;---destroy old bytes and insert an unconditional jump NextInst: &lt;----|_________________________ .. | SomePlace: | "dancing with wolves" | jmp NextInst &lt;------- this will jump back to-&gt;| </code></pre> <p>In the case, if you are interested in replacing two bytes with two bytes, then almost all hex editors have some form of search and replace functionality.</p> <p>Or you can write a simple script in your favorite utility.</p> <p>A simple windbg example script for replacing all the <code>push XXXX</code> <code>68 XXXXXX</code> bytes to <code>EB FE</code>. This example is a prototype, you need to tweak it based on the pattern you get:</p> <pre><code>.foreach /pS4 /ps 9 ( place { # 68?? 401000 l?0x20} ) {u place L1;ew place feeb;u place L1 } </code></pre> <p>All what this does is <code>search</code> the disassembly for the <code>pattern 68??</code> (blind search can alter unintended data, use with caution).</p> <p>When it is found, it uses the address where it was found to replace the two bytes <code>68XX</code> with <code>EB FE</code>.</p> <p>It does this for all the bytes that are found in a given range. In addition to this, it also prints out the assembly prior to modification and after modification:</p> <pre><code># 68?? pattern search command in windbg 401000 l?0x20 start search from 0x401000 end at 401020 u place l1 disassemble one instruction when pattern found ew place feeb write word 0xfeeb at found address dis assemble again loop with foreach where ps and pS are skip before and skip after bytes </code></pre> <p>A sample output of the above script:</p> <pre><code>0:000&gt; .foreach /pS4 /ps 9 ( place { # 68?? 401000 l?0x20} ) {u place L1;ew place feeb;u place L1 } msgbox!start+0x2 [msgbox.asm @ 17]: 00401002 6800304000 push offset msgbox!MsgCaption (00403000) msgbox!start+0x2 [msgbox.asm @ 17]: 00401002 ebfe jmp msgbox!start+0x2 (00401002) msgbox!start+0x7 [msgbox.asm @ 17]: 00401007 6819304000 push offset msgbox!MsgBoxText (00403019) msgbox!start+0x7 [msgbox.asm @ 17]: 00401007 ebfe jmp msgbox!start+0x7 (00401007) </code></pre>
2790
2013-09-14T06:57:53.203
<p>After opening a PE file with a disassembler, I know which instructions I have to patch. And if I have to add some data I can adjust the PE file structure manually so that it gets parsed correctly and executes.</p> <p>Example, Replace <code>EB 1C</code> with <code>E9 1C FD</code></p> <p>Now, the question. I have to modify multiple locations and manually adjusting values is killing me. Can I do this with <a href="http://code.google.com/p/pefile" rel="noreferrer">code.google.com/p/pefile</a> from python, which I am assuming will help in adjusting? Or is there any other module I can use? Some sample code I can find?</p>
Patching PE File - Adding data
|pe|
<p>One thing you need to keep in mind is that code in your process and the code in the target process reside in <strong>different address spaces</strong>. So any address in your program is not necessary valid in the target process and vice versa.</p> <p>This means the code that you inject cannot make any assumptions about addresses of functions or variables. Even your <code>inject</code> function's address is valid only in <em>your</em> process; to make it available in the target process you'd have to: 1) copy the code there; and 2) make sure any functions or memory addresses it refers to are valid in the new address space.</p> <p>That's why the normal approach used with <code>CreateRemoteThreadEx</code> is to copy the DLL name to the target process and create the thread using the address of the <code>LoadLibrary</code> function:</p> <pre><code>// 1. Allocate memory in the remote process for szLibPath pLibRemote = ::VirtualAllocEx( hProcess, NULL, sizeof(szLibPath), MEM_COMMIT, PAGE_READWRITE ); // 2. Write szLibPath to the allocated memory ::WriteProcessMemory( hProcess, pLibRemote, (void*)szLibPath, sizeof(szLibPath), NULL ); // Load "LibSpy.dll" into the remote process // (via CreateRemoteThread &amp; LoadLibrary) hThread = ::CreateRemoteThread( hProcess, NULL, 0, (LPTHREAD_START_ROUTINE) ::GetProcAddress( hKernel32, "LoadLibraryA" ), pLibRemote, 0, NULL ); </code></pre> <p>(snippet <a href="http://www.codeproject.com/Articles/4610/Three-Ways-to-Inject-Your-Code-into-Another-Proces" rel="nofollow noreferrer">from Code Project</a>)</p> <p>You can see that <code>pLibRemote</code> (with the address of the DLL name in the target process) is passed as the parameter to the thread routine. So the result of this is equivalent to:</p> <pre><code>LoadLibraryA(pLibRemote); </code></pre> <p>executed in the target process.</p> <p>Strictly speaking, this is not guaranteed to work because the address of <code>LoadLibraryA</code> in your process is not necessarily the same as <code>LoadLibraryA</code> in the other process. However, in practice it does work because system DLLs like kernel32 (where <code>LoadLibraryA</code> resides) are mapped to the same address in all processes, so <code>LoadLibraryA</code> also has the same address in both processes.</p>
2793
2013-09-14T15:20:45.010
<p>So i just read a little bit about how one would go about for injecting a dll into a running program <a href="https://en.wikipedia.org/wiki/DLL_injection">on Wikipedia</a> (the <code>CreateRemoteThread</code> idea). I followed the steps described and eventually got it working. The thing i found interesting though which took some time to figure out are the following: When creating my remote thread and sending in the function i would like to be run as the first/starting one i hit a snag, when it was run it failed to call the proper functions, they seemed to turn into rubbish when i looked at them in OllyDBG which in turn resulted in the program crashing down on me. The code i used then was something along these lines:</p> <pre><code>static DWORD __stdcall inject(LPVOID threadParam) { MessageBoxA(NULL, "test", "test", NULL); LoadLibrary("my.dll"); return 0; } </code></pre> <p>And somewhere else:</p> <pre><code>CreateRemoteThreadEx(hProcess, NULL, 0, LPTHREAD_START_ROUTINE(fnPageBase), dbPageBase, 0, NULL, &amp;threadId); </code></pre> <p>Where <code>fnPageBase</code> is the memory I've allocated in the to be injected process for my function and dbPageBase the memory I've allocated for a struct that is passed as the <code>LPVOID threadParam</code>.</p> <p>Something like that, the problem was that both <code>MessageBoxA</code> and <code>LoadLibrary</code> didn't get a proper address it would seem, when i checked them in OllyDBG they always pointed to something that didn't exist. I googled around a little and found out that i should be using <code>GetProcAddr</code> to get a address to ie: <code>LoadLibrary</code> which i could later use by sending in some data via the <code>LPVOID threadParam</code> in my <code>inject()</code> call. So my question is: Why does it work when i use the <code>GetProcAddr</code> and not when I just try to use it "normally"? Do I get some specific address that's always mapped in for everyone in the same region in memory when using that? </p> <p>Also, what happens to my strings in the <code>inject()</code> function? Are they moved to some other place during compile which makes them unavailable to the program i'm injecting since it's in a totally different place of the memory (i.e., it's not mapped to there?)? I worked that around by sending that along in a struct with the <code>LPVOID threadParam</code> aswell in a struct that i had copied over to memory available to the <code>.exe</code> I was injecting. </p> <p>If you need more info on how I did the other parts please do tell and I'll update.</p>
Dll injection and GetProcAddress with the winapi
|windows|dll|c++|dll-injection|
<p>Previous answer is good. I would say this depends on machine and emulator. There are many more tricks to recognize emulators.</p> <p>You might look at the environment, is there an emultor in the file system? Is the number of running applications indicating a virtual application?</p> <p>Ask the operating system whether the application is debugged; different methods exist, most are easily defeated.</p> <p>I have a program which measures the execution time between close instructions. If the machine does not have hardware support for emulation, this is pretty reliable.</p> <p>Use google for anti-debug</p> <p>Chris Jacobi</p>
2805
2013-09-18T04:55:51.537
<p>I've been given a program that emulates the Windows API. I'm attempting to find flaws in this emulator where it either:</p> <ol> <li>Always returns a constant value, regardless of the host system <em>(Useful for fingerprinting)</em> <ul> <li>For example, calls to get the username in this emulator return various random strings. But calls to get the free disk space always returns the same number, regardless of the actual value on the host system.</li> </ul></li> <li>Returns the real value from bare metal <em>(Emulator leaking real information)</em> <ul> <li>For example, calls to get the MAC address return the value from the host system.</li> </ul></li> </ol> <p>Instead of writing functions to test the return values from various functions in the Windows API, I'm looking for a way to automate code generation (preferably in C/C++) to query a large number of functions provided by the WinAPI . Is anything like this possible or has it been done for other projects that I could leverage?</p>
Detecting an emulator using the windows api
|winapi|
<h3>Depending on your need</h3> <p>If you need to <strong>change the behavior of Objective-C</strong> (possibly also Swift) <strong>methods or classes</strong>, it is way easier to <strong>create a tweak</strong> for the app. There are also many advantages in doing so, one of them being that a tweak can be un/-installed easily at a large scale (just create a source for Cydia with your tweak).</p> <p>Note that if you need a one-time and <em>non permanent</em> change, consider using <strong>Cycript</strong> instead. It is really straightforward (cycript.org). Just inspect the target app's headers with <em>Clutch</em> and <em>class-dump-z</em> in order to have an idea of what you want to modify and you're good to go.</p> <h3>Creating a tweak</h3> <p>In order to create a tweak, you can use <a href="http://www.iosopendev.com" rel="nofollow noreferrer"><strong>iOSOpenDev</strong></a> (and its <a href="http://iphonedevwiki.net/index.php/Logos" rel="nofollow noreferrer"><em>Logos</em></a> template) or <strong>Theos</strong>. iOSOpendev allows you to create your tweak in Xcode and install it to your device, making it really convenient to use.</p>
2814
2013-09-20T11:37:49.667
<p>I'm trying to get jailbreak statistics for a University project related to security in mobile devices. My purpose is to disassemble, add a sample code and re-assemble to obtain a runnable iOS app again.</p> <p>I have read a lot about IDA, IDA pro, HEX-Rays, and o'tool to disassemble an ipa file.</p> <p>Since i'm working with a macbook pro, i think that using otool to disassemble an '.ipa' file is the best and faster way. I have tried it with a non-signed <code>.ipa</code> and I have obtained the assembly code.</p> <p>Then, I have difficulties. I have tried to create a new Xcode project, import this assembly code and try to compile it to generate a new app, without inserting new code just to simplify the process.</p> <p>But when i tried to compile, Xcode fails in every single code line.</p> <p>I think that my problem is, that the process described:</p> <ol> <li>Disassemble with otool</li> <li>Import the code in XCode</li> <li>Compile and build</li> <li>Obtain the new app</li> </ol> <p>Is not correct.</p>
Disassemble, edit and re-assembly iOS ipa apps
|disassembly|assembly|ios|
<p>Ok, this can be tackled in a great number of ways. As you recently learned DLL injection a fun exercise is to use this knowledge to overwrite a function :) </p> <p>A good start is the <a href="https://www.htbridge.com/publications/inline_hooking_in_windows.html" rel="nofollow">Inline Hooking in Windows Presentation by High-Tech Bridge</a> and <a href="http://www.codeproject.com/Articles/2082/API-hooking-revealed" rel="nofollow">this codeproject</a> page. What you do is overwrite the function. What you'll have to to in order to redirect the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa365747%28v=vs.85%29.aspx" rel="nofollow">WriteFileA</a> to your own write function. This allows you to trace-back by walking the return values to determine the flow of the data. You can also examine the way data is written (once or by chunks).</p> <p>You can also Trace the application, check the addresses of data that is collected, see if it gets parsed though some kind of encryption or compression algorithm. </p> <p>Hope I am some form of help. :) </p>
2817
2013-09-20T19:58:50.470
<p>I am working on automating some functionality within a closed-source third party application; I want to automate the creation of "Project Files" (in its simplest form, just a collection of video files in a specific order). The video files which this application works with each have an associated metadata file, and I have already managed to understand and recreate 99% of its format. Both these "project files" and the metadata files are more-or-less plain XML (with some strange tag names I have yet to decipher).</p> <p>Basically, I want to know what methods I can use to determine the format of these project files so that I can write my own and reference the video files I have chosen in the prior part of my script.</p> <p>There are <strong><em>many</em></strong> DLL files in the applications directory, and I was thinking that maybe monitoring their use during a save operation (of a project file in the application) could point me in the right direction? If so, how could I go about this? I have also began learning DLL injection, and was wondering if this could be of use?</p>
Reverse engineer a proprietary save/file format structure
|disassembly|windows|file-format|dll|
<h2>The <em>traditional</em> way to determine the function pointed to by <code>[edi+1Ch]</code> is as follows:</h2> <p>Find the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa378712%28v=vs.85%29.aspx" rel="nofollow noreferrer">Interface Definition Language (IDL)</a> file for the given interface. In your case, the interface is <code>IShellWindows</code>. According to the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/cc836570%28v=vs.85%29.aspx" rel="nofollow noreferrer">documentation for <code>IShellWindows</code></a>, its interface is defined in IDL file <code>Exdisp.idl</code>. That IDL file is included in the <a href="http://en.wikipedia.org/wiki/Microsoft_Windows_SDK" rel="nofollow noreferrer">Windows SDK</a> (downloadable for free), and will be installed to a location such as <code>C:\Program Files\Microsoft SDKs\Windows\v7.1A\Include\Exdisp.idl</code>. You can open that <code>Exdisp.idl</code> file with a text editor to see the Interface Definition of <code>IShellWindows</code>:</p> <pre><code>[ uuid(85CB6900-4D95-11CF-960C-0080C7F4EE85), // IID_IShellWindows helpstring("Definition of interface IShellWindows"), oleautomation, dual, odl, ] interface IShellWindows : IDispatch { //Properties [propget, helpstring("Get count of open Shell windows")] HRESULT Count([out, retval] long *Count); //Methods [id(0), helpstring("Return the shell window for the given index")] HRESULT Item([in,optional] VARIANT index, [out, retval]IDispatch **Folder); [id(-4), helpstring("Enumerates the figures")] HRESULT _NewEnum([out, retval] IUnknown **ppunk); // Some private hidden members to allow shell windows to add and // remove themself from the list. We mark them hidden to keep // random VB apps from trying to Register... [helpstring("Register a window with the list"), hidden] HRESULT Register([in] IDispatch *pid, [in] long hwnd, [in] int swClass, [out]long *plCookie); [helpstring("Register a pending open with the list"), hidden] HRESULT RegisterPending([in] long lThreadId, [in] VARIANT* pvarloc, // will hold pidl that is being opened. [in] VARIANT* pvarlocRoot, // Optional root pidl [in] int swClass, [out]long *plCookie); [helpstring("Remove a window from the list"), hidden] HRESULT Revoke([in]long lCookie); // As an optimization, each window notifies the new location // only when // (1) it's being deactivated // (2) getFullName is called (we overload it to force update) [helpstring("Notifies the new location"), hidden] HRESULT OnNavigate([in]long lCookie, [in] VARIANT* pvarLoc); [helpstring("Notifies the activation"), hidden] HRESULT OnActivated([in]long lCookie, [in] VARIANT_BOOL fActive); [helpstring("Find the window based on the location"), hidden] HRESULT FindWindowSW([in] VARIANT* pvarLoc, [in] VARIANT* pvarLocRoot, /* unused */ [in] int swClass, [out] long * phwnd, [in] int swfwOptions, [out,retval] IDispatch** ppdispOut); [helpstring("Notifies on creation and frame name set"), hidden] HRESULT OnCreated([in]long lCookie,[in] IUnknown *punk); [helpstring("Used by IExplore to register different processes"), hidden] HRESULT ProcessAttachDetach([in] VARIANT_BOOL fAttach); } </code></pre> <p>We can see that the <code>IShellWindows</code> interface has the following <a href="http://en.wikipedia.org/wiki/Virtual_method_table" rel="nofollow noreferrer">vtable</a> entries:</p> <pre><code>- Count() - Item() - _NewEnum() - Register() - RegisterPending() - Revoke() - OnNavigate() - OnActivated() - FindWindowSW() - OnCreated() - ProcessAttachDetach() </code></pre> <p>However, you can also see in the IDL that the <code>IShellWindows</code> interface inherits from <code>IDispatch</code>. <code>IDispatch</code> has the following vtable entries (from <code>OAIdl.idl</code>):</p> <pre><code>- GetTypeInfoCount() - GetTypeInfo() - GetIDsOfNames() - Invoke() </code></pre> <p>The IDL for <code>IDispatch</code> in <code>OAIdl.idl</code> also specifies that <code>IDispatch</code> inherits from <code>IUnknown</code>. <code>IUnknown</code> has the following vtable entries (from <code>Unknwn.idl</code>):</p> <pre><code>- QueryInterface() - AddRef() - Release() </code></pre> <p>So now we know that <code>IShellWindows</code> inherits from <code>IDispatch</code>, which inherits from <code>IUnknown</code>. As such, the full layout of the vtable for <code>IShellWindows</code> is as follows:</p> <pre><code>*ppv+00h = QueryInterface() *ppv+04h = AddRef() *ppv+08h = Release() *ppv+0Ch = GetTypeInfoCount() *ppv+10h = GetTypeInfo() *ppv+14h = GetIDsOfNames() *ppv+18h = Invoke() *ppv+1Ch = Count() *ppv+20h = Item() *ppv+24h = _NewEnum() *ppv+28h = Register() ... </code></pre> <p>Looking back at your code, we see a call to <code>*ppv+1Ch</code>, which we see from our constructed vtable above is a call to the function <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/cc836569%28v=vs.85%29.aspx" rel="nofollow noreferrer"><code>IShellWindows::Count()</code></a>, and <code>&amp;var_C</code> is the pointer to <code>IShellWindows::Count()</code>'s <code>[out, retval] long *Count</code> parameter.</p> <hr> <h2>The <em>dynamic</em> way to determine the function pointed to by <code>[edi+1Ch]</code> is as follows:</h2> <p>Run your code above in a debugger, set a breakpoint on <code>call dword ptr [edi+1Ch]</code>, and see what function that instruction calls.</p> <hr> <h2>The <em>easiest</em> way to determine the function pointed to by <code>[edi+1Ch]</code> is as follows:</h2> <p>Use <a href="http://www.japheth.de/COMView.html" rel="nofollow noreferrer">COMView</a> (<a href="https://web.archive.org/web/20140614155346/http://www.japheth.de/COMView.html" rel="nofollow noreferrer">wayback machine link to COMView</a>) to inspect the <code>IShellWindows</code> interface:</p> <p><img src="https://i.stack.imgur.com/KCaYn.png" alt="&lt;code&gt;IShellWindows&lt;/code&gt; vtable in COMView"></p> <p>You can see in the screenshot above that the function at vtable offset 28 (1Ch) is <code>Count()</code>.</p>
2822
2013-09-22T13:25:17.497
<p>I'm reversing malware and it uses COM, which I evidently don't know. My question is how to find out what method is called using ppv (and objectstublessclient?)</p> <pre><code>push offset ppv ; Address of pointer variable that receives the interface pointer requested in riid push offset IShellWindows push 7 push 0 push offset rclsid call ds:_CoCreateInstance mov ebx, eax mov eax, num4 movsx edx, num8 add eax, edx sub eax, 0Ch cmp ebx, eax ; S_OK, operation successful jnz exit lea eax, [ebp+var_C] ;? push eax mov eax, ppv push eax mov edi, [eax] call dword ptr [edi+1Ch] ; ObjectStublessClient7 </code></pre> <p>I guessed that the last called function is objectStublessClient7 given that there are three methods(queryinterface etc) and then objectStublessClient's (and code looks like it). <em>(Is that right?)</em></p> <p>According to this Microsoft <a href="https://web.archive.org/web/20161029205000/https://www.microsoft.com/msj/0199/com/com0199.aspx" rel="nofollow noreferrer">article</a>:</p> <blockquote> <p>ObjectStubless simply calls into ObjectStublessClient, passing the method index (from ecx) as a parameter. Finally, ObjectStublessClient teases out the format strings from the vtable and jumps to NdrClientCall2. Like NdrStubCall2, this RPCRT4.DLL routine performs the interpretive marshaling and unmarshaling just as if a compiled proxy and stub were in use. </p> </blockquote> <p>What does ObjectStublessClient actually do in simple words? Calls a method by its index? If so, then in my case it will be OnActivate of <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/cc836570%28v=vs.85%29.aspx" rel="nofollow noreferrer">IShellWindows interface</a>? It looks like the arguments don't match (does the first one look like <code>this</code>?)</p>
COM interface methods
|disassembly|windows|com|
<p>In fact, there may be something like:</p> <pre><code>.text:00192CB6 POP {R4} .text:00192CB8 B.W sub_268508 .text:00192CB8 ; End of function XXX::YYY::zZz(void) </code></pre> <p>IIRC I also have seen conditional branches leading outside of what I would expect to be function boundaries, but I cannot find any example now.</p>
2825
2013-09-23T03:14:55.120
<p>I am disassembling and reverse engineering the logic of an assembly routine written in ARMv7 (hope I'm using the right terminology, as I'm a newbie for this particular processor).</p> <p>In doing so, I came across this site: <a href="http://www.davespace.co.uk/arm/introduction-to-arm/pc.html" rel="nofollow" title="Introduction to ARM">Introduction to ARM</a>. In order to determine how much code I need to disassemble, first, I need to determine the length of the code. It is my understanding that I only need to look for <code>[Bxx][2]</code> (branch) instructions and instructions that alter the PC (program counter), for example, </p> <ul> <li><code>MOV PC, r14</code></li> <li><code>POP {r4, r5, pc}</code></li> </ul> <p>Can someone please advise if I have missed out any instructions that I need to look out for? Thank you.</p>
How do I determine the length of a routine on ARMv7?
|disassembly|arm|
<p><code>ldr r2, [r5, #0]</code><br> means r2=*(r5+0)<br> which loads the value pointed to by r5 and places it in r2.<br><br></p> <p><code>sub.w sp, sp, r2</code><br> means sp=sp-r2<br> which subtracts sp by the value in r2 (to allocate stack space).<br><br></p> <p><code>add.w r0, r4, #20 ; 0x14</code><br> means r0=r4+20<br> which adds 20 (decimal) to r4 and places the result in r0.<br><br></p> <p><code>ldr r0, [sp, #0]</code><br> means r0=*(sp+0)<br> which loads the value pointed to by sp and places it in r0.<br><br></p> <p><code>ldr r1, [sp, #4]</code><br> means r1=*(sp+4)<br> which loads the value pointed to by (sp+4) and places it in r1.<br><br></p> <p>In C pseudo-code it looks something like this:</p> <pre><code>x_a7a4d8(dword *ptr_allocsize, void *arg1) { alloca(*ptr_allocsize) dword p2; qword p1; x_5c0864(&amp;arg1, &amp;p1, &amp;p2, ptr_allocsize) return p1; } </code></pre> <p>so it allocates some space for the value returned by the 5c0864 routine (because it uses the stack to return the value), calls the 5c0864 routine, and returns the value returned by 5c0864.</p>
2828
2013-09-23T15:51:42.213
<p>I have some ARMv7 instructions that I do not understand, despite reading the reference at: <a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0040d/Cihcaahe.html" rel="noreferrer">ARM Information Center</a></p> <p>In the context of:</p> <pre><code> a7a4d8: b530 push {r4, r5, lr} a7a4da: 466c mov r4, sp a7a4dc: 4605 mov r5, r0 a7a4de: 682a ldr r2, [r5, #0] a7a4e0: ebad 0d02 sub.w sp, sp, r2 a7a4e4: f104 0014 add.w r0, r4, #20 ; 0x14 a7a4e8: 4669 mov r1, sp a7a4ea: b082 sub sp, #8 a7a4ec: 466a mov r2, sp a7a4ee: 462b mov r3, r5 a7a4f0: f746 f1b8 bl 5c0864 &lt;RoutineName&gt; a7a4f4: 9800 ldr r0, [sp, #0] a7a4f6: 9901 ldr r1, [sp, #4] a7a4f8: 46a5 mov sp, r4 a7a4fa: bd30 pop {r4, r5, pc} </code></pre> <p>What does the following do? Can someone explain in terms of pseudo-code?</p> <pre><code> a7a4de: 682a ldr r2, [r5, #0] a7a4e0: ebad 0d02 sub.w sp, sp, r2 a7a4e4: f104 0014 add.w r0, r4, #20 ; 0x14 a7a4f4: 9800 ldr r0, [sp, #0] a7a4f6: 9901 ldr r1, [sp, #4] </code></pre>
What do the following ARM instructions mean?
|disassembly|arm|
<p>The LZMA compression identified by binwalk is correct (or at least most of them are - I didn't check them all). If you actually extract and decompress the LZMA files, you'll find that the first one (at offset 0x30) contains the device's code (a MIPS RTOS of some sort) and the rest appear to be the HTML files for the web interface.</p>
2830
2013-09-24T08:58:16.033
<p>I'm trying to extract this firmware but I'm running into some issues. The first lecture of the firmware with binwalk shows this:</p> <pre><code>DECIMAL HEX DESCRIPTION ------------------------------------------------------------------------------------------------------------------- 48 0x30 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 992240 bytes 275832 0x43578 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 65011 bytes 312165 0x4C365 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 6425 bytes 314338 0x4CBE2 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 6198 bytes 316542 0x4D47E LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 11645 bytes 319496 0x4E008 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 9923 bytes 322366 0x4EB3E LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 3981 bytes 323721 0x4F089 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 1269 bytes 324228 0x4F284 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 9785 bytes 327024 0x4FD70 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 9717 bytes 329754 0x5081A LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 9957 bytes 332630 0x51356 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 4544 bytes 334066 0x518F2 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 378 bytes 334305 0x519E1 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 1019 bytes 334787 0x51BC3 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 12756 bytes 338395 0x529DB LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 16497 bytes 343482 0x53DBA LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 11019 bytes 347416 0x54D18 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 39577 bytes 358366 0x577DE JPEG image data, JFIF standard 1.02 358907 0x579FB JPEG image data, JFIF standard 1.02 359442 0x57C12 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 1787 bytes 361070 0x5826E LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 893 bytes 361902 0x585AE LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 637 bytes 362528 0x58820 JPEG image data, JFIF standard 1.02 363522 0x58C02 JPEG image data, JFIF standard 1.02 364963 0x591A3 JPEG image data, JFIF standard 1.01 376049 0x5BCF1 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 683 bytes 376714 0x5BF8A LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 761 bytes 377462 0x5C276 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 225 bytes 377638 0x5C326 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 4146 bytes 378953 0x5C849 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 1487 bytes 379723 0x5CB4B LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 2240 bytes 380729 0x5CF39 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 1527 bytes 381510 0x5D246 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 8294 bytes 384148 0x5DC94 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 10412 bytes 385299 0x5E113 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 16812 bytes 389806 0x5F2AE LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 9294 bytes 391417 0x5F8F9 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 9108 bytes 392764 0x5FE3C LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 4796 bytes 393633 0x601A1 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 3710 bytes 394440 0x604C8 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 7870 bytes 395948 0x60AAC LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 10764 bytes 398896 0x61630 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 6804 bytes 400960 0x61E40 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 2135 bytes 401785 0x62179 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 2864 bytes 402878 0x625BE LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 3747 bytes 404192 0x62AE0 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 2776 bytes 405196 0x62ECC LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 6761 bytes 407148 0x6366C LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 1582 bytes 407859 0x63933 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 6849 bytes 409864 0x64108 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 4678 bytes 411440 0x64730 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 11297 bytes 414011 0x6513B LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 3990 bytes 415534 0x6572E LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 12540 bytes 418894 0x6644E LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 3623 bytes 420239 0x6698F LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 13366 bytes 423782 0x67766 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 5498 bytes 425717 0x67EF5 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 1524 bytes 426450 0x681D2 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 28728 bytes 434580 0x6A194 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 18125 bytes 439538 0x6B4F2 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 36719 bytes 445116 0x6CABC LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 1940 bytes </code></pre> <p>Checking the hexdump code I found that binwalk detects the lzma magic number '5d 00' but I think that this is inconsistent and a false positive:</p> <pre><code>root@kali:~/Desktop/Firmwares/DLink# cat hexdump.txt | grep '5d 00' 00000030 5d 00 00 00 02 f0 23 0f 00 00 00 00 00 00 20 20 |].....#....... | 0000c7b0 f9 5d 00 0e e6 e7 55 ca 16 5f d1 c9 67 67 30 c7 |.]....U.._..gg0.| 00049900 ac 00 5d 00 00 00 02 c9 1d 00 00 00 00 00 00 00 |..].............| 0004a2c0 6e 93 3d d1 e8 e3 96 5a f9 17 38 b1 28 5d 00 00 |n.=....Z..8.(]..| 0004bb30 25 14 f9 96 26 85 58 20 18 07 b9 fa e3 5d 00 00 |%...&amp;.X .....]..| 0004c360 9f f6 e9 d8 28 5d 00 00 00 02 19 19 00 00 00 00 |....(]..........| 0004cbe0 f6 20 5d 00 00 00 02 36 18 00 00 00 00 00 00 00 |. ]....6........| 0004d470 3f 38 df 6f 97 98 4b 41 0d 83 14 d8 4d 00 5d 00 |?8.o..KA....M.].| 0004e000 78 c4 bc c4 11 98 56 00 5d 00 00 00 02 c3 26 00 |x.....V.].....&amp;.| 0004eb30 e6 73 64 e2 bc fa 37 7a 11 0d 3c b1 d2 af 5d 00 |.sd...7z..&lt;...].| 0004f080 57 ad 80 5f 20 ef 40 0e 7c 5d 00 00 00 02 f5 04 |W.._ .@.|]......| 0004f280 1a 1c ab 00 5d 00 00 00 02 39 26 00 00 00 00 00 |....]....9&amp;.....| 0004fd70 5d 00 00 00 02 f5 25 00 00 00 00 00 00 00 1e 12 |].....%.........| </code></pre> <p>After this I browsed the hexdump and found some strings in 00000000 and 00042fa0:</p> <pre><code>00000000 41 49 48 30 4c 0f c1 fb 80 00 01 00 00 04 2f 74 |AIH0L........./t| 00042fa0 6e 23 00 00 41 49 48 30 4c 0f c1 fb 00 00 00 00 |n#..AIH0L.......| </code></pre> <p>Googling for AIH0L I did not find anything useful and now I'm stuck.</p> <p>Other things I tried was to search bin img sqsh sq sh and other strings in the hexdump without result.</p> <p>Also the entropy analysis seems weird for me. <img src="https://i.stack.imgur.com/rSKlo.png" alt="Entropy output binwalk"></p> <p>Did anyone faced this issues or can figure out how to extract this? Regards.</p> <p><strong>EDIT:</strong> Searching for filesystems 'fs' in the hexdump file I found a zfs header:</p> <p>t@kali:~/Desktop/Firmwares/DLink# cat hexdump.txt | grep zfs</p> <pre><code>0000b990 65 a7 0c aa 7a 66 73 24 1e bc b6 e8 d7 c4 29 1a |e...zfs$......).| </code></pre> <p>I'm not sure wether this points to a real zfs or it's just a coincidence. I copied the firmware from that position to the end but the new file is not recognized and the binwalk lecture is the same as above.</p>
Reversing DLink DIR100 firmware
|firmware|
<p>Do you have md5 for the application?</p> <p>It seems like a GUI/Cocoa application. The code seems to be stuck in <code>msgloop</code>. This loop generally occurs in applications, which require user interaction or when application is interacting with messages.</p> <p>The image shows the breakpoint has been hit inside <code>__CFRunLoopRun</code>. It means app was running and processing system messages until it met a breakpoint (which is <kbd>Command</kbd>+<kbd>C</kbd>, in this case) it need some kind of user interaction or is waiting for some message, may be a click or key press or message from some system process.</p> <p>If you have the sample md5 or SHA, I can have a look at it</p>
2832
2013-09-24T21:19:16.853
<p>Currently I have a binary that I am investigating. The application is GUI / event driven, so that makes it difficult to set a break point. I would like to set a break point on a certain button click, so I thought I would click the button, and then run a <code>backtrace</code> in GDB to see what functions were called when I clicked the button, but the output of the <code>bt</code> is just showing <code>mach_msg_trap()</code>, and a few other "functions" I suppose. Does anyone know why I'm in the <code>mach_msg_trap()</code> I am assuming it's some security feature implemented by Apple to prevent people from reversing their software, I just thought I would ask, as my googlefu didn't really return any tangible results.</p> <p><img src="https://i.stack.imgur.com/ZpuXV.png" alt="Screenshot of the GDB output"></p>
Reversing a Mac OS X binary that appears to be non encrypted, backtrace just shows mach_msg_trap ()
|gdb|osx|mach-o|
<p>When looking for functions, you should always check the SDK headers. These two are listed in <code>loader.hpp</code>:</p> <pre><code>// Get offset in the input file which corresponds to the given ea // If the specified ea can't be mapped into the input file offset, // return -1. idaman int32 ida_export get_fileregion_offset(ea_t ea); // Get linear address which corresponds to the specified input file offset. // If can't be found, then return BADADDR idaman ea_t ida_export get_fileregion_ea(int32 offset); </code></pre> <p>So you can use them from IDAPython like this:</p> <pre><code>offset = idaapi.get_fileregion_offset(ea) ea = idaapi.get_fileregion_ea(offset) </code></pre> <p>NB: not all SDK functions are exposed in Python. If you absolutely need something which is only available in C API, you can <a href="http://www.hexblog.com/?p=695">use <code>ctypes</code> to call it</a>.</p>
2835
2013-09-25T13:35:02.847
<p>For every selected byte Ida Pro displays the <em>offset in the input file</em> where the byte can be found (displayed in the buttom bar of the Ida-View and the Hex-View). How can I retrieve this information when using the idapython API?</p>
How to extract the input file offset of a byte in idapython?
|ida|idapython|
<p>The reason is for loading performance - the jumps are gathered into a single region that is made temporarily writable for the purpose of placing the API addresses, and is usually only a single page in size. This avoids multiple calls to VirtualProtect() by the loader, in order to write all over the code space to every reference to any given API.</p>
2857
2013-09-29T15:53:39.220
<p>I am trying to analyze an old malware sample in OllyDbg. It has instruction of the format <code>CALL &lt;JMP.&amp;KERNEL32.SetUnhandledExceptionFilter&gt;</code></p> <p>I am not an expert in Assembly. I know that CALL is used to call a sub-routine and JMP is used to jump to a particular address in the memory but what is the result of using CALL with JMP? Could anyone clarify on it? Even pointers to where I could find answers would be very helpful. Thanks.</p>
Why is JMP used with CALL?
|disassembly|malware|assembly|
<p>There's a nice blog entry on it here: <a href="http://www.singlehop.com/blog/binary-vivisection-part-1/" rel="nofollow">http://www.singlehop.com/blog/binary-vivisection-part-1/</a></p> <blockquote> <p>...</p> <p>While looking over the changelog and documentation, I realized that there doesn’t really seem to be a good tutorial or primer for getting familiar with the <strong>Vivisect</strong> framework so hopefully we can remediate that today. In this series, we’ll be covering the usage of VDB (dynamic debugging component) and <strong>vivisect</strong> (static analysis tool).</p> <p>...</p> </blockquote> <p>You can also see the <code>README</code> file <a href="https://code.google.com/p/vtrace-mirror/source/browse/trunk/README-vivisect" rel="nofollow">here</a>, and some related scripts <a href="https://github.com/pdasilva/vtrace_scripts" rel="nofollow">here</a>.</p>
2862
2013-09-30T14:15:16.893
<p>Where can I find some resources to start learning about vivisect? Blog posts, presentations, PDFs, code examples, anything would be appreciated.</p> <p>I am aware I can read the code but before doing that I would like to have something to get me started.</p>
vtrace / vivisect resources
|python|dynamic-analysis|static-analysis|
<h2>System calls through <code>sysenter</code></h2> <p><code>sysenter</code> is a i586 instruction, specifically tight to 32-bits applications. It has been subsumed by <code>syscall</code> on 64-bits plateforms.</p> <p>One particularity of <code>sysenter</code> is that it does require, in addition to the usual register setting, a few manipulations on the stack before calling it. This is because before leaving <code>sysenter</code>, the process will go through the last part of the <code>__kernel_vsyscall</code> assembler snippet (starting from <code>0xf7ffd430</code>):</p> <pre><code>Dump of assembler code for function __kernel_vsyscall: 0xf7ffd420 &lt;+0&gt;: push %ecx 0xf7ffd421 &lt;+1&gt;: push %edx 0xf7ffd422 &lt;+2&gt;: push %ebp 0xf7ffd423 &lt;+3&gt;: mov %esp,%ebp 0xf7ffd425 &lt;+5&gt;: sysenter 0xf7ffd427 &lt;+7&gt;: nop 0xf7ffd428 &lt;+8&gt;: nop 0xf7ffd429 &lt;+9&gt;: nop 0xf7ffd42a &lt;+10&gt;: nop 0xf7ffd42b &lt;+11&gt;: nop 0xf7ffd42c &lt;+12&gt;: nop 0xf7ffd42d &lt;+13&gt;: nop 0xf7ffd42e &lt;+14&gt;: int $0x80 =&gt; 0xf7ffd430 &lt;+16&gt;: pop %ebp 0xf7ffd431 &lt;+17&gt;: pop %edx 0xf7ffd432 &lt;+18&gt;: pop %ecx 0xf7ffd433 &lt;+19&gt;: ret End of assembler dump. </code></pre> <p>So, the <code>sysenter</code> instruction expect to have the stack forged in that way:</p> <pre><code>0x______0c saved_eip (ret) 0x______08 saved_%ecx (pop %ecx) 0x______04 saved_%edx (pop %edx) 0x______00 saved_%ebp (pop %ebp) </code></pre> <p>That's why, each time we need to call <code>sysenter</code>, we first have to push the values of the saved <code>%eip</code>, and the same with<code>%ecx</code>, <code>%edx</code> and <code>%ebp</code>. Which leads to:</p> <pre><code>.data msg: .ascii "Hello World!\n" len = . - msg .text .globl _start _start: pushl %ebp movl %esp, %ebp # Write the string to stdout movl $len, %edx movl $msg, %ecx movl $1, %ebx movl $4, %eax # Setting the stack for the systenter pushl $sysenter_ret pushl %ecx pushl %edx pushl %ebp movl %esp,%ebp sysenter # and exit sysenter_ret: movl $0, %ebx movl $1, %eax # Setting the stack for the systenter pushl $sysenter_ret # Who cares, this is an exit ! pushl %ecx pushl %edx pushl %ebp movl %esp,%ebp sysenter </code></pre>
2869
2013-10-02T18:33:00.043
<p>I would like to know what are the different ways to perform a system call in x86 assembler under Linux. But, with no cheating, only assembler must be used (i.e. compilation with <code>gcc</code> must be done with <code>-nostdlib</code>).</p> <p>I know four ways to perform a system calls, namely:</p> <ul> <li><code>int $0x80</code></li> <li><code>sysenter</code> (i586)</li> <li><code>call *%gs:0x10</code> (vdso trampoline)</li> <li><code>syscall</code> (amd64)</li> </ul> <p>I am pretty good at using <code>int $0x80</code>, for example, here is a sample code of a classic 'Hello World!' in assembler using <code>int $0x80</code> (compile it with <code>gcc -nostdlib -o hello-int80 hello-int80.s</code>):</p> <pre><code>.data msg: .ascii "Hello World!\n" len = . - msg .text .globl _start _start: # Write the string to stdout movl $len, %edx movl $msg, %ecx movl $1, %ebx movl $4, %eax int $0x80 # and exit movl $0, %ebx movl $1, %eax int $0x80 </code></pre> <p>But the <code>sysenter</code> is often ending with a segmentation fault error. Why ? And, how to use it right ?</p> <p>Here is an example with <code>call *%gs:0x10</code> (compiled with <code>gcc -o hello-gs10 hello-gs10.s</code>). Note that I need to go through the <code>libc</code> initialization before calling it properly (that is why I am using <code>main</code> and not anymore <code>_start</code> and, that is also why I removed the option <code>-nostdlib</code> from the compile line):</p> <pre><code>.data msg: .ascii "Hello World!\n" len = . - msg .text .globl main main: # Write the string to stdout movl $len, %edx movl $msg, %ecx movl $1, %ebx movl $4, %eax call *%gs:0x10 # and exit movl $0, %ebx movl $1, %eax call *%gs:0x10 </code></pre> <p>Also, the <code>syscall</code> is working pretty well also if you know the <a href="http://lxr.linux.no/#linux+v2.6.32/arch/x86/include/asm/unistd_64.h">syscall codes for this architecture</a> (thanks to lfxgroove) (compiled with: <code>gcc -m64 -nostdlib -o hello-syscall hello-syscall.s</code>):</p> <pre><code>.data msg: .ascii "Hello World!\n" len = . - msg .text .globl _start _start: # Write the string to stdout movq $len, %rdx movq $msg, %rsi movq $1, %rdi movq $1, %rax syscall # and exit movq $0, %rdi movq $60, %rax syscall </code></pre> <p>So, the only problem I have to trigger a system call is this <code>sysenter</code> way. Here is an example with <code>sysenter</code> ending with a segmentation fault (compiled with <code>gcc -m32 -nostdlib -o hello-sysenter hello-sysenter.s</code>):</p> <pre><code>.data msg: .ascii "Hello World!\n" len = . - msg .text .globl _start _start: # Write the string to stdout movl $len, %edx movl $msg, %ecx movl $1, %ebx movl $4, %eax push final sub $12, %esp mov %esp, %ebp sysenter # and exit final: movl $0, %ebx movl $1, %eax sub $12, %esp mov %esp, %ebp sysenter </code></pre>
How to use sysenter under Linux?
|assembly|x86|
<p>Another reason for NOP insertion is due to pipeline scheduling. If it takes a cycle for branch prediction to determine whether it was correct or not (and if not to flush the pipe), then you'd need a cycle delay before results are committed to registers.</p> <p>Regarding the specific example where the jump equal goes to a NOP, it appears to me that the processor needs a cycle to determine whether it got the right answer or not and adjust the pipe as necessary. </p> <p>Great job digging in to the code and understanding what is going on. :)</p>
2876
2013-10-03T21:28:22.077
<p>So I have the following C code I wrote:</p> <pre><code>#include &lt;stdio.h&gt; int main() { int i = 1; while(i) { printf("in loop\n"); i++; if(i == 10) { break; } } return 0; } </code></pre> <p>Compiled with gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2 it disassembles to this:</p> <pre><code> 0x000000000040051c &lt;+0&gt;: push %rbp 0x000000000040051d &lt;+1&gt;: mov %rsp,%rbp 0x0000000000400520 &lt;+4&gt;: sub $0x10,%rsp 0x0000000000400524 &lt;+8&gt;: movl $0x1,-0x4(%rbp) 0x000000000040052b &lt;+15&gt;: jmp 0x400541 &lt;main+37&gt; 0x000000000040052d &lt;+17&gt;: mov $0x400604,%edi 0x0000000000400532 &lt;+22&gt;: callq 0x4003f0 &lt;puts@plt&gt; 0x0000000000400537 &lt;+27&gt;: addl $0x1,-0x4(%rbp) 0x000000000040053b &lt;+31&gt;: cmpl $0xa,-0x4(%rbp) 0x000000000040053f &lt;+35&gt;: je 0x400549 &lt;main+45&gt; 0x0000000000400541 &lt;+37&gt;: cmpl $0x0,-0x4(%rbp) 0x0000000000400545 &lt;+41&gt;: jne 0x40052d &lt;main+17&gt; 0x0000000000400547 &lt;+43&gt;: jmp 0x40054a &lt;main+46&gt; 0x0000000000400549 &lt;+45&gt;: nop 0x000000000040054a &lt;+46&gt;: mov $0x0,%eax 0x000000000040054f &lt;+51&gt;: leaveq 0x0000000000400550 &lt;+52&gt;: retq </code></pre> <p>Why is there a <code>nop</code> on +45? And why does not <code>je</code> on +35 just jump right to +46?</p>
Why is there in a nop in the while loop
|disassembly|
<p>Have a look at <a href="https://reverseengineering.stackexchange.com/a/267/225">this answer</a>. It includes beginner malware training videos.</p> <p>Not familiar with malware myself, I do often see the following books recommended in answers:</p> <ul> <li><p><a href="http://rads.stackoverflow.com/amzn/click/0470613033" rel="nofollow noreferrer">Malware Analyst's Cookbook</a></p> <blockquote> <p>Security professionals will find plenty of solutions in this book to the problems posed by viruses, Trojan horses, worms, spyware, rootkits, adware, and other invasive software. Written by well-known malware experts, this guide reveals solutions to numerous problems and includes a DVD of custom programs and tools that illustrate the concepts, enhancing your skills.</p> </blockquote></li> <li><p><a href="http://rads.stackoverflow.com/amzn/click/1593272901" rel="nofollow noreferrer">Practical Malware Analysis: The Hands-On Guide to Dissecting Malicious Software</a></p> <blockquote> <p>For those who want to stay ahead of the latest malware, Practical Malware Analysis will teach you the tools and techniques used by professional analysts. With this book as your guide, you'll be able to safely analyze, debug, and disassemble any malicious software that comes your way.</p> </blockquote></li> </ul> <p>Keeping an eye on <a href="http://www.reddit.com/r/malware" rel="nofollow noreferrer">/r/Malware</a> over at Reddit can also be a good idea. It's a place where allot of analysis reports are posted. Which you can look at as small tutorials.</p> <p>-edit-</p> <p>Another source I remembered is: <a href="http://fumalwareanalysis.blogspot.nl/p/malware-analysis-tutorials-reverse.html" rel="nofollow noreferrer">Dr. Fu's Malware analysis tutorials</a></p> <blockquote> <p>It describes building and configuring a malware lab using virtual machines and then continues analyzing a real piece of malware.</p> </blockquote>
2881
2013-10-04T03:14:39.533
<p>I would like learn how to reverse engineer malwares. I have a very small experience reverse engineering windows applications. I would like to know if there are good resources that is helpful in learning this. </p>
Intro to reverse engineering
|malware|
<p>I recommend You to start from basics, so:</p> <ol> <li><p><a href="http://technet.microsoft.com/en-us/sysinternals/bb963901%28v=msdn.10%29.aspx" rel="nofollow">"Windows Internals"</a> by Mark Russinovich and David Solomon is a good start for hard copy book.</p></li> <li><p><a href="http://opensecuritytraining.info/Training.html" rel="nofollow">OpenSecurityTraining</a> - start from Beginner's courses by interest</p></li> </ol> <p>When You done with those - I am sure You'll be able to ask more specific questions and get more detailed and sophisticated answers. Good luck!</p>
2887
2013-10-05T19:36:21.723
<p>I have just started my journey into the vast and intersting field of malware analysis. I would like to know if there is any website/book or another resource that explains what a particular block of assembly code does. A detailed description of the code would be well appreciated. I know assembly language to some extent and is familiar with all the concepts,function call procedure etc. But i have very little knowledge on how all these applies when it come to windows. like what happens when a dll is used,etc... I would be very glad if someone could tell me where to find a resource that provides a step by step detailed analysis of any malware or any program for that matter.</p> <p>I have already a considerable experience in reverse engineering windows applications, most of the knowledge been taken from the 'legend of r4ndom' and woodman websites. I need something that clearly explains how a particular assembly code interacts with windows dlls, resources like menu bars text boxes, etc..</p>
Detailed description of malware content
|malware|
<p>Delphi implements <code>try</code>/<code>except</code>/<code>finally</code> by using Win32 Structured Exception Handlers (SEH). The basics of SEH are explained in the <a href="http://www.microsoft.com/msj/0197/Exception/Exception.aspx" rel="noreferrer">classic article by Matt Pietrek</a>, so I'll skip to the details relevant to Delphi only.</p> <h1>1. <code>try</code> entry</h1> <p>Entry to a <code>try</code> block, or a block which protects automatic variables that need to be destructed on exit (such as strings) looks like the following:</p> <pre><code>xor eax, eax push ebp push offset SEH_HANDLER push dword ptr fs:[eax] mov fs:[eax], esp </code></pre> <p>This is a typical way of setting up a SEH frame. After it's run, top of the stack will look like this:</p> <pre><code> +-----------+ ESP+00 | next | &lt;- fs:[0] points here +-----------+ ESP+04 | handler | +-----------+ ESP+08 | saved_ebp | +-----------+ </code></pre> <p>The pointer to this structure will be passed to the SEH handler.</p> <h1>2. <code>try</code> exit</h1> <p>At the end of the <code>try</code> block, the SEH frame is torn down:</p> <pre><code> xor eax, eax pop edx ; pop 'next' into edx pop ecx ; pop handler pop ecx ; pop saved_ebp mov fs:[eax], edx ; move 'next' into fs:[0] </code></pre> <p>If there is a <code>finally</code> handler or automatic destructors, then it continues like this:</p> <pre><code> push offset AFTER_TRY ; make it so the 'ret' will jump to AFTER_TRY FINALLY_HANDLER: &lt;destruct automatic variables created in the try block&gt; &lt;finally handler body&gt; ret ; jumps to AFTER_TRY </code></pre> <p>Otherwise there is a simple jump:</p> <pre><code> jmp AFTER_TRY </code></pre> <h1>3. <code>finally</code> handler</h1> <p>In case the program use <code>finally</code> statement, or in case of the <code>try..finally</code> added by the compiler to guard automatic variables, the SEH handler looks like this:</p> <pre><code>SEH_HANDLER: jmp _HandleFinally jmp FINALLY_HANDLER </code></pre> <h1>4. <code>except</code> handler</h1> <p>If the program uses an <code>except</code> handler to catch all exceptions, the code looks a little different:</p> <pre><code>SEH_HANDLER: jmp _HandleAnyException &lt;handler code&gt; call _DoneExcept </code></pre> <h1>5. <code>except on</code> handlers</h1> <p>If the program uses <code>except on...</code> to match the exception(s) being caught, the compiler generates a table of one or more possible exception classes with corresponding handlers:</p> <pre><code>SEH_HANDLER: jmp _HandleOnException dd &lt;numExceptions&gt; dd offset ExceptionClass1 dd offset OnException1_handler dd offset ExceptionClass2 dd offset OnException2_handler &lt;...&gt; OnException1_handler: &lt;handler code&gt; call _DoneExcept OnException2_handler: &lt;handler code&gt; call _DoneExcept </code></pre> <p>There may be some variations, but I think I covered most of it.</p> <p>The source code of <code>_HandleFinally</code>, <code>_HandleAnyException</code>, <code>_HandleOnException</code>, <code>_DoneExcept</code> and a few other exceptions-related functions can be found in <code>system.pas</code> in the VCL sources.</p>
2895
2013-10-06T23:42:28.683
<p>I'm having trouble reverse-engineering a specific Delphi Pascal .exe (old vsn., pre-1995 so probably v.3). From the system calls I understand this is <em>probably</em> a <code>try..except..finally</code> block, but I am at a loss finding the 'normal' route through the code, and what the <code>except</code> and (possibly) <code>finally</code> blocks are.</p> <p>The assembly looks like this:</p> <pre><code>782CFC 33 C0 xor eax, eax 782CFE 55 push ebp 782CFF 68 (782E37) push _FINALLY_A_0_782E37 782D04 64 FF 30 push dword ptr fs:[eax] 782D07 64 89 20 mov dword ptr fs:[eax], esp _try_0_782D0A: 782D0A 8B D3 mov edx, ebx 782D0C 8B C6 mov eax, esi 782D0E E8 D1 F3 FF FF call ...unrelated... 782D13 8D 56 1C lea edx, [esi+1Ch] .. lots of regular code here .. .. ending with .. 782E17 8B 18 mov ebx, dword ptr [eax] 782E19 FF 53 20 call dword ptr [ebx+20h] finally_1_782E1C: 782E1C 33 C0 xor eax, eax 782E1E 5A pop edx 782E1F 59 pop ecx 782E20 59 pop ecx 782E21 64 89 10 mov dword ptr fs:[eax], edx 782E24 68 (782E3E) push _end_1_782E3E @block_L: 782E29 8D 45 F4 lea eax, [ebp + local_0C] 782E2C BA 02 00 00 00 mov edx, 2 782E31 E8 12 E3 F7 FF call System.@LStrArrayClr 782E36 C3 retn _FINALLY_A_0_782E37: 782E37 E9 B4 E2 F7 FF jmp System.@HandleFinally _FINALLY_B_0_782E3C: 782E3C EB EB jmp @block_L ; ------- _end_1_782E3E: 782E3E 5F pop edi 782E3F 5E pop esi 782E40 5B pop ebx 782E41 8B E5 mov esp, ebp 782E43 5D pop ebp 782E44 C3 retn </code></pre> <p>-- this is output from my own disassembler, but I don't think there are errors in it. The labels have been auto-named, but I still cannot follow the 'logic' (if any) from one block to the next. In particular, the bottom half, right before the function epilogue, confuses me.</p> <p>Are these fragments enough to reconstruct the original <code>try</code>..<code>finally</code> blocks?</p> <hr> <p>After reading Igor's answer: yes they are. Consider these flowcharts: left, original before special handling of try/finally blocks, right, afterwards.</p> <p><img src="https://i.stack.imgur.com/1B6lK.png" alt="flowcharts"></p> <p>In the original flowchart, I considered every jump from one basic block to another as a <em>link</em>, and the code flow stops at every <code>retn</code>. <code>if</code> (E-(F)-K) and <code>if-else</code> (G-H/I-J) structures can clearly be discerned. However, pushing return addresses and the other 'tricks' of exception handling, defeat this, as can be seen by the dangling blocks N and O -- they 'enter' from nowhere --, and a separate block 'M' which comes and goes from nowhere.</p> <p>At the right, I separated the <em>initialization</em> of the exception block from the main code (adding a new block B), and concatenated the <em>finalize</em> structure into one single new block (M), which ultimately jumps to an AFTER_TRY (which happened to be the last <em>Exit</em> block). Now it's clear that</p> <ol> <li>right after the prologue, a <code>try</code> is initiated;</li> <li>all code ends up at the <code>finally</code> block M, which</li> <li>then always exists the code at a single fixed point.</li> </ol>
Delphi Pascal Try..Except..Finally block
|disassembly|decompilation|
<p>Two additional methods that haven't been mentioned yet.</p> <p><code>binwalk</code>'s disassembly scan (note: <a href="https://github.com/ReFirmLabs/binwalk/blob/master/INSTALL.md#dependencies" rel="nofollow noreferrer">must have <code>capstone</code> installed</a>)</p> <pre><code>Disassembly Scan Options: -Y, --disasm Identify the CPU architecture of a file using the capstone disassembler -T, --minsn=&lt;int&gt; Minimum number of consecutive instructions to be considered valid (default: 500) -k, --continue Don't stop at the first match </code></pre> <p>Example output (image is ARM LE):</p> <pre><code>$ binwalk -Yk image.img DECIMAL HEXADECIMAL DESCRIPTION -------------------------------------------------------------------------------- 3 0x3 ARM executable code, 32-bit, big endian, at least 726 valid instructions 1048576 0x100000 ARM executable code, 32-bit, little endian, at least 1250 valid instructions 2099012 0x200744 ARM executable code, 32-bit, little endian, at least 846 valid instructions 3158316 0x30312C ARM executable code, 32-bit, little endian, at least 899 valid instructions 4201328 0x401B70 ARM executable code, 32-bit, little endian, at least 1250 valid instructions 5253066 0x5027CA ARM executable code, 16-bit (Thumb), big endian, at least 2499 valid instructions 6308406 0x604236 ARM executable code, 16-bit (Thumb), little endian, at least 2499 valid instructions </code></pre> <p><a href="https://github.com/airbus-seclab/cpu_rec" rel="nofollow noreferrer"><code>cpu_rec</code></a></p> <p>Can be used as either a standalone tool or a <code>binwalk</code> module.</p> <p><code>binwalk</code> usage:</p> <pre><code>Statistical CPU guessing Options: -%, --markov Identify the CPU opcodes in a file using statistical analysis </code></pre> <p>Example output, used as a binwalk module (image is ARM LE):</p> <pre><code>$ binwalk -% image.img DECIMAL HEXADECIMAL DESCRIPTION -------------------------------------------------------------------------------- 0 0x0 None (size=0x800, entropy=0.757822) 2048 0x800 CLIPPER (size=0x800, entropy=0.728492) 4096 0x1000 None (size=0x2000, entropy=0.129643) 12288 0x3000 ARMel (size=0x35c000, entropy=0.795123) 3534848 0x35F000 None (size=0x800, entropy=0.797443) 3536896 0x35F800 ARMel (size=0x16800, entropy=0.834972) 3629056 0x376000 None (size=0x800, entropy=0.764094) 3631104 0x376800 ARMel (size=0x16a000, entropy=0.797543) 5113856 0x4E0800 None (size=0x1800, entropy=0.841936) 5120000 0x4E2000 ARMel (size=0x1000, entropy=0.812677) 5124096 0x4E3000 None (size=0x1000, entropy=0.844949) 5128192 0x4E4000 ARMel (size=0xc000, entropy=0.792995) 5177344 0x4F0000 None (size=0x24000, entropy=0.763681) 5324800 0x514000 6502 (size=0x24000, entropy=0.974422) 5472256 0x538000 None (size=0x137800, entropy=0.728785) </code></pre>
2897
2013-10-08T11:41:41.500
<p>Assuming that I have binary file with code for an unknown CPU, can I somehow detect the CPU architecture? I know that it depends mostly on the compiler, but I think that for most CPU architectures it should be a lot of CALL/RETN/JMP/PUSH/POP opcodes (statistically more than others). Or maybe should I search for some patterns in code specific for a particular CPU (instead of opcode occurrences)?</p>
Tool or data for analysis of binary code to detect CPU architecture
|binary-analysis|
<p>It has the fingerprint of an <code>assert</code>:</p> <ol> <li>it's called directly after a test;</li> <li>it uses a number -- probably a <em>source line number</em> --, a string which points to a file name -- the <em>source file</em> -- and a string that describes an error condition;</li> <li>it does not return. (Can be inferred because the inspected value would lead to an erronous situation if the called function returned.)</li> </ol> <p><code>assert</code> is a standard function in most (if not outright all!) standard libraries, and so if your decompiler could recognize which compiler was used, it would have assigned a standard label to <code>sub_6E0D40</code>. Since it didn't, you could trace that address and see if (a) it jumps immediately to an external routine such as Windows' native <code>Assert</code>, or (b) does what an assert does: outputting the error and immediately exiting.</p> <hr> <p>Addition: using the stack plus registers ecx and edx seem to indicate this sub is declared "Microsoft <code>__fastcall</code>" (<a href="http://en.wikipedia.org/wiki/X86_calling_conventions#Microsoft_fastcall">wikipedia</a>).</p>
2904
2013-10-09T19:39:24.000
<p>This C++ binary has code snippets and paths to sourcecode files everywhere, which is probably some sort of debug info. </p> <ul> <li>Is this something standard? (Is this RTTI)</li> <li>If so, how is this called?</li> <li>Are there plugins/tools to help with this?</li> </ul> <p><img src="https://i.stack.imgur.com/YYXtD.png" alt="IDA Screenshot of debug info"></p>
Are those code snippets and file paths in a C++ binary some sort of standard debug information?
|ida|c++|debugging-symbols|
<p>for completeness, implementing <code>get_frame_retsize</code> [<code>int (*get_frame_retsize(func_t *pfn)</code>] in your <code>processor_t LPH</code> is the solution to this.</p> <p>in that function for my processor I needed to return zero instead of the default of 4.</p>
2907
2013-10-10T04:08:40.120
<p>Original question asked on Stackoverflow: <a href="https://stackoverflow.com/questions/14976139/can-the-r-be-removed-from-a-function-stack">Can the 'r' be removed from a function stack ?</a></p> <p>I am trying to modify the processor for the Fujitsu FR, and IDA by default inserts the return variable <code>r</code> on each stack, but the Fujitsu FR processor does not put <code>r</code> as the first item, so this stuffs up the stack.</p> <p>What I can't workout is: in the processor plugin, what needs overriding to resolve this, or if any of the example processors have solutions to copy. </p>
Can the 'r' be removed from a function stack
|ida|
<p>If you look at the disassembly of authorize() I'm sure you'll find that the compiler is pushing and restoring more registers than just EBP or aligning the stack. I would recommend that you always look at the disassemly when dealing with overflows of various kinds. The compiler and decompiler, if you use one, hides a lot of details. The disassembly never lies and allows you to make a prediction without resorting to dynamic analysis. I'm a strong proponent of learning with static methods when you're just starting out.</p> <p>Anyways, whether there's more registers, a stack canary, stack alignment or something else, the disassembly of authorize() will reveal the answer to your question.</p> <p>For your reference this is the dissembly of the authorize() function using GCC 4.7.3 with -O2.</p> <pre> push ebx sub esp, 58h lea ebx, [esp+5Ch+password] mov [esp+5Ch+arg0], "Escriba la contrase" call _printf mov [esp+5Ch+arg0], ebx call _gets mov eax, secret mov [esp+5Ch+arg0], ebx mov [esp+5Ch+arg1], eax call _strcmp test eax, eax setz al add esp, 58h movzx eax, al pop ebx retn </pre> <p>You'll notice that it doesn't use push to move arguments, ebp is unused as a stack frame and the compiler aligns the stack since sum of stack changes is 0x60; return value misaligns by 4, push ebx by 4 more, then sub esp, 0x58 results in 0x60.</p>
2911
2013-10-12T14:54:51.987
<p>some days ago I took this piece of code from opensecuritytraining.info to test a buffer overflow exploitation:</p> <pre><code>#include &lt;stdio.h&gt; char *secret = "pepito"; void go_shell(){ char *shell = "/bin/sh"; char *cmd[] = { "/bin/sh", 0 }; printf("¿Quieres jugar a un juego?...\n"); setreuid(0); execve(shell,cmd,0); } int authorize(){ char password[64]; printf("Escriba la contraseña: "); gets(password); if (!strcmp(password,secret)) return 1; else return 0; } int main(){ if (authorize()){ printf("Acceso permitido\n"); go_shell(); } else{ printf("Acceso denegado\n"); } return 0; } </code></pre> <p>The first test before injecting a shellcode was trying to execute the go_shell function without knowing the password, overflowing the return address of main function and pointing it to the location of go_shell.</p> <p>As far as I understand the stack is divided as below:</p> <pre><code>[STACK] {Return_address}{EBP}{password_buffer(64)}... </code></pre> <p>So If I store in password_buffer 68 bytes plus the address of go_shell it should overwrite the return address and execute the desired function.</p> <pre><code>[STACK] {4bytes (Location of go_shell)}{EBP(4 Bytes of junk)}{password_buffer(64)(64 bytes of junk)}... </code></pre> <p>The problem here is that I need to fill the buffer with 76 bytes of junk plus 4 bytes of the address to actually override the return address and point %eip to go_shell. What I don't understand is where do those additional 8 bytes come from?</p> <p>This is the GDB output before injecting 74 A (0x41) + the address in a breakpont at line if (!strcmp(password,secret)):</p> <pre><code>EBP: 0xbffff4a8: 0x41414141 0x0804851c AAAA + memory_address </code></pre> <p>And continuing to go_shell execution (Breakpoint at void go_shell(){ ):</p> <p>EIP now points to the last return address overwrited:</p> <pre><code>(gdb) x/2x $eip 0x804851c &lt;go_shell&gt;: 0x83e58955 0x45c728ec </code></pre> <p>Any help understanding this?</p> <p>Regards.</p>
Understanding this Buffer Overflow exploitation
|c|exploit|buffer-overflow|
<p>As everybody else is saying, in this case it is due to linear sweep. However, I would like to add that even IDA can be fooled with Junk Bytes and you can only trust the disassembly while debugging a sample. As encoders can change the code on the run, only trust the value on the EIP and nothing else to be correct code.</p>
2917
2013-10-15T19:49:10.320
<p>When using objdump I see the following disassembled code:</p> <pre><code>8049436: 89 04 24 mov DWORD PTR [esp],eax 8049439: e8 52 f7 ff ff call 8048b90 &lt;gtk_entry_get_text@plt&gt; 804943e: 89 44 24 24 mov DWORD PTR [esp+0x24],eax 8049442: eb 01 jmp 8049445 &lt;gtk_grid_new@plt+0x6c5&gt; 8049444: 1d c7 04 24 0b sbb eax,0xb2404c7 8049449: 00 00 add BYTE PTR [eax],al 804944b: 00 e8 add al,ch 804944d: 0f f7 ff maskmovq mm7,mm7 8049450: ff eb jmp &lt;internal disassembler error&gt; </code></pre> <p>This is using an obfuscation technique to make the disassembling harder. When I check in gdb I see the real code at 0x8049445:</p> <pre><code>(gdb) &gt; x/10i 0x8049445 0x8049445: mov DWORD PTR [esp],0xb 0x804944c: call 0x8048b60 &lt;raise@plt&gt; 0x8049451: jmp 0x8049454 0x8049453: sbb eax,0xfff8a7e8 </code></pre> <p>Now, my question is: is it possible to tell objdump that the byte at 0x8049444 can be ignored for the purpose of disassembly? One obvious way is to actually patch the file, but is there another way?</p> <p>And if not with objdump, are there other tools that can do that? Though I'd rather stay with the basic tools included with Linux so as to familiarize myself with those better.</p>
Deal with obfuscated assembly
|disassembly|obfuscation|objdump|
<p><strong>TL;DR</strong> you can call anything, locating the right part of code is the hard part.</p> <h1>export table</h1> <p>If you mean 'just as Windows does', then you mean the functions of the DLL that are available to the others, ie the exported ones? in this case, you need to parse the export table - check <a href="http://code.google.com/p/pefile/source/browse/trunk/pefile.py#3349" rel="noreferrer">pefile</a> for a readable and reliable implementation.</p> <h1>locating any function</h1> <h2>IDA</h2> <p>If you actually mean 'all the functions, including the internal ones', then you need to disassemble and tell the difference from code and data. in this case, your best bet is to open the files in IDA - with symbols preferrably - and export the function list.</p> <h2>manually</h2> <p>If you want to do that manually, then you need your own smart disassembler, which is far from trivial: sometimes, compilers generate some code that doesn't immediately look like parts of a function.</p> <h2>calling identified functions</h2> <p>Once you've located the functions, you can just call them directly, without the need of injection, but you have to make sure you have the exact same version of the DLL. <a href="https://code.google.com/p/corkami/source/browse/trunk/src/PE/hard_imports.asm" rel="noreferrer">hard_imports</a> use such a method to call pieces of code directly.</p>
2928
2013-10-17T20:37:13.847
<p>I am trying to do some experimenting with certain system files (DLLs, EXEs) in Windows and would like to know how I can get information about the functions that they contain. I want to be able to call some of them just as if Windows does. How could one do this? </p> <p>I guess I would need to know what the function names are, and how to call the functions by their names, and what parameters to pass.</p>
How can I locate exported functions of an EXE or DLL?
|windows|pe|c++|symbols|
<p>You can create a free-form comment mentioning "004A3390" at 004A3F07. Anything that remotely resembles a valid reference is clickable in IDA Pro. Double-clicking 004A3390 in your comment will take you to the location.</p>
2931
2013-10-20T08:37:05.090
<p>I have an indirect call to a function. I traced the program and added the target to the xref, so this works fine. The problem is though, that on the position where the call is, there is no link shown. I thought, that, when I add an XREF, both positions are shown, because this is also the behaviour with the other referenzes, IDA automatically finds out.</p> <p>To illustrate what I mean:</p> <p>The call is here without showing me where it points to:</p> <pre><code>CODE:004A3F07 00C call dword ptr [edx+28h] </code></pre> <p>The xref I added is here showing the link:</p> <pre><code>CODE:004A3390 DecryptMemory proc near ; CODE XREF: sub_4A3EC0:loc_4A3F07 P </code></pre> <p>Is it possible to make IDA show the reference on both addresses? I know I can create a manual xref there as well, but then IDA creates a label as well, which makes it a bit confusing, when revisting. I tried to remove the label, but this doesn't work either (would this be possible?).</p>
Adding Backlink for XREF in IDA
|ida|
<p>You may want to perform <a href="https://en.wikipedia.org/wiki/Automatic_baud_rate_detection" rel="nofollow">Automatic baud rate detection</a></p> <p>There are a couple of projects on github that implement these such as BAUD RATE RS232 DETECTOR EXAMPLE for atmega8</p> <p>You may also want to use <a href="https://github.com/cyphunk/RS232enum" rel="nofollow">RS232enum</a> that uses Arduino to try to enumerate all serial lines (RX/TX).</p>
2933
2013-10-20T22:48:01.153
<p>How can i determine the serial protocol of a electric typewriter? some electric typewriters have a serial port in the back and it is a shape that is not commonly used today. I am planing on interfacing the typewriter with a Arduino and using it as a printer.</p> <p>How do i determine things such as the baud rate, the pinout and the voltage. I already broke one typewriter trying to find out the protocol, I cannot get a owners manual for the typewriters, all of the other guides that i found involved modifying the circuit board and connecting the wires to the keys. I have not been able to find out how a a typewriter with a serial port works.</p> <p>Here is a picture of the serial port, what type is it?</p> <p><img src="https://i.stack.imgur.com/wr9sP.jpg" alt="enter image description here"></p>
Determining the serial port protocol of a typewriter
|hardware|serial-communication|
<p>The type of encoding is Base64 encoding.</p> <pre><code>$ echo MDQwNTA2MjlD | base64 -d 04050629C $ echo SDEzMTUwMTU0NzExQTEx | base64 -d H13150154711A11 </code></pre>
2940
2013-10-24T08:25:38.220
<p>I am currently looking at a TIFF file generated by a microscope vendor. They store an XML within the TIFF (ImageDescription tag). Within this XML I can find a <code>&lt;barcode&gt;</code> element. But instead of storing the actual barcode (PDF417, DataMatrix) value, they store something else.</p> <p>I have three samples, first one is a PDF417, the last two are DataMatrix. Decoding the values leads to:</p> <ol> <li><code>04050629C</code></li> <li><code>H13150154711A11</code></li> <li><code>H13150154512A02</code></li> </ol> <p>while the XML element <code>&lt;barcode&gt;</code> contains (in that order):</p> <ol> <li><code>MDQwNTA2MjlD</code></li> <li><code>SDEzMTUwMTU0NzExQTEx</code></li> <li><code>SDEzMTUwMTU0NTEyQTAy</code></li> </ol> <p>What type of encoding is this ?</p>
Storing barcodes as ASCII
|encodings|
<p>Below are two functions from <a href="https://bitbucket.org/Alexander_Hanel/fwrapper/src/" rel="nofollow">fwrapper</a> that give examples on how to patch IDBs and import data from a file. I'd recommend checking out the code. I use it all the time for samples that decodes/decrypts data or when I have to manually dump a block of memory and patch an IDB.</p> <pre><code>def patch(self, temp = None): '''patch idb with data in fwrapper.buffer''' if temp != None: self.buffer = temp for index, byte in enumerate(self.buffer): PatchByte(self.start+index, ord(byte)) def importb(self): '''import file to save to buffer''' fileName = AskFile(0, "*.*", 'Import File') try: self.buffer = open(fileName, 'rb').read() except: sys.stdout.write('ERROR: Cannot access file') </code></pre>
2943
2013-10-24T09:15:59.983
<p>Is it possible to paste a series of bytes into hex view of IDA? Say I have a large buffer I need to fill with a specific value, and I have it in the form most hex editors output... 0A AB EF FF 00 01... is there some quick way to write this value to a segment of the hex view? Or do this through IDAPython?</p> <p><strong>Edit:</strong></p> <p>Solved using PatchByte as suggested below:</p> <pre><code>def PatchArr(dest, str): for i, c in enumerate(str): idc.PatchByte(dest+i, ord(c)); # usage: patchArr(start address, string of bytes to write) patchArr(0xCAFEBABE, "\x01\x02\x03") </code></pre> <p>Note that I am not a fan of edits to volatile debug memory causing IDA to complain about the IDB being patched post-debug...</p>
Paste hex bytes into IDA Pro Hex View
|ida|python|idapython|hex|memory|
<p>If "something like wi-fi" means it's radio but not really 802.11, you might want to take a look at Software Defined Radio projects. As the question isn't really clear, your mileage may vary. </p> <p>There are numerous hardware tools you can use. From relatively expensive tools like <a href="http://nuand.com/bladeRF" rel="nofollow">bladeRF</a> and <a href="http://greatscottgadgets.com/hackrf/" rel="nofollow">hackRF</a> to really cheap alternatives like <a href="http://sdr.osmocom.org/trac/wiki/rtl-sdr" rel="nofollow">rtl-sdr</a>. You'd probably need to do some research on how to actually use them for what you want. </p>
2956
2013-10-26T16:24:56.680
<p>Scenario: </p> <ul> <li>Two devices have wireless connect. ( like wi-fi )</li> <li>Probably encrypted. ( like wi-fi's WPA2 )</li> </ul> <p>Which instruments are best for discovering carrier frequency?</p> <p>How encrypted-text should be gathered to attack on it ( kind of software, e.g. something like <a href="http://br1.einfach.org/tech/horst/" rel="nofollow">horst</a>, but more broad )?</p>
Attack on wireless interconnection
|tools|hardware|encryption|physical-attacks|
<p>As mentioned above by 0xea, <a href="https://twitter.com/domi007">@domi007</a> published 4 blog posts (<a href="http://domonkos.tomcsanyi.net/?p=418">1</a>,<a href="http://domonkos.tomcsanyi.net/?p=422">2</a>,<a href="http://domonkos.tomcsanyi.net/?p=425">3</a>,<a href="http://domonkos.tomcsanyi.net/?p=428">4</a>) detailing his experience with GSM sniffing and cracking. He also published his <a href="https://www.youtube.com/watch?v=3cnnQFP3VqE">recorded presentation</a> about GSM security (<a href="http://camp.hsbp.org/2013/zer0/gsm.pdf">slides</a>). On the same topic, there's also <a href="http://binaryrf.com/viewtopic.php?t=6&amp;f=9">Sniffing GSM with HackRF</a>, <a href="http://www.rtl-sdr.com/rtl-sdr-tutorial-analyzing-gsm-with-airprobe-and-wireshark/">Analyzing GSM with Airprobe and Wireshark</a>, three Chaos Computer Club presentations (One discussing <a href="https://www.youtube.com/watch?v=ZrbatnnRxFc">Wideband GSM sniffing</a>, another discussing the <a href="https://www.youtube.com/watch?v=9wwco24EsHs">functioning of GSM networks</a>) and the one mentioned <a href="https://events.ccc.de/congress/2009/Fahrplan/events/3654.en.html">above</a> about GSM Cracking. Last but not least, there's also a Black Hat 2008 Presentation called "Intercepting Mobile Phone/GSM Traffic", by David Hulton and Steve <a href="http://www.blackhat.com/html/featured_media/bh08-002-Stream-1.mov">video (.mov)</a>. Observation : There's also <a href="https://srlabs.de/airprobe-how-to/">this tutorial by Srlabs</a>, which uses their own tool, Kraken, that covers decrypting GSM using Airprobe and the <a href="https://svn.berlin.ccc.de/projects/airprobe/wiki/A">Airprobe's own tutorial</a> on decoding GSM. When choosing your SDR, I suggest you read <a href="http://www.taylorkillian.com/2013/08/sdr-showdown-hackrf-vs-bladerf-vs-usrp.html">this comparison</a> about <a href="http://greatscottgadgets.com/hackrf/">HackRF</a>, <a href="http://nuand.com/">bladeRF</a> and the <a href="https://www.ettus.com/product/details/UB210-KIT">USRP B210</a>. There is also <a href="http://sdr.osmocom.org/trac/wiki/rtl-sdr">RTL-SDR</a> . They are all quite nice. I also suggest using <a href="http://gqrx.dk/">Gqrx</a> as it's built on Gnuradio and has a neat interface.</p> <p>Architecture and theory wise, I'd recommend <a href="https://docs.google.com/viewer?url=http://www2.informatik.hu-berlin.de/~goeller/isdn/GSMDmChannels.pdf">About GSM Dm Channels</a>, which is a quite complete and detailed beginner paper that explains the GSM Architecture and how it works. I also recommend <a href="http://rads.stackoverflow.com/amzn/click/0470030704">GSM - Architecture, Protocols and Services</a> and <a href="http://rads.stackoverflow.com/amzn/click/B004W7DNWY">4G: LTE/LTE-Advanced for Mobile Broadband</a> (if considering LTE), which provide further information and details about the functioning of GSM for those that want to delve into it.</p> <p>Regarding GSM Encryption and its flaws, I suggest <a href="https://docs.google.com/viewer?url=http%3A%2F%2Fwww.cs.technion.ac.il%2Fusers%2Fwwwb%2Fcgi-bin%2Ftr-get.cgi%2F2006%2FCS%2FCS-2006-07.pdf">Instant Ciphertext-Only Cryptanalysis of GSM Encrypted Communication</a>, which discusses ciphertext attacks on A5/(1,2,3), <a href="https://docs.google.com/viewer?url=http://www.emsec.rub.de/media/crypto/attachments/files/2010/04/da_gendrullis.pdf">Hardware-based Cryptanalysis of the GSM A5/1 Encryption Algorithm</a> - includes a 2 page brief on A5/1 and then goes on to the cryptoanalysis - and <a href="https://docs.google.com/viewer?url=http://cryptome.org/a5-3-attack.pdf">A Practical-Time Attack on the A5/3 Cryptosystem Used in Third Generation GSM Telephony</a> - discusses attacks on A5/3. Finally, there is also <a href="http://cryptome.org/a51-bsw.htm">Real Time Cryptanalysis of A5/1 on a PC</a>, a very nice document called <a href="http://www.researchgate.net/publication/235339185_Security_of_3G_and_LTE">Security of 3G and LTE</a> that discusses the security architecture and the attacks on it's flaws, and <a href="https://docs.google.com/viewer?url=http://www.bolet.org/~pornin/2000-ches-pornin%2bstern.pdf">Software Hardware Trade-offs - Applications to A5/1 Cryptanalysis</a> - another nice paper on A5/1. Observations : You can find the specifications for A5/3 in the <a href="http://www.3gpp.org/Confidentiality-Algorithms">middle of this page</a>. There are also two Blackhat presentions that cover part of those papers in a succinct way <a href="https://docs.google.com/viewer?url=https://srlabs.de/blog/wp-content/uploads/2010/07/Attacking.Phone_.Privacy_Karsten.Nohl_1.pdf">Attacking Phone Privacy</a> and <a href="https://docs.google.com/viewer?url=https://srlabs.de/blog/wp-content/uploads/2010/07/100729.Breaking.GSM_.Privacy.BlackHat1.pdf">Breaking Phone Privacy</a>. If you like animations, there is an <a href="https://www.youtube.com/embed/LgZAI3DdUA4">A5/1 Cipher Animation</a> on YouTube. <a href="https://twitter.com/matthew_d_green">@matthew_d_green</a> deserves to be mentioned, considering he wrote a small synthesis of cellular communications crypto flaws in his <a href="http://blog.cryptographyengineering.com/2013/05/a-few-thoughts-on-cellular-encryption.html">blog</a>. </p> <p>Important observation : The GSM specifications are located in <a href="http://www.3gpp.org/">3GPP's website</a>. To find them, you need to determine the <a href="http://www.3gpp.org/Specification-Numbering">numbering</a> of the part you're looking for. Then, you browse into <a href="ftp://ftp.3gpp.org/specs/">their ftp server</a> and look for the date and release you fancy. (Releases prior to 2012-13 need to be solicited through their contact mail). Supposing you want the latest "3G and Beyond / GSM" Signalling Protocols specifications, you'll need to browse to their "latest" folder, descend to the release you're looking for (i.e. Release 12), and finally download the "Series" that contain the information you need - which in this case would be "Series 24". Therefore, the result of your endeavor would be : <a href="ftp://ftp.3gpp.org/specs/latest/Rel-12/24_series/">ftp://ftp.3gpp.org/specs/latest/Rel-12/24_series/</a> . It's not a good user experience, especially because there are several empty directories, but with patience, you can find what you're looking for.</p> <p><a href="https://twitter.com/gat3way">@gat3way</a> deserves a special mention for documenting his experiments in cracking GSM A5/1 in his blog (<a href="http://www.gat3way.eu/index.php?mact=News,cntnt01,detail,0&amp;cntnt01articleid=199&amp;cntnt01returnid=57">1</a>,<a href="http://www.gat3way.eu/index.php?mact=News,cntnt01,detail,0&amp;cntnt01articleid=200&amp;cntnt01returnid=57">2</a>,<a href="http://www.gat3way.eu/index.php?mact=News,cntnt01,detail,0&amp;cntnt01articleid=201&amp;cntnt01returnid=57">3</a>) - includes a brief description of the A5/1 mechanism - and the fact that he has implemented support for cracking A5/1 using Pornin's attack in his password recovery tool, <a href="http://www.gat3way.eu/hashkill/index.php">hashkill</a> - <a href="https://github.com/gat3way/hashkill/commit/d43fdd2ce042d75862930044fd0b4570bee56cf0">git commit</a>.</p> <p>An existing tool to crack A5/1 is Kraken, by srlabs (available through git://git.srlabs.de/kraken.git), which should be used after recording the data with Gnuradio/Gqrx and parsing it with <a href="https://svn.berlin.ccc.de/projects/airprobe/">Airprobe</a>. It needs GSM rainbow tables, available at the <a href="https://opensource.srlabs.de/projects/a51-decrypt/files">jump</a>. </p> <p>Another tool that can be considered is <a href="https://github.com/gat3way/hashkill/">hashkill</a>, which takes the key to be cracked in a "frame_number:keystream" format - it's author published the code for converting a bin burst into the required input format <a href="http://www.gat3way.eu/poc/encode.c">here</a>. He also published a <a href="http://www.gat3way.eu/poc/si5.phps">php script</a> to locate suitable SI5/SI6 encrypted bursts for cracking - you'll need to change the hardcoded values for SI5 frames to fit your location -, which, together with Kraken's xortool, <a href="http://www.mail-archive.com/a51@lists.reflextor.com/msg01023.html">gsmframecoder</a> (that will be used to calculate Timing Advance changes) and <a href="https://svn.berlin.ccc.de/projects/airprobe/">Airprobe</a> should be sufficient to crack GSM.</p>
2962
2013-10-27T07:15:54.770
<p>I would like to know what is needed to intercept GSM communications with an <a href="http://en.wikipedia.org/wiki/Universal_Software_Radio_Peripheral">USRP</a> (Universal Software Radio Peripheral) and using <a href="http://gnuradio.org/">Gnu Radio</a>.</p> <ul> <li>Is there tutorial about that ?</li> <li>What type of USRP is recommended ?</li> <li>Where to find technical documentation about the GSM protocols ?</li> <li>Is there already existing tools to break the A5/1 encryption ?</li> <li>...</li> </ul> <p>All in one, my question is more about looking for advices about "<strong>where to start ?</strong>" when trying to understand GSM communication.</p>
Intercepting GSM communications with an USRP and Gnu Radio
|radio-interception|gnu-radio|
<p>Delphi and Borland C++ Builder use <code>EAX</code>, <code>EDX</code> and <code>ECX</code> for the first three arguments in their variant of the <a href="http://en.wikipedia.org/wiki/Fastcall#fastcall" rel="nofollow"><code>__fastcall</code> calling convention</a>. So if you choose "Delphi" or "C++ Builder" in Options-Compiler, you can just use <code>__fastcall</code> in the function prototype - no need to resort to <code>__usercall</code>.</p>
2964
2013-10-27T09:31:07.690
<p>I have some code (I assume Delphi) which uses only the EAX and EDX register for passing the arguments (and of course the stack if more are required). I looked which calling conventions would match, but I haven't found one which uses only EAX and EDX. AFAIK Borland fastcall/register is using EAX and EDX, but also ECX, which is not the case here.</p> <p>Can I tell IDA somehow about this calling convention? How would I do this?</p>
Which calling convention to use for EAX/EDX in IDA
|ida|calling-conventions|
<p>From <a href="http://en.wikipedia.org/wiki/Address_space_layout_randomization" rel="nofollow">http://en.wikipedia.org/wiki/Address_space_layout_randomization</a> -</p> <blockquote> <p><strong>Address space layout randomization (ASLR)</strong> is a computer security technique involved in protection from buffer overflow attacks. In order to prevent an attacker from reliably jumping to a particular exploited function in memory (for example), ASLR involves randomly arranging the positions of key data areas of a program, including the base of the executable and the positions of the stack, heap, and libraries, in a process's address space.</p> </blockquote> <p>You can disable ASLR in your C app at build-time by using the linker option <a href="http://msdn.microsoft.com/en-us/library/bb384887.aspx" rel="nofollow"><code>/DYNAMICBASE:NO</code></a>.</p>
2966
2013-10-27T10:52:42.373
<p>Why do IDA and Ollydbg always open some programs with the main() function at the same address?</p> <p>The address given by IDA is equal to that given by Ollydbg in runtime. However, when I wrote my own C app and ran it, the address of <code>main()</code> was always different between each runtime in Ollydbg.</p> <p>In IDA, though, there was always the same address, never equal to the one given by Ollydbg, which looked like just some relative address.</p> <p>Is this caused by the compiler or by something else?</p>
Some programs have always same addressing and some different
|ida|debuggers|ollydbg|
<p>Just debug the file in IDA itself and <a href="https://www.hex-rays.com/products/ida/support/idadoc/1470.shtml" rel="nofollow">take a memory snapshot</a> once the data is decrypted.</p>
2970
2013-10-27T15:25:17.123
<p>So I have some encrypted data in this executable. IDA couldn't do much with it, so it defined it as arrays. Now I know how to decrypt this data, and it has some encrypted code. I could of course, put the encrypted data into some separate file, run the decryption on it, and then let IDA process it, but then it looses connection to the original executable.</p> <p>Is it possible to replace the encrypted data 1:1 with the decrypted one, so I can let IDA process it, in the context of the executable?</p>
Put encrypted code blocks back as unencrypted in IDA
|ida|decryption|
<p>The one that worked for me eventually was &quot;<a href="https://github.com/mandiant/flare-ida/blob/master/plugins/stackstrings_plugin.py" rel="nofollow noreferrer">stackstrings</a>&quot; plugin from FireEye/Mandiant FLARE (<a href="https://github.com/mandiant/flare-ida/blob/master/python/flare/stackstrings.py" rel="nofollow noreferrer">based on this module</a>)</p>
2977
2013-10-29T16:48:48.743
<p>How can I clean up/simplify strings that are built at runtime?</p> <p>I've seen this a couple of times and figured that there has to be something easier. I've been manually converting the characters to try and interpret what strings are being formed.</p> <pre><code>.text:0040166E C6 45 F0 5C mov [ebp+pszSubKey+2Ch], '\' .text:00401672 C6 45 F1 57 mov [ebp+pszSubKey+2Dh], 'W' .text:00401676 C6 45 F2 69 mov [ebp+pszSubKey+2Eh], 'i' .text:0040167A C6 45 F3 6E mov [ebp+pszSubKey+2Fh], 'n' .text:0040167E C6 45 F4 6C mov [ebp+pszSubKey+30h], 'l' .text:00401682 C6 45 F5 6F mov [ebp+pszSubKey+31h], 6Fh .text:00401686 C6 45 F6 67 mov [ebp+pszSubKey+32h], 67h .text:0040168A C6 45 F7 6F mov [ebp+pszSubKey+33h], 6Fh .text:0040168E C6 45 F8 6E mov [ebp+pszSubKey+34h], 6Eh .text:00401692 C6 45 F9 5C mov [ebp+pszSubKey+35h], 5Ch </code></pre>
How can I clean up strings built at runtime (stack strings)?
|ida|idapython|
<p>Just to add to the answers, I can tell how to get close to a clean environment despite <code>gdb</code>. In fact, there are two methods to reach this:</p> <ol> <li><p>We can get rid of the extra environment variables added by <code>gdb</code> as follow:</p> <pre><code>(gdb) unset environment LINES (gdb) unset environment COLUMNS </code></pre> <p>Write these commands before running the program, and you should be close to the normal environment. Note that you still have to take care of the <code>_</code> variable.</p></li> <li><p>One can also generate a memory core of the vulnerable program and analyze it with <code>gdb</code>:</p> <pre><code>$&gt; gdb vuln_program core </code></pre> <p>You should just look at the memory and never <code>run</code>, <code>next</code>, <code>step</code>, ... because doing so will force you to restart the program with a fresh memory (with the shift).</p></li> </ol> <p>That was two methods you can use with <code>gdb</code> to follow a program without too much differences with the real execution. But, they are many others!</p>
2983
2013-10-30T11:15:39.893
<p>It's something that puzzle me for a long time. I can observe that there is a difference between the real execution of a program and the <code>gdb</code>-controlled one.</p> <p>But, here is an example:</p> <ol> <li><p>First, here is the example code (we use an automatic variable to get the location of the stack):</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int main () { char c = 0; printf ("Stack address: %p\n", &amp;c); return EXIT_SUCCESS; } </code></pre></li> <li><p>Then, we disable the ASLR (we use the personality flags of the process and not the system-wide method through <code>/proc/sys/kernel/randomize_va_space</code>):</p> <pre><code>$&gt; setarch `uname -m` -R /bin/bash </code></pre></li> <li><p>Then, get a run in the real memory environment:</p> <pre><code>Stack address: 0x7fffffffe1df </code></pre></li> <li><p>And, the same through <code>gdb</code>:</p> <pre><code> (gdb) r Starting program: ./gdb-against-reality Stack address: 0x7fffffffe17f [Inferior 1 (process 5374) exited normally] (gdb) </code></pre></li> </ol> <p>So, here we have a difference of 96 bytes between the two runs. But, how can I predict this difference for a given program without having it running in the <em>real</em> memory layout (just by knowing the <code>gdb</code> memory layout) ?</p> <p>And, also, from where/what is coming this difference ?</p>
How to predict address space layout differences between real and gdb-controlled executions?
|gdb|memory|
<p>The following code is taken from GreyHat Python, and is very similar to the previous answer:</p> <pre><code>from idaapi import * funcs = ["malloc","free","strcmp"] for f in funcs: curAddr = LocByName(f) if curAddr != BADADDR: xrefs = CodeRefsTo(curAddr,0) print "Cross References to %s" % f for ref in xrefs: print "08x" % ref SetColor(ref,CIC_ITEM,0x0000ff) </code></pre> <p>This function will also highlight the call to make tracing it easier</p>
2990
2013-10-31T07:52:24.587
<p>Is it possible to see a kind of statistics in IDA about functions and how often they are referenced? When analyzing a program, I find it helpfull.</p> <p>Functions that are referenced very often typically are common functionality. An example would be stuff like <code>strcmp()</code>, <code>malloc()/free()</code>, <code>strlen()</code>, etc..</p> <p>Some of those are quite easy to identfiy (like a <code>strcmp()</code> implementation), and giving a name to those functions early on, makes the analysis of the rest more easy.</p>
Statistics of call XREFs
|ida|
<p>What you referring to as ptr-4 and ptr-8 are in fact location of singled out variables on stack. IDA has to know the structure in order to recognize it automatically. If you setup custom structure in "Structures" subview. Subsequently, You can manually set whatever variable you choose to be the type of that particular variable. Thereafter, IDA will replace references within disassembly view with appropriate offsets to the structure members. </p> <p>If IDA "lands" in what seems to be the middle of the structure. You could follow the work around below to make it display it differently:</p> <blockquote> <ol> <li>invert the operand sign by pressing _ (underscore)</li> <li>select the instruction</li> <li>press T. provide calculated delta, select the desired structure and its field</li> </ol> </blockquote> <p>For details consult <a href="http://www.hexblog.com/?p=63" rel="nofollow">Negative structure offsets</a> of <a href="http://www.hexblog.com" rel="nofollow">Hex Blog</a>. </p>
2991
2013-10-31T11:39:20.817
<p>I have a structure which looks like this:</p> <pre><code> RefString struct RefCount dd ? StrLen dd ? CString db... RefString ends </code></pre> <p>When the code passes around a pointer, it doesn't point to the beginning of the struct (RefCount), instead it points to CString, which is allocated as a normal C-String with a zero terminating character, as well as having the strlen and a refcount. So when the code accesses the strlen or refcount it uses <code>ptr-4</code> respectively <code>ptr-8</code>.</p> <p>Actually that's quite a nice construct, because this way the string can be used as a delphistring, but also directly passed to some system functions without the need of converting back and forth. </p> <p>Now I wonder though, if it is possible in IDA to create a struct with the basepointer to the string and it knows that the other fields are with the negative offset.</p>
Struct with negative offset in IDA possible
|ida|struct|
<p>In fact, the memory layout within <code>gdb</code> and outside of it differs of a few bytes. There have been recently a question about this here. You can read: <a href="https://reverseengineering.stackexchange.com/questions/2983/how-to-predict-address-space-layout-differences-between-real-and-gdb-controlled">How to predict address space layout differences between real and gdb-controlled executions?</a></p> <p>In your case, you may just have to adjust your address by adding/subtracting 96 bytes.</p> <p>I can, also, give you a few tricks with <code>gdb</code> to help you a bit with this:</p> <ul> <li><p><code>info frame</code>: This command gives you a full image of the frame you are in. Including where are stored the <em>saved eip</em> ans the <em>saved ebp</em>. It is extremely useful to observe if you reach the right spot in the memory to modify. You may set a breakpoint on <code>read_txt</code> and display the content of the <em>saved eip</em> before and after the <code>gets()</code> is called in order to see if the modification occurred properly.</p></li> <li><p>When hitting a:</p> <pre><code>0xbffff489 in ?? () </code></pre> <p>It basically means that <code>gdb</code> did not find any symbol linked to the memory location. But, it might be assembly code, especially if it is your shellcode. So, to disassemble it you can use either of these commands:</p> <ul> <li><code>disas 0xbffff489,+40</code></li> <li><code>x /10i 0xbffff489</code></li> </ul></li> </ul> <p>Hope this help.</p>
2995
2013-11-01T19:26:55.183
<p>Some days ago I coded a simple code to test a buffer overflow exploitation on x86 system. In order to keep it simple I disabled ASLR and NX so there are no protection that could cause weird behaviours.</p> <p>This is my C code to exploit:</p> <pre><code>#include &lt;stdio.h&gt; void read_txt(){ char txt[64]; printf("Write something:"); gets(txt); } int main(){ read_txt(); return 0; } </code></pre> <p>I also wrote my own shellcode that just prints a string. As far as I know the payload should be something like this, fill the buffer with NOP instructions + shellcode, add 0x41414141 (AAAA) to overwrite EBP register and finally I override the return address with an address pointing to the middle of the NOPs.</p> <p>Actually it does not work in that way and my payload is as follows:</p> <pre><code>[1-\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x31\xc0\x31\xdb\x31\xc9\x31\xd2\xb0\x04\xb3\x01\x68\x20\x3b\x29\x20\x68\x68\x73\x65\x63\x68\x20\x48\x69\x67\x68\x48\x6f\x6c\x61\x89\xe1\xb2\x0f\xcd\x80\xb0\x01\x31\xdb][2-\x41\x41\x41\x41][3-\x89\xf4\xff\xbf][4-\x89\xf4\xff\xbf] 1- NOPs + Shellcode = 60bytes 2- AAAA =4 bytes (Padding to fill the buffer, if NOP+Shellcode fills 64bytes it does not work) 3- Address to override EBP (In the middle of NOPs) 4- Overrides Return Address </code></pre> <p>This exploit works on gdb but fails if I pass the payload directly to the program, and I think that the problem is that just before the program executes gets() function the disasembler shows the <strong>leave</strong> instruction which points esp to ebp and causes an error.</p> <p>This is the disassembly of read_txt() function:</p> <pre><code>0x0804844c &lt;+0&gt;: push %ebp 0x0804844d &lt;+1&gt;: mov %esp,%ebp 0x0804844f &lt;+3&gt;: sub $0x44,%esp 0x08048452 &lt;+6&gt;: movl $0x8048510,(%esp) 0x08048459 &lt;+13&gt;: call 0x8048320 &lt;printf@plt&gt; 0x0804845e &lt;+18&gt;: lea -0x40(%ebp),%eax 0x08048461 &lt;+21&gt;: mov %eax,(%esp) 0x08048464 &lt;+24&gt;: call 0x8048330 &lt;gets@plt&gt; 0x08048469 &lt;+29&gt;: leave 0x0804846a &lt;+30&gt;: ret </code></pre> <p>And this is the execution of the exploit on GDB:</p> <pre><code>(gdb) x/20x $esp 0xbffff47c: 0xbffff480 0x90909090 0x90909090 0x90909090 0xbffff48c: 0x90909090 0xc0319090 0xc931db31 0x04b0d231 0xbffff49c: 0x206801b3 0x6820293b 0x63657368 0x69482068 0xbffff4ac: 0x6f486867 0xe189616c 0x80cd0fb2 0xdb3101b0 0xbffff4bc: 0x41414141 0xbffff489 0xbffff489 0xbffff500 (gdb) s Warning: Cannot insert breakpoint 0. Error accessing memory address 0x90909090: I/O Error. 0xbffff489 in ?? () (gdb) c Continuing. Shellcode Executed Program received signal SIGSEGV, Segmentation fault. 0xbffff4b9 in ?? () (gdb) </code></pre> <p>Notice that EBP points to 0x90909090 because it has the same address that overrides the return address, and also notice the string <strong>Shellcode Executed</strong> that is the shellcode included in the payload.</p> <p>My question is, where could I point EBP to avoid this problem before pointing the return address to the NOP slide? Also as secondary question why I can't fill the 64bytes buffer with NOPs+Shellcode?</p> <p>Regards.</p>
Illegal Instruction exploiting sample Buffer Overflow code
|c|exploit|buffer-overflow|
<p>Not worth any bounty, but it might help, as <code>Tomovision.exe</code> doesn't look obfuscated in any way after a quick look, and contains the algorithm you're looking for:</p> <ol> <li>open it in your favorite disassembler</li> <li>check for reference to <code>RICE</code> strings (such as <code>C:\TomoVision\Prog\Prog_Lib\TomoVision_Convert\NEMA_Compression_RICE_decode.cpp</code> at address <code>4F59C4</code>)</li> <li>study the ASM code - a.k.a. do your homework ;)</li> </ol>
2999
2013-11-02T07:24:50.567
<p>I am trying to figure out how the <a href="http://www.firstpr.com.au/audiocomp/lossless/#rice" rel="nofollow">Lossless Rice compression</a> algorithm works on the following file. Here is a <a href="http://www.sendspace.com/file/me8bcw" rel="nofollow">DICOM file</a>.</p> <p>Looking at the information I can see:</p> <pre><code>$ gdcmdump I160 | grep "Tamar Compression Type" (07a1,1011) CS [LOSSLESS RICE ] # 14,1 Tamar Compression Type </code></pre> <p>I can open the image using <a href="http://www.tomovision.com/download/binaries/Tomo_21_r5.zip" rel="nofollow">TomoVision</a>. The image is 512x512, 16bits (unsigned).</p> <p>The compressed stream:</p> <pre><code>$ gdcmraw -t 07a1,100a I160 comp.raw </code></pre> <p>contains (hexdump comp.raw):</p> <pre><code>1A D5 F8 EB F2 77 A5 CE A3 54 D5 2A C0 5D AA 32... </code></pre> <p>But TomoVision seems to output a series of zeroes until byte 0x1DE. I can also use a command line tool: <a href="http://www.tomovision.com/download/download_dicomatic.htm" rel="nofollow">DICOMatic</a> to process the file. However without a proper license, the <a href="http://www.speedyshare.com/qhjq2/I160.dcm" rel="nofollow">generated file</a> contains a waterwark. So only the first few bytes looks ok:</p> <pre><code>$ gdcmraw /tmp/I160.dcm /tmp/pixeldata.raw $ hexdump /tmp/pixeldata.raw |less </code></pre> <p>Some more encoded files can be found <a href="http://www.speedyshare.com/4Xr9f/lossless-rice.tgz" rel="nofollow">here</a>.</p>
Lossless Rice Compression
|decryption|
<p>Are you perhaps looking for <a href="https://code.google.com/p/binwalk/" rel="noreferrer">binwalk</a>? Especially the <em>magic</em> folder of its source code.</p>
3000
2013-11-02T11:20:34.640
<p>While reading <a href="https://reverseengineering.stackexchange.com/a/2996/115">an answer to another question</a>, it was mentioned that "<code>78 9C</code>" was a well-known pattern for Zlib compressed data. Intrigued, I decided to search up the signature on <a href="http://www.filesignatures.net/index.php?search=789c&amp;mode=SIG" rel="nofollow noreferrer">the file signature database</a> to see if there were any related numbers. It wasn't on there. So I checked on <a href="http://www.garykessler.net/library/file_sigs.html" rel="nofollow noreferrer">Gary Kessler's magic number list</a> to see that it wasn't there either.</p> <p>I even ended up creating a binary file with the signature at the beginning and ran "<code>file</code>" on it as a sort of <em>"I-doubt-it-will-work-but-maybe"</em> attempt (Since that works with "<code>50 4b</code>" because that is a valid ZIP file header and is commonly in the middle of other files.) But none of these attempts revealed that I was looking at a Zlib signature.</p> <p>It would appear as though most magic number databases only contain file-format magic numbers rather than numbers to differentiate data in the middle of a file. So, my question is:</p> <p>Are there any places one could find a list of binary signatures of certain types of data streams that are <em>not</em> file formats themselves? Data that is not a file itself, but rather <em>inside</em> a file. </p> <p>Thanks in advance.</p>
Where could one find a collection of mid-file binary signatures?
|file-format|magic-number|
<p>There are several approaches to locating strings in an unknown file. One you already tried: <code>strings</code>. This looks for plain, unencoded ASCII text:</p> <blockquote> <p>Strings looks for ASCII strings in a binary file [..] A string is any sequence of 4 (the default) or more printing characters ending with a newline or a null. (<code>man strings</code>)</p> </blockquote> <p>But there are many reasons why this naive approach may fail. First off: not every text in the world is ASCII encoded. In fact, examining your file with a binary editor, you can find graphic images for the font used in the game at offset 0x20010 -- monochrome bitmaps of 8x16 pixels. If you assume the first character (a '0') is numbered zero, then 'A' is at position 31 -- definitely <em>not</em> ASCII text. Of course, it's possible the text drawing routine knows this, and re-orders characters to be printed according to this scheme; but, given the age of this particular game (1987) it is more likely that the textual data is <em>stored</em> according to this weird encoding.</p> <p>In itself, however, this should not be a problem.</p> <p>Googling for this game provides a number of screen shots, and you can read some of the texts that may appear -- "The last thing you remember", "Word of your historic quest", etc. --, and a noteworthy point is that all text appears to be in ALL CAPS.</p> <p>How does that help? Well, if the encoding is <em>remotely</em> 'normal', the character code of an 'A' might be anything, but you can safely assume that <code>code+1</code> is 'B', <code>code+2</code> is 'C', and so on. Now let's assume the text "THE" occurs <em>anywhere</em> (a safe assumption). Subtract 'T' from the first byte in the data and note the difference. Subtract this difference from the next byte and test if it is an 'H'; if so, test the same difference on the <em>next</em> byte and see if it is an 'E'. Three times is a charm (in this case), and since the string "THE" ought to come up very frequent, you should see lots of hits with the same difference. Then you can write a custom routine to 'convert' <em>all</em> data bytes according to this scheme, and check again if you find useful strings.</p> <p>That didn't work for Shadowgate.</p> <p>Another option is that the text has been deliberately obfuscated. A popular (because <em>fast</em>) option was to <a href="http://en.wikipedia.org/wiki/Xor">XOR</a> text with a constant. That way the text was not readily visible when inspected with a hex viewer, yet could easily be displayed. So I did the same as above, only now with a XOR operation instead of a constant subtraction. It didn't work either.</p> <p>Next: given that SG is a <em>text</em> adventure, it stands to reason the writers tried to stuff as much as possible text into the poor NES memory. To find <em>real world compression</em> (ZIP, LZW) in such an old game is fairly rare, the compression schemes tended to be quite simple. After all, not only RAM was limited but CPU speed as well. What if every character is stored as a 5-bit sequence? That would save lots of memory -- every 8 characters of text could be stored in just 5 bytes, a compression rate of 62.5%.</p> <p>Why "5-bit"? We're talking English text here, plus a handful of punctuation characters, plus (maybe) digits '0' to '9'. The alphabet itself is 26 characters long, which leaves another 6 values for anything else -- and, hey, one of the extra codes could mean "for the next character use all 8 bits".</p> <p>Checking every 5 bits against my test string (which in cryptography is called a <a href="http://en.wikipedia.org/wiki/Crib_%28cryptanalysis%29">"crib"</a>), I found the following:</p> <pre><code>candidate at 0570, delta is 41 H_A\`THE[TROLL[ candidate at 0670, delta is 41 _H\`ATHE[TROLL[ candidate at 0878, delta is 41 `AN`QTHE[TROLL[ candidate at 09E3, delta is 41 FROM^THE[DEPTHS candidate at 1380, delta is 41 E[OF[THEM_A[THI candidate at 13F0, delta is 41 ]NX_ATHE[WORDS[ candidate at 14C0, delta is 41 PD^`QTHE[FLAME[ candidate at 1BBA, delta is 41 UDGE[THEM[BY_A_ candidate at 22E0, delta is 41 ]BX_ATHE[GLASS[ candidate at 230D, delta is 41 ID_A[THE^SIGN[O candidate at 2375, delta is 41 S[ON[THEM_A\`AB candidate at 2390, delta is 41 LLOW[THE^VISCOU candidate at 2528, delta is 41 F]PX_THE[STONE[ candidate at 25E6, delta is 36 @CP=KTHE@?OFHBS candidate at 27F8, delta is 41 YDP]ATHE[BARK[O candidate at 2B1E, delta is 41 D_H\]THE[WATER[ </code></pre> <p>.. and many more. You can see it works, because I also decoded a few bytes before and after the test string, and that's recognizable as 'something' as well. The 'delta' shown is the difference between the five-bit code (0..31) and ASCII, and you can see it's <code>41</code> for the majority of strings (the only exception seems a false positive).</p> <p>To assure that this <em>is</em> correct, I tried with another crib: <code>KING</code> (it's a fantasy game):</p> <pre><code>candidate at 0661, delta is 41 Y[LOOKING[SPEAR candidate at 23B4, delta is 41 [DRINKING[TAR_A candidate at 2B5D, delta is 41 [DRINKING_A\`AA candidate at 8E1B, delta is 43 \XVFDKINGDHEEVE candidate at 146F9, delta is 34 JL54HKING48A4:D </code></pre> <p>That seems to work out as well: not the 'king' I was expecting, but nevertheless good results with a delta of 41, random stuff with another delta.</p> <p>But finding useful strings this way is rather fortunate, because of course there is no guarantee that reading every 5 bits <em>starting at the first byte</em> should display anything useful. There may be lots of other strings in between the ones shown, but they didn't happen to start on a multiple of 5*8 bits. Suppose there was no text at position #0, but there <em>was</em> at position #1, then I cannot see it:</p> <pre><code> bits for byte 0,1 0000.0000 TTTT.T000 (T = Text character bits) --- reading 1st 5 bits 1111.1??? ????.???? 2nd 5 bits -- the wrong ones! .... .111 11??.???? </code></pre> <p>To properly decode <em>all</em> strings, you'd now take the following route:</p> <ul> <li>my list of results contain readable text, but some garbage as well. Find out what the 'garbage' is (<code>[</code> appears to be a simple space, but <code>THEM_A\'AB</code> needs a closer look).</li> <li>find as much as possible <em>string starts</em> and note down their addresses</li> <li>search the binary for these addresses. After all, if they are 'used', there needs to be some reference to them.</li> <li>Before and after these addresses, there will be more. These are addresses of strings the search algorithm did <em>not</em> find, but still may be valid.</li> <li>Usually, a list of this kind is a contiguous one (although there may be some data associated with each string). Scan the binary up and down for similar addresses, until you found what's sure to be the start and the end.</li> <li>Loop over the list and display everything you can according to the decoding scheme.</li> <li>Sit back and enjoy a job well done.</li> </ul>
3001
2013-11-02T13:42:02.317
<p>I want to extract the strings in <a href="http://www.speedyshare.com/NGGVr/Shadowgate-U.nes">Shadowgate for NES</a>. I ran <code>file</code> on the image and then <code>strings</code>, no luck. I found <a href="http://fms.komkon.org/EMUL8/NES.html#LABM">some information about the NES cartridge file format</a>. The docs mention the use of “Name Tables”. Is there a way to disassemble this file and view the strings? I tried</p> <pre><code> strings -e -T rom.bin </code></pre> <p>I also tried :</p> <pre><code> objdump -i rom.bin </code></pre> <p>The processor looks to be an M6502 processor and there are Windows disassemblers available.</p>
String extraction from an iNES ROM dump
|disassembly|strings|
<p>You should take a look at the <a href="http://www.honeynet.org/project" rel="nofollow noreferrer">honeynet project</a> as it's probably the most well known implementation of a honey pot, and it includes plenty of tools and instructions to set up the honey pot and properly set up logging information. You can also see <a href="https://security.stackexchange.com/questions/10168/setting-up-a-honeypot">this</a> thread as the accepted answer here provides a lot of detail and perspective about what you should think about when you're setting up a honeypot.</p> <p>Any time you're doing any kind of analysis or interaction with malware you should be running it inside of a Virtual Machine. Security procedures aside you never know what you're going to run into when you're doing analysis. </p> <p>That being said, there is plenty of malware that operates differently if it detects it's running inside of a virtual machine vs. a real system but if you're just getting started I would recommend doing your analysis inside of a VM.</p>
3003
2013-11-02T22:48:20.783
<p>I want to operate honeypots for malware analysis purpose and packet capture.</p> <p>What honeypots are recommended for beginners ? And, what is the best to set-up an honeypot, should it be in a real machine or in a virtual machine ? Finally, does this technique really work for malware capture or is there a better way to get real malware ?</p>
What Honeypots are recommended to capture malwares (for analysis)?
|malware|
<p>When I looked into the URL, I can see that the base64 encoded data is having newline character.</p> <p>When you remove newline characters and present that as one single line to openssl, you need the <strong><em>-A</em></strong> option.</p> <p>The below will work fine.</p> <pre><code>$openssl enc -A -d -base64 &lt;&lt;&lt; /9j/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/2Q== </code></pre> <p>Or you can also use still a simple method as below</p> <pre><code>$ echo "/9j/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIfIiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/2Q==" | base64 --decode </code></pre> <p>We can also do this with notepad++ using <a href="http://download.tuxfamily.org/nppplugins/MimeTools/mimeTools.v1.7.zip" rel="nofollow">MIME tools plugin</a>.</p> <p>This proves this is base64 encoded data.</p>
3021
2013-11-07T08:13:06.420
<p>I am starring at the following which looks like base64 but not quite:</p> <pre><code>$ curl -s 'http://cgp.compmed.ucdavis.edu/chapr/education/PATHOBIOLOGY%20OF%20THE%20MOUSE%20TIER%201A/MICROANATOMY/Images/EX02-0006-4.svs?XINFO' | xpath -q -e '//cdata' &lt;cdata&gt;/9j/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIfIiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/2Q==&lt;/cdata&gt; &lt;cdata&gt;/9j/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/2Q==&lt;/cdata&gt; &lt;cdata&gt;/9j/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/2Q==&lt;/cdata&gt; </code></pre> <p>However this does not appear to be proper base64 encoded stream:</p> <pre><code>$ openssl enc -base64 -d &lt;&lt;&lt; /9j/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/2Q== </code></pre> <p>openssl returns nothing as if it was invalid base64.</p> <p>What is the encoding used in this case ?</p> <p>EDIT:</p> <p>I was confused by the output. The encoded is actually a valid JPEG header, it does not contains no image, but it contains a valid JPEG Quantization Table (DQT) &amp; Huffman Table(s) (DHT).</p>
Invalid base64 encoding
|decryption|encodings|
<p>Yes, Spy++ can detect folder- and file-clicks in shell windows. Just make sure you're monitoring the right process (typically Explorer.exe).</p>
3026
2013-11-08T21:28:40.887
<p>I want to make a program that can intercept events (something like OnClickFolder as well as OnClickFile). Is there a way <a href="http://msdn.microsoft.com/en-us/library/aa264396%28v=vs.60%29.aspx" rel="nofollow">Spy++</a> or similar programs can do this?</p>
How to use Spy++ to find OnClickFolder or OnClickFile events in Windows Explorer?
|windows|
<p>Easiest solution is to undefine the function (navigate in the disassembly to the beginning of the function and press <kbd>U</kbd>) and then redefine the function (navigate in the disassembly to the beginning of the function and press <kbd>P</kbd>). Note that this will reset any variable names you had already set, though.</p>
3031
2013-11-10T16:32:28.183
<p>When you open the stack window in IDA with <code>Ctrl-K</code> there is a comment at the top saying:</p> <p>; Two special fields " r" and " s" represent return address and saved registers.</p> <p>When I made some mistake and undefined these fields, then how can I recreate them? Defining data creates just a normal variable type. Or can those not be set, so I have to live with the data types?</p>
IDA special fields in stack window
|ida|
<p>Unfortunately, certain factors are in play that will make it incredibly hard to filter. Specifically, everything from the calling convention windows uses to function prologs to space in said <a href="https://en.wikibooks.org/wiki/X86_Disassembly/Functions_and_Stack_Frames#Hot_Patch_Prologue" rel="nofollow noreferrer">prologues</a> to allow hot patching, etc...Windows' Application Binary Interface (ABI) is incorporated in every execution on the box. Naturally, this means you wont be able to filter it out, as several instructions are fairly common.</p> <p>If you're merely trying to diff binaries to see how similar they are, the main one i would suggest is <a href="http://www.forensicswiki.org/wiki/Ssdeep" rel="nofollow noreferrer">SSDEEP</a> found in this <a href="https://reverseengineering.stackexchange.com/questions/3507/is-there-any-tool-to-quantitatively-evaluate-the-difference-of-binary">answer</a></p>
3036
2013-11-14T09:28:45.523
<p>I'm comparing memory dumps in python with diStorm and volatility and try to analyze for given MemoryDumps (the 'dump' and the 'truth') whenever or not there was process injection.</p> <p>Mainly I try to match processes and vads in to dumps to each other to compare them, but i get quiet a lot of white noise (false positives).</p> <p>Here is a log I received comparing two clean memory dumps only by comparing modules (notepad and calc):</p> <pre><code>[10:08:13] Loading 'D:\notepad.zip' [10:08:36] Loading 'D:\calc.zip' [10:08:59] No match found for #208 "calc.exe"! [10:08:59] 01/17 matching "csrss.exe" [10:09:08] 02/17 matching "VBoxTray.exe" [10:09:18] 03/17 matching "svchost.exe" [10:12:51] 04/17 matching "ctfmon.exe" [10:12:55] 05/17 matching "VBoxService.exe" [10:13:24] 06/17 matching "smss.exe" [10:13:25] 07/17 matching "explorer.exe" [10:14:39] Module difference @ 0x772fb186 "\WINDOWS\system32\shlwapi.dll" SUB AL, 0x77 SUB AL, 0x77 POP ESP MOV DL, 0x14 DB 0x15 DB 0xbd DB 0x2d [10:14:39] Module difference @ 0x772fb817 "\WINDOWS\system32\shlwapi.dll" XOR [EAX], EAX XOR [EAX], EAX ADD [EAX], AL DB 0x0 DB 0x0 DB 0xbd [10:14:39] Module difference @ 0x77fb5e17 "\WINDOWS\system32\ntdll.dll" ADD [ECX+0x0], AH ADD [EDI+0x0], CH INS BYTE [ES:EDI], DX DB 0x74 [10:14:39] Module difference @ 0x77fb5e1f "\WINDOWS\system32\ntdll.dll" ADD [EBP+0x0], AH ADD [ECX+0x0], AH DB 0x78 DB 0x64 [10:14:39] Module difference @ 0x77fb5e27 "\WINDOWS\system32\ntdll.dll" ADD [EAX], AL ADD [EAX+0x0], BH DB 0x0 DB 0x65 DB 0x73 [10:14:41] 08/17 matching "spoolsv.exe" [10:15:24] 10/17 matching "svchost.exe" [10:15:47] 11/17 matching "msmsgs.exe" [10:16:06] 12/17 matching "svchost.exe" [10:16:38] 13/17 matching "svchost.exe" [10:17:08] 14/17 matching "winlogon.exe" [10:18:03] 15/17 matching "services.exe" [10:18:19] 16/17 matching "lsass.exe" [10:19:15] Module difference @ 0x74414320 "\WINDOWS\system32\samsrv.dll" ADD [EAX], AL JO 0x743bffb4 ADD [EAX], AL ADC AL, 0xc ADD [EAX], AL OR AL, 0xde ADD [EAX], AL INTO [10:19:15] Module difference @ 0x74414546 "\WINDOWS\system32\samsrv.dll" ADD [EAX], AL ADD [EAX], AL ADD [EAX], AL DB 0xff ADD [EAX], AL DB 0xff DB 0x0 DB 0xff [10:19:16] Module difference @ 0x76f411bf "\WINDOWS\system32\wldap32.dll" ADD [EAX], AL ADD AL, CH DB 0x3e JAE 0x76f2000f DB 0xc [10:19:17] Module difference @ 0x77cff169 "\WINDOWS\system32\rpcrt4.dll" DB 0x3 MOV AL, [0x49ff5965] DB 0x35 DB 0xa1 IN AL, 0x3a [10:19:20] 17/17 matching "System" </code></pre> <p>If i try ans also compare the executable image of the process I recieve even more noise</p> <pre><code>[12:10:13] 01/17 matching "csrss.exe" [12:10:22] Instruction missmatch @ 0x5302db (13) ADD [EAX-0x671ea561], CH ADD AL, CH RETF AND AL, 0x98 AND ECX, 0x2b0003 CWDE [12:10:22] Instruction missmatch @ 0x53033b (6) ADD [EBP+0x0], AH ADD [EBX+0x0], DH [12:10:22] Instruction missmatch @ 0x5304c7 (9) ADD [EAX], AH ADD AL, CH ADC EAX, 0x95d8bc65 ADD [EAX], AL TEST AL, 0xe1 ADD [EAX], AL [12:10:22] Instruction missmatch @ 0x53065d (2) ADD [EBX], AL ADD [EAX+EAX], AL [12:10:22] Instruction missmatch @ 0x5307bb (6) ADD [EBX+0x0], DH ADD AL, CH [12:10:22] Instruction missmatch @ 0x5307c5 (7) ADD [EAX+EAX-0x439c6800], AH ADD [ECX+0x0], BL [12:10:22] Instruction missmatch @ 0x530864 (1) STD FLD DWORD [EAX] [12:10:22] Instruction missmatch @ 0x53086d (4) ADD [EAX+EAX+0x18], AL ADD [EDX+0x60551800], AL [12:10:22] Instruction missmatch @ 0x53096c (13) CMP [EBP+0x65], CH MOV AL, [0x70e18a84] MOV ESP, 0xe1a895d8 LOOPZ 0x530072 ADD EAX, 0xd0000300 ADD EAX, [EAX] </code></pre> <p>Each dump has been created on the same Windows XP VM. Any idea on how to filter that noise? Would be thankful for any hint and sorry for my bad english.</p>
Differences in memory dumps of executable data
|executable|memory|
<p>If you are looking to better understand the basic principles of PUFs, I would warmly recommend the <a href="http://security1.win.tue.nl/~bskoric/physsec/files/LectureNotes_2IC35_v1.4.pdf" rel="nofollow">lecture notes of Boris Skoric</a>. Chapter 5 is all about PUFs: history, examples, applications and entropy. Some of the things presented there are also formalized, which requires a decent level of information theory knowledge.</p>
3040
2013-11-15T09:39:10.917
<p>I would like to know how are achieved PUFs (Physicaly Unclonable Functions) and if there is a way reverse these hardware electronic components ?</p> <p>Recent papers such as "<a href="http://nedos.net/fdtc2013.pdf" rel="nofollow">Invasive PUF Analysis</a>" present techniques to extract information from PUFs but, I would like to better understand the basic principles of PUFs and what are the problems when trying to clone it.</p>
How are achieved PUFs (Physicaly Unclonable Functions) and can we workaround?
|obfuscation|hardware|
<p>After seeing the test files (thanks!):</p> <p>... too easy :)</p> <p>In <code>value.hex</code>, the first dword appears to be a total file length; the second dword the data length. The third and fourth dwords may be flags of some kind and do not appear to point to data. This lops off the first 16 bytes, hence my guess the 2nd dword is 'data length'.</p> <p>Right after this header comes that familiar pair <code>78 9C</code> again, so I brought out my zlib decoder wrapper. Unpacking <code>value.hex</code>, starting at offset 0x10, and using <code>TINFL_FLAG_PARSE_ZLIB_HEADER</code> (as I am using <code>miniz.c</code> for eaze) gave me a correct unpacking result and a data file of 33,208 bytes long.</p> <p>Inspecting this with 0xED shows this file consists entirely out of <em>double values</em> (8 bytes each); the first few are</p> <pre><code>0.991932 0.991931 0.991932 0.991932 0.991932 0.991933 </code></pre> <p>(okay, there appears to be a pattern here -- the devil is in the last few digits which 0xED doesn't show, they are not all the same values).</p> <p>The second file, <code>index.dat</code>, also unpacks correctly and gives another long list of double values, this time clearly going up:</p> <pre><code>0.0000 0.0082 0.0163833 0.0245667 </code></pre> <p>I didn't cross-reference these values against the XLS file you provided, I assume you can work that out from here.</p> <p>I only unpacked until I got a positive result back, I did not check if there are more data packets (compressed or otherwise) following the first one and you should verify using the end result of your own favourite decompression routine.</p> <hr> <p>Just as I was heading to bed, it struck me that the 3rd and/or 4th dwords in the header (weren't they the same anyway?) may be the 'unpacked' length.</p>
3042
2013-11-15T21:36:18.173
<p>I have a proprietary file format that is a compressed database file. This database file has a few dozen tables. Each of these tables only have a few records, many of them don't have any records at all. A few of these tables contain fields that are stored as blobs of hex data. These blobs account for 99% of the disk space of the overall database file.</p> <p>As far as I can tell, these blobs are not compressed data (by using unix 'file' command). I have tried finding known values in these blobs by exporting values from the proprietary software, converting to hex and searching for that value in the database file. So far I haven't been able to find any matches. The problem is that the software can export in a myriad of formats and I'm not sure which one (if any) the data would be stored in.</p> <p>Most of the tables contain checksum fields, which I believe, are responsible for my inability to edit the blobs and see what changes in the proprietary software. This combined with the fact that I cannot directly change the values that I wish to extract from the proprietary files leaves me in a difficult position.</p> <p>Does anybody know any tricks for trying to tease out time series data from binary data?</p> <p><strong>Edit</strong> <a href="http://pastelink.me/dl/4e6d0c#sthash.Co5cEOJS.dpuf" rel="nofollow">This zip file</a> contains 2 hex blobs (index and value) from the decompressed database and the same data as it is exported from the program.</p>
Decoding a blob
|binary-analysis|
<p>One thing that's important to realize is that standard runtimes are commonly treated as any other code or library. How compiled code is linked and loaded depends a lot on the platform. .net is very different from c++.</p> <p>Basically functions have at least three major ways of showing up inside of your binary: </p> <h3>Dynamically linked</h3> <p>This when a function is kept inside of a dynamically loaded library and is the case for many of the functions you'd get through <i>windows.h</i> as you said. Identifying these are generally easy as they're functionally separated and named either through their string name, decorated or undecorated, or through ordinal. Most disassemblers should handle dynamically linked standard functions without issues. This is the most common default for various compiler, runtime and platform options. This depends on the compiler being able to move the function to a separate compilation unit, which is commonly not the case with many templates in C++. Calling conventions are respected and prologue and epilogue are present.</p> <h3>Statically linked and not inlined</h3> <p>This is when a function is included inside of your binary but is functionally separate from other functions. This can be identified using a set of signatures of some form. IDA uses <a href="https://www.hex-rays.com/products/ida/tech/flirt/in_depth.shtml">FLIRT signatures</a>. Something like <a href="http://www.zynamics.com/bindiff.html">bindiff</a> uses a more varied and complex approach to comparing functions, for instance using flow graph analysis. Usually parameters are passed according to calling convention unless the binary is built with <a href="https://en.wikipedia.org/wiki/Link-time_optimization">link time optimization</a> in which case the compiler is free to pass arguments in any order it feels like. If you're lucky the binary contains debug information which could allow for significant recovery of function names and parameters.</p> <h3>Statically linked and inlined</h3> <p>This is when a function is included inside of your binary and is not functionally separate from other functions. This generally happens when a function is small enough that the overhead to do a function call is expensive enough to warrant repeating the same function in the calling function or if the function is only called in very few locations, usually once, in the binary. This means that the disassembler has very little information to know that this was originally a separate function and debug information will not help much with recovery of these functions. There will be no function prologue or epilogue. Opcodes can be heavily rearranged/ The only tool I'm aware of that does very limited recovery of this sort of function is Hex-Rays decompiler, not diassembler. I've seen binaries with link time optimization where a function ends up being a massive result of hundreds of nested inlined functions, resulting in a function with thousands of branches. Separating them back out into their original functions would have been a very useful operation to have.</p> <h3>Finally</h3> <p>There is no solution that solves all the cases mentioned above. Hex-Rays IDA combined with their decompiler and BinDiff probably provides the most complete solution I know of. On very <a href="https://en.wikipedia.org/wiki/Reflection_%28computer_programming%29">reflective platforms</a> such as .net, java or python this isn't much of an issue. </p>
3044
2013-11-16T14:43:44.000
<p>Do disassemblers detect the use of C/C++ standard functions and specify them in the output code, adding the <code>#include</code> line to the appropriate header file (such as <code>stdio.h</code> or even <code>windows.h</code>)?</p> <p>If not, does the whole big library is being recognized as the developer's own business-logic code, and written fully? Aren't the standard libraries known binary sequences (or can be processed some way to be known, as a binary-code can be different because of addressing)?</p> <p>Do you know disassemblers that do detect standard functions and properly #include them in the output?</p>
Do disassemblers detect standard functions?
|ida|disassembly|disassemblers|
<p>IDA introduced &quot;Variable Length Structures&quot; and describe the usage of it with a very straight forward <a href="https://www.hex-rays.com/products/ida/support/tutorials/varstr/" rel="nofollow noreferrer">tutorial</a>.</p> <p>In short, you need to make sure the &quot;flexible&quot; item is the last item of the struct, and define it as an array of size 0. To do this, define a new struct member <code>char Name</code>, click on it and press <kbd>*</kbd>. Then, set the &quot;Array size&quot; to 0.</p> <p>Now, the shortcoming is that IDA won't look for a null terminator to define the string, but instead, you'd have to tell it its size every time you want to use the structure.</p>
3047
2013-11-17T14:38:34.517
<p>Normally I struct is a fixed size. Is it possible to define a structure which contains an element which has different sizes?</p> <p>To illustrate what I mean is this.</p> <p>The layout of the data in the file looks like this:</p> <pre><code>ID WORD 0 FunctionPtr DWORD OFFSET Fkt Name db 'Name of the function',0 align 4 </code></pre> <p>'Name' is now a C-String which is as long until it reaches the 0-byte at the end and then follows the align instruction. So is it possible to tell IDA that the structure is including the string, no matter how long it is?</p>
Creating a struct in IDA which contains a cString?
|ida|struct|
<p>The data at virtual address <code>00400174</code> is the <code>IMAGE_DATA_DIRECTORY</code> entry for <code>IMAGE_DIRECTORY_ENTRY_RESOURCE</code>.</p> <p>Read the PE/COFF specification at <a href="http://download.microsoft.com/download/9/c/5/9c5b2167-8017-4bae-9fde-d599bac8184a/pecoff_v83.docx">http://download.microsoft.com/download/9/c/5/9c5b2167-8017-4bae-9fde-d599bac8184a/pecoff_v83.docx</a>, and use either a hex editor or a PE editor to navigate through the PE header content.</p>
3048
2013-11-17T15:49:57.383
<p>According to IDA the file I'm inspecting has <code>imagebase 0x400000</code>. The first data I can see starts at <code>0x401000</code> but the program reads some data which is at <code>00400174</code>.</p> <p>When I put a data access breakpoint there, it breaks in <code>ntdll!RtlpImageDirectoryEntryToData32</code> which probably means that there is some process data (using Windows 7). Where can I find some information as to what exactly is there stored?</p> <p>From the call stack it looks like there should be some resource data as there is <code>FindResource</code> among other things.</p> <pre><code>ChildEBP RetAddr 0012f998 7c910385 ntdll!RtlpImageDirectoryEntryToData32+0xf 0012f9b8 7c9118c0 ntdll!RtlImageDirectoryEntryToData+0x57 0012fa84 7c911db7 ntdll!LdrpSearchResourceSection_U+0x34 0012faa0 7c80ad8b ntdll!LdrFindResource_U+0x18 0012faf4 7e419dbb kernel32!FindResourceExW+0x64 0012fb18 7e42c924 user32!LoadStringOrError+0x31 0012fb3c 00404bcd user32!LoadStringA+0x1c </code></pre>
What data before the code segment in PE files?
|windows|pe-resources|
<p>The answer is a clear NO. Whatever protection you do could still be improved if so desired.</p> <p>The question is a little bit unclear, as there are many different protections possible. - protect against reverse engineering - protect against executing on the wrong computer - protect against copying - protect against modifications. - ... whatever method is best for one purpose may not be best for some other purpose. When you know what you are against, you are really in a better situation to make a good protection.</p> <p>You could also say there is no perfect protection, as any protection can be broken. But maybe that doesn't matter: maybe the time to brake a particular protection with todays computer-speeds is similar to the age of the universe? Maybe the protection is just good enough to protect your executable until the protection is no more needed. Maybe it is just good enough so that an attacker gives up just before suceeding? Maybe it makes it just hard enough so that an attacker chooses to work on an another program. Maybe it is broken within minutes after a release...</p> <p>In practice: Unless you are a seasoned protection engeneer or very good hacker and reverse engineer, your protection will be broken in surprisingly short time. On the other side, if you understand what you are doing: Know what compilers generate, know what is hard to reverse engineer, know the program to be protected, know the machine architecture, build the protection in from the beginning, or use some professional protection tools, understand the applications performance requirements, you can keep more or less everybody out. There is some debate about that. Before a protection finally is cracked, protectors err by thinking is too hard; reverse engineers err by thinking it is too easy. Actually when you create high-end protections you might never know, as attackers for high-end stuff won't tell you if/when they succeeded.</p> <p>There are plenty of tools to help making protections, the price range for such tools goes from free to astronomical. I don't know whether this discussion list allows me to name companies. If you want to find out mine, or any other, google for tamper-proofing.</p>
3049
2013-11-17T17:47:04.860
<p>I tried UPX, ASPack and other protectors, but it seems that my application has a weak protection.</p> <p>What is the best method for protecting your program? Using packers or something else?</p> <p>At least for a beginner; because I guess there is no perfect protection in the planet an expert can't reverse.</p>
Is there a perfect method for protecting executable files?
|packers|copy-protection|
<p>Anti-attaching depends heavily on the fact that windows creates a remote thread in the target process. What is specific about this thread is usually used to detect attaching.</p> <p>For example: The entry point Windows chooses for the attaching thread is by default the "DbgUiRemoteBreakin" function. Anti-attaching tricks usually hook this function or its sibling, the "DbgBreakPoint" function.</p> <p>Also, The fact that the attaching thread (like most normal threads) will have the associated TLS callbacks called is also exploited to detect attaching.</p> <p>Debug blocks, NtContinue, ThreadHideFromDebugger etc.</p> <p><a href="http://waleedassar.blogspot.de/2011/12/debuggers-anti-attaching-techniques.html">http://waleedassar.blogspot.de/2011/12/debuggers-anti-attaching-techniques.html</a> <a href="http://waleedassar.blogspot.de/2011/12/debuggers-anti-attaching-techniques_11.html">http://waleedassar.blogspot.de/2011/12/debuggers-anti-attaching-techniques_11.html</a> <a href="http://waleedassar.blogspot.de/2011/12/debuggers-anti-attaching-techniques_13.html">http://waleedassar.blogspot.de/2011/12/debuggers-anti-attaching-techniques_13.html</a> <a href="http://waleedassar.blogspot.de/2012/02/debuggers-anti-attaching-techniques_15.html">http://waleedassar.blogspot.de/2012/02/debuggers-anti-attaching-techniques_15.html</a> <a href="http://waleedassar.blogspot.de/2012/11/sizeofstackreserve-as-anti-attaching.html">http://waleedassar.blogspot.de/2012/11/sizeofstackreserve-as-anti-attaching.html</a></p>
3057
2013-11-19T20:14:48.373
<p>Sometimes I've tried to attach Ollydbg to applications those have some protection against debuggers, but I have never coded any of these applications and did not see this protection in many applications... So it looks like it is not hard to bypass this, however I am curious and never tried it before. How do you do it guys? (at least some examples on some simple program).</p> <p>Thanks in advance.</p>
How to attach debugger to app if it has protection against attaching?
|anti-debugging|
<p>Add your struct in the function's stack view:</p> <ol> <li>With your cursor in the function's disassembly view, press <kbd>Ctrl</kbd>+<kbd>K</kbd> to open the stack view.</li> <li>In the stack view, ensure that enough function arguments exist to get to at least <code>+00000010</code> in the stack. Use <kbd>D</kbd> to add more function arguments as necessary.</li> <li>Position your cursor on the <code>+00000010</code> line in the stack view and press <kbd>Alt</kbd>+<kbd>Q</kbd> to specify <code>my_struct</code> at that offset.</li> </ol>
3061
2013-11-20T12:57:46.693
<p>I have a small function that is given a <code>struct</code> as parameters. The <code>struct</code> looks to something like this:</p> <pre><code>struct my_struct { short a; unsigned int b; unsigned int c; }; </code></pre> <p>Taking care of the alignment I build the following <code>struct</code> in IDA:</p> <pre><code>field_0 +0x0 field_1 +0x4 field_2 +0x8 </code></pre> <p>The compiler builds it so that it takes <code>rbp+0x10</code> as the first field in the <code>struct</code>, <code>rbp+0x14</code> as the second and so on. The problem now arises because if I try to apply the pre-defined IDA <code>struct</code> to the instructions, I always get something like <code>[rbp+struct.field_0+0x10]</code>. This get more complicated if there is actually something in my struct at <code>+0x10</code>, because then it just shows <code>[rbp+struct_fieldX]</code> (which is wrong).</p> <p>The question is: <em>Is there a way to tell IDA (I'm using 6.3) to apply the <code>struct</code> with an offset of <code>0x10</code>?</em> </p> <p>The dirty trick for this simple case is to create a <code>struct</code> that has 2 <code>size_t</code> dummy fields for the <code>RIP</code> and <code>SFP</code>, but that does not seem to be right way to go here.</p>
IDA Pro: use structs on parameters
|ida|struct|
<p>This is code from the <a href="https://www.kernel.org/doc/Documentation/ABI/stable/vdso">vDSO</a> which is mapped by the kernel into every process, not from the wget binary. You could probably figure it out by inspecting the <code>/proc/&lt;pid&gt;/maps</code> file.</p> <p>Here's what I have in IDA for <code>gettimeofday</code> from it:</p> <pre><code>.text:FFFFFFFFFF700D17 mov rbx, 0FFFFFFFFFFDFF000h .text:FFFFFFFFFF700D1E lsl r11d, eax .text:FFFFFFFFFF700D22 xor r15d, r15d .text:FFFFFFFFFF700D25 mov r10d, r11d .text:FFFFFFFFFF700D28 mov r9d, ds:0FFFFFFFFFF5FF080h .text:FFFFFFFFFF700D30 test r9b, 1 .text:FFFFFFFFFF700D34 jnz loc_FFFFFFFFFF700FDF .text:FFFFFFFFFF700D3A mov rax, ds:0FFFFFFFFFF5FF0A8h .text:FFFFFFFFFF700D42 mov r13d, ds:0FFFFFFFFFF5FF088h .text:FFFFFFFFFF700D4A mov [rdi], rax .text:FFFFFFFFFF700D4D mov edx, ds:0FFFFFFFFFF5FF088h .text:FFFFFFFFFF700D54 mov r14, ds:0FFFFFFFFFF5FF0B0h </code></pre> <p>So it seems PIN's disassembler chose to not sign-extend addresses (which are encoded in 4 bytes in the opcodes).</p>
3063
2013-11-20T19:46:02.990
<p>In fuzzing (with Pintool) to get examining execution traces of the program, here it is wget. I get some weird instructions, following is a piece extracted from a (very long) trace:</p> <pre><code>RIP register instruction 0x7fff751fed17 mov rbx, 0xffffffffffdff000 0x7fff751fed1e lsl r11d, eax 0x7fff751fed22 xor r15d, r15d 0x7fff751fed25 mov r10d, r11d 0x7fff751fed28 mov r9d, dword ptr [0xff5ff080] 0x7fff751fed30 test r9b, 0x1 0x7fff751fed34 jnz 0x7fff1fdb4fdf 0x7fff751fed3a mov rax, qword ptr [0xff5ff0a8] 0x7fff751fed42 mov r13d, dword ptr [0xff5ff088] 0x7fff751fed4a mov qword ptr [rdi], rax 0x7fff751fed4d mov edx, dword ptr [0xff5ff088] 0x7fff751fed54 mov r14, qword ptr [0xff5ff0b0] </code></pre> <p>To me, they are quite weird. First, some of them access directly to the memory, that means some addresses, e.g. <code>0xff5ff080</code>, <code>0xff5ff0a8</code> have been hard-coded into the program. Second, I find them nowhere in the loaded libraries and wget itself. Third, even more weird, by passing the parameter <code>(IARG_MEMORYREAD_EA)</code> to get the virtual addresses of the accessed memories. I got the addresses, e.g. <code>0xffffffffff5ff080</code>, <code>0xffffffffff5ff0a8</code>, etc, and all of them do not belong to the program's memory space.</p> <p>Coud anyone give me some suggestions ?.</p>
Weird instructions
|fuzzing|memory|instrumentation|
<p>The way this usually works in my experience is that if you have a documentation need outside of the IDB database it's generally because you're trying to share information with other reverse engineers. For this, you may want to take a look at <a href="http://www.idabook.com/collabreate/" rel="nofollow noreferrer">collabREate</a> or the <a href="http://thunkers.net/~deft/code/toolbag/" rel="nofollow noreferrer">IDA toolbag</a>. The unfortunate truth is that a lot of these projects tend to slow down or die completely due to a lack of interest from the original authors.</p> <p>Now if your problem is completely centered around documentation, what I also find fairly common is to have header files with the function, class and structure definitions in them with <a href="http://www.doxygen.nl/" rel="nofollow noreferrer">doxygen-</a> or <a href="http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html" rel="nofollow noreferrer">JavaDoc-</a>formatted comments in them. You then use doxygen to generate automatic documentation and class diagrams. This way the documentation becomes completely living, self-maintaining and easily navigated.</p>
3069
2013-11-21T13:39:24.443
<p>I've been reversing a regularly updated application with various tools (mosty IDA, Olly) for a while now, and I always wondered how to document my findings. For example function names, static variables, relations, namespaces, fields, etc...maybe even changes trough version changes, but that's just an extra.</p> <p>The best thing I came up with is a local MediaWiki, where I create a new page/definition for every function, and stuff, but it's obviously pain in the ass, nearly impossible to maintain. There must be some industry standard right? I wonder if you guys know / use any tool like for this issue.</p> <p>Edit: Here is the structure I'm using now with in the Wiki : <img src="https://i.stack.imgur.com/N4UBs.png" alt="MediaWiki Documentation structure"></p> <p><strong>If you know another solution, I'm looking forward for your answer as well :)</strong></p>
Documenting reversed application
|ida|tools|history|
<p>Struct: <kbd>Alt</kbd>+<kbd>Q</kbd></p> <p>Array: Numeric keypad <kbd>*</kbd></p>
3081
2013-11-24T01:32:01.807
<p>As the title says im a bit lost on how to get something in the data section to be recognized as a struct or an array of structs or an array of strings etc.</p> <p>Cheers</p>
In IDA how can I define a data address as a struct and array of datatype
|ida|struct|
<p>The IDAScope plugin has similar functionality to rename functions based on the Windows API functions they are calling. You can find a standalone script here that does that <a href="http://hooked-on-mnemonics.blogspot.fr/2012/06/automated-generic-function-naming-in.html">http://hooked-on-mnemonics.blogspot.fr/2012/06/automated-generic-function-naming-in.html</a> it should give you an idea how to implement what you are looking for.</p>
3090
2013-11-25T21:20:26.137
<p>I'ld like to know how to bulk rename functions in IDA, based on some condition.</p> <p>Example: Rename all functions to Foo_XYZ where the function accesses a certain static variable, for example : dword_12345.</p> <p>This would help me a lot, because I know that address would be only accessed from functions that can be associated with some logic/functionality in the application.</p>
Automatic function naming
|ida|static-analysis|memory|strings|functions|
<p>It's possible since <a href="http://hopperapp.tumblr.com/post/76212665426/hopper-disassembler-v3-at-last-its-almost" rel="noreferrer">Hopper v3</a>, under <code>File &gt; Read Debug Symbols File...</code></p> <p><img src="https://i.stack.imgur.com/kQ2vf.png" alt="screenshot"></p>
3098
2013-11-28T10:55:23.727
<p>Can I load dSYM symbols into Hopper? (I searched extensively in the menus etc. but couldn't find such an option)</p> <p>Context: I want to see how a program I created using Xcode was compiled into machine code using Hopper to view the machine code. My program is stripped during build but I do have its symbols in a <code>.dSYM</code> package.</p>
Load dSYM symbols in Hopper
|osx|hopper|symbols|
<p>This is the Import Address Table, which contains the virtual addresses for the imported functions.</p> <p>Since the DLLs have been loaded at different addresses (7bxxxxxx in one case, 76xxxxxx in the other), the Import Address Table is filled with different DWORD values.</p>
3100
2013-11-28T18:11:44.943
<p>Few days after asking the question I realised I misinterpreted my original findings. It seems .rdata section on file is copied directly to memory, but then first 36 bytes are overwritten by loader with IAT RVA. The erroneous question about added 96 bytes is result of me not noticing that the sequence of bytes I was checking in my tests is repeated on the file. </p> <p>What I just said still might not be 100% accurate. The investigation will continue for the next few days.</p> <h2>Original Question</h2> <p>I'm trying to write a program to analyse Windows executables. I was assuming that sections in executable file are directly copied to memory. I have noticed strange behaviour in several programs. </p> <p>One example is <code>crackme12.exe</code>. When I check with debugger <code>.rdata</code> section loaded into memory, I can see that for some reason 96 bytes have been added at the beginning of a section loaded into memory that was not there in the executable file. I have spent 2 days trying to read Windows executable documentation, but I can't find explanation why is it happening.</p> <h2>Additional Info</h2> <p>I'm trying to load this file on Linux under Wine. Debugger I use is called OllyDbg. File download link: <a href="http://www.reversing.be/easyfile/file.php?show=20080602192337264" rel="nofollow">http://www.reversing.be/easyfile/file.php?show=20080602192337264</a></p> <p>I'm trying to write the program in Common Lisp. This is the link to the test file: <a href="https://github.com/bigos/discompiler/blob/master/test/lisp-unit.lisp" rel="nofollow">https://github.com/bigos/discompiler/blob/master/test/lisp-unit.lisp</a></p> <p>I have tried to load the same crackme under Windows and got another surprise. Screen-shot at <a href="https://github.com/bigos/discompiler/blob/fc3d8432f10c8bd5dfd14a8b5e2b113331db15df/my-reference/images/differences%20between%20lin%20and%20win.png" rel="nofollow">https://github.com/bigos/discompiler/blob/fc3d8432f10c8bd5dfd14a8b5e2b113331db15df/my-reference/images/differences%20between%20lin%20and%20win.png</a> shows Windows and Wine side by side. </p> <p>From address x402060, highlighted in the screen-shot in red shows data copied from section on the file. On loading operating system inserted 96 bytes. To my surprise Wine loader has inserted different data. When you compare differences between Wine and Windows you will see that first two lines differ. Can somebody enlighten me what is happening?</p> <h2>Conclusion</h2> <p>It turns out that Import Table RVA and IAT RVA were placed at addresses between x402000 and x402060. So it looks like loader copies section to memory after those tables.</p> <p>I have added some code to my little program and got following output:</p> <p>RVAs: (((320 "Import Table RVA" 8228) (324 "Import Table Size" 60) "in memory from" "402024" "to" "402060") ((328 "Resource Table RVA" 16384) (332 "Resource Table Size" 1792) "in memory from" "404000" "to" "404700") ((408 "IAT RVA" 8192) (412 "IAT Size" 36) "in memory from" "402000" "to" "402024"))</p>
Loading Windows executable - unexpected data appended at beginning sections after loading in memory
|windows|static-analysis|pe|executable|
<p>The surprising part for me is <code>objdump</code> can recognize <em>anything</em> in a PE file. According to <a href="http://en.wikipedia.org/wiki/Portable_Executable" rel="noreferrer">Wikipedia</a>,</p> <blockquote> <p>.. PE is a modified version of the Unix COFF file format. PE/COFF is an alternative term in Windows development.</p> </blockquote> <p>so apparently there is just enough overlap in the headers to make it work (at least partially). The basic design of one is clearly based on the other, but after that they evolved separately. Finding the exact differences at this point in time might well be a pure academical exercise.</p> <p>Yes: in a DLL, the export directory <em>is</em> what you are looking for. Here is a screen grab from <a href="http://www.dependencywalker.com" rel="noreferrer">Dependency Walker</a> inspecting <code>comctl32.dll</code> (using VirtualBox 'cause I'm on a Mac):</p> <p><img src="https://i.stack.imgur.com/5CPMn.png" alt="Dependency Walker showing Exports"></p> <p>The field "E^" lists the exported function names and other interesting details.</p> <p>If you are in to Python: <a href="http://code.google.com/p/pefile/" rel="noreferrer"><code>pefile</code></a> has been mentioned as a library that can access PE parts, but then again PE has been so long around there is no end to good descriptions of all the gory low level details of all its headers and structures. Last time I felt inspecting some Windows program, I used these descriptions to write a full set of PE import/export C routines from scratch (.. <em>again</em>, I should add -- this way I can have return it the exact data I want in exactly the required format).</p> <p>IDA Pro seems to be the utility of choice for most disassembling jobs, and last time I used that it did a good job of loading both Import and Export directories, although it didn't provide a concise list of all functions.</p>
3101
2013-11-28T18:47:04.807
<p>I am a man full of contradictions, I am using Unix and, yet, I want to analyze a Microsoft Windows DLL.</p> <p>Usually, when looking for symbols in a dynamic or static library in the ELF World, one can either use <code>nm</code> or <code>readelf</code> or even <code>objdump</code>. Here is an example with <code>objdump</code>:</p> <pre><code>$ objdump -tT /usr/lib/libcdt.so /usr/lib/libcdt.so: file format elf64-x86-64 SYMBOL TABLE: no symbols DYNAMIC SYMBOL TABLE: 0000000000000cc8 l d .init 0000000000000000 .init 0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 free 0000000000000000 w D *UND* 0000000000000000 _ITM_deregisterTMCloneTable 0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 memcmp 0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 strcmp 0000000000000000 w D *UND* 0000000000000000 __gmon_start__ 0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 malloc 0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 realloc 0000000000000000 w D *UND* 0000000000000000 _Jv_RegisterClasses 0000000000000000 w D *UND* 0000000000000000 _ITM_registerTMCloneTable 0000000000000000 w DF *UND* 0000000000000000 GLIBC_2.2.5 __cxa_finalize 0000000000000ec0 g DF .text 0000000000000097 Base dtclose 0000000000204af8 g DO .data 0000000000000008 Base Dtorder 0000000000204af0 g DO .data 0000000000000008 Base Dttree ... cut ... </code></pre> <p>So, we have all exported function name from reading this dynamic library. But, lets try it with a DLL:</p> <pre><code>$ objdump -tT SE_U20i.dll SE_U20i.dll: file format pei-i386 objdump: SE_U20i.dll: not a dynamic object SYMBOL TABLE: no symbols DYNAMIC SYMBOL TABLE: no symbols </code></pre> <p>As you see, <code>objdump</code> fail to extract the exported symbols from the DLL (and so do <code>nm</code>). But, if I can see a few thing more if I do:</p> <pre><code>$ objdump -p SE_U20i.dll SE_U20i.dll: file format pei-i386 Characteristics 0xa18e executable line numbers stripped symbols stripped little endian 32 bit words DLL big endian ... clip ... There is an export table in .edata at 0x658000 The Export Tables (interpreted .edata section contents) Export Flags 0 Time/Date stamp 0 Major/Minor 0/0 Name 0025803c SE_U20i.dll Ordinal Base 1 Number in: Export Address Table 00000002 [Name Pointer/Ordinal] Table 00000002 Table Addresses Export Address Table 00258028 Name Pointer Table 00258030 Ordinal Table 00258038 Export Address Table -- Ordinal Base 1 [ 0] +base[ 1] 23467c Export RVA [ 1] +base[ 2] 233254 Export RVA [Ordinal/Name Pointer] Table [ 0] DoResurrection [ 1] Initialize ... clip ... </code></pre> <p>So, the <em>export table</em> seems to be what we are looking for (not sure about it). But it is drown among a lot of other information (the option <code>-p</code> display really a LOT of lines).</p> <p>So, first, is the export table what I am looking for to know what are the functions and variables that exported by the DLL ?</p> <p>Second, why did <code>objdump</code> present differently the exported symbols in the case of ELF and PE ? (I guess there is some technical differences between exported symbols in ELF and PE and that confusing both would be extremely misleading, but I would like to know in what they differ).</p>
Looking for exported symbols in a DLL with objdump?
|disassembly|dll|objdump|
<p>Some plugins like <a href="http://reflexil.net/">reflexil</a> provide this functionality.</p>
3105
2013-11-29T01:56:49.630
<p>I have some obfuscated C# .NET code I want to analyze.</p> <p><img src="https://i.stack.imgur.com/SNylK.png" alt="obfuscated C# code"></p> <p>Is it possible to rename those obfuscated symbols? So I can more easily track them? Like IDA Pro can work with renaming functions and so forth.</p>
Rename obfuscated names with .NET Reflector?
|tools|obfuscation|.net|c#|
<p>Unfortunately, it seems to be not supported (a bug?). See this <a href="https://sourceware.org/bugzilla/show_bug.cgi?id=13584" rel="nofollow">bug report</a> in <code>gdb</code> bugzilla.</p> <p>I am not aware of any recent update concerning this bug...</p>
3121
2013-12-02T16:35:14.583
<p>My question is quite straight forward: is there a possibility to tell gdbserver to follow the child when forking like</p> <pre><code>set follow-fork-mode child </code></pre>
Is there something like follow-fork-mode for gdbserver?
|gdb|
<p>First of all, I have bad news for you ! Doug Lea's malloc is almost no more used in any C library implementation (even if understanding <code>dlmalloc</code> can help a lot to understand new ones).</p> <p>The new implementation that is most widely used is <code>ptmalloc2</code> and the best way to learn about it is... to read the code... So, if you are using a Debian(-like) distribution, just like me, you just need to get the source code of the libc like this:</p> <pre><code>$&gt; apt-get source libc6 </code></pre> <p>Note that the <a href="http://lwn.net/Articles/488778/" rel="nofollow noreferrer">glibc is no more</a> and has been subsumed by the <a href="http://www.eglibc.org/home" rel="nofollow noreferrer">eglibc project</a>. The Debian distribution switched to eglibc some time ago (see <a href="http://blog.aurel32.net/47" rel="nofollow noreferrer">here</a> and <a href="http://lwn.net/Articles/332000/" rel="nofollow noreferrer">there</a> and even on the <a href="http://packages.qa.debian.org/g/glibc.html" rel="nofollow noreferrer">glibc source package page</a>). So, the implementation of <code>malloc</code> has changed considerably (and some security safeties have been added since <code>dlmalloc</code>).</p> <p>But, let see what does look like the <code>malloc</code> implementation:</p> <pre><code>$&gt; cd eglibc-2.17/malloc/ $&gt; less malloc.c ... /* This is a version (aka ptmalloc2) of malloc/free/realloc written by Doug Lea and adapted to multiple threads/arenas by Wolfram Gloger. There have been substantial changesmade after the integration into glibc in all parts of the code. Do not look for much commonality with the ptmalloc2 version. ... </code></pre> <p>As I said, the algorithm used here is <code>ptmalloc2</code> (POSIX Threads Malloc), but with significant modifications. So, you'd better read the code to know better about it.</p> <p>But, to sum up a bit, the heap memory is managed through memory chunks which are prefixed by meta-data gathering these information (I am just quoting comments that are in the <code>malloc.c</code> source file, refer to the whole file for more):</p> <pre><code>/* malloc_chunk details: (The following includes lightly edited explanations by Colin Plumb.) Chunks of memory are maintained using a `boundary tag' method as described in e.g., Knuth or Standish. (See the paper by Paul Wilson ftp://ftp.cs.utexas.edu/pub/garbage/allocsrv.ps for a survey of such techniques.) Sizes of free chunks are stored both in the front of each chunk and at the end. This makes consolidating fragmented chunks into bigger chunks very fast. The size fields also hold bits representing whether chunks are free or in use. An allocated chunk looks like this: chunk-&gt; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Size of previous chunk, if allocated | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Size of chunk, in bytes |M|P| mem-&gt; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | User data starts here... . . . . (malloc_usable_size() bytes) . . | nextchunk-&gt; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Size of chunk | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Where "chunk" is the front of the chunk for the purpose of most of the malloc code, but "mem" is the pointer that is returned to the user. "Nextchunk" is the beginning of the next contiguous chunk. Chunks always begin on even word boundries, so the mem portion (which is returned to the user) is also on an even word boundary, and thus at least double-word aligned. Free chunks are stored in circular doubly-linked lists, and look like this: chunk-&gt; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Size of previous chunk | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ `head:' | Size of chunk, in bytes |P| mem-&gt; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Forward pointer to next chunk in list | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Back pointer to previous chunk in list | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Unused space (may be 0 bytes long) . . . . | nextchunk-&gt; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ `foot:' | Size of chunk, in bytes | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ The P (PREV_INUSE) bit, stored in the unused low-order bit of the chunk size (which is always a multiple of two words), is an in-use bit for the *previous* chunk. If that bit is *clear*, then the word before the current chunk size contains the previous chunk size, and can be used to find the front of the previous chunk. The very first chunk allocated always has this bit set, preventing access to non-existent (or non-owned) memory. If prev_inuse is set for any given chunk, then you CANNOT determine the size of the previous chunk, and might even get a memory addressing fault when trying to do so. Note that the `foot' of the current chunk is actually represented as the prev_size of the NEXT chunk. This makes it easier to deal with alignments etc but can be very confusing when trying to extend or adapt this code. The two exceptions to all this are 1. The special chunk `top' doesn't bother using the trailing size field since there is no next contiguous chunk that would have to index off it. After initialization, `top' is forced to always exist. If it would become less than MINSIZE bytes long, it is replenished. 2. Chunks allocated via mmap, which have the second-lowest-order bit M (IS_MMAPPED) set in their size fields. Because they are allocated one-by-one, each must contain its own trailing size field. */ </code></pre> <p>You can also refer to '<a href="https://csg.utdallas.edu/wp-content/uploads/2012/08/Heap-Based-Exploitation.pdf" rel="nofollow noreferrer"><em>Heap-Based Exploitation</em></a>' which is a talk from Scott Hand about heap management and overflow exploitation.</p> <p>Still, you have a lot of work to do to understand everything, I would have like to have more time to explain. But, I hope it helped you a bit to find ways to go deeper (downloading the source is really the key here).</p>
3127
2013-12-04T20:26:32.243
<p>A few days ago, I was wondering how one could teach himself heap-based overflow exploitation.</p> <p>So I searched through documentation, subsequently practicing what I read in order to have a better insight of how the heap works under Linux.</p> <p>We are told that the malloc() / free() function works around <a href="http://gee.cs.oswego.edu/dl/html/malloc.html">Doug Lea's memory allocator</a> but, in spite of the great explanation given by the link, I cannot figure things out as I debug my program.</p> <p>Given this example:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; int n = 5; int main(int argc, char** argv) { char* p; char* q; p = malloc(1024); q = malloc(1024); printf("real size = %d\n",*(((int*)p)-1) &amp; 0xFFFFFFF8); if(argc &gt;= 2) { strcpy(p, argv[1]); } free(q); printf("n = 0x%08X\n", n); free(p); return EXIT_SUCCESS; } </code></pre> <p>I would like to dump this structure in memory:</p> <pre><code>struct chunk { int prev_size; int size; struct chunk *fd; struct chunk *bk; }; </code></pre> <p>Here is my workflow:</p> <pre><code>geo@lilith:~/c/vuln_malloc$ gcc -o vuln vuln.c -m32 -ggdb geo@lilith:~/c/vuln_malloc$ gdb ./vuln GNU gdb (GDB) 7.4.1-debian Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt; This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". For bug reporting instructions, please see: &lt;http://www.gnu.org/software/gdb/bugs/&gt;... Reading symbols from /home/geo/c/vuln_malloc/vuln...done. (gdb) b 21 Breakpoint 1 at 0x804850f: file vuln.c, line 21. (gdb) r `perl -e 'print "A" x 1024'` Starting program: /home/geo/c/vuln_malloc/vuln `perl -e 'print "A" x 1024'` real size = 1032 Breakpoint 1, main (argc=2, argv=0xffffd414) at vuln.c:21 21 free(q); (gdb) x/10x q-4 0x804a40c: 0x00000409 0x00000000 0x00000000 0x00000000 0x804a41c: 0x00000000 0x00000000 0x00000000 0x00000000 0x804a42c: 0x00000000 0x00000000 (gdb) </code></pre> <p>Here I can see the size-field's value, which is 0x409. I can easily guess that the real size of my chunk is 0x409 &amp; 0xFFFFFF8 = 0x408 = 1032, as explained by the documentation (the three least significant actually define some flags). Then I run until the free() function is processed.</p> <pre><code>(gdb) b 22 Breakpoint 2 at 0x804851b: file vuln.c, line 22. (gdb) c Continuing. Breakpoint 2, main (argc=2, argv=0xffffd414) at vuln.c:22 22 printf("n = 0x%08X\n", n); (gdb) x/10x q-4 0x804a40c: 0x00020bf9 0x00000000 0x00000000 0x00000000 0x804a41c: 0x00000000 0x00000000 0x00000000 0x00000000 0x804a42c: 0x00000000 0x00000000 </code></pre> <p>Firstly I don't understand the new value - 0x20bf9 - at all, secondly I don't understand why there isn't any relevant values as regard the fd and bk pointers either.</p> <p>All of that stuff does not make much sense for me, that's why I was wondering wether you could give me some clues about all of this or not. Does the Doug Lea's implementation still exist in recent glibc versions, or...?</p>
Understanding the most recent heap implementation under Linux
|linux|exploit|buffer-overflow|software-security|
<p>I thought about this after work and realised that it was just going to be the data XOR-ed with the low bits off the offset. Based off that I got out a valid JPEG:</p> <pre><code>Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00000000 FF D8 FF E0 00 10 4A 46 49 46 00 01 01 00 00 01 ÿØÿà..JFIF...... 00000010 00 01 00 00 FF E1 00 34 45 78 69 66 00 00 4D 4D ....ÿá.4Exif..MM 00000020 00 2A 00 00 00 08 00 01 87 69 00 04 00 00 00 01 .*......‡i...... 00000030 00 00 00 1A 00 00 00 00 00 01 A4 01 00 03 00 00 ..........¤..... 00000040 00 01 00 01 00 00 00 00 00 00 FF E3 00 3A 4D 65 ..........ÿã.:Me 00000050 74 61 00 00 4D 4D 00 2A 00 00 00 08 00 03 C3 65 ta..MM.*......Ãe </code></pre>
3128
2013-12-05T05:46:41.430
<p>This might be a bit of a narrow question but I think it is interesting. HP Photo Creations has made a thumbnail file that seems to contain an obfuscated JPEG inside it. I'm not sure why they would bother to obfuscate it but each byte seems to be modified based off its offset:</p> <pre><code>Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00000000 FF D9 FD E3 04 15 4C 41 41 4F 0A 0A 0D 0D 0E 0E ÿÙýã..LAAO...... 00000010 10 10 12 13 EB F4 16 23 5D 61 73 7D 1C 1D 53 52 ....ëô.#]as}..SR 00000020 20 0B 22 23 24 2D 26 26 AF 40 2A 2F 2C 2D 2E 2E ."#$-&amp;&amp;¯@*/,-.. 00000030 30 31 32 29 34 35 36 37 38 38 9E 3A 3C 3E 3E 3F 012)456788ž:&lt;&gt;&gt;? 00000040 40 40 42 42 44 45 46 47 48 49 B5 A8 4C 77 03 2A @@BBDEFGHIµ¨Lw.* 00000050 24 30 52 53 19 18 56 7D 58 59 5A 53 5C 5E 9D 3A $0RS..V}XYZS\^.: </code></pre> <p>Where I would expect the first line to be something closer to:</p> <pre><code>00000000 FF D8 FF E0 00 10 4A 46 49 46 00 01 01 00 00 01 ÿØÿà..JFIF...... </code></pre> <p>Any ideas on what is going on here?</p> <p>Thanks in advance!</p>
Obfuscated JPEG
|file-format|
<p>Those functions are exported by IISUTIL.DLL. That is not a core Windows library, and thus wouldn't be documented in any "Windows Internals" references.</p>
3137
2013-12-06T23:57:32.587
<p>In <code>w3wp.exe</code>, <code>STRU</code> namespace is used. Where is the <code>STRU</code> namespace documented? With functions like <code>STRU::QuerySizeCCH()</code>, <code>STRU::Resize()</code>?</p>
'STRU' namespace in the Windows Internals API?
|windows|
<p>You need to use <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms679363%28v=vs.85%29.aspx"><code>GetThreadSelectorEntry()</code></a>.</p> <p>Pseudocode:</p> <pre><code>GetThreadContext(hThread, &amp;context); GetThreadSelectorEntry(hThread, context.SegFs, &amp;selectorEntry); ReadProcessMemory(hProcess, (selectorEntry.BaseLow | (selectorEntry.HighWord.Bytes.BaseMid &lt;&lt; 0x10) | (selectorEntry.HighWord.Bytes.BaseHi &lt;&lt; 0x18)) + 0x2C, &amp;pTLS, sizeof(pTLS), &amp;numberOfBytesRead); </code></pre> <p>You can see the function <code>GetProcessEntryPointAddress()</code> <a href="http://nerdworks.in/downloads/myselfdel.c">here</a> for some sample code that does something similar.</p>
3139
2013-12-07T00:14:12.523
<p>The Thread Local Storage (TLS) contains static or global values for a thread. Those values can be very important to find reliable references to memory structures when the memory locations are not static.</p> <p>I would like to get the Thread Local Storage of another process.</p> <p>The TLS should be at <a href="http://en.wikipedia.org/wiki/Win32_Thread_Information_Block">[FS:0x2C] in the Thread Information Block (TIB)</a>. Though I quite don't understand how the FS register works. I guess I have to find the TIB Base address first? I think I can find it in the Thread Context I can get with <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms679362%28v=vs.85%29.aspx">WINAPI GetThreadContext</a>, but I am a little bit overwhelmed.</p>
How can I find the Thread Local Storage (TLS) of a Windows Process Thread?
|windows|winapi|thread|
<p>You need to select the range of instructions you're interested in, then use the same <kbd>T</kbd> shortcut as you would for a single occurrence. The dialog shown will allow you to select the register, the offset delta to add to the displacement, and the struct you want to apply.</p> <p>The dialog does some preparation work/struct analysis before showing up. If you have a large selection or a lot of structures it can take a while to appear, you just need to be patient. When you change the register/delta inside the dialog, the analysis needs to be updated, which again takes time. Placing the selection cursor over an occurrence of the register you want to change <em>before</em> calling up the dialog is a good idea.</p>
3148
2013-12-08T17:38:57.913
<p>I read that question here (<a href="https://reverseengineering.stackexchange.com/questions/2098/how-do-you-set-registers-as-structs-within-a-function-in-ida">How do you set registers as structs within a function in IDA?</a>) but this applies only to individual lines.</p> <p>Is it possible to set a register as a basepointer for a scope so that all usages of this register will be using the structure you assigned it to?</p> <pre><code>mov eax, [ebx+C] xor [ebx+1C], eax mov eax, [ebx+24] xor [ebx+68], eax mov eax, [ebx+C] xor [ebx+30], eax mov eax, [ebx+24] xor [ebx+48], eax ... </code></pre> <p>Or do you have to apply <code>T</code> on each occurence individually?</p>
IDA: setting a register as a basepointer to struct
|ida|struct|
<p>Full Disclosure is always appreciated. This seems to be a ("the"?) data file for FASA Studio's "Shadowrun". Anyway, the data file contains enough recognizable items to get a good start (PNGs, Unicode text). Data seems to be aligned on 16 bytes, padded with what seems to be random trash.</p> <p>PNG images are a good start; you can extract them 'manually' (I used <a href="http://www.suavetech.com/0xed/" rel="nofollow noreferrer">0xED</a>) and see if they are well-formed. The few I tried were, and the all-but-one last data block should be a PNG image, according to the toc file. I located it at <code>0x82A72D0</code>, with a length of <code>0x2E231</code> bytes.</p> <p><img src="https://i.stack.imgur.com/WDvNG.png" alt="the very last PNG in core.data"></p> <p>Then I checked the data around the last PNG file <em>name</em> in <code>core.toc</code> for these bytes. Bingo - not a huge challenge.</p> <p>The initial part of the toc file is unknown but may be a fast look-up table. I didn't cross-reference this any further with what follows. After that, the following data can be found per each file:</p> <pre><code>4 bytes length (little endian) 4 bytes offset 8 bytes unknown (perhaps checksum, perhaps file data/time, who knows?) 3 bytes name length -- possibly only the first 2 though, 3 bytes is rare # x bytes name </code></pre> <p>Right after the block of file names more stuff appears, I couldn't think of a use for it. You could extract all file names, count them, and see if this is relevant. It seems it isn't as the file name block contains everything you were looking for.</p> <h2>Edit:</h2> <p># Ah-- for the first file, this <code>name length</code> is <code>0x0E 0x00 0x01</code>. Seems the third byte indicates something else, then. I found 2 so far with a <code>0x01</code>, both are '<em>pathless</em>' files.</p>
3155
2013-12-10T11:27:51.390
<ul> <li><a href="https://mega.co.nz/#!0MJgGAAL!ArUvamiuumle0uR0HJNDWjebI3g_R12iBLVq-geuZFE" rel="nofollow">core.toc</a> [87 KB]</li> <li><a href="https://mega.co.nz/#!hEwlGD4Z!RSA3zXEVk41gjbzdfOKCez3EjI9BZChvPr34VR10Ocg" rel="nofollow">core.data</a> [130 MB]</li> </ul> <p>the <code>.toc</code> is a table of contents files that always starts with the header 1rrs. It also contains directory and file paths at offsets that will relate to the data file.</p> <p>Where should I start trying to use the <code>.toc</code> to extract from the <code>.data</code> file?</p>
Extracting files from .data and .toc files
|file-format|
<ol> <li>Build the module with debug symbols</li> <li>Load the module you built into IDA Pro and import the debug symbols</li> <li>Use <a href="http://www.zynamics.com/bindiff.html">BinDiff</a> to port function names, etc. from the IDB of the module you built to the IDB of your target module</li> </ol>
3166
2013-12-12T04:51:46.793
<p>The situation is the following:</p> <p>I'm reversing an application, In which I found a lot of functions that belongs to the OpenSSL library. Since I have the source code for this module, I was wondering if it's possible to somehow "extract" the variable names, structures, function names from the source code, and sync/map it to IDA?</p>
Mapping an external module's source code to assembly - extracting information from source code
|disassembly|ida|assembly|functions|reassembly|
<p>Normally the linker will leave the functions in their original order.</p> <p>However, techniques like <em>Working-Set Tuning</em> (see also <em>Profile-Guided Optimization</em>) can profile the program to see which parts are called the most often, then re-link it with that information in mind. This will clump the most frequently used code together (not only reordering functions, but also possibly splitting them into separate chunks) for memory paging purposes, and of course throw the original function ordering out the window.</p>
3167
2013-12-12T05:16:08.567
<p>Can I group functions based on their place in the binary? Can I assume functions next to each othe belong to the same logical group, or at least they have similar functionality? I suspect that the ordering/layout of the functions are decided compile time, however I still don't know what exactly controls this.</p> <p>Anyway, here is an example for better understanding my question. Let's say I have 3 functions that IDA named for me :</p> <pre><code>sub_00543210 sub_00543211 sub_00543212 </code></pre> <p>Later during the analysis I find out the name of two functions.</p> <pre><code>foo_bar1 sub_00543211 foo_bar3 </code></pre> <p>At this point I would say that the name of the 2nd function, surrounded by found function names is definitely has something to do with "foo" so I'll name it "foo_bar2". (Which later it turned out to be true.)</p> <p><strong>Is this a valid assumption, or was this a special occasion?</strong></p>
Grouping functions based on their placement/order in the binary
|ida|compilers|memory|functions|
<p>Exception handling can also make a difference. I'm currently looking at some code which triggers exceptions causing program termination if run outside the debugger under the right circumstances. When the same happens inside the debugger, the exception handling is intercepted and the program behaves differently (it doesn't crash anymore but it also doesn't behave as if run outside the debugger).</p>
3178
2013-12-13T08:35:12.023
<p>What impact does noninvasive user mode debugging with WinDbg have on the process? Will it be detectable by the process?</p> <p>Of course I could imagine that if the threads are suspended, differences in execution time of a function could be detected by comparing to "usual" values.</p> <p>Microsoft itself <a href="http://msdn.microsoft.com/en-us/library/windows/hardware/ff552274%28v=vs.85%29.aspx">does not indicate</a> more impact than suspending threads. Is that true?</p>
What impact does noninvasive debugging have?
|anti-debugging|windbg|
<p>The paging file is generally for dirty pages, not for clean ones. The clean ones can be read from the original file directly, so there's no need to store them in the page file (and if they haven't ever been read yet then they won't be in memory at all). Further, delay-load DLLs won't be in memory if they've never been referenced, so anything related to them won't be available to you. So just because you disable paging does not mean that everything will be entirely in memory, if physical memory constraints exist. You could try increasing the size of the physical memory, and perhaps let the process run for longer.</p>
3180
2013-12-13T14:44:00.030
<p>I'm doing memory forensics with volatility and pefile on Windows XP SP2 memory dumps. </p> <p>I run windows in a VirtualBox VM and aquire the dumps with vboxmanage debugvm dumpguestcore --filename dump.vmem </p> <p>I'm trying to build a tree of dll's imported by a process. Therefore I recursively walk the dll's starting at the process <code>ImageBaseAddress</code>. The problem that occurs is that for some dll's the dllBase is paged and so I can't read the import and delay import directory structures. </p> <p>I tried disabling the paging in <code>Control Panel</code> -> <code>System</code> -> <code>Advanced</code> -> <code>Perfomance</code> -> <code>Advanced</code> -> <code>Virtual Memory</code> -> <code>No paging file</code>. I also changed the registy entry <code>HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\DisablePagingExecutive</code> from <code>0</code> to <code>1</code>, but the behaviour stays the same.</p> <p>Another Problem is that even if the dllBase is not paged, sometimes reading the import or delay import directories with PEfile fails although the module / dll has the directory.</p> <p>Any help is most appreciated.</p>
Memory forensics: disabled pagefile but still not everything in memory
|windows|memory|digital-forensics|
<p>By intercepting or hooking interrupts in DOS you can make the system behave differently whenever an interrupt is triggered. And there are many interrupts used in x86 architecture, some are triggered by hardware (such as clock, keyboard, divide overflow/divide by zero), some are BIOS services that can be called from software and some are OS services or other services that can also be called from software. All interrupts are equally easy to hook. All you need is <code>cli</code>, replace the interrupt vector with your own one, <code>sti</code>, or use some BIOS or DOS service.</p> <p>By hooking an interrupt you can first do your thing in your own interrupt handler and then forward the original parameters to the original interrupt handler, but you can also replace entire interrupts or specific services of chosen interrupts (without forwarding). TSRs (terminate &amp; stay resident) programs are all based on hooking interrupts (with or without interrupt forwarding). For example many DOS debuggers are TSRs, and probably many viruses too.</p> <p>For example it's possible to write an interrupt handler for interrupt 0x13 that disables all hard drive formatting functions of BIOS interrupt 0x13, by first checking the parameters for <code>int 0x13</code>, and if the function (in <code>ah</code>) is 5, 6, 7, 0x1a ... then set the desired return values in registers and flags as you like , then <code>iret</code>, otherwise <code>jmp</code> to the original interrupt handler. You can write a TSR debugger that hooks the chosen interrupts and presents the debugger screen whenever a chosen interrupt is triggered. You can adjust the system timer interrupt frequency and then hook the timer interrupt to use it to play music eg. with AdLib or SoundBlaster. You can write a TSR keylogger, a TSR virus scanner or a TSR hard drive defragmenter. You can make the computer play "Jingle Bells" through PC speaker or sound card whenever the user presses Enter and it's December. The possibilities are limited only by the hardware available and the skill of the programmer.</p>
3185
2013-12-14T07:58:21.203
<p>I'm currently reading <a href="http://vxheaven.org/vx.php?fid=17" rel="nofollow">40hex magazine</a> regarding virus writing in the early 90's. They talk a lot there about <code>interrupt intercepting</code> Which is something security guys from anti viruses company will try to do, and should be prevented (from virus writing point of view)</p> <p>What is exactly <code>interrupt intercepting ?</code></p>
Interrupt interception
|dos|malware|
<p>By your description:</p> <p>Yes, your program should have only one thread running, without debuger. You can check this on task manager. However when you attach to windbg it will create a thread on break. The third thread that you mention, i really dont have a clue. Maybe a injected dll running code... </p> <p>But you can try to find out by opening the windows "call stack" on winbgd. (and selecting each thread, on thread window)</p> <ul> <li>You will see you code's thread, with last function call on top.</li> <li>Windbg thread , probably with the function ntdll!DbgBreakPoint on top. </li> <li>The third one, see where it stops and what dll the code belongs on dissambly window.</li> </ul> <p>You are right. You just need to set a breakpoint any thread will trigger on acess :).</p> <p>Lets us know what you find out :).</p> <p>Hope I have helped!</p> <p><strong>UPDATE</strong></p> <pre><code>002: </code></pre> <p>The windbg creates that thread every time you pause the attached process execution. It makes sense because the windbg needs a breakpoint to stop the execution, since he dont know where to patch a normal breakpoint on the code, to break immediately. He creates a thread to call dbgbreakpoint and break.</p> <p>If you continue the execution, the windbg's thread will terminate. This is a normal behavior of the debuggers, not only windbg.</p> <pre><code>001: </code></pre> <p>The msiltcfg.dll has functions to handle MSI installers. "Windows Installer Configuration API Stub" Its strange,for me, that the process has this dll loaded. By the stack call you show, its waiting for something. A thread, mutex event, etc... This thread has nothing to do with windbg. Something has loaded that dll on your process and created the thread. Almost for sure it is a operating system process.</p> <p>One thing you can do is check if other processes (calc.exe or notpad.exe, simple ones) got the same thread or the same dll loaded. Some programs/OS can load dll's on abritary processes or even all and run code (using the WIN32 API function CreateRemoteThread). This is a normal behavior done by malware too :). </p> <p>One thing you have for sure is that your program has only created one thread. And in a normal situation it should not have more than one.</p> <p>I tested a program like your to be sure, and just got a thread.</p>
3195
2013-12-15T17:16:41.573
<p>I wrote a little program which just shows a dialog. Basically an ASM Hello World. When the dialog is displayed and I break in WinDBG, I can see three threads even though the application doesn't use any threads at all.</p> <p>I was not aware that there is something like default threads applied to a process, or is this because of WinDBG?</p> <p>The Process/Thread window shows</p> <pre><code> 000:13d4:MyApp.exe 000:d14 001:11bc 002:50c </code></pre> <p>If I put a memory access breakpoint and the process would have multiple threads, do I have to specify in which thread this should be triggered. I think this shouldn't matter right? So if an address is accessed by any thread, the breakpoint should trigger regardless.</p> <p><strong>udate</strong></p> <p>So I took now a closer look (the handle numbers have changed, but the IDs are relevant anyway). I'm Running Windows 7-32bit-x86 if that helps.</p> <p><code>000:</code> refers to my original process, but this was already known.</p> <p><code>001:</code> Stacktrace when I break looks like this (some thread snychronization required by WinDBG?):</p> <pre><code>ntdll!KiFastSystemCallRet kernel32!WaitForMultipleObjectsEx+0x8e kernel32!WaitForMultipleObjects+0x18 msiltcfg!RestartMsi+0x32e kernel32!BaseThreadInitThunk+0x12 ntdll!RtlInitializeExceptionChain+0xef ntdll!RtlInitializeExceptionChain+0xc2 </code></pre> <p>It seems that this thread belongs to some <code>msiltcfg.dll</code> which would be a Windows 7 DLL, but why does it cread threads in my process?</p> <p><code>002:</code> So this would probably be the WinDBG thread which Akira32 refers to in his answer, right? (why does WinDBG need a thread of his own?).</p> <pre><code>ntdll!DbgBreakPoint kernel32!BaseThreadInitThunk+0x12 ntdll!RtlInitializeExceptionChain+0xef ntdll!RtlInitializeExceptionChain+0xc2 </code></pre>
Three threads in Windows
|windbg|thread|
<p>I would answer the part</p> <blockquote> <p>put them together in order and recompile</p> </blockquote> <p>If your decompilation contains function chunks, be aware using an assembler that accept code outside from a function environment and be aware, too, with the data prevention execution.</p> <p>For more information about function chunks: <a href="https://reverseengineering.stackexchange.com/questions/3676/chunked-function-discontinuous-chunks-of-code-comprising-a-function">Chunked function (discontinuous chunks of code comprising a function)</a></p>
3203
2013-12-16T21:03:24.710
<p>currently I am trying to use IDA pro to <strong>generate assembly code from PE file and recompile it</strong>.</p> <h3>Firstly</h3> <p>basically I know this way:</p> <pre><code>File -&gt; Produce File -&gt; Create ASM File </code></pre> <p>and it seems the asm file it generated cannot be directly recompile.</p> <h3>Second</h3> <p>use some IDC or Python script in the IDA to extract useful asm instructions, put them together in order and recompile, this kind of solution can be seen from some academic paper, but non of them have given some detailed instructions about how to do this task...</p> <p>Could anyone give me some instructions about this issue..? Thank you!</p>
Recompile the asm file IDA pro created
|disassembly|ida|idapython|