Answer
stringlengths
38
29k
Id
stringlengths
1
5
CreationDate
stringlengths
23
23
Body
stringlengths
55
28.6k
Title
stringlengths
15
145
Tags
stringlengths
3
68
<p>So, it is totally untested but here is the result of a few Internet browsing.</p> <p>First the stack base address is present in <code>/proc/&lt;pid&gt;/maps</code>, then it must be accessible from user-space at some point.</p> <p>I looked at the code of the <a href="http://www.linuxcommand.org/man_pages/pstack1.html">pstack</a> command which is printing the content of the stack of a running process. This code is getting the base address from a <code>link_map</code> structure and store it inside the field <code>l_addr</code>. This field is set inside the function <code>readLinkMap()</code>:</p> <pre><code>static void readLinkMap(int pid, ElfN_Addr base, struct link_map *lm, char *name, unsigned int namelen) { /* base address */ lm-&gt;l_addr = (ElfN_Addr) ptrace(PTRACE_PEEKDATA, pid, base + offsetof(struct link_map,l_addr), 0); /* next element of link map chain */ if (-1 != (long) lm-&gt;l_addr || !errno) lm-&gt;l_next = (struct link_map *) ptrace(PTRACE_PEEKDATA, pid, base + offsetof(struct link_map, l_next), 0); if ((-1 == (long) lm-&gt;l_addr || -1 == (long) lm-&gt;l_next) &amp;&amp; errno) { perror("ptrace"); quit("can't read target."); } loadString(pid, base + offsetof(struct link_map, l_name), name, namelen); } </code></pre> <p>I guess this is the right way to go. So, I would advise you to take a look at the code of the <code>pstack</code> command (the file is not very long) and to get inspiration from it because it does something extremely similar to what you want (at least if I understand what you said correctly).</p> <p>Hope this short note will help you a bit.</p>
1612
2013-04-05T14:55:52.963
<p>I'm adding a feature to my Linux debugger (I'm using Ptrace to manipulate the traced process as well as libbfd/libopcodes) to unwind the stack and determine if discrepancies exist between each CALL's allocated stack space and a statically derived local variable size, printing the address and local stack size of each frame along the way.</p> <p>My general methodology is to take the address in the base pointer (EBP/RBP), increment the pointer to should should contain the stored frame pointer, dereference that address, examine it with PTRACE_PEEKDATA and repeat until I dereference an address occupying an area outside the stack.</p> <p>I know how to check code/data segment registers, but ideally I'd like a method to check if I'm still inside the callstack even if the segmentation has been changed by W^X memory pages or an otherwise nonexecutable stack.</p> <p>In short, how can I check (in the general case) when I've moved outside the stack without triggering a general protection fault?</p> <p>(As as aside, I realize I'm operating on the assumption that checking an address's page segment is the ideal methodology here -- perhaps another simpler method exists to determine if an address is within the current process's stack space)</p>
How can I check I've moved outside the stack without triggering a protection fault?
|debuggers|linux|x86|callstack|segmentation|
<p>When examining the VirtualAddress property of the IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR within the Data Directory of a running process, one may observe the manifestation of native code as .NET. This occurrence is attributed to the dynamic execution of .NET modules during runtime. However, it is imperative to consider.</p>
1614
2013-04-05T17:54:15.087
<p>How can I quickly tell if a EXE or DLL I have is managed code or not?</p> <p>I spent some time recently trying to disassemble a file and then later learned through some traces in the code that I could have skipped all that work and just used ILspy. How can I avoid repeating that experience in the future?</p>
Determining if a file is managed code or not
|windows|tools|dll|pe|
<h1>Sniffing traffic only ... is easy</h1> <p>If you merely wanted to sniff the traffic you could <a href="http://wiki.wireshark.org/Protocols/tds" rel="nofollow noreferrer">use the TDS protocol sniffer</a> that comes with <a href="http://www.wireshark.org/" rel="nofollow noreferrer">WireShark</a>.</p> <h1>Let the laziness guide you - laziness is the reverser's <em>friend</em></h1> <blockquote> <p>Listening to pipes or TCP/IP is not an option at this moment; I would like to inject at a higher level, preferably at SQLOS-component level.</p> </blockquote> <p>I don't know why you insist on doing this a particular way when all information is readily available and all you need to do is put the jigsaw pieces together. This would seem to be the easiest, fastest - in short: laziest - method. Besides TCP/IP <em>is</em> the higher level, because you can intercept it even before it reaches the actual SQL server <em>machine</em> if you can hijack the IP/name of the SQL server and put a "proxy" in between. How <em>high level</em> do you want it? What you insist on is actually drilling down into the lower level guts of the MS SQL Server.</p> <p>MS SQL Server uses a <a href="http://msdn.microsoft.com/en-us/library/cc448435.aspx" rel="nofollow noreferrer">documented protocol</a> and using <a href="http://www.microsoft.com/msj/0599/LayeredService/LayeredService.aspx" rel="nofollow noreferrer">an LSP</a> you should/would be able to sniff, intercept and even manipulate that traffic. As far as I recall LSPs run within the process space of the application whose traffic they're filtering. You can consider them a makeshift application-level firewall, literally.</p> <p>Alternatively - and probably the better choice anyway - you could write a proxy based on the existing and free <a href="http://www.freetds.org" rel="nofollow noreferrer">FreeTDS</a> (licensed under LGPL). The <a href="http://freetds.cvs.sourceforge.net/viewvc/freetds/freetds/src/pool/" rel="nofollow noreferrer"><code>tdspool</code></a> program would be a good point to start this endeavor. And yes, this should be suitable for actual <em>interception</em>, not just sniffing forwarded traffic. You can use the library (FreeTDS) to decode and re-encode the queries. That library would also be the one to use inside your LSP, obviously.</p> <p>I'll save the time to go into details of the disassembly, although I installed MS SQL Server 2008 and briefly looked at it in IDA Pro. <a href="https://reverseengineering.stackexchange.com/a/1778/245">Brendan's answer</a> provides a good overview, even if I disagree with this overly involved method where an easier one is available. But then, <a href="https://reverseengineering.stackexchange.com/q/1617/245">you (Hernán) asked for it.</a></p>
1617
2013-04-05T19:45:11.907
<p>I'm researching into intercepting queries that arrive at the SQL Server 2008 process.</p> <p>SQLOS architecture is divided in the following system DLLs:</p> <ul> <li><strong>sqlmin.dll</strong>: Storage, replication, security features,etc.</li> <li><strong>sqllang.dll</strong>: TransactSQL query execution engine, expression evaluation, etc.</li> <li><strong>sqldk.dll</strong>: Task scheduling and dispatch, worked thread creation, message loops, etc.</li> </ul> <p><em>SQLSERVR</em> service process instances the SQLOS components through <em>sqlboot.dll</em> and <em>sqldk.dll</em>, and the worker threads receive queries through the selected connection method in the server (TCP/IP, local shared memory or named-pipes).</p> <p>I've debugged the sqlservr.exe process address space searching for textual queries. It seems that query strings are readable, but I could not find a point where queries can be intercepted while they enter the SQLOS scheduler.</p> <p>Listening to pipes or TCP/IP is not an option at this moment; I would like to inject at a higher level, preferably at SQLOS-component level.</p> <p>Any idea on where to start looking into? </p>
Server-side Query interception with MS SQL Server
|windows|dll|mssql|
<p>Another option that's pointed out in the comments above by @CallMeV is to use hooking. On Windows you may look at using <a href="http://easyhook.codeplex.com/" rel="nofollow">EasyHook</a>.</p>
1628
2013-04-06T13:45:41.450
<p>Always wondered how it would be possible to see what data is being transmitted back and forth with an application that calls home.</p> <p>Let's say we emulate the server via host file redirect. Would it be possible to see what requests are being made by the application?</p> <p>Also is it possible at all to intercept the response(and view data) from the real server before it reaches the application?</p>
How to see what data is being transmitted when an application calls home?
|tools|windows|security|php|serial-communication|
<p>Hi,the most important reason is: debugging / reversing is quite abstruse and difficult, when you see a full screen assembly codes, and then suddently, they carsh/ fatals / freeze ... You just have no any idea to go on. So you have to search the answer in Internet, but most informations are all about Ollydbg 1.1, and there are lots of plugins to help you resolve the problem, enen though you don't know any secret inside the plugin or else. </p> <p>So, would you take your advantage to try the v2.0, face to helpless situation lonely ?</p>
1636
2013-04-06T15:18:09.063
<p>I see that most RE tutorials around the web that give RE examples use OllyDbg 1, even if the tutorial was written after the release of OllyDbg 2.</p> <p>Is there any particular reason for that? Is version 2 too buggy, or were some of the features dropped?</p>
Advantages of OllyDbg 1 over OllyDbg 2
|ollydbg|
<p>Yes, they work as @broadway already pointed out. However, PIN under OSX have many-many restrictions, some of them documented and others not. The most noticeable feature it lacks is support for creating threads in a PIN tool.</p>
1641
2013-04-06T23:38:55.913
<p>I see that PinTool works for Windows and Linux. Does it also happen to work for OSX? Or is there a similar tool that I can use to easily record code coverage for a closed-source app?</p>
Pintool For OSX
|dynamic-analysis|osx|
<p>As suggested by DCoder, I use the following helper class to efficiently resolve addresses to basic blocks:</p> <pre><code># Wrapper to operate on sorted basic blocks. class BBWrapper(object): def __init__(self, ea, bb): self.ea_ = ea self.bb_ = bb def get_bb(self): return self.bb_ def __lt__(self, other): return self.ea_ &lt; other.ea_ # Creates a basic block cache for all basic blocks in the given function. class BBCache(object): def __init__(self, f): self.bb_cache_ = [] for bb in idaapi.FlowChart(f): self.bb_cache_.append(BBWrapper(bb.startEA, bb)) self.bb_cache_ = sorted(self.bb_cache_) def find_block(self, ea): i = bisect_right(self.bb_cache_, BBWrapper(ea, None)) if i: return self.bb_cache_[i-1].get_bb() else: return None </code></pre> <p>It can be used like this:</p> <pre><code>bb_cache = BBCache(idaapi.get_func(here())) found = bb_cache.find_block(here()) if found: print "found: %X - %X" % (found.startEA, found.endEA) else: print "No basic block found that contains %X" % here() </code></pre>
1646
2013-04-07T12:24:01.923
<p>Say I have an arbitrary address and I want to find out which basic block (i.e. area_t structure) corresponds to it. How would I do that?</p> <p>Edit: more specifically, I want to know the beginning / end of the basic block to which a given address belongs.</p>
How to map an arbitrary address to its corresponding basic block in IDA?
|idapython|ida|
<p>BAP is mostly a rewrite of BitBlaze, so feature-wise there are many common features. However, many of these have been re-written or re-designed for BAP.</p> <p><strong>Common features:</strong></p> <ul> <li>Lifting of usermode, x86 instructions</li> <li>Datafow analysis module</li> <li>Dominator analysis</li> <li>CFG and SSA representations</li> <li>Optimization framework</li> <li>Verification condition generation</li> <li>Dependency graphs</li> <li>Slicing</li> </ul> <p>I am a BAP developer, so I can mainly attest to what is new in BAP since we split. However, I don't think BitBlaze has (publicly) added new features since then.</p> <p><strong>New in BAP</strong>:</p> <ul> <li>Formally defined semantics for the IL</li> <li>PIN-based user-level taint tracking and tracing tool</li> <li>Integration with LLVM</li> <li>Native instruction lifting (i.e., in OCaml)</li> </ul> <p><strong>Only in BitBlaze:</strong></p> <ul> <li>TEMU system-level taint tracking and tracing tool</li> </ul>
1653
2013-04-08T12:03:57.463
<p><a href="http://bitblaze.cs.berkeley.edu/">BitBlaze</a> and <a href="http://bap.ece.cmu.edu/">BAP</a> are two platforms to perform binary analysis. And, if I understand well, they are sharing lots of common features. What are their respective main features and in what do they differ from each other ?</p>
What are the differences between BitBlaze and BAP?
|tools|static-analysis|dynamic-analysis|binary-analysis|
<p>As others have said, this is for getting current instruction's address. But it's not recommended as it'll hurt performance because it won't return anywhere, causing disagreement of return addresses in data stack and in the CPU's internal calling stack</p> <p>The recommended way is</p> <pre><code>GetCurrentAddress: mov eax, [esp] ret ... call GetCurrentAddress mov [currentInstruction], eax </code></pre> <blockquote> <p>The reason is the &quot;hidden variables&quot; inside the processor. All modern processors contain much more state than you can see from the instruction sequence. There are TLBs, L1 and L2 caches, all sorts of stuff that you can't see. The hidden variable that is important here is the return address predictor.</p> <p><strong>The more recent Pentium (and I believe also Athlon) processors maintain an internal stack that is updated by each CALL and RET instruction</strong>. When a CALL is executed, the return address is pushed both onto the <em>real stack</em> (the one that the ESP register points to) as well as to the <em>internal return address predictor stack</em>; a RET instruction pops the top address of the return address predictor stack as well as the real stack.</p> <p>The return address predictor stack is used when the processor decodes a RET instruction. It looks at the top of the return address predictor stack and says, <em>&quot;I bet that RET instruction is going to return to that address.&quot;</em> It then speculatively executes the instructions at that address. Since programs rarely fiddle with return addresses on the stack, these predictions tend to be highly accurate.</p> <p><a href="https://devblogs.microsoft.com/oldnewthing/20041216-00/?p=36973" rel="nofollow noreferrer">https://devblogs.microsoft.com/oldnewthing/20041216-00/?p=36973</a></p> </blockquote>
1654
2013-04-08T12:42:47.817
<p>While reversing a 32bit Mach-O binary with Hopper, I noticed this peculiar method. The instruction on 0x0000e506 seems to be calling an address right below the instruction.</p> <p>What would be the reason for this? Is it some kind of register cleaning trickery?</p> <p><a href="https://i.stack.imgur.com/OBxX3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OBxX3.png" alt="Disassembly listing containing an instruction call 0xe50b at address 0xe506, immediately followed by pop eax at address 0xe50b" /></a></p>
Why would a program contain a call instruction targetting the address immediately following that instruction?
|assembly|x86|
<p>The answers already in this thread are good ones. In a nutshell, an opaque predicate is "something that a program analysis might miss, if the program analysis is not sophisticated enough". Denis' example was based on the inverse of constant propagation, and served as an anti-checksum mechanism. Joxean's <code>SetErrorMode</code> example was an environment-based opaque predicate that was used for dynamic anti-emulation. Two of Ange's answers were also dynamic anti-emulation; based upon the environment, and based upon uncommon platform features. Ange's other example was more like an anti-disassembly trick via indirect addressing.</p> <p>In the academic literature, an opaque predicate is referred to as a branch that always executes in one direction, which is known to the creator of the program, and which is unknown a priori to the analyzer. The notion of "hardness" of an opaque predicate is deliberately omitted from this definition. Academic predicates are often based upon number-theoretic constructions, aliasing relationships, recursive data structures; basically anything that is commonly understood by program analysis researchers to cause problems for a program analysis tool. </p> <p>My favorite researcher Mila Dalla Preda has shown that the ability for an abstract interpreter to break a given category of opaque predicate is related to the "completeness" of the domain with respect to the property tested by the predicate. She demonstrates by using mod-k-based opaque predicates, and elicits a family of domains that are complete (i.e. incur no abstract precision loss) for mod-k with respect to common transformers (addition, multiplication, etc). Then she explores the use of obscure theoretical constructions such as completeness refinement to automatically construct a domain for breaking a certain category of predicate. See <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.69.3653&amp;rep=rep1&amp;type=pdf" rel="nofollow noreferrer">this paper</a> for more details.</p>
1669
2013-04-09T07:48:31.540
<p>I saw the term of <em>opaque predicates</em> several times in obfuscation papers. As far as I understand it, it refers to predicates that are hard to evaluate in an automated manner. Placing it at strategical points of the program (<code>jmp</code>, <code>test</code>, ...) can mislead the analysis of a program by automatic tools.</p> <p>My definition is lacking of precision and, moreover, I have no idea on how to estimate the <em>opacity</em> of such a predicate (its efficiency). So, can somebody give a proper definition and maybe a few examples ?</p>
What is an "opaque predicate"?
|obfuscation|
<p>Samurai's answer is correct , but put more clearly , your mistake is that you enter the literal string </p> <pre><code>123456789abc\x7c\x84\x04\x08 </code></pre> <p>where as what you probably want is something like:</p> <pre><code>perl -e 'print "123456789abc\x7c\x84\x04\x08"' | ./yourbinary </code></pre> <p>In the first case the <code>\x7c\x84\x04\x08</code> is just that, a 16 characters length string, where in the second case, the <code>\x</code> escape sequence is actually interpreted and <code>\x7c\x84\x04\x08</code> is printed as just 4 bytes.</p>
1672
2013-04-09T08:21:37.047
<p>I was trying to understand buffer overflow attacks using the following C program </p> <pre><code>#include"stdio.h" #include"string.h" void iwontprint() { printf("i wont be printed!"); } void callme() { char buffer[8]; gets(buffer); puts(buffer); } int main(int argc,int** argv) { callme(); return 0; } </code></pre> <p>Loading up the program in GDB before calling the <code>gets(buffer)</code> gives the following value of ESP : </p> <pre><code>0xbffff4d4: 0xb7ff0590 0x080484db 0xb7fc1ff4 0xbffff4e8 0xbffff4e4: 0x080484b6 0xbffff568 0xb7e79e46 0x00000001 </code></pre> <p>And after entering the input <code>123456789abc\x7c\x84\x04\x08</code> I am getting totally different values in ESP :</p> <pre><code>0xbffff4d4: 0xbffff4d8 0x34333231 0x38373635 0x63626139 0xbffff4e4: 0x6337785c 0x3438785c 0x3430785c 0x3830785c </code></pre> <p>I've already set <code>randomize_va_space = 0</code></p> <pre><code>$cat /proc/sys/kernel/randomize_va_space 0 </code></pre> <p>Can anybody provide any pointers as to what am I missing here ?</p>
Why is this string on the stack not exactly the one I entered?
|disassembly|gdb|buffer-overflow|
<p>This is also commonly known as an <strong>encryption wrapper</strong>. I'm sure there are several other similar names used in the industry. </p> <p>The actual code isn't as important as the concept. The plaintext code is prepended (in executive order) by a decryption stub responsible for decoding the body of the code. In this way, the main code body (payload in the case of malware) is encrypted, and thus doesn't have constant bytes. The decoder stub itself remains constant in this example, though <strong>polymorphism</strong> is a later evolution that regenerates the encoder and decoder so that they, too, contain no constant bytes. By lessening the number of constant bytes between copies of the code, detection signature exposure is reduced.</p> <p>Decoder stubs can offer decompression as well.</p> <p>This mechanism got heavy use in the early days of self-replicating PC viruses. These were labeled with the characteristic of being <strong>self-encrypting</strong>. It is still used in today by some subversive software. </p> <p><em>Importantly, native code isn't the only code that can be 'wrapped' in this fashion.</em></p>
1673
2013-04-09T08:27:22.040
<p>I have an obfuscated binary which only print a simple <code>Hello World!</code> and exit like this:</p> <pre><code>Hello World! </code></pre> <p>But, when I am looking at the assembly with <code>objdump</code>, I cannot find any call to <code>printf</code> or <code>write</code>, nor find the string <code>Hello World!</code>.</p> <pre><code>0804840c &lt;main&gt;: 804840c: be 1e 84 04 08 mov $0x804841e,%esi 8048411: 89 f7 mov %esi,%edi 8048413: b9 26 00 00 00 mov $0x26,%ecx 8048418: ac lods %ds:(%esi),%al 8048419: 34 aa xor $0xaa,%al 804841b: aa stos %al,%es:(%edi) 804841c: e2 fa loop 8048418 &lt;main+0xc&gt; 804841e: 23 4f 29 and 0x29(%edi),%ecx 8048421: 46 inc %esi 8048422: ae scas %es:(%edi),%al 8048423: 29 4e 5a sub %ecx,0x5a(%esi) 8048426: 29 6e ae sub %ebp,-0x52(%esi) 8048429: c2 9c 2e ret $0x2e9c 804842c: ae scas %es:(%edi),%al 804842d: a2 42 17 54 55 mov %al,0x55541742 8048432: 55 push %ebp 8048433: 23 46 69 and 0x69(%esi),%eax 8048436: e2 cf loop 8048407 &lt;frame_dummy+0x27&gt; 8048438: c6 c6 c5 mov $0xc5,%dh 804843b: 8a fd mov %ch,%bh 804843d: c5 d8 c6 ce 8b vshufps $0x8b,%xmm6,%xmm4,%xmm1 8048442: a0 aa 90 90 90 mov 0x909090aa,%al 8048447: 90 nop ... 804844f: 90 nop </code></pre> <p>The obfuscation technique claimed to be used here is called <em>instruction camouflage</em> (see this <a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.125.5028" rel="noreferrer">paper</a>). Can someone explain what is it and how does it works ?</p>
What is "instruction camouflage" obfuscation?
|obfuscation|
<p>In general what you do is that you make a new segment in the executable, change the entry point to your new segment. Your new segment has the decryption code for the original code and the changed entry point now means that the first code to execute when the executable is loaded is your decryption code. </p> <p>Your encryption code then either maps a segment, usually at the address where the original executable segment was located, and decrypts the source segment into the mapped segment or it directly decrypts the segment in place. If your code decrypts the segment in place you need to make sure the remove any relocations from the original executable. </p> <p>In all cases, except if you get to map your decrypted executable segment at its original intended address, you need to do the relocations yourself after decryption so that the executable won't crash. Personally I would implement the relocations in order to support things like ASLR. After decryption and relocation you simply call into the original entry point.</p> <p>This way you do not have to create your encryption or "masking" code for a particular binary and applying it to arbitrary binaries in the future should be possible.</p>
1676
2013-04-09T08:41:45.237
<p>I would like to know what is the simplest way to produce code binaries with instruction camouflage (see <a href="https://reverseengineering.stackexchange.com/questions/1673/what-is-a-instruction-camouflage-obfuscation">this question</a>). </p> <p>The problem here is that you first have to produce a correct assembly code and then to hide it with a given method directly into the binary. Doing it by hand is quite painful, especially if you have to take care of the static jumps into the code. Right now, I am using <a href="http://www.nasm.us/" rel="nofollow noreferrer">nasm</a>, and more precisely its <a href="http://www.nasm.us/xdoc/2.10.07/html/nasmdoc4.html" rel="nofollow noreferrer">preprocessor</a> to perform the camouflage operations. But, I wonder if there are better ways to do it.</p> <p>So, what tools or tricks do you use to produce such binaries ? </p>
How to produce binaries with "instruction camouflage" obfuscation?
|tools|obfuscation|
<p>There is an H8 port of GNU binutils (the target is called 'h8300' I believe) which includes <code>objdump</code>. It seems it's even available in Debian in the package <a href="http://packages.debian.org/sid/binutils-h8300-hms"><code>binutils-h8300-hms</code></a> (might be outdated).</p> <p>Alternative GNU-based toolchains for many Renesas processors (including H8) are provided by <a href="http://www.kpitgnutools.com/">KPIT</a> (free but requires registration). I think they've been contributing to mainline too but not sure how's their progress there.</p> <p>Just for reference, here's how to use <code>objdump</code> to disassemble a raw binary:</p> <pre><code>objdump -m h8300 -b binary -D myfile.bin </code></pre> <p>Renesas offers their own commercial compiler/assembler/simulator (and I <em>think</em> a disassembler too) suite called <a href="http://am.renesas.com/products/tools/coding_tools/c_compilers_assemblers/h8_compiler/index.jsp">High-performance Embedded Workshop</a> (HEW) but I couldn't find out how much it costs. There is a <a href="http://am.renesas.com/support/downloads/download_results/C2000301-C2000400/evaluation_h8c.jsp">downloadable evaluation version</a>, however.</p> <p>For a quick look at some hex you can also try the <a href="http://www.onlinedisassembler.com/odaweb/run_hex">Online Disassembler</a>, it has a couple of H8 variants.</p>
1684
2013-04-09T21:28:14.397
<p>IDA Pro can deal with the Renesas H8 processors, but not the free version.</p> <p>Are there any free or low cost (&lt;£100) disassemblers for the Renesas H8 family or processors?</p>
Are there any free or low cost disassemblers for the Renesas H8 family of processors?
|tools|disassembly|renesas-h8|
<p>Here is a collection of anti-sandbox/vm/debugger techniques implemented in a open source program which will give you a clear idea how to detect virtualization: <a href="https://github.com/LordNoteworthy/al-khaser" rel="nofollow noreferrer">https://github.com/LordNoteworthy/al-khaser</a>.</p> <p>Here are the list of supported techniques:</p> <h3>Anti-debugging attacks</h3> <ul> <li>IsDebuggerPresent</li> <li>CheckRemoteDebuggerPresent</li> <li>Process Environement Block (BeingDebugged)</li> <li>Process Environement Block (NtGlobalFlag)</li> <li>ProcessHeap (Flags)</li> <li>ProcessHeap (ForceFlags)</li> <li>NtQueryInformationProcess (ProcessDebugPort)</li> <li>NtQueryInformationProcess (ProcessDebugFlags)</li> <li>NtQueryInformationProcess (ProcessDebugObject)</li> <li>NtSetInformationThread (HideThreadFromDebugger)</li> <li>NtQueryObject (ObjectTypeInformation)</li> <li>NtQueryObject (ObjectAllTypesInformation)</li> <li>CloseHanlde (NtClose) Invalide Handle</li> <li>SetHandleInformation (Protected Handle)</li> <li>UnhandledExceptionFilter</li> <li>OutputDebugString (GetLastError())</li> <li>Hardware Breakpoints (SEH / GetThreadContext)</li> <li>Software Breakpoints (INT3 / 0xCC)</li> <li>Memory Breakpoints (PAGE_GUARD)</li> <li>Interrupt 0x2d</li> <li>Interrupt 1</li> <li>Parent Process (Explorer.exe)</li> <li>SeDebugPrivilege (Csrss.exe)</li> <li>NtYieldExecution / SwitchToThread</li> <li>TLS callbacks</li> </ul> <h3>Anti-Dumping</h3> <ul> <li>Erase PE header from memory</li> <li>SizeOfImage</li> </ul> <h3>Timing Attacks [Anti-Sandbox]</h3> <ul> <li>RDTSC (with CPUID to force a VM Exit)</li> <li>RDTSC (Locky version with GetProcessHeap &amp; CloseHandle)</li> <li>Sleep -> SleepEx -> NtDelayExecution</li> <li>Sleep (in a loop a small delay)</li> <li>Sleep and check if time was accelerated (GetTickCount)</li> <li>SetTimer (Standard Windows Timers)</li> <li>timeSetEvent (Multimedia Timers)</li> <li>WaitForSingleObject -> WaitForSingleObjectEx -> NtWaitForSingleObject</li> <li>WaitForMultipleObjects -> WaitForMultipleObjectsEx -> </li> </ul> <h3>Human Interaction / Generic [Anti-Sandbox]</h3> <ul> <li>Mouse movement</li> <li>Total Physical memory (GlobalMemoryStatusEx)</li> <li>Disk size using DeviceIoControl (IOCTL_DISK_GET_LENGTH_INFO)</li> <li>Disk size using GetDiskFreeSpaceEx (TotalNumberOfBytes)</li> <li>Count of processors (Win32/Tinba - Win32/Dyre)</li> </ul> <h3>Anti-Virtualization / Full-System Emulation</h3> <ul> <li><p><strong>Registry key value artifacts</strong></p> <ul> <li>HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0 (Identifier) (VBOX)</li> <li>HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0 (Identifier) (QEMU)</li> <li>HARDWARE\Description\System (SystemBiosVersion) (VBOX)</li> <li>HARDWARE\Description\System (SystemBiosVersion) (QEMU)</li> <li>HARDWARE\Description\System (VideoBiosVersion) (VIRTUALBOX)</li> <li>HARDWARE\Description\System (SystemBiosDate) (06/23/99)</li> <li>HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0 (Identifier) (VMWARE)</li> <li>HARDWARE\DEVICEMAP\Scsi\Scsi Port 1\Scsi Bus 0\Target Id 0\Logical Unit Id 0 (Identifier) (VMWARE)</li> <li>HARDWARE\DEVICEMAP\Scsi\Scsi Port 2\Scsi Bus 0\Target Id 0\Logical Unit Id 0 (Identifier) (VMWARE)</li> </ul></li> <li><p><strong>Registry Keys artifacts</strong></p> <ul> <li>"HARDWARE\ACPI\DSDT\VBOX__"</li> <li>"HARDWARE\ACPI\FADT\VBOX__"</li> <li>"HARDWARE\ACPI\RSDT\VBOX__"</li> <li>"SOFTWARE\Oracle\VirtualBox Guest Additions"</li> <li>"SYSTEM\ControlSet001\Services\VBoxGuest"</li> <li>"SYSTEM\ControlSet001\Services\VBoxMouse"</li> <li>"SYSTEM\ControlSet001\Services\VBoxService"</li> <li>"SYSTEM\ControlSet001\Services\VBoxSF"</li> <li>"SYSTEM\ControlSet001\Services\VBoxVideo"</li> <li>SOFTWARE\VMware, Inc.\VMware Tools</li> <li>SOFTWARE\Wine</li> </ul></li> <li><p><strong>File system artifacts</strong></p> <ul> <li>"system32\drivers\VBoxMouse.sys"</li> <li>"system32\drivers\VBoxGuest.sys"</li> <li>"system32\drivers\VBoxSF.sys"</li> <li>"system32\drivers\VBoxVideo.sys"</li> <li>"system32\vboxdisp.dll"</li> <li>"system32\vboxhook.dll"</li> <li>"system32\vboxmrxnp.dll"</li> <li>"system32\vboxogl.dll"</li> <li>"system32\vboxoglarrayspu.dll"</li> <li>"system32\vboxoglcrutil.dll"</li> <li>"system32\vboxoglerrorspu.dll"</li> <li>"system32\vboxoglfeedbackspu.dll"</li> <li>"system32\vboxoglpackspu.dll"</li> <li>"system32\vboxoglpassthroughspu.dll"</li> <li>"system32\vboxservice.exe"</li> <li>"system32\vboxtray.exe"</li> <li>"system32\VBoxControl.exe"</li> <li>"system32\drivers\vmmouse.sys"</li> <li>"system32\drivers\vmhgfs.sys"</li> </ul></li> <li><p><strong>Directories artifacts</strong></p> <ul> <li>"%PROGRAMFILES%\oracle\virtualbox guest additions\"</li> <li>"%PROGRAMFILES%\VMWare\"</li> </ul></li> <li><p><strong>Memory artifacts</strong></p> <ul> <li>Interupt Descriptor Table (IDT) location</li> <li>Local Descriptor Table (LDT) location</li> <li>Global Descriptor Table (GDT) location</li> <li>Task state segment trick with STR</li> </ul></li> <li><p><strong>MAC Address</strong></p> <ul> <li>"\x08\x00\x27" (VBOX)</li> <li>"\x00\x05\x69" (VMWARE)</li> <li>"\x00\x0C\x29" (VMWARE)</li> <li>"\x00\x1C\x14" (VMWARE)</li> <li>"\x00\x50\x56" (VMWARE)</li> </ul></li> <li><p><strong>Virtual devices</strong></p> <ul> <li>"\\.\VBoxMiniRdrDN"</li> <li>"\\.\VBoxGuest"</li> <li>"\\.\pipe\VBoxMiniRdDN"</li> <li>"\\.\VBoxTrayIPC"</li> <li>"\\.\pipe\VBoxTrayIPC")</li> <li>"\\.\HGFS"</li> <li>"\\.\vmci"</li> </ul></li> <li><p><strong>Hardware Device information</strong></p> <ul> <li>SetupAPI SetupDiEnumDeviceInfo (GUID_DEVCLASS_DISKDRIVE) <ul> <li>QEMU</li> <li>VMWare</li> <li>VBOX</li> <li>VIRTUAL HD</li> </ul></li> </ul></li> <li><p><strong>Adapter name</strong></p> <ul> <li>VMWare</li> </ul></li> <li><p><strong>Windows Class</strong></p> <ul> <li>VBoxTrayToolWndClass</li> <li>VBoxTrayToolWnd</li> </ul></li> <li><p><strong>Network shares</strong></p> <ul> <li>VirtualBox Shared Folders</li> </ul></li> <li><p><strong>Processes</strong></p> <ul> <li>vboxservice.exe (VBOX)</li> <li>vboxtray.exe (VBOX)</li> <li>vmtoolsd.exe (VMWARE)</li> <li>vmwaretray.exe (VMWARE)</li> <li>vmwareuser (VMWARE)</li> <li>vmsrvc.exe (VirtualPC)</li> <li>vmusrvc.exe (VirtualPC)</li> <li>prl_cc.exe (Parallels)</li> <li>prl_tools.exe (Parallels)</li> <li>xenservice.exe (Citrix Xen)</li> </ul></li> <li><p><strong>WMI</strong></p> <ul> <li>SELECT * FROM Win32_Bios (SerialNumber) (VMWARE)</li> <li>SELECT * FROM Win32_PnPEntity (DeviceId) (VBOX)</li> <li>SELECT * FROM Win32_NetworkAdapterConfiguration (MACAddress) (VBOX)</li> <li>SELECT * FROM Win32_NTEventlogFile (VBOX)</li> <li>SELECT * FROM Win32_Processor (NumberOfCores) (GENERIC)</li> <li>SELECT * FROM Win32_LogicalDisk (Size) (GENERIC)</li> </ul></li> <li><p><strong>DLL Exports and Loaded DLLs</strong></p> <ul> <li>kernel32.dll!wine_get_unix_file_nameWine (Wine)</li> <li>sbiedll.dll (Sandboxie)</li> <li>dbghelp.dll (MS debugging support routines)</li> <li>api_log.dll (iDefense Labs)</li> <li>dir_watch.dll (iDefense Labs)</li> <li>pstorec.dll (SunBelt Sandbox)</li> <li>vmcheck.dll (Virtual PC)</li> <li>wpespy.dll (WPE Pro)</li> </ul></li> <li><p><strong>CPU*</strong></p> <ul> <li>Hypervisor presence using (EAX=0x1)</li> <li>Hypervisor vendor using (EAX=0x40000000) <ul> <li>"KVMKVMKVM\0\0\0" (KVM)</li> <li>"Microsoft Hv" (Microsoft Hyper-V or Windows Virtual PC)</li> <li>"VMwareVMware" (VMware)</li> <li>"XenVMMXenVMM" (Xen)</li> <li>"prl hyperv " ( Parallels) -"VBoxVBoxVBox" ( VirtualBox)</li> </ul></li> </ul></li> </ul> <h3>Anti-Analysis</h3> <ul> <li><strong>Processes</strong> <ul> <li>OllyDBG / ImmunityDebugger / WinDbg / IDA Pro</li> <li>SysInternals Suite Tools (Process Explorer / Process Monitor / Regmon / Filemon, TCPView, Autoruns)</li> <li>Wireshark / Dumpcap</li> <li>ProcessHacker / SysAnalyzer / HookExplorer / SysInspector</li> <li>ImportREC / PETools / LordPE</li> <li>JoeBox Sandbox</li> </ul></li> </ul>
1686
2013-04-09T22:12:45.620
<p>What are the different ways for a program to detect that it executes inside a virtualized environment ? And, would it be possible to detect what kind of virtualization is used ?</p>
How to detect a virtualized environment?
|anti-debugging|virtual-machines|
<p>In order of increasing complexity: oligomorphic, polymorphic, metamorphic.</p> <p>The first two terms are generally applied to decryptors. We (anti-virus industry) define them this way: oligomorphic - decryptor with few variable elements, which does not affect the size or shape of the code. It means that the variable elements are usually fixed-size instructions, but it can also apply to the register initialization.</p> <h1>Oligomorphic example</h1> <pre><code>std ;fake, might be replaced by cld / nop / xchg ax, cx / ... mov cx, size mov ax, ax ;fake, might be replaced by mov bx, bx / or cx, cx / ... mov si, decrypt_src cld ;fake mov di, decrypt_dst or ax, ax ;fake mov bl, key and bp, bp ;fake decrypt: xor [di], bl xchg dx, ax ;fake inc di cld ;fake loop decrypt </code></pre> <p>In this case, the <code>di</code> register could be exchanged with <code>si</code>, for example. Very simple replacement.</p> <h1>Polymorphic</h1> <p>decryptor with potentially highly variable elements, which does affect the size and/or shape of the code. It means that all kinds of changes can be applied, including subroutine creation, large blocks of garbage instructions, code &quot;islands&quot;, or even algorithmic register initialisation (example <a href="http://pferrie.host22.com/papers/bounds.pdf" rel="nofollow noreferrer">here</a>).</p> <h1>Metamorphic</h1> <p>highly variable elements are applied directly to the body. There is generally no decryptor in this case. The same techniques for polymorphism are applied to the code itself. The most famous example of this is the Simile virus from 2002 (details <a href="http://pferrie.host22.com/papers/simile.pdf" rel="nofollow noreferrer">here</a>). There's a detailed paper on the subject with actual examples <a href="http://pferrie.host22.com/papers/metamorp.pdf" rel="nofollow noreferrer">here</a>)</p>
1696
2013-04-10T08:34:49.783
<p>Malware use several methods to evade anti-virus software, one is to change their code when they are replicating. I saw mainly three type of techniques in the wild which are: <em>metamorphic malware</em>, <em>oligomorphic malware</em> and <em>polymorphic malware</em> (I might have missed one). What are the main differences between theses techniques and what do they do ?</p>
What are the differences between metamorphic, oligomorphic and polymorphic malware?
|obfuscation|malware|
<p>I recommend <code>uncompyle6</code>. it can decompile pyc/pyo files and it is compatible with python 3</p> <ol> <li><p><code>pip install uncompyle6</code></p> </li> <li><p><code>uncompyle6 FILE.pyc</code></p> </li> </ol>
1701
2013-04-10T14:02:31.443
<p>Does anybody have a suggestion for (non commercial) software to decompile "byte-code" Python (.pyc) files?</p> <p>Everything I've found seems to break...</p>
Decompiling .pyc files
|tools|decompilation|python|
<p>ELF itself doesn't specify any kind of checksum. Your link error is likely due to an incorrect edit which changed some offsets within the file. If you don't adjust the offsets, you have to replace a string with a string that is no longer than the original, and you cannot add new fields unless you have a known amount of slack space available.</p> <p>Use <code>readelf -a</code> to check the ELF file headers, and compare old with new.</p>
1703
2013-04-10T17:38:55.013
<p>I've hex-edited a string in an Android ELF binary.<br> Now, it won't run, and gives the error message <em>CANNOT LINK EXECUTABLE</em>, presumably due to a bad checksum.</p> <p>Does anybody have a tool to fix the checksum? </p>
Fixing the checksum of a modified Android ELF
|tools|android|elf|
<p><a href="http://www.eclipse.org/aspectj/" rel="nofollow">AspectJ</a> can be used to do this on the JVM, via load-time weaving. It's built on Asm but there's more abstraction (no bytecode). Tracing method calls is fairly straight-forward: first define a filter to match "pointcuts" you're interested in, then specify the actions you want to perform ("advice").</p> <p>The syntax is a bit awkward though:</p> <pre><code>package aspects; import java.util.logging.Level; import java.util.logging.Logger; import org.aspectj.lang.Signature; aspect Trace{ pointcut traceMethods() : (execution(* *(..))&amp;&amp; !cflow(within(Trace))); before(): traceMethods(){ Signature sig = thisJoinPointStaticPart.getSignature(); String line =""+ thisJoinPointStaticPart.getSourceLocation().getLine(); String sourceName = thisJoinPointStaticPart.getSourceLocation().getWithinType().getCanonicalName(); Logger.getLogger("Tracing").log( Level.INFO, "Call from " + sourceName +" line " + line +" to " +sig.getDeclaringTypeName() + "." + sig.getName() ); } } </code></pre> <p>Compile with: <code>ajc -outxml -outjar aspects.jar Trace.java</code>.</p> <p>To run FooClass with the weaver, run:</p> <pre><code>java -javaagent:aspectjweaver.jar -cp aspects.jar:${target_jar_name} FooClass </code></pre>
1714
2013-04-11T09:37:10.487
<p>This is not strictly 'reverse engineering', it's mostly related to dynamic instrumentation.</p> <p>So, in the same fashion as <code>strace</code> which allows you to see syscalls made by a process, or <code>ftrace</code> to see function calls, is there anything similar for Java?</p> <p>What I am interested in is having a <code>.jar</code> file that is run in a javaVM. </p> <p>Is there any way to instrument or trace all the Java API calls the application code makes ?</p> <p>That is, without any static analysis of the contents of the <code>.jar</code> or without any editing of the contents of <code>.jar</code> (e.g. to add hooks). Ideally, a solution equivalent to <code>strace</code> or e.g. a manipulated javaVM</p> <p>The same applies on Android - Is there a way to trace all Android framework API calls (or other essentially DalvikVM functions) an application makes without any editing at all of the APK file? All other editing of the environment/system is fine.</p> <p>In my ideal world, the analyst would get the following output, while running an UNEDITED application (<code>.jar</code> or <code>.apk</code>):</p> <pre><code>timestamp1: java.security.SecureRandom.getSeed() called. Arguments: (Number) timestamp2: javax.security.cert.X509Certificate.checkValidity() called. Arguments: (null) ... timestamp3: java.sql.Connection.prepareStatement() called. Arguments: ("SELECT * FROM X WHERE Y = W") </code></pre>
Dynamic java instrumentation?
|dynamic-analysis|java|android|
<p>While this answer is certainly not true in all situations, the answer for which your teacher is probably looking:</p> <ul> <li>Local variables are in the form <code>[EBP - ...]</code></li> <li>Passed arguments are in the form <code>[EBP + ...]</code></li> </ul>
1722
2013-04-11T15:48:28.053
<p>How can you determine if a variable is a local variable of the function or an argument passed to the function?</p>
Determining if a variable is local or an argument passed to a function
|disassembly|c|c++|
<p>Recently, two new kernel instrumentation systems have been released, of which I am the creator of one:</p> <ol> <li><a href="https://github.com/Granary/granary">Granary</a>, which is primarily focused on module instrumentation. This is the instrumentation created by me. Granary internally uses parts of DynamoRIO, but works rather differently. The goal of Granary is to make it easy to develop debugging and analysis tools. There will be a paper in HotDep'13 about one of the major memory debugging tools built on top of Granary.</li> <li><a href="https://github.com/piyus/btkernel">btkernel</a>, a recently released full kernel instrumentation system. You can find a paper about btkernel in SOSP'13.</li> </ol>
1724
2013-04-11T18:05:07.347
<p>I've found some universities that are porting <a href="http://www.dynamorio.org/" rel="noreferrer">DynamoRIO</a> (or something very similar) to Linux kernel space, but the code doesn't seem to be available. Is there a resource I am unaware of?</p> <p><a href="http://www.cs.toronto.edu/~peter/feiner_asplos_2012.pdf" rel="noreferrer">Here's</a> an example. </p>
How can I use DynamoRIO or something similar in Linux kernel space?
|tools|dynamic-analysis|dynamorio|
<p>As it turns out, somebody asked roughly the same question on reddit about a year ago and I <a href="http://www.reddit.com/r/ReverseEngineering/comments/smf4u/reverser_wanting_to_develop_mathematically/c4fa6yl" rel="nofollow noreferrer">posted a rather extensive answer to it</a>, and I have continued to edit it in the meantime.</p>
1727
2013-04-11T18:39:57.193
<p>I would like more information about the mathematical foundations of vulnerability and exploit development.online sources or books in the right direction will be helpful.</p>
mathematical background behind exploit development and vulnerabilities
|vulnerability-analysis|
<p>Select the first byte, Edit -> Strings -> Unicode.</p>
1734
2013-04-12T03:37:45.860
<p>In IDA 5.0 Freeware how do you convert a block of data into a unicode string, the only thing I can find is to convert it into an ascii string.</p> <pre><code>db 'a' db 0 db 'b' db 0 db 'c' db 0 db 'd' db 0 db 0 db 0 </code></pre> <p>into</p> <pre><code>unicode &lt;abcd&gt;, 0 </code></pre>
IDA Convert to Unicode
|ida|encodings|
<h1>Explanation</h1> <p>The break on attach is due to the <code>ntdll</code> <code>DbgUiRemoteBreakin</code> and <code>DbgBreakPoint</code> functions being called. If you check the <code>kernel32</code> <code>DebugActiveProcess</code> function called by the debugger, OllyDbg or ImmunityDebugger, you will see a call to the <code>CreateRemoteThread</code>, <code>CreateRemoteThreadEx</code>, or <code>ZwCreateThreadEx</code> function depending on your OS.</p> <p>So, i guess one way to bypass breaking is:</p> <ol> <li>debug the debugger itself</li> <li>go to the <code>DbgUiIssueRemoteBreakin</code> function and spot the call to the function creating the remote thread.</li> <li>change the <code>lpStartAddress</code> parameter in case of <code>CreateRemoteThread</code>/<code>CreateRemoteThreadEx</code> to <code>DbgBreakPoint</code>+1 <code>RETN 0xC3</code></li> </ol> <h1>Plugin</h1> <p>I created an OllyDbg v1.10 <a href="http://code.google.com/p/ollytlscatch/downloads/detail?name=SilentAttach.dll" rel="noreferrer">plugin</a> which <code>NOP</code>s the <code>INT3</code> in <code>DbgBreakPoint</code> in the process with the PID you choose. It has only been tested on Windows 7.</p> <h2>Usage</h2> <p>Place SilentAttach.dll in OllyDbg directory, fire OllyDbg, Press <kbd>Alt</kbd>+<kbd>F12</kbd>, and then enter process Id of the process you want to silently attach to.</p> <p>N.B. Since no break occurs, OllyDbg does not extract many piece of info. e.g. list of loaded module. So, you have to activate the context by something like <kbd>Alt</kbd>+<kbd>E</kbd> then <kbd>Alt</kbd>+<kbd>C</kbd></p>
1738
2013-04-12T09:40:39.973
<p>When I attach OllyDbg or ImmunityDebugger to a process, it automatically breaks execution. I'm attaching to a user-mode service running as SYSTEM and only need to catch exceptions, so this is not ideal. Is there a way to disable the break-on-attach behaviour?</p>
How can I prevent Immunity Debugger / OllyDbg from breaking on attach?
|tools|debuggers|ollydbg|immunity-debugger|
<h1>Books:</h1> <ul> <li><strong><a href="https://rads.stackoverflow.com/amzn/click/com/0764574817" rel="nofollow noreferrer" rel="nofollow noreferrer">Reversing: Secrets of Reverse Engineering</a></strong>, Eldad Eilam</li> <li><a href="http://nostarch.com/idapro2.htm" rel="nofollow noreferrer"><strong>IDA Pro Book, 2nd Edition</strong></a>, Chris Eagle (<a href="http://www.idabook.com/" rel="nofollow noreferrer">book's website</a>)</li> <li><a href="http://nostarch.com/ghpython.htm" rel="nofollow noreferrer"><strong>Gray Hat Python</strong></a>, Justin Seitz</li> <li><a href="http://technet.microsoft.com/en-us/sysinternals/bb963901.aspx" rel="nofollow noreferrer"><strong>Windows Internals, 6th edition</strong></a></li> <li><a href="https://rads.stackoverflow.com/amzn/click/com/0735663777" rel="nofollow noreferrer" rel="nofollow noreferrer"><strong>Windows via C/C++ 5th Ed</strong></a></li> </ul> <h1>Articles:</h1> <h1>Tutorials:</h1> <ul> <li><a href="http://tuts4you.com/download.php?list.17" rel="nofollow noreferrer">Lena's Reversing 101</a> — the classic introduction for newbie reverser.</li> <li><a href="http://octopuslabs.io/legend/blog/sample-page.html" rel="nofollow noreferrer">The Legend of Random</a> — list of tutorials and texts to read on RE topics.</li> </ul> <h1>Links:</h1> <ul> <li><a href="http://opensecuritytraining.info/Training.html" rel="nofollow noreferrer">OpenSecurityTraining</a> — place of great and free online courses to learn, from beginners to hi-level pros.</li> </ul> <h1>Forums:</h1> <ul> <li><s><a href="http://www.kernelmode.info/forum/" rel="nofollow noreferrer">KernelMode</a> — here you'll find not only a wide range of topics regarding different parts of RE, but also a great community.</s> (archived)</li> </ul>
1754
2013-04-13T16:32:58.253
<p>This post is for collecting all the best books and tutorials that exist dealing with <a href="/questions/tagged/windows" class="post-tag" title="show questions tagged &#39;windows&#39;" rel="tag">windows</a> specific reverse engineering techniques and concepts. The content will be added to the <a href="https://reverseengineering.stackexchange.com/tags/windows/info">Windows wiki</a>. Any suggestions of books and tutorials should be added into the CW answer. Please do not add any other answers. </p> <hr> <p>If you have anything to say about this, post your opinion here :</p> <ul> <li><p><a href="https://reverseengineering.meta.stackexchange.com/questions/53/how-should-book-tutorial-questions-be-dealt-with">How should book/tutorial questions be dealt with?</a></p></li> <li><p><a href="https://reverseengineering.meta.stackexchange.com/questions/96/lets-develop-a-tag-wiki-format">Lets develop a Tag Wiki format</a></p></li> <li><p>If you have something else to say not covered in the above discussions, start a <a href="https://reverseengineering.meta.stackexchange.com/questions/ask">new meta discussion</a>.</p></li> </ul>
Windows Wiki : Books and Tutorials
|windows|
<p>I am not aware of a currently active generic "firmware reversing" forum.</p> <p>A few years ago there was a pretty ambitious attempt with <a href="http://wayback.archive.org/web/20100514210317/http://lostscrews.com/">lostscrews.com</a> but unfortunately it languished due to lack of attention, got overwhelmed with spam and eventually the domain has expired. I think the guys behind the <a href="http://www.devttys0.com/blog/">/dev/ttyS0 blog</a> also tried opening a forum a couple months ago but it wasn't very active and apparently has been closed down.</p> <p>I guess the problem is that the area is somewhat nebulous and trying to cover everything won't really work. However, there are numerous forums that specialize in a specific type of firmware, manufacturer, or even just one product, and some of them are pretty big on their own. Here's a few examples that come to mind:</p> <ul> <li><a href="http://forum.xda-developers.com/">XDA Developers</a>: everything about hacking Android and Windows Mobile-based phones and other devices.</li> <li>PC BIOS hacking: <a href="http://www.wimsbios.com/forum/">Wim's BIOS</a> and <a href="http://forums.mydigitallife.info/forums/25-BIOS-Mods">My Digital Life</a>.</li> <li>Samsung TVs: <a href="http://forum.samygo.tv/">SamyGO TV</a>.</li> <li>Digital cameras: <a href="http://chdk.setepontos.com/">CHDK</a>, <a href="http://www.magiclantern.fm/forum/index.php">Magic Lantern</a>, <a href="http://nikonhacker.com/">Nikon Hacker</a>.</li> <li>Ebook readers: <a href="http://www.mobileread.com/forums/">MobileRead</a></li> <li>Audio players: <a href="http://forums.rockbox.org/">Rockbox</a></li> <li>Wireless routers: <a href="http://en.wikipedia.org/wiki/List_of_wireless_router_firmware_projects">too many to list here</a>.</li> <li>iPhone/iPod/iPad: <a href="http://www.idroidproject.org/forum/">iDroid Project</a> (and many others)</li> <li>and so on.</li> </ul>
1757
2013-04-13T21:14:00.353
<p>The question pretty much says it. Beyond knowing people that are interested in the same things, is there a collaborative reversing dumping ground for documenting specifically disassembly of closed source firmware?</p>
Is there a collaborative reversing forum for people that deal with firmware?
|decompilation|disassembly|firmware|
<p>As others have mentioned the first thing you should do is dump the memory with MoonSols. This will allow you to do memory analysis using Volatility later. When it comes to malware analysis I find IDA the most useful. In order for it be useful you will need a process dump and a way to rebuild the import table. If the malware can spread to other processes I would create a dummy process, dump it then rebuild the import table. If for example the malware injects into iexplore.exe, open up Ollydbg change the debugging options events to System Breakpoint, open up iexplore.exe, then search for memory of RWX (described <a href="http://hooked-on-mnemonics.blogspot.com/2013/03/working-with-injected-processes.html">here</a>). Check the contents of the memory, if it contains your memory malware dump the process and then rebuild the import table. If you need to manually rebuild the import table you can use the following <a href="http://hooked-on-mnemonics.blogspot.com/2012/09/importing-ollydbg-addresses-into-ida.html">script</a>. If the process does not spread you could attach to the process via a debugger. </p> <p>Disclaimer: I am the author of those links. </p>
1761
2013-04-14T09:41:56.633
<p>I have an infected MS-Windows 7 machine with an <em>in-memory</em> malware, shutting it down will probably make it disappear and I would like to get the malware in a more convenient format to perform some analysis on it.</p> <p>What are the different in-memory malware and what kind of methods do you recommend for each type of in-memory malware ?</p>
How to capture an "in-memory" malware in MS-Windows?
|malware|digital-forensics|
<p>The webdecomp tool didn't work for me on the latest builds of DD-WRT, managed to extract the firmware though.</p> <pre><code>root@ubuntu:~/Desktop/firmware-mod-kit/src/webcomp-tools$ ./webdecomp --httpd="/home/root/Desktop/firmware-mod-kit/fmk/rootfs/usr/sbin/httpd" -www="/home/root/Desktop/firmware-mod-kit/fmk/rootfs/etc/www" --dir="/home/root/Desktop/www" --extract Failed to locate websRomPageIndex! Failed to detect httpd settings! Failed to process Web files! root@ubuntu:~/Desktop/firmware-mod-kit/fmk/rootfs/usr/sbin$ file httpd httpd: ELF 32-bit LSB executable, MIPS, MIPS32 version 1, dynamically linked, interpreter /lib/ld-uClibc.so.0, corrupted section header size </code></pre> <p>Looks like they have obfuscated the section headers.</p> <pre><code>root@ubuntu:~/Desktop/firmware-mod-kit/src/webcomp-tools$ readelf -a /home/root/Desktop/firmware-mod-kit/fmk/rootfs/usr/sbin/httpd ELF Header: Magic: 7f 45 4c 46 01 01 01 00 01 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 1 Type: EXEC (Executable file) Machine: MIPS R3000 Version: 0x1 Entry point address: 0x401a30 Start of program headers: 52 (bytes into file) Start of section headers: 0 (bytes into file) Flags: 0x54001005, noreorder, cpic, o32, mips16, mips32 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 7 Size of section headers: 0 (bytes) Number of section headers: 0 Section header string table index: 0 There are no sections in this file. There are no sections to group in this file. </code></pre>
1763
2013-04-14T12:43:55.180
<p>When reversing a router firmware based on DD-WRT I came across a mention of "webcomp". It seems it's used for storing internal HTML files for the web interface. What exactly it is and how can I extract those files from the firmware image?</p> <p>NOTE: This is a self-asked and answered question to add to the knowledge based.</p>
What is "webcomp" and how does it work?
|linux|firmware|webcomp|
<p>Data Interleaving is a term I made up to reflect an idea I've been contemplating lately; interleaving the bits of a set of variables into a single binary blob. Any number and types of variables could be interleaved together. Access to variables in the interleaved blob can even be on-demand, with a controller class encoding or decoding variables on the fly.</p> <h2>What in the World?</h2> <p>Data Interleaving is the process of translating any number of variables to a single binary blob by interleaving the bits of the variables. This obfuscates the variables in memory or external storage. The entire blob need not be decoded to access member variables, though it can be for improved performance.</p> <h2>Why?</h2> <p>This will help complicate reverse engineering of code. It will particularly deter identifying data types and variables. Plaintext is also well obfuscated with this interleave.</p> <h2>Interleave Map</h2> <p>The variables to be encoded could be defined by an array of byte sizes of those variables and, optionally, pointers to a location in memory to retrieve or store their reconstituted form. In the case of on-demand access to an interleaved blob, individual variables can be decoded and re-encoded on the fly, so buffers for reconstituted storage are optional (though they may be temporarily reconstituted by the controller class as members are modified).</p> <p>The members of the bitwise interleave can be referenced in the source code via their indices. For instance, index 0 may be MY_VARIABLE_INSTANCE. By passing the variable index to an interleave blob controller class, it knows the size and, optionally, a pointer for constituted storage.</p> <p>Member data types can be anything. They need not be similar. When one variable ends, it is simply ended. See a few paragraphs below for what happens when a single variable is longer than the others.</p> <pre><code>/* member information */ /* optional pointer to its normal, constituted storage location */ /* (for use in encoding and decoding the member) */ /* and the size of the member */ class CInterleaveMember { void *pvConstitutedStore; unsigned long nMemberByteSize; }; /* INTERLEAVE MAP */ CInterleaveMember aInterleaveMap[] { szSomeString, sizeof(szSomeString) }, { &amp;nIntegerMan, sizeof(nIntegerMan) }, { &amp;cMyClass , sizeof(cMyClass) }; void *pBLOB; /* interleaved data stored in a dynamically allocated blob */ </code></pre> <p>The total size of the blob need not be stored, as it is the sum of all member sizes in the interleave map. The interleave map provides everything we need to know.</p> <h2>The Process</h2> <p>In case it is not clear, the process for the interleave would go something like this: The array of members is 'walked', putting or getting the current bit index from each member variable, advancing to the next bit index after the entire array has been walked. When a member variable is full of bits (exhausted), it is skipped in subsequent interleave iterations (more on long vars later).</p> <p>For simplicity, let me define a few variables in bits only (not matching above):</p> <pre><code>szSomeString 0 1 1 1 0 0 1 0 nIntegerMan 1 1 1 0 0 0 1 1 1 0 0 1 0 0 0 1 cMyClass 0 0 0 1 </code></pre> <p>For the interleave, a bit is taken from each variable in succession.</p> <pre><code>First iteration of the interleave, get first bit from each ... 0 1 0 Next iteration(s), get the next bit from each ... 0 1 0 1 1 0 0 1 0 1 1 0 1 1 0 ... </code></pre> <h2>When a Member is Longer than the Others</h2> <p>In the case where one variable is much longer than the others, thus having no pair to encode with, one could use a simple XOR, and/or toss in redundant, unused data from the prior members. Any number of strategies are possible to prevent plaintext storage in the case of an abnormally long variable not having an interleave partner for its ending bits.</p> <h2>Sample Code</h2> <p>For example, the following pseudo-code represents this algorithm:</p> <pre><code>/* PROTECTED VARIABLES */ /* These get stored in an bitwise interleave in the binary blob */ char szSomeString = "Is there anybody out there?"; unsigned long nIntegerMan = 0x9090; MyClass cMyClass("whoopie"); class CInterleaveMember { void *pvConstitutedStore; unsigned long nMemberByteSize; }; /* INTERLEAVE MAP */ CInterleaveMember aInterleaveMap[] { szSomeString, sizeof(szSomeString) }, { &amp;nIntegerMan, sizeof(nIntegerMan) }, { &amp;cMyClass , sizeof(cMyClass) }; /* NOTE: Total size of the resultant bitwise interleave is the sum of the members of a Interleave Map */ /* INTERLEAVE REFS */ typedef enum { _szSomeString=0, _nIntegerMan, _cMyClass, } InterleavedVariables; void *pBinaryBlob; /* dynamically allocated blob storage */ /* Fictional class constructor, passing the interleave map to it */ /* From the interleave map, it can calculate the total blob size, */ /* then dynamically allocate storage for the blob. */ CBitInterleaver cBitInterleave(aInterleaveMap); /* If the blob is externally loaded, or needs externally stored, we */ /* may need to get access to the blob buffer. Fictional example: */ /* We know the blob size from map! The input size is for safety. */ cBitInterleave.SetBlob(pIncomingBlob, nSrcBufferSize); /* Or we can get the blob */ nBlobSize=cBitInterleave.GetBlob(ppOutgoingBlob); /* Example to encode or decode the entire blob to constituted */ /* storage. We already provided the map, and it decodes or encodes */ /* to the listed pointers. cBitInterleave.EncodeBlob(); cBitInterleave.DecodeBlob(); /* Example call to decode a member of the array */ /* We pass it the INDEX into the MAP, and dest buffer */ /* From the Index of _nIntegerman, we ALREADY know the size */ /* The out size is for safety. */ cBitInterleave.GetVariable(_nIntegerMan, &amp;nIntegerMan, sizeof(nIntegerMan)); /* OR we can use the default storage address in the interleave map */ cBitInterleave.GetVariable(_nIntegerMan); /* Example call to encode a member of the array */ /* We pass it the INDEX into the MAP, and input reference */ cBitInterleave.SetVariable(_szSomeString, &amp;szSomeString, sizeof(szSomeString)); /* And so on... I'm literally coding this in this answer, like a fool */ </code></pre>
1766
2013-04-14T17:16:43.087
<p>What is data interleaving? Is this something I can use to obfuscate collections of variables?</p>
What is Data Interleaving?
|obfuscation|
<h2>Definition</h2> <p>We'll define a packer as an executable compressor. </p> <p>Packers reduce the physical size of an executable by compressing it. A decompression stub is usually then attached, parasitically, to the executable. At runtime, the decompression stub expands the original application and transfers control to the <em>original entry point</em>.</p> <p>Packers exist for almost all modern platforms. There are two fundamental types of packers:</p> <ul> <li><strong>In-Place (In Memory)</strong></li> <li><strong>Write To Disk</strong></li> </ul> <p><strong>In-Place</strong> packers do what is termed an in-place decompression, in which the decompressed code and data ends up at the same location it was loaded at. The decryption stub attached to these compressed executables transfer control to the original application entry point at runtime, after decompression is complete. </p> <p><strong>Write to Disk</strong> packers have a decryption stub (or entire module) that, at runtime, write the decompressed application out to the file system, or a block of memory, then transfer control to the original application via execution of the application's code via normal API calls.</p> <h2>Uses</h2> <p>The original intention of executable compressors was to reduce storage requirements (size on disk), back when disk space was at a premium. They can also lower the network bandwidth footprint for transmitted compressed executables, at least when the network traffic would not otherwise be compressed.</p> <p>These days, there is no premium on disk space, so their use is less common. They are most often used as part of a protection system against reverse engineering. Abuse is also, sadly, common.</p> <h2>Abuse</h2> <p>Some packers are abused by malware authors in an attempt to hide malware from scanners. Most scanners can scan 'inside' (decompress) packed executables. Ironically, use of packers on malware is often counter-productive as it makes the malware appear suspicious and thus makes it subject to deeper levels of analysis.</p> <h2>Additional Features</h2> <p>Additional features such as protection from reverse engineering can be added to the packer, making the packer also a protector. The process of compression is itself a form of obfuscation and abstraction that inherently serves as some protection.</p>
1779
2013-04-15T11:36:23.980
<p>I know the basic principle of a packer. Basically, it is a small routine launched at the beginning of the program that decompress the actual program and jump to it once achieved.</p> <p>Yet, it seems that there are quite a lot of variations around this principles. I recently learned about "<em>virtualized packers</em>" or "<em>on-the-fly packers</em>", and I might miss a lot. So, can somebody define what a basic packer is and then explain what are the different types that can be encountered ?</p>
What are the different types of packers?
|obfuscation|malware|packers|
<p>If you aren't afraid to get your hands dirty, on Windows you could always write a filter driver on top of or below the device object for the dongle. The <a href="http://msdn.microsoft.com/en-us/library/windows/hardware/ff548294.aspx" rel="nofollow"><code>IoAttachDevice()</code></a> function and the three other functions starting with that name are your friend. The advantage of that is to have a complete in-software solution for the problem without the expenses involved with hardware sniffers. You'll notice that this is actually what the USBpcap project does in <a href="https://github.com/desowin/usbpcap/blob/master/USBPcapDriver/USBPcapFilterManager.c" rel="nofollow"><code>USBPcapFilterManager.c</code></a>. So if you are merely writing this for research, this would be a good starting point, unless the GPL is too restrictive for you.</p> <p>There is a potential downside with in-software solutions. A filter driver will only see what the other drivers want it to see. Keep in mind that in Windows kernel mode all drivers have the same privileges. Even attaching to the root hub may not always yield meaningful results. So if one driver decides to do funny things such as stealing entry points (<a href="http://msdn.microsoft.com/en-us/library/windows/hardware/ff550710.aspx" rel="nofollow">IRP major function codes</a>) to proactively counter filtering or debugging of any kind, it becomes an arms race. Otherwise it will be the cheapest solution you can get, given you only need this to work on a particular OS.</p> <p>However, if I was you I'd first sniff the user mode traffic between the library (hook <code>DeviceIoControl</code>, <code>ReadFile</code>, <code>WriteFile</code> et al, or their native counterparts) and the driver or the library and the application that requires the dongle. Of course if the dongle poses as a HID device you'd have to look for the respective IOCTLs and decode them or hook the HID functions directly. This is the method I was using to investigate the traffic sent between a sports watch with USB connectivity and my box. I based it on <a href="https://github.com/OpenRCE/paimei" rel="nofollow">PaiMai</a> and <a href="https://github.com/OpenRCE/pydbg" rel="nofollow">pydbg</a>, because the application wasn't guarding against being debugged. If yours does, you may have to cheat a little to "convince" the application to play nicely <a href="http://newgre.net/idastealth" rel="nofollow">IDAStealth provided a few good pointers</a> (link is dead as of May 2016) how to go about.</p>
1786
2013-04-15T18:29:01.353
<p>How can I monitor a usb dongle's traffic? I would like to see how a program and its usb dongle talk to each other, if it is possible replay this traffic?</p> <p>Since I am new to this type of thing, any tutorial or tool suggestion is welcome.</p>
USB Dongle Traffic Monitoring
|tools|executable|usb|dongle|
<p>A more up-to-date answer to this question would be to suggest <a href="http://www.capstone-engine.org/" rel="nofollow">Capstone</a> library. I've used it for ARM disassembly and it's quite reliable. IMHO, It's the best open source library available. </p> <p>The library is based on LLVM's TabelGen instruction descriptions. Therefore, its ISA support is as complete as LLVM.</p>
1791
2013-04-15T22:04:52.597
<p>Are there any ARM (or other non-x86) disassemblers that decompose an instruction into its component parts in a machine-friendly structure? Ideally it would be something like <a href="http://www.cs.virginia.edu/kim/publicity/pin/docs/20751/Xed/html/" rel="noreferrer">XED</a> or <a href="https://code.google.com/p/distorm/" rel="noreferrer">distorm3</a>, which disassemble into a structure and then provide an API for querying things like "Is this a call?" "Is this a conditional branch?" etc., or getting the operands of an instruction.</p> <p>I found <a href="https://code.google.com/p/armstorm/" rel="noreferrer">armstorm</a>, but it currently only supports THUMB.</p> <p>Edit: To clarify, I'm looking for something that can be called from within another program and hopefully has liberal licensing (GPL-compatible).</p>
Are there any ARM disassemblers that provide structured output?
|tools|disassembly|arm|
<p>You might be better off looking at a generic data packer first, such as <a href="http://code.google.com/p/lz4/">LZ4</a>. It's a very simple packer written in C. There are various unpackers in several languages, too, on the same site. Jumping right into a runtime packer means lots of file format details that, really, no-one gets quite right in all cases.</p>
1792
2013-04-15T22:13:42.270
<p>There are great questions here about different types of packers and that is very interesting to me. I would like to try my hand at reverse engineering one. Since I am very new to this, I would like the source code as well.</p> <p>I am hoping that by continuously compiling and recompiling the source, I can learn to match it up in IDA Pro and gain a better understanding of both topics at once.</p> <p>I've checked out the source code for UPX but it is very complex as it handles many different platforms and types. </p> <p>Is there an open source code packer that deals exclusively with Windows executables and is <strong>very simple</strong> to understand?</p>
Is there any simple open source Windows packer?
|windows|packers|
<p>Tools like Qemu or Bochs are IMO pretty similar to DBI frameworks conceptually and they work on the entire system, including the kernel. Research efforts like <a href="http://bitblaze.cs.berkeley.edu/" rel="nofollow">BitBlaze</a> and <a href="http://dslab.epfl.ch/proj/s2e" rel="nofollow">S2E</a> have used modified versions of Qemu to trace kernel mode components for bug finding. </p> <p>The key difference, I think, is that Qemu/Bochs as whole system emulators do not present a by default view of the program under inspection as a DBI does. A DBI allows for dynamic editing of the program by default. Emulators have the primitives required to effect DBI, they can read and write memory and by extension program code, but they do not provide the API that PIN does for program modification.</p> <p>So the best I can do is, you can use Qemu to make a kernel mode DBI and others have done this, but I don't know of something more usable out of the box. </p>
1797
2013-04-15T22:27:57.460
<p>Is there anything like PIN or DynamoRIO to instrument at Kernel level? The platforms I'm more interested on are Windows and OSX.</p>
Kernel level Dynamic Binary Instrumentation
|windows|dynamic-analysis|osx|kernel-mode|instrumentation|
<p>Like many others have stated, there are many different types of professional RCE positions. I think the first step for you is to determine which aspect of RCE you would like to pursue. Getting started professionally is a lot easier if you are able to specialize in a particular area: malware, vuln research, DRM, firmware reversing for compatibility, T&amp;E, etc... If I were you, the next thing I would try to do is find my focus. I can tell you from experience that there are <strong>plenty</strong> of incident response teams looking for good malware analysts. </p>
1812
2013-04-16T23:13:49.257
<p>I'm currently a high school sophomore. I haven't really done much on the RCE of malware, I've unpacked <code>zbot</code> and <code>rbot</code>, and looked at how they work, but I can manipulate practically any game to my liking by reverse engineering it and finding out which functions I need to detour, or what addresses of code I need to patch. </p> <p>From what I've read on the <a href="http://www.reddit.com/r/ReverseEngineering/">/r/ReverseEngineering</a>, I should create a blog, but what do what do I write on the blog? Do I just detail how I hacked the game? Or must it be purely reversing of malware?</p>
How do I move from RCE being a hobby to RCE being a profession?
|career-advice|
<p>Just for completeness: one more disassembler, <a href="https://binary.ninja/">Binary Ninja</a>:</p> <p>As for now (9/26/2016) it has the following properties:</p> <ul> <li>Commercial ($99 as introductory price for personal use license)</li> <li>Handles x86, x64, ARMv7-8, MIPS and 6502 architectures</li> <li>Works on Linux, Mac OsX and Windows</li> <li>Supports PE/COFF, ELF, .NES and Mach-O</li> <li>Has python API</li> <li>Has Undo</li> <li>Has IL</li> <li>Has a lot of other cool features</li> </ul>
1817
2013-04-17T00:59:59.900
<p>Is there any disassembler (not only a live debugger) second to IDA in capabilities? IDA is wonderful, and somewhat amazing in how robust and useful it is for reversing. However, it is quite expensive to properly license. Is there <em>any</em> viable alternative, or does IDA hold the monopoly on this market?</p> <p>I don't expect an alternative to be as good as IDA, just looking for other options that may be more affordable, and useful <em>enough</em>.</p> <p>EDIT: Preferrably, multi-platform support should exist, though that's optional. MIPS, ARM, x86, and x86-64 would be nice, but a disassembler that handles any one of those is a good option to know about.</p>
Is there any disassembler to rival IDA Pro?
|tools|ida|disassemblers|
<h1>By Architecture</h1> <p><em>Generic helpers for reverse engineering of a specific architecture.</em></p> <h2>ia32</h2> <h2>amd64</h2> <h2>ARM</h2> <hr /> <h1>By Operating System</h1> <p><em>Generic helpers for reverse engineering of a specific operating system.</em></p> <h2>Windows</h2> <h2>Linux</h2> <hr /> <h1>By Compiler</h1> <p><em>Generic helpers for reverse engineering of binaries generated using a specific compiler.</em></p> <h2>Microsoft Visual Studio</h2> <h3><a href="http://www.openrce.org/downloads/details/196/Microsoft_VC++_Reversing_Helpers" rel="noreferrer">Microsoft Visual C++ Reversing Helpers</a></h3> <blockquote> <p>These IDC scripts help with the reversing of MSVC programs. One script scans the whole program for typical SEH/EH code sequences and comments all related structures and fields. The other script scans the whole program for RTTI structures and vftables.</p> </blockquote> <h2>GCC</h2> <h2>Delphi</h2> <h3><a href="http://www.openrce.org/downloads/details/61/Delphi_RTTI_script" rel="noreferrer">Delphi RTTI script</a></h3> <blockquote> <p>This script deals with Delphi RTTI structures</p> </blockquote> <h2>Borland</h2> <h3><a href="http://www.openrce.org/downloads/details/72/Borland_C++_Builder_RTTI_Support" rel="noreferrer">Borland C++ Builder RTTI</a></h3> <blockquote> <p>Borland C++ Builder Run Time Type Information (RTTI) support for IDA Pro</p> </blockquote> <hr /> <h1>By Technology</h1> <p><em>Generic helpers for reverse engineering of a technology.</em></p> <h2>COM</h2> <h3><a href="http://www.openrce.org/downloads/details/10/Com_Plugin_v1.2" rel="noreferrer">COM Plugin</a></h3> <blockquote> <p>The plugin tries to extract the symbol information from the typelibrary of the COM component. It will then set the function names of interface methods and their parameters, and finally add a comment with the MIDL-style declaration of the interface method.</p> </blockquote> <h2>Remote Procedure Call</h2> <h3><a href="http://www.openrce.org/downloads/details/186/mIDA" rel="noreferrer">mIDA</a></h3> <blockquote> <p>mIDA is a plugin for the IDA disassembler that can extract RPC interfaces from a binary file and recreate the associated IDL definition. mIDA is free and fully integrates with the latest version of IDA (5.2 or later)</p> </blockquote> <hr /> <h1>Cryptography</h1> <p><em>Generic helpers for reverse engineering of encryption and decryption algorithms.</em></p> <h2>Signature Based</h2> <h3><a href="http://www.openrce.org/downloads/details/189/FindCrypt2" rel="noreferrer">FindCrypt2</a></h3> <blockquote> <p>The idea behind it pretty simple: since almost all crypto algorithms use magic constants, we will just look for these constants in the program body. The plugin supports virtually all crypto algorithms and hash functions.</p> </blockquote> <hr /> <h1>Deobfuscation</h1> <p><em>Plugins and scripts for removing obfuscations from disassembly.</em></p> <h2>ia32</h2> <h3><a href="http://code.google.com/p/optimice/" rel="noreferrer">Optimice</a></h3> <blockquote> <p>Optimice applies common optimization techniques on obfuscated code to make it more readable/user friendly. This plugin enables you to remove some common obfuscations and rewrite code to a new segment.</p> </blockquote>
1829
2013-04-17T10:02:42.920
<p>I am just starting to use <a href="https://www.hex-rays.com/products/ida/">IDA Pro</a>. After discussing a bit with the community, it seems that IDA Pro plugins and scripts are quite important to reach a good level of productivity while analyzing a program.</p> <p>What are some <em>must have</em> plugins for IDApro that you would recommend for an everyday usage.</p>
Could you list some useful plugins and scripts for IDA Pro?
|ida|ida-plugin|
<p>I usually rebase it in IDA to <code>0</code>. Then using <code>Adv Ctr + G</code> option of StrongOD, you can just put the address from IDA as RVA to needed module.</p>
1833
2013-04-17T14:17:46.000
<p>I'm currently trying to gain some practice in RE and I need some help for patching a DLL. Here are my steps: I first analyze the main program and the dll in IDA trying to understand the logic. I then switch to OllyDBG for patching. Well, the problem is, since Olly dynamically loads the dll (in contrast to the static standalone analysis in IDA), the offsets are different and I don't know how to find the offset that I've inspected in IDA. Is there some easy way to "rediscover" the offset in the dll?</p> <p>Thanks in advance!</p>
How to find offsets in OllyDBG from IDA
|ida|ollydbg|
<p>from its <a href="http://radare.org/y/?p=features">feature</a> page:</p> <ul> <li>Multi-architecture and multi-platform <ul> <li>GNU/Linux, Android, *BSD, OSX, iPhoneOS, Windows{32,64} and Solaris</li> <li>x86{16,32,64}, dalvik, avr, arm, java, powerpc, sparc, mips, bf, csr, m86k, msil, sh</li> <li>pe{32,64}, [fat]mach0{32,64}, elf{32,64}, te, dex and java classes</li> </ul></li> <li>Highly scriptable <ul> <li>Vala, Go, Python, Guile, Ruby, Perl, Lua, Java, JavaScript, sh, ..</li> <li>batch mode and native plugins with full internal API access</li> <li>native scripting based in mnemonic commands and macros</li> </ul></li> <li>Hexadecimal editor <ul> <li>64bit offset support with virtual addressing and section maps</li> <li>Assemble and disassemble from/to many architectures</li> <li>colorizes opcodes, bytes and debug register changes</li> <li>print data in various formats (int, float, disasm, timestamp, ..)</li> <li>search multiple patterns or keywords with binary mask support</li> <li>checksumming and data analysis of byte blocks</li> </ul></li> <li>IO is wrapped <ul> <li>support Files, disks, processes and streams</li> <li>virtual addressing with sections and multiple file mapping</li> <li>handles gdb:// and rap:// remote protocols</li> </ul></li> <li>Filesystems support <ul> <li>allows to mount ext2, vfat, ntfs, and many others</li> <li>support partition types (gpt, msdos, ..)</li> </ul></li> <li>Debugger support <ul> <li>gdb remote and <strong>brainfuck</strong> debugger support</li> <li>software and hardware breakpoints</li> <li>tracing and logging facilities</li> </ul></li> <li>Diffing between two functions or binaries <ul> <li>graphviz friendly code analysis graphs</li> <li>colorize nodes and edges</li> </ul></li> <li>Code analysis at opcode, basicblock, function levels <ul> <li>embedded simple virtual machine to emulate code</li> <li>keep track of code and data references</li> <li>function calls and syscall decompilation</li> <li>function description, comments and library signatures</li> </ul></li> </ul>
1842
2013-04-18T09:34:49.823
<p><a href="http://radare.org/y/">Radare2</a> is a framework for reverse-engineering gathering several tools (see this <a href="http://www.phrack.org/issues.html?issue=66&amp;id=14#article">Phrack article</a> about radare1 to know a bit more about the framework).</p> <p>I would like to know if someone could point out the main useful features of the framework for reverse engineering ? And, particularly what makes radare2 different from other tools or frameworks ?</p>
What are the main features of radare2?
|tools|binary-analysis|radare2|
<h2 id="e9patch-et3b"><a href="https://github.com/GJDuck/e9patch" rel="nofollow noreferrer">e9patch</a></h2> <blockquote> <p>E9Patch is different to other tools in that it can statically rewrite x86_64 Linux ELF binaries without modifying the set of jump targets. To do so, E9Patch uses a set of novel low-level binary rewriting techniques, such as instruction punning, padding and eviction that can insert or replace binary code without the need to move existing instructions. Since existing instructions are not moved, the set of jump targets remains unchanged, meaning that calls/jumps do not need to be corrected (including cross binary calls/jumps).</p> </blockquote> <p><a href="https://i.stack.imgur.com/Yqb4J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yqb4J.png" alt="e9patch techniques" /></a></p> <p>Paper: <a href="https://www.comp.nus.edu.sg/%7Egregory/papers/e9patch.pdf" rel="nofollow noreferrer">Binary Rewriting without Control Flow Recovery</a></p> <h2 id="projects-based-on-e9patch-z2xw">Projects based on e9patch:</h2> <ul> <li><a href="https://github.com/GJDuck/e9afl" rel="nofollow noreferrer">e9afl</a> - inserts AFL's instrumentation into ELF binaries. I've had success using this to fuzz closed-source binaries in a production environment; however, using AFL++ with QEMU outperformed this approach.</li> <li><a href="https://github.com/GJDuck/e9syscall" rel="nofollow noreferrer">e9syscall</a> - System call interception using static binary rewriting of libc.so.</li> </ul>
1843
2013-04-18T09:43:07.177
<p>I would like to be able to rewrite or reorganize an ELF binary program directly from the executable format (not at compile-time). </p> <p>The only library I know to do this is <a href="http://hg.secdev.org/elfesteem/">elfesteem</a> (used in <a href="http://code.google.com/p/smiasm/">Miasm</a>). But, there must be others. So, what are the libraries or frameworks that you use to statically modify ELF executables ?</p>
What are the available libraries to statically modify ELF executables?
|tools|obfuscation|deobfuscation|elf|
<p>I was just sent <a href="https://www.dropbox.com/s/yj30fqj2dxxlmnj/mIDA-1.0.10.zip">mIDA-1.0.10</a>, from 2008.</p> <pre><code>mIDA is an IDA plugin which extracts RPC interfaces and recreates the associated IDL file. mIDA supports inline, interpreted and fully interpreted server stubs. </code></pre>
1849
2013-04-18T14:14:04.363
<p><a href="https://reverseengineering.stackexchange.com/questions/59/what-are-the-essential-ida-plugins-or-ida-python-scripts-that-you-use/62#62">Some posts</a> reference the <a href="http://www.openrce.org/downloads/details/186/mIDA" rel="nofollow noreferrer">mIDA</a> plugin, but the download site seems unavailable. Is there any mirror or a link to an archive version?</p>
where can I get mIDA
|ida|ida-plugin|
<p>My answer is a little late; newcomer to this site. The Decompiler project was initiated in order to decompile MS-DOS EXE and COM binaries. The project has both a command-line and a GUI tool:</p> <p><a href="https://sourceforge.net/projects/decompiler/" rel="nofollow">https://sourceforge.net/projects/decompiler/</a></p> <p>Use the following command with the command-line tool to decompile COM programs:</p> <pre><code>decompile --default-to ms-dos-com myprog.com </code></pre> <p>In the GUI, use the menu command <code>File</code> > <code>Open as...</code> to open the COM file and specify a start address like 0800:0100.</p>
1854
2013-04-18T20:07:52.410
<p>What can I do to reverse engineer a DOS .COM file? As far as debugging goes, I've looked DEBUG and DEBUGX from the creators of FreeDOS, as well as the default DEBUG command that comes with Windows. Sure, I can probably work with them and eventually figure out what I'm doing, but I feel like the process would end up being longer than necessary. Is there a better tool I can use?</p> <p>If there are no "better" tools than DEBUG or DEBUGX, then what can I use to work with output from these two tools? My main goal is to create something that mimics the .COM program, but in a more manageable format (as far as code goes).</p>
Working with DOS .COM files
|tools|windows|dos-com|
<p>If you think the encoding is wrong then you can try these 2 things:</p> <ul> <li>Try using <code>x/hs</code> <a href="http://sourceware.org/gdb/onlinedocs/gdb/Memory.html">as described here</a></li> </ul> <blockquote> <p>Each time you specify a unit size with x, that size becomes the default unit the next time you use x ... Use x /hs to display 16-bit char strings</p> </blockquote> <ul> <li>set the character set in gdb <a href="http://sourceware.org/gdb/onlinedocs/gdb/Character-Sets.html">as described here</a></li> </ul> <blockquote> <p>gdb has no way to automatically recognize which character set the inferior program uses; you must tell it, using the set target-charset command, described below.</p> </blockquote>
1860
2013-04-19T04:02:20.333
<p>Are there any useful snippets or Gdb functions that you guys normally use to print out Unicode strings? I'm trying to debug Mach-O binaries and <code>x/s</code> seems to be printing out junk. I believe the default encoding for Objective C strings is UTF-16.</p>
Printing Unicode strings in Gdb in OSX
|osx|gdb|encodings|mach-o|strings|
<p><a href="http://rammichael.com/multimate-assembler" rel="nofollow noreferrer"><strong>Multiline Ultimate Assembler</strong></a> is a multiline (and ultimate) assembler (and disassembler) plugin for OllyDbg. It’s a perfect tool for modifying and extending a compiled executable functionality, writing code caves, etc.</p>
1869
2013-04-19T18:45:39.290
<p>I'm working with some x86 assembly code and I need to rip from one executable and paste that code into another.</p> <p>Originally, I had an executable that was meant to accept two command line parameters and run a handwritten function on them. However, I ran into annoyances with using <code>GetCommandLine</code> et al. to return the parameters in my ASM. Namely, it returned Unicode and I needed the parameters in ANSI. Rather than dealing with setting up the library calls and converting that way, I compiled a small program that uses command line arguments with the intent of reusing code.</p> <p>So now I have two executables:</p> <ul> <li>one with the command line parameters parsed and in their proper places</li> <li>two with the actual assembled function code inside of it.</li> </ul> <p>The first executable has the space for the function <code>NOP</code>'d out, but I need a good way to paste the logic in. I've looked at Asm2clipboard, Code Ripper and data ripper, but they only have the functionality to rip the assembly out, but not paste it back in.</p> <p>I'm aware I'll have to fix addresses and things like that, but I can't find a way in Olly or other tools to move the code between the executables. I can go into HexEdit or something like that I supposed, but I was hoping there's an easier way.</p>
Ripping/pasting code into an executable using Olly
|disassembly|pe|ollydbg|patching|
<p>I had the same problem at first when trying to connect <code>IDAPro</code> to <code>windbg</code>. What I did was the following:</p> <ol> <li>Manually edit the <code>ida.cfg</code> file located inside <code>.\IDA 6.4\cfg\ directory</code>.</li> <li><p>Change the <code>DBGTOOLS</code> path with WinDbg tools directory. For example, to:</p> <pre><code>DBGTOOLS = "C:\\Program Files (x86)\\Windows Kits\\8.0\\Debuggers\\x86\\"; </code></pre></li> </ol>
1873
2013-04-20T06:01:15.870
<p>Environment:</p> <ul> <li>Host: Win7 SP1 x64: VMWare Workstation 9.02, VirtualKD, IDA Pro 6.4.13 (x64) and WinDbg</li> <li>Guest: Win7 SP1 x64</li> </ul> <p>I have VirtualKD setup correctly in my guest and host. I say this because attaching WinDbg to the guest VM through VirtualKD works flawlessly.</p> <p>But when I try to connect IDA Pro's WinDbg interface using instruction on <a href="http://www.hexblog.com/?p=123" rel="noreferrer">this page</a>, IDA keeps throwing the following error:</p> <pre><code>Windbg: using debugging tools from '&lt;PATH&gt;' Connecting to debugger server with 'com:port=\\.\pipe\kd_Win7x64_SP1,pipe' Connect failed: The server is currently disabled. </code></pre> <p>VirtualKD's <code>vmmon</code> is running on the host and shows the following:<img src="https://i.stack.imgur.com/SFqc3.png" alt="vmmon UI"></p> <p><strong>UPDATE:</strong> Turns out, It's a problem with IDA 6.4. I happened to have IDA 6.3 installed on my machine too. That worked with no issues. Has anyone used IDA6.4 for live kernel debugging? Can someone please tell me how I can correct this issue <em>in IDA 6.4</em>?</p>
WinDbg fails to connect to IDA Pro debugger server
|windows|ida|debuggers|kernel-mode|windbg|
<p>After a little bit more work and some more careful re-reading, I figured out my mistake: the files in <code>/data/app-asec/</code> are the encrypted <em>containers</em>. They're actually dm-crypt volumes, which then get mounted at <code>/mnt/asec/[app_id]</code>. The <code>pkg.apk</code> in that directory is the unencrypted apk that can be analyzed using any of the fine tools in <a href="https://reverseengineering.stackexchange.com/a/46/257">this answer</a>.</p>
1876
2013-04-21T03:48:04.687
<p>I've been trying to reverse engineer a paid android app that writes out some binary data so that I can export that data into other programs (it's a run/walk timer app, if anyone's curious, and I'm trying to get its GPS traces out). However, it looks like the apk is encrypted and stored in <code>/data/app-asec/[app_id].asec</code>.</p> <p>There's a nice <a href="http://nelenkov.blogspot.com/2012/07/using-app-encryption-in-jelly-bean.html">blog post</a> that says the encryption used is TwoFish, with a key stored in <code>/data/misc/systemkeys/AppsOnSD.sks</code>, but I haven't been able to decrypt the file using the naïve strategy of just using that key directly with TwoFish on the <code>.asec</code>.</p> <p>How can I decrypt this to get an apk I can actually analyze?</p> <p>Note: I realize that this information is considered somewhat delicate in places like xda-developers, since it could be used to enable piracy. I have no such intentions, I just want to examine the serialization code.</p>
Analyzing encrypted Android apps (.asec)?
|android|encryption|
<p>As an open source alternative there's <a href="https://github.com/noseglasses/elf_diff" rel="nofollow noreferrer">elf_diff</a> which compares elf-files and generates html or pdf reports. It's available as a Python package.</p>
1879
2013-04-21T13:57:12.093
<p>I'm looking for a tool like <code>Beyond Compare</code>, <code>meld</code>, <code>kdiff</code>, etc. which can be used to compare two disassembled binaries. I know that there's binary (hex) comparison, which shows difference by hex values, but I'm looking for something that shows op-codes and arguments.</p> <p>Anyone knows something that can help ?</p>
how can I diff two x86 binaries at assembly code level?
|tools|binary-analysis|bin-diffing|
<p><a href="http://www.openwatcom.org/">OpenWatcom</a> has full support for Win16 including debugging, though I personally haven't tried it. It even has remote debugging support over TCP/IP, serial and a couple other protocols.</p> <p>Older SoftICE versions also supported Win16, you may try your luck with that.</p>
1891
2013-04-22T09:49:45.830
<p>I'm trying to debug a 16-bit Windows executable (format: New Executable). The problem is that all the standard tools (W32DASM, IDA, Olly) don't seem to support 16-bit debugging.</p> <p>Can you suggest any win16-debuggers?</p>
Debugging NewExecutable binaries
|tools|debuggers|ne|
<p>A '<em>side-channel attack</em>' define any technique that will consider unintended and/or indirect information channels to reach his goal. It has been first defined in smart-card cryptography to describe attacks which are using unintentional information leak from the embedded chip on the card and that can be used in retrieval of keys and data. For example, it may be used by monitoring:</p> <ul> <li><p><strong>Execution Time</strong> (Timing attack): To distinguish which operations has been performed and guess, for example, which branch of the code has been selected (and, thus, the value of the test).</p> </li> <li><p><strong>Power Consumption</strong> (Power monitoring attack): To distinguish precisely what sequence of instructions has been performed and be able to recompose the values of the variables. Note that there exist several techniques of analysis using the same input but with slightly different way of analyzing it. For example, we can list: <em>Single Power Analysis</em> (SPA), <em>Differential Power Analysis</em> (DPA), <em>High-order Differential Power Analysis</em> (HO-DPA), <em>Template Attacks</em>, ...</p> </li> <li><p><strong>Electromagnetic Radiation</strong> (Electromagnetic attacks): Closely related to power consumption, but can also provide information that are not found in power consumption especially on RFID or NFC chips.</p> </li> </ul> <p>If you're more interested in learning how to leverage this information then I'd suggest to start by reading <a href="https://rads.stackoverflow.com/amzn/click/com/1441940391" rel="nofollow noreferrer" rel="nofollow noreferrer">Power Analysis Attacks</a>. Don't get 'scared' away by the fact that the book is about smart cards. Most of the information also applies 1-to-1 on 'normal' (SoC) embedded devices.</p> <p>Forgot to mention there's an open source platform called <a href="http://sourceforge.net/projects/opensca/" rel="nofollow noreferrer">OpenSCA</a> and some open source hardware called FOBOS (Flexible Open-source BOard for Side-channel) for which I can't seem to find a proper link from home.</p> <h2>Application to Software Reverse-engineering</h2> <p>Speaking about the application of side-channel attacks in software reverse engineering now, it is more or less any attacks that will rely on using unintended or indirect information leakage. The best recent example is this <a href="http://shell-storm.org/blog/A-binary-analysis-count-me-if-you-can/" rel="nofollow noreferrer">post</a> from <a href="https://twitter.com/JonathanSalwan" rel="nofollow noreferrer">Jonathan Salwan</a> describing how he guessed the password of a crackme just by counting the number of instructions executed on various inputs with <a href="http://software.intel.com/en-us/articles/pin-a-dynamic-binary-instrumentation-tool" rel="nofollow noreferrer">Pin</a>.</p> <p>More broadly, this technique has been used since long in software reverse-engineering without naming it, or could have improved many analysis. The basic idea is to first consider that if a piece of software is too obscure to understand it quickly, we can consider it as a black-box and think about using a side-channels technique to guess the enclosed data through a guided trial and error technique.</p> <p>The list of side-channels available in software reverse-engineering is much longer than the one we have in hardware. Because it enclose the previous list and add some new channels such as (non exhaustive list):</p> <ul> <li><p><strong>Instruction Count</strong>: Allow to identify different behaviors depending on the input.</p> </li> <li><p><strong>Read/Write Count</strong>: Same as above, with more possibilities to identify patterns because it includes also instruction read.</p> </li> <li><p><strong>Raised Interrupt Count</strong>: Depending on what type of interrupt is raised, when and how, you might identify different behaviors and be able to determined the good path to your goal.</p> </li> <li><p><strong>Accessed Instruction Addresses</strong>: Allow to rebuild the parts of the program that are active at a precise moment.</p> </li> <li><p><strong>Accessed Memory Addresses</strong>: Allow to rebuild data pattern or complex data-structure stored or accessed in memory (eg. in the heap).</p> </li> </ul> <p>This list is far from being exhaustive, but basically tools such as Valgrind VM or others can be used to perform such analysis and quickly deduce information about the behavior of a given program, thus speeding up the reverse-engineering.</p> <h2>Obfuscation and Possible Counter-measures</h2> <p>Trying to build a software which will be resistant to such attacks will borrow also a lot from the smart-card industry. But, not only. Here are a few tricks, I could think of (but far from being complete about all we can find).</p> <h3>Armoring Program Branches</h3> <p>The instruction count is extremely efficient to detect which branch has been taken in code like this:</p> <pre><code>if (value) ret = foo(); else ret = bar(); </code></pre> <p>With <code>foo()</code> and <code>bar()</code> having different instruction count.</p> <p>This can be defeated by executing <code>foo()</code> and <code>bar()</code> whatever <code>value</code> is and deciding afterward what is the value of <code>ret</code>.</p> <pre><code>tmp_foo = foo(); tmp_bar = bar(); if (value) ret = tmp_foo; else ret = tmp_bar; </code></pre> <p>This technique render your program much more difficult to guess from a side-channel attack, but also much less efficient. One has to find a proper trade-off.</p> <h3>Countering Timing Attacks</h3> <p>Timing attacks are extremely easy to perform and difficult to workaround because <code>sleep()</code> cannot be an option (too easy to detect in a code and, anyway you cannot assume a specific speed for the processor). The programmer has to identify the execution time of each branch of his program and to <em>balance</em> each branch with extra non-useful operations which are of the same computational power than the ones from the other branchs. The point being to render each branch indistinguishable from the others only based on the execution time.</p> <h3>Threading Madness</h3> <p>Another way to dilute the side-channel is to massively multi-thread your program. Imagine that each branch of your program is executed in a separate thread, and one variable tell in which thread the current program really is (if possible in a cryptic manner). Then side-channel analysis will be much more difficult to perform.</p> <h2>Conclusion and Further Research</h2> <p>Side-channel attacks has been widely under-estimated for software reverse-engineering, it can drastically speed-up the reverse of many programs. But, in the same time, obfuscation techniques exists and have to be developed specifically targeting software reverse-engineering. So, don't be surprised if you see more and more novelties related to this field.</p>
1897
2013-04-22T19:24:31.780
<p>When reversing smart-cards, the <a href="http://en.wikipedia.org/wiki/Side_channel_attack" rel="nofollow">side-channel attacks</a> are known to be quite effective on hardware. But, what is it, and can it be used in software reverse-engineering and how?</p>
What is SCARE (Side-Channel Attacks Reverse-Engineering)?
|hardware|physical-attacks|smartcards|
<h3>Fault Injection Attacks</h3> <p>Basically, we assume here that we have a black-box that produces an output using a known algorithm but with some unknown parameters. In the case of cryptography, the black-box could be a chip on a smart-card, the know algorithm could be a cryptographic algorithm and the unknown parameters would be the key of the algorithm which lies hidden in the chip (and never go out).</p> <p>In this particular setting, we can perform what we call a '<em>chosen clear-text attack</em>', meaning that we can choose the inputs of the black-box and look at the output. But, lets also suppose that this is not enough to guess the unknown parameters (the key). So, we need a bit more to help us.</p> <p>Our second assumption will be that we are able to introduce errors at specific chosen phase of the known algorithm. Usually, when speaking about smart-cards, it means that we have a physical setup with a very precise timer linked to the smart-card clock and a laser targeting a physical register on the chip. Beaming up the register with the laser, usually reset the register (or may introduce some random values).</p> <p>The point of fault-injection is thus to study the effect of the injected fault on the cipher algorithm and to deduce some information about the value of the key.</p> <p>Depending on the cipher algorithm used in the chip, the most interesting bits to reset in order to maximize the information collected about the key may vary a lot because the propagation of the error is not the same depending on the computation performed. So, each cipher algorithm need to be studied first, in order to know the best way to proceed in order to extract the key.</p> <h3>Types of Fault-injection Attacks</h3> <p>The different types of fault-injection analysis depends mainly on the accuracy with which you can control the error that you introduce (from the easiest to the most difficult):</p> <ul> <li><strong>Fully controlled error</strong>: We suppose that we have a full control on the error. Basically, we can choose what is the content of the register and when to introduce the error in the algorithm.</li> <li><strong>Known error</strong>: We suppose that we have a partial control on the error. Meaning that we know where it has been introduced and we know what is written in the register but we cannot choose it in advance.</li> <li><strong>Unknown error</strong>: We know exactly where, in the algorithm, the error has been introduced but we cannot control what is written nor have a knowledge of what has been written in the register.</li> <li><strong>Fully uncontrolled error</strong>: We have no exact knowledge of what is written nor when it has been introduced in the algorithm.</li> </ul> <h3>Counter-measures</h3> <p>Countering fault-injection is, in fact, quite easy but costly. You only need to duplicate the circuits and check that the two circuits gives the same output when finished. If not, you just have to issue an error without leaking any information.</p> <p>Of course, in the case of a '<em>fully controlled error</em>' attack, one can just duplicate the laser beam as well. But, usually, the '<em>fully controlled error</em>' attack is an ideal case that is almost never reached in practice.</p> <p>More difficult to work around, in the case of the '<em>known error</em>' attack, you can use the output of the chip (<code>output</code> / <code>error</code>) to guess the content of any register you want. You just need to perform attacks always on the same input until you get a normal <code>output</code>, then you can store what you wrote on the register. And, thus, rebuild the value of the key.</p> <p>Anyway, the cost of circuit redundancy on a chip is quite high, both in money and power-consumption. So, not all the chips can be equipped with this.</p> <h3>Other Related Attacks and Conclusion</h3> <p>These attacks have to be compared (or combined) with '<em>side-channel attack</em>'. Both attacks have a different approaches and use different assumptions on what is possible or not. Combining them allow to get way further in extracting information about the device that you study.</p> <p>Talking now about <strong>software reverse engineering</strong>, I do not know any practical use of fault injection attack nowadays. But, I'm pretty confident that you can use this technique to guess the parameters of a know algorithm that has been obfuscated without having to dissect it in details. Somehow, any debugger can rewrite a register at precise time in the program (breakpoints) with a full control of what is written in the register (we are here in the case of the '<em>fully controlled error</em>' attack). So, this can certainly be used in the case of usual obfuscated programs.</p>
1898
2013-04-22T19:32:17.807
<p>Trying to extract data from the hardware is often quite difficult (especially when dealing with smartcards). Fault-injection attacks allow to guess cryptographic keys based on the propagation of errors through the encryption/decryption algorithm. I know some of the types of fault-injections possible, but not all.</p> <ul> <li>What are the different types of fault-injections possible?</li> <li>Do the different types of techniques offer any special advantages?</li> </ul>
What is fault-injection reverse engineering? What are the techniques involved?
|hardware|physical-attacks|smartcards|
<p>None of the answers so far answer the actual question so here goes.</p> <p>A debugger plugin differs from a "normal" one in two points:</p> <ol> <li>it has <code>PLUGIN_DBG</code> in the plugin's flags.</li> <li>in init(), it must set the global variable <code>dbg</code> to a pointer to an implementation of <code>debugger_t</code> structure. See <code>idd.hpp</code> for the definition.</li> </ol> <p>For examples, see <code>plugins/debugger</code> in the SDK, and also the recently updated <a href="https://github.com/wjp/idados"><code>idados</code> plugin</a>. Warning: making debugger plugins is not for the faint of heart.</p>
1899
2013-04-22T19:50:47.310
<p>Are there any good resources for developing debugger plugins in IDA Pro using the SDK that describe the IDA debugger API? An example of this is the <a href="http://sourceforge.net/projects/idaproarmdebug/">IDA Pro ARM debugger plugin</a> on Sourceforge. There seem to be few projects that have accomplished this. Specifically, how do you make a plugin in IDA which registers itself as one of the available debuggers and allows stepping through the IDA database while controlling a target? </p>
Creating IDA Pro debugger plugins - API documentation and examples?
|ida|debuggers|ida-plugin|
<p>One of things I do is to read the machine code and translate it back into IR pseudo opcodes sans any addressing address values, and then perform differences between those two pseudo-IR binaries after using this reduction method on each. </p>
1902
2013-04-22T21:30:23.277
<p>How comes that text diffing tools like <code>diff</code>, <code>kdiff3</code> or even more complex ones usually fail at highlighting the differences between two disassemblies in textual form - in particular two <em>related</em> binary executable files such as different versions of the same program?</p> <p>This is the question <a href="https://reverseengineering.stackexchange.com/users/107/gilles">Gilles</a> asked <a href="https://reverseengineering.stackexchange.com/questions/1879/">over here</a> in a comment:</p> <blockquote> <p>Why is diff/meld/kdiff/... on the disassembly not satisfactory?</p> </blockquote> <p>I thought this question deserves an answer, <a href="http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/">so I'm giving an answer Q&amp;A style</a>, because it wouldn't fit into a 600 character comment for some strange reason ;)</p> <p><strong>Please don't miss out on <a href="https://reverseengineering.stackexchange.com/a/1907/245">Rolf's answer</a>, though!</strong></p>
Why are special tools required to ascertain the differences between two related binary code files?
|tools|disassembly|assembly|bin-diffing|
<p>From <a href="https://www.hex-rays.com/products/ida/6.4/index.shtml">IDA 6.4 news</a>:</p> <pre><code>+ SDK: added extra_cmt_changed IDB event for the anterior/posterior comment changes; also renamed the SDK functions related to these comments </code></pre>
1906
2013-04-22T23:19:41.360
<p>IDA Pro allows plugins to receive notifications for a number of events. These are defined in the <code>hook_type_t</code> enumeration inside <code>loader.hpp</code> in the SDK from what I saw. If I subscribe to <code>HT_IDB</code> events, I have a host of options for notifications I can subscribe to (<code>event_code_t</code> in <code>idp.hpp</code>).</p> <p>Now, if I wanted to patch up <a href="http://sourceforge.net/projects/collabreate/" rel="nofollow">collabREate</a> by Chris Eagle to support anterior and posterior comments - how would I go about that?</p> <p>colleabREate is a very useful piece of software, but in real collaboration scenarios these issues turn out to be real shortcomings.</p> <p><strong>In short: how can I receive notifications to events in my plugin which Hex-Rays doesn't make available through the SDK as of yet?</strong></p>
How can my plugin get notified of anterior or posterior comments (and more) changes to an IDA database?
|ida|ida-plugin|idapro-sdk|
<p>You can also position your cursor in one of the code, hex-view, or stack view windows, and press 'g' to bring up the "jump to address" dialog.</p>
1909
2013-04-23T07:21:57.103
<p>This is a very naive question about IDA Pro. Once the IDA debugger started, I would like to be able to type a memory address (or a memory zone) and look easily at the content of it (in various format). With <code>gdb</code> you would do <code>print /x *0x80456ef</code> or, if you want a wider zone, <code>x /6x 0x80456ef</code>.</p> <p>So, what is the best way to display the memory content from the IDA debugger ?</p>
How to display memory zones content on IDA Pro?
|tools|ida|
<h1>TL;DR</h1> <ol> <li><p>the first 3 lines set an exception handler (an 'error catcher')</p></li> <li><p>the <code>int3</code> generates an exception</p></li> <li><p>execution resumes at <code>next</code></p></li> </ol> <hr> <h1>Explanation</h1> <p>this trick is (ab)using <a href="http://www.microsoft.com/msj/0197/exception/exception.aspx" rel="noreferrer">Structured Exception Handling</a>, a mechanism to define exception handlers, typically by compilers when <code>try</code>/<code>catch</code> blocks are used.</p> <p>In 32bits versions of Windows, they can be set on the fly, without any pre-requirement (unless the binary is compiled with /SafeSEH).</p> <p>The first element of the exception handlers' chain is pointed by the first member of the <a href="http://en.wikipedia.org/wiki/Win32_Thread_Information_Block" rel="noreferrer">Thread Information Block (TIB)</a>, in turn a member of the <a href="http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/NT%20Objects/Thread/TEB.html" rel="noreferrer">Thread Environment Block (TEB)</a>, which is pointed to by <code>fs:0</code> (which is also reachable 'directly' - via something like <code>ds:7efdd00</code>, depending on the OS version etc)</p> <p>So here is what happens:</p> <ol> <li><p>the first two <code>push</code> reserve stack space for the structure <code>_EXCEPTION_REGISTRATION_RECORD</code>.</p> <ol> <li>the new top handler</li> <li>the previous top handler, which was until now at <code>fs:[0]</code></li> </ol></li> <li><p>the <code>mov</code> sets the current stack position as the new structure. When an exception happens, <code>next</code> will be now the first called handler.</p></li> <li><p><code>int3</code> triggers an exception instantaneously (there are many other kinds of <a href="http://seh.corkami.com" rel="noreferrer">exception triggers</a>).</p></li> <li><p>as an exception is triggered, Windows dispatches the exception to the first handler, and the next one if it's not handled, until one of them has handled it.</p></li> </ol> <p><img src="https://raw.githubusercontent.com/angea/wiki_old/master/pics/seh_flowchart.png" alt="flowchart of Exception handling"></p> <h1>Following execution</h1> <p>This is done here under OllyDbg 1.10. YMMV.</p> <p>As we want to go through exceptions ourselves, we have to ask OllyDbg not to handle them:</p> <ol> <li><p>go to debugging options: <kbd>Alt</kbd>-<kbd>O</kbd>, tab <code>Exceptions</code></p></li> <li><p>unselect <code>INT3 breaks</code></p></li> </ol> <p>And when an exception is triggered, we have to enforce that execution is done via exceptions (see below).</p> <p>Here are 3 methods of increasing level to follow the exception handling execution safely:</p> <h2>step by step: set a breakpoint manually</h2> <p>As the handler has just been set on the stack, you can manually set a breakpoint then run.</p> <ol> <li><p>select the new handler address on the stack</p> <p><img src="https://i.stack.imgur.com/QQQOQ.png" alt="new handler on the stack"></p></li> <li><p>Right-click or <kbd>F10</kbd></p> <ul> <li>select <code>Follow in Dump</code></li> </ul></li> <li><p>in the dump window, open the menu (same shortcut)</p> <ul> <li>select <code>BreakPoint</code>, then <code>Hardware, on execution</code></li> </ul></li> <li><p>Execute: menu <code>Debug/Run</code> / shortcut <kbd>F9</kbd> / command-line <code>g</code></p></li> <li><p>Exceptions will be triggered</p></li> <li><p>Execute with exception handling: shortcut <kbd>Shift</kbd>-<kbd>F9</kbd> / command-line <code>ge</code>.</p></li> </ol> <h2>shortcut: execute until exception handler via command-line</h2> <ul> <li><p>as the address is on the stack, the easiest way is to type via the command line <code>ge [esp+4]</code>, which means, <code>Go with Exceptions</code>, until the 2nd address on the stack is encountered. Thus, no need to set and unset a breakpoint.</p> <ul> <li>in the case of a more complex example, where the address might not be obvious on the stack anymore, then the absolute formula would be <code>ge ds:[fs:[0]+4]</code>, which just gets the actual address from the TIB.</li> </ul></li> </ul> <h2>keeping full control: break on <code>KiUserExceptionDispatcher</code></h2> <p><code>KiUserExceptionDispatcher</code> is the Windows API handling all user-mode exceptions. Setting a breakpoint there guarantees that you keep full control - but then, you're in the middle of a Windows API ;) </p> <p>In this case, you can ask OllyDbg to skip exceptions, as you will still break execution manually in any cases. You might also want to combine that with a <a href="http://tuts4you.com/download.php?list.53" rel="noreferrer">script</a>.</p> <p>Of course, some advanced code might check that you set a breakpoint on it before triggering an exception.</p>
1911
2013-04-23T12:31:29.360
<p>In a 32 bits Windows binary, I see this code:</p> <pre><code> push next push fs:[0] mov fs:[0], esp int3 ... next: </code></pre> <p>I see that something happens on the <code>int3</code> (an error), but I don't understand why, and how to follow execution while keeping control.</p>
What's 'fs:[0]' doing and how can I execute it step by step?
|windows|x86|seh|
<p>It expects the (beginning of the) actual type description (like <code>Portable executable for 80386 (PE)</code>), not the name of the loader plugin (like <code>pe.ldw</code>), because a loader plugin can generate different types.</p> <p>So in the case of a Windows PE, any of these should work:</p> <ul> <li><code>-T"Portable executable for 80386 (PE)"</code></li> <li><code>-TPortable</code></li> <li><code>-TP</code> (as the other types for a PE are likely starting with <code>Binary</code>, <code>Microsoft</code> or <code>MS-DOS</code>)</li> </ul>
1918
2013-04-24T09:28:24.673
<p>I would like IDA to remember my default load file settings instead of presenting the <a href="https://www.hex-rays.com/products/ida/support/idadoc/242.shtml" rel="noreferrer">load file</a> dialog on every start. <a href="https://www.hex-rays.com/products/ida/support/idadoc/417.shtml" rel="noreferrer">The documentation says</a> there is a <strong>-T</strong> command line switch that should take a 'file type prefix' argument and then not display the load file dialog, but I don't know what a valid 'file type prefix' would be. I tried -TPE but a warning popped up saying 'PE' was not recognized. </p> <p>Any suggestions?</p>
How to avoid the load file dialog in IDA GUI
|ida|
<p>After decompressing and loading the kernel, you need to find a couple of tables that encode the compressed symbol table. These are (in the usual order they are placed in binary):</p> <ul> <li><code>kallsyms_addresses</code> - a table of addresses to all public symbols in the kernel</li> <li><code>kallsyms_num_syms</code> - not a table but just an integer with total number of symbols (should match previous table)</li> <li><code>kallsyms_names</code> - a list of length-prefixed byte arrays that encode indexes into the token table</li> <li><code>kallsyms_token_table</code> - a list of 256 zero-terminated tokens from which symbol names are built</li> <li><code>kallsyms_token_index</code> - 256 shorts pointing to the corresponding entry in <code>kallsyms_token_table</code></li> </ul> <p>They're not hard to find with some experience. A good way to find the first one is to look for several 0xC0008000 values in a row, because a typical kernel symbol table starts like this:</p> <pre><code>C0008000 T __init_begin C0008000 T _sinittext C0008000 T _stext C0008000 T stext </code></pre> <p>After locating the tables the symbol recovery is trivial. I made a script for IDA that does it automatically, you can find it <a href="http://www.hexblog.com/?p=130">here</a> (<code>kallsyms.py</code> in the tools zip).</p> <p>For more the details of how it's implemented in the kernel, see <code>kernel/kallsyms.c</code>.</p>
1922
2013-04-24T16:47:09.463
<p>Igor posted a great <a href="https://stackoverflow.com/a/14811668/139463">answer</a> previously on SO about the format of the Linux kernel image on ARM.</p> <p>Assuming I can't boot my kernel image, can someone give me pointers on finding this compressed symbol table in the binary? </p>
Locating Linux Kernel Symbols on ARM
|linux|arm|
<p>[Back in 2013] the decompiler did not have a scripting API. So you had these choices:</p> <ul> <li><a href="http://www.hexblog.com/?p=126" rel="nofollow">Add necessary functions to IDC</a> using a native plugin that calls the decompiler API.</li> <li>Use <code>ctypes</code> or similar to call the C++ API directly from Python. I posted a small PoC script doing it to the Hex-Rays forum a couple years ago.</li> <li>If you just want to have the decompiled text, you can use <a href="https://www.hex-rays.com/products/decompiler/manual/batch.shtml" rel="nofollow">the command line option</a>.</li> </ul> <p><a href="https://www.hex-rays.com/products/ida/6.6/index.shtml" rel="nofollow">IDA 6.6 (released in June 2014)</a> added official Python bindings for the decompiler, so it now can be scripted from Python. For sample code, see <code>vds*.py</code> scripts in the <a href="https://github.com/idapython/src/tree/master/examples" rel="nofollow">IDAPython repository</a>.</p>
1929
2013-04-25T06:30:29.873
<p>I want to use IDA with the Hex-Rays decompiler plugin as part of automated static analysis, possibly on a large number of files without opening each one and telling it to produce a C file individually. </p> <p>Ideally, I'd like to run IDA from the command line, and get the decompilation based on initial autoanalysis as output. This way I can run it as part of <a href="http://sourceforge.net/projects/mastiff/">Mastiff</a> or grep for certain functions in a set of binaries. By my reading of <a href="http://www.hexblog.com/?p=53">On batch analysis</a> from the Hex Blog, what I need is an IDA script that interacts with the decompiler plugin, but I can't figure out how to actually do so. </p> <p>So this leaves me with 2 subquestions:</p> <ul> <li>How can I tell the Hex-Rays decompiler to "Produce C file" (decompile all functions) from a script?</li> <li>Does that script need to be IDC, or is IDAPython possible?</li> </ul>
How can I control the Hex-Rays decompiler plugin from IDA with scripts?
|ida|ida-plugin|idapython|
<p>It is possible the ways the other commenters suggested. However, all of them are interceptable, if you read a file, it can be intercepted and your program will be given different result, if you check if LD_PRELOAD is set, it can be unset before you can reach out to it, etc. Suid is another story, though, but there may be different ways of exploiting it too.</p>
1930
2013-04-25T08:07:47.923
<p>Under Linux it's possible to trace exactly the kernel system calls with <code>strace</code>. <code>ltrace</code> can be used also to trace library calls. I wonder if it's possible to detect if my executable is running under <code>strace</code> or <code>ltrace</code> ?</p> <p>Here's an example of the output of <code>strace</code> and <code>ltrace</code> for the <code>diff</code> executable.</p> <p><strong>strace</strong> </p> <pre><code>$ strace diff execve("/usr/bin/diff", ["diff"], [/* 43 vars */]) = 0 brk(0) = 0x110a000 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcbc13f6000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=122500, ...}) = 0 mmap(NULL, 122500, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fcbc13d8000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/x86_64-linux-gnu/librt.so.1", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0&gt;\0\1\0\0\0\340!\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0644, st_size=31784, ...}) = 0 mmap(NULL, 2129016, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fcbc0fce000 mprotect(0x7fcbc0fd5000, 2093056, PROT_NONE) = 0 mmap(0x7fcbc11d4000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7fcbc11d4000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0&gt;\0\1\0\0\0\200\30\2\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=1811160, ...}) = 0 mmap(NULL, 3925240, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fcbc0c0f000 mprotect(0x7fcbc0dc4000, 2093056, PROT_NONE) = 0 mmap(0x7fcbc0fc3000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b4000) = 0x7fcbc0fc3000 mmap(0x7fcbc0fc9000, 17656, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fcbc0fc9000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/x86_64-linux-gnu/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0&gt;\0\1\0\0\0\200l\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=135398, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcbc13d7000 mmap(NULL, 2212936, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fcbc09f2000 mprotect(0x7fcbc0a0a000, 2093056, PROT_NONE) = 0 mmap(0x7fcbc0c09000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7fcbc0c09000 mmap(0x7fcbc0c0b000, 13384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fcbc0c0b000 close(3) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcbc09f1000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcbc09f0000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcbc09ef000 arch_prctl(ARCH_SET_FS, 0x7fcbc09f0700) = 0 mprotect(0x7fcbc0fc3000, 16384, PROT_READ) = 0 mprotect(0x7fcbc0c09000, 4096, PROT_READ) = 0 mprotect(0x7fcbc11d4000, 4096, PROT_READ) = 0 mprotect(0x61b000, 4096, PROT_READ) = 0 mprotect(0x7fcbc13f8000, 4096, PROT_READ) = 0 munmap(0x7fcbc13d8000, 122500) = 0 set_tid_address(0x7fcbc09f09d0) = 32425 set_robust_list(0x7fcbc09f09e0, 0x18) = 0 futex(0x7fff27e5992c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 1, NULL, 7fcbc09f0700) = -1 EAGAIN (Resource temporarily unavailable) rt_sigaction(SIGRTMIN, {0x7fcbc09f8750, [], SA_RESTORER|SA_SIGINFO, 0x7fcbc0a01cb0}, NULL, 8) = 0 rt_sigaction(SIGRT_1, {0x7fcbc09f87e0, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7fcbc0a01cb0}, NULL, 8) = 0 rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0 getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM_INFINITY}) = 0 brk(0) = 0x110a000 brk(0x112b000) = 0x112b000 open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=7216624, ...}) = 0 mmap(NULL, 7216624, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fcbc030d000 close(3) = 0 sigaltstack({ss_sp=0x61c5e0, ss_flags=0, ss_size=8192}, NULL) = 0 open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=2570, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcbc13f5000 read(3, "# Locale name alias data base.\n#"..., 4096) = 2570 read(3, "", 4096) = 0 close(3) = 0 munmap(0x7fcbc13f5000, 4096) = 0 open("/usr/share/locale/en_US/LC_MESSAGES/diffutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/en/LC_MESSAGES/diffutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/en_US/LC_MESSAGES/diffutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/en/LC_MESSAGES/diffutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) rt_sigaction(SIGSEGV, {0x40b3c0, [], SA_RESTORER|SA_STACK|SA_NODEFER|SA_RESETHAND|SA_SIGINFO, 0x7fcbc0c454a0}, NULL, 8) = 0 write(2, "diff: ", 6diff: ) = 6 write(2, "missing operand after `diff'", 28missing operand after `diff') = 28 write(2, "\n", 1 ) = 1 write(2, "diff: ", 6diff: ) = 6 write(2, "Try `diff --help' for more infor"..., 39Try `diff --help' for more information.) = 39 write(2, "\n", 1 ) = 1 exit_group(2) = ? </code></pre> <p><strong>ltrace</strong> </p> <pre><code>$ ltrace diff __libc_start_main(0x402310, 1, 0x7fff876fcf28, 0x4151d0, 0x415260 &lt;unfinished ...&gt; strrchr("diff", '/') = NULL setlocale(6, "") = "en_US.UTF-8" bindtextdomain("diffutils", "/usr/share/locale") = "/usr/share/locale" textdomain("diffutils") = "diffutils" sigaltstack(0x7fff876fccd0, 0, 1, 0x736c6974756666, 3) = 0 dcgettext(0, 0x4183d7, 5, -1, 3) = 0x4183d7 dcgettext(0, 0x4183e5, 5, 0, 1) = 0x4183e5 sigemptyset(0x7fff876fccf8) = 0 sigaction(11, 0x7fff876fccf0, NULL) = 0 re_set_syntax(264966, 0x7fff876fcb88, 0, -1, 0) = 0 malloc(16) = 0x016e1160 memset(0x016e1160, '\000', 16) = 0x016e1160 getopt_long(1, 0x7fff876fcf28, "0123456789abBcC:dD:eEfF:hHiI:lL:"..., 0x00417360, NULL) = -1 malloc(1) = 0x016e1180 dcgettext(0, 0x415598, 5, 8, 3) = 0x415598 error(0, 0, 0x415598, 0x7fff876fd469, 1diff: missing operand after `diff' ) = 0 dcgettext(0, 0x415878, 5, 0, 0x7fad1793c700) = 0x415878 error(2, 0, 0x415878, 0x7fff876fd469, 1diff: Try `diff --help' for more information. &lt;unfinished ...&gt; +++ exited (status 2) +++ </code></pre>
Detecting tracing in Linux
|linux|anti-debugging|
<p>perror's answer I think is the correct way to do it. I wanted to post the way I ended up doing this for other's sake just in case the issue I mentioned in my comment to perror's answer is correct. I don't have all my notes with me right now and will update if necessary.</p> <p>Basically I ran the program in gdb, set a break point in PyObject_New (or possibly PyObject_Init). I set the break point near the end of the function so that the object would be created. From there I was able to look into the object in memory to extract the byte code.</p> <p>To get this info back to pyREtic, I dumped function names and bytecode to a file from within GDB, modified pyREtic so that instead of calling co_code to get the bytecode, it would extract it from the file.</p> <p>Like I said, it has been a while now (the stackoverflow question was from Sept 2012). I'll look back over my notes and fill in the details.</p>
1934
2013-04-26T18:36:54.600
<p>I posted this a while back on <a href="https://stackoverflow.com/questions/12513901/is-it-possible-to-get-python-bytecode-without-using-co-code">stackoverflow</a> (too old to migrate though).</p> <p>Say I am in the python interpreter and define a function as follows:</p> <pre><code>def h(a): return a </code></pre> <p>If I want to look at the bytecode (not a disassembly using dis), I can typically use <code>h.func_code.co_code</code>. Is there any other way to look at the bytecode? This particular application was packaged with a custom python interpreter (using py2exe probably) which removed access to co_code. I can't just look at the pyc file as they are encrypted.</p> <p>For example, in the interpreter, if I just type <code>h</code> without making it a function call, I get the address of the function. Can I use that address to get the bytecode? Is there some other way?</p> <p>P.S. My original goal in doing this at the time was to use pyREtic (which calls co_code) to decompile. Since it called co_code, it would fail to work. I figured out one way to do it which I will post as an answer eventually. Wanted to see what others have done or come up with.</p>
Is it possible to get python bytecode without using co_code?
|python|
<p>I used to use <a href="https://github.com/gdbinit/Gdbinit" rel="nofollow noreferrer">https://github.com/gdbinit/Gdbinit</a> for tuning GDB but it's getting a bit dated, so I'd recommend <a href="https://github.com/hugsy/gef" rel="nofollow noreferrer">https://github.com/hugsy/gef</a> now as a modern alternative.</p>
1935
2013-04-27T03:13:34.493
<p>I have GDB but the binary I want to reverse engineer dynamically has no symbols. That is, when I run the <a href="https://www.man7.org/linux/man-pages/man1/file.1.html" rel="nofollow noreferrer"><code>file</code></a> utility it shows me <strong>stripped</strong>:</p> <pre><code>ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped </code></pre> <p>What options do I have if the environment in which this runs doesn't allow a remote IDA Pro instance to connect to <code>gdbserver</code>? In short: the environment you have is limited in what it allows you to do, but you do have trusty old <code>gdb</code> and a binary to reverse engineer.</p>
How to handle stripped binaries with GDB? No source, no symbols and GDB only shows addresses?
|tools|dynamic-analysis|linux|debuggers|gdb|
<p>Currently I'm using TreeDBNotes, they have a free and pro version available. I haven't compared it to any of the methods mentioned in other answers, but find it quite useful for keeping track of my project notes/data.</p> <p><a href="http://www.mytreedb.com" rel="nofollow">http://www.mytreedb.com</a></p>
1937
2013-04-27T09:29:13.530
<p>Since now, when I am analyzing a binary, I'm using a "pen and paper" method to locate the different location of the function, the different type of obfuscations, and all my discoveries. It is quite inefficient and do not scale at all when I try to analyze big binaries.</p> <p>I know that IDAPro is having a data-base to store comments and a memory zone, but, in case we do not want to use IDAPro, what techniques or (free) tools are you using to collect your notes and to display it properly ?</p>
How do you store your data about a binary while performing analysis?
|tools|binary-analysis|
<p>You have some options. </p> <p>You can create your own obfuscation method comprised of existing encryption tools...i.e. openssl. But, beware, it will likely take you a considerable amount of time to complete this type of project. </p> <p>It'll require you to map out how you're going to enclosed the "passwords/passkeys" within the obfuscated code in such a way that no one, except you, can get to it. It'll be preferable if even you cant get to it. </p> <p>Then, you need to add in some logic that will cause the script to protect itself from inquisitive users who may try to pry it apart. And equally as important, whatever method you come up with must not add significantly to the execution time of the script. </p> <p>This may sound impossible, but i think its doable. You just have to be motivated and have enough time on your hands. </p> <p>Or, if you want a shortcut, you can try pasting a sample unix based python script to <a href="http://www.EnScryption.com/encrypt-and-obfuscate-scripts.html" rel="nofollow noreferrer">this site</a>, and see if you can break their code and unveil your "hidden" code.</p>
1943
2013-04-27T20:06:56.917
<p>This question is related to this <a href="https://reverseengineering.stackexchange.com/questions/1934/is-it-possible-to-get-python-bytecode-without-using-co-code">other one</a>. I just wonder what are the techniques applicable and which can be found in the real world to obfuscate Python program (similar questions can be found on stackoverflow <a href="https://stackoverflow.com/questions/261638/how-do-i-protect-python-code">here</a> and <a href="https://stackoverflow.com/questions/576963/python-code-obfuscation">here</a>).</p> <p><a href="https://reverseengineering.stackexchange.com/questions/1934/is-it-possible-to-get-python-bytecode-without-using-co-code/1942#1942">mikeazo mentioned</a> the fact that his program was provided with a custom Python interpreter, but what are the other techniques and how efficient are they ?</p>
What are the techniques and tools to obfuscate Python programs?
|tools|obfuscation|python|
<p>Crisis is trying to locate dyld location in that piece of code: 32bits dyld is usually located at 8FE00000 - it uses that to solve symbols, if I'm not mistaken.</p> <p>Check my Crisis <a href="http://reverse.put.as/2012/08/06/tales-from-crisis-chapter-1-the-droppers-box-of-tricks/">analysis</a> if you haven't already.</p>
1946
2013-04-28T11:36:50.347
<p>I was reverse engineering a piece of code in "Crisis" for fun and I encountered the following :-</p> <pre><code>__INIT_STUB_hidden:00004B8F mov eax, 8FE00000h __INIT_STUB_hidden:00004B94 __INIT_STUB_hidden:00004B94 loc_4B94: __INIT_STUB_hidden:00004B94 mov ebx, 41424344h __INIT_STUB_hidden:00004B99 cmp dword ptr [eax], 0FEEDFACEh __INIT_STUB_hidden:00004B9F jz short loc_4BB9 __INIT_STUB_hidden:00004BA1 add eax, 1000h __INIT_STUB_hidden:00004BA6 cmp eax, 8FFF1000h __INIT_STUB_hidden:00004BAB jnz short loc_4B94 </code></pre> <p>What is supposed to happen here? Why is the presence of <code>FEEDFACE</code> expected at the address <code>8FFF0000</code> or <code>8FFF1000</code>? I understand that <code>feedface</code>/<code>feedfacf</code> are Mach-O magic numbers -- however why are they expected to be present at those addresses?</p>
FEEDFACE in OSX malware
|malware|osx|
<p>When I needed to do a similar task I ended up hooking the IDB save event and then scanned the IDB for modifications using the IDA API before each user save. it took about a few seconds to scan the entire function list, aggregating most information for both functions and data elements.</p> <p>To me, that sounds like a more practical approach than trying to reverse engineer IDA and patching these hooks in, especially when trying to catch UI events such as user hotkeys.</p> <p>one point to note though, is that aggregating structure/enum data might be difficult if you choose not to rely on IDA's id numbers if you're doing to handle more than one IDB file.</p> <p>If you do wish to reverse engineer IDA, it'll be very interesting to join a discussion on the topic somewhere. since IDA now uses Qt for most of it's UI (though I'll guess the migration to Qt wasn't as smooth as one could hope), a great starting point into Qt will be <a href="http://www.codeproject.com/Articles/31330/Qt-Internals-Reversing" rel="nofollow noreferrer">Daniel Pistelli's Qt Internals and Reversing</a> article, which also includes an IDAPython script at the end (yet reading the entire article is highly recommended).</p> <p>it's somewhat outdated but assuming IDA uses Qt 4.8.x there aren't many differences (if you'd like I can list the ones I know of).</p> <p>basically, since Qt is very event-driven (and with some luck IDA 6.0 was designed with that in mind) it might be the case that you just need to listen, in Qt-dialect this is called <code>connect</code>-ing a <code>slot</code> (event handler) to a <code>signal</code> (event), for at-least some of the specific events you wish to hook.</p> <p>I previously did some moderate Qt-IDA hacks as I call them, using Qt and PyQt to manipulate Qt objects under IDA's application. In the same manner I managed to add and edit menu items and tool bars manually, it is definitely possible to look up the context menu popup when right-clicking in IDA's disassembly view or hooking the hotkeys.</p> <p><a href="https://reverseengineering.stackexchange.com/questions/11181/adding-a-toolbar-to-ida-using-pyside/12999#12999">This RE.SE</a> answer of mine might be a good place to start.</p>
1956
2013-04-29T01:12:29.017
<p>In my <a href="https://reverseengineering.stackexchange.com/questions/1906/how-can-my-plugin-get-notified-of-anterior-or-posterior-comments-and-more-chan">previous question</a> I had originally asked for this, but since this aspect of the question was completely disregarded, I feel compelled to ask it separately.</p> <p>There are certain events apparently not covered in the IDA SDK. I learned in the above linked question that anterior and posterior comments are supported, but what about other events such as when I press <kbd>h</kbd> (e.g. <code>2Ah</code> becomes <code>42</code>) to change the number to base 10 (and back) or <kbd>r</kbd> to show it as character (e.g. <code>2Ah</code> becomes <code>*</code>).</p> <p>How would I go about to catch these?</p> <p><strong>NB:</strong> in general this question would also relate to IDA versions prior to the ones supporting a particular event notification. E.g. the IDA SDK 6.4, according to Igor, introduced notifications for anterior and posterior comments. How can I get older versions and 6.4 to co-operate w.r.t. those events in conjunction with <a href="http://sourceforge.net/projects/collabreate/" rel="nofollow noreferrer">collabREate</a>?</p> <p>I know that it is allowed to reverse engineer IDA itself, so what I am looking for are pointers.</p>
How to get notified about IDA database events not covered in the IDA SDK?
|ida|ida-plugin|idapro-sdk|
<p>When single-stepping through code, the <code>T</code> flag is set so that the CPU can break after the instruction completes execution. When an interrupt occurs, the state of the <code>T</code> flag is placed on the stack, and used when the <code>iret</code> instruction is executed by the handler. However, the <code>iret</code> instruction is one of a few instructions that causes a one-instruction delay in the triggering of the <code>T</code> flag, due to legacy issues relating to the initialization of the stack.</p> <p>So the skipped instruction is executing but you can't step into it (but if you set a breakpoint at that location and run to that point instead, then you will get a break).</p>
1958
2013-04-29T16:28:50.237
<p>I'm reversing some malware on an OSX VM when I noticed something peculiar. While stepping through the instructions, the instruction just after a <code>int 0x80</code> gets skipped <em>i.e.</em> gets executed without me stepping through this.</p> <p><strong>Example:</strong></p> <pre><code> int 0x80 inc eax ; &lt;--- this gets skipped inc ecx ; &lt;--- stepping resumes here </code></pre> <p>Why does this happen? Have you encountered something similar to this?</p>
Strange GDB behavior in OSX
|malware|gdb|osx|x86|mach-o|
<p><strong>I edited the whole example a little so that it would better match the question.</strong></p> <p>My SPARC assembly fu is weak, but what I did was write a little "Hello world" with a twist (or one could say with jumps/<code>goto</code>s) in C and use <code>gcc -S</code> to translate it to assembly. I have a SPARC on which I am running it, details:</p> <pre><code>$ isainfo -v 64-bit sparcv9 applications vis2 vis 32-bit sparc applications vis2 vis v8plus div32 mul32 </code></pre> <p><strong>NB:</strong> <code>b</code> is the same as <code>jmp</code>, it's just a different mnemonic for the same thing, really. One takes an immediate value (<code>b</code>), the other a register (<code>jmp</code>).</p> <p>It turns out that what <a href="http://en.wikibooks.org/wiki/SPARC_Assembly/SPARC_Details#Delayed_Branch" rel="nofollow noreferrer">the link</a> you gave is true for GCC:</p> <blockquote> <p>Notice that the last instruction executes before the jump takes place, not after the subroutine returns. This first instruction after a jump is called a delay slot. It is common practice to fill the delay slot with a special operation that performs no task, called a no-operation, or <code>nop</code>.</p> </blockquote> <h1>Real life test</h1> <p>I reckon we need to do this with and without debugger, because it's not clear whether it might behave differently under a debugger. So the code should output something readable so we can see what kind of effect our tinkering has ;)</p> <h2>C code</h2> <pre><code>#include &lt;stdio.h&gt; int foo(int argc) { switch(argc) { case 0: case 1: goto a1; case 2: return 3; case 4: goto a2; case 5: return -1; default: goto a4; } a1: return 1; a2: return 2; a4: return 4; } int main(int argc, char** argv) { printf("Hello world: %i\n", foo(argc)); return foo(argc); } </code></pre> <p>This gives me plenty of branch instructions to play around with the idea raised in the question.</p> <h2>Assembly created by <code>gcc -S</code></h2> <p>Here's the assembly before I tinkered with it:</p> <pre><code> .file "test.c" .section ".text" .align 4 .global foo .type foo, #function .proc 04 foo: !#PROLOGUE# 0 save %sp, -120, %sp !#PROLOGUE# 1 st %i0, [%fp+68] ld [%fp+68], %g1 cmp %g1, 5 bgu .LL11 nop ld [%fp+68], %g1 sll %g1, 2, %i5 sethi %hi(.LL12), %g1 or %g1, %lo(.LL12), %g1 ld [%i5+%g1], %g1 jmp %g1 nop .LL6: mov 3, %g1 st %g1, [%fp-20] b .LL1 nop .LL9: mov -1, %g1 st %g1, [%fp-20] b .LL1 nop .LL5: mov 1, %g1 st %g1, [%fp-20] b .LL1 nop .LL8: mov 2, %g1 st %g1, [%fp-20] b .LL1 nop .LL11: mov 4, %g1 st %g1, [%fp-20] .LL1: ld [%fp-20], %i0 ret restore .align 4 .align 4 .LL12: .word .LL5 .word .LL5 .word .LL6 .word .LL11 .word .LL8 .word .LL9 .size foo, .-foo .section ".rodata" .align 8 .LLC0: .asciz "Hello world: %i\n" .section ".text" .align 4 .global main .type main, #function .proc 04 main: !#PROLOGUE# 0 save %sp, -112, %sp !#PROLOGUE# 1 st %i0, [%fp+68] st %i1, [%fp+72] ld [%fp+68], %o0 call foo, 0 nop mov %o0, %o5 sethi %hi(.LLC0), %g1 or %g1, %lo(.LLC0), %o0 mov %o5, %o1 call printf, 0 nop ld [%fp+68], %o0 call foo, 0 nop mov %o0, %g1 mov %g1, %i0 ret restore .size main, .-main .ident "GCC: (GNU) 3.4.3 (csl-sol210-3_4-branch+sol_rpath)" </code></pre> <p>I'll concentrate on modifying the result of <code>foo()</code>, so I won't repeat all of the assembly code again but instead only bits and pieces.</p> <p>btw: GCC created the extra indentation for the <code>nop</code> instructions, but it makes it easy to spot them, of course.</p> <h2>Steps to get from C to executable with tinkering involved</h2> <p>Here are the steps to get to the modified program.</p> <ul> <li>use <code>gcc -S test.c</code> to get a <code>test.s</code> file</li> <li>modify the <code>test.s</code></li> <li>Assemble it with <code>gas -o test.o test.s</code></li> <li>Link with GCC using <code>gcc -o test test.o</code></li> </ul> <h2>Modifications to the assembly code</h2> <p>First, I felt compelled to "optimize" the instructions in <code>LL6</code>, <code>LL9</code>, <code>LL5</code>, <code>LL8</code>, <code>LL11</code> and <code>LL1</code> like this:</p> <pre><code>.LL6: mov 3, %i0 b .LL1 nop .LL9: mov -1, %i0 b .LL1 nop .LL5: mov 1, %i0 b .LL1 nop .LL8: mov 2, %i0 b .LL1 nop .LL11: mov 4, %i0 .LL1: ret restore </code></pre> <p>It should be clear that if your colleague is right, we should be able to substitute the <code>nop</code> instructions for a <code>mov ..., %i0</code> to see something other than the expected value.</p> <p>I called my modified assembly file <code>modified.s</code> so as to not confuse myself ;)</p> <h3>Verifying my "optimizations"</h3> <p>First test is with my "optimizations only". I wrote a little test script:</p> <pre><code>#!/usr/bin/env bash for i in optimized test; do echo -n "$i: "; ./$i echo -n "$i: "; ./$i a1 echo -n "$i: "; ./$i a1 a2 echo -n "$i: "; ./$i a1 a2 a3 done </code></pre> <p>The binaries are called <code>optimized</code> (my "optimizations" from above) and <code>test</code> (plain assembly created by GCC from C code).</p> <p><strong>Results:</strong></p> <pre><code>$ ./runtest optimized: Hello world: 1 optimized: Hello world: 3 optimized: Hello world: 4 optimized: Hello world: 2 test: Hello world: 1 test: Hello world: 3 test: Hello world: 4 test: Hello world: 2 </code></pre> <p>So my "optimizations" seem to be just fine. Now let's tinker a little.</p> <h3>Tinkering with the instructions which modify the program counter</h3> <p>The claim is that anything past a <code>jmp</code> (i.e. <code>b</code>) will get executed <em>before</em> the jump itself. We have several labels with jumps, so let's replace the <code>nop</code> in each with something that changes the value inside <code>%i0</code> and thus the return value of <code>foo()</code>.</p> <p><strong>The changes:</strong></p> <pre><code>.LL6: mov 3, %i0 b .LL1 mov 30, %i0 .LL9: mov -1, %i0 b .LL1 mov 42, %i0 .LL5: mov 1, %i0 b .LL1 mov 10, %i0 .LL8: mov 2, %i0 b .LL1 mov 20, %i0 .LL11: mov 4, %i0 .LL1: ret restore </code></pre> <p>So except for return code <code>-1</code> (which becomes <code>42</code>) and <code>4</code> (which stays the same) everything should now return the original value times ten.</p> <p>Let's see the results (I added <code>modified</code> to the list of items in my <code>for</code> loop):</p> <pre><code>$ ./runtest optimized: Hello world: 1 optimized: Hello world: 3 optimized: Hello world: 4 optimized: Hello world: 2 test: Hello world: 1 test: Hello world: 3 test: Hello world: 4 test: Hello world: 2 modified: Hello world: 10 modified: Hello world: 30 modified: Hello world: 4 modified: Hello world: 20 </code></pre> <h1>A change that is as close to your example as I can get it</h1> <pre><code> mov 39, %i0 jmp %g1 b .LL11 b .LL1 .LL6: mov 37, %i0 b .LL1 mov 30, %i0 [...] .LL11: mov 4, %i0 .LL1: ret restore </code></pre> <p>Amending the test script, here's the output:</p> <pre><code>$ ./runtest optimized: Hello world: 1 optimized: Hello world: 3 optimized: Hello world: 4 optimized: Hello world: 2 test: Hello world: 1 test: Hello world: 3 test: Hello world: 4 test: Hello world: 2 modified: Hello world: 10 modified: Hello world: 30 modified: Hello world: 4 modified: Hello world: 20 question: Hello world: 4 question: Hello world: 4 question: Hello world: 4 question: Hello world: 4 </code></pre> <p>Baffling!</p> <h1>Result</h1> <p>You can play tricks on the reverse engineer's mind with this - no doubt. I learned something new and that alone was worth it.</p> <p>Here's the situation</p> <pre><code>jmp %g1 b .LL11 ; &lt;-- this is the branch taken b .LL1 mov 37, %i0 ; &lt;-- but this gets executed first (at least in GDB) </code></pre> <p>Now I don't know whether this is true for all SPARC machines, but certainly for the one I was using for my tests (specs at the top)</p> <h1>Conclusion</h1> <p>Yes, this can certainly be used to trick the unwitting reverse engineer and perhaps the disassembler (static analysis tool). It's basically an opaque predicate. I.e. the outcome is clear at compile time, but it looks like it's dynamic.</p> <p>It's difficult to see how good different disassemblers cope, given that I only have IDA Pro and <code>objdump</code> available here. My educated guess would be that they cope the same as with other <a href="http://en.wikipedia.org/wiki/Opaque_predicate" rel="nofollow noreferrer">opaque predicates</a>, i.e. sometimes they'll get fooled, sometimes they'll be surprisingly smart. So whether or not this is a suitable obfuscation method remains unsolved.</p> <h2>Bonus information</h2> <p>As opposed to prior to the edit, IDA seems to be mildly confused by the new code, watch this graph view:</p> <p><img src="https://i.stack.imgur.com/1Ybgl.png" alt="IDA slightly confused"> <a href="https://i.stack.imgur.com/jDzvg.png" rel="nofollow noreferrer">click here for full size image</a> (<a href="https://i.stack.imgur.com/jDzvg.png" rel="nofollow noreferrer">previous version</a>)</p> <h2>Little GDB session</h2> <p><code>0x106CC</code> is the <code>mov 39, %i0</code> instruction, found via IDA.</p> <pre><code>$ gdb -q ./question (no debugging symbols found) (gdb) b *0x106CC Breakpoint 1 at 0x106cc (gdb) run a1 Starting program: /export/home/builder/test/question a1 [New LWP 1] [New LWP 2] [LWP 2 exited] [New LWP 2] (no debugging symbols found) (no debugging symbols found) Breakpoint 1, 0x000106cc in foo () (gdb) disp/i $pc 1: x/i $pc 0x106cc &lt;foo+44&gt;: mov 0x27, %i0 (gdb) si 0x000106d0 in foo () 1: x/i $pc 0x106d0 &lt;foo+48&gt;: jmp %g1 0x106d4 &lt;foo+52&gt;: b 0x1070c &lt;foo+108&gt; 0x106d8 &lt;foo+56&gt;: b 0x10710 &lt;foo+112&gt; 0x106dc &lt;foo+60&gt;: mov 0x25, %i0 (gdb) 0x000106d4 in foo () 1: x/i $pc 0x106d4 &lt;foo+52&gt;: b 0x1070c &lt;foo+108&gt; 0x106d8 &lt;foo+56&gt;: b 0x10710 &lt;foo+112&gt; 0x106dc &lt;foo+60&gt;: mov 0x25, %i0 (gdb) 0x000106dc in foo () 1: x/i $pc 0x106dc &lt;foo+60&gt;: mov 0x25, %i0 (gdb) 0x0001070c in foo () 1: x/i $pc 0x1070c &lt;foo+108&gt;: mov 4, %i0 (gdb) 0x00010710 in foo () 1: x/i $pc 0x10710 &lt;foo+112&gt;: ret 0x10714 &lt;foo+116&gt;: restore (gdb) </code></pre> <p>So according to GDB we are executing the <code>mov 37, %i0</code> before the branching. This seems to suggest to me that even when you chain multiple branch instructions, the first thing to be executed is whatever comes after the last one in the chain.</p>
1962
2013-04-29T17:49:06.700
<p>Our team recently had to look at <a href="http://www.sparc.com/standards/V8.pdf" rel="nofollow">SPARC assembly specifications</a>, the problem is that I do not have a SPARC processor to try things on it (I should set up a simulator or get one of these old Sparc station on my desk... I know).</p> <p>Somehow, the <code>ba</code> (branch always) instruction puzzled me because it is a <a href="http://en.wikibooks.org/wiki/SPARC_Assembly/SPARC_Details#Delayed_Branch" rel="nofollow">delayed branch execution</a> instruction. This mean that the instruction located just <strong>after</strong> the <code>ba</code> get executed before the jump occurs.</p> <p>One of my colleague raised a very interesting question, what does occur in this case:</p> <pre><code>0x804b38 ba 0x805a10 0x804b3c ba 0x806844 ... 0x805a10 add %r3, %r2, %r5 ... 0x806844 sub %r3, %r5, %r2 ... </code></pre> <p>Our guess, following the specifications, is that the run should behave like this:</p> <pre><code>0x805a10 add %r3, %r2, %r5 0x806844 sub %r3, %r5, %r2 0x806848 ... </code></pre> <p>Which means that you can probably jump and pick up one instruction inside a block of others and run to the next <code>ba</code>... I wonder what the CFG would look like.</p> <p>Whatever, it was the "<em>simple</em>" case, what if we have dynamic jumps (the <code>jmp</code> instruction is like a <code>ba</code> but based on the address stored in the given register):</p> <pre><code>0x804b38 jmp %r3 0x804b3c jmp %r0 ... (%r3) change %r0 ... </code></pre> <p>Would it be a good way to mislead a static-analyzer ? Or, is there a way to have an easy computation to guess what it is doing ?</p>
On SPARC, what happens when a branch is placed in the branch-delay slot of another branch?
|obfuscation|binary-analysis|sparc|
<p>Newer versions of Android actually include a mechanism like this. It uses jdwp to send a signal to tell the app that you've connected up. See the ndk-gdb script from the NDK =)</p>
1965
2013-04-29T18:57:17.257
<p>I have an android application that uses a shared library which I would like to step through with a debugger. I've had success using IDA 6.3 to debug executables with the <code>android_server</code> debug server included with IDA but haven't gotten it to work with shared objects yet. </p> <p>For a specific example, suppose I have the following Java code (This comes from the hellojni example in the Android NDK):</p> <pre><code>System.loadLibrary("hello-jni"); tv.setText( stringFromJNI() ); </code></pre> <p>With the JNI C code as:</p> <pre><code>jstring Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject thiz ) { return (*env)-&gt;NewStringUTF(env, "Hello from JNI !"); } </code></pre> <p>If the java code is run only when the application starts up, how can I break in the function <code>Java_com_example_hellojni_HelloJni_stringFromJNI</code>?</p>
How to break on an Android JNI function with IDA Pro Debugger
|ida|android|
<p>The best option for Windows that I have found in 2023 is using WinShark, which is not that well known:</p> <p><a href="https://github.com/airbus-cert/Winshark" rel="nofollow noreferrer">https://github.com/airbus-cert/Winshark</a></p> <p>It uses ETW to capture PID related to each packet, you just have to use something like <code>winshark.header.ProcessId == 1234</code>.</p> <p><a href="https://i.stack.imgur.com/OoHJa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OoHJa.png" alt="enter image description here" /></a></p> <p>Installing it is also very straightforward which is explained in their github.</p>
1970
2013-04-30T19:44:25.337
<p>Is it possible to sniff TCP traffic for a specific process using Wireshark, even through a plugin to filter TCP traffic based on process ID?</p> <p>I'm working on Windows 7, but I would like to hear about solution for Linux as well.</p>
Sniffing TCP traffic for specific process using Wireshark
|sniffing|wireshark|
<p>Here's an explanation for what I think the individual symbols mean. I'm basing this around the presumption that a little selector is going through the cells, one by one.</p> <ul> <li><code>\xFF</code> = Null cell</li> <li><code>\x05</code> = A string is following, with <code>\xNumber</code> coming after the string to define how far to displace the string from the selector's current position, if at all. </li> <li><code>\xNumber string</code> = A string of length number</li> <li><code>\x2A</code> = Could be a byte that says not to displace the current string, and also to assume that the next piece of data is defining a string to be placed in the next cell. Questionable meaning.</li> <li><code>\x04 \xNumber</code> = Move selector ahead <code>\xNumber</code> cells and place previous string into there.</li> <li><code>0 \x00 \x0Number</code> = New column, move selector into row <code>\xNumber</code>, and place previous string into there. <code>@</code> = Place previously used string in the cell following the current one.</li> </ul> <p>So here's my interpretation of the data you're giving us:</p> <ul> <li><code>\xFF\xFF</code> = two null cells</li> <li><code>\x05</code> = A cell, singular, with a string, placed following the null cells, because of the <code>\x2A</code> following the string </li> <li><code>\x04 test</code> = The string.</li> <li><code>\x2A \x05 test1</code> = Another string placed into the cell following. No number needed, since \x2A implies that it's being placed right after "test"</li> <li><code>@</code> = Place "test1" into the cell after the "test1" string was first placed.</li> <li><code>\x04 \x03</code> = Move selector ahead three cells and place test1 where it lands.</li> <li><code>@@</code> = Place into the two cells following also.</li> <li><code>\x04 \x05 @</code> = Skip four cells, place into two cells.</li> <li><code>0</code> = New column.</li> <li><code>\x00 \x00 @</code> = Using string last defined (test1), place into first two cells of the column. </li> <li><code>\x05 \x05 test2 \x03</code> = Place a cell three cells afterwords.</li> <li><code>\x05\x05test1\x06</code> = Place test1 into a cell 6 after test2</li> <li><code>@</code> = Place test1 again, too.</li> <li><code>0</code> = move to next column</li> <li><code>\x00\x01</code> = Place previous string at location 01 </li> <li><code>@</code> = And also at location 02</li> <li><code>\x00</code> = Done</li> </ul> <p>Explanation: My method was to look for a pattern, check if the pattern withstood further scrutiny - the first pattern I checked seemed to - and clear up any minor issues I had with it. Seems to have worked.</p>
1971
2013-04-30T19:57:56.433
<p>I have binary data representing a table.</p> <p>Here's the data when I print it with Python's <a href="http://docs.python.org/2/library/repr.html#module-repr">repr()</a>: <code>\xff\xff\x05\x04test\x02A\x05test1@\x04\x03@@\x04\x05@0\x00\x00@\x05\x05test2\x03\x05\x05test1\x06@0\x00\x01@\x00</code></p> <p>Here's what the table looks like in the proprietary software.</p> <p><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>test1</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><br/> <kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>test1</kbd><kbd>test1</kbd><br/> <kbd>test&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>test1</kbd><br/> <kbd>test1</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><br/> <kbd>test1</kbd><kbd>test2</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><br/> <kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><br/> <kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><br/> <kbd>test1</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><br/> <kbd>test1</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><br/> <kbd>test1</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><br/> <kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>test1</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><br/> <kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>test1</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><br/> <kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><br/> <kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><br/> <kbd>test1</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><br/> <kbd>test1</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><br/></p> <p>I was able to guess some of it:</p> <ul> <li>It's column by column then cell by cell, starting at the top left cell.</li> <li>The <code>\x04</code> in <code>\x04test</code> seems to be the length (in bytes I guess) of the following word.</li> <li><code>@</code> mean the last value</li> </ul> <p>Anyone knows if the data is following a standard or have any tips how to decode it?</p> <p>Thanks!</p> <p>Here's an example with python :</p> <pre><code>from struct import unpack def DecodeData(position): print "position", position firstChar = data[position:][:1] size_in_bytes = unpack('B', firstChar)[0] print "firstChar: {0}. size_in_bytes: {1}".format(repr(firstChar), size_in_bytes) return size_in_bytes def ReadWord(position, size_in_bytes): word = unpack('%ds' % size_in_bytes, data[position:][:size_in_bytes])[0] print "word:", word data = "\xff\xff\x05\x04test\x02A\x05test1@\x04\x03@@\x04\x05@0\x00\x00@\x05\x05test2\x03\x05\x05test1\x06@0\x00\x01@\x00" position = 0 print "" position += 1 DecodeData(position) print "\\xff - ?" print "" position += 1 DecodeData(position) print "\\x05 - ?" print "" position += 1 size_in_bytes = DecodeData(position) position += 1 ReadWord(position, size_in_bytes) print "" position += size_in_bytes DecodeData(position) position += 1 DecodeData(position) print """'2A' : could be to say that "test" has 2 empty cells before it""" print "" position += 1 size_in_bytes = DecodeData(position) position += 1 word = unpack('%ds' % size_in_bytes, data[position:][:size_in_bytes])[0] print "word:", word position += size_in_bytes DecodeData(position) print """@: mean that there's another "test1" cell""" print "" position += 1 DecodeData(position) position += 1 DecodeData(position) print "\\x04\\x03 - Could be that the next value is 3 cells down" print "" position += 1 DecodeData(position) print "" position += 1 print "@@ - Seems to mean 3 repetitions" print "" position += 1 DecodeData(position) position += 1 DecodeData(position) print "\\x04\\x05 - Could be that the next value is 5 cells down" print "" position += 1 DecodeData(position) print "@ - repetition" print "" position += 1 DecodeData(position) print "" position += 1 DecodeData(position) position += 1 DecodeData(position) print "\\x00\\x00 - That could mean to move to the first cell on the next column" print "" position += 1 DecodeData(position) print "@ - repetition" print "" position += 1 DecodeData(position) print "\\x05 - ?" print "" position += 1 size_in_bytes = DecodeData(position) position += 1 word = unpack('%ds' % size_in_bytes, data[position:][:size_in_bytes])[0] print "word:", word position += size_in_bytes print "" DecodeData(position) print "\\x03 - Could be to tell that the pervious word 'test2' is 3 cells down" print "" position += 1 DecodeData(position) print "\\x05 - ?" print "" position += 1 size_in_bytes = DecodeData(position) position += 1 word = unpack('%ds' % size_in_bytes, data[position:][:size_in_bytes])[0] print "word:", word position += size_in_bytes print "" DecodeData(position) print "\\x06 - Could be to tell that the pervious word 'test1' is 6 cells down" print "" position += 1 DecodeData(position) print "@ - repetition" print "" position += 1 DecodeData(position) print "\\0 - ?" print "" position += 1 DecodeData(position) position += 1 DecodeData(position) print "\\x00\\x01 - Seems to mean, next column second cell" print "" position += 1 DecodeData(position) print "@ - repetition" print "" position += 1 DecodeData(position) print "\\x00 - end of data or column" </code></pre>
Any idea how to decode this binary data?
|unpacking|file-format|
<p>According to devttys0's answer.</p> <p>This script is for IDA version higher than 7.4.</p> <pre><code> def convert_data(): align_size = ida_kernwin.ask_long(4, &quot;align size&quot;) if align_size == None: return start = idc.read_selection_start() end = idc.read_selection_end() print(&quot;Align %d bytes from 0x%X - 0x%X&quot; % (align_size, start, end)) ida_bytes.del_items(start, (end-start), ida_bytes.DELIT_SIMPLE) flag = None if align_size == 1: flag = ida_bytes.FF_BYTE elif align_size == 2: flag = ida_bytes.FF_WORD elif align_size == 4: flag = ida_bytes.FF_DWORD elif align_size == 8: flag = ida_bytes.FF_QWORD elif align_size == 16: flag = ida_bytes.FF_OWORD if flag == None: ida_kernwin.warning(&quot;align size is invalid&quot;) return while start &lt; end: ida_bytes.create_data(start, flag, align_size, ida_idaapi.BADADDR) start += align_size </code></pre>
1973
2013-05-01T12:12:02.280
<p>I have a large section in IDA that is a data lookup table of word length data. I want to change them all to word length rather than byte length. I know you can make an array but when I do it becomes an array of bytes.</p>
How to change a large section of bytes to words in IDA Pro
|ida|
<h2>With source</h2> <p>You could use something like <a href="http://research.sensepost.com/tools/mobile/xapspy">XAPSpy</a> and <a href="https://github.com/andreycha/tangerine">Tangerine</a> on Github which is updated to work with WP8. It may work without source not sure.</p> <p>XAPSpy Source: <a href="https://github.com/sensepost/XAPSpy">Github</a>. </p> <h2>Without source</h2> <p>Something more advanced is need something more like <a href="http://www.securityninja.co.uk/application-security/windows-phone-app-analyser-v1-0-released-today-2/">Windows Phone App Analyser</a> </p> <p>Download/Source: <a href="http://sourceforge.net/projects/wpaa/">SourceForge</a></p> <p>I would imagine you could use them both together by decompliling the .xap you are working with with WPPA and then using XAPSpy on that source. I've never tried that though.</p> <p>Sadly if you are dealing with a newer app you won't be able to decompile it as <a href="http://forum.xda-developers.com/showthread.php?t=2140706">they are encrypted</a>. You might be able to somehow get the keys out of the operating system but that would be difficult as well.</p> <p>Here is a set of slides on the topic: <a href="http://www.slideshare.net/AndreyChasovskikh/inspection-of-windows-phone-applications">Inspection of Windows Phone Applciations</a> that goes into some detail about tangerine.</p>
1977
2013-05-01T16:57:56.057
<p>I'm interested in debugging and monitoring a Windows Phone 8 application for which I do not have the source code. Android and iOS can both be rooted/jailbroken, which allows me to use tools like GDB (and others) to debug and monitor a running application, but I'm not aware of anything similar for Windows Phone 8.</p> <p>Additionaly I want to monitor filesystem activity while running the application (I use <a href="http://www.newosxbook.com/src.jl?tree=listings&amp;file=3-filemon.c">Filemon for iOS</a> for this task on iOS). Or is it easier to simply run the application in the Windows Phone 8 simulator and attempt to monitor the app that way?</p> <p>How do you debug a Windows Phone 8 application without source code?</p>
How can I debug or monitor a Windows Phone 8 application?
|windowsphone|
<p>Although it doesn't support breakpoints, <a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx" rel="nofollow noreferrer">Process Monito</a>r is an excellent tool to monitor registry access. Using Filters you can easily choose which keys you want to include, exclude, highlight etc. It also allows you to view the stack trace of any event.</p> <blockquote> <p>Process Monitor is an advanced monitoring tool for Windows that shows real-time file system, Registry and process/thread activity. It combines the features of two legacy Sysinternals utilities, Filemon and Regmon, and adds an extensive list of enhancements including rich and non-destructive filtering, comprehensive event properties such session IDs and user names, reliable process information, full thread stacks with integrated symbol support for each operation, simultaneous logging to a file, and much more. Its uniquely powerful features will make Process Monitor a core utility in your system troubleshooting and malware hunting toolkit.</p> </blockquote> <p><img src="https://i.stack.imgur.com/P1DcF.gif" alt="enter image description here"> <img src="https://i.stack.imgur.com/3evMc.gif" alt="enter image description here"></p>
1979
2013-05-01T20:49:47.897
<p>I have WinDbg attached to a process I don't have the source code for. I've set a breakpoint with <code>bm ADVAPI32!_RegOpenKeyExW@20</code>. The output of dv is:</p> <pre><code>Unable to enumerate locals, HRESULT 0x80004005 Private symbols (symbols.pri) are required for locals. Type ".hh dbgerr005" for details. </code></pre> <p>The output of kP is:</p> <pre><code>0:000&gt; kP ChildEBP RetAddr 001ae174 5b73a79c ADVAPI32!_RegOpenKeyExW@20 001ae1cc 5b77bb20 msenv!?ReadSecurityAddinSetting@@YG_NPAGK@Z+0x8a 001ae468 5b781aad msenv!? QueryStatusCmd@CVSCommandTarget@@QAEJPBVCIcmdGuidCmdId@@PBU_GUID@@KQAU_tagOLECMD@@PAU_tagOLECMDTEXT@@@Z+0x254 001ae49c 5b786073 msenv!?IsCommandVisible@CVSShellMenu@@QAEJPBVCIcmdGuidCmdId@@_N@Z+0xbf 001ae4e4 5b785fd2 msenv!?IsCommandVisible@CSurfaceCommandingSupport@@UAGJABU_COMMANDTABLEID@@_NPAH@Z+0xa0 . . . </code></pre> <p>What can I do to look at the values of the paramaters passed (particularly the second one: <em>LPCTSTR lpSubKey</em>)? Also, what can I do to set a conditional breakpoint based on the value?</p> <p>I have the Visual Studio debugger as well as WinDbg. I'm willing to try other tools as well.</p>
How do I see the parameters passed to RegOpenKeyEx, and set a conditional breakpoint?
|debugging-symbols|windbg|
<p><code>%fs:028h</code> is actually using the form <code>segment:offset</code>, which means it is reaching the memory address at offset <code>28h</code> in the segment selected by the Far Segment <code>FS</code>.</p> <p>Any memory reference has an implicit segment (most of the time, <code>CS</code> for execution, <code>DS</code> for data read/write), which can be overriden by a segment prefix.</p>
1990
2013-05-03T07:13:20.343
<p>When I disassemble a function, I encounter from time to time an expression of the form <code>%reg:value</code>. Typically, I encounter this syntax when I activate the canaries in GCC (<code>-fstack-protector</code>), as in the following example:</p> <pre><code>(gdb) disas Dump of assembler code for function foo: 0x000000000040057c &lt;+0&gt;: push %rbp 0x000000000040057d &lt;+1&gt;: mov %rsp,%rbp 0x0000000000400580 &lt;+4&gt;: sub $0x20,%rsp 0x0000000000400584 &lt;+8&gt;: mov %edi,-0x14(%rbp) =&gt; 0x0000000000400587 &lt;+11&gt;: mov %fs:0x28,%rax 0x0000000000400590 &lt;+20&gt;: mov %rax,-0x8(%rbp) 0x0000000000400594 &lt;+24&gt;: xor %eax,%eax 0x0000000000400596 &lt;+26&gt;: mov $0x4006ac,%edi 0x000000000040059b &lt;+31&gt;: callq 0x400440 &lt;puts@plt&gt; 0x00000000004005a0 &lt;+36&gt;: mov -0x8(%rbp),%rax 0x00000000004005a4 &lt;+40&gt;: xor %fs:0x28,%rax 0x00000000004005ad &lt;+49&gt;: je 0x4005b4 &lt;foo+56&gt; 0x00000000004005af &lt;+51&gt;: callq 0x400450 &lt;__stack_chk_fail@plt&gt; 0x00000000004005b4 &lt;+56&gt;: leaveq 0x00000000004005b5 &lt;+57&gt;: retq </code></pre> <p>What is the meaning of this kind of syntax?</p>
What does %reg:value mean in ATT assembly?
|disassembly|x86|assembly|
<p>Let me summarize the links given at <a href="https://reverseengineering.stackexchange.com/a/1993/12321">https://reverseengineering.stackexchange.com/a/1993/12321</a> without going into serious disasembly analysis for now. </p> <p>When the Linux kernel + dynamic linker is going to run a binary with <code>exec</code>, it traditionally just dumped the ELF section into a known memory location specified by the linker during link time.</p> <p>So, whenever your coded:</p> <ul> <li>referenced a global variable inside your code</li> <li>called a function from inside your code</li> </ul> <p>the compiler + linker could just hardcode the address into the assembly and everything would work.</p> <p>However, how can we do it when dealing with shared libraries, which must necessarily get loaded at potentially different addresses every time to avoid conflicts between two shared libraries?</p> <p>The naive solution would be to keep relocation metadata on the final executable, <a href="https://stackoverflow.com/questions/3322911/what-do-linkers-do">much like the actual linker does</a> and whenever the program is loaded, have the dynamic linker go over every single access and patch it up with the right address.</p> <p>However, this would be too time consuming, since there could be a lot of references to patch on a program, and then that program would take a long time to start running.</p> <p>The solution, as usual, is to add another level of indirection: the GOT and PLT, which are two extra chunks of memory setup by the compilation system + dynamic linker.</p> <p>After the program is launched, the dynamic linker checks the address of shared libraries, and hacks up the GOT and PLT so that it will point correctly to the required shared library symbols: </p> <ul> <li><p>whenever a global variable of a shared library is accessed by your program, the compiler + linker emits instead two memory accesses:</p> <pre><code>mov 0x200271(%rip),%rax # 200828 &lt;_DYNAMIC+0x1a0&gt; mov (%rax),%eax </code></pre> <p>The first one load the true address of the variable from the GOT, which the dynamic linker previously set, into <code>rax</code>.</p> <p>The second indirect access actually accesses the variable indirectly through the address from <code>rax</code>.</p></li> <li><p>for code, things are a bit more complicated.</p> <p>Whenever a function from a shared library is called, the linker makes us jump to an address in the PLT.</p> <p>The first time the function is called, the PLT code uses offsets stored in the GOT to decide the actual final location of the function, and then:</p> <ul> <li>stores this pre-calculated value</li> <li>jumps there</li> </ul> <p>The next times the function is called, the value has already been calculated, so it just jumps there directly.</p> <p>Due to this lazy resolution mechanism:</p> <ul> <li>programs can start running quickly even if the shared libraries have a lot of symbols</li> <li>we can replace functions on the fly by playing with the <code>LD_PRELOAD</code> variable</li> </ul></li> </ul> <p>Nowadays, <a href="https://stackoverflow.com/questions/2463150/what-is-the-fpie-option-for-position-independent-executables-in-gcc-and-ld">position independent executables (PIE)</a> are the default on distros such as Ubuntu 18.04.</p> <p>Much like shared libraries, these executables are compiled so that they can be placed at a random position in memory whenever they are executed, in order to make certain vulnerabilities harder to exploit.</p> <p>Therefore, it is not possible to hardcode absolute function and variable addresses anymore in that case. Executables must either:</p> <ul> <li>user instruction pointer relative addressing if those are available on the assembly language, e.g.: <ul> <li>ARMv8: <ul> <li><code>B</code> does 26-bit jumps, <code>B.cond</code> 19-bit</li> <li><a href="https://stackoverflow.com/questions/28638981/howto-write-pc-relative-adressing-on-arm-asm/54480999#54480999">"LDR (literal)"</a> does 19-bit loads</li> <li><code>ADR</code> calculates 21-bit relative addresses that other instructions can use</li> </ul></li> </ul></li> <li>use the GOT / PLT otherwise</li> </ul>
1992
2013-05-03T08:39:11.810
<p>From time to time, when disassembling x86 binaries, I stumble on reference to <code>PLT</code> and <code>GOT</code>, especially when calling procedures from a dynamic library.</p> <p>For example, when running a program in <code>gdb</code>:</p> <pre><code>(gdb) info file Symbols from "/home/user/hello". Local exec file: `/home/user/hello', file type elf64-x86-64. Entry point: 0x400400 0x0000000000400200 - 0x000000000040021c is .interp 0x000000000040021c - 0x000000000040023c is .note.ABI-tag 0x000000000040023c - 0x0000000000400260 is .note.gnu.build-id 0x0000000000400260 - 0x0000000000400284 is .hash 0x0000000000400288 - 0x00000000004002a4 is .gnu.hash 0x00000000004002a8 - 0x0000000000400308 is .dynsym 0x0000000000400308 - 0x0000000000400345 is .dynstr 0x0000000000400346 - 0x000000000040034e is .gnu.version 0x0000000000400350 - 0x0000000000400370 is .gnu.version_r 0x0000000000400370 - 0x0000000000400388 is .rela.dyn 0x0000000000400388 - 0x00000000004003b8 is .rela.plt 0x00000000004003b8 - 0x00000000004003c6 is .init =&gt; 0x00000000004003d0 - 0x0000000000400400 is .plt 0x0000000000400400 - 0x00000000004005dc is .text 0x00000000004005dc - 0x00000000004005e5 is .fini 0x00000000004005e8 - 0x00000000004005fa is .rodata 0x00000000004005fc - 0x0000000000400630 is .eh_frame_hdr 0x0000000000400630 - 0x00000000004006f4 is .eh_frame 0x00000000006006f8 - 0x0000000000600700 is .init_array 0x0000000000600700 - 0x0000000000600708 is .fini_array 0x0000000000600708 - 0x0000000000600710 is .jcr 0x0000000000600710 - 0x00000000006008f0 is .dynamic =&gt; 0x00000000006008f0 - 0x00000000006008f8 is .got =&gt; 0x00000000006008f8 - 0x0000000000600920 is .got.plt 0x0000000000600920 - 0x0000000000600930 is .data 0x0000000000600930 - 0x0000000000600938 is .bss </code></pre> <p>And, then when disassembling (<code>puts@plt</code>):</p> <pre><code>(gdb) disas foo Dump of assembler code for function foo: 0x000000000040050c &lt;+0&gt;: push %rbp 0x000000000040050d &lt;+1&gt;: mov %rsp,%rbp 0x0000000000400510 &lt;+4&gt;: sub $0x10,%rsp 0x0000000000400514 &lt;+8&gt;: mov %edi,-0x4(%rbp) 0x0000000000400517 &lt;+11&gt;: mov $0x4005ec,%edi =&gt; 0x000000000040051c &lt;+16&gt;: callq 0x4003e0 &lt;puts@plt&gt; 0x0000000000400521 &lt;+21&gt;: leaveq 0x0000000000400522 &lt;+22&gt;: retq End of assembler dump. </code></pre> <p>So, what are these GOT/PLT ?</p>
What is PLT/GOT?
|x86|binary-analysis|elf|amd64|
<p>Yes, the base address of <code>libc.so.6</code> should be <code>0xb7e5c000</code> for that binary. You can verify this by catting <code>/proc/&lt;pid&gt;/maps</code> while your application is running.</p>
1994
2013-05-03T15:26:58.313
<p>I'm on a Linux machine with ASLR disabled. Running <code>ldd</code> on a binary gives me the following result :</p> <pre><code>linux-gate.so.1 =&gt; (0xb7fe1000) libc.so.6 =&gt; /lib/i386-linux-gnu/libc.so.6 (0xb7e5c000) /lib/ld-linux.so.2 (0xb7fe2000) </code></pre> <p>Does this mean that <code>libc.so.6</code> will be loaded at the address <code>0xb7e5c000</code>? I'm trying to build a ROP chain for an old CTF challenge and I'd like to get gadgets from the library. I'm looking to know the base address of the library so that I can add it to the offsets of the gadgets.</p>
Base address of shared objects from ldd output
|linux|libraries|dynamic-linking|
<p>A challenge in writing a tool to extract the control flow of python bytecode is that there are so many Python bytecodes versions to choose from, about 25 or so by now (if you include pypy variants).</p> <p>The bytecode in the example graph with its <code>JUMP_IF_FALSE</code> followed by some <code>POP_TOP</code>s and <code>PRINT_NEWLINE</code> instruction, reflect Python before 2.7. </p> <p>However the example in one of the comments from the Flare_bytecode_graph with its <code>POP_TOP_IF_FALSE</code> is 2.7. Python 3 drops the <code>PRINT_ITEM</code> instruction.</p> <p>Anyone writing such a tool will have to come to grips with that; or be happy with living in a single version of Python, for which 2.7 is probably the most popular choice. Or you could ensure that the version of Python you are running matches the bytecode you want to analyze and use the current <em>dis</em> and <em>opcode</em> modules that Python provides. But even here those modules change over time, not in the least being the particular bytecode instructions.</p> <p>I wrote a python package called <a href="https://pypi.python.org/pypi/xdis" rel="nofollow noreferrer">xdis</a> for those who want to work across all versions of Python bytecode, and don't want to be tied with using the same version of Python that the bytecode requires.</p> <p>The next thing that you'll probably want to do in this endeavor is to classify instructions into categories like those which can branch and those that can't and if the branch is conditional or not. </p> <p>Python has some lists that cover some of this, ("hasjrel", "hasjabs") but alas it doesn't have the categories that are most useful. And for possibly historical reasons the categories are lists rather than sets. But again xdis to the rescue here; it fills this information in with sets "CONDITION_OPS", "JUMP_UNCONDITIONAL" and "JUMP_OPS". </p> <p>Using this I've written <a href="https://github.com/rocky/python-control-flow" rel="nofollow noreferrer">https://github.com/rocky/python-control-flow</a> which uses xdis and has some rudimentary code that will create a control flow graph and dominator tree for most Python bytecodes. There is some code to create dot files and I use graphviz to display that. I notice that Python, can create a lot of dead code.</p> <p>The intended use of that package is to reconstruct high-level Python control structures. There is some rudimentary control structure detection, although this needs a lot more work. Python control structures are pretty rich when you include the try/while/for "else" clauses, and the "finally" clauses. Even as is, the annotated control flow of the basic blocks very helpful in manually reconstructing structured control flow.</p> <p>When this is finished, I can replace a <em>lot</em> of the hacky code for doing that in <a href="https://pypi.python.org/pypi/uncompyle6" rel="nofollow noreferrer">uncompyle6</a>. </p> <p>And this leads me to the list of decompilers mentioned in the accepted answer...</p> <p>As stated, those particular versions of uncompyle and uncompyle2 handle only Python 2.7. As suggested, there are older versions that handle multiple Python versions 1.5 to 2.3 or 2.4 or so. That is if you have a Python 2.3 or 2.4 interpreter to run this on.</p> <p><strong>But none of these projects are actively maintained</strong>. In uncompyle, there are <a href="https://github.com/gstarnberger/uncompyle/issues" rel="nofollow noreferrer">currently 25 or so issues with the code</a>, many that I have fixed in uncompyle6. And this is for a version of Python that no longer changes! (To be fair though there are some bugs in uncompyle6 that don't exist in uncompyle2. And to address those, I'd really need to put in place that better control flow analysis) </p> <p>A number of the bugs in uncompyle could easily be fixed by just doing the same thing that uncompyle6 does, and I think some of that I've noted in the issues. At this point uncompyle2 is much better than uncompyle, and if you are only interested in Python 2.7, that is the most accurate.</p> <p>As for pycdc, while it is pretty good for its relatively small size (compared to uncompyle6), it too isn't maintained to the level that it would need to keep up with Python changes. So it is weak around Python 3.4 or so and gets progressively weaker for later versions. Uncompyle6 is like that too, but currently less so. <a href="https://github.com/zrax/pycdc/issues" rel="nofollow noreferrer">pycdc has over 60 issues logged against it</a> and I doubt those will be addressed anytime soon. Some of them aren't <em>that</em> difficult to fix. My own (possibly slanted) comparison of those two decompilers is <a href="https://github.com/rocky/python-uncompyle6/wiki/pycdc-compared-with-uncompyle6" rel="nofollow noreferrer">https://github.com/rocky/python-uncompyle6/wiki/pycdc-compared-with-uncompyle6</a></p>
1999
2013-05-03T17:06:20.423
<p>Recently on <a href="http://www.reddit.com/r/ReverseEngineering" rel="noreferrer">Reddit ReverseEngineering</a> I stumbled on a <a href="http://www.reddit.com/r/ReverseEngineering/comments/1da222/selfmodifying_python_bytecode/" rel="noreferrer">self-modifying code in Python</a>. Looking at the <a href="https://github.com/0vercl0k/stuffz/tree/master/Python%27s%20internals" rel="noreferrer">Github</a> repository was quite instructive and I found picture of the Python bytecode program exposed in CFG form:</p> <p><img src="https://i.stack.imgur.com/TKeQM.png" alt="enter image description here"></p> <p>I am wondering if there are tools to perform static analysis on Python bytecode program with some nice features (such as generating the CFG or allowing to manipulate the code, ...) ?</p>
What are the tools to analyze Python (obfuscated) bytecode?
|tools|python|
<p>A great resource for old tools is the <a href="http://www.sac.sk/" rel="noreferrer">SAC server</a>. From a quick search <a href="ftp://ftp.sac.sk/pub/sac/utilprog/resgrabr.exe" rel="noreferrer">Resource Grabber</a> seems to support NE resources, though the UI is annoying to use.</p> <p>Another options is <a href="http://hp.vector.co.jp/authors/VA003525/emysoft.htm#6" rel="noreferrer">eXeScope</a> (shareware).</p> <p>Also, long time ago I found somewhere a tool with the name <code>dresplay.exe</code>. I don't have it at hand right now and Google doesn't seem to know about it...</p>
2000
2013-05-03T20:49:37.897
<p>I'm trying to extract menus and other stuff from a <a href="https://en.wikipedia.org/wiki/New_Executable" rel="noreferrer">New Executable (NE)</a>, i.e. the ones from Windows' 16-bit times. The tools I find (e. g. ResourceTuner) work for <a href="https://en.wikipedia.org/wiki/Portable_Executable" rel="noreferrer">PEs</a> only.</p> <p>Any idea for tools to facilitate the resource extraction? Could be several steps too, e.g. one program extracting the raw resources, one displaying them in a proper form.</p>
How can one extract resources from a New Executable?
|tools|ne|
<p>i wrote a windows specific answer to a question that was marked as duplicate and closed and the close flag referred to this thread so i post an answer here </p> <p><strong>os win7 sp1 32 bit machine<br> kernel dump using livekd from sysinternals</strong></p> <p>a 16 bit segment register contains<br> 13 bits of selector<br> 1 bit of table descriptor<br> 2 bits of requester_privilege_level </p> <pre><code>Selector tl rpl 0000000000000----0---00 </code></pre> <p>so cs and fs converted to binary will be </p> <pre><code>kd&gt; r cs;r fs cs=00000008 = 0b 00001 0 00 fs=00000030 = 0b 00110 0 00 </code></pre> <p>2 bits rpl means 0,1,2,3 rings ( so 00 = 0 = ring zero) </p> <p>gdt = 1 bit means 0,1 (0 is for <strong>GDT</strong> and 1 is for <strong>LDT</strong>)</p> <p>global descriptor table and local descriptor table </p> <p>the high 13 bits represent segment selector</p> <p>so cs = 0x08 has a segment selector of 0b 001 = 0x1 ie gdtr@1<br> &amp; fs = 0x30 has a segment selector 0f 0b 110 = 0x6 ie gdtr@6 </p> <p>the kernel cs,fs are different from user cs,fs as can be noticed from dg command from windbg </p> <pre><code>kd&gt; dg @cs &lt;&lt;&lt;&lt;&lt;&lt;&lt;--- kernel P Si Gr Pr Lo Sel Base Limit Type l ze an es ng Flags ---- -------- -------- ---------- - -- -- -- -- -------- 0008 00000000 ffffffff Code RE Ac 0 Bg Pg P Nl 00000c9b 0:000&gt; dg @cs &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;----user P Si Gr Pr Lo Sel Base Limit Type l ze an es ng Flags ---- -------- -------- ---------- - -- -- -- -- -------- 001B 00000000 ffffffff Code RE Ac 3 Bg Pg P Nl 00000cfb kd&gt; dg @fs &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;------- kernel P Si Gr Pr Lo Sel Base Limit Type l ze an es ng Flags ---- -------- -------- ---------- - -- -- -- -- -------- 0030 82f6dc00 00003748 Data RW Ac 0 Bg By P Nl 00000493 0:000&gt; dg @fs P Si Gr Pr Lo Sel Base Limit Type l ze an es ng Flags ---- -------- -------- ---------- - -- -- -- -- -------- 003B 7ffdf000 00000fff Data RW Ac 3 Bg By P Nl 000004f3 </code></pre> <p>you can glean sufficient information about gdt from<br> <a href="http://wiki.osdev.org/Global_Descriptor_Table" rel="noreferrer">osdevwiki_gdt</a><br> <a href="http://www.rcollins.org/ddj/Aug98/Aug98.html" rel="noreferrer">robert-collins_ddj_article</a></p> <p>to do that manually im using livekd here</p> <p>using windbg you can get the Descriptor and Task Gate Registers</p> <pre><code>kd&gt; rM 100 gdtr=80b95000 gdtl=03ff idtr=80b95400 idtl=07ff tr=0028 ldtr=0000 </code></pre> <p>each gdtr entry is 64 bits so you can have 7f gdtr entries as you can see gdtl is 3ff 0x80*0x08-1 = 0x400-1 = 0x3ff (index starts from 0 not 1)</p> <p>so gdtr entry @1,@2 are @gdtr+(0x1*0x8) @gdtr+(0x2*0x08=0x10) and so on</p> <pre><code>kd&gt; dq @gdtr+8 l1 gdtr@1 = gdtr+0n1*0x8 =0n8 = 0x8 80b95008 00cf9b00`0000ffff = gdtr+0n6*0x8 =0n48 = 0x30 kd&gt; dq @gdtr+30 l1 80b95030 824093f6`dc003748 kd&gt; dq @gdtr+38 l1 80b95038 7f40f3fd`e0000fff </code></pre> <p>lets bit game the last two gdtr entries manually </p> <pre><code>------------------------------------------------------------------------------------------- gdtrentry [63: [55: [51: [47: [39: [15: 56] 52] 48] 40] 16] 0] base gdrs L p d t Base Base Limit Hi rb0y h r l y Mid Low ------------------------------------------------------------------------------------------- bit position 66665555 5555 5544 4 44 44444 33333333 3322222222221111 1111110000000000 32109876 5432 1098 7 65 43210 98765432 1098765432109876 5432109876543210 ------------------------------------------------------------------------------------------- 824093f6dc003748 10000010 0100 0000 1 00 10011 11110110 1101110000000000 0011011101001000 as hex 0x82 0100 0 1 0 0x13 0xF6 0xDC00 0x3748 --------------------------------------- --------------------------------------------------- 7f40f3fde0000fff 01111111 0100 0000 1 11 10011 11111101 1110000000000000 0000111111111111 as hex 0x7F 0100 0 1 3 0x13 0xFD 0xE000 0x0FFF ------------------------------------------------------------------------------------------- </code></pre>
2006
2013-05-04T06:18:49.163
<p>I try to understand the process of memory segmentation for the i386 and amd64 architectures on Linux. It seems that this is heavily related to the segment registers <code>%fs</code>, <code>%gs</code>, <code>%cs</code>, <code>%ss</code>, <code>%ds</code>, <code>%es</code>. </p> <p>Can somebody explain how these registers are used, both, in user and kernel-land programs ?</p>
How are the segment registers (fs, gs, cs, ss, ds, es) used in Linux?
|linux|x86|assembly|amd64|
<p>Several great answers here, and the one posted by Igor is perfect for debugging the service before it actually starts. One piece of insight I would like to contribute is looking into the malware to see if there are any threads that are created that hold the functionality you wish to review. </p> <p>Oftentimes in my analysis, I've dealt with malware that runs as a service, but rather than go through some of the hoops you need to go through to launch a debugger when the service is invoked, I often have luck looking at the malware for a main thread that is spun off after initial criteria for the service startup is handled. Once I find the 'main', thread (assuming it exists and is standalone) I will just load the DLL/EXE in Olly, set my new origin on the thread start and proceed on with my debugging.</p> <p>End of day, its really just a different approach, but something to possibly consider if the situation presents itself. </p>
2019
2013-05-07T21:04:43.703
<p>I'm trying to debug a malware sample that installs to a system as service and then will only start if it starts as a service. Other functions are still available without the service start, like configuring or install under a different name. </p> <p>I'm trying to catch the network communications the malware is sending and receiving as soon as it starts as a service. If I attach to a running service/process with Immunity it already has sent the network packets and received, and I've missed what it has done with them. If I try to start it any other way I get the following error: <code>ERROR_FAILED_SERVICE_CONTROLLER_CONNECT</code> (00000427). </p> <p>Is there another way to go about this? Or some workaround? I'm fairly new to this so I certainly be missing some obvious.</p>
Debugging malware that will only run as a service
|windows|malware|debuggers|networking|
<p>All ATMs that I am aware of and have worked on in a past life have a way to get into 'admin' mode either from the front or a rear keypad. Methods vary. Sniffing a network probably won't help as the communication is encrypted. That said, buy one: <a href="http://www.atmexperts.com/used_atm_machines.html">http://www.atmexperts.com/used_atm_machines.html</a> <a href="http://www.bellatm.net/Default.asp">http://www.bellatm.net/Default.asp</a> Then you'll have all the time and access you could want - and, unless you misuse anything learned, will avoid prison.</p>
2023
2013-05-08T13:31:05.560
<p>This question is using ATMs as an example, but it could apply to any number of 'secure' devices such as poker machines, E-voting machines, payphones etc. </p> <p>Given that ATMs are relatively hardened (in comparison to say, most consumer electronics for example), what would be the process of reverse engineering a device in a black-box AND limited access scenario?</p> <p>Given that traditionally, an end user of a device such as an ATM will only ever have access to the keypad/screen/card input/cash outlet (at a stretch, access to perhaps the computer housed in the top of the plastic casing(think private ATMs at small stores etc)), it seems like most attack vectors are quite limited. Under these types of circumstances, what could be done to reverse, understand and potentially exploit hardened, limited access systems?</p> <p>Is the 'ace up the sleeve' kind of situation here physical access to the ATM components? Or is there a way to RE a device from within the environment a user is presented?</p>
How to reverse engineer an ATM?
|hardware|security|physical-attacks|
<p>I do not know of a disassembler that will do this, but I have written a Java decompiler that has a bytecode output mode. It is open source, and it would be easy enough to modify to suit your needs. Feel free to check it out <a href="https://bitbucket.org/mstrobel/procyon/overview" rel="nofollow">here</a>.</p>
2036
2013-05-10T23:22:18.610
<p>I am after a java bytecode disassembler whose output includes the bytecodes themselves, their operands, and their addresses in the .class file, and which displays numbers in hex, not decimal.</p> <p>To show what I mean, here are a few lines taken from the output of javap:</p> <pre><code>private java.text.SimpleDateFormat createTimeFormat(); Code: Stack=3, Locals=2, Args_size=1 0: new #84; //class java/text/SimpleDateFormat 3: dup 4: ldc #17; //String yyyy-MM-dd'T'HH:mm:ss 6: invokespecial #87; //Method java/text/SimpleDateFormat."&lt;init&gt;":(Ljava/lang/String;)V 9: astore_1 </code></pre> <p>Every java bytecode disassembler I have found (I have spent much time on google, and downloaded several different ones to try) produces output which is essentially the same as this. Some format or decorate it slightly differently; some replace the command line interface with a fancy GUI; but not one of them displays the addresses of the instructions in the .class file, nor the bytecodes themselves - there are several which <em>claim</em> to show the bytecodes, but none of them actually do, they display only the textual mnemonics representing the bytecodes rather than the bytecodes themselves. Also, they all display the numerical information in decimal, not in hex.</p> <p>Here is an edited version of the above output which I have transformed by hand to produce an example of the sort of thing I am looking for:</p> <pre><code>private java.text.SimpleDateFormat createTimeFormat(); Code: Stack=3, Locals=2, Args_size=1 000010cf 0: bb 00 54 new #54; //class java/text/SimpleDateFormat 000010d2 3: 59 dup 000010d3 4: 12 11 ldc #11; //String yyyy-MM-dd'T'HH:mm:ss 000010d5 6: b7 00 57 invokespecial #57; //Method java/text/SimpleDateFormat."&lt;init&gt;":(Ljava/lang/String;)V 000010d8 9: 4c astore_1 </code></pre> <p>The addresses at the start of the lines correspond to the position of the instructions in the .class file, as one would find in a plain hexdump. The hex representations of the bytecodes and their operands are shown, and the disassembly shows the constants in hex.</p> <p>Is there anything available which would produce output resembling this? It does not matter if the fields are in a different order, as long as they are all there. It must run on Linux, either natively or under java.</p>
Wanted: Java bytecode disassembler that shows addresses, opcodes, operands, in hex
|java|hex|disassemblers|
<p>Even stripped libraries still must retain the symbols necessary for dynamic linking. These are usually placed in a section named <code>.dynsym</code> and are also pointed to by the entries in the dynamic section.</p> <p>For example, here's the output of <code>readelf</code> on a stripped Android library:</p> <pre><code>Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .hash HASH 000000b4 0000b4 000280 04 A 2 0 4 [ 2] .dynsym DYNSYM 00000334 000334 0005b0 10 A 3 6 4 [ 3] .dynstr STRTAB 000008e4 0008e4 00042f 00 A 0 0 1 [ 4] .rel.dyn REL 00000d14 000d14 000008 08 A 2 2 4 [ 5] .rel.plt REL 00000d1c 000d1c 000100 08 A 2 6 4 [ 6] .plt PROGBITS 00000e24 000e24 000214 04 AX 0 0 4 [ 7] .text PROGBITS 00001038 001038 00210c 00 AX 0 0 8 [ 8] .rodata PROGBITS 00003144 003144 000a70 00 A 0 0 4 [ 9] .ARM.extab PROGBITS 00003bb4 003bb4 000024 00 A 0 0 4 [10] .ARM.exidx ARM_EXIDX 00003bd8 003bd8 000170 00 AL 7 0 4 [11] .dynamic DYNAMIC 00004000 004000 0000c8 08 WA 3 0 4 [12] .got PROGBITS 000040c8 0040c8 000094 04 WA 0 0 4 [13] .data PROGBITS 0000415c 00415c 000004 00 WA 0 0 4 [14] .bss NOBITS 00004160 004160 000940 00 WA 0 0 4 [15] .ARM.attributes ARM_ATTRIBUTES 00000000 004160 000010 00 0 0 1 [16] .shstrtab STRTAB 00000000 004170 000080 00 0 0 1 </code></pre> <p>You can see that even though it's missing the <code>.symtab</code> section, the <code>.dynsym</code> is still present. In fact, the section table can be removed as well (e.g. with <code>sstrip</code>) and the file will still work. This is because the dynamic linker only uses the program headers (aka the segment table):</p> <pre><code>Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align EXIDX 0x003bd8 0x00003bd8 0x00003bd8 0x00170 0x00170 R 0x4 LOAD 0x000000 0x00000000 0x00000000 0x03d48 0x03d48 R E 0x1000 LOAD 0x004000 0x00004000 0x00004000 0x00160 0x00aa0 RW 0x1000 DYNAMIC 0x004000 0x00004000 0x00004000 0x000c8 0x000c8 RW 0x4 </code></pre> <p>The <code>DYNAMIC</code> segment corresponds to the <code>.dynamic</code> section and contains information for the dynamic linker:</p> <pre><code>Dynamic section at offset 0x4000 contains 21 entries: Tag Type Name/Value 0x00000001 (NEEDED) Shared library: [liblog.so] 0x00000001 (NEEDED) Shared library: [libcutils.so] 0x00000001 (NEEDED) Shared library: [libc.so] 0x00000001 (NEEDED) Shared library: [libstdc++.so] 0x00000001 (NEEDED) Shared library: [libm.so] 0x0000000e (SONAME) Library soname: [libnetutils.so] 0x00000010 (SYMBOLIC) 0x0 0x00000004 (HASH) 0xb4 0x00000005 (STRTAB) 0x8e4 0x00000006 (SYMTAB) 0x334 0x0000000a (STRSZ) 1071 (bytes) 0x0000000b (SYMENT) 16 (bytes) 0x00000003 (PLTGOT) 0x40c8 0x00000002 (PLTRELSZ) 256 (bytes) 0x00000014 (PLTREL) REL 0x00000017 (JMPREL) 0xd1c 0x00000011 (REL) 0xd14 0x00000012 (RELSZ) 8 (bytes) 0x00000013 (RELENT) 8 (bytes) 0x6ffffffa (RELCOUNT) 1 0x00000000 (NULL) 0x0 </code></pre> <p>The two entries here necessary for symbol resolution are <code>STRTAB</code> and <code>SYMTAB</code>. They together make up the dynamic symbol table:</p> <pre><code>Symbol table '.dynsym' contains 91 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00001038 0 SECTION LOCAL DEFAULT 7 2: 00003144 0 SECTION LOCAL DEFAULT 8 3: 00003bb4 0 SECTION LOCAL DEFAULT 9 4: 0000415c 0 SECTION LOCAL DEFAULT 13 5: 00004160 0 SECTION LOCAL DEFAULT 14 6: 00000000 0 FUNC GLOBAL DEFAULT UND clock_gettime 7: 000026e1 88 FUNC GLOBAL DEFAULT 7 ifc_init 8: 00000001 20 FUNC GLOBAL DEFAULT UND strcpy 9: 00002d6d 140 FUNC GLOBAL DEFAULT 7 open_raw_socket [...] </code></pre> <p>You can see that it contains both <code>UND</code> (undefined) symbols - those required by the library and imported from other .so, and the "normal" global symbols which are exported by the library for its users. The exported symbols have their addresses inside the library listed in the Value column.</p>
2038
2013-05-11T10:09:14.170
<p>Lately I've been reversing the Android framework for the Nexus S mobile phone. 99% of the source code is of course open, but there are few propriety shared libraries which needs to be downloaded in order to compile the operating system. These shared libraries are stripped from symbols and suddenly I came to understand that I don't really understand how stripped libraries are linked against. How can the linker match referenced library functions if the symbols don't exist?</p>
How are stripped shared libraries linked against?
|linux|elf|libraries|
<p>Hard to say with so little info, but I suspect that you edited the data after it has already been parsed by the game code. You probably need to intercept the moment it arrives from the remote server and change it then.</p>
2039
2013-05-11T11:16:55.810
<p>I was trying to change the values of a Flash game which loads the SWF and some JSON over a HTTPS site. So changing the values of JSON was not possible using browser cache.</p> <p>I changed the values of that JSON by editing the memory of the Adobe Flash process by loading it in <a href="http://mh-nexus.de/en/hxd/" rel="nofollow">HxD</a>. Still I wasn't able to see the changed values inside Firefox.</p> <p>Can anybody guide as to what protects the changed values from reflecting?</p>
No apparent effect after editing some JSON in the memory of a Flash process
|flash|
<p>If your application is compiled to a binary you might still be able to use normal debuggers like IDA. However, Lua has its own tools for decompiling from machine code and byte code. These links should be kept up to date by the Lua community. </p> <p><strong>Lua Wiki:</strong> <a href="http://lua-users.org/wiki/LuaTools">LuaTools</a></p> <p>If you need support for Lua 5.2 <a href="https://github.com/mlnlover11/LuaAssemblyTools">LuaAssemblyTools</a> is the first to support that.</p>
2049
2013-05-16T16:17:12.610
<p>Since <code>Lua</code> is an interpreted/compiled language that its own compilers and isn't usually translated/compiled with a C compiler. What tools should be used to reverse engineer an application written in <code>Lua</code>?</p>
Where can I find tools for reverse engineering Lua
|disassembly|tools|decompile|byte-code|
<p>You can use <code>#pragma pack(1)</code> before the declaration.</p>
2051
2013-05-17T13:29:00.033
<p>I defined a struct in a header file, similar to this one:</p> <pre><code>struct STRUCT { char a; int b; }; </code></pre> <p>This is parsed successfully by IDA, however it adds padding bytes after the <code>char</code>:</p> <pre><code>00000000 STRUCT struc ; (sizeof=0x4) 00000000 a db ? 00000001 db ? ; undefined 00000002 b dw ? 00000004 STRUCT ends </code></pre> <p>I can't remove the padding field using <kbd>u</kbd>, so the question is: How can one remove padding fields automatically inserted by IDA, or how can one prevent IDA from creating padding fields?</p>
How to prevent automatic padding by IDA?
|ida|
<p>Usually you only get addresses and raw bytes, but some tools/compilers may use custom record types or add extra information. For example, Tasking VX toolchain for Tricore uses an S0 record for identification:</p> <blockquote> <p><strong>S0-record</strong></p> <pre><code>'S' '0' &lt;length_byte&gt; &lt;2 bytes 0&gt; &lt;comment&gt; &lt;checksum_byte&gt; </code></pre> <p>A linker generated S-record file starts with a S0 record with the following contents:</p> <p>length_byte : 0x6<br> comment : ltc (TriCore linker)<br> checksum : 0xB6</p> <pre><code> l t c S00600006C7463B6 </code></pre> <p>The S0 record is a comment record and does not contain relevant information for program execution.</p> </blockquote>
2056
2013-05-19T06:10:18.827
<p>When working with embedded systems, it is often easiest to use a downloadable firmware file rather than recover the firmware from the device.</p> <p>Mostly these are ROM images in the form of a .bin file. Sometimes, they are Motorola SREC files (often called .s19 files or .mot files). </p> <p>These are easily converted into bin files using many available tools. The SREC files tend to only contain records where there is actually data/code and the gaps are filled with padding values during conversion. Padding tends to be 0x00 or 0xFF.</p> <p>This can gives us a hint about the data segment of the image - it allows us to tell if the memory has been initialised with 0x00/0xFF intentionally by the compiler/assembler, or if it is just padding. Sometimes this can make identifying data structures easier.</p> <p>Is there anything else an SREC file can leak?</p>
Does a Motorola SREC file give me any additional information over a binary ROM image?
|firmware|embedded|
<p>BinNavi was just <a href="https://github.com/google/binnavi" rel="nofollow">released as open source</a> today by Google, so you can get it for free.</p> <p>About using it with something else than REIL, if you're fearless, you can give a try to <a href="http://radare.org" rel="nofollow">radare2</a>, since it <a href="https://github.com/radare/radare2/pull/2341" rel="nofollow">can translate</a> its intermediary language <a href="https://github.com/radare/radare2/wiki/ESIL" rel="nofollow">ESIL</a>, to REIL.</p>
2058
2013-05-19T18:45:53.677
<p><a href="https://www.zynamics.com/binnavi.html" rel="nofollow noreferrer">BinNavi</a> is originally a <a href="https://www.zynamics.com/" rel="nofollow noreferrer">Zynamics</a> product. But, since the company has been bought by Google, it seems to be difficult to get the library.</p> <p>I tried to look in the <a href="https://www.zynamics.com/binnavi/manual/" rel="nofollow noreferrer">BinNavi manual</a> in the <a href="https://www.zynamics.com/binnavi/manual/html/installation.htm" rel="nofollow noreferrer">installation</a> chapter. But, I couldn't find any way to get the source code or a binary package.</p> <p>Is there any hope that the code or, at least, a binary form of BinNavi become available at some point ? </p> <p>And, about the BinNavi API, is it possible to use BinNavi with other languages than REIL or is BinNavi hard linked with it ?</p> <p><img src="https://www.zynamics.com/images/binnavi_screenshot_5.png" alt="BinNavi Example"></p>
Is BinNavi available? If not, can I get the source from anywhere?
|tools|binary-analysis|
<p>Parsing PE files correctly is hard and there are almost always ways to make tools crash or refuse to work, while the Windows loader still executes the program normally. See e.g. <a href="https://www.virusbtn.com/pdf/conference_slides/2007/CaseySheehanVB2007.pdf" rel="nofollow">Pimp My PE</a>, <a href="https://media.blackhat.com/bh-us-11/Vuksan/BH_US_11_VuksanPericin_PECOFF_WP.pdf" rel="nofollow">Undocumented PECOFF</a></p> <p>A loop in the resource tree structure might be enough to crash Resource Hacker.</p> <p>Although these papers are mainly about malicious files, this applies for non-malicious ones as well, if the owner wanted to protect them or if he just happened to use a compiler or packer that violates the PECOFF specification or certain conventions.</p>
2060
2013-05-19T22:33:29.790
<p>I use <a href="http://www.angusj.com/resourcehacker/" rel="nofollow">Resource Hacker</a> Application for Reverse Engineering purposes, I've cracked 3 softwares by using this software, but it doesn't grab all <code>.EXE</code>, <code>.DLL</code> files.<br> sometimes It says, This is not a valid Win32 executable file, but I've provided it a valid Win32 File. <br> Any Solution please, Thanks in advance</p>
Why my Resource Hacker doesn't work with some .EXE files
|windows|unpacking|executable|decompiler|
<p>Just to add to the list. SANS posted a blog about a week ago on different tools for XOR encryption. The list is very good and it provides several tools, all which are good in my opinion. </p> <p>Here is the link : <a href="http://computer-forensics.sans.org/blog/2013/05/14/tools-for-examining-xor-obfuscation-for-malware-analysis">SANS Blog on XOR tools</a></p>
2062
2013-05-20T16:44:55.427
<p>I know that modern cryptographic algorithms are as close as they can to fully random data (<a href="http://en.wikipedia.org/wiki/Ciphertext_indistinguishability">ciphertext indistinguishability</a>) and that trying to detect it is quite useless. But, what can we do on weak-crypto such as <strong>xor encryption</strong> ? Especially if we can get statistical studies of what is encrypted ? </p> <p>What are the methods and which one is the most efficient (and under what hypothesis) ? And, finally, how to break efficiently this kind of encryption (only based on a statistical knowledge of what is encrypted) ?</p>
What is the most efficient way to detect and to break xor encryption?
|cryptography|cryptanalysis|
<p>No, a debugger views code sequentially whereas a cpu may reorder code on the fly before it gets executed and even execute more than one instruction at a time. This is the case even for Simulators like Bochs. Simics on the other hand might implement something more in line with reality but I doubt it.</p> <p>Essentially the pipeline is supposed to be transparent to the programmer. As execution wise it should function the same as a single cycle implementation even though the performance would be much different.</p> <p>If you want the see the effect of passing different instructions through a pipeline what you want is a profiler.</p> <p>If you want a tool that will allow you to analyse the progress of the uOPs through the entire pipeline look for things like <a href="http://marss86.org/~marss86/index.php/Home">Marss86</a> which simulates down to the uOp level and will allow you to see the goings on inside the pipeline at least of the architecture they simulate. Note that there are various implementations of the x86 pipelines and your simulator of choice may or may not implement the exact one you are intending to target.</p>
2067
2013-05-21T21:03:33.103
<p>Instruction pipelining is used to execute instructions in a parallel fashion by dividing them into several steps .When I pause the execution in a debugger I am only able to see the location of the eip register but not the current pipeline state. Is there a way to find out ? </p>
How to view the instruction pipeline?
|machine-code|
<p>Other people have mentioned the downsides of this, but if you're still interested in this path, then <a href="https://github.com/jthuraisamy/SysWhispers2" rel="nofollow noreferrer">here's a lib</a> that converts the ntdll API names into syscalls.</p>
2070
2013-05-22T08:29:47.090
<p>I have compiled following C source code in VS2010 console project.</p> <pre><code>#include &lt;stdio.h&gt; int main(int argc, char* argv[]){ printf("hello world\n"); return 0; } </code></pre> <p>then I used <code>/MT</code> option for release mode to statically link the C-runtime library. However, as far as I know, C-runtime library still invokes lower level system functions - for example, C-runtime function <code>printf</code> eventually calls <code>WriteFile</code> Windows API.</p> <p>And the actual function body of <code>WriteFile</code> is in <code>kernel32.dll</code>. So, even if I link the C-runtime library statically, the binary doesn't contain the entire routine including the <code>SYSENTER</code>, or <code>INT 0x2E</code> instructions... The core part is still in a DLL. The following diagram describes how I understand it:</p> <p><img src="https://i.stack.imgur.com/w2XJH.png" alt="enter image description here"></p> <p>What I want is to statically link EVERYTHING into single EXE file. Including <code>kernel32.dll</code>, <code>user32.dll</code> to eliminate the necessity of loader parsing the IAT and resolving the function names.</p> <p>The following picture describes what I want:</p> <p><img src="https://i.stack.imgur.com/IQtdo.png" alt="enter image description here"></p> <p>I understand this is simple in Linux with <code>gcc</code>. All I have to do is give the option <code>-static</code></p> <p>Is there any option like this in VS2010? Please correct me if I'm misunderstanding.</p>
Can I statically link (not import) the Windows system DLLs?
|windows|dll|compilers|symbols|dynamic-linking|
<p>I like Robert explanation, it has a very good example, but.. I think it misses the point of which is the real purpose of this instruction. </p> <blockquote> <p>is done as a debugging aid and in some cases for exception handling</p> </blockquote> <p>Well.. not really, not only. It is part of the standard function prologue for x86 (32 bit), and it is the (common) technique to set up a function stack frame, so that parameters and locals are accessible as fixed offsets of <code>ebp</code>, which is, after all, the *B*ase frame *P*ointer.</p> <p>Making <code>ebp</code> equal to <code>esp</code> at function entry, you will have a fixed, relative pointer inside the stack, that will not change for the lifetime of your function, and you will able to access parameters and locals as (fixed) positive and (fixed) negative offsets, respectively, to <code>ebp</code>.</p> <p>You can or cannot see this standard prologue in release, optimized code: optimizers can do (and often do) FPO (frame pointer optimization) to get rid of <code>ebp</code> and just use <code>esp</code> inside your function to access params and locals. This is much trickier (I would not do it by hand) as <code>esp</code> can vary during the function lifetime, and therefore a parameter, for example, can be accessed using 2 different offsets at two distinct points in the code.</p>
2073
2013-05-22T14:42:12.397
<p>When execution enters a new function by performing call I do often see this code template (asm list generated by Gnu Debugger when in debugging mode):</p> <pre><code>0x00401170 push %ebp 0x00401171 mov %esp,%ebp 0x00401173 pop %ebp </code></pre> <p>So what's the purpose of moving esp to ebp?</p>
What purpose of mov %esp,%ebp?
|disassembly|
<p>When loading time is involved the entry point is DllMain.<br> (Ex. COM in-process server DLL).<br> When running time is involved the entry point is DllEntryPoint.<br> (Ex. LoadLibrary get called). </p>
2079
2013-05-22T19:33:34.490
<p>I have a piece a malware to analyze. It is a DLL according to the <code>IMAGE_FILE_HEADER-&gt;Characteristics</code>. I was trying to do some dynamic analysis on it. I have done the following:</p> <ul> <li>Run it with <code>rundll32.exe</code>, by calling its exports. Nothing.</li> <li>Changed the binary's characteristics to an exe. Nothing.</li> </ul> <p>So I moved on to static analysis, Loaded on IDA and OllyDbg. Which brings me to my question. :)</p> <p><strong>What is the main difference between <code>DllMain</code> and <code>DllEntryPoint</code>?</strong></p> <p><strong>When/How does one get call vs the other?</strong></p> <p><strong>[EDIT]</strong></p> <p>So after reading MSDN and a couple of books on MS programming. I understand <code>DllEntryPoint</code>. <code>DllEntryPoint</code> is your <code>DllMain</code> when writing your code. Right?! So then why have <code>DllMain</code>. In other words, when opening the binary in IDA you have <code>DllEntryPoint</code> and <code>DllMain</code>.</p> <p>I know it is probably something easy but I am visual person, so obviously not seeing something here.</p>
Difference between DllMain and DllEntryPoint
|windows|malware|dll|
<p>You can use <a href="https://github.com/x64dbg/ScyllaHide" rel="noreferrer">ScyllaHide</a>. There are plugins for many debuggers, but it is also possible to use <code>InjectorCLI.exe</code> to inject ScyllaHide into any process. Here are the steps (for a 32 bit process, if you want a 64 bit process, replace every <code>x86</code> with <code>x64</code>):</p> <ol> <li>Extract ScyllaHide (<a href="https://github.com/x64dbg/ScyllaHide/releases" rel="noreferrer">download</a>) anywhere;</li> <li>Run <code>NtApiTool\x86\PDBReaderx86.exe</code> and when it's finished, copy <code>NtApiCollection.ini</code> to the same directory as <code>InjectorCLIx86.exe</code>;</li> <li>Open <code>ScyllaTest_x86.exe</code> with WinDbg (x86) you should be in <code>LdrpDoDebuggerBreak</code>;</li> <li>Execute <code>InjectorCLIx86.exe ScyllaTest_x86.exe HookLibraryx86.dll</code>;</li> <li>Run (F5) in WinDbg.</li> </ol> <p>Without using ScyllaHide:</p> <p><img src="https://i.stack.imgur.com/e7hK5.png" alt="no hiding"></p> <p>When using ScyllaHide:</p> <p><img src="https://i.stack.imgur.com/gps0Z.png" alt="hiding"></p> <p>This process works for any debugger, if you feel like it you can even make an actual plugin for WinDbg. It should be quite easy.</p> <p>I just added an option to inject to a process by process id. You can do this with:</p> <pre><code>InjectorCLIx86.exe pid:1234 HookLibraryx86.dll </code></pre>
2082
2013-05-23T04:11:09.953
<p>Are there any good WinDbg hiding plugins like OllyDbg's? Or a plugin that's open source and still in development for this purpose?</p>
Debugger hiding plugin for WinDbg?
|debuggers|anti-debugging|windbg|
<p>Yes. </p> <ol> <li>Find the address of kernel32 using anyone of the known tricks (PEB or any other way) </li> <li>Implement a simple export section parser and find the address of <code>LoadLibrary</code> and <code>GetProcAddress</code>. </li> <li>Use those to load any other API you want.</li> </ol>
2092
2013-05-24T20:33:55.447
<p>while reading the answers to <a href="https://reverseengineering.stackexchange.com/q/2070/245">Can I statically link (not import) the Windows system DLLs?</a> I came up with another question. So: </p> <ol> <li>Is there a way to write a program that has no dependencies (nothing is statically compiled too - it has <strong>only</strong> my code) and everything is resolved during run-time assuming that <code>kernel32.dll</code> will be loaded/mapped into the process no matter what?</li> <li>Is my assumption about <code>kernel32.dll</code> correct?</li> </ol> <p>During run-time, I mean using the <code>PEB</code> structure.</p>
Program with no dependencies
|windows|malware|development|winapi|
<p>You can use <a href="https://github.com/radareorg/r2dec-js" rel="nofollow noreferrer">r2dec</a> plugin on <a href="https://rada.re" rel="nofollow noreferrer">radare2</a> with command <code>pdda</code></p> <pre><code>[0x08048060]&gt; pdda ; assembly | /* r2dec pseudo code output */ | /* ret @ 0x8048060 */ | #include &lt;stdint.h&gt; | ; (fcn) entry0 () | int32_t entry0 (void) { | do { | /* [01] -r-x section size 23 named .text */ 0x08048060 mov cl, byte [eax] | cl = *(eax); 0x08048062 cmp cl, 0x20 | | if (cl &gt;= 0x20) { 0x08048065 jb 0x804806c | 0x08048067 cmp cl, 0x2c | | if (cl != 0x2c) { 0x0804806a jne 0x804806f | goto label_0; | } | } 0x0804806c mov byte [eax], 0x20 | *(eax) = 0x20; | label_0: 0x0804806f mov cl, byte [eax + 1] | cl = *((eax + 1)); 0x08048072 inc eax | eax++; 0x08048073 test cl, cl | 0x08048075 jne 0x8048060 | | } while (cl != 0); | } [0x08048060]&gt; </code></pre>
2096
2013-05-25T19:15:24.437
<p>How could this 32-bit x86 assembly be written in C?</p> <pre><code>loc_536FB0: mov cl, [eax] cmp cl, ' ' jb short loc_536FBC cmp cl, ',' jnz short loc_536FBF loc_536FBC: mov byte ptr [eax], ' ' loc_536FBF mov cl, [eax+1] inc eax test cl, cl jnz short loc_536FB0 </code></pre> <p>I have already figured out that it is a for loop that loops 23 times before exiting.</p>
convert this x86 ASM to C?
|assembly|x86|c|
<p>Igor is right on, here are a few additional tips I have to offer. </p> <p>Make sure when declaring variables within your structure, that you are accurately accommodating for the size of the variable. For example, is it a DWORD or some other multibyte buffer (maybe a memset/memcpy can give you a clue on its size here in these cases)? </p> <p>Accurately accounting for these kinds of things is important when dealing with structures with many objects. It can help with your overall understanding of how it is used within the program, as well as further defining structure members</p> <p>Also, keep in mind you can name the fields as you normally would any other variable in IDA. To be thorough, you can also declare the field type in the structure tab, to do this, right-click the field, then select field type.</p> <p>Finally, when declaring the size of a multibyte array within a structure for example, you can actually do so in hex by just pre-pending '0x' in the array size field. Doesn't seem like much but it's a small tip that can come in handy.</p> <p>There is so much more to explore concerning structures and their use within IDA. If you are looking to learn more about this and IDA in general, then I would highly recommend Chris Eagle's IDA Pro Book. </p> <p><a href="http://www.idabook.com/">http://www.idabook.com/</a></p>
2098
2013-05-25T20:10:23.460
<p>For example, in the following disassembly:</p> <pre><code>.text:007C6834 014 mov eax, [esi+4] .text:007C6837 014 mov dword ptr [esi], offset ??_7CAvatar@@6B@ ; const CAvatar::`vftable' </code></pre> <p>How would I be able to set the type of the esi register to a struct, so that in an ideal world the disassembly would turn into:</p> <pre><code>.text:007C6834 014 mov eax, [esi.field_04] .text:007C6837 014 mov dword ptr [esi.vtable], offset ??_7CAvatar@@6B@ ; const CAvatar::`vftable' </code></pre>
How do you set registers as structs within a function in IDA?
|ida|disassembly|struct|
<p>The trick is to find the object's constructor. Let's suppose the code looks like this:</p> <pre><code>a = new CFoo(); a-&gt;bar(); </code></pre> <p>The compiler (I assume MSVC, 32bits) might produce something like this:</p> <pre><code>push 12h ; size_t call ??2@YXYXY@Z ; operator new(uint) mov [ebp+var_8], eax mov esi, eax test esi, esi jz loc_1 mov ecx, esi call ??0CFoo@@AAAA@AA ; CFoo::CFoo(void) mov [ebp+var_8], eax jmp loc_2 loc_1: mov [ebp+var_8], 0 loc_2: ... ... ... mov eax, [ebp+var_8] mov ecx, [eax] mov ebx, ecx mov ecx, [ebp+var_8] call dword ptr [ebx+08h] </code></pre> <p>Looking at <code>??0CFoo@@AAAA@AA</code>, a.k.a. <code>CFoo::CFoo():</code></p> <pre><code>... mov esi, ecx mov dword ptr [esi], unk_12345 ... </code></pre> <p><code>unk_12345</code> is <code>CFoo</code>'s virtual table offset:</p> <pre><code>unk_12345: dd offset sub_23456 dd offset sub_34567 dd offset sub_45678 ... </code></pre> <p>And that <code>sub_45678</code> at <code>unk_12345+08h</code> (which would be 3rd entry, in this case) is what gets called, i.e. <code>CFoo::bar()</code>.</p>
2119
2013-05-28T12:17:15.000
<p>For learning (<em>and fun</em>) I have been analyzing a text editor application using IDA Pro. While looking at the disassembly, I notice many function calls are made by explicitly calling the name of the function. For example, I notice IDA translates most function calls into the following two formats.</p> <pre><code>call cs:CoCreateInstance </code></pre> <p>Or</p> <pre><code>call WinSqmAddToStream </code></pre> <p>But sometimes the format does not use a function name. The following example includes the code leading up to the line in question. The third line of code seem to be "missing" the function name. (The comments are my own.)</p> <pre><code>mov rcx, [rsp+128h+var_D8] // reg CX gets the address at stack pointer+128h+var_D8 bytes mov r8, [rcx] // the address at reg CX is stored to reg r8 call qword ptr [r8 + 18h] // at address rax+18h, call function defined by qword bytes </code></pre> <p>My questions are as follows:</p> <ol> <li><p>How do I make the connection between <code>call qword ptr &lt;address&gt;</code> and a function in the disassembly?</p></li> <li><p>I understand that IDA cannot use a function name here since it does not know the value stored at the register R8... so what causes this? Was there a certain syntax or convention used by the developer? In other words, did the developer call the function <code>WinSqmAddToStream</code> in a different manner than the function at <code>[r8+18h]</code>?</p></li> </ol>
What to do when IDA cannot provide a function name?
|ida|disassembly|
<p><code>ollydbg 1.10</code> automatically refreshes the memory window when protection attributes are changed if the address that is passed on to VirtualProtect lies in the first allocated page</p> <p>if subsequent page's attributes were changed using Virtualprotect ollydbg's memory window wont reflect them as it shows the complete allocated Size as one contiguous dump </p> <p>windbg <code>!vprot</code> will show the modified protection attributes only if you traverse page by page</p> <p>in <code>ollydbg 2.01</code> memory window will show attribute changes page by page automatically</p> <p>an example</p> <pre><code>int _tmain(int argc, _TCHAR* argv[]) { printf("lets valloc \n"); PCHAR foo; foo = (PCHAR)VirtualAlloc(0,0x1004,MEM_COMMIT,PAGE_READONLY); printf("we valloced lets vprot\n"); DWORD oldprot; if ( (VirtualProtect(foo+0x1000,1,PAGE_EXECUTE_READWRITE,&amp;oldprot) == FALSE) ) { printf("our vprot failed\n"); return FALSE; } if ( (VirtualProtect(foo+0xfff,1,PAGE_EXECUTE_READWRITE,&amp;oldprot) == FALSE) ) { printf("our vprot failed\n"); return FALSE; } printf("we vprotted fine \n"); return 0; } </code></pre> <p><strong>ollydbg 1.10 memory window Display will be same after VirtualAlloc and after first Virtualprotect</strong></p> <p><strong>display will change only after second VirtualProtect</strong></p> <pre><code>Memory map, item 19 Address=003A0000 Size=00002000 (8192.) Owner= 003A0000 (itself) Section= Type=Priv 00021002 Access=R Initial access=R </code></pre> <p>after second Virtualprotect</p> <pre><code>Memory map, item 19 Address=003A0000 Size=00002000 (8192.) Owner= 003A0000 (itself) Section= Type=Priv 00021040 **Access=RWE** Initial access=R </code></pre> <p>windbg will show changed attribute only if traversed page by page</p> <pre><code>0:000&gt; g ModLoad: 5cb70000 5cb96000 C:\WINDOWS\system32\ShimEng.dll Breakpoint 0 hit &gt; 8: { 0:000&gt; p &gt; 9: printf("lets valloc \n"); 0:000&gt; p &gt; 11: foo = (PCHAR)VirtualAlloc(0,0x1004,MEM_COMMIT,PAGE_READONLY); 0:000&gt; p &gt; 12: printf("we valloced lets vprot\n"); 0:000&gt; ?? foo char * 0x003a0000 "" 0:000&gt; !vprot @@c++(foo) BaseAddress: 003a0000 AllocationBase: 003a0000 AllocationProtect: 00000002 PAGE_READONLY RegionSize: 00002000 State: 00001000 MEM_COMMIT Protect: 00000002 PAGE_READONLY Type: 00020000 MEM_PRIVATE 0:000&gt; p &gt; 14: if ( (VirtualProtect(foo+0x1000,1,PAGE_EXECUTE_READWRITE,&amp;oldprot) == FALSE) ) 0:000&gt; p &gt; 19: if ( (VirtualProtect(foo+0xfff,1,PAGE_EXECUTE_READWRITE,&amp;oldprot) == FALSE) ) 0:000&gt; !vprot @@c++(foo) BaseAddress: 003a0000 AllocationBase: 003a0000 AllocationProtect: 00000002 PAGE_READONLY RegionSize: 00001000 State: 00001000 MEM_COMMIT Protect: 00000002 PAGE_READONLY Type: 00020000 MEM_PRIVATE 0:000&gt; !vprot (@@c++(foo)+1000) BaseAddress: 003a1000 AllocationBase: 003a0000 AllocationProtect: 00000002 PAGE_READONLY RegionSize: 00001000 State: 00001000 MEM_COMMIT Protect: 00000040 PAGE_EXECUTE_READWRITE Type: 00020000 MEM_PRIVATE </code></pre> <p>ollydbg 2.01 will show any changes instantly note memory map item no and address </p> <pre><code>Memory map, item 19 Address = 003A0000 Size = 00002000 (8192.) Owner = 003A0000 (self) Section = Contains = Type = Priv 00021002 Access = R Initial access = R Mapped as = </code></pre> <p>after first Virtualprotect</p> <pre><code>Memory map, item 20 Address = 003A1000 Size = 00001000 (4096.) Owner = 003A0000 Section = Contains = Type = Priv 00021040 Access = RWE Initial access = R Mapped as = </code></pre>
2123
2013-05-28T14:52:22.493
<p>I'm looking for a way to view memory permissions on a specific section of memory using OllyDbg (technically I'm using Immunity but I'm assuming if it exists in Olly it'll be the same there).</p> <p>The program I'm looking at is calling VirtualProtect to make a block of code go RW->RWE, but the result looks like the protection is extending to 4 bytes before the address passed in as a parameter. I checked the MSDN and it said that there is a rounding/boundary extension with t VirtualProtect with respect to the size, but it doesn't say specifically how the extensions get propagated across pages.</p> <p>I'm confident that's what's happening but I wanted to look at the memory permissions for the specific segment to confirm. It doesn't look like the Memory map refreshes after the call to VP and I couldn't find another place to show the memory permissions. On WinDbg I can do something like !vprot so I was curious if there was something similar here.</p>
Viewing memory permissions in Ollydbg for memory segments
|windows|ollydbg|