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
<h2>Direct Detection</h2> <p>At the lowest level you can just have copies of the libraries and check if they are the one used. </p> <h2>Signature based Detection</h2> <p>At a higher level than that is <a href="https://www.hex-rays.com/products/ida/tech/flirt/index.shtml">IDA FLIRT</a> which stores just enough information about a library to identify its use. But its main benefit is reduced disk usage... it is worth noting that you can add more definitions to the default ones.</p> <p>Hex-Rays talks about the technology <a href="https://www.hex-rays.com/products/ida/tech/flirt/in_depth.shtml#implementation">in-depth here</a>.</p> <h2>Generic recognition</h2> <p>Tools like Coverity or the <a href="http://clang-analyzer.llvm.org/">Clang static analyzer</a> or <a href="http://klee.llvm.org/">KLEE</a> are more general and more likely to include models for programming idioms.</p> <p>The only thing I know of coming close to IDA that is open source is <a href="https://github.com/radare/radare2">radare</a> which might have some library recognition. Also <a href="http://www.radare.org/"><code>radare</code>'s main page</a>. And I have been looking since I am hunting something like IDA that supports SPARC for free and it looks like <code>radare</code> does although I haven't had time it give it a go yet.</p> <p>From what I can tell REC and Boomerang do not recognize libraries the way IDA does, but instead just attempt to decompile everything. <a href="http://bap.ece.cmu.edu/">BAP</a> does analysis of binaries and is derived from the Vine component of the BitBlaze project the two projects below are part of as well.</p> <h2>Flow Analysis</h2> <p>TEMU and Rudder <a href="http://bitblaze.cs.berkeley.edu/#projects">here</a> look to be quite advanced. And deal with code as it executes. TEMU helps to relate imputs and outputs to the flow. </p> <p>It is also worth noting that the Bitblaze tools are designed to provide traces for use in IDA although they could probably be adapted for use otherwise.</p> <p>Going off of the specifics you provided <a href="http://bitblaze.cs.berkeley.edu/temu.html">TEMU</a> sounds the closest to what you want.... it allows you to mark tainted inputs (memory locations, physical inputs etc...) and detect the effects of those taints on the execution. If you want to try out TEMU and are on a newer Linux distro (anything with GCC 4+ which is most anything in the past few years) follow the <a href="https://groups.google.com/forum/?fromgroups#!topic/bitblaze-users/QdoY9l8D-ho">instructions here</a>.</p>
1
2013-03-19T19:05:55.320
<p>When we're doing reverse engineering, we have a few levels of models. One of them is the instruction semantics model, which tells us what every native instruction does to modify instruction state. We're making progress there. However, another problem is that of platform semantics, which is at a higher level. </p> <p>For example, a high-level model of a userspace linux program would need to include information about mprotect and that it can alter the visibility of certain regions of code. Threading and callback semantics are also a platform modeling issue, we can discover a programs entrypoint from its header (which is another kind of semantic! but one we're probably not going to compromise on), but other entrypoints are published in the program in the form of arguments to atexit, pthread_create, etc. </p> <p>What is our current best effort/state of the art at capturing this high level platform information in a way that is understood by practicioners? What about by mechanical / automated understanding systems? I know that IDA has (or has to have) information about different platform APIs, it seems to know that when an immediate is a parameter to pthread_create then that immediate is a pointer to code and should be treated as such. What do we have beyond that?</p>
What is the current state of the art for platform modeling?
|code-modeling|
<p>As others have said, I usually look for a function call where a reference is passed - but I also look for instances where a malloc'ed buffer is returned (this is how you know/confirm the size of the structure) - and various members of the 'buffer' are set/initialized.</p>
4
2013-03-19T19:24:53.760
<p>I took a basic 40-hr Reverse Engineering course a few summers ago. While teaching us to use IDAPro, the instructor demonstrated, rather quickly and without explaining much, how to label certain variables in the ASM as members of a structure, basically equivalent to a good old fashioned <code>struct</code> in C/C++, and treat them as such wherever they are seen in the rest of the code. This seems rather useful to me.</p> <p>What he did not cover, however, was how to identify a structure. How do you know when a group of variables does in fact constitute a structure and not just a set of related variables? How can you be sure that the author used a <code>struct</code> (or something similar) there?</p>
How is a structure located within a disassembled program?
|ida|assembly|struct|
<blockquote> <p>There are many great resources to learn assembly but none of them seem to go into much detail on how assembly mnemonics get turned into raw binary instructions.</p> </blockquote> <p>The mnemonics aren't 'turned in' to raw binary instructions, they are the raw binary instructions. It is a human readable representation of the actual hex bytes that are encoding the instructions of the (first generation language) machine code. We typically talk about these bytes by their mnemonics for clarity.</p> <p>This is unlike assembly (so, second generation language such as gas or masm) or C (third generation language). Both assembly and higher generation languages are source files with a character encoding (such as UTF-8) that encodes the letters of the source code. In the case of assembly, it needs to be assembled to raw x86 bytes. The raw bytes can be disassembled by IDA into a readable form; it's called disassembly because it's presenting the mnemonic representation encoded in a character set like UTF-8 and displayed to the screen (which resembles an assembly language (a second generation language) that would be assembled to machine code -- in this case it's obviously not going to be assembled and isn't really an assembly language on it's own -- it's showing you what the assembly that was compiled to the machine code <em>would have been</em>).</p> <p>x86 encoding looks like this (I created a diagram):</p> <p><a href="https://i.stack.imgur.com/OnFm6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OnFm6.png" alt="enter image description here" /></a></p> <p>By the same token, CIL bytecode is a 1st generation language because the opcodes run directly on the virtual machine -- a virtual CPU. This means that the CIL bytecode does not need to be assembled or compiled from a source file with a source character set. <code>ilasm</code> shows a disassembled, mnemonic form of this bytecode.</p>
5
2013-03-19T19:30:22.060
<p>I'm writing a small utility library for hooking functions at run time. I need to find out the length of the first few instructions because I don't want to assume anything or require the developer to manually input the amount of bytes to relocate and overwrite.</p> <p>There are many great resources to learn assembly but none of them seem to go into much detail on how assembly mnemonics get turned into raw binary instructions.</p>
How are x86 CPU instructions encoded?
|assembly|x86|
<p>I guess the first thing you should do to determine the compiler version unless you literally mean the compiler version instead of linker version, is inspect the "MajorLinkerVersion" and "MinorLinkerVersion" fields of the PE header of the executable, be it EXE, DLL, or SYS. See list below.</p> <p>Major Minor</p> <p>0x5 0x0 (5.0) Borland C++ / MS Linker 5.0</p> <p>0x6 0x0 (6.0) Microsoft VIsual Studio 6</p> <p>0x7 0xA (7.10) Microsoft VIsual Studio 2003</p> <p>0x8 0x0 (8.0) Microsoft VIsual Studio 2005</p> <p>0x9 0x0 (9.0) Microsoft VIsual Studio 2008</p> <p>0xA 0x0 (10.0) Microsoft VIsual Studio 2010</p> <p>0x2 0x15 (2.21) MinGw</p> <p>0x2 0x19 (2.0.0.25) Borland Delphi (linker 2.0.0.25)</p> <p>Unfortunately, packers and protectors tend to overwrite these value to write their own and/or harden the process of guessing the original compiler. </p> <p>Also, the resource directory of an executable is a good place to search for specific linker info. e.g. RT_RCDATA having a resource named "DVCLAL" is a sign of Borland C++ or Delphi and the "RT_MANIFEST" in case of a MSVC-built executable can tell us about the specfic version of runtime DLL's it is linked to and hence the compiler version.</p> <p>Also, an executable with the "TimeDateStamp" field set to 0x2A425E19 is a sign of being built with Delphi.</p> <p>Now, if you want to determine compiler from assembly code, then the sign of a recent MSVC compiler version is seeing the function that generates the stack cookie just at the entry point.</p> <p>Seeming, a JMP instruction at the entry point followed by the string "fb:C++Hook" is a sign of Borland C++, and so on.</p>
11
2013-03-19T20:01:48.563
<p>When I am looking at the machine code of an application, are there hints and patterns I can discern from the generated machine code which would indicate which compiler (and possibly version) was used to generate it?</p> <p>Does knowing the compiler used to generate an application help me to more effectively reverse engineer back from the generated object to what the source code might have been, and if it does help, how so?</p>
What hints in machine code can point me to the compiler which was used to generate it?
|assembly|compilers|object-code|hll-mapping|
<p>Literally, for a first look on malware, you won't need anything special locally installed. There are enough online sandboxes you may use:</p> <ul> <li><a href="https://www.virustotal.com/" rel="noreferrer">virustotal.com</a> have their sandbox implemented using <a href="http://www.cuckoosandbox.org/" rel="noreferrer">Cuckoo Sandbox</a>. When you apply new sample, it automatically executed as part of analysis. After about 10-15 mins you can see the result in "Behavioural information"</li> <li><a href="http://anubis.iseclab.org/" rel="noreferrer">anubis.iseclab.org</a> is another place you may submit binary to see it behavior before executing it locally. Here you got report and pcap file of network activity, if any.</li> </ul> <p>As a result - you may get basic idea of what a binary does and how to analyse it. But - please note, that sophisticated malware checks its environment for sandbox traces and VM presence. So there is a chance that the seemingly "harmless binary" turns out to be sophisticated malware under real conditions.</p>
23
2013-03-19T21:27:57.400
<p>I've recently managed to isolate and archive a few files that managed to wreak havoc on one of my client's systems. So I was wondering what software and techniques make the best sandbox for isolating the code and digging into it to find out how it works.</p> <p>Usually, up to this point in time I would just fire up a new VMWare or QEMU instance and dig away, but I am well aware that some well-written malware can break out of a VM relatively easily. So I am looking for techniques (Like using a VM with a different emulated CPU architecture for example.) and software (Maybe a sandbox suite of the sorts?) to mitigate the possibility of the code I am working on "breaking out".</p> <p>What techniques do you recommend? What software do you recommend?</p>
How can I analyze a potentially harmful binary safely?
|virtual-machines|malware|sandbox|security|
<p>Well, since it's a Solaris driver, first you need to find up some docs on how Solaris drivers communicate with the kernel (or kernel with them). A quick search turned up <a href="http://docs.oracle.com/cd/E19455-01/806-0638/6j9vrvct2/index.html" rel="nofollow">this</a>:</p> <blockquote> <p><code>_init()</code> initializes a loadable module. It is called before any other routine in a loadable module. <code>_init()</code> returns the value returned by <code>mod_install(9F)</code> . The module may optionally perform some other work before the <code>mod_install(9F)</code> call is performed. If the module has done some setup before the <code>mod_install(9F)</code> function is called, then it should be prepared to undo that setup if <code>mod_install(9F)</code> returns an error.</p> <p><code>_info()</code> returns information about a loadable module. <code>_info()</code> returns the value returned by <code>mod_info(9F)</code>. </p> <p><code>_fini()</code> prepares a loadable module for unloading. It is called when the system wants to unload a module. If the module determines that it can be unloaded, then <code>_fini()</code> returns the value returned by <code>mod_remove(9F)</code>. Upon successful return from <code>_fini()</code> no other routine in the module will be called before <code>_init()</code> is called.</p> </blockquote> <p>There's a nice code sample below.</p> <p><a href="http://docs.oracle.com/cd/E18752_01/html/816-4855/config12-9.html" rel="nofollow">This guide</a> also seems relevant.</p> <p>Once you found the entry points, it's just a matter of following the calls and pointers. </p> <p>Here's how it looks in IDA:</p> <pre><code>.text:00000000 _init: ! DATA XREF: leo_attach+5A8o .text:00000000 ! leo_attach+5BCo ... .text:00000000 save %sp, -0x60, %sp .text:00000004 sethi %hi(leo_debug), %i2 .text:00000008 ld [leo_debug], %o0 .text:0000000C cmp %o0, 4 .text:00000010 bl loc_38 .text:00000014 sethi %hi(leo_state), %o0 .text:00000018 set aLeoCompiledSS, %o0 ! "leo: compiled %s, %s\n" .text:00000020 set a141746, %o1 ! "14:17:46" .text:00000028 sethi %hi(aLeo_c6_6Jun251), %l0 ! "leo.c 6.6 Jun 25 1997 14:17:46" .text:0000002C call leo_printf .text:00000030 set aJun251997, %o2 ! "Jun 25 1997" .text:00000034 sethi %hi(leo_state), %o0 .text:00000038 .text:00000038 loc_38: ! CODE XREF: _init+10j .text:00000038 set leo_state, %i1 .text:0000003C sethi %hi(0x1800), %l0 .text:00000040 mov %i1, %o0 .text:00000044 set 0x1980, %o1 .text:00000048 call ddi_soft_state_init .text:0000004C mov 1, %o2 .text:00000050 orcc %g0, %o0, %i0 .text:00000054 bne,a loc_80 .text:00000058 ld [%i2+(leo_debug &amp; 0x3FF)], %o0 .text:0000005C sethi %hi(0x14C00), %l0 .text:00000060 call mod_install .text:00000064 set modlinkage, %o0 .text:00000068 orcc %g0, %o0, %i0 .text:0000006C be,a loc_80 .text:00000070 ld [%i2+(leo_debug &amp; 0x3FF)], %o0 .text:00000074 call ddi_soft_state_fini .text:00000078 mov %i1, %o0 .text:0000007C ld [%i2+(leo_debug &amp; 0x3FF)], %o0 .text:00000080 .text:00000080 loc_80: ! CODE XREF: _init+54j .text:00000080 ! _init+6Cj .text:00000080 cmp %o0, 4 .text:00000084 bl locret_9C .text:00000088 nop .text:0000008C set aLeo_initDoneRe, %o0 ! "leo: _init done, return(%d)\n" .text:00000094 call leo_printf .text:00000098 mov %i0, %o1 .text:0000009C .text:0000009C locret_9C: ! CODE XREF: _init+84j .text:0000009C ret .text:000000A0 restore .text:000000A0 ! End of function _init </code></pre> <p>At 0x60 you can see <code>mod_install</code> being called with a pointer to <code>modlinkage</code>, so you can follow there and see what the fields are pointing to.</p> <p>But you don't even have to do that all the time. In this case, the programmers very thoughtfully left intact all the symbols and debug output. This should help you in your work :)</p> <p>Depending on situation, you may skip straight to the helpfully-named functions like <code>leo_blit_sync_start</code> or <code>leo_init_ramdac</code>. I personally prefer the first way, top-down, but to each his own.</p> <p><strong>EDIT</strong>: one rather simple thing you can do is to patch the <code>leo_debug</code> variable at the start of <code>.data</code> section to 5 or so. That should produce a lot of debug output about the operations the driver is performing.</p>
27
2013-03-19T22:51:02.077
<p>I have several Solaris 2.6 era drivers I would like to reverse engineer.</p> <p>I have a Sparc disassembler which provides some info but it isn't maintained anymore so I think it may not give me all the information possible.</p> <p>The drivers are for an Sbus graphics accelerator I own. Namely the <a href="http://www.hyperstation.de/SBus-Framebuffer/SUN_Leo_ZX/sun_leo_zx.html" rel="nofollow">ZX aka Leo</a> one of the early 3d accelerators.</p> <p>So what are some ways I can go about reverse engineering this driver? I can disassemble it but I am not sure what to make of the output. I also have Solaris of course so perhaps there are things I can do there as well.</p> <p>The final goal is to have enough information to design a driver for an Operating System. There are drivers for NetBSD, although incomplete as the hardware documentation that does exist (isn't free to access) does not have the Window ID encoding as it is missing. Also, since the hardware uses an Sbus interface on a double wide <a href="http://en.wikipedia.org/wiki/PCI_Mezzanine_Card" rel="nofollow">mezzanine card</a>, it would be impractical to use it on anything but a SparcStation or early UltraSparc machine.</p>
Reverse engineering a Solaris driver
|sparc|solaris|driver|sbus|
<p>You can simply grep the file for "<code>javaw.exe</code>" or <code>java.exe</code>... This will usually be a pretty good indicator whether or not the program is a Java wrapper or not.</p> <pre><code>archenoth@Hathor ~/apps/Minecraft $ grep javaw.exe /host/Windows/notepad.exe archenoth@Hathor ~/apps/Minecraft $ grep javaw.exe ./Minecraft.exe Binary file ./Minecraft.exe matches archenoth@Hathor ~/apps/Minecraft $ </code></pre> <p>This is because wrappers usually contain the following:</p> <p><img src="https://i.stack.imgur.com/00AAL.png" alt="enter image description here"></p>
34
2013-03-20T01:43:12.077
<p>Let's say I have a .jar file and wrap it into a .exe using any number of free utilities out there, like <a href="http://jsmooth.sourceforge.net/">JSmooth</a>.</p> <p>Would it be possible to tell, given just the .exe, if it was generated using one such utility from a .jar file?</p>
Checking if an .exe is actually a .jar wrapped in an .exe
|decompilation|java|jar|pe|
<p>Another tool is <strong>Bytecode Viewer</strong>: </p> <p><a href="https://github.com/Konloch/bytecode-viewer" rel="nofollow">https://github.com/Konloch/bytecode-viewer</a></p> <blockquote> <p>Bytecode Viewer is an Advanced Lightweight Java Bytecode Viewer, GUI Java Decompiler, GUI Bytecode Editor, GUI Smali, GUI Baksmali, GUI APK Editor, GUI Dex Editor, GUI APK Decompiler, GUI DEX Decompiler, GUI Procyon Java Decompiler, GUI Krakatau, GUI CFR Java Decompiler, GUI FernFlower Java Decompiler, GUI DEX2Jar, GUI Jar2DEX, GUI Jar-Jar, Hex Viewer, Code Searcher, Debugger and more. It's written completely in Java, and it's open sourced. It's currently being maintained and developed by Konloch.</p> </blockquote>
42
2013-03-20T09:02:41.433
<p>The Android java code is compiled into Dalvik byte code, which is quite readable. I wonder, is it possible in theory and in practice to write a decompilation software for Dalvik byte code?</p>
Decompiling Android application
|decompilation|java|android|byte-code|
<p>They aren't any, do not try to do the mathematically impossible.</p> <blockquote> <p>For now, all the techniques I found on Internet were easily worked around as soon as the anti-debug technique has been understood. So, I wonder if there are stronger ones.</p> </blockquote> <p>Yes, because there is no way of detecting a debugger that can not be faked. Software can not detect if it runs in a perfect emulation or in the real world. And a emulator can be stopped, the software can be analyzed, variables can be changed, basically everything can be done that can be done in a debugger.</p> <p>Let's say you want to detect if the parent process is a debugger. So you make a system call to get the parent PID? The debugger can intercept the system call and return any PID which does not have to be the real PID. You want to intercept every SIGTRAP so the debugger can't use it anymore? Well the debugger can just stop in this case and send the SIGTRAP also to your process. You want to measure the time when you send SIGTRAP to know if the process stops for a short time by the debugger for sending SIGTRAP so you know when there is a debugger? The debugger can replace your calls to get the time and return a fake time. Let's say you run on a Processor that has a instruction that returns the time, so no function call is needed to get the time. Now you can know that the time you are getting is real? No, the debugger can replace this instruction with a SIGTRAP instruction and return any time he wants or in case such a instruction does not exist, run the Software in a emulator that can be programmed in any way. Everything you can come up with to detect a debugger or emulator can be faked by the environment and you have 0 change to detect it.</p> <p>The only way to stop debugging is by not giving the software to the customers but keep it in your hands. Make a cloud service and run the software on your server. In this case the customer can not debug your program since he does not run it and has no control over it. Except the customer can access the server or the data somehow, but that is a different story.</p>
43
2013-03-20T09:13:52.113
<p>I am trying to scan all possible techniques to disrupt the usage of a debugger on a Unix platform (ie POSIX and a bit more).</p> <p>I am thinking about techniques such as the <code>PTRACE</code> test at the beginning of a program (or at various points of its execution), the insertion of fake breakpoints (eg <code>int3</code>/<code>0xcc</code> x86 opcode) or time checks. But, also global strategies defined on the program to slow down the analysis of the program.</p> <p>For now, all the techniques I found on Internet were easily worked around as soon as the anti-debug technique has been understood. So, I wonder if there are stronger ones.</p>
Anti-debug techniques on Unix platforms?
|assembly|obfuscation|anti-debugging|
<p>What is functional encryption for all circuits and indistinguishability obfuscation for all circuits ?</p> <ol> <li>A proposed <strong>indistinguishability obfuscation</strong> for NC1 circuits where the security is based on the so called Multilinear Jigsaw Puzzles (a simplified variant of multilinear maps).</li> <li>Pair the contribution in 1 with <strong>Fully Homomorphic Encryption</strong> and you get indistinguishability obfuscation for all circuits.</li> <li>Combine 2 with <strong>public key encryption and non-interactive zero-knowledge proofs</strong> and you <strong>functional encryption for all circuits</strong>. I believe that prior to <a href="http://www.rdmag.com/news/2013/07/computer-scientists-develop-mathematical-jigsaw-puzzles-encrypt-software?et_cid=3395460&amp;et_rid=54755808&amp;location=top" rel="nofollow">this</a>, functional encryption for all circuits was not possible.</li> </ol>
45
2013-03-20T09:35:01.860
<p>FHE (Fully Homomorphic Encryption) is a cryptographic encryption schema in which it is possible to perform arithmetic operations on the ciphered text without deciphering it.</p> <p>Though there is no really efficient crypto-system with this property at this time, several proofs of concepts show that this kind of cryptography does actually exist. And, that, maybe one day, we might find an efficient crypto-system with the FHE properties.</p> <p>For now, the usage of FHE is mainly directed towards "Cloud Computing" where one want to delegate a costly computation to a remote computer without spreading his data away. So, the principle is just to send out encrypted data and the Cloud will apply a given computation on the data and send back the encrypted answer without having knowledge of what is inside.</p> <p>The link with code obfuscation is quite obvious as if we can perfectly obfuscate data, then we can also perfectly obfuscate the algorithm by coding it into a universal Turing machine. But, the Devil is always in the details. A recent paper [<a href="http://eprint.iacr.org/2011/675">1</a>] presents a way to use the FHE for obfuscation, but in a too stronger way (in my humble opinion).</p> <p>My question is the following: Suppose we have an efficient FHE schema, suppose also that our goal is to slow down the analysis of a program (and not totally prevent it). Then, what would be the most efficient usage of the FHE in obfuscation ?</p>
Usage of FHE in obfuscation?
|obfuscation|cryptography|
<p>While it's not possible to obfuscate object files, it is possible to obfuscate the underlying assembly file. There is no such thing as name obfuscation in C++ since references are by address, not by name. Using full optimization (-O3 -Ob2 -flto) can also make it hard to reverse engineer your code. Also, you can also use VMProtect/Denuvo to encrypt and obfuscate your executable.</p> <p>You may find those posts useful</p> <p><a href="https://stackoverflow.com/questions/137038/how-do-you-get-assembler-output-from-c-c-source-in-gcc">https://stackoverflow.com/questions/137038/how-do-you-get-assembler-output-from-c-c-source-in-gcc</a></p> <p><a href="https://reverseengineering.stackexchange.com/a/22052/33533">https://reverseengineering.stackexchange.com/a/22052/33533</a></p>
47
2013-03-20T09:43:11.807
<p>Is it possible to create an object file using <code>gcc</code> that cannot be reverse engineered to its source code ?</p>
Can I create an object file using gcc that cannot be reverse engineered?
|c|object-code|
<p>This <a href="http://jsbeautifier.org/" rel="noreferrer">also breaks some beautifers</a> (but <a href="http://www.javascriptbeautifier.com/" rel="noreferrer">not all</a>). For example, running your code through JS Beautifier:</p> <pre><code> var ab = "Hello, world!", a‍ b = "Completely different string!", a‌ b = "Yet another completely different string!"; document.getElementById('result1').innerHTML = ab; document.getElementById('result2').innerHTML = a‍ b; document.getElementById('result3').innerHTML = a‌ b; </code></pre> <p>(Note the spaces in between "a" and "b".)</p> <p>You could argue that this is a pro and a con. Depending on exactly how confusing you make the code, it may be even more confusing to see random spaces being injected. On the other hand, it also alerts the reader that something is definitely up.</p>
53
2013-03-20T12:06:39.137
<p>This comes from comments on a question on StackOverflow about JavaScript Variables: <a href="https://stackoverflow.com/a/7451569/1317805">Why aren't ◎ܫ◎ and ☺ valid JavaScript variable names?</a></p> <p>JavaScript accepts zero-width characters as valid variable names, for example all three of these variables have different names but are visually identical:</p> <pre><code>var ab, /* ab */ a‍b, /* a&amp;zwj;b */ a‌b; /* a&amp;zwnj;b */ </code></pre> <p>Here's a <a href="http://jsfiddle.net/MYLx9/" rel="noreferrer">JSFiddle</a> example of the above three variables in use.</p> <p>What are the pros and cons of doing this as an obfuscation technique for JavaScript (and other supporting languages)?</p>
Obfuscating JavaScript with zero-width characters - pros and cons?
|obfuscation|javascript|
<p>I'd like to add <a href="http://www.idabook.com/collabreate" rel="nofollow">collabREate</a> - plugin, which allow to do reverse engineering in the small team, all share the same IDA session.</p>
59
2013-03-20T12:57:53.483
<p>I'm a bit of a novice with IDA Pro, and have been discovering some of the excellent plugins available from the RE community as well as its vendors. My small list of plugins that I have found extremely valuable to me are:</p> <ul> <li><a href="https://www.hex-rays.com/products/decompiler/index.shtml">Hex-Rays Decompiler</a> (commercial) - convert program to pseudo-C</li> <li><a href="http://thunkers.net/~deft/code/toolbag/">IDA Toolbag</a> - Adds too much awesome functionality to IDA to list. <a href="http://thunkers.net/~deft/code/toolbag/docs.html#Usage">Just see/read about it</a>.</li> <li><a href="https://bitbucket.org/daniel_plohmann/simplifire.idascope/">IDAscope</a> - Function tagging/inspection, WinAPI lookup, Crypto identification</li> </ul> <p>Granted, this is a very short list. What IDA Pro scripts/plugins do you find essential?</p>
What are the essential IDA Plugins or IDA Python scripts that you use?
|tools|ida|idapython|
<p>I think questions beginning with the clause "Is it legal to..." can only ever be correctly answered with certainty in a court of law. And as @0xC0000022L mentioned, you'd need to start by specifying which country you're asking about.</p> <p>Short of going to court, I think such questions can only ever be answered correctly with the phrase, "It depends."</p> <p>From the other answers, it seems well-known within this community that reverse engineering something is very closely connected to both <a href="http://www.copyright.gov/regstat/2013/regstat03202013.html">copyright law</a> and the <a href="https://www.eff.org/issues/cfaa">Computer Fraud and Abuse Act</a>, both of which (as the links attest) are hotly contested right now in the US.</p> <p>Harvard Law School has recently published a <a href="http://boingboing.net/2013/03/04/copyrightx-a-massively-open-o.html">massively open online course on copyright</a>. The professor <a href="http://www.tfisher.org/PTK.htm">published a book</a> on copyright reform in 2004. He also started <a href="http://www.tfisher.org/Disclosure.htm">Noank Media, Inc. in 2007</a> to try and implement one of the ideas in his book in China. Although his MOOC lectures and readings are all available globally, I'm taking this course through <a href="https://www.edx.org/">edX</a> right now, and even with the benefit of several law students to help answer questions, there's still a <em>tremendous</em> amount of information and ambiguity to consider (even limiting the scope of my answer here to copyright and not dealing with the CFAA). As @JMcAfreak wrote, the DMCA also applies, and my guess is that there are several other laws that could also potentially apply to your question in the US.</p> <p>What I've learned after 8 weeks in this course is that you'd need to spend at least 12 weeks reading case law before really being able to answer the question you pose here. And as Aaron Swartz discovered, the stakes are incredibly high, and computer programmers and reverse engineers (who may routinely do some—potentially illegal—act thousands or millions of times through the use of a computer program) are especially vulnerable to multiple counts of illegal acts where the penalties add up very quickly.</p> <p>If you're considering doing something that makes you ask the question, then you also need to consider who might be most motivated to pursue you for illegal activity as a result, and if that's a wealthy individual or business entity, then you probably shouldn't risk it. If Shepard Fairey had used a reference photograph for <a href="http://en.wikipedia.org/wiki/Shepard_Fairey#Legal_issues_with_appropriation_and_fair_use">his Obama HOPE poster</a> owned by an entity less affluent than the Associated Press, then I'm sure that situation would have ended very differently for him.</p>
60
2013-03-20T13:14:09.463
<p>Is it legal to reverse engineer certain features of a closed source application and then integrate those features into a closed or open source application that may be either a commercial or non-commercial application ?</p> <hr> <p>Brownie points for an answer covering the situation in India.</p>
Is reverse engineering and using parts of a closed source application legal?
|law|
<p>Blackstorm portal has a huge collection of Unpacking tutorials <a href="http://portal.b-at-s.net/news.php" rel="noreferrer">Blackstorm portal tutorials</a></p> <p>Tuts4You has another large collection of unpacking tutorials <a href="https://tuts4you.com/download.php?list.19" rel="noreferrer">Tuts4You</a></p> <p>It took me a long time at first but over time unpacking got a lot easier, lots of patience and practice required though.</p>
72
2013-03-20T15:25:47.117
<p>I find that more and more often binaries are being packed with exe protectors such as upx, aspack etc. I tried to follow a few tutorials on how to unpack them but the examples are often quite easy while my targets are not.</p> <p>I am looking for good resources and any hints/tips on how to unpack targets.</p>
Unpacking binaries in a generic way
|decompilation|unpacking|pe|
<p>The <a href="http://radare.org" rel="nofollow">radare2</a> project uses an extensive <a href="https://github.com/radare/radare2-regressions/tree/master/t.asm" rel="nofollow">test-suite</a> for each of its disassembler engine, along with more specific tests, like <a href="https://github.com/radare/radare2-regressions/tree/master/t.formats" rel="nofollow">formats</a>, its own <a href="https://github.com/radare/radare2-regressions/tree/master/t.anal" rel="nofollow">analysis capabilities</a>, …</p>
74
2013-03-20T15:56:57.997
<p>A key tool in reverse engineering is a good disassembler, so to ensure that a disassembler is performing properly, are there any good test suites available for use to test the correctness of a disassembler? Are these architecture specific, or can they be configured to work across multiple object architectures? A good test should include checking the more obscure architecture instructions and malformed portable execution files.</p> <p>Here is <a href="http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/i386/?cvsroot=src">one specifically for i86</a> that I have seen. Are there any that are modular across architectures?</p>
Are there any open source test suites for testing how well a disassembler performs?
|tools|disassembly|
<p>.NET assemblies (.exe and .dll) can be decompiled online at <a href="http://decompiler.com" rel="nofollow noreferrer">Decompiler.com</a></p> <p>The author is affiliated with the mentioned website it appears (username: <a href="http://www.Decompiler.com" rel="nofollow noreferrer">www.Decompiler.com</a>).</p>
77
2013-03-20T16:18:40.027
<p>Are there any tools available to take an already compiled .dll or .exe file that you know was compiled from C# or Visual Basic and obtain the original source code from it?</p>
Is there any way to decompile a .NET assembly or program?
|decompilation|dll|.net|pe|
<p>RapidSmith does that for you. <a href="http://rapidsmith.sourceforge.net/" rel="nofollow noreferrer">http://rapidsmith.sourceforge.net/</a></p> <p>There is also a paper that you can read as the starting point: "Recent Advances in FPGA Reverse Engineering" Hoyoung Yu, Hansol Lee, Sangil Lee , Youngmin Kim and Hyung-Min Lee</p>
85
2013-03-20T17:27:34.680
<p>Let's assume I have a device with an FPGA on it, and I managed to extract the bitstream from its flash. How would I go about recovering its behavior?</p> <p>One simple case is if it implements a soft processor - in that case there should be firmware for that processor somewhere and I can just disassemble that. But what if it's just a bunch of IP blocks and some additional logic?</p>
Reversing an FPGA circuit
|hardware|fpga|
<p>I gave a talk at Recon in 2011 ("Practical C++ Decompilation") on this exact topic. <a href="http://www.hexblog.com/wp-content/uploads/2011/08/Recon-2011-Skochinsky.pdf" rel="nofollow noreferrer">Slides</a> and <a href="https://www.youtube.com/watch?v=efkLG8-G3J0" rel="nofollow noreferrer">video</a> (<a href="https://www.youtube.com/watch?v=efkLG8-G3J0" rel="nofollow noreferrer">mirror</a>) are available.</p> <p>The basic approach is simple: represent classes as structures, and vtables as structures of function pointers. There are some tricks I described that allow you to handle inheritance and different vtables for the classes in the same hierarchy. These tricks were also described on <a href="http://blog.0xbadc0de.be/archives/67" rel="nofollow noreferrer">this blog</a>; I'm not sure if it was based on my talk or an independent work.</p> <p>One additional thing that I do is add a repeatable comment to each slot in the vtable structure with the implementation's address. This allows you to quickly jump to the implementation when you apply the structure to the vtable slot load:</p> <p><img src="https://i.stack.imgur.com/dAGk2.png" alt="enter image description here"></p>
87
2013-03-20T18:09:54.637
<p>When reverse engineering binaries compiled from C++, it is common to see many indirect calls to function pointers in <a href="http://en.wikipedia.org/wiki/Virtual_method_table">vtables</a>. To determine where these calls lead, one must always be aware of the object types expected by the <code>this</code> pointer in <a href="http://en.wikipedia.org/wiki/Virtual_function">virtual functions</a>, and sometimes map out a class hierarchy.</p> <p>In the context of static analysis, what tools or annotation techniques do you use to make virtual functions simpler to follow in your disassembly? Solutions for all static analysis toolkits are welcome.</p>
Static analysis of C++ binaries
|static-analysis|ida|c++|vtables|virtual-functions|
<p>I used <a href="https://noraesae.github.io/perfect-scrollbar/" rel="nofollow noreferrer">https://noraesae.github.io/perfect-scrollbar/</a> that is very similar and easy to use</p>
90
2013-03-20T18:51:19.000
<p>I want to know what jQuery plugins Facebook uses for their special scrollbar, like the two on the left, not the normal one on the right:</p> <p><img src="https://i.stack.imgur.com/odVcU.png" alt="enter image description here"></p> <p>(<a href="http://www.pcworld.com/article/240475/two_important_facebook_hover_tricks.html" rel="nofollow noreferrer">source</a>)</p> <p>Generally, how should I go when I want to know what jQuery plugin [website X] uses for [behaviour Y]?</p>
Get used jQuery plugins from website
|javascript|websites|
<p>It is very simple in some architectures, and not very obvious in others. I'll describe a few I'm familiar with.</p> <h2>SystemV x86_64 (Linux, OS X, BSD)</h2> <p>Probably the easiest to recognize. Because of the boneheaded decision to specify the number of used XMM registers in <code>al</code>, most vararg functions begin like this:</p> <pre><code> push rbp mov rbp, rsp sub rsp, 0E0h mov [rbp+var_A8], rsi mov [rbp+var_A0], rdx mov [rbp+var_98], rcx mov [rbp+var_90], r8 mov [rbp+var_88], r9 movzx eax, al lea rdx, ds:0[rax*4] lea rax, loc_402DA1 sub rax, rdx lea rdx, [rbp+var_1] jmp rax movaps xmmword ptr [rdx-0Fh], xmm7 movaps xmmword ptr [rdx-1Fh], xmm6 movaps xmmword ptr [rdx-2Fh], xmm5 movaps xmmword ptr [rdx-3Fh], xmm4 movaps xmmword ptr [rdx-4Fh], xmm3 movaps xmmword ptr [rdx-5Fh], xmm2 movaps xmmword ptr [rdx-6Fh], xmm1 movaps xmmword ptr [rdx-7Fh], xmm0 loc_402DA1: </code></pre> <p>Note how it's using <code>al</code> to determine how many xmm registers to spill onto the stack.</p> <h2>Windows x64 aka AMD64</h2> <p>In Win64 it's less obvious, but here's one sign: the registers that correspond to the elliptic parameters are always spilled onto the stack and at positions that line up with the rest of arguments passed on the stack. E.g. here's the <code>printf</code>'s prolog:</p> <pre><code> mov rax, rsp mov [rax+8], rcx mov [rax+10h], rdx mov [rax+18h], r8 mov [rax+20h], r9 </code></pre> <p>Here, <code>rcx</code> contains the fixed <code>format</code> argument, and the elliptic arguments are passed in <code>rdx</code>, <code>r8</code> and <code>r9</code> and then on the stack. We can observe that <code>rdx</code>, <code>r8</code> and <code>r9</code> are stored exactly one after another, and just below the rest of the arguments, which begin at <code>rsp+0x28</code>. The area [rsp+8..rsp+0x28] is reserved <a href="http://msdn.microsoft.com/en-us/library/ew5tede7.aspx">exactly for this purpose</a>, but the non-vararg functions often don't store all register arguments there, or reuse that area for local variables. For example, here's a <em>non</em>-vararg function prolog:</p> <pre><code> mov [rsp+10h], rbx mov [rsp+18h], rbp mov [rsp+20h], rsi </code></pre> <p>You can see that it's using the reserved area for saving non-volatile registers, and not spilling the register arguments.</p> <h2>ARM</h2> <p>ARM calling convention uses <code>R0</code>-<code>R3</code> for the first arguments, so vararg functions need to spill them onto stack to line up with the rest of parameters passed on the stack. Thus you will see <code>R0</code>-<code>R3</code> (or <code>R1</code>-<code>R3</code>, or <code>R2</code>-<code>R3</code> or just <code>R3</code>) being pushed onto stack, which <em>usually</em> does not happen in non-vararg functions. It's not a 100% foolproof indicator - e.g. Microsoft's compiler sometimes pushes <code>R0</code>-<code>R1</code> onto the stack and accesses them using <code>SP</code> instead of moving to other registers and using that. But I think it's a pretty reliable sign for GCC. Here's an example of GCC-compiled function:</p> <pre><code>STMFD SP!, {R0-R3} LDR R3, =dword_86090 STR LR, [SP,#0x10+var_14]! LDR R1, [SP,#0x14+varg_r0] ; format LDR R0, [R3] ; s ADD R2, SP, #0x14+varg_r1 ; arg BL vsprintf LDR R3, =dword_86094 MOV R2, #1 STR R2, [R3] LDR LR, [SP+0x14+var_14],#4 ADD SP, SP, #0x10 RET </code></pre> <p>It's obviously a vararg function because it's calling <code>vsprintf</code>, and we can see <code>R0</code>-<code>R3</code> being pushed right at the start (you can't push anything else before that because the potential stack arguments are present at <code>SP</code> and so the <code>R0</code>-<code>R3</code> have to precede them).</p>
95
2013-03-20T20:34:26.300
<p>How would a C variable argument function such as <code>printf(char* format, ...)</code> look like when disassembled?</p> <p>Is it always identified by calling convention, or are there more ways to identify it?</p>
Identifying variable args function
|disassembly|calling-conventions|c|
<p>Using ptrace-based dynamic analysis tools on suid binaries makes them run without privileges. Because of this, a copy of the file running as your user is probably sufficient for analysis purposes.</p> <p>When I have had to do this, I used the <a href="http://reverse.lostrealm.com/tools/xocopy.html">xocopy tool</a>, which uses <code>ptrace</code> to reconstruct ELF files when the header is mapped into memory (most compilers do this, possibly for use by the dynamic linker). I haven't tested the tool with ASLR, but you may be able to combine it with some of the techniques covered in other answers. Once the file has been dumped, it can be analysed statically, or run with any dynamic analysis tool.</p>
98
2013-03-20T21:22:29.067
<p>I have a binary on a Linux (Kernel 2.6) which I can execute, but can't read (chmod 0711). Therefore no static analysis is possible.</p> <pre><code>user1: $ ls -l bin -r-s--x--- user2 user1 bin user1: $ file bin setuid executable, regular file, no read permission </code></pre> <p>I'm looking for different dynamic techniques to gather as much information as possible.</p> <p>For example <code>strace</code> works with this executable.</p> <hr> <p>UPDATE : I was able to resolve the issue. <a href="https://reverseengineering.stackexchange.com/a/110">See answer.</a></p> <p>Thank you all &lt;3 this new reverseengineering community rocks!</p>
How can I analyse an executable with no read permission?
|linux|dynamic-analysis|
<p>several possible ways:</p> <ol> <li><p>identify the packer</p> <ul> <li>get standard packers of your platform (<a href="http://upx.sourceforge.net/" rel="nofollow">UPX</a> for example), check if it's not the one used.</li> <li>If it's a standard packer, then maybe you've already won, as it might be documented, or even better, like UPX, it can unpack itself and is open-source.</li> </ul></li> <li><p>identify the algorithm</p> <ul> <li>there are not so many good+widespread packer algorithms (NRV, LZMA, JCAlg, ApLib, BriefLZ). they're usually easily identifiable by their body size or their constants. (I implemented several of them in pure python in <a href="https://code.google.com/p/kabopan/source/browse/#svn%2Ftrunk%2Fkbp%2Fcomp" rel="nofollow">Kabopan</a>)</li> <li>if you can easily identify the packing/encryption algorithm, then you can probably find a clean implementation for static unpacking</li> </ul></li> <li><p>get your hands dirty</p> <ul> <li>if you still don't know the algorithm and it's apparently really a custom one, then read another packer for the same platform (ie once again, read UPX Mips binary and its source), so it can make you familiar with similar (packer) tricks used on your platform.</li> <li>then look for the likely compression algorithm (likely a different-looking piece of code, people <strong>very rarely</strong> mess with them, and re-implement the algorithm in your favorite language, and unpack externally (locate parameters, apply algorithms, modify/reconstruct binary)</li> </ul></li> <li><p>Lazy method by bruteforcing: some algorithms like <a href="http://corkami.googlecode.com/svn/trunk/wip/MakePE/examples/packer/aplib.py" rel="nofollow">ApLib</a> don't have any header nor parameter (not even a size): the algorithm just requires a pointer to a compressed buffer, so it's sometimes enough to just blindly try it on any offset of your binary, and check if we get a decent decompressed buffer (not too small, not huge+full of 00s).</p></li> </ol>
113
2013-03-21T04:24:08.590
<p>Say I have a binary that I'm not able to execute (for example it runs on some device that I don't have one of), but I can disassemble it. I can get the docs on the architecture. (It's MIPS little endian in my case.) But the binary has very few imports, very few strings, etc., so it really seems like it's packed.</p> <p>How can I go about <em>statically</em> unpacking it? (Edit: I mean, unpacking it without any access to the original device.)</p>
Unpacking binary statically
|obfuscation|unpacking|executable|
<p><strong>Compiler</strong></p> <p>The choice of a compiler has minimal effects on the difficulty to reverse engineer your code. The important things to minimize are all related to information leaks from your code. You want to at least disable any runtime type information (RTTI). The leakage of type information and the simplicity of the instruction set of the virtual machine is one of the reasons CLR and JVM code is easier to reverse engineer. They also have an JIT which applies optimizations to code which may reduce the strength of obfuscation. Obfuscation is basically the opposite of optimization and a lot of obfuscations are solved by first applying an optimization pass.</p> <p><strong>Debugging information</strong></p> <p>I would advise you to also turn off any debugging information, even if it doesn't leak any majorly important information today it might do so tomorrow. The amount of information leakage from the debug information varies from compiler to compiler and from binary format to binary format. For instance, Microsoft Visual C++ keeps all important debugging information in an external database, usually in the form of a PDB. The most you might leak is the path you used when building your software.</p> <p><strong>Strings</strong></p> <p>When it comes to strings you should definitely encrypt them if you need them at all. I would aim to replace all the ones that are for error tracing and error logging with numeric enumerations. Strings that reveal any sort of information about what is going on right now in your binary need to be unavailable. If you encrypt the strings, they will be decrypted. Try to avoid them as much as possible.</p> <p><strong>System APIs</strong></p> <p>Another strong source of information leakage is imports of system APIs. You want to make sure that any imported function which has a known signature is well-hidden and can not be found using automatic analysis. So an array of function pointers from something like LoadLibrary/GetProcAddress is out of the question. All calls to imported functions need to go through a one-way function and need to be embedded within an obfuscated block.</p> <p><strong>Standard runtime libraries</strong></p> <p>Something a lot of people forget to take into consideration is the information leaked by standard libraries, such as the runtime of your C++ compiler. I would avoid the use of it completely. This is because most experienced reverse engineers will have signatures prepared for a lot of standard libraries.</p> <p><strong>Obfuscation</strong></p> <p>You should also cover any critical code with some sort of heavy obfuscation. Some of the heavier and cheaper obfuscations right now are <a href="http://oreans.com/codevirtualizer.php" rel="nofollow noreferrer">CodeVirtualizer/Themida</a> and <a href="http://vmpsoft.com/" rel="nofollow noreferrer">VMProtect</a>. Be aware that these packages have an abundance of defects though. They will sometimes transform your code to something which will not be the equivalent of the original which can lead to instability. They also slow down the obfuscated code significantly. A factor of 10000 times slower is not uncommon. There's also the issue of triggering more false positives with anti-virus software. I would advise you to sign your software using a reputable certificate authority.</p> <p><strong>Separation of functional blocks</strong></p> <p>The separation of code into functions is another thing that makes it easier to reverse-engineer a program. This applies especially when the functions are obfuscated because it creates boundaries around which the reverse engineer can reason about your software. This way the reverse engineer can solve your program in a divide-and-conquer manner. Ideally, you would want your software in one effective block with obfuscation applied uniformly to the entire block as one. To reduce the number of blocks, use inlining very generously and wrap them in a good obfuscation algorithm. The compiler can easily do some heavy optimizations and stack ordering which will make the block harder to reverse engineer.</p> <p><strong>Runtime</strong></p> <p>When you hide information it is important that the information is well hidden at runtime as well. A competent reverse engineer will examine the state of your program as it is running. So using static variables that decrypt when loaded or by using packing which is completely unpacked upon loading will lead to a quick find. Be careful about what you allocate on the heap. All heap operations go via API calls and can be easily logged to a file and reasoned about. Stack operations are generally harder to keep track of just because of how frequent they are. Dynamic analysis is just as important as static. You need to be aware of what your program state is at all times and what information lies where.</p> <p><strong>Anti-debugging</strong></p> <p>Anti-debugging is worthless. Do not spend time on it. Spend time on making sure your secrets are well hidden independent of whether your software is at rest or not.</p> <p><strong>Packing and encrypting code segment</strong></p> <p>I will group encryption and packing into the same category. They both serve the same purpose and they both have the same issues. In order to execute the code, the CPU needs to see the plain text. So you have to provide the key in the binary. The only remotely effective way of encrypting and packing code segments is if you encrypt and decrypt them at functional boundaries and only if the decryption happens upon function entry and then re-encryption happens when leaving the function. This will provide a small barrier against dumping your binary as it is running but is must be coupled with strong obfuscation.</p> <p><strong>Finally</strong></p> <p>Study your software in something like the free version of IDA. Your goal is to make sure that it becomes virtually impossible for the reverse engineer to find a steady mental footing. The less information you leak and the more changing the environment is, the harder it will be to study. If you're not an experienced reverse engineer, designing something hard to reverse engineer is almost impossible.</p> <p>If you're designing a copy protection system prepare for it to be broken mentally. Make sure you have a plan for how you will deal with the break and how to make sure the next version of your software adds enough value to drive upgrades. Build your system on solid ground which can not be broken, do not resort to generating your own license keys using some custom algorithm hidden in the manner I described above. The system needs to be built on a sound cryptographic foundation for the unforgeability of messages.</p>
118
2013-03-21T11:05:10.740
<p>If I am building a C++ application and I want to make it more difficult to reverse engineer, what steps can I take to do this?</p> <ul> <li>Does the choice of compiler affect this?</li> <li>What about compiler flags, presumably a high optimization level would help, what about other flags?</li> <li>Does stripping symbols help and not building with debug symbols?</li> <li>Should I encrypt any internal data such as static strings?</li> <li>What other steps might I take?</li> </ul>
What kinds of steps can I take to make my C++ application harder to reverse engineer?
|obfuscation|compilers|c++|symbols|strings|
<p>I think there's a couple of approaches to get where you want. Given your scenario where you have the KB patch on your fully updated system. To get back to the previous version, uninstall that patch.</p> <p>The Metasploit Unleashed class used (still does?) has this command for XP that uninstalls all the patches:</p> <pre><code>C:\&gt;dir /a /b c:\windows\$ntuninstallkb* &gt; kbs.txt &amp;&amp; for /f %i in (kbs.txt) do cd c:\windows\%i\spuninst &amp;&amp; spuninst.exe /passive /norestart &amp;&amp; ping -n 15 localhost &gt; nul </code></pre> <p>Another approach that I think gets you to the same, if not better, state is to install a completely unpatched version of the operating system (e.g. from a MSDN install with no service packs). From here, you can extract the base files. For the patched versions, MSFT provides an ISO every month with the patches. You can extract the patched executables from here. For example, <a href="http://www.microsoft.com/en-nz/download/details.aspx?id=36959" rel="nofollow" title="here's">here's</a> the ISO from this month of security updates.</p>
120
2013-03-21T12:53:55.163
<p>For the purpose of learning about the complexities involved in writing PoC's (and gaining experience in) one could do patch diffing and have real world vulnerable examples to practice on. For now please disregard the idea of making your own vulnerable programs.</p> <p>For patch diffing I see 3 states an OS can be in, let's take windows 7 as example:</p> <ol> <li>Plain state (no service packs, no patches)</li> <li>Partially patched (not updated to the latest released patches)</li> <li>Fully patched</li> </ol> <p><strong>Scenario</strong></p> <ul> <li>My vmware/vbox system is in state 3 (fully patched).</li> <li>Next I go to the Microsoft Security Bulletin and pick a vulnerability (e.g. kernel).</li> <li>Now I want to revert to a useful state...</li> </ul> <p>Although it will likely work on the plain state(1), the diff results will be bigger/harder to spot the issue. Secondly, the bug to the latest vulnerability could have been introduced by a previous patch/service pack.</p> <p><em>Therefore, how does one go from OS state 3 to state 2, where state 2 is a system patched up to just before the new patch that resolves the issue? Or if more convenient, from state 1 to state 2.</em></p> <h2>update</h2> <p>I realize my question isn't as clear as I thought it was in my head, hopefully this clarifies a bit</p> <p>I'm aware of the snapshot features of vmware/vbox but that is not what I'm looking for. What I'm actually aiming for is</p> <ol> <li>How to get the old versions of the changed binaries?</li> <li>How to know to which version to revert? Is there some naming scheme in the files?</li> </ol> <p>Example:</p> <ul> <li>My system is fully up to date.</li> <li>I find a KB-XXXXX at the Security bulletin, extract it and it gives me an updated .dll named abc_005.dll</li> <li>Now I want to put my system in a state that I get the previous (vulnerable) version of the dll (e.g. abc_004.dll). &lt;- How would I do this part?</li> </ul>
How to manage/revert to specific OS versions for effective patch diffing?
|windows|operating-systems|
<p>There is a way to recompile with this opensource app, called RetDec:</p> <p><a href="https://github.com/avast-tl/retdec" rel="nofollow noreferrer">https://github.com/avast-tl/retdec</a></p>
125
2013-03-21T14:30:15.477
<p>I have an Arduino Uno Rev3. I would like to extract and find out what code is burned on the ROM of the micro-controller board. </p> <ol> <li>How do I extract the code from the board?</li> <li>How do I figure out the original source code that went into the hex file? </li> </ol>
How do I figure out what is burned on an Arduino ROM?
|decompilation|rom|dumping|
<p>In the paper <a href="http://www.openpcd.org/images/HID-iCLASS-security.pdf">Heart of Darkness - exploring the uncharted backwaters of HID iCLASS TM security </a> is a technique described (section III.C) that might work,but it does require a working device which might not be at hand in your situation.</p> <p>In short they use a TTL-232 cable in synchronous bit bang mode to emulate the PIC programmer. They then override the boot block by a special dumper firmware. Why it seems to work:</p> <blockquote> <p>Microchip PIC microcontrollers internal memory is an EEPROM which means that data are stored and erase by pages (which hold a predefined amount of data). The "key" point is that , whenever memory is copy protected, individual blocks can be erased resetting the copy protection bits only for these blocks.</p> </blockquote>
128
2013-03-21T15:29:33.923
<p>I have a <a href="http://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf">PIC18F4550</a> from an old device and I need to see the code. I tried reading it using my ICD3 programmer, but the chip seems to have its code protected. How can I get the code anyway?</p>
Get code from protected PIC
|hardware|pic|security|dumping|
<p>I don't think I disassembled any microkernels, but "message passing" is common in at least two categories of programs: Win32 GUI (both raw Win32 and MFC-based), and Objective-C executables.</p> <p>In both cases you have some kind of a central <em>dispatcher routine</em> (or routines) that accept messages and forward them to some <em>recipients</em>, which may be inside or outside the current program.</p> <p>The recipients can be registered dynamically (<code>RegisterClass</code> in Win32) or may be specified in some static fashion (Objective-C class metadata or MFC's message handler tables).</p> <p>As for dispatchers, let's consider Win32's <code>SendMessage</code>. It has arguments <code>hWnd</code> and <code>Msg</code> (and extra parameters). The first specifies the recipient. You may be able to trace where it came from and then just look up the class registration corresponding to the window and check whether its window procedure handles this specific message. I guess you could mark the call with a comment "goes to window procedure 0x35345800" or similar to keep track of it. With MFC you'll need to find the class' message table and look up the corresponding handler.</p> <p>With Objective-C, <code>objc_msgSend</code> accepts the receiving object and the <em>selector</em> to perform. If you can track back the the object, you can check if it has the selector with that name. Or, alternatively, check all selectors with this name in the program. Again, once you found it, make a comment.</p> <p>So, a similar approach can probably be extended to all other message-passing systems - find recipients, then at the place of the dispatcher call check which ones can potentially handle it, and check the handlers. Sometimes you don't even need to actually do the first part - if the message ID/name is unique enough, you may be able to find the handler just by searching for it.</p> <p>A somewhat related problem is working with C++ and virtual functions but it has been covered in <a href="https://reverseengineering.stackexchange.com/questions/87/static-analysis-of-c-binaries">another question</a>.</p> <hr> <p>I've just remembered one more kind of programs that don't use the call stack. It's those that use <a href="http://en.wikipedia.org/wiki/Continuation-passing_style" rel="nofollow noreferrer">Continuation-passing Style</a>, usually written in some kind of a functional language. Greg Sinclair wrote a very nice and entertaining paper on the horrors of disassembling CHICKEN - an implementation of the language Scheme. His site is down but luckily Archive.org <a href="http://web.archive.org/web/20080827225015/http://www.nnl-labs.com/papers/" rel="nofollow noreferrer">kept a copy</a>. One quote from it:</p> <blockquote> <p>For a reverse engineer, Continuation Passing Style means the end of civilianization as we know it.</p> </blockquote>
143
2013-03-22T02:12:29.987
<p>In a microkernel, much of the interesting functionality happens not with traditional function calls, but instead through message passing between separate entities.</p> <p>Is there a structure that OS architectures like this generally use to implement message passing? And is there a methodical way to label this while disassembling, to make it as easy to follow paths of messages as it is to follow the call stack? </p>
Tracing message passing instead of a call stack
|disassembly|static-analysis|operating-systems|
<p>The one stop solution for all pyinstaller exe things. Use this program to reverse engineer a pyinstaller generated exe file. </p> <p><a href="https://sourceforge.net/projects/pyinstallerexerebuilder/" rel="nofollow">https://sourceforge.net/projects/pyinstallerexerebuilder/</a></p>
160
2013-03-22T14:01:31.240
<p>Having recently watched/read a presentation <a href="http://www.trustedsec.com/files/Owning_One_Rule_All_v2.pdf">given by Dave Kennedy at DEF CON 20 [PDF]</a>, I'd like to know how to decompile a Python script compiled with <a href="http://www.pyinstaller.org/">PyInstaller</a>.</p> <p>In his presentation, he is creating a basic reverse shell script in Python, and converts it to an EXE with PyInstaller.</p> <p>My question is how do you take a PyInstaller created EXE and either completely, or generally, retrieve the logic/source code from the original Python script(s)?</p>
How do you reverse engineer an EXE "compiled" with PyInstaller
|python|pe|
<ol> <li>get <a href="http://upx.sourceforge.net/" rel="noreferrer">UPX</a></li> <li>make your own UPX-packed ELFs, with different options (LZMA, NRV,...)</li> <li>As UPX is easy to modify, and very often modified, patched or even faked, comparing the code starts will make it easy to check if your target is indeed UPX-packed, and if this is truely the original UPX version or if it's modified in any way.</li> </ol>
168
2013-03-22T23:31:46.983
<p>I have an ELF file and want to know if it is UPX packed. How can I detect UPX compression in GNU/Linux?</p>
How to check if an ELF file is UPX packed?
|linux|upx|
<p>There is nothing wrong with using <a href="http://wiki.wireshark.org/Protocols/tds" rel="nofollow">the TDS protocol decoder that comes with WireShark</a>, assuming the connection is established via something that can be sniffed by WireShark. This is <strong>a specialized protocol decoder for <a href="http://msdn.microsoft.com/en-us/library/cc448435.aspx" rel="nofollow">TDS</a></strong> so I am not sure what you mean by:</p> <blockquote> <p>I understand that it may be possible to use Wireshark to view the network traffic, but it feels quite clumsy so I am looking for something more specialized for this purpose.</p> </blockquote> <p>If you want to get your hands dirty you can write a proxy based on <a href="http://www.freetds.org" rel="nofollow">FreeTDS</a>. The perhaps biggest problem seems that either this project is now mature or abandoned. The <a href="http://freetds.cvs.sourceforge.net/viewvc/freetds/freetds/src/pool/" rel="nofollow"><code>tdspool</code></a> program is probably your best point to start if you wanted to write a proxy. But it's possible you could coerce jTDS into doing what you want (from a casual reading of the source code it doesn't seem to be as good a starting point as the <code>tdspool</code> program).</p>
171
2013-03-23T06:43:39.273
<p>I am reversing a closed-source legacy application that uses Microsoft SQL Server (2005) and I would like to find out precisely what queries are being executed in the background. </p> <p>I understand that it may be possible to use Wireshark to view the network traffic, but it feels quite clumsy so I am looking for something more specialized for this purpose. </p> <p><strong>Is there a tool that is similar to <a href="https://addons.mozilla.org/en-us/firefox/addon/tamper-data/">Firefox's Tamper Data</a>, but for MSSQL to view, and possibly edit queries?</strong></p> <p>Features that I am looking for:</p> <ul> <li>Able to view queries precisely as executed by the application (including blobs etc.)</li> </ul> <p>Features that would be very useful:</p> <ul> <li>Able to intercept query execution and allow edits to the value</li> </ul>
Viewing MSSQL transactions between closed-source application and server
|windows|mssql|
<p>Clearly Peter has addressed the main points of proper implementation. Given that I have - without publishing the results - "cracked" two different dongle systems in the past, I'd like to share my insights as well. user276 already hints, in part, at what the problem is.</p> <p>Many software vendors think that they purchase some kind of security for their licensing model when licensing a dongle system. They couldn't be further from the truth. All they do is to get the tools that allow them to implement a relatively secure system (within the boundaries pointed out in Peters answer).</p> <p>What is the problem with copy protection in general? If a software uses mathematically sound encryption for its licensing scheme this has no bearing on the security of the copy protection as such. Why? Well, you end up in a catch 22 situation. You don't trust the user (because the user could copy the software), so you encrypt stuff or use encryption somehow in your copy protection scheme. Alas, you need to have your private key in the product to use the encryption, which completely contradicts the notion of mistrusting the user. Dongles try to put the private key (and/or algorithm and/or other ingredients) into hardware such that the user has no access in the first place.</p> <p>However, since many vendors are under the impression that they purchase security out of the box, they don't put effort into the correct implementation. Which brings me to the first example. It's a CAD program my mother was using. Out of the knowledge that dongles connecting to LPT tend to fail more often than their more recent USB counterparts, I set out to "work around" this one. That was around 2005.</p> <p>It didn't take me too long. In fact I used a simple DLL placement attack (the name under which the scenario later became known) to inject my code. And that code wasn't all too elaborate. Only one particular function returned the value the dongle would usually read out (serial number), and that was it. The rest of the functions I would pass through to the original DLL which the dongle vendor requires to be installed along with the driver.</p> <p>The other dongle was a little before that. The problem here was that I was working for a subcontractor and we had limited access only to the software for which we were supposed to develop. It truly was a matter of bureaucracy between the company that licensed the software and the software vendor, but it caused major troubles for us. In this case it was a little more challenging to work around the dongle. First of all a driver had to be written to sniff the IRPs from and to the device. Then the algorithm used for encryption had to be found out. Luckily not all was done in hardware which provided the loop hole for us. In the end we had a little driver that would pose as the dongle. Its functionality was extended so far as to read out a real dongle, save the data (actually pass it to a user mode program saving it) and then load it back to pose as this dongle.</p> <p><strong>Conclusion:</strong> dongles, no matter which kind, if they <em>implement</em> core functionality of the program to which they belong will be hard to crack. For everything else it mostly depends on the determination and willingness to put in time of the person(s) that set out to work around the dongle. As such I would say that dongles pose a considerable hindrance - if implemented correctly - but in cases of negligence on part of the software vendor seeking to protect his creation also mere snake oil.</p> <p>Take heed from the very last paragraph in Peters answer. But I would like to add one more thought. Software that is truly worth the effort of being protected, because it is unique in a sense, shouldn't be protected on the basis of customer harassment (== most copy protection schemes). Instead consider the example of IDA Pro, which can certainly be considered pretty unique software. They watermark the software to be able to track down the person that leaked a particular bundle. Of course, as we saw with the ESET leak, this doesn't help always, but it creates <a href="https://www.hex-rays.com/products/ida/support/hallofshame/index.shtml">deterrence</a>. It'll be less likely that a cracker group gets their hands on a copy, for example.</p>
174
2013-03-23T08:39:25.617
<p>Various software companies distribute their software with hardware security, usually a dongle which must be mounted in order for the software to operate.</p> <p>I don't have experience with them, but I wonder, do they really work?</p> <p>What is it that the dongle actually does? I think that the only way to enforce security using this method, and prevent emulation of the hardware, the hardware has to perform some important function of the software, perhaps implement some algorithm, etc.</p>
Are hardware dongles able to protect your software?
|hardware|security|dongle|
<p>FLIRT stands for <strong>Fast Library Identification and Recognition Technology</strong>.</p> <p>Peter explained the basics, but here's a white paper about how it's implemented:</p> <p><a href="https://www.hex-rays.com/products/ida/tech/flirt/in_depth.shtml">https://www.hex-rays.com/products/ida/tech/flirt/in_depth.shtml</a></p> <blockquote> <p>To address those issues, we created a database of all the functions from all libraries we wanted to recognize. IDA now checks, at each byte of the program being disassembled, whether this byte can mark the start of a standard library function. </p> <p>The information required by the recognition algorithm is kept in a signature file. Each function is represented by a pattern. Patterns are first 32 bytes of a function where all variant bytes are marked.</p> </blockquote> <p>It's somewhat old (from IDA 3.6) but the basics still apply.</p> <p>To create your own signatures, you'll need FLAIR tools, which can be downloaded separately.<br> (FLAIR means Fast Library Acquisition for Identification and Recognition)</p> <p>The IDA Pro book has <a href="http://my.safaribooksonline.com/9781593273750/library_recognition_using_flirt_signatur">a chapter</a> on FLIRT and using FLAIR tools.</p>
175
2013-03-23T08:48:10.120
<p>I've seen this referenced in a couple of other questions on this site. But what's a FLIRT signature in IDA Pro? And when would I create my own for use?</p>
What is a FLIRT signature?
|ida|flirt-signatures|
<p>&quot;ptrace()&quot; was casually mentioned by Giles. But I think it deserved a whole section by itself. &quot;ptrace()&quot; is a system call API provided by OS (Linux and all UNIX have it, and so do Windows) to exert debug control over another process. When you used PTRACE_ATTACH (as part of ptrace()) to attach to another process, the kernel will pause the CPU running that process completely, allowing you to make changes to ANY part of the process: CPU, any registers, any part of that process memory etc. That is how dynamic inline hooking work. (ptrace() attach, modify binary in-memory, and then ptrace() unattached). As far as I know, all dynamic modification of another process has to use ptrace() - as that is the only mechanism provided by kernel to guarantee integrity via system call at this point.</p> <p>But recently similar API like utrace() is popping up, and so inline hooking is also theoretically possible:</p> <p><a href="http://landley.net/kdocs/ols/2007/ols2007v1-pages-215-224.pdf" rel="nofollow noreferrer">http://landley.net/kdocs/ols/2007/ols2007v1-pages-215-224.pdf</a></p> <p>For kernel hooking, there are many methods: syscall, interrupt, and inline hooking. This is for interrupt hooking:</p> <p><a href="http://mammon.github.io/Text/linux_hooker.txt" rel="nofollow noreferrer">http://mammon.github.io/Text/linux_hooker.txt</a></p> <p>When the CPU is in STOP mode, basically you can do anything you like to the CPU/memory space/register - just make sure you restore back to its original state before returning to the original address where it stopped.</p> <p>And if you use library inject technique, you can implement any functionalities - calling remote libraries, remote shell etc:</p> <p><a href="https://attack.mitre.org/techniques/T1055/001/" rel="nofollow noreferrer">https://attack.mitre.org/techniques/T1055/001/</a></p> <p><a href="https://stackoverflow.com/questions/24355344/inject-shared-library-into-a-process">https://stackoverflow.com/questions/24355344/inject-shared-library-into-a-process</a></p> <p><a href="https://backtrace.io/blog/backtrace/elf-shared-library-injection-forensics/" rel="nofollow noreferrer">https://backtrace.io/blog/backtrace/elf-shared-library-injection-forensics/</a></p>
185
2013-03-23T13:55:12.740
<p>I want to add some functionality to an existing binary file. The binary file was created using <code>gcc</code>. </p> <ul> <li>Do I need to decompile the binary first, even though I sufficiently understand the functioning of the program ? </li> <li>How should I go about adding the necessary code ?</li> <li>Do I need any tools to be able to do this ?</li> </ul>
How do I add functionality to an existing binary executable?
|linux|c|executable|hll-mapping|
<p>There are various techniques used and I'll list some.</p> <ol> <li><p><strong>Probing while operating</strong> - if you have a probe station you can operate the device and probe intermediate signals within the die. This requires that the encapsulations (usually Si#N4 -or sometimes Polyimide) needs to also have been removed. Once this is removed the chip has a limited life, but you can't probe through that.</p> <p>Also, the feature size of the chip on top metal must also be large enough to be able to probe. In most modern processes this is very problematic as even on the coarsest resolution layers it is still far too small for probing.</p> <p>In this case, we use a FIB (Focused Ion Beam) machine to cut and also to add test points on the chip. In this case, you'd leave the passivation on and the pad is deposited on top of the passivation. The FIB then cuts through the passivation and connects to the traces below. These machines are typically charged out at $100's per hour.</p> </li> <li><p><strong>Delayering -</strong> The chip is etched layer by layer and photographs and/or electron micrographs are taken at each stage. Understanding the construction of the devices will allow you to regenerate the device structure down to the Si. Here dimensions are important. Understanding the implants into the Si itself requires the use of SIMS (Secondary Ion Mass Spectrograph) machine and tiny holes are milled into the substrate the ions are vacuumed into a Mass spectrometer machine and the species and doping profiles are shown as the machine drills down.</p> <p>There are lots of other machines that are used that can help determine species and doping levels.</p> </li> <li><p>The two techniques above cannot help if there are flash or EEPROM devices, because the state of the device is set by the presence or absence of charge, which you can't read. In this case, there are other tools that are used. You would delayer to just above the gate levels and try to read the stored charge on the floating gate using various techniques like AFM (with the ability to read electron affinity- special attachment). There are even techniques that can be used such as SEM with surface contrast enhancement that allows you to monitor a running chip almost like a strobe light. But this requires that the device can have significant metal layers removed and STILL be operational. Which is not usual.</p> </li> </ol> <p>To fully RE a chip you will require multiple chips and you progressively learn as you slowly step through the various layers.</p> <p>There are many different techniques used, most are developed to help designers debug problems rather than to RE, this is only a short overview at best.</p>
187
2013-03-23T14:05:44.343
<p>I've seen numerous examples of people essentially <a href="http://www.youtube.com/watch?v=mT1FStxAVz4">dissolving away the resin</a> from integrated circuits in boiling high strength acid in order to expose the raw silicon chip underneath. My general understanding is that this has, from time to time, allowed for attackers to determine 'secret' information like crypto keys and the like. In addition, undocumented functionality can be determined and unlocked by doing this in some cases. </p> <p>How can one go about 'reading data' from raw silicon? What kind of other benefits can you obtain from hardware level reverse engineering?</p>
What kind of information can i get from reverse engineering an integrated circuit package
|hardware|integrated-circuit|
<p>Yep, the answer depends on what exactly you are trying to achieve.</p> <p>In terms of analyzing the .NET app itself, you can get a complete source code by using, e.g. DotPeek written by JetBrains. You can even export it into a fully-functional Visual Studio Project, build it and debug. However, some apps may be obfuscated.</p> <p>Another scenario is when a .NET app is a part of another application written in another language (e.g. C++). In this case, most likely .NET code is compiled into DLL which is also can be disassembled using apps like DotPeek.</p> <p>Probably, there are may exist much more complex scenarios like a custom JIT-compiler, embedded into a malware. In such cases, the most reasonable way may be to write a custom plugin (e.g. using IDAPython for IDA Pro). This plugin should be aware of data structures or behavior and can assist you in each step of a reverse engineering process. But writing a custom plugin may require a lot of knowledge of the underlying language and may be a challenge on its own.</p>
197
2013-03-23T18:38:09.513
<p>A lot of code I encounter today has a considerable amount of code generated at runtime, making analysis extremely laborious and time consuming.</p> <p>Is there any way I can create symbolic names for the various functions introduced by the JIT compiler that keep cropping up, or for the various artifacts (such as type information) introduced into the executable through the JIT compiler in GDB or WinDBG?</p>
How can I analyze a program that uses a JIT compiled code?
|debuggers|
<p>First, let's see UPX structure.</p> <h1>UPX Structure</h1> <ol> <li><p>Prologue</p> <ol> <li><p>CMP / JNZ for DLLs parameter checks</p></li> <li><p>Pushad, set registers</p></li> <li><p>optional NOP alignment</p></li> </ol></li> <li><p>Decompression algorithm</p> <ul> <li>whether it's NRV or LZMA</li> </ul></li> <li><p>Call/Jumps restoring</p> <ul> <li>UPX transform relative calls and jumps into absolute ones, to improve compression. </li> </ul></li> <li><p>Imports</p> <ul> <li>load libraries, resolve APIs</li> </ul></li> <li><p>Reset section flags</p></li> <li><p>Epilogue</p> <ul> <li>clean stack</li> <li>jump to the original EntryPoint</li> </ul></li> </ol> <p>For more details, <a href="http://corkami.googlecode.com/files/upx-idb.zip">here</a> is a commented IDA (free version) IDB of a UPX-ed PE.</p> <h1>modified UPX variants</h1> <p>Simple parts like prologue/epilogue are easy to modify, and are consequently often modified:</p> <ul> <li>basic polymorphism: replacing an instruction with an equivalent</li> <li>moving them around with jumps</li> </ul> <p>Complex parts like decompression, calls restoration, imports loading are usually kept unmodified, so usually, custom code is inserted between them:</p> <ul> <li>an anti-debug</li> <li>an extra xor loop (after decompression)</li> <li>a marker that will be checked further in the unpacked code, so that the file knows it was unpacked.</li> </ul> <h2>faking</h2> <p>As the prologue doesn't do much, it's also trivial to copy it to the EntryPoint of a non UPX-packed PE, to fool identifiers and fake UPX packing.</p>
198
2013-03-23T20:12:39.453
<p>Recently I asked a <a href="https://reverseengineering.stackexchange.com/q/168/214"> question about detecting UPX compression</a>. <a href="https://reverseengineering.stackexchange.com/users/245/0xc0000022l">0xC0000022L</a> wanted to know if it was plain UPX. However until that point I only was aware of <a href="http://upx.sourceforge.net/" rel="nofollow noreferrer">plain UPX</a>. So my question is:</p> <ul> <li>What versions/modifications of UPX exist?</li> <li>How do they differ? What features do they have?</li> </ul>
What different UPX formats exist and how do they differ?
|upx|
<p><strong>theZoo</strong><br> theZoo is a project created to make the possibility of malware analysis open and available to the public. Since we have found out that almost all versions of malware are very hard to come by in a way which will allow analysis we have decided to gather all of them for you in an available and safe way. theZoo was born by Yuval tisf Nativ and is now maintained by Shahak Shalev.<br> <a href="https://github.com/ytisf/theZoo/tree/master/malwares/Source" rel="nofollow">Malware Source</a><br> <a href="https://github.com/ytisf/theZoo/tree/master/malwares/Binaries" rel="nofollow">Malware Binaries</a></p>
206
2013-03-23T21:36:15.177
<p>It seems that a popular use of software reverse engineering skills is to reverse malicious code in an effort to build better protection for users.</p> <p>The bottleneck here for people aspiring to break into the security industry through this path seems to be easy access to new malicious code samples to practice on and build heuristics for.</p> <p>Are there any good resources for a person unaffiliated with any organization to download malware in bulk to run analysis on?</p>
Where can I, as an individual, get malware samples to analyze?
|malware|
<p>SetWindowsHookEx isn't really used for this sort of hooking as far as I'm aware. </p> <p>You could hook NtSetInformationThread in the import of the binary you want to analyze and make it always return success on ThreadHideFromDebugger but not forward the call to the actual function. This would be weak since GetProcAddress or manual imports would bypass it.</p> <p>You could hook the NtSetInformationThread function by inserting a call to your own function in the function prologue and then ignore ThreadHideFromDebugger while forwarding the rest to the original function.</p> <p>I strong advice against it but for the sake of completeness, you could also hook NtSetInformationThread in the <a href="http://en.wikipedia.org/wiki/System_Service_Dispatch_Table" rel="noreferrer">system service dispatch table</a>. There's a good dump of the table for different Windows versions <a href="http://j00ru.vexillium.org/ntapi/" rel="noreferrer">here</a>. If you want to get the index in the table yourself you can just disassemble the NtSetInformationThread export from ntdll.dll.</p> <p>If you're interested in more anti-debugging techniques strongly recommend reading <a href="http://pferrie.host22.com/papers/antidebug.pdf" rel="noreferrer">Peter Ferrie's awesome anti-debugging reference</a>.</p>
209
2013-03-23T22:18:53.200
<p>I'm sure many of you are familiar with this classic antidebug trick accomplished by calling <code>ZwSetInformationThread</code> with <code>ThreadInformationClass</code> set to 0x11. Although many OllyDbg modules exist for the purposes of revealing the existence of threads hidden with this method, I haven't been able to find any information on the canonical technique employed to unhide these threads in OllyDbg. </p> <p>Is the function generally hooked in user mode (e.g <code>SetWindowsHookEx</code>), or is it more pragmatic to patch instructions that either call the NTDLL function directly or system calls which indirectly invoke it?</p>
Canonical method to circumvent the ZwSetInformationThread antidebugging technique
|windows|anti-debugging|
<p>Most probably Windows 8 is using <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa385483%28v=vs.85%29.aspx" rel="nofollow">WinINet</a> to connect with the App Store. If this is the case, you can see the unencrypted streams hooking into the wininet.dll instead of using a proxy. <a href="https://code.google.com/p/hookme/" rel="nofollow">HookME</a> does this and it was presented last year in BlackHat.</p> <p>Probably you need to make some minor changes to compile and use it under Windows 8.</p>
211
2013-03-23T23:42:30.040
<p>In Windows Store application development for Windows 8, there is a class called remoteSettings that lets a developer store batches of data so that the user will have access to it across several machines, as long as they are logged in with the same account. </p> <p>I hooked up WireShark and discovered that the packet is stored in Azure, and is secured with TLS. I would like to MITM myself so that I can decrypt the packet and see if the data in encrypted on Azure.</p> <p>I obviously don't have the private key for Azure, so I'd like to know if anyone has an idea on how to accomplish that MITM analysis.</p>
Decryping TLS packets between Windows 8 apps and Azure
|decryption|windows-8|
<p>Given you have a 14 pin package it could be almost anything from a op-amp(s) to 74XX series logic.</p> <p>Start with a continuity tester and see if there are any pins that are obviously shorted together. If so that would be a big hint that they maybe power rails. Also look for common pinouts (Vcc, Vss on corners pins 7,14 etc.). THen use a diode checker and to determine the connectivity of these pins, where to you see opens and shorts, Vforward etc. You will start to see which pins are wired and likely which are +'ve rails and ground -'ve rails. Do keep in mind that there will be ESD protection diodes you will see. If there are no diodes at all then there is a chance that that pin might be a Analog input.</p> <p>Next set your power supply current limit to very low and power up the device via the pins that you thing are the rails. Be aware that you can power up a device through an input pin through the ESD structures, but that is noticeable because outputs will have a output voltage that is one diode drop below rails on them. Increase current limit and test probe and slowly work your way into understanding the chip, eliminating possibilities as you go. IS it an op-amp or logic? An open loop op-amp will act somewhat "digital" but probably won't go to the rails.</p> <p>The permutations and combinations of possibilities and techniques rapidly expand from this point forward.</p>
230
2013-03-24T13:41:43.673
<p>I found a 14 pin integrated circuit with no visible markings. I have no information about its functioning. How should I go about trying to explore its functionality without <a href="https://reverseengineering.stackexchange.com/questions/187/what-kind-of-information-can-i-get-from-reverse-engineering-an-integrated-circui">destroying</a> it ?</p> <p>I have a lot of analog components such as resistors, capacitors and inductors, a variable power source (1V-14V) and a multimeter at hand.</p>
How should I go about investigating an IC's functionality without destroying it?
|hardware|integrated-circuit|
<p>(Answer converted from comment)</p> <p>Recovering the toolchain provenance of the binary code you've specified, at the very least, requires comparing the results of various PIC compilers, I don't know PIC assembly but the last two instructions look interesting for identifying the compiler (Provided your disassembler has misinterpreted the information at <code>0x38</code>, how can the instruction possibly be called?). </p> <p>Some compilers generate prologues to functions intended for quick-n-dirty later patching that can be a giveaway as well. Best of luck! </p>
234
2013-03-24T14:59:36.647
<p>I extracted a .hex file from a PIC16F88. For example:</p> <pre><code>:020000040000FA :100000008F3083160F0570388F009B0183129F017C :1000100083169F0107309C0005108312051483127C :1000200003131730A0006730A1002930A2000A1284 :100030008A11A20B17280A128A11A10B15280A127D :100040008A11A00B13280510831203131730A00088 :100050006730A1002930A2000A128A11A20B2C28B5 :100060000A128A11A10B2A280A128A11A00B282829 :020070000D2859 :02400E00782F09 :02401000FF3F70 :00000001FF </code></pre> <p>In MPLAB, I imported this .hex file and found the disassembly code, in this case:</p> <pre><code> 1 000 308F MOVLW 0x8f 2 001 1683 BSF 0x3, 0x5 3 002 050F ANDWF 0xf, W 4 003 3870 IORLW 0x70 5 004 008F MOVWF 0xf 6 005 019B CLRF 0x1b 7 006 1283 BCF 0x3, 0x5 8 007 019F CLRF 0x1f 9 008 1683 BSF 0x3, 0x5 10 009 019F CLRF 0x1f 11 00A 3007 MOVLW 0x7 12 00B 009C MOVWF 0x1c 13 00C 1005 BCF 0x5, 0 14 00D 1283 BCF 0x3, 0x5 15 00E 1405 BSF 0x5, 0 16 00F 1283 BCF 0x3, 0x5 17 010 1303 BCF 0x3, 0x6 18 011 3017 MOVLW 0x17 19 012 00A0 MOVWF 0x20 20 013 3067 MOVLW 0x67 21 014 00A1 MOVWF 0x21 22 015 3029 MOVLW 0x29 23 016 00A2 MOVWF 0x22 24 017 120A BCF 0xa, 0x4 25 018 118A BCF 0xa, 0x3 26 019 0BA2 DECFSZ 0x22, F 27 01A 2817 GOTO 0x17 28 01B 120A BCF 0xa, 0x4 29 01C 118A BCF 0xa, 0x3 30 01D 0BA1 DECFSZ 0x21, F 31 01E 2815 GOTO 0x15 32 01F 120A BCF 0xa, 0x4 33 020 118A BCF 0xa, 0x3 34 021 0BA0 DECFSZ 0x20, F 35 022 2813 GOTO 0x13 36 023 1005 BCF 0x5, 0 37 024 1283 BCF 0x3, 0x5 38 025 1303 BCF 0x3, 0x6 39 026 3017 MOVLW 0x17 40 027 00A0 MOVWF 0x20 41 028 3067 MOVLW 0x67 42 029 00A1 MOVWF 0x21 43 02A 3029 MOVLW 0x29 44 02B 00A2 MOVWF 0x22 45 02C 120A BCF 0xa, 0x4 46 02D 118A BCF 0xa, 0x3 47 02E 0BA2 DECFSZ 0x22, F 48 02F 282C GOTO 0x2c 49 030 120A BCF 0xa, 0x4 50 031 118A BCF 0xa, 0x3 51 032 0BA1 DECFSZ 0x21, F 52 033 282A GOTO 0x2a 53 034 120A BCF 0xa, 0x4 54 035 118A BCF 0xa, 0x3 55 036 0BA0 DECFSZ 0x20, F 56 037 2828 GOTO 0x28 57 038 280D GOTO 0xd </code></pre> <p>Now I want to know with what compiler this code is compiled. How can I do that? I'm looking for <em>general</em> ways to check what compiler made some ASM code. The code listed is just an example.</p>
How to see what compiler made PIC ASM code?
|disassembly|compilers|pic|hex|
<p>The feature is described in a bit more detail on <a href="http://sourceware.org/gdb/wiki/ProcessRecord" rel="noreferrer">GDB wiki</a>:</p> <blockquote> <h2>How it works</h2> <p>Process record and replay works by logging the execution of each machine instruction in the child process (the program being debugged), together with each corresponding change in machine state (the values of memory and registers). By successively &quot;undoing&quot; each change in machine state, in reverse order, it is possible to revert the state of the program to an arbitrary point earlier in the execution. Then, by &quot;redoing&quot; the changes in the original order, the program state can be moved forward again.</p> </blockquote> <p><a href="http://www.ckernel.org/news/hellogcc/prec.pdf" rel="noreferrer">This presentation</a> describes even more of the internals.</p> <p>In addition to above, for some remote targets GDB can make use of their &quot;native&quot; <a href="http://sourceware.org/gdb/current/onlinedocs/gdb/Reverse-Execution.html" rel="noreferrer">reverse execution</a> by sending Remote Serial Protocol <a href="http://sourceware.org/gdb/current/onlinedocs/gdb/Packets.html" rel="noreferrer">packets</a> <code>bc</code> (backward continue) and <code>bs</code> (backward step). Such targets <a href="http://sourceware.org/gdb/news/reversible.html" rel="noreferrer">include</a>:</p> <ul> <li>moxie-elf simulator</li> <li>Simics</li> <li>VMware Workstation 7.0</li> <li>the SID simulator (xstormy16 architecture)</li> <li>chronicle-gdbserver using valgrind</li> <li>UndoDB</li> </ul>
243
2013-03-24T17:46:39.220
<p>A curious and useful feature of GDB is <a href="http://sourceware.org/gdb/current/onlinedocs/gdb/Process-Record-and-Replay.html#Process-Record-and-Replay">process recording</a>, allowing an analyst to step forwards and backwards through execution, writing a continuous log of the changes to program state that allow for remarkably accurate playback of program code.</p> <p>Although we can all safely say the process recording log contains the executable's changes to the various data and control registers, the functionality is much more than keeping some serialized representation of the current continuation. For example, I've been able to reify the state of an executable that uses threads to modify shared memory.</p> <p>Certainly we can't expect time dependent code to work, but if threading code modifying shared state can, in general, be stepped through backwards and <em>still work reliably again</em>, what limitations does process recording have beyond the purely architectural challenges (i.e displaced stepping) specified in the documentation?</p>
How does GDB's process recording work?
|gdb|debuggers|
<p>courtsey <strong>Hotpatching and the Rise of Third-Party Patches</strong> presentation at BlackHat USA 2006 by <strong>Alexander Sotirov</strong></p> <p><strong>What Is Hotpatching?</strong> Hotpatching is a method for modifying the behavior of an application by modifying its binary code at runtime. It is a common technique with many uses:</p> <p>• debugging (software breakpoints)</p> <p>• runtime instrumentation</p> <p>• hooking Windows API functions</p> <p>• modifying the execution or adding new functionality to closed-source applications</p> <p>• deploying software updates without rebooting</p> <p>• fixing security vulnerabilities</p> <p><strong>Hotpatches</strong> are generated by an automated tool that compares the original and patched binaries. The functions that have changed are included in a file with a .hp.dll extension. When the hotpatch DLL is loaded in a running process, the first instruction of the vulnerable function is replaced with a jump to the hotpatch.</p> <p>The <strong>/hotpatch</strong> compiler option ensures that the first instruction of every function is a <strong>mov edi, edi</strong> instruction that can be safely overwritten by the hotpatch. Older versions of Windows are not compiled with this option and cannot be hotpatched.</p>
250
2013-03-25T09:56:00.087
<p>I see this instruction in the beginning of several Windows programs. It's copying a register to itself, so basically, this acts as a <code>nop</code>. What's the purpose of this instruction?</p>
What is the purpose of 'mov edi, edi'?
|disassembly|windows|
<p>There are several tools that I have used:</p> <ol> <li><a href="http://tuts4you.com/download.php?view.398">PEiD</a> (PE iDentifier)</li> <li>I've also followed <a href="https://code.google.com/p/pefile/wiki/PEiDSignatures">this guide</a> and converted PEiD signatures to YARA signatures and simply used <a href="https://code.google.com/p/yara-project/">YARA</a></li> <li><a href="http://mark0.net/soft-trid-e.html">TRiD</a> can also provide another way to identify the compiler used</li> </ol> <p>It's also worth mentioning that if you submit a file to <a href="https://www.virustotal.com">Virus Total</a>, they will run TRiD against your binary.</p> <p>These tools are not always definitive, but they can generally give you the correct compiler (and therefore language) that was used.</p>
252
2013-03-25T14:41:09.427
<p>I have an executable file and I would like to figure out which programming language was the source code written in. The first step would be to use a disassembler. </p> <p>What should be done after that ?</p> <p>Also, I read that determining which libraries are used during runtime would be a good indicator of the programming language being used. How should I determine which libraries are used ?</p>
How should I go about trying to figure out the programming language that was used?
|linux|executable|
<p>I'm the author of <a href="http://rainbowsandpwnies.com/rdis/">rdis</a> and have put a bit of thought into this problem. I recommend taking a look at my <a href="http://rainbowsandpwnies.com/~endeavor/blog/">blog</a> if you have more questions after this.</p> <p>I would also refer you to Andrew Ruef's blog post <a href="http://www.mimisbrunnr.net/~munin/blog/binary-analysis-isnt.html">Binary Analysis Isn't</a>. The key take away is we often attempt to understand our programs with the context of compilers, and not necessarily as just a continuum of instructions. He coins the term, "Compiler Output Analysis," which is more or less what we attempt to achieve in our disassemblers.</p> <h2>Terms and Definitions</h2> <p>Start over with your definitions of terms common to disassembly. We have data, or state, which can be composed of memory, registers, all the good stuff. We have code, which is <em>a label we apply to data we expect the machine to execute</em> (we'll come back to code). We have a program, which is an algorithm encoded in the data which, when interpreted by a machine, causes the data to be manipulated in a certain way. We have a machine which is a mapping of one state to another. We have instructions which, for our purposes, exist at a single point in time and are composed of specific pieces of data which control the way our machine manipulates data.</p> <p>Often times we believe our goal is the transformation of code, the data we expect to be executed by the machine, into a readable disassembly. I believe we do this because of our division of program analysis between Control-Flow Analysis (Code) and Data-Flow Analysis (Data). In program analysis, our code is state-less, and our data has state. In reality, our code is just data, it all has state.</p> <h2>Program Recovery</h2> <p>Instead, our goal should be the recovery of the program by observation or prediction of the machine. In other words, we are not interested in transforming data into a readable disassembly, but in discovering the instructions which will be interpreted by our machine.</p> <p>Additionally, our representation of the program should be stored <em>separately</em> from our stateless representation of data, which is usually the initial memory layout given to us by our executable file (ELF/PE/MACH-O/etc). Really, it should be stored in a directed graph. When I see a linear representation of memory with multiple locations labelled as instructions, I shutter. You don't know yet!</p> <p>I believe the next step in disassembly involves processes which make better predictions about machines by allowing for changes in state during the disassembly process. I believe we will have both emulated disassembly and abstract disassembly. Some people are, more or less, doing this already, though I am unsure if anyone is doing it expressly for the purpose of creating usable and understandable "program recoveries".</p> <p>You can see an example of the difference between a recursive disassembly of a program and an emulated disassembly of a program <a href="http://rainbowsandpwnies.com/~endeavor/blog/a-magical-time-traveling-control-flow-graph.html">here</a>.</p> <h2>What is a correct disassembler?</h2> <p>So, now to answer your question, "What is a correct disassembler?" I believe a correct disassembler is one which clearly defines the behavior of its program recovery process and adheres to this definition. Once we get disassemblers which do THAT, the better disassemblers will be the ones whose definitions best predict the behavior of the machines for which they recover programs.</p>
255
2013-03-25T17:02:44.300
<p>A disassembler is supposed to produce a human readable representation of the binary program. But the most well known techniques: <em>linear sweep</em> and <em>recursive traversal</em> (see this <a href="https://reverseengineering.stackexchange.com/questions/139/what-are-the-techniques-disassemblers-use-to-process-a-binary/140#140">comment</a> for more) are known to be easily mislead by specific tricks. Once tricked, they will output code that will never be executed by the real program.</p> <p>Thought there exists new techniques and new tools more concerned about correctness (eg <a href="http://www.jakstab.org/" rel="nofollow noreferrer">Jakstab</a>, <a href="http://www.grammatech.com/research/technologies/mcveto" rel="nofollow noreferrer">McVeto</a>, ...), the notion of <em>correctness</em> of the output has never been properly defined, up to my knowledge, for disassemblers.</p> <p>What would be a good definition of a disassembler, what would be a proper definition of correctness for its output and how would you classify the existing disassemblers in regard of this definition of <em>correction</em> ?</p>
What is a correct disassembler?
|obfuscation|disassembly|static-analysis|
<p>Well, obviously the particulars will very much depend on the particulars of the file format and what you expect to achieve in general. However, some steps will largely be the same. One thing you could do is:</p> <ol> <li>try hard to find all kinds of clues about the format. This can be a small note in some bulletin board or the cached copy of some year old website that has since vanished. Often the gems won't pop up as top search results when you are looking for something specific enough. Weeding through pages of search results <em>can make sense</em>. Als make sure to use tools such as <code>file</code> which look for magic bytes and would be able to identify things not obvious to the naked eye.</li> <li>find a proprietary program that uses the format and is able to read/write it (you seem to have that) <ol> <li>Use a trial &amp; error technique such as making distinct changes to the document, saving them and observing and noting down the differences, AFAIK this is how the MS Office file formats were decoded initially for StarOffice (now OOo and LibreOffice)</li> <li>reverse engineer the program itself to find the core routines reading and writing the data format</li> </ol></li> <li>find an open source program in the same way -> read its source</li> </ol> <p>If you understand the language in which the program from option 3 is written, no problem at all. If you don't have that or if you are faced with other challenges then you have to resort to the good old technique outlined in point 2, patching gaps with pieces you gather with method 1.</p> <p>The point 2.1 should be obvious: you want to find out how recursive text is encoded? Type some text, format it, save, observe the change. Rinse, lather, repeat.</p> <p>Point 2.2 will take a lot more effort and should likely be used sparsely to make sure you got details from 2.1 right.</p>
261
2013-03-25T21:45:01.723
<p>How should I begin trying to reverse engineer this file format? The only thing I can think of is saving a simple file, and then dig in with a hex editor. But since the file format may be some kind of archive, that seems like the wrong approach. I've always been a little interested in the idea of reverse-engineering a file format, but I never actually attempted it. How should I begin?</p> <p>In particular, I am interested in <a href="http://smarttech.com/us/Solutions/Education+Solutions/Products+for+education/Software/SMART+Notebook+collaborative+learning+software/SMART+Notebook+collaborative+learning+software">Smart Notebook</a> which loads and saves data into .notebook files. This is an undocumented proprietary file format. SMART is the leading manufacturer of white boards and their notebook software is therefore one of the most popular formats for educational (presentation) content. There is an open standard for whiteboard files and <a href="http://open-sankore.org/">Open Sankore</a> is an open source program that can open and save them. However, Smart Notebook is not fully compatible with the open whiteboard format so I really would like to understand the .notebook file format so that I can write software that makes use of it. The open stand (.iwb files) are zip archives that contain images and SVG data. It occurs to me that .notebook files may also be compressed or at least contain a number of sub-files within it (like images and swf files). </p>
How to reverse engineer a proprietary data file format (e.g. Smartboard Notebook)?
|file-format|
<p>The Legend of R4ndom has a long series on a variety of reversing topics. <strike><a href="http://thelegendofrandom.com/blog/sample-page" rel="nofollow noreferrer">http://thelegendofrandom.com/blog/sample-page</a></strike><br> <a href="http://octopuslabs.io/legend/blog/sample-page.html" rel="nofollow noreferrer">http://octopuslabs.io/legend/blog/sample-page.html</a></p>
265
2013-03-25T23:14:30.373
<p>Can someone give a list of websites with good (and free) reverse engineering training exercises ?</p>
Where to find (free) training in reverse engineering?
|obfuscation|cryptography|
<p>(I was planning to make it a comment but it turned out rather long and it makes an answer on its own)</p> <p>Some of the comments mentioned the Hex-Rays decompiler. Its basic ideas are not a trade secret and are in fact described in the <a href="https://www.hex-rays.com/products/ida/support/ppt/decompilers_and_beyond_white_paper.pdf">white paper</a> by Ilfak Guilfanov which accompanies <a href="http://www.youtube.com/watch?v=00EqvVtLdJo">the presentation</a> he gave in 2008.</p> <p>I'll paste the relevant part here:</p> <blockquote> <h3>Local variable allocation</h3> <p>This phase uses the data flow analysis to connect registers from different basic blocks in order to convert them into local variables. If a register is defined by a block and used by another, then we will create a local variable covering both the definition and the use. In other words, a local variable consists of all definitions and all uses that can be connected together. While the basic idea is simple, things get complicated because of byte/word/dword registers.</p> </blockquote> <p>It's simple on the surface but of course the implementation has to account for numerous details. And there's always room for improvement. There's this passage:</p> <blockquote> <p>For the time being, we do not analyze live ranges of stack variables (this requires first a good alias analysis: we have to be able to prove that a stack variable is not modified between two locations). I doubt that a full fledged live range analysis will be available for stack variables in the near future.</p> </blockquote> <p>So, for stack variables the approach right now is simple: each stack slot is considered a single variable for the whole function (with some minor exceptions). The decompiler relies here on the work done by IDA during disassembly, where a stack slot is created for each access by an instruction.</p> <p>One current issue is multiple names for the same variable. For example, the compiler may cache the stack var in a register, pass it to some function, then later reload it into another register. The decompiler has to be pessimistic here. If we can't prove that the same location contains the same value at two points in time, we can't merge the variables. For example, any time the code passes an address of a variable to a call, the decompiler has to assume the call may spoil anything after that address. So even though the register still contains the same value as the stack var, we can't be 100% certain. Thus the excess of variable names. User can override it with manual mapping, however.</p> <p>There are some ideas about introducing function annotations that would specify exactly how a function uses and/or changes its arguments (similar to Microsoft's SAL) which would alleviate this problem, but there are some technical implementation issues there.</p>
287
2013-03-26T16:31:58.307
<p>Assuming we have an assembly code, what are the known techniques that could be used to recover the variables used in the original high-level code ?</p> <p><strong>Edit</strong>: By <em>recovering variables</em>, I do not mean <em>recovering variable names</em>, but trying to identify memory locations that are used to store temporary results that could be replaced by a variable in the high-level code. Also, I am not speaking about bytecodes, but real binary code with no type information, nor complete names embedded in it.</p>
How to recover variables from an assembly code?
|decompilation|disassembly|static-analysis|
<p>A simple logic analyzer, such as the <a href="http://www.saleae.com/">Saleae</a> is invaluable for finding simple transmit serial pins. Receive serial pins are harder due to them being silent. </p> <p>Are you sure that this is <a href="http://en.wikipedia.org/wiki/RS232">RS232</a> and not just serial? It's pretty rare to see RS232 on embedded systems unless they're industrial. <a href="http://en.wikipedia.org/wiki/RS232#Voltage_levels">RS232 goes way above TTL levels</a>.</p>
291
2013-03-26T16:48:45.367
<p>I have a device with two chips without part numbers. It looks like their using RS232 for serial communication (proper setup, right voltage), but I do not know the bus settings (speed, parity, etc.). Is there any way to determine the bus settings without brute force (trying everything)? </p> <p>I have a multimeter and an oscilloscope on my workbench.</p>
Determining RS232 bus settings
|communication|serial-communication|
<p>My guess is that the protocol is standard, using a non standard protocol between two devices involves using bitbanging which is not very useful. Let's assume then that the protocol is standard. It's not SPI, SPI needs 4 lines To work. I2C needs two, RS232 needs only two. I don't know what the third line job is, maybe it's used for trigerring/synchronization between the chips.</p> <p>What now ? I would open the data sheet of the microcontroller and see what protocols the chips supports, usually if they are new 32bit SOC, they all support CAN, SPI, USART, etc. Then I would check the pinout of the corresponding lines, to see to which ports they are connected on the chip. This will point you to the exact protocol used.</p> <p>Then connect a logic analyzer, such as this <a href="http://www.saleae.com/logic/" rel="nofollow">one</a>, which is bundled with a software that can dumo the data transfered acordding to the protocol.</p>
298
2013-03-26T18:11:01.840
<p>I have two chips that are connected using two lines. One appears to be the clock line (50% duty cycle), but it doesn't have to be (sometimes constant high). The other line appears to be totally random, but still digital. It might be data.</p> <p>There is a third line between the chips, but it appears to be for something else - it's on a way slower speed and is on another place on the PCB. It also doesn't use a pull-up, while the other two do.</p> <p>How can I find out what protocol (I2C, SPI, RS232, ...) is being used on the lines, if any standard?</p>
Determining communication protocol
|communication|pcb|
<p><strong>Non Destructive</strong></p> <p>Highly unlikely to be successful unless you have intimate knowledge of how the pacakges were epoxied together. If you did go this route it might be possible to break down the glue that binds the chips together a REing effort in its own right. Once you did that it might not be possible to join them back together without machinery to align the chips under x-ray. And even then the soder balls might not be too happy about what you have done to them...</p> <p><strong>Destructive</strong></p> <p>Since package on package usually means the chips are epoxied together you basically have to distroy the packages to get them appart. Once you did you could look at them under microscope and RE them that way. You could possibly separate them without damaging the interconnects and test the top chip... as a black box I would imagine the bottom chip woudln't work without the top one though since it is usually RAM at least in mobile devices.</p> <p><strong>Related Info</strong> <a href="http://www.smartcard.co.uk/articles/Whatthesiliconmanufacturerhasputtogetherletnomanputasunder.php" rel="nofollow">Christopher Tarnovsky</a> and <a href="http://www.chipworks.com" rel="nofollow">http://www.chipworks.com</a></p> <p>That company specializies in REing chips... and that is the sort of setup you would need to do it sucessfully. 1 million+ USD for something like an arm processor.</p>
299
2013-03-26T18:51:06.220
<p>To analyze the communication protocol between two chips running unknown firmware, we eavesdrop into the communication bus between the chips. In the ideal case, this is “just” a matter of matching exposed paths on a PCB with the contacts of a logic analyzer.</p> <p>What if the chips are stacked in a <a href="http://en.wikipedia.org/wiki/Package_on_package" rel="noreferrer">package on package</a> configuration? How can the contacts be exposed? Can the chips be separated? Does this damage the chips, or will they look as new afterwards?</p>
Exposing the connectors in a package on package
|integrated-circuit|communication|
<p>It sounds like what you need is node groups. Since the very first implementation (5.0) IDA's graph view allowed to group several nodes into one "super-node" with a custom title. Just select the nodes you want to group with Ctrl-click and choose "Group nodes" from the context menu.</p> <p>For more info, see "Graph node groups" in IDA's help or <a href="https://www.hex-rays.com/products/ida/support/idadoc/1129.shtml">online</a>.</p>
302
2013-03-27T00:13:18.707
<p>When reverse engineering programs, I often find functions like the one below. This function in particular has a set of nested if/else blocks (pink boxes) which would typically be fairly easy to follow. When code executes at the blue box however, the code becomes messy and can take either of two independent code paths (purple or yellow). If the developer had used a function (or not used an inline function) for the purple or yellow code blocks, this code would be much easier to reverse engineer. As a function, I can rename and comment on the code block, and the overall program becomes easier to read.</p> <p>My usual technique when I come across this kind of function is to apply colors to the code blocks like you see in the graph below. Is there a way for IDA to treat an arbitrary collection of code blocks as a function that is not called and/or are there better approaches to dealing with inline code and independent code blocks?</p> <p><img src="https://i.stack.imgur.com/kmK4c.png" alt="Large function"></p>
Treating independent code as a function in IDA Pro
|ida|
<p>Somebody at XKCD fora pasted a link to this <a href="https://gist.github.com/cincodenada/5246094">gist</a> which contains a deobfuscated and annotated source along with some explanations: </p> <blockquote> <p>The main part of Javascript that drives xkcd's "Time" comic (<a href="http://xkcd.com/1190/">http://xkcd.com/1190/</a>), deobfuscated and annotated. The bulk of the script seems to be an implementation of EventSource - which, while important, is not terribly interesting for our purposes, so I've omitted it here. After some Googling around, I am in fact fairly certain that the EventSource implementation used here is <a href="https://github.com/Yaffle/EventSource">https://github.com/Yaffle/EventSource</a> - after minifying and beautifying that code, it looks very similar to what shows up in time07.min.js.</p> </blockquote> <p>As far as I can tell, it has no magic in it and serves just as a simple way for the server to let the client know when there is a new image. </p>
306
2013-03-27T01:16:39.540
<p>The latest (as of now) comic is titled <a href="http://xkcd.com/1190/">"Time"</a>. It's a standard-looking comic though without much action, but the picture's alt title says "Wait for it.". I waited but nothing happened (tried in Opera and IE9) so I took a look at the page source.</p> <p>Next to the picture's <code>&lt;img&gt;</code> tag there was a <code>&lt;script&gt;</code> which included the following URL:</p> <p><a href="http://imgs.xkcd.com/static/time07.min.js">http://imgs.xkcd.com/static/time07.min.js</a></p> <p>I tried to make sense of it, but I can't figure it out. Can someone explain how it works and what was supposed to happen?</p>
Reverse engineering XKCD 1190
|javascript|websites|
<p>Since you already have the source file, I believe that there is a simpler and easier approach (as compared to rerouting network traffic on low levels would be to intercept the methods being called.)</p> <p>Firstly, identify and replace methods in your php file (remember to make a copy!). For example, if you want to intercept <code>mail()</code>, you can find <code>mail(</code> and replace it with <code>shim_mail(</code>. You can also do so for other <em>interesting</em> methods such as <code>mysql_connect()</code>. </p> <p>Once you finish, add <code>include 'shim.php';</code> at the top of your file. The "shim" will act as a layer between the php script and the actual method, so you can choose to log it to a text file, allow it to execute, or even point it to a replica database!</p> <p><strong>shim.php</strong> <pre><code>$logfile = 'log.txt'; function shim_mysql_connect($server, $username, $password, $new_link = false, $client_flags = 0) { file_put_contents($logfile, file_get_contents($logfile) . "\r\nmysql_connect() to " . $server . " with username " . $username . " and password " . $password); // intercept the command and point it to the 'honeypot' return mysql_connect('your_new_server', 'username', 'password'); } function shim_mail($to, $subject, $message, $additional_headers = '', $additional_parameters = '') { file_put_contents($logfile, file_get_contents($logfile) . "\r\nmail() to " . $to . " with subject " . $subject . " and message " . $message); // don't actually send an email } ?&gt; </code></pre> <p>In this shim file, you can add functions that you are interested to find out about (simply by copying the same method signature as the original file and printing relevant logs). By observing the log, you can probably find out a lot more about the php script!</p> <p>(while I was midway composing this, I realized that Daniel W. Steinbrook has also come up with a similar method. My method has a slight advantage that it is simpler without adding new dependencies, but runkit sounds like a more <em>correct</em> way. Either way, you can simply pick one that works!)</p>
310
2013-03-27T08:23:11.430
<p>I have a very messy PHP script of which I need to determine the function. I can't quite understand the code, it's <em>really</em> messy. Now I thought that I perhaps could reverse engineer this script.</p> <p>What I want to do is to run this script (eventually with specific parts commented) to gain a better understanding of what part of the script does what. With that information, I should be able to get a full understanding of the script.</p> <p>However, I do not want to change anything in the database on the server, I do not want that the script is going to mail things, etc. Basically, the script should be totally separated from the world, but I do want to see what it <em>tries</em> to do. So, for example, when the script runs a <code>mail()</code> function, I want to see that a mail would've been sent if the script wasn't separated from the world.</p> <p>I therefore need a copy of the server installation (Ubuntu Server 12.04), which isn't that hard. The hard part is that I need to have a system which <em>acts</em> like it is the outside world, but actually is a <em>logging system</em> in which I can see what's happening. </p> <p>Are there any tools that can do this? If not, how should I go in building it myself?</p>
Secure RE-ing a PHP script
|tools|php|
<p>Java and .NET both include a feature called &quot;reflection&quot;, which makes it possible to access inner workings of a class and instances thereof, using runtime-generated strings that hold the names of those features. In C code, if one includes a structure definition:</p> <pre><code>struct foo { int x,y,z,supercalifragilisticexpialidocious; }; </code></pre> <p>expressions that access field <code>supercalifragilisticexpialidocious</code> will generate machine code that accesses an <code>int</code>-sized object at offset <code>3*sizeof(int)</code> in the structure, but nothing in the machine code will care about the name.</p> <p>In C# by contrast, if code that was running with suitable Reflection permissions were to generate the string <code>x</code>, <code>y</code>, <code>z</code>, <code>supercalifragilisticexpialidocious</code>, or <code>woof</code> somehow, and used Reflection functions to retrieve the value of the field having that name (if any) from an instance of that type, the Runtime would need to have access to the names of those fields. Even if a program would in fact never use Reflection to access the fields by name, there would generally be no way the Compiler could know that. Thus, compilers need to include within executable programs the names of almost all identifiers used the source code, without regard for whether anything would ever care about whether or not they did so.</p>
311
2013-03-27T10:12:23.533
<p>Java and .NET decompilers can (usually) produce an almost perfect source code, often very close to the original.</p> <p>Why can't the same be done for the native code? I tried a few but they either don't work or produce a mess of gotos and casts with pointers.</p>
Why are machine code decompilers less capable than for example those for the CLR and JVM?
|decompilation|x86-64|x86|arm|
<p>In addition to the fine suggestions in the other answers, here are some suggestions specific to audio:</p> <ul> <li>If you know how long the playtime of the audio is (roughly), calculate the approximate bitrate of the audio file. This will tell you whether it is compressed or not, and the compression ratio can tell you roughly what you might be dealing with. For example, 4kbps~32kbps is indicative of a speech codec, 64~256kbps is ordinary compressed audio (AAC/MP3/Ogg Vorbis), 512~3072kbps likely means a lossless codec, and substantially higher means uncompressed or weakly compressed (e.g. ADPCM, PCM) audio. In turn, this may clue you into what it contains (speech, music, sound effects, etc.).</li> <li>If you suspect it might be weakly compressed, try opening the file up as a raw PCM stream in your favorite audio editor (e.g. Audacity) and listening to it. There will probably be an insane amount of noise if it's compressed in any way, but some formats (e.g. ADPCM) can still be audible in this circumstance if they are relatively constant bitrate. I've used this tactic in the past to work out the spoken contents of a (still unknown) audio sample I received. Indeed, this tactic can even reveal the contents of poorly encrypted, uncompressed files by exploiting human pattern recognition.</li> <li>Check for metadata chunks in the file -- <code>strings</code>, a quick examination of the first and last chunks of the file in a hex editor, or just searching for strings you might expect to see.</li> </ul>
324
2013-03-27T14:20:54.423
<p>I have an audio file in an unknown format. How should I try to determine its format ?</p> <p>Also, is it possible to do this by manual observation and not using any automated tool ?</p>
How should I determine the format of this audio file?
|file-format|
<p>At the moment, there is no way to debug a dylib. I know that it is a real problem, and I plan to add such a feature in a future update.</p> <p>Another thing that will be added to Hopper is the ability to load multiple file in the same document, in order to disassemble things like kext for instance.</p>
1327
2013-03-27T16:15:00.803
<p>Can external libraries be used in Hopper scripts? I'd like to add PDB support to <a href="http://www.hopperapp.com/">Hopper</a> using <a href="https://code.google.com/p/pdbparse/">pdbparse</a>, but I haven't been able to get it to use external libraries.</p> <p>Alternatively, I suppose one could just dump the debug symbol offsets to a text file and read that, but it seems like a clunkier solution (since you wouldn't be able to, e.g., auto-download symbols from the MS Symbol Server).</p>
Importing external libraries in Hopper scripts?
|disassembly|python|hopper|pdb|
<p>You're looking for this on the command line (for a class called MyClass):</p> <p>On Unix/Linux:</p> <pre><code>javap -verbose MyClass | grep "major" </code></pre> <p>On Windows:</p> <pre><code>javap -verbose MyClass | findstr "major" </code></pre> <p>You want the major version from the results. Here are some example values:</p> <ul> <li>Java 1.2 uses major version 46</li> <li>Java 1.3 uses major version 47</li> <li>Java 1.4 uses major version 48</li> <li>Java 5 uses major version 49</li> <li>Java 6 uses major version 50</li> <li>Java 7 uses major version 51</li> <li>Java 8 uses major version 52</li> </ul>
1328
2013-03-27T16:24:44.427
<p>I have a java class file. How do I find out the version of the compiler used to compile this file? I'm on Ubuntu Server 12.04.</p>
Find out a Java class file's compiler version
|compilers|java|
<p>Your best bet is to contact Adam Roben directly for the symbol files. He seems to be the person who put these out 5 years ago.</p> <p>You can find his email and some more information regarding symbol server at the following links. <a href="http://trac.webkit.org/changeset/35512" rel="nofollow">http://trac.webkit.org/changeset/35512</a> <br> <a href="https://lists.webkit.org/pipermail/webkit-dev/2008-August/004741.html" rel="nofollow">https://lists.webkit.org/pipermail/webkit-dev/2008-August/004741.html</a> <br> <a href="http://mac-os-forge.2317878.n4.nabble.com/Safari-for-Windows-symbol-server-updated-td177872.html" rel="nofollow">http://mac-os-forge.2317878.n4.nabble.com/Safari-for-Windows-symbol-server-updated-td177872.html</a> <br></p>
1346
2013-03-28T09:26:54.353
<p>Apple developer network site has a small guide about <a href="https://developer.apple.com/internet/safari/windows_symbols_instructions.html" rel="nofollow">setting up debugging symbols server for Safari browser on Windows</a>. But it doesn't work. First, the link to actual symbols server gets redirected from http to https, but then it just 404s. Now, I know that Safari isn't supported on Windows any longer, but I wanted to play with existing version. Any idea if the symbols are actually available somewhere?</p>
Safari windows debugging symbols
|debugging-symbols|safari|
<p>I don't see <a href="https://ghidra-sre.org" rel="nofollow noreferrer">Ghidra</a> in the lists in the other answers, probably because this question was asked in 2013, and Ghidra has only more recently been made available to the public.</p> <p>Ghidra comes with built-in cooperative working tools. Each user who wishes to cooperate on a reverse engineering project would connect to Ghidra server. This is a simple server that can be run on any computer that these Ghidra users can all access. It provides network storage for the shared project too. It controls user access, provides file versioning, and supports check in, check out and version history. Quite neat.</p>
1347
2013-03-28T09:39:52.443
<p>What's a working tool/methodology to work cooperatively on the same binary (if possible in parallel), that is proven to work?</p> <hr> <p>I used various methods long ago to share information with others, but not in parallel:</p> <ul> <li>sending IDB back &amp; forth</li> <li>sharing TXT notes on a repository</li> <li>exporting IDB to IDC and sharing the IDC on a repository</li> </ul> <p>However, none of these were really efficient. I am looking for better methodologies and tools for collaborative work.</p>
Tools to work cooperatively on the same binary
|tools|disassembly|static-analysis|ida|
<p>A potential tool would be QuarkLabs' <a href="http://www.quarkslab.com/fr-blog+list+1024" rel="nofollow">qb-sync</a>, which advertises:</p> <ul> <li>Synchronization between IDA and WinDbg, OllyDbg2, GDB</li> <li>Source code available (GNU GPL 3)</li> </ul>
1349
2013-03-28T10:05:06.293
<p>It's really a productivity bottleneck when various analysis tools can't share information.</p> <p>What's an efficient way to store symbols+comments+structures, so that they can be easily imported into other reversing tools?</p> <hr> <p>I used to rely on SoftIce's IceDump extension to load/save IDA symbols, or load exported MAP symbols from IDA into OllyDbg via gofather+'s GoDup, but nothing recent nor portable.</p>
Which format/tool to store 'basic' informations?
|disassembly|tools|debuggers|
<p>Some options which may or may not be applicable depending on your needs:</p> <ol> <li><p><strong>Avoid</strong> using strings to leak out interesting information when possible. For example if you are using strings to display error information or logging information, this can give any reverse engineer valuable details as to what might be going on in your application. Instead replace these strings with numerical error codes.</p></li> <li><p><strong>Obfuscate</strong> all strings with some kind of symmetric algorithm like a simple XOR routine, or a crypto algorithm like AES. This will prevent the string from being discovered during a casual examination of your binary. I say 'obfuscate' as you will presumably be storing the crypto/xor key in your binary. Any reverse engineer who tries a little harder will surely recover the obfuscated strings.</p></li> <li><p><strong>Encrypt</strong> all strings (make all the strings get linked into a separate section in your executable and encrypt this section) and store the decryption key outside of your binary. You could store the key remotely and restrict access server side where possible. So if a reverse engineer does get your binary they <em>may</em> not be able to access the key. The decryption key could also be generated dynamically on the users computer based off several predictable factors known about that users machine, essentially only allowing the encrypted data to be decrypted when run on this specific machine (or type of machine). This technique has been used by government malware to encrypt payloads for specific targets (If I can remember the link to the paper I read this in I will update answer).</p></li> <li><p><strong>Get Creative</strong>, Store all strings in a foreign language and then at run time use an online translation service to translate the string back to your expected native language. This is of course not very practical.</p></li> </ol> <p>Of course if your strings do get decoded/decrypted at run time then a reverse engineer could just dump the process from memory in order to see the strings. For this reason it may be best to decode/decrypt individual strings only when needed (possibly storing the decoded string in a temporary location and zeroing it after use).</p>
1356
2013-03-28T16:55:16.840
<p>Text strings are usually easily read in a binary file using any editor that supports ASCII encoding of hexadecimal values. These text snippets can be easily studied and altered by a reverse engineer.</p> <p>What options does a developer have to encrypt these text snippets, and decrypt them, in runtime ?</p>
Encrypting text in binary files
|obfuscation|c|c++|
<p>I am not exactly a Java expert but a while ago I researched the firmware of a car navigation system. For the java bits of it I used the <a href="http://java.decompiler.free.fr/" rel="nofollow">“Java Decompiler project”</a> and it seemed to work well for decompilation.</p> <blockquote> <p>The “Java Decompiler project” aims to develop tools in order to decompile and analyze Java 5 “byte code” and the later versions.</p> <p>JD-Core is a library that reconstructs Java source code from one or more “.class” files. JD-Core may be used to recover lost source code and explore the source of Java runtime libraries. New features of Java 5, such as annotations, generics or type “enum”, are supported. JD-GUI and JD-Eclipse include JD-Core library.</p> <p>JD-GUI is a standalone graphical utility that displays Java source codes of “.class” files. You can browse the reconstructed source code with the JD-GUI for instant access to methods and fields.</p> <p>JD-Eclipse is a plug-in for the Eclipse platform. It allows you to display all the Java sources during your debugging process, even if you do not have them all.</p> <p>JD-Core works with most current compilers including the following:</p> <pre><code>jdk1.1.8 jdk1.3.1 jdk1.4.2 jdk1.5.0 jdk1.6.0 jdk1.7.0 jikes-1.22 harmony-jdk-r533500 Eclipse Java Compiler v_677_R32x, 3.2.1 release jrockit90_150_06 </code></pre> </blockquote>
1361
2013-03-28T20:28:48.750
<p>What tools or methodology do you use to de-obfuscate Java classes?</p> <hr> <ul> <li>I know you can theoretically decompile, modify and recompile, but that's only you fully trust a Java decompiler (and none is regularly updated).</li> <li>One might also edit java bytecode directly with <a href="http://rejava.sourceforge.net/" rel="nofollow">reJ</a> but that's tedious and risky (it's easy to break the bytecode without any warnings...)</li> </ul>
How do you deobfuscate Java classes?
|tools|java|deobfuscation|
<p>I'm using <a href="https://github.com/JetBrains/intellij-community/tree/master/plugins/java-decompiler/engine" rel="nofollow noreferrer">https://github.com/JetBrains/intellij-community/tree/master/plugins/java-decompiler/engine</a> It's the decompiler from IntelliJ, it decompile codes where JD-GUI fail.</p> <p>It's a unofficial mirror to download: <a href="http://files.minecraftforge.net/maven/net/minecraftforge/fernflower/" rel="nofollow noreferrer">http://files.minecraftforge.net/maven/net/minecraftforge/fernflower/</a></p>
1370
2013-03-29T15:44:07.180
<p>I am using <a href="http://jd.benow.ca/">JD-GUI</a> to decompile Java JAR files, but the problem is that it leaves many errors, such as duplicate variables which I have to fix myself and check to see if the program still works (if I fixed the errors correctly).</p> <p>I also tried Fernflower, but that leaves blank classes if it's missing a dependency.</p> <p>I'd like to know which decompiler:</p> <ul> <li>gives the least amount of errors</li> <li>deobfuscates the most.</li> </ul>
What is a good Java decompiler and deobfuscator?
|decompilation|tools|java|deobfuscation|jar|
<p>For figuring out JTAG pinout, there are many hits on google for "JTAG Finder". I also have my own implementation:</p> <p><a href="http://mbed.org/users/igorsk/code/JTAG_Search/" rel="noreferrer">http://mbed.org/users/igorsk/code/JTAG_Search/</a></p> <p>It's for mbed but I tried to make it easily portable (original version was for a Stellaris board).</p> <p>Here's a quote from the comment which describes the basic approach:</p> <pre><code> The overall idea: 1) choose any 2 pins as TMS and TCK 2) using them, reset TAP and then shift DR, while observing the state of all other pins 3) for every pin that received anything like a TAP ID (i.e. bit 0 is 1): 4) using the pin as TDI, feed in a known pattern into the TAP 5) keep shifting and monitor the rest of the pins 6) if any of the remaining pins received the pattern, it is TDO </code></pre>
1374
2013-03-29T18:32:04.087
<p>I'm a software guy through and through. But periodically when I'm taking apart hardware I know to look for JTAG ports and RS232 ports. So far I've always been lucky and have been able to solder on pins to the RS232 port and get a serial connection.</p> <p>For the times in the future that I am unlucky, can someone explain to me what JTAG is (i.e. is there only one type of JTAG and I can expect to hook it up to a single type of port, like a DB-9 for serial?) and how I would go about using it to dump firmware off an embedded system or is it all manufacturer specific?</p>
How do I identify and use JTAG?
|hardware|jtag|
<p>Don't know about the state of the art , but some advances have been in the direction of combining symbolic execution as with <a href="https://web.archive.org/web/20160311223607/http://research.microsoft.com/en-us/um/people/pg/public_psfiles/cacm2012.pdf" rel="nofollow noreferrer">SAGE</a> from MS Research (there should be a better paper, but I think it's paywalled). Also <a href="https://ieeexplore.ieee.org/document/6200194" rel="nofollow noreferrer">A Taint Based Approach for Smart Fuzzing</a> shows how to combine taint analysis for advanced fuzzing (there should be some non-paywalled version around). Also, I expect most people don't really publish their advanced techniques until they exhaust them, which is the main problem of this question.</p>
1375
2013-03-29T18:37:25.567
<p>I've previously rolled my own Fuzzing Framework, and tried a few others like Peach Fuzzer. It's been awhile since I've looked at vulnerability hunting, what is the state of the art with regard to fuzzing? That is, if I were to start fuzzing Acme Corp's PDF Reader today, what toolset should I look into? </p>
State of the Art Fuzzing Framework
|fuzzing|
<p>The implementation of AppInit DLL in windows 7 is as follows:</p> <p>In <code>user32.dll!ClientThreadSetup</code> the <code>LoadAppInitDlls</code> export from kernel32.dll is being called for any process except the LogonProcess.</p> <p><code>kernel32.dll!LoadAppInitDlls</code> checks the <code>LoadAppInit_DLLs</code> registry key and if set calls <code>BasepLoadAppInitDlls</code> (except when offset 3 of the <a href="http://en.wikipedia.org/wiki/Process_Environment_Block">PEB</a> has value 2).</p> <p><code>BasepLoadAppInitDlls</code> calls <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179%28v=vs.85%29.aspx">LoadLibraryEx</a> for each DLL set in the <code>AppInit_DLLs</code> registry key. If signing is required (when the <code>RequireSignedAppInit_DLLs</code> registry value is set) the <code>LOAD_LIBRARY_REQUIRE_SIGNED_TARGET</code> flag is passed to LoadLibraryEx.</p> <p>So by setting this registry key, the malware dll will be injected into every process started after setting this key. On previous OS versions AppInit DLL's were not called for non gui/console processes but at least on Windows 7 it's also called for non gui processes.</p>
1376
2013-03-29T18:58:10.950
<p>I have a malware sample that adds a DLL to the registry key <code>HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\AppInit_DLLs</code>. There is malicious functionality in the DLL referenced by the registry key but this malware sample does not load or call the DLL, nor does it exhibit any other malicious behavior.</p> <p>Why would malware add a DLL to this registry key?</p>
What happens when a DLL is added to AppInit_DLL
|windows|malware|dll|
<p><code>nt!IopLoadDriver</code> indirect call is used only for SERVICE_DEMAND start driver entry</p> <p>for boot loading drivers you would need to break on <code>nt!IopInitializeBuiltInDriver</code> indirect call as well</p> <p>you can see a short example on message #17 &amp; #18 in this link </p> <p><a href="http://www.osronline.com/showthread.cfm?link=231280" rel="nofollow">http://www.osronline.com/showthread.cfm?link=231280</a></p> <p>this is a dormant script (slightly edited to use gc (go from conditional instead of go as recommended ) that keeps waiting forever and will print out the !drvobj details when ever any driver is loaded in a kernel debugging session </p> <p>no word wraps the command should be in a single line</p> <pre><code>.foreach /pS 1 /ps 10 ( place { # call*dword*ptr*\[*\+*\] nt!IopInitializeBuiltinDriver} ) {bu place ".printf \"%msu\\n\", poi(esp+4);r $t0 = poi(esp); gu; !drvobj $t0 2;gc"} .foreach /pS 1 /ps 10 ( place { # call*dword*ptr*\[*\+*\] nt!IoploadDriver} ) {bu place ".printf \"%msu\\n\", poi(esp+4);r $t1 = poi(esp); gu; !drvobj $t1 2;gc"} </code></pre> <p>xp sp3 vm</p> <p>in a connected kd session do <code>sxe ibp; .reboot</code> kd will request an initial break on rebooting (equivalent to /break switch in boot.ini) when broken run this script</p> <pre><code>$$&gt;a&lt; "thisscript.extension" </code></pre> <p>in addition to printing all the system driver entry points and their driver objects</p> <p>if your application loads an additional driver their details will be printed too</p> <p>a sample output for sysinternals dbgview opened in the target vm </p> <p>the dbgv.sys entry point is called when you <code>check mark the enable kernel capture (ctrl+k)</code></p> <pre><code>\REGISTRY\MACHINE\SYSTEM\ControlSet001\Services\DBGV *** ERROR: Module load completed but symbols could not be loaded for Dbgv.sys Driver object (ffbd6248) is for: \Driver\DBGV DriverEntry: f6d89185 Dbgv DriverStartIo: 00000000 DriverUnload: 00000000 AddDevice: 00000000 Dispatch routines: [00] IRP_MJ_CREATE f6d87168 Dbgv+0x1168 [01] IRP_MJ_CREATE_NAMED_PIPE 804fa87e nt!IopInvalidDeviceRequest [02] IRP_MJ_CLOSE f6d87168 Dbgv+0x1168 [03] IRP_MJ_READ 804fa87e nt!IopInvalidDeviceRequest [04] IRP_MJ_WRITE 804fa87e nt!IopInvalidDeviceRequest [05] IRP_MJ_QUERY_INFORMATION 804fa87e nt!IopInvalidDeviceRequest [06] IRP_MJ_SET_INFORMATION 804fa87e nt!IopInvalidDeviceRequest [07] IRP_MJ_QUERY_EA 804fa87e nt!IopInvalidDeviceRequest [08] IRP_MJ_SET_EA 804fa87e nt!IopInvalidDeviceRequest [09] IRP_MJ_FLUSH_BUFFERS 804fa87e nt!IopInvalidDeviceRequest [0a] IRP_MJ_QUERY_VOLUME_INFORMATION 804fa87e nt!IopInvalidDeviceRequest [0b] IRP_MJ_SET_VOLUME_INFORMATION 804fa87e nt!IopInvalidDeviceRequest [0c] IRP_MJ_DIRECTORY_CONTROL 804fa87e nt!IopInvalidDeviceRequest [0d] IRP_MJ_FILE_SYSTEM_CONTROL 804fa87e nt!IopInvalidDeviceRequest [0e] IRP_MJ_DEVICE_CONTROL f6d87168 Dbgv+0x1168 [0f] IRP_MJ_INTERNAL_DEVICE_CONTROL 804fa87e nt!IopInvalidDeviceRequest [10] IRP_MJ_SHUTDOWN 804fa87e nt!IopInvalidDeviceRequest [11] IRP_MJ_LOCK_CONTROL 804fa87e nt!IopInvalidDeviceRequest [12] IRP_MJ_CLEANUP 804fa87e nt!IopInvalidDeviceRequest [13] IRP_MJ_CREATE_MAILSLOT 804fa87e nt!IopInvalidDeviceRequest [14] IRP_MJ_QUERY_SECURITY 804fa87e nt!IopInvalidDeviceRequest [15] IRP_MJ_SET_SECURITY 804fa87e nt!IopInvalidDeviceRequest [16] IRP_MJ_POWER 804fa87e nt!IopInvalidDeviceRequest [17] IRP_MJ_SYSTEM_CONTROL 804fa87e nt!IopInvalidDeviceRequest [18] IRP_MJ_DEVICE_CHANGE 804fa87e nt!IopInvalidDeviceRequest [19] IRP_MJ_QUERY_QUOTA 804fa87e nt!IopInvalidDeviceRequest [1a] IRP_MJ_SET_QUOTA 804fa87e nt!IopInvalidDeviceRequest [1b] IRP_MJ_PNP 804fa87e nt!IopInvalidDeviceRequest </code></pre>
1380
2013-03-29T20:43:20.327
<p>When you unpack manually a Windows user-mode executable, you can easily break at its EntryPoint (or TLS), then trace until you reach the original EntryPoint. However that's not possible with a packed driver.</p> <p>How can you reliably unpack a Windows driver manually?</p>
How can you reliably unpack a Windows driver manually?
|windows|unpacking|driver|
<ul> <li>Peter Ferrie's <a href="http://pferrie.host22.com/papers/antidebug.pdf">“Ultimate” Anti-Debugging Reference</a> (PDF, 147 pages) contains <strong>many</strong> anti-debugs, whether they're hardware or API based...</li> <li>Walied Assar's <a href="http://waleedassar.blogspot.com/">blog</a> shows his researches, which are focused on finding new anti-debugs.</li> </ul> <p>other (maybe redundant) resources:</p> <ul> <li>Nicolas Fallière's <a href="http://www.symantec.com/connect/articles/windows-anti-debug-reference">Windows Anti-Debug reference</a></li> <li>OpenRCE's <a href="http://www.openrce.org/reference_library/anti_reversing">Anti Reverse Engineering Techniques Database</a></li> <li>Daniel Plohmann's <a href="https://bitbucket.org/fkie_cd_dare/simplifire.antire">AntiRE</a></li> <li>Rodrigo Branco's <a href="http://research.dissect.pe/docs/blackhat2012-paper.pdf">Scientific but Not Academical Overview of Malware Anti-Debugging, Anti-Disassembly and Anti- VM Technologies</a></li> <li>Mark Vincent Yason's <a href="http://www.blackhat.com/presentations/bh-usa-07/Yason/Whitepaper/bh-usa-07-yason-WP.pdf">Art Of Unpacking</a></li> </ul>
1383
2013-03-29T21:46:40.973
<p>What are good anti-debug references for Windows which help with manual unpacking, emulating, or sandboxing?</p>
What are good Windows anti-debug references?
|windows|anti-debugging|
<p>Frankly speaking... Nothing can really compare to the GDB itself. Just take the newest version, start it with <code>gdb-multiarch</code> <em>(GDB now has support for all architectures and you don't need any kind of GDB branch anymore)</em>.</p> <p>When GDB runs just load a file:</p> <pre><code>file &lt;some_file_with_gdb_symbols.elf&gt; </code></pre> <p>and connect to a running GDB server <em>(on port <code>:3333</code>)</em> - in my case Openocd that communicates with any kind of embedded board:</p> <pre><code>target extended-remote :3333 </code></pre> <p>When the session starts type these commands taken directly from the newest GDB manual <em>(<a href="https://sourceware.org/gdb/current/onlinedocs/gdb.pdf" rel="nofollow noreferrer">link</a>, section 25)</em>:</p> <pre><code>tui enable tui new-layout mylayout {-horizontal {src 8 asm 2} 6 regs 4} 8 status 0 cmd 2 layout mylayout refresh set tui border-kind space set tui tab-width 4 set tui compact-source on with pagination off -- focus cmd </code></pre> <blockquote> <p>Put these commands in a system wide GDB configuration file <code>/etc/gdb/gdbinit</code> and live happily ever after.</p> </blockquote> <p>After all is done you should end up with something like this:</p> <p><a href="https://i.stack.imgur.com/rsWqP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rsWqP.png" alt="enter image description here" /></a></p> <p>Extremely pleasing if you ask me. Especially with the newest GDB that now can stack windows horizontally (excluding <code>cmd</code> &amp; <code>status</code> where <code>cmd</code> can only be full width... oh why such limitations...) as can be seen from the command where I created my layout i.e. <code>mylayout</code>.</p> <p>All that I am missing is a window for monitoring variables, addresses or expressions which I would love to position on the right of <code>asm</code> window... GNU, I know you can do it!</p>
1392
2013-03-30T02:30:22.320
<p>Learning the GDB commands is on my bucket-list, but in the meantime is there a graphical debugger for *nix platforms that <strong>accepts</strong> Windbg commands, and has similar functionality? For example, the ability to bring out multiple editable memory windows, automatically disassemble around an area while stepping, set disassembly flavor, and have a window with registers that have editable values?</p>
Decent GUI for GDB
|debuggers|gdb|
<p>There is possible padding, try adding the -nopad option, assuming that you are using the same compression method. </p>
1393
2013-03-30T02:34:20.290
<p>I love using <a href="https://code.google.com/p/firmware-mod-kit/" rel="noreferrer">firmware-mod-kid</a> to modify SoHo router firmware. The problem I encounter is that it often bloats the size of the image. It appears this happens during the <code>mksquashfs</code> step.</p> <p>If I'm just unsquashing a filesystem and then resquashing it with the same compression, with no modifications, why is the resulting image larger than the original?</p>
Firmware-Mod-Kit Increases Size
|firmware|
<p>If you are using IDA Pro, Ctrl-E (Windows shortcut <a href="https://www.hex-rays.com/products/ida/support/freefiles/IDA_Pro_Shortcuts.pdf" rel="nofollow">https://www.hex-rays.com/products/ida/support/freefiles/IDA_Pro_Shortcuts.pdf</a>) it will show you entry point. You can directly jump to Main/start function.</p>
1395
2013-03-30T03:08:00.460
<p>How do I debug an executable that uses TLS callbacks? It's my understanding that these run before my debugger will attach.</p>
Debugging EXE with TLS
|windows|dynamic-analysis|executable|
<p>This paper might be of interest: <a href="https://gmplib.org/~tege/divcnst-pldi94.pdf" rel="nofollow noreferrer">Division by invariant multiplication</a>.</p> <p>Bumped into this <a href="https://stackoverflow.com/questions/30790184/perform-integer-division-using-multiplication">here</a>.</p>
1397
2013-03-30T07:14:20.033
<p>When compiling a division or modulo by a constant, my compiler (LLVM GCC) generates a series of instructions that I don't understand.</p> <p>When I compile the following minimal examples:</p> <pre><code>int mod7(int x) { return x % 7; } int div7(int x) { return x / 7; } </code></pre> <p>The following code is generated:</p> <pre><code>_mod7: push rbp mov rbp,rsp mov ecx,0x92492493 mov eax,edi imul ecx add edx,edi mov eax,edx shr eax,0x1f sar edx,0x2 add edx,eax imul ecx,edx,0x7 mov eax,edi sub eax,ecx pop rbp ret _div7: push rbp mov rbp,rsp mov ecx,0x92492493 mov eax,edi imul ecx add edx,edi mov ecx,edx shr ecx,0x1f sar edx,0x2 mov eax,edx add eax,ecx pop rbp ret </code></pre> <ul> <li>How is this mathematically equivalent, and where do the constants come from?</li> <li>What's the easiest way to turn the assembly back in to C (for arbitrary constants on the right-hand side)?</li> <li>How could a tool, such as a decompiler or analysing disassembler, automate this process?</li> </ul>
How can I reverse optimized integer division/modulo by constant operations?
|disassembly|static-analysis|
<p>Also, we can exploit bugs in the editors themselves to prevent tampering with our resources. The interesting part here is that most Resource Editors have no idea how to parse non-typical (not very non-typical) PE files. For example, Some editors assume the resource section name must always be <code>.rsrc</code>. Examples:</p> <ol> <li><p><a href="http://www.angusj.com/resourcehacker/">Resource Hacker</a></p> <ul> <li><p>Inserting a special resource to cause Resource Hacker to go into an infinite loop. Demo here : <a href="http://code.google.com/p/ollytlscatch/downloads/detail?name=antiResHacker.exe">http://code.google.com/p/ollytlscatch/downloads/detail?name=antiResHacker.exe</a></p></li> <li><p>Inserting a special <code>RT_STRING</code> resource to cause Resource Hacker to crash.</p></li> <li><p>It assumes the size of the <code>IMAGE_OPTIONAL_HEADER</code> structure is assumed to be <code>sizeof(IMAGE_OPTIONAL_HEADER)</code>, currently <code>0xE0</code> in hex, while it can even be greater. Having the size to be of a greater value causes Resource Hacker to discard the whole PE file.</p></li> </ul></li> <li><p><a href="http://www.bome.com/products/restorator">Restorator</a></p> <ul> <li>Same as 1c.</li> <li>Uses the <code>NumberOfRvaAndSizes</code> field, which can easily be forged to be <code>0xFFFFFFFF</code>. This causes Restorator to discard the whole PE file.</li> <li>Assumes the resource section name must be <code>.rsrc</code>. Change it anything else. This causes Restorator to discard the whole PE.</li> <li>Any resource Section with the <code>Characteristics</code> field set to <code>IMAGE_SCN_CNT_UNINITIALIZED_DATA</code> among other characteristics will be discarded by Restorator. </li> </ul> <p>Demos here : <a href="http://pastebin.com/ezsDCaud">http://pastebin.com/ezsDCaud</a></p></li> </ol>
1399
2013-03-30T08:03:51.863
<p>There are variety of tools that allow editing the resources of Windows executables. These tools allow a very easy interface for changing the programs look and feel. Replacing icons, text, menus can be easily done without any knowledge in reversing.</p> <p>My question is, what option I have to prevent the resources being so easily edited ?</p>
How to prevent use of Resource editors
|windows|pe-resources|
<p>Not sure how it fares against application with JIT compiled code, but peach has a <a href="http://peachfuzzer.com/v3/minset.html">minset</a> utility to make a minimal set of files with highest code coverage:</p> <blockquote> <p>This tool will run each sample file through a target program and determine code coverage. It will then find the least number of files needed to cover the most code. This will be the minimum set of files that should be used when fuzzing.</p> </blockquote> <p>But as far as I can see it uses the method you proposed, monitoring hits of all basic blocks of the application. It uses a pintool to do this. </p>
1405
2013-03-30T19:58:10.487
<p>Let's say I'd like to begin fuzzing Acme Corp's PDF Reader. I'd like to try to follow what Miller <a href="http://fuzzinginfo.files.wordpress.com/2012/05/cmiller-csw-2010.pdf">did</a> by downloading a bunch of benign PDFs and mutate them. </p> <p>Miller began by reducing his corpus of PDF samples to a minimum by pruning samples that had similar code coverage.</p> <p>How is that specific step done? That is, how did he determine what was a similar code coverage? </p> <p>I can imagine a tool that traces execution and records JMP/CALLs to get an execution graph, and I suppose you could diff those graphs. But what about JIT code? Wouldn't those graphs be very different since the JIT would likely be in different locations in memory?</p>
How do I determine code coverage when fuzzing
|tools|fuzzing|
<p>You might find this useful -- I ended up writing a tutorial about this recently, since, as you note, documentation for this stuff is always so sketchy and often out of date.</p> <p><a href="http://soundly.me/osx-injection-override-tutorial-hello-world/" rel="nofollow">http://soundly.me/osx-injection-override-tutorial-hello-world/</a></p>
1414
2013-03-31T01:32:02.497
<p>Much reverse engineering has been done on Windows over the years leading to great undocumented functionality, such as using <code>NtCreateThreadEx</code> to <a href="http://securityxploded.com/ntcreatethreadex.php">inject</a> threads across sessions. </p> <p>On OSX the topic of thread injection seems relatively uncharted. With the operating system being so incredibly large, where can I begin looking in order to uncover the functionality I desire?</p> <p>For example, if someone were to ask me this about Windows, I would expect an answer telling me to begin reverse engineering <code>CreateRemoteThread</code> or to start looking at how the kernel creates user threads and point them into <code>ntoskrnl.exe</code>.</p>
Thread Injection on OSX
|osx|
<p>I would suggest this as a solution <a href="http://accessroot.com/arteam/site/download.php?view.185">http://accessroot.com/arteam/site/download.php?view.185</a> as I had similar problem in one of crackmes. What I did was to write my own hooks for SoftICE to bypass ring0 hooks of int 3 and int 1. Could be useful for your problem. Interesting section is "SoftICE comes to the rescue".</p>
1420
2013-03-31T02:48:00.997
<p>I understand that on x86, <code>INT 1</code> is used for single-stepping and <code>INT 3</code> is used for setting breakpoints, and some other interrupt (usually 0x80 for Linux and 0x2E for Windows) used to be used for system calls. </p> <p>If a piece of malware hooks the Interrupt Descriptor Table (IDT) and substitutes its own <code>INT 1</code> and <code>INT 3</code> handlers that perform system call-like functionality, how can I use a debugger to trace its execution? Or am I stuck with using static-analysis tools?</p>
Malware Hooking INT 1 and INT 3
|malware|debuggers|dynamic-analysis|kernel-mode|
<p>A nice combination of findcrypt2 by HexRays and the work done by Felix Gröbert is <a href="https://bitbucket.org/daniel_plohmann/simplifire.idascope">IDAScope</a>. It's very useful for searching for and identifying encryption algorithms. For more information on IDAScope's Crypto Identification I'd recommend the following <a href="http://pnx-tf.blogspot.com/2012/08/idascope-update-crypto-identification.html">link</a>. </p>
1423
2013-03-31T03:12:12.127
<p>I'm analyzing some software that appears to encrypt its communications over the network, but it does not appear to be SSL. How can I easily determine what encryption algorithm its using, and maybe find the key?</p>
Determine Encryption Algorithm
|tools|cryptography|
<p>It's extremely easy to decompile. LLVM for a long time shipped with a CBackend that would convert LLVM into C. </p> <p>The LLVM that is created by todays frontends (clang) is very amenable to any kind of analysis and understanding that you can think of. So you can probably just use normal LLVM tools (opt, llc) to "decompile" the IR. I find LLVM IR quite readable on its own, but I'm strange. </p> <p>However, just like compilation of C to assembler, some information is lost or destroyed. Structure field names are gone, forever replaced with indexes. Their types remain though. Control flow, as a concept, remains, there is no confusion of code and data, but functions can be removed because they are dead or inlined. I believe enum values are removed as well. Parameter information to function remains, as do the types of global variables. </p> <p>There actually is a decent <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/043719.html">post</a> where an LLVM contributor outlines pitfalls and problems with using their bitcode format in the manner that you suggest. Many people seem to have listened to him, so I'm not sure if we'll ever need to move beyond the tools we currently have for understanding LLVM bitcode...</p>
1428
2013-03-31T08:27:00.800
<p>LLVM IR is a fairly high-level, typed bitcode which can be directly executed by LLVM and compiled to JIT on the fly. It would not surprise me if a new executable format or programming language was designed directly on top of LLVM, to be executed as if it were an interpreted language.</p> <p>In this regard, I am curious as to the state of the art on LLVM decompilation. Because it is a typed bitcode specifically designed to be easy to analyze, one might expect that it is relatively easy to decompile (or at least reassemble into a more readable or logical form).</p> <p>Googling turns up <a href="http://www.cdl.uni-saarland.de/publications/theses/moll_bsc.pdf">this BSc thesis</a> which does a relatively rudimentary job, but seemingly few other leads. I might have expected this <a href="http://www.cdl.uni-saarland.de/people/hack/publications.php">fellow's supervisor</a> to have done some further research in this area, but it seems his focus is more towards the compiler design area of research.</p> <p>Are there research projects, commercial prototypes, or even any kinds of active research being done in the field of LLVM decompilation?</p>
What is the state of art in LLVM IR decompilation?
|decompilation|llvm|
<p>There are <a href="http://www.pcbreverseengineering.com/" rel="nofollow">comprehensive tools</a> that can do precisely this. Part of the software that comes with them allows you to place part numbers between pads and have the circuit diagram automatically generated for you. Unfortunately, they're likely to set you back a fair bit of cash.</p> <p>An alternative is to use corrosives and sharp implements to manually split the layers, but that's difficult and prone to mistakes. If you've got a number of boards you can destroy in the process, this is probably the cheapest option.</p>
1440
2013-04-01T13:14:19.190
<p>I have found a multilayer PCB of which I need to draw the circuit. At first, I tried to find the circuit on the internet using part numbers, but I did not get any result. The PCB is from a very old alarm installation.</p> <p>Are there any tools or techniques I can use to get to know the structure of the layers I can't see?</p>
Draw circuit of a multilayer PCB
|tools|pcb|
<p>After buying NuMega technologies in 1997, Compuware seemed to feel that SoftICE was a liability, both technically and legally (as the #1 hacker tool of the time), and that may have played into why they discontinued support. SoftICE required constant updates in order to continue working against the various updates of Windows that were coming out, and there were only a couple of people who knew how to make those updates. In 2007, they closed down the NuMega office in Nashua, NH, and moved all the intellectual property to Compuware's headquarters (then in Detroit, MI). The product line that included all that stuff was sold off to MicroFocus in 2009, along with the remaining developers, none of which knew a thing about building SoftICE, let alone updating it to work with updated versions of Windows. We toyed with resurrecting the product around 2011, but could not get management to buy off on it, so it didn't happen.</p> <p>The source code remains in its own stasis box (a source control database), and will likely never go anywhere from there.</p> <p><strong>Disclaimer:</strong> I work for MicroFocus, and currently maintain the formerly NuMega product "DevPartner Studio", the BoundsChecker portion in particular.</p>
1445
2013-04-01T17:53:15.223
<p>I have seen mentions of SoftICE on various questions throughout this site. However, the <a href="http://en.wikipedia.org/wiki/SoftICE">Wikipedia article</a> on SoftICE implies that the tool is abandoned. Searching google, I see many links claiming to be downloads for SoftICE, but they seem to have questionable origins and intent. </p> <p>Is there an official website where I can purchase and download SoftICE, or an official MD5 of a known SoftICE installer?</p>
How do I acquire SoftICE?
|tools|debuggers|softice|
<p>You would probably need some <a href="http://www.pcbreverseengineering.com/" rel="noreferrer">expensive scanning equipment</a>. It is possible you could get old equipment that is being discarded but that would be rather difficult. Then you would probably need to write software to handle the output of the equipment as you most likely wouldn't have a license for the accompaning software unless you nabbed a complete system intact.</p> <p>If you were willing to forgo saving the original PCB you could do <a href="http://www.flexiblecircuitpcb.com/blog/pcb-copy-board-methods-and-steps.html" rel="noreferrer">this</a>. Basically carefully note component positions, remove the parts, scan both sides, clean up scans with image tool, then repeat removing layers of the board as you go... sounds quite error prone to me.</p> <p>It is also possible you could figure out a few by checking exhaustivly if some groups of pins go to the same layer... you could probably assume those were power/ground pins.</p> <p>Another thing that may help is if the board is designed to support <a href="http://people.ee.duke.edu/~krish/teaching/ECE269/boundaryscan_tutorial.pdf" rel="noreferrer">boundary scan</a> testing. If I understand correctly you might be able to use that to automate detecting connecitons between chips if not which layer they are on. And here is a <a href="http://events.ccc.de/congress/2009/Fahrplan/attachments/1435_JTAG.pdf" rel="noreferrer">PDF on that topic</a>.</p>
1460
2013-04-01T21:24:22.093
<p>I'm trying to reverse engineer some boards that have multiple layers, but can't figure out any way of discovering which layer certain vias go to. Unfortunately I can't destroy the board with corrosives, since it's my only one. How can I find out how deep they go?</p>
How can I work out which PCB layer a via goes to, without destroying the board?
|hardware|pcb|
<p>No <em>absolutely reliable</em> way, no.</p> <p>Either way you'll need a full dump, but the problem is that malware could even hook the responsible functions inside the kernel and modify <em>what</em> gets dumped. There are several things that have to be considered here.</p> <p>You <em>can</em> detect it if the malware used a trivial method for hooking in the first place. Let's assume the address was replaced by one to a trampoline or to inside another loaded image (or even outside one just in nonpaged pool), then you can <em>easily detect</em> it. You can simply enumerate all the modules and attempt to find the one inside which the address from inside the SSDT points. In case of a trampoline you'll have to disassemble the instructions there to see where it jumps/calls. There are plenty of libraries out there for the purpose, such as <a href="http://udis86.sourceforge.net/"><code>udis86</code></a>.</p> <p>However, if a malware is sneaky, it could use the natural gaps inside an executable (such as the kernel) when loaded into memory. As you probably know, the way a PE file (such as <code>ntoskrnl.exe</code> and friends) is represented differently on disk and in memory. The on-disk file format is more terse. Loaded into memory, the sections are aligned in a particular way described in the PE header. This way gaps will likely exist between the real size of a section (end) and the properly aligned section size ("padding"). This leaves place to <em>hide</em> something like a trampoline or even more shell code than a simple trampoline. So a naive check such as the above - i.e. enumerating modules and checking whether the SSDT functions point inside the kernel image - will not work. It would get bypassed by malware sophisticated enough to do what I just described.</p> <p>As you can imagine, this means that things - as all things malware/anti-malware - quickly becomes an arms race. What I would strongly suggest is that you attach a kernel debugger (<code>WinDbg</code> via Firewire comes to mind) and keep the infected (or allegedly infected) machine in limbo while you investigate. While you are connected and broke into the debugger, the debuggee can't do anything. This can be used to debug a system live and - assuming the malware wasn't sneaky enough to also manipulate <code>kdcom</code> - to gain valuable metrics - it can also be used to create a crashdump directly (see WinDbg help). If you have conclusive evidence that a machine is infected, due to symptoms it exhibits, odds are the malware isn't all too sophisticated and you will not have to care about the special case I outlined. However, keep in mind that this special case can only be considered <em>one</em> out of many conceivable cases used to hide. So long story short: there is no <em>absolutely reliable</em> way to do what you want.</p> <p>It has sometimes been said - and it's true - that the attacker just needs to find one out of an infinite number of attack vectors, whereas the defender can only defend a finite number of <em>known</em> attack vectors. The lesson from this should be that we - as anti-malware industry (in which I work) - can always claim that <em>we</em> didn't find anything on the system, but that it is wrong to claim that the system is clean.</p> <hr> <h2>How to deliberately cause a BSOD</h2> <p>The keyboard driver(s) can be told to cause a BSOD:</p> <pre><code>HKLM\CurrentControlSet\Services\kbdhid\Parameters </code></pre> <p>or (for older PS/2 keyboards)</p> <pre><code>HKLM\SYSTEM\CurrentControlSet\Services\i8042prt\Parameters </code></pre> <p>And there set a <code>REG_DWORD</code> named <code>CrashOnCtrlScroll</code> to <code>1</code>.</p> <p>After the next reboot you can force the blue screen by <kbd>Ctrl</kbd>+<kbd>ScrollLk</kbd>+<kbd>ScrollLk</kbd>. The bug check code will in this case be <code>0xE2</code> (<code>MANUALLY_INITIATED_CRASH</code>).</p> <hr> <p>Side-note: I have also read, but never seen it in a kernel debugging session myself or in any kind of FLOSS implementation, that some method tries to re-load the kernel from the image on disk and run it through the early initialization steps, thereby creating a "shadow" SSDT. This one would then be pristine and could be used to "unhook" everything in one fell swoop from the original SSDT. Again, haven't seen this implemented, but from my knowledge of the internals it seems a possibility. Of course this plays more with the idea of detecting/unhooking a rootkit's functions than it does with your original intention of getting a memory dump of an infected system.</p>
1461
2013-04-01T21:56:28.287
<p>The <a href="http://en.wikipedia.org/wiki/System_Service_Dispatch_Table">SSDT</a> is a dispatch table inside the Windows NT kernel, and it is used for handling calls to various internal kernel APIs. Often malware will change addresses in the SSDT in order to hook certain kernel functions. Spotting this kind of thing in a memory dump would be awesome, because it would allow me to identify potential rootkits. Is there a way to reliably detect them? What kind of memory dump is required?</p>
Is there an easy way to detect if the SSDT has been patched from a memory dump?
|windows|malware|
<p>If a binary uses deflate or gzip (which uses deflate), the code is generally linked in as a library and thus easy to detect based on string artifacts. This can certainly be automated, e.g., you could simply search for the respective strings. Manually matching functions against the source code is a somewhat tedious process, but it usually works nicely. The process is much more difficult for less common algorithms or when you don't have any artifacts. In that case you have to identify the algorithm by its semantics (things like word size, constants, data structures may provide hints).</p> <p>In addition to the already mentioned FLIRT signatures: If you use IDA Pro with the Hex-Rays plugin and you are lucky, you may be able to find an algorithm on <a href="http://crowd.re" rel="nofollow">http://crowd.re</a>. There are a few annotations for compression algorithms available. Apart from that, I am not aware of any tools or scripts that do what you want.</p>
1463
2013-04-01T22:49:19.713
<p>I know there are tools for identifying common ciphers and hash algorithms in code, but are there any similar scripts / tools / plugins for common compression algorithms such as gzip, deflate, etc? Primarily aimed at x86 and Windows, but answers for other platforms are welcomed too.</p> <p>Note that I'm looking to find <em>code</em>, not <em>data</em>.</p>
Are there any tools or scripts for identifying compression algorithms in executables?
|tools|windows|x86|
<p>By default, IDA generates graphs in GDL (WinGraph) format, but you can switch it to DOT which is supported by GraphViz and some other tools. It seems <a href="http://gephi.org/2010/new-graphviz-dot-csv-and-ucinet-formats/">Gephi</a> can do 3D.</p> <p>See <code>GRAPH_FORMAT</code> and <code>GRAPH_VISUALIZER</code> in <code>ida.cfg</code>.</p>
1471
2013-04-02T05:31:36.057
<p>Is there any way to leave 2D flow chart graphs and go to 3D model? I mean something like that:</p> <p>Usual 2D graph: <img src="https://i.stack.imgur.com/uHTxH.png" alt="2D graph"> </p> <p>3D graph: <img src="https://i.stack.imgur.com/qMhs1.png" alt="3D graph"></p> <p>The only one solution I've seen is using UbiGraph + Linux on VM (to use UbiGraph) + some X-server for Win (the process of making all that stuff to work is described at Cr4sh's blog). That's kinda perverted solution, up to me. </p> <p>Also it would be brilliant if there could be displayed disasm in nodes, like in ordinary 2D IDA graphs.</p> <p>Perhaps there are some more elegant solutions?</p>
3D control-flow graphs in IDA
|disassembly|ida|
<p>In general, BinDiff in its current version as of this writing (4.x) works by matching attributes on the function level. Basically, matching is divided into two phases: first initial matches are generated which are then refined in the drill down phase.</p> <h2>Initial Matches</h2> <p>First of all BinDiff associates a signature based on the following attributes to each function:</p> <ul> <li>the number of basic blocks</li> <li>the number of edges between those blocks</li> <li>the number of calls to subfunctions</li> </ul> <p>This step gives us a set of signatures for each binary which in turn are used to generate the set of initial matches. Following a one-to-one relation, BinDiff selects these initial matches based on the above characteristics.</p> <p>The next step tries to find matchings on the call graph of each binary: for a verified match, the set of called functions from the matched function is examined in order to find event more matches. This process is repeated as long as new matches are found.</p> <h2>Drill Down</h2> <p>In practice, not all functions will be matched by the one-to-one relation induced by the initial matching strategy, so after the initial matchings have been determined we still have a list of unmatched functions. The idea of the drill down phase is to have multiple different function matchings strategies which are applied until a match is found. The order of applying these strategies is important: BinDiff tries those strategies for which it assumes the highest confidence, first. Only if no match could be found, it goes on with the next strategy. This is repeated until BinDiff runs out of strategies, or until all functions are matched. Examples include MD index, match based on function names (i.e. imports), callgraph edges MD index, etc.</p> <p><a href="https://www.sto.nato.int/publications/STO%20Meeting%20Proceedings/RTO-MP-IST-091/MP-IST-091-26.pdf" rel="nofollow noreferrer">MD-Index paper</a></p> <p><a href="http://static.googleusercontent.com/external_content/untrusted_dlcp/www.zynamics.com/en//downloads/bindiffsstic05-1.pdf" rel="nofollow noreferrer">Graph-based Comparison of Executable Objects</a></p> <p><a href="http://static.googleusercontent.com/external_content/untrusted_dlcp/www.zynamics.com/en//downloads/dimva_paper2.pdf" rel="nofollow noreferrer">Structural Comparison of Executable Objects</a></p> <p>(Disclaimer: working @ team zynamics / google, hopefully I didn't mess up anything, otherwise soeren is going to grill me ;-))</p>
1475
2013-04-02T09:35:57.497
<p>I would like to know what are the basic principles (and maybe a few things about the optimizations and heuristics) of the <a href="http://www.zynamics.com/bindiff.html">BinDiff software</a>. Does anyone have a nice and pedagogic explanation of it?</p>
How does BinDiff work?
|tools|tool-bindiff|
<p>I can support the presented view of the other responders. You will rarely encounter code virtualization when looking at in the wild samples.</p> <p>Just to add, here is a recent <a href="http://linuxch.org/poc2012/Tora,%20Devirtualizing%20FinSpy.pdf">case-study by Tora</a> looking at the custom virtualization used in FinFisher (sorry, direct link to PDF, have no other source).</p> <p>The VM used here has only 11 opcodes, thus this example can be easily understood and used to get an impression of some common design principles behind custom VMs.</p>
1478
2013-04-02T12:14:23.807
<p>I'm just getting into the RE field, and I learned about virtualized packers (like VMProtect or Themida) in a class about a year ago. How often is malware in the wild really packed with virtualized packers, and what is the state of the art in unpacking them for static analysis?</p>
How common are virtualized packers in the wild?
|obfuscation|static-analysis|malware|unpacking|virtualizers|
<p>While there is no GUI, I believe it's worth mentioning command lines tools that will help with the <code>in an automated way</code> part of your question. I've personally used the <a href="https://mupdf.com/" rel="nofollow noreferrer"><code>mupdf</code></a> associated command line tool: <code>mutool</code>.</p> <p>For example working on the following <a href="http://storage.googleapis.com/google-code-attachments/openjpeg/issue-235/comment-0/Bug691816.pdf" rel="nofollow noreferrer">PDF file</a>, here is what you would do to extract the encapsulated JPX stream:</p> <pre><code>$ mutool info Bug691816.pdf Bug691816.pdf: PDF-1.5 Info object (49 0 R): &lt;&lt;/ModDate(D:20101122114310-08'00')/CreationDate(D:20101122114251-08'00')/Title(ID1561x.indd)/Creator(Adobe InDesign 1.5.2)/Producer(Adobe PDF Library 4.16)&gt;&gt; Pages: 1 Retrieving info from pages 1-1... Mediaboxes (1): 1 (54 0 R): [ 0 0 612 792 ] Images (1): 1 (54 0 R): [ JPX ] 300x161 8bpc Idx (58 0 R) </code></pre> <p>So you simply need to:</p> <pre><code>$ mutool show -be -o obj58.jp2 Bug691816.pdf 58 </code></pre> <p>You can verify:</p> <pre><code>$ file obj58.jp2 obj58.jp2: JPEG 2000 Part 1 (JP2) </code></pre> <p>See documentation:</p> <ul> <li><a href="https://mupdf.com/docs/manual-mutool-show.html" rel="nofollow noreferrer">A tool for displaying the internal objects in a PDF file.</a></li> </ul> <hr> <p>For <code>PDF/A-3: EmbeddedFile</code> (as in <a href="https://github.com/ManuelB/add-zugferd-to-pdf/raw/61fe76c7469666742dc54a4a52ee56d3d6d4282d/src/test/resources/ferd-examples/ZUGFeRD_1p0_BASIC_Einfach.pdf" rel="nofollow noreferrer">this file</a>) you can even run:</p> <pre><code>$ mutool portfolio ZUGFeRD_1p0_BASIC_Einfach.pdf x 0 ZUGFeRD-invoice.xml $ head ZUGFeRD-invoice.xml &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!-- Nutzungsrechte ZUGFeRD Datenformat Version 1.0, 25.6.2014 Beispiel Version 29.09.2014 Zweck des Forums für elektronische Rechnungen bei der AWV e.V („FeRD“) ist u.a. die Schaffung und Spezifizierung eines offenen Datenformats für strukturierten elektronischen Datenaustausch auf der Grundlage offener und nicht diskriminierender, standardisierter Technologien („ZUGFeRD Datenformat“) </code></pre> <p>See documentation:</p> <ul> <li><a href="https://mupdf.com/docs/manual-mutool-portfolio.html" rel="nofollow noreferrer">Manipulate PDF portfolios.</a></li> </ul>
1526
2013-04-03T03:09:07.193
<p>I've been looking for an open-source GUI tool to extract PDF's in an automated way on Windows systems. I've used Didier Steven's tools with great interest for a while, but cannot make sense of how to use his <a href="http://blog.didierstevens.com/programs/pdf-tools/">PDF decomposing</a>/<a href="http://blog.didierstevens.com/2008/10/20/analyzing-a-malicious-pdf-file/">analyzing tools</a>, even after watching some of his videos. They seem to require significant understanding of the underlying PDF construction, and possibly much more.</p> <p>For SWF files, the tool <a href="http://h30499.www3.hp.com/t5/Following-the-Wh1t3-Rabbit/SWFScan-FREE-Flash-decompiler/ba-p/5440167">SWFScan</a> is the kind I'm looking for: you load the file in question into the tool. From there, you can explore the links, scripts, and images. It even auto-analyses code and shows which parts may have security issues and what the issue is for each one, then gives a webpage reference with more information.</p> <p>Does anyone know of a good open-source GUI for Windows that can load a PDF and not execute it but extract all the scripts, compiled code, text, links, images, etc.? Ideally, it would show the relation of each, like when you click on a certain image, it would tell you what script(s) are run, which URL it goes to, and let you see the image on its own.</p> <p>PDF's are so common, next to SWF, that this kind of tool seems like it would already be common. I may have overlooked it/them.</p>
Open source GUI tool for decomposing a PDF
|decompilation|tools|windows|
README.md exists but content is empty. Use the Edit dataset card button to edit it.
Downloads last month
3
Edit dataset card