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>The easiest way to find out the function in question would probably be by dynamic analysis. You can easily do this by placing a breakpoint on that instruction in a debugger and examining the registers. </p> <p>A more general solution would probably involve some scripting to record all calls and add that information to the IDA database. <a href="https://github.com/deresz/funcap">Funcap</a> plugin does something similar if not exactly what you are looking for:</p> <blockquote> <p>This script records function calls (and returns) across an executable using IDA debugger API, along with all the arguments passed. It dumps the info to a text file, and also inserts it into IDA's inline comments. This way, static analysis that usually follows the behavioral runtime analysis when analyzing malware, can be directly fed with runtime info such as decrypted strings returned in function's arguments.</p> </blockquote>
2127
2013-05-28T16:36:23.640
<p>I am reverse engineering some code from which IDA has generated the following disassembly. These specific lines of code are just for illustrative purposes. Notice that the third line does not call a specifc function by its name but rather by its address.</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>I'm interested in determining which function is being called. What mechanisms, tools, tricks, etc. can I use to determine which function in the dissassembly a call <code>qword ptr &lt;address&gt;</code> is referring to? I'm up for trying other disassembler programs.</p> <p>From an answer to my <a href="https://reverseengineering.stackexchange.com/questions/2119/what-to-do-when-ida-cannot-provide-a-function-name">previous question</a>, this is known as an "indirect call" or (perhaps a "virtual function call"). The disassembly has many of these, so how do I resolve them? In addition, IDA has identified hundreds of functions. How do I go about figuring out which one was actually being called during any given indirect call (or virtual call)? </p>
How to identify function calls in IDA Pro's disassembly?
|ida|disassembly|virtual-functions|
<p>I think the default in IDA 6.8 is a Cross reference depth of 16. I increased this first to 32 and then to 1024 and then to 65535 (because why not). None of this led to my xref working as desired so I must not understand something.</p> <p>I'm analyzing an ARM ELF shared object file. The function I'm looking at is called by a function referenced by an offset in the .init_array segment (not sure if that's relevant). The offset I want to see all references of is:</p> <pre><code>.bss:00424778 ; void *dword_424778 .bss:00424778 dword_424778 % 4 </code></pre> <p>It was originally identified as unk_424778 but I pressed <kbd>Y</kbd> and set the type was "void *".</p> <p>Hex Rays shows this assignment:</p> <pre><code> dword_424778 = &amp;_sF; </code></pre> <p>Using HexRaysCodeXplorer I press <kbd>J</kbd> to jump back to disassembly from Hex Rays. It put me on line 0026D69C:</p> <pre><code>... .text:0026D668 LDR R5, [R4,R2] ; unk_424758 .text:0026D66C ADD R0, R5, #0x1C .text:0026D670 STMIA R5, {R3,R7} .text:0026D674 STR R7, [R5,#8] .text:0026D678 STR R7, [R5,#0xC] .text:0026D67C STR R7, [R5,#0x10] .text:0026D680 STR R7, [R5,#0x14] .text:0026D684 STR R7, [R5,#0x18] .text:0026D688 BL sub_26F42C .text:0026D68C LDR R2, =(off_374A30 - 0x374C20) .text:0026D690 LDR R3, [SP,#0x38+var_34] .text:0026D694 STR R9, [R5] .text:0026D698 STR R8, [R5,#0x24] .text:0026D69C STR R11, [R5,#0x20] ... </code></pre> <p>I don't know ARM very well but I read that the STMIA R5, {R3,R7} will result in unpredictable behavior due to the reglist ({R3,R7}) starting with a lower-number register than Rn (R5).</p> <p>Could the problem be related to dword_424778 being in the .bss section?</p>
2130
2013-05-28T19:21:45.277
<p>In the IDA view I see (<code>glb_SomeVar</code> is a byte array):</p> <pre><code>cmp al, glb_SomeVar+22h </code></pre> <p>But when I hit <kbd>x</kbd> to find the cross references of glb_SomeVar, I only find two other matches in the same function:</p> <pre><code>cmp al, glb_SomeVar+0Ah cmp al, glb_SomeVar+0Bh </code></pre> <p>Is there a way to fix this, like making IDA re-analyze the selected function or even the whole code? I guess at other places, there are cross references missing too.</p>
IDA is not recognizing cross references
|ida|
<p>If you can not add something to the imports viewer you can write your own. Here is the simple example (it is slightly modified example referenced at <a href="http://www.hexblog.com/?p=229" rel="noreferrer">this hexblog entry</a> and located <a href="http://hexblog.com/ida_pro/files/ImportExportViewer.py" rel="noreferrer">here</a> with added double-click functionality, added columns, removed exports and fixed bug for a case of unknown origin of the imported function). See the function BuildImports for creating additional imports (manual_func1 and manual_func2)</p> <pre><code>import idaapi import idautils from idaapi import PluginForm from PySide import QtGui, QtCore class ImpExpForm_t(PluginForm): def imports_names_cb(self, ea, name, ord): self.items.append((ea, '' if not name else name, ord)) # True -&gt; Continue enumeration return True def BuildImports(self): tree = {} nimps = idaapi.get_import_module_qty() for i in xrange(0, nimps): name = idaapi.get_import_module_name(i) if not name: name = "unknown" # Create a list for imported names self.items = [] # Enum imported entries in this module idaapi.enum_import_names(i, self.imports_names_cb) if name not in tree: tree[name] = [] tree[name].extend(self.items) tree["manually_added"] = [(0x01, "manual_func1", 3), (0x02, "manual_func2",4)] return tree def PopulateTree(self): # Clear previous items self.tree.clear() # Build imports root = QtGui.QTreeWidgetItem(self.tree) root.setText(0, "Imports") for dll_name, imp_entries in self.BuildImports().items(): imp_dll = QtGui.QTreeWidgetItem(root) imp_dll.setText(0, dll_name) for imp_ea, imp_name, imp_ord in imp_entries: item = QtGui.QTreeWidgetItem(imp_dll) item.setText(0, "%s" % imp_name) item.setText(1, "0x%08x" % imp_ea) item.setText(2, "0x%08x" % imp_ord) def dblclick(self, item): try: idaapi.jumpto(int(item.text(1).encode("ascii", "ignore"), 16)) except: print "Can not jump" def OnCreate(self, form): """ Called when the plugin form is created """ # Get parent widget self.parent = self.FormToPySideWidget(form) # Create tree control self.tree = QtGui.QTreeWidget() self.tree.setColumnCount(4) self.tree.setHeaderLabels(("Names","Address", "Ordinal", "Source")) self.tree.itemDoubleClicked.connect(self.dblclick) self.tree.setColumnWidth(0, 100) # Create layout layout = QtGui.QVBoxLayout() layout.addWidget(self.tree) self.PopulateTree() # Populate PluginForm self.parent.setLayout(layout) def OnClose(self, form): """ Called when the plugin form is closed """ global ImpExpForm del ImpExpForm print "Closed" def Show(self): """Creates the form is not created or focuses it if it was""" return PluginForm.Show(self, "Imports / Exports viewer", options = PluginForm.FORM_PERSIST) # -------------------------------------------------------------------------- def main(): global ImpExpForm try: ImpExpForm except: ImpExpForm = ImpExpForm_t() ImpExpForm.Show() # -------------------------------------------------------------------------- main() </code></pre>
2133
2013-05-29T16:04:24.183
<p>The title says most of it. Say I have a Windows PE (x86, 32bit) binary (just so we have case to discuss), the imports list will usually only show the imports found in the import directory. The attributes it shows are address of the function, name and library from which it got imported as shown in this screenshot snippet:</p> <p><img src="https://i.stack.imgur.com/KYZWX.png" alt="Screenshot of import tab in IDA Pro"></p> <p>Is there a way for me through scripting (IDC or Python, I don't care too much), to add imports of my own to the list and, for example, have them point (the address attribute) to code such as this (highlighted line)?:</p> <p><img src="https://i.stack.imgur.com/4lUw2.png" alt="Dynamically imported function in IDA Pro"></p> <p>I.e. the line would in such case look like:</p> <pre><code>0DCBA987 GetLongPathNameW kernel32.dll </code></pre> <p>or even just</p> <pre><code>0DCBA987 GetLongPathNameW ??? </code></pre> <p>assuming the above <code>call GetProcAddress</code> would be at address <code>0DCBA987</code>.</p> <p>The advantage to me would be readability. But it would also yield a more comprehensive list of imports (and consequently xrefs) as some functions are frequently imported dynamically due to their availability in the various Windows versions.</p> <p>It should be quite trivial given a certain binary to figure out all xrefs to candidate functions that retrieve the imported function's address (such as <code>GetProcAddress</code>) and then walk their calls to find which function was imported. The DLL part may be more complicated to find out, but it could be left empty or entered manually. But I didn't find a function that would allow me to add imports. Is there a way?</p>
In IDA, is there a way to add a reference to a dynamically imported function into the Imports tab?
|ida|idapython|import-reconstruction|ida-plugin|
<p><strong>Note:</strong> I am assuming 32bit x86 on Windows, your question unfortunately doesn't state for certain. But since it's Windows and you don't explicitly mention x64 this was the sanest assumption I could make.</p> <p>First off, try to search for the function names with a search engine. Don't just settle for a single search engine. Failing that, inspect whatever came in the package with the DLL. Are there import LIBs included? If so, use these to provide clues (may or may not work).</p> <h2>Otherwise ...</h2> <p>Most disassemblers (read the tag wiki <a href="/questions/tagged/tools" class="post-tag" title="show questions tagged &#39;tools&#39;" rel="tag">tools</a>) will readily show you exported functions. So <em>locating</em> them won't be a problem at all. They will also usually be shown with their exported names.</p> <p>From the output your screenshot shows, it looks like the names aren't <a href="https://en.wikipedia.org/wiki/Name_mangling" rel="noreferrer">mangled/decorated</a>. This suggests - but is <em>not</em> conclusive <em>proof</em> - that the functions use the <code>stdcall</code> <a href="https://en.wikipedia.org/wiki/Calling_convention" rel="noreferrer">calling convention</a> (better yet read <a href="http://code.google.com/p/corkami/wiki/CallingConventions" rel="noreferrer">this one by Ange</a>, one of the moderators pro temp here). Now I don't know how much you know, but since you attempt RCE you are probably well-versed in calling conventions. If not let's sum it up like this: calling conventions govern how (order, alignment) and by what means (registers, stack) parameters get passed to functions. We'll get back to this in a moment. If you are on x64 Windows and the DLL is 64bit as well, you can rely on the Microsoft x64 calling convention (read <a href="https://en.wikipedia.org/wiki/X86_calling_conventions" rel="noreferrer">this article</a>).</p> <h2>Now there are two main routes you can take</h2> <h3>Route 1 - analyze a program using the DLL</h3> <p>If you happen to have a program that uses the DLL in question, you can use a debugger or disassembler to find out both the calling convention and the number of parameters passed. Simply look out for <code>call</code> instructions referencing the exported DLL functions and find <code>mov</code> or <code>push</code> instructions in front. If you happen to come across <code>cdecl</code> functions, the stack pointer (<code>esp</code>) will be adjusted again after the <code>call</code>. It's possible this is the case (see below for an example), but as unlikely as the various compiler-specific <code>fastcall</code> variants, since <code>stdcall</code> provides the broadest possible compatibility.</p> <p>The methods outlined below in the second approach will also explain some of the concepts introduced here in greater detail.</p> <h3>Route 2 - analyzing the DLL itself</h3> <p>If you happen to have IDA and you analyze a 32bit DLL, chances are that IDA already identified the number of parameters and the calling convention using its heuristics. Let me demonstrate (using <code>sqlite3.dll</code>). In the Exports tab find a function you're interested in and double-click it. This will take you to the address where the function starts (here <code>sqlite3_open</code>).</p> <p><img src="https://i.stack.imgur.com/jdRup.png" alt="enter image description here"></p> <p>As you can see IDA readily found that the function takes two arguments (you can look at <a href="http://www.sqlite.org/c3ref/open.html" rel="noreferrer">the SQLite3 docs</a> to verify this finding). However, there is another thing here. After the <code>call sqlite3_open_v2_0</code> we can see that the stack pointer is adjusted by 10h (=16) thereby cleaning up four parameters. Looking at the <code>push</code> instructions before the <code>call</code> we can see that indeed four 32bit (i.e. DWORD) parameters are passed via the stack. Since there is no further cleanup on part of the function <code>sqlite3_open</code> itself, it is now clear that it is likely following the C calling convention (<code>cdecl</code>) as well. Again we can verify the finding (a benefit you won't have) by looking at the documentation. And indeed since no explicit calling convention is given, you end up defaulting to <code>cdecl</code>. The single <code>retn</code> (some disassemblers will show <code>ret</code>), meaning <code>return</code>, also doesn't clean up the stack, since otherwise it would look like <code>retn 8</code> or similar.</p> <p>This is a rather small function, but even with the circumstantial information we are able to deduce a lot about it.</p> <p>Now for something <code>stdcall</code>, a case you are more likely to encounter as mentioned before. And why not go for something famous, like, say, <code>kernel32.dll</code> from Windows 7? Again, I'll take a trivial function as it is better to showcase the points. Note that I told IDA not to make use of the debug symbols from Microsoft and to skip using FLIRT signatures. This means some of the good stuff that kicks in by default is being suppressed to show how to identify what's going on. Look:</p> <p><img src="https://i.stack.imgur.com/nZ9Di.png" alt="enter image description here"></p> <p>The green lines are uninteresting for our case, but you'll encounter them a lot. It is commonly found in several compilers and <code>ebp</code> is commonly referred to as "frame pointer" (frame as in stack frame), basically an offset on which to base access to the stack variables. You can see a typical use in the line <code>push [ebp+arg_0]</code>. IDA figured this out and shows us <code>Attributes: bp-based frame</code>.</p> <p>We see no adjustment of the stack pointer after <code>call sub_77E29B80</code>, so it looks like that (internal) function follows the <code>stdcall</code> calling convention as well. However, the <code>ret 4</code> hints that the callee (i.e. the function <code>AddAtomA</code> in this case) is meant to clean up the stack, which means we can exclude <code>cdecl</code> as a possibility. It's four bytes because that is the "natural" size on a 32bit system. You can also see from my inline comments, that parameters are passed on the stack in reverse. But you should know such things anyway before engaging in RCE, otherwise read up in the above linked articles and in some books such as <a href="https://reverseengineering.stackexchange.com/a/1755/245">those here</a>.</p> <p>In this particular case we could dare to make another assumption, but it could bite us. Say this was Microsoft's <code>fastcall</code> convention (keep in mind that they vary by compiler), then the registers <code>ecx</code> and <code>edx</code> would be used, followed by arguments passed on the stack. This means that in our case we might want to assume that this can't be the case, because those registers aren't saved before calling <code>sub_77E29B80</code>. This is a good argument for machine-generated code such as this one. However, were this hand-optimized code, the programmer could rely on the knowledge about the calling convention and skip saving/restoring the registers before/after the <code>call</code>. Still, in this case hand-optimized code would be less likely (or unlikely) to make use of the frame pointer. It's three instructions that aren't strictly needed to do the job. So arguing like this - even without prior knowledge - we could now set out to write a little program using the prototype:</p> <pre><code>int __stdcall AddAtomA(void* unknown) </code></pre> <p>and use a debugger to see <em>what</em> gets passed. It's generally a tedious process, but a lot of the process - especially finding the number of parameters - can likely be scripted. Also, once you have a single function figured out, it's likely that the calling convention would be the same (exceptions exist, of course) throughout the DLL. Just make sure you analyze a function taking at least one parameter, otherwise you won't be able to distinguish between <code>stdcall</code> and <code>cdecl</code> from the circumstantial data.</p> <h3>Route X - the ugly one</h3> <p>You can also simply use <code>dumpbin</code> or a similar tool to script the creation of a test program. This test program would then call the function, check the stack pointer before and after and could thereby distinguish between <code>stdcall</code> and <code>cdecl</code>. You could also play tricks like passing 20 arguments on the stack (if you want to assume <code>stdcall</code> for the experiment) and see how much of that your callee cleaned up. There are loads of possibilities to simply try instead of analyze. But you'll get better (more reliable) results with the first two approaches.</p> <p>If you need to build an import LIB because you don't want to use <code>GetProcAddress</code>, see <a href="https://stackoverflow.com/a/15117763/476371">this answer by me over on StackOverflow</a>. It shows how to build an import LIB just from the DLL.</p> <h2>Conclusion</h2> <p>The methods won't differ too much with other disassemblers, I just needed to show things in a way you can reproduce them, that's why I went with IDA. The freeware edition of IDA will likely be sufficient (32bit, PE, x86) - keep in mind it's not permissible for commercial use, though.</p> <p>Screenshots taken from IDA 6.4.</p>
2134
2013-05-29T21:00:14.810
<p>I have an unknown .dll from another program which I want to work with. With <a href="http://www.nirsoft.net/utils/dll_export_viewer.html">DLL Export Viewer</a> I was able to find the exported functions.</p> <p><img src="https://i.stack.imgur.com/qIDYL.png" alt="enter image description here"></p> <p>But to call them I need the information about the parameters and the return type. </p> <ul> <li>Is there an easy way to identify them in the disassembly?</li> <li>Do tools exist which can extract those prototypes, or help me in a way?</li> </ul>
Get the function prototypes from an unknown .dll
|windows|dll|
<p>In a typical, non-packed Windows PE executable, the header contains metadata that describes to the operating system which symbols from other libraries that the executable depends upon. The operating system's loader is responsible for loading those libraries into memory (if they are not already loaded), and for placing the addresses of those imported symbols into structures (whose locations are also specified by the metadata) within the executable's memory image. Packers, on the other hand, often destroy this metadata, and instead perform the resolution stage (which would normally be performed by the loader) itself. The goal of unpacking is to remove the protections from the binary, including the missing import information. So the analyst (or unpacking tool) must determine the collection of imports that the packer loads for the executable, and re-create metadata within the unpacked executable's image that will cause the operating system to properly load the imports as usual. </p> <p>Typically in these situations, the analyst will determine where within the executable's memory image the import information resides. In particular, the analyst will usually locate the <code>IMAGE_THUNK_DATA</code> arrays, which are <code>NULL</code>-terminated arrays that contain the addresses of imported symbols. Then, the analyst will run a tool that basically performs the inverse of <code>GetProcAddress</code>: given one of these pointers to imported symbols, it will determine in which DLL the pointer resides, and which specific exported entry is referred to by the pointer. So for example, we might resolve <code>0x76AE3F3C</code> to <code>Kernel32!CreateFileW</code>. Now we use this textual information to recreate <code>IMAGE_IMPORT_DESCRIPTOR</code> structures describing each imported DLL, use the original addresses of the <code>IMAGE_THUNK_DATA</code> arrays, store the names of the DLLs and imported symbols somewhere in the binary (perhaps in a new section), and point the <code>IMAGE_THUNK_DATA</code> entries to those new names.</p> <p><a href="http://www.woodmann.com/collaborative/tools/index.php/ImpREC%E2%80%8E">ImpRec</a> is a popular tool that automates most or all of this process, depending upon the packer. What I just described is reflective of reality in about 95% of cases. More serious protections such as video game copy protections and tricky custom malware use further tricks that stymie the reconstruction process.</p>
2142
2013-05-30T22:15:57.203
<p>When reading about unpacking, I sometimes see an "import reconstruction" step. What is this and why is it necessary?</p>
What is import reconstruction and why is it necessary?
|unpacking|import-reconstruction|
<p>DynamoRIO could be very good for more in-depth dynamic library analysis. DynamoRIO is a dynamic binary translator that works on both Linux and Windows, for both x86 and x86-64.</p> <p>To analyse DLLs using DynamoRIO, you would register module load and unload events using the <code>dr_register_module_load_event</code> and <code>dr_register_module_unload_event</code> functions, respectively.</p> <p>You can also register events that allow you to manipulate instructions before they are executed. These events would enable you to isolate code that is executed from a particular DLL, and apply custom instrumentation to that DLL.</p>
2147
2013-05-31T03:25:59.193
<p>Are there techniques for dynamic analysis of shared libraries? I know for example that DLLs have an entry point, but how about calling other exported functions? Do I need to write a custom executable that calls exports for each DLL I want to analyze?</p>
Dynamic Analysis for Shared Libraries?
|dynamic-analysis|dll|
<p>Ok, I had a few e-mails with Fabrice Desclaux (aka serpilliere), one of the main contributor of miasm.</p> <p>In fact, miasm (version 1) cannot disassemble amd64 opcodes (but do not issue any error if such executable is encountered). What is really misleading, is that the elf-64 is handled but the disassembler fail to recognize the amd64 opcodes.</p> <p>So, this behavior is "normal" even if no error message is issued.</p> <p>The good news, is that the main contributor of miasm is working on a second version of the software (<code>miasm2</code>) which is handling amd64 (and with a lot of new features).</p>
2152
2013-05-31T12:59:09.943
<p>I am trying to use <a href="http://code.google.com/p/smiasm/" rel="nofollow">Miasm</a> to reverse some binaries in i386 and amd64 instruction sets, but I encounter a few problem when using it.</p> <p>First, the installation phase went nice. I managed to install <code>tinycc</code> with the small modification of the <code>Makefile</code> and the installation script did not complain.</p> <p>But, once I tried to use the script <code>miasm/example/disas_and_graph.py</code>, the CFG stop suddenly shortly after the entrypoint.</p> <p>Strangely, I installed Miasm on a 32bits virtual machine and it worked fine and displayed the whole CFG properly. So, did I miss something about a restriction or a bug on amd64 architecture ?</p>
Is miasm working on 64bits architecture?
|amd64|
<p>Following up alahel's answer, the date is indeed a number of milliseconds, but it includes 1 further bit to the left and is from the standard epoch of 1 Jan 1970. For example:</p> <pre><code>08014273ed2071a6800017 ~^^^^^^^^^^ </code></pre> <p>where it includes the least significant bit from the &quot;7&quot;, so 0x13ed2071a68, which corresponds to:</p> <pre><code>2013-05-23 15:34:41:00 (UTC) </code></pre> <p>There appears to be a 5 hour difference due to timezone.</p> <p>The author seems to have cared somewhat about being space-efficient by using exactly 41 bits - capable of reaching the year 2039 (whereas 40 bits would only reach 2004).</p>
2159
2013-06-01T10:36:24.940
<p>I have the following hex parts and I have a strong suspicion that behind them is a date of an event:</p> <pre><code>2013.05.23 20:35:00 08014273ed2071a6800017 2013.05.23 21:45:00 08014273ed246cf0000017 2013.05.24 17:10:00 08014273ed675173000017 2013.05.25 01:10:00 08014273ed82900f000017 2013.05.25 02:15:00 08014273ed8667b3800017 2013.05.25 17:15:00 08014273edb9c78e800017 2013.05.25 19:55:00 08014273edc2ee93000017 2013.05.25 20:30:00 08014273edc52a5a000017 2013.05.29 06:25:00 08014273eede5079000017 2013.05.29 06:35:00 08014273eedeac45000017 2013.05.29 06:40:00 08014273eedf09c6800017 2013.05.30 21:40:00 08014273ef64b021800017 </code></pre> <p>The first and the second are my observations of the event (I do not have an exact time for minutes and seconds), also it might be in my time zone. In the third column is hex value, which I suspect to be a presentation of this time. Currently I assume that <code>08</code> and <code>17</code> are just delimiters. </p> <p>I was looking for a timestamp representation and date time, but currently with no success. Any guess what it can be?</p> <p>P.S an update with some completely different dates. I will try to find also the earlier date possible. Thanks for help</p> <pre><code>2013.01.01 00:50:00 08014273bf2ba0ed000017 2012.12.15 03:25:00 08014273b9bbb8cd000017 </code></pre>
Trying to reverse engineer dump of a timestamp
|obfuscation|file-format|
<p>Based on <a href="http://pastebin.com/raw.php?i=t8BG08xf" rel="nofollow">the output</a> of <a href="http://www.solemnwarning.net/page/code#nedump" rel="nofollow">NE dumper</a>, the level data appears to begin at file offset 0x17600 and each level appears to be 0x200 bytes long.</p>
2160
2013-06-01T13:33:26.727
<p>I am trying to recreate an old game just for the sake of nostalgia and learning something new alongside (I can program in various languages and know a bit of assembly language, but I'm new to reverse engineering). The game is called Banania and looks like this:</p> <p><img src="https://i.stack.imgur.com/VNEfD.jpg" alt="enter image description here"></p> <p>Now, my problem is finding the level data of this game (It's only one .exe file, nothing else). If I would have made this game, I would have stored the levels (which seem to be of Size 21x13) in a three dimensional array (50x21x13) for 50 total levels. However, I just can't seem to find any rectangular pattern of that size that look like levels in my hex editor.</p> <p>How would you try to find it? I'd be grateful for some help.</p> <p>EDIT: After staring at the binaries for the whole day, I finally found the level data! I discovered it by luck, it was just a large chunk with only about 20 different numbers used. The format is exactly like I expected. Since I know how the levels look, it shouldn't be too hard to guess what integer stands for which item. Apparently, Integers on Windows 3.1 were 16 bit long (at least, that's my guess), that's why I didn't find it at first.</p>
Find level data in binaries?
|binary-analysis|
<p>Your best bet is <a href="https://bitbucket.org/haypo/hachoir/wiki/hachoir-subfile" rel="nofollow noreferrer">Hachoir-Subfile</a>. You can pass a file stream to Hachior-Subfile, it will search for all known embedded files and display the location. Some known formats it will calculate the size of the file. This makes it easy to carve out the files using dd. A helpful description of Hachoir-Subfile was left by one of the developers a couple weeks back in a similar <a href="https://reverseengineering.stackexchange.com/a/1664/1425">question</a>.</p>
2161
2013-06-01T14:33:48.113
<p>I have a .bin file I would like to analyse. Especially find images embedded in this firmware update.</p> <ul> <li><a href="https://code.google.com/p/binwalk/" rel="nofollow">binwalk</a> couldn't find anything.</li> </ul> <p>What other tools do you know to search for possible embedded files?</p>
Find file signatures inside an unknown file
|tools|binary-analysis|file-format|firmware|
<p>Without further information, it looks like deliberate obfuscation: instructions with no ultimate effect inserted into the code to make it harder to read. I doubt that code was generated by a compiler.</p>
2167
2013-06-02T03:08:42.323
<p>I have recently came across the following sequence of assembly instructions. </p> <pre><code>call ds:WSAStartup push ecx push edi mov ecx, 69E65AC4h mov edi, 2776452Ah pop edi pop ecx jmp short loc_ABCD </code></pre> <p>Please help me make sense of these particular 4 instructions below:</p> <pre><code>mov ecx, 69E65AC4h mov edi, 2776452Ah pop edi pop ecx </code></pre> <p>Why would you move direct values into registers, just to over write them with next 2 instructions?</p> <p><b>ADDED:</b> In regards to <a href="https://reverseengineering.stackexchange.com/users/182/rolf-rolles">Rolf Rolles</a> and <a href="https://reverseengineering.stackexchange.com/users/1323/peter-ferrie">peter ferrie</a> comments bellow. First off, thank you, guys, for your input. I really appreciate it. What puzzles me the most and seems to be relatively interesting is the fact the the executable in question seems to be clean and clear of code obfuscation of any sort. How relevant is such a small amount of obfuscation for AV defeating purposes? I would assume, not too relevant. </p> <p>I have also came across the post here on RE <a href="https://reverseengineering.stackexchange.com/questions/250/what-is-the-purpose-of-mov-edi-edi"><b>What is the purpose of 'mov edi, edi'?</b></a> . RE user <a href="https://reverseengineering.stackexchange.com/users/123/qaz">QAZ</a> on the accepted answer mentioned something about support of run time hot patching. Could it be something along those lines?</p>
What could this sequence of assembly instructions possibly mean?
|disassembly|windows|assembly|x86|
<p>To detect the polymorphic engine itself - properly - requires a copy of the engine. That was the case in the past, since the virus carried the engine in order to produce new copies of itself. The obvious attack against that is server-side polymorphism, where we ("we"=the AV industry) are left to guess at the capabilities of the engine, and which can change at any time, in response to our detections. However, back to the actual question: given an engine that can produce a sequence like this:</p> <pre><code>mov reg1, offset_of_crypted [optional garbage from set 1] [optional garbage from set 2] [optional garbage from set 3] mov reg2, key_for_crypted [optional garbage from set 1] [optional garbage from set 2] [optional garbage from set 3] mov reg3, size_of_crypted [optional garbage from set 1] [optional garbage from set 2] [optional garbage from set 3] [decrypt] [optional garbage from set 1] [optional garbage from set 2] [optional garbage from set 3] [adjust reg3] [optional garbage from set 1] [optional garbage from set 2] [optional garbage from set 3] [branch to decrypt until reg3 completes] </code></pre> <p>then we can analyse the opcodes that can produce the register assignments, and we know the set of garbage instructions, the decryption methods, the register adjustment, etc.</p> <p>From there, we can use a state machine to watch for the real instructions, and ignore the fake ones. The implementation details of that are long and boring, and not suitable as an answer here. It's a one-engine one-algorithm relationship, in most cases.</p> <p>As a result, the emulator became the most useful tool that we have against that attack, allowing us to essentially "let the virus decrypt itself" and then we can see what's underneath (the attack against that is obviously metamorphism, and the simplest implementation is at the source level rather than post-compilation).</p> <p>So, in short, the answer is generally "we don't anymore". That is, we tend to no longer detect the polymorphic engine itself. There are of course exceptions to that, but they are few and far between these days.</p>
2169
2013-06-02T06:03:22.543
<p>I was working on a hobby AV project using ClamAV's engine. While ClamAV is a good open source engine, it has poor support for detecting polymorphic viruses. The latest updated version failed to detect many instances of Virut and Sality. How do commercial AVs detect polymorphic viruses?</p>
How do AV vendors create signatures for polymorphic viruses?
|malware|
<p>MSR tracing generally refers to using the Intel Model-Specific Registers (MSRs) to obtain trace information from the CPU. Because modern (post-Pentium 4, generally) processors have hardware support for debugging, this can be faster than software-only solutions. There are a few ways this can be done:</p> <ul> <li><p>As described in a <a href="http://pedramamini.com/blog/2006-12-13/" rel="nofollow noreferrer">post by Pedram Amini</a>, one can speed up single-step execution by setting the <code>MSR_DEBUGCTLA</code> MSR and enabling the <code>BTF (single-step on branches)</code> flag. This gives better performance than pure single-stepping, which raises a debug exception on every instruction.</p></li> <li><p>One can use the "<code>Branch Trace Store (BTS)</code>" facility to log all branches into a buffer in memory; furthermore, the processor can be configured to raise an interrupt whenever this buffer is filled, so you can flush it to disk (or whatever you like). On some models there are also options for tracing only user-mode (CPL > 0) or only kernel-mode (CPL = 0) code. Sections 17.4.5-6 and 17.4.9 of the Intel Software Developer's Manual Volume 3B are required reading if you go this route.</p> <p>In Linux, there is some kernel support for this, though as far as I can tell none of it has made it into the stock kernel. In 2011 there was a <a href="http://lwn.net/Articles/444885/" rel="nofollow noreferrer">proposed patch by Akihiro Nagai</a> to the <code>perf</code> tool to add a <code>perf branch trace</code> command which would use the Intel BTS system; a <a href="http://events.linuxfoundation.org/slides/2011/linuxcon-japan/lcj2011_nagai.pdf" rel="nofollow noreferrer">presentation</a> on this is also available. Also, in 2007, there was a <a href="http://lwn.net/Articles/259339/" rel="nofollow noreferrer">patch proposed</a> to <code>ptrace</code> to expose the BTS facility.</p> <p>I don't know of anything off-the-shelf that can do this in Windows.</p></li> <li><p>Finally, If you only care about a fairly small (4-16) number of branches, you can use the <code>Last Branch Recording (LBR)</code> feature. This has the advantage of having basically no overhead, but the fairly major downside that it will only give you the last N branches, where N varies depending on the processor (from as few as 4 to as many as 16). Details on this can be found in Section 17.4.8 of the Intel developer's manual.</p> <p>One interesting note is that Haswell (Intel's just-released processor architecture) <a href="http://lwn.net/Articles/535152/" rel="nofollow noreferrer">has a version of this</a> that will keep track of calls and returns, effectively giving you a small shadow call stack, which can be quite useful in some scenarios.</p> <p>LBR has also been used in <a href="http://research.microsoft.com/pubs/153179/sim-ccs09.pdf" rel="nofollow noreferrer">at least one</a> security system to verify that a function is only being called from a trusted source, but this is getting a bit off-topic for the question.</p></li> </ul> <p>So, to sum up, MSR tracing is a way of doing tracing faster using hardware support in Intel processors. It's very appealing theoretically, but there isn't (yet) a lot of support for it in commonly available tools.</p> <p>Sources:</p> <ul> <li><p><a href="http://download.intel.com/products/processor/manual/325384.pdf" rel="nofollow noreferrer">Intel Software Developer's Manual, Volume 3</a></p></li> <li><p><a href="https://stackoverflow.com/questions/14670586/what-is-the-overhead-of-using-intel-last-branch-record">StackOverflow: What is the overhead of using Intel Last Branch Record?</a></p></li> <li><p><a href="http://pedramamini.com/blog/2006-12-13/" rel="nofollow noreferrer">Pedram Amini: Branch Tracing with Intel MSR Registers</a></p></li> <li><p><a href="http://www.codeproject.com/Articles/517466/Last-branch-records-and-branch-tracing" rel="nofollow noreferrer">Last branch records and branch tracing</a></p></li> </ul>
2173
2013-06-02T19:01:38.480
<p>I was reading a <a href="http://www.openrce.org/blog/view/1061/Industrial-Grade_Binary-Only_Profiling_and_Coverage">old blog post on OpenRCE</a> that mentions MSR tracing in the context of binary only profiling and coverage. The only Google hits for this term are a few emails on the Xen mailing list that I am not able to understand. What is MSR tracing?</p>
What is MSR Tracing?
|dynamic-analysis|
<p>First Find the address you are looking for. Then cycle this:</p> <ol> <li>Find the base (the beginning of the record).</li> <li>Dissect the memory around this to recognize array or linked list.</li> <li>Search the memory for pointer to that base.</li> </ol> <p><strong>Example</strong>:</p> <p>Scan for parameter finding the address <code>30000032</code>.</p> <p>Find out the base of this record is <code>30000000</code>.</p> <p>Checking memory - nothing fancy around.</p> <p>Finding pointer to the base at <code>20000004</code>.</p> <p>Find out the base of the record is <code>20000000</code>.</p> <p>Checking memory - still nothing...</p> <p>Finding pointer to the base at <code>10000008</code>.</p> <p>Finding out the base is <code>10000000</code>.</p> <p>Checking memory - all pointers to objects I am looking for are 12 bytes away from each other. (Obviously this is some sort of collection.)</p> <p>Last memory scan for pointer to make sure I am not wrong at <code>0000040</code>.</p> <p>Find pointer to that collection, and right after it: count of the objects in the collection.</p> <p>Restart the game/computer few times to find a consistent pointer to that address.</p> <p>Reward myself with a beer for the good work.</p> <p><strong>How to find the base</strong>: I like to use the "pointer scan", and check the last offset. The smallest from the most commonly found, is usually the correct one.</p> <p>Sometimes, I am trying to find a record, at the beginning of allocated memory, and in this case I am sure something is base.</p> <p>Another trick is to find two one after another in memory, determine their "max size", and this means the base must be no further than this number back in the memory.</p> <p><strong>How to recognize collections</strong>: Most of them are EXTREMELY organized, with specific offset, or have pointers to same type of objects.</p> <p>Like if you have:</p> <pre><code>Pointer to Player 1 data, 4 Bytes 4 Bytes Pointer to Player 2 data, 4 Bytes 4 Bytes Pointer to Player 3 data </code></pre> <p>It should ring a bell.</p> <p>Keep in mind that such alignment may randomly happen in the source, so try to search for: Player 3 data, Player 3 data +/- 4, Player 3 data +/- 8. </p> <p>Anyway, if you find something like this, you are most likely really close.</p> <p>This works for me, hope it works for you guys too.</p>
2176
2013-06-03T06:13:11.763
<p>I am reversing a game using Cheat Engine and OllyDBG, through this memory addresses within an FPS game are read and monitored, these addresses will contain the coordinates(xyz) of enemies.</p> <p>My Objective is to find an address or a pattern that will allow me to loop through up to 32 enemies in order to read all their coordinates, in order to do this I have been attempting to find a pattern between each of their addresses with no luck. I have been able to collect 3 different enemy addresses, this information is useful but searching through 32 addresses is a task which requires more effort than I believe is necessary.</p> <p>As stated I have access to the first 3 enemy addresses and if from that information it is possible to trace back to the base either through Cheat Engine or other reverse engineering software the process would be appreciated.</p> <p>Ultimately my question is, is there a way to detect a pointer array in memory from one of its addresses, for example if if I have 3 enemy coordinates can I somehow trace the memory location back to an address that accesses all 32 enemy addresses whether it is by using cheat engine or another reversing tool.</p>
How to find arrays of objects (entities, enemies) in a game I'm reversing with Cheat Engine?
|disassembly|ollydbg|debugging|debuggers|struct|
<p>Go to the <code>Local Types</code> (<code>View-&gt;Open Subviews-&gt;Local Types</code> or <kbd>Shift</kbd> + <kbd>F1</kbd>) window and then edit it from there by right clicking and clicking on <code>edit</code> on your structure's entry on the list.</p>
2178
2013-06-03T08:36:41.400
<p>I manage my structures in C files, the header might look like this:</p> <pre><code>#pragma pack(0) typedef struct { short important_value; char _A[2]; // unknown int interesting_value; } STRUCT; </code></pre> <p>I loaded this into IDA via <kbd>Ctrl</kbd>+<kbd>F9</kbd>. Now I find out more about the structure, seeing that <code>_A</code> contains <code>short imaginary_value</code>.</p> <p>When I try to reload this in IDA via <kbd>Ctrl</kbd>+<kbd>F9</kbd>, nothing happens. When I delete the structure in IDA, parse the C file and re-create the structure, I see the new structure, however all instances of <code>STRUCT</code> in the database are deleted.</p> <p>So the question is, how do I reload the structure without removing all instances from the database.</p>
How to let IDA reload a structure from a C file?
|ida|
<blockquote> <p>But surely something must know where all the devices live in memory, because something is responsible for routing memory reads/writes to the correct device.</p> </blockquote> <p>In embedded devices there's nothing like PCI (well, it may be present but it's just one of the many HW blocks). So you can't just scan all possibilities to discover the existing devices. The code must know where everything is.</p> <p>That said, there are some sources of information you may try to find.</p> <ol> <li><p>Datasheets - always the best choice. Even if there are typos and c&amp;p errors it still beats anything else. Note that many manufacturers have separate <em>datasheets</em> for pinout, electrical/temperature characteristics of specific chips, and <em>user manuals</em> (also called software or programming manuals) which are shared among many chips in the same family. You usually need the latter, though sometimes the former can also give some useful hints.</p></li> <li><p><em>Any</em> source code (OS, drivers, etc) you may find for the device. Even if it's not for the specific hardware block you're interested in, the headers may include defines for it.</p></li> <li><p>If you can't find the exact match for your chip, look for anything in the same family - often the differences are just sizes of some blocks or number of ports.</p></li> <li><p>Look at the docs for the same HW blocks in <em>any</em> chip of this manufacturer. Some makers reuse their IP blocks across architectures - e.g. Infineon used pretty much the same GPIO blocks in their E-GOLD (C166) and S-GOLD (ARM) basebands. Renesas is another example - they reused IP blocks from SuperH series in their ARM chips.</p></li> <li><p>Some hardware is standardized across all architectures and manufacturers, e.g.: PCI, USB controllers (OHCI, EHCI, XHCI), SD host controllers, eMMC and so on.</p></li> </ol> <p><strong>EDIT</strong>: sometimes, the hardware <em>external</em> to chip may be connected via an <em>external bus interface</em> (or external memory interface, or many other names). This is usually present in the bigger chips with at least a hundred pins. This interface can be programmable, and you can set up which address ranges go to which set of pins. Often there are also so-called <em>chip select</em> (CS) lines involved, which allow multiplexing the same set of pins for accessing several devices, so that one range of addresses will assert CS1, the other CS2 and so on. If you have such a set up, you need to find out the code which initializes the external interface, or dump its configuration at runtime. If you can't do that, you can try looking for memory accesses which correspond to the register layout of the external chip (such as an Ethernet controller), modulo some base address in the CPU's address space.</p>
2181
2013-06-03T17:03:07.547
<p>On many embedded systems, a great deal of communication with devices is done by reading and writing to memory-mapped I/O (MMIO) addresses in software. Supposing that I have access to the physical device, and a copy of the firmware that I can load in IDA, how can I figure out which devices are at which addresses?</p> <p>So far I've just been making guesses by looking at the code, string references (e.g., if a function prints out "Initializing timer interrupt" I can guess that maybe some of the addresses are for configuring a timer). But surely <em>something</em> must know where all the devices live in memory, because something is responsible for routing memory reads/writes to the correct device.</p> <p>So, is there a more systematic way to derive this information?</p>
How can I figure out the device memory map for an embedded system?
|hardware|embedded|
<p>Okay, Windows XP, OpenWatcom. I am using OpenWatcom 1.9. When trying to reproduce your problem, I used <code>calc.exe</code> from Windows XP for which there are no Watcom debug symbols available (only the PDB format from Microsoft, which Watcom doesn't support <em>at all</em>).</p> <p>When dismissing the open dialog from your first step, we get the assembly view like this. I am returning from that call (<code>Run -&gt; Until Return</code>) a few times and realize that the call stack shows I am still in the loader phase.</p> <p><img src="https://i.stack.imgur.com/LjloV.png" alt="enter image description here"></p> <p>The most logical thing to do now would be to break at either <code>kernel32!BaseThreadInitThunk</code> which is basically <em>the</em> entry point for any Win32 thread, including the very first in a process, but isn't exported (and, remember, we have no symbols). For a writeup on the startup process, see <a href="http://abdelrahmanogail.wordpress.com/2010/11/05/thread-basics/" rel="nofollow noreferrer">here</a> or the "Windows Internals" book. The next possible candidate would be <code>ntdll!RtlUserThreadStart</code> which also isn't exported and therefore unavailable.</p> <p>So, assuming you really have no modern debugger (WinDbg, cdb, let alone IDA, Hopper and friends) available, and don't want to use <a href="http://live.sysinternals.com/livekd.exe" rel="nofollow noreferrer"><code>livekd.exe</code> from SysInternals</a> (which however requires a recent <code>dbghelp.dll</code>) the only method that seems to be reasonable is to load your target executable into an editor (<a href="http://www.ntcore.com/exsuite.php" rel="nofollow noreferrer">CFF Explorer comes to mind</a>) and put an <code>int3</code> (<code>cc</code>) instruction at the entry point or simply move the entry point elsewhere. In my case I chose to overwrite the <code>push 70h</code> (<code>6A 70</code>) with <code>int3; nop</code> (<code>CC 90</code>). That enabled me to break at the beginning of the program (not considering TLS callbacks or anything like that, though).</p> <p>Another less intrusive method is to use the above mentioned CFF Explorer or really any suitable tool to give you the VA of the entry point. Since we're talking about Windows XP we need not worry about ASLR or anything like that. </p> <p><img src="https://i.stack.imgur.com/Z8YPK.png" alt="enter image description here"></p> <p>The entry point in our case is at RVA <code>0x12475</code>, which the Address Converter translates to:</p> <p><img src="https://i.stack.imgur.com/Henkx.png" alt="enter image description here"></p> <p>VA <code>0x1012475</code>. Sweet. Now we can try to let OpenWatcom stop at this address. Setting a bpx at this address (<code>Break -&gt; View All -&gt; Rightclick -&gt; New</code>, enter address) and then pressing <kbd>F5</kbd> (for "Go") to skip the startup phase for the process gets us straight to the entry point.</p> <p><img src="https://i.stack.imgur.com/ZFfzH.png" alt="enter image description here"></p> <p>From there we can use <kbd>F8</kbd> for further single-stepping. And I'm sure similar to the experience we shared during the startup phase, any little thing that changed since the debugger was last adjusted to a more recent OS will trip you (or rather the OW debugger) up. Short of switching debuggers, you might want to make heavy use of <code>Break -&gt; On Debug Message</code>, but even that seemed of little use when I tried it.</p> <h1>Conclusion</h1> <p>It's possible, but heck it's tedious and it may fall short of your needs at any point.</p> <p>Quite frankly, some debuggers are better left alone when no source is available (assembly debugging). Admittedly I am not as familiar with the Watcom debugger as with GDB or WinDbg, but I've used it in the past and found it pure horror <em>with</em> symbols. That impression will likely only get worse <em>without</em> symbols. I find myself confirmed in that sense from looking into the issue you were experiencing.</p> <h2>20th century debugging</h2> <p>OpenWatcom, while still being "developed" is old. Its roots are in the old Sybase product Watcom, which had a broad following. Problem is, that this product existed even before Windows 2000. So I don't think you can expect a lot from it, as most people these days are using compilers and debuggers with better support. Be it WinDbg or be it GDB if you happen to use MinGW or something like that.</p>
2185
2013-06-03T22:45:34.807
<p><a href="http://www.openwatcom.org" rel="nofollow">OpenWatcom's</a> debugger just executes the binary instead of single-stepping through it, when I attempt the following steps:</p> <ol> <li><code>File-&gt;Open</code>, select executable</li> <li><code>Run-&gt;Trace Into</code></li> </ol> <p>This attempt <a href="http://chat.stackexchange.com/transcript/message/9732918#9732918">is on Windows XP</a>.</p> <p>How do I single step through a program using OpenWatcom's debugger?</p>
How to debug using OpenWatcom's debugger?
|windows|debuggers|
<p>UPDATE: This seems to be obsolete.</p> <p>You can debug IDAPython scripts using Python Tools for Visual Studio. It is completely free, and very easy to use.</p> <p>See <a href="http://sark.readthedocs.org/en/latest/debugging.html" rel="nofollow noreferrer">this tutorial</a> for this information.</p>
2190
2013-06-04T19:47:44.587
<p>IDAPython is great plugin in IDA. It is so handy to write small script to decode, decrypt or fix (patch) a binary in IDA. I can just write, load and run a script, and can use <code>print</code> for the usual shotgun debugging. But when I develop a bigger IDAPython script, I need a way to debug it. </p> <p>I have searched and found that I can debug IDAPython with <a href="http://wingware.com/doc/howtos/idapython">WingIDE</a> but I want to find another that doesn't require WingIDE. Is there another way to debug IDAPython scripts?</p>
How to debug an IDAPython script from within IDA?
|python|idapython|ida|
<p>Have a look at the <code>var_4</code> definition at the start of the function:</p> <pre><code>var_4 = dword ptr -4 </code></pre> <p>So it's actually negative as expected.</p> <p>For a more complete picture, use <kbd>Ctrl+K</kbd> or double-click/Enter on the stack var to see the <a href="https://www.hex-rays.com/products/ida/support/idadoc/488.shtml">stack frame layout</a>:</p> <pre><code>-00000018 ; Two special fields " r" and " s" represent return address and saved registers. -00000018 ; Frame size: 18; Saved regs: 4; Purge: 0 -00000018 ; -00000018 -00000018 var_18 dd ? -00000014 var_14 dd ? -00000010 var_10 db 12 dup(?) -00000004 var_4 dd ? +00000000 s db 4 dup(?) +00000004 r db 4 dup(?) +00000008 arg_0 dd ? +0000000C +0000000C ; end of stack variables </code></pre>
2194
2013-06-07T01:11:42.543
<p>Let's take a look of how IDA displays address of local variable. For instance:</p> <pre><code>MOV EAX, [EBP + var_4] </code></pre> <p>As we all know as far as local variables go, they are located at lower addresses of EBP.</p> <p><img src="https://i.stack.imgur.com/XDoh3.png" alt="Stack Frame"></p> <p>Though, I have been taking it for granted and inevitable, I am still very curious. Why does IDA display local variable offset as <strong><code>[EBP + var]</code></strong>, not <strong><code>[EBP - var]</code></strong>?</p> <p>Thank you so much.</p>
IDA EBP variable offset
|disassembly|assembly|static-analysis|callstack|ida|
<p>Hex-Rays performs liveness analysis and dead code elimination, which in the case of your function, it sounds like it decided everything was dead. I think it's impossible to tell Hex-Rays via __usercall that the return location for some function is in a flag location, so under that assumption, Hex-Rays can't help in this situation.</p> <p>What you want is a tool that is capable of rendering the intermediate language translation for a given instruction or block of instructions. To that extent, tools such as BitBlaze, BAP, and miasm can help. Also see <a href="http://edmcman.bitbucket.org/blog/2013/02/27/bap-for-everyone/">this link</a> for a language-agnostic interface to BAP.</p>
2197
2013-06-07T21:36:26.960
<p>I came across a small function whose only side effects were to modify the state of some processor flags. When I decompiled this function using the Hex Rays decompiler, I simply got an empty function, which is not useful at all in figuring out what the function does. Instead I had to look up each instruction in the assembly language manual and read the pseudocode to determine the net effect of the function. Is there some tool I can paste assembly instructions into and it will spit out <em>all</em> side effects, including flags? I'm interested in x86.</p>
Take A Snippet of Assembly and Make All Side Effects Explicit?
|assembly|x86|ida|
<blockquote> <p>Why does the function pointer get overwritten even though is declared before the vulnerable buffer?</p> </blockquote> <p>In the vulnerable code the order of declaration is:</p> <pre><code>void (*functionpointer)(void) = bad; char buffer[50]; </code></pre> <p>The assembly code shows us that the <strong>function pointer</strong> variable is located at <code>ebp-0xc</code> and the <strong>buffer</strong> at <code>ebp-0x58</code>. </p> <p>This proves that the <strong>stack is growing downwards</strong>(to lower addresses) in this system as the <strong>buffer</strong> is placed at a lower address than the <strong>function pointer</strong> variable. </p> <p>Another proof that the stack is growing downwards in this system is the below instruction which allocates the required space by substracting <code>esp</code>:</p> <pre><code>80484cb: 83 ec 78 sub $0x78,%esp </code></pre> <p><br/> Now <code>memcpy</code> copies <code>num</code> bytes starting from the byte located at <code>ebp-0x58</code> and then it continues by incrementing.</p> <p>Adding <code>1</code> to <code>ebp-0x58</code> makes it <code>ebp-0x57</code>, so if <code>num</code> is long enough, <code>memcpy</code> will overwrite the <strong>function pointer</strong> located at <code>ebp-0xc</code>.</p> <p><code>ebp</code> holds an address, lets say <code>0x00400000</code>, so <code>ebp-0x58</code> is the address <code>0x003FFFA8</code> incrementing from that address you will eventually reach <code>ebp-0xc(0x003FFFF4)</code>.</p> <pre><code>0x003FFFA8     buffer ... 0x003FFFF4     function pointer 0x003FFFF8      0x003FFFFC     0x00400000     saved ebp 0x00400004     saved return address </code></pre>
2209
2013-06-08T16:43:26.337
<p>I am working on <a href="http://io.smashthestack.org:84/" rel="noreferrer">io-wargames</a> for fun right now, level3:</p> <p>I do understand why there is a stack-overflow in this code <code>(strlen(argv[1])</code>), but what I don't understand is why it overflows the function pointer <code>functionpointer</code>. </p> <p><code>functionpointer</code> is declared before <code>char buffer[50];</code> on the stack so How comes it overwrites it ??? </p> <p>Here is the main vulnerable code: </p> <pre><code>int main(int argc, char **argv, char **envp) { void (*functionpointer)(void) = bad; char buffer[50]; if(argc != 2 || strlen(argv[1]) &lt; 4) return 0; memcpy(buffer, argv[1], strlen(argv[1])); memset(buffer, 0, strlen(argv[1]) - 4); printf("This is exciting we're going to %p\n", functionpointer); functionpointer(); return 0; } </code></pre> <p>Here is the shell exploits the stackoverflow:</p> <pre><code>level3@io:~$ /levels/level03 11111111 This is exciting we're going to 0x80484a4 I'm so sorry, you're at 0x80484a4 and you want to be at 0x8048474 level3@io:~$ /levels/level03 111111111111111111111111111111111111111111111111111111111111111111111111111111111 This is exciting we're going to 0x31313100 Segmentation fault </code></pre> <hr> <p>Here is the <code>objump -d</code> of the executable:</p> <pre><code>080484c8 &lt;main&gt;: 80484c8: 55 push %ebp 80484c9: 89 e5 mov %esp,%ebp 80484cb: 83 ec 78 sub $0x78,%esp 80484ce: 83 e4 f0 and $0xfffffff0,%esp 80484d1: b8 00 00 00 00 mov $0x0,%eax 80484d6: 29 c4 sub %eax,%esp 80484d8: c7 45 f4 a4 84 04 08 movl $0x80484a4,-0xc(%ebp) 80484df: 83 7d 08 02 cmpl $0x2,0x8(%ebp) 80484e3: 75 17 jne 80484fc &lt;main+0x34&gt; 80484e5: 8b 45 0c mov 0xc(%ebp),%eax 80484e8: 83 c0 04 add $0x4,%eax 80484eb: 8b 00 mov (%eax),%eax 80484ed: 89 04 24 mov %eax,(%esp) 80484f0: e8 a7 fe ff ff call 804839c &lt;strlen@plt&gt; 80484f5: 83 f8 03 cmp $0x3,%eax 80484f8: 76 02 jbe 80484fc &lt;main+0x34&gt; 80484fa: eb 09 jmp 8048505 &lt;main+0x3d&gt; 80484fc: c7 45 a4 00 00 00 00 movl $0x0,-0x5c(%ebp) 8048503: eb 74 jmp 8048579 &lt;main+0xb1&gt; 8048505: 8b 45 0c mov 0xc(%ebp),%eax 8048508: 83 c0 04 add $0x4,%eax 804850b: 8b 00 mov (%eax),%eax 804850d: 89 04 24 mov %eax,(%esp) 8048510: e8 87 fe ff ff call 804839c &lt;strlen@plt&gt; 8048515: 89 44 24 08 mov %eax,0x8(%esp) 8048519: 8b 45 0c mov 0xc(%ebp),%eax 804851c: 83 c0 04 add $0x4,%eax 804851f: 8b 00 mov (%eax),%eax 8048521: 89 44 24 04 mov %eax,0x4(%esp) 8048525: 8d 45 a8 lea -0x58(%ebp),%eax 8048528: 89 04 24 mov %eax,(%esp) 804852b: e8 5c fe ff ff call 804838c &lt;memcpy@plt&gt; 8048530: 8b 45 0c mov 0xc(%ebp),%eax 8048533: 83 c0 04 add $0x4,%eax 8048536: 8b 00 mov (%eax),%eax 8048538: 89 04 24 mov %eax,(%esp) 804853b: e8 5c fe ff ff call 804839c &lt;strlen@plt&gt; 8048540: 83 e8 04 sub $0x4,%eax 8048543: 89 44 24 08 mov %eax,0x8(%esp) 8048547: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 804854e: 00 804854f: 8d 45 a8 lea -0x58(%ebp),%eax 8048552: 89 04 24 mov %eax,(%esp) 8048555: e8 02 fe ff ff call 804835c &lt;memset@plt&gt; 804855a: 8b 45 f4 mov -0xc(%ebp),%eax 804855d: 89 44 24 04 mov %eax,0x4(%esp) 8048561: c7 04 24 c0 86 04 08 movl $0x80486c0,(%esp) 8048568: e8 3f fe ff ff call 80483ac &lt;printf@plt&gt; 804856d: 8b 45 f4 mov -0xc(%ebp),%eax 8048570: ff d0 call *%eax 8048572: c7 45 a4 00 00 00 00 movl $0x0,-0x5c(%ebp) 8048579: 8b 45 a4 mov -0x5c(%ebp),%eax 804857c: c9 leave 804857d: c3 ret 804857e: 90 nop 804857f: 90 nop </code></pre> <hr> <p>I see that the complier reserved in the main's prolog function frame <code>0x78</code> bytes for the local main function variables. </p>
Why does the function pointer get overwritten even though is declared before the vulnerable buffer?
|c|linux|assembly|x86|
<p>GDB protects you to overflow your char array. </p> <pre><code>(gdb) p &amp;buffer $25 = (char (*)[512]) 0x7fffffffdfe0 </code></pre> <p>To bypass this security you can either write directly the memory :</p> <pre><code>(gdb) set 0x7fffffffe1e0=0x41414141 </code></pre> <p>Or cast the array as a bigger one and then set your stuff :</p> <pre><code>set {char [513]}buffer="512xA" </code></pre>
2215
2013-06-09T01:47:19.077
<p>I'm trying to understand very basic stack-based buffer overflow I'm running Debian wheezy on a x86_64 Macbook Pro.</p> <p>I have the following unsafe program:</p> <pre><code>#include &lt;stdlib.h&gt; #include &lt;stdio.h&gt; CanNeverExecute() { printf("I can never execute\n"); exit(0); } GetInput() { char buffer[512]; gets(buffer); puts(buffer); } main() { GetInput(); return 0; } </code></pre> <p>I compiled with <code>-z execstack</code> and <code>-fno-stack-protector</code> for my tests.</p> <p>I have been able to launch the program through gdb, get the address of <code>CanNeverExecute</code> function which is never called, and overflow the buffer to replace the return address by this address. I got printed "I can never execute", which is, so far, so good.</p> <p>Now I'm trying to exploit this buffer overflow by introducing shellcode in the stack. I'm currently trying directly into gdb: break in <code>GetInput</code>function, set buffer value through gdb and jump to buffer adress with <code>jump</code> command.</p> <p>But I have a problem when setting the buffer: I have a breakpoint just after gets function, and I ran the programm with 512 <code>a</code> characters as input.</p> <p>In gdb, I do:</p> <pre><code>(gdb) p buffer $1 = 'a' &lt;repeats 512 times&gt; </code></pre> <p>The input was read without any problem, and my buffer is 512 <code>a</code> I then try to modify its value. If I do this:</p> <pre><code>(gdb) set var buffer="" </code></pre> <p>and try to print buffer, its length is now 511! How come??</p> <pre><code>(gdb) p buffer $2 = '\000' &lt;repeats 511 times&gt;et: </code></pre> <p>And when I try to set it back to, for instance, 512 <code>a</code>, I get:</p> <pre><code>Too many array elements </code></pre> <p>I can set it to 511 <code>a</code> though, it is really that las byte that doesn't work... How come, is there a simple explanation?</p>
GDB Error "Too many array elements"
|gdb|buffer-overflow|
<p>Control flow flattening is an obfuscation\transformation technique that can be applied to code for almost all languages in order to make it more difficult to understand and reverse engineer.</p> <pre><code>int gSDetETSDG119 = 1010545; while (gSDetETSDG119 != 1010544) { switch (gSDetETSDG119) { case 1010545: { if (n &lt;= 0) { gSDetETSDG119 = 1010546; } else { gSDetETSDG119 = 1010547; } break; } case 1010546: { return (0.000000e+000); gSDetETSDG119 = 1010544; break; } case 1010547: { gSDetETSDG119 = 1010544; break; } } } } int gSDetETSDG118 = 1010541; while (gSDetETSDG118 != 1010540) { switch (gSDetETSDG118) { case 1010541: { if (incx != 1 || incy != 1) { gSDetETSDG118 = 1010542; } else { gSDetETSDG118 = 1010543; } break; } case 1010542: { { ix = 0; iy = 0; { int gSDetETSDG117 = 1010537; while (gSDetETSDG117 != 1010536) { switch (gSDetETSDG117) { case 1010537: { if (incx &lt; 0) { gSDetETSDG117 = 1010538; } else { gSDetETSDG117 = 1010539; } break; } case 1010538: { ix = (-n + 1) * incx; gSDetETSDG117 = 1010536; break; } case 1010539: { gSDetETSDG117 = 1010536; break; } } } } { int gSDetETSDG116 = 1010533; while (gSDetETSDG116 != 1010532) { switch (gSDetETSDG116) { case 1010533: { if (incy &lt; 0) { gSDetETSDG116 = 1010534; } else { gSDetETSDG116 = 1010535; } break; } case 1010534: { iy = (-n + 1) * incy; gSDetETSDG116 = 1010532; break; } case 1010535: { gSDetETSDG116 = 1010532; break; } } } } { i = 0; { int gSDetETSDG110 = 1010510; while (gSDetETSDG110 != 1010509) { switch (gSDetETSDG110) { case 1010510: { { int gSDetETSDG115 = 1010529; while (gSDetETSDG115 != 1010528) { switch (gSDetETSDG115) { case 1010529: { if (i &lt; n) { gSDetETSDG115 = 1010530; } else { gSDetETSDG115 = 1010531; } break; } case 1010530: { gSDetETSDG110 = 1010511; gSDetETSDG115 = 1010528; break; } case 1010531: { gSDetETSDG110 = 1010509; gSDetETSDG115 = 1010528; break; } } } } break; } case 1010511: { { dtemp = dtemp + dx[ix] * dy[iy]; ix = ix + incx; iy = iy + incy; } eTDGEyDg246: { i++; } eTDGEyDg251: { ; } gSDetETSDG110 = 1010510; break; } } } eTDGEyDg252: { ; } } } return (dtemp); } gSDetETSDG118 = 1010540; break; } case 1010543: { gSDetETSDG118 = 1010540; break; } } } } </code></pre> <p>This technique involves transforming the control flow of a program in a way that makes it more difficult to trace\debug, while still preserving the same logic of the original program.</p> <p>There are a number of different ways that control flow flattening can be implemented, but the basic idea is to take the control flow of the program and transform it into a series of nested if-then-else\while\switch statements.</p> <p>This can be done by replacing all of the branches in the original code with conditional statements, and then nesting these statements so that the overall control flow becomes much more complex.</p> <p>To avoid automatic code simplification and folding we can use opaque predicates technique with known conditions.</p> <p>One of the biggest benefits of control flow flattening is that it can make it much more difficult for an attacker to understand the code and figure out how it works. This can be especially useful for protecting against reverse engineering and tampering attacks, as it can make it much more difficult for an attacker to modify the code or to understand its internal logic</p>
2221
2013-06-10T13:46:25.980
<p>I recently heard about the &quot;control-flow flattening&quot; obfuscation which seems to be is used to break the structure of the CFG of the binary program (see <a href="https://www.sstic.org/2013/presentation/execution_symbolique_et_CFG_flattening/" rel="nofollow noreferrer">Symbolic Execution and CFG Flattening</a>).</p> <p>Can somebody make an explanation of what is its basic principle and, also, how to produce such obfuscation (tools, programming technique, ...) ? And, it would be nice to know if there are ways to extract the real shape of the control-flow of the program.</p>
What is a "control-flow flattening" obfuscation technique?
|obfuscation|
<p>The difference between a debug apk and a release apk is that a debug apk is signed by a particular key which is provided with the SDK, whereas a release apk is signed by some other key. There's nothing to reverse engineer: all you have to do to make a release apk and sign it.</p> <p>Nobody but you can create an apk signed by you. But anyone can make their own release apk by signing them.</p> <p>A solution in your case would be to produce a binary including some DRM and refuse to run except on your customer's pre-registered device. How to implement such DRM, especially while letting your customer debug his applications, is left as an exercise to the reader.</p>
2223
2013-06-10T16:04:42.910
<p>I am making a system in which the users can create Android applications. I want them to give an option to download a <a href="http://developer.android.com/tools/building/building-cmdline.html#DebugMode" rel="noreferrer">debug apk</a> so that they can try it out first. After that, they have to pay for it to get the <a href="http://developer.android.com/tools/building/building-cmdline.html#ReleaseMode" rel="noreferrer">apk in release mode</a>, so that it can be distributed in the Google Play Store.</p> <p>I of course don't want them to be able to reverse-engineer the debug apk so that they can extract the needed files from it and then sign it themselves. Hence my question: </p> <p><strong>Is it possible to reverse engineer a debug apk to extract the classes and everything needed to build it in release mode?</strong></p> <p>If so, would there be any way to secure the debug versions so that it isn't possible anymore?</p>
Can a debug-apk be reverse engineered to make it a release-apk?
|decompilation|unpacking|android|copy-protection|apk|
<p><strong><a href="http://www.openrce.org/downloads/details/171" rel="nofollow noreferrer">Process Stalker</a></strong> is designed to do exactly what you want.</p> <p><img src="https://i.stack.imgur.com/qYf7z.gif" alt="Snippet of Process Stalker&#39;s basic block highlighting"></p> <p>Sample usage: <a href="https://www.openrce.org/articles/full_view/12" rel="nofollow noreferrer">https://www.openrce.org/articles/full_view/12</a></p> <p>PowerPoint slides: <a href="http://2005.recon.cx/recon2005/papers/Pedram_Amini/process_stalking-recon05.pdf" rel="nofollow noreferrer">http://2005.recon.cx/recon2005/papers/Pedram_Amini/process_stalking-recon05.pdf</a></p>
2228
2013-06-11T03:13:30.460
<p>When I execute a program using IDA's debugger interface, I would like to see the basic blocks that were executed highlighted in the IDB. Is there a way to do this?</p>
Highlight Executed Basic Blocks in IDA
|ida|
<p>As Dcoder indicated, an array of <code>short</code> data types begins at the lower address, and the increment of the base of the array by <code>2</code> corresponds to adding <code>1</code> to the index. Consider the following C code:</p> <pre><code>short array[256]; // ... cx = array[variable_1+1]; // ... // ... dx = array[variable_1]; // ... </code></pre> <p>Consider the choices that the compiler has in compiling these snippets of code. It could produce code like this:</p> <pre><code>mov eax, [ebp+Variable_1] xor ecx, ecx mov cx, word_4305FC[eax*2+2] ; note the +2 and the -FC address </code></pre> <p>Or maybe:</p> <pre><code>mov eax, [ebp+Variable_1] inc eax ; note this xor ecx, ecx mov cx, word_4305FC[eax*2] ; note the -FC address </code></pre> <p>Or, in the case of what you posted, this is an equivalent code sequence:</p> <pre><code>mov eax, [ebp+Variable_1] xor ecx, ecx mov cx, word_4305FE[eax*2] ; note the -FE address </code></pre> <p>What the compiler did was to eliminate the "+2" in the address displacement, or the "inc eax" in the index computation, and replaced it by adding 1*sizeof(short) to the address of the array. This allows for a more optimized computation that does not have any increments taking place at runtime.</p>
2232
2013-06-11T18:24:18.107
<p>I have the following data:</p> <pre><code>.data:004305FC word_4305FC dw 1583h .data:004305FC .data:004305FE word_4305FE dw 35B6h .data:00430600 dw 6835h .data:00430602 dw 6553h .data:00430604 dw 6351h .data:00430606 dw 23F5h .data:00430608 dw 6845h .data:0043060A dw 6344h .data:0043060C dw 6823h .data:0043060E dw 2342h .data:00430610 dw 2474h ... </code></pre> <p>In addition, I have the following disassembly of the code accessing the data:</p> <pre><code>... mov eax, [ebp+Variable_1] xor ecx, ecx mov cx, word_4305FE[eax*2] ... mov eax, [ebp+Variable_1] xor edx, edx mov dx, word_4305FC[eax*2] ... </code></pre> <p>It looks like array within another array. Am I correct? If not, what do you think the data structure is? If it is a single array, why is it been accessed through 2 different "heads" <strong><code>word_4305fc</code></strong> and <strong><code>word_4305FE</code></strong>?</p> <p>Thank you.</p> <p><strong>ADDED:</strong></p> <p>The following is in response to the comments below. Thank you, guys, so much for your input! I really do appreciate it and RE community in general. I feel as if my question needs certain clarification. I do realize that this is an array. I also clearly see that <strong><code>Variable_1</code></strong> is an index to the array. In addition, I can see iteration. However, it is not my question. What I am really looking for is clarification or possibly an explanation. How would I be able to distinguish if this array is indeed more complex data type? Why did compiler choose to refer to this data type with 2 different angles: using 2 global variables both <strong><code>word_4305fc</code></strong> and <strong><code>word_4305FE</code></strong>? Is there a specific reason for it? Is it an indication of more complex data type? </p>
What type of data structure is it?
|disassembly|assembly|ida|struct|
<p>This is my basic understanding of how Windows service works. I have used it with Windows XP and Windows 7. These are general concepts anyways. </p> <p>Any service requires three things to be present: </p> <ol> <li>A Main Entry Point</li> <li>A Service Entry Point</li> <li>A Service Control Handler</li> </ol> <p>You are absolutely right. In the Main Entry Point service must call <strong><code>StartServiceCtrlDispatcher(const SERVICE_TABLE_ENTRY *lpServiceTable)</code></strong> providing Service Control Manager with filled in <strong><code>SERVICE_TABLE_ENTRY</code></strong>, which is (per <a href="http://msdn.microsoft.com/en-us/" rel="nofollow noreferrer">MSDN</a>):</p> <pre><code>typedef struct _SERVICE_TABLE_ENTRY { LPTSTR lpServiceName; LPSERVICE_MAIN_FUNCTION lpServiceProc; } SERVICE_TABLE_ENTRY, *LPSERVICE_TABLE_ENTRY; </code></pre> <p>As you can see, there are two things which are required to be supplied in SERVICE_TABLE_ENTRY structure. Those are pointer to name of the service, and pointer to service main function. Right after service registration, Service Control Manager calls Service Main function, which is also called ServiceMain or Service Entry Point. Service Control Manager expects that following tasks are performed by Service Entry Point:</p> <ol> <li>Register the service control handler.</li> <li>Set Service Status</li> <li>Perform necessary initialization (creating events, mutex, etc)</li> </ol> <p>Service Control Handler is a callback function with the following definition: <strong><code>VOID WINAPI ServiceCtrlHandler (DWORD CtrlCode)</code></strong>(<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms685149%28v=vs.85%29.aspx" rel="nofollow noreferrer">MSDN</a>). It is expected to handle service STOP, PAUSE, CONTINUE, and SHUTDOWN. It is imperative that each service has a handler to handle requests from the SCM. Service control handler is registered with <strong><code>RegisterServiceCtrlHandlerEx()</code></strong>(<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms685058%28v=vs.85%29.aspx" rel="nofollow noreferrer">MSDN</a>), which returns <strong><code>SERVICE_STATUS_HANDLE</code></strong>. Service uses the handle to communicate to the SCM. The control handler must also return within 30 seconds. If it does not happen the SCM will return an error stating that the service is unresponsive. This is due to the fact that the handler is called out of the SCM and will freeze the SCM until it returns from the handler. Only then, service may use <strong><code>SetServiceStatus()</code></strong>(<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms686241%28v=vs.85%29.aspx" rel="nofollow noreferrer">MSDN</a>) function along with service status handle to communicate back to the SCM. </p> <p>You don't communicate "Start" to a service. Whenever a service loads, it loads in the "started" state. It is service's responsibility to report its state to the SCM. You can PAUSE it or CONTINUE (plus about dozen more control codes). You communicate it to the SCM by using <strong><code>ControlService()</code></strong>(<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682108%28v=vs.85%29.aspx" rel="nofollow noreferrer">MSDN</a>) function. The SCM in turn relays the control code (e.g. SERVICE_CONTROL_PAUSE, SERVICE_CONTROL_CONTINUE or any other one) through to the service using registered service control handler function. Afterwards, it is the services responsibility to act upon received control code.</p> <p>I don't think services.exe executes or runs threads behind actual services. It is the SCM itself. I take it coordinates services in general. Each service "lives" in svchost.exe instance. Taking mentioned above into account, I could assume that Service Entry Point or Service Main is executed in the context of instance of the svchost.exe. In its turn, svchost.exe executes Service Main in context of main thread, blocking main thread until Service Main exists signaling that the service exited.</p> <p>If you are thinking to create your own service control manager, there is no need to reverse engineer how services.exe does it. You can do it your own way and anyway that you like it :)</p> <p>I hope it helps.</p> <p><strong>ADDED:</strong></p> <p>As <a href="https://reverseengineering.stackexchange.com/users/161/mick">Mick</a> commented below, <strong><code>services.exe</code></strong> is the Service Control Manager itself. </p> <p>If you are creating your own service wrapper to run existing serivce executables outside of the SCM, you will have to adhere to above mentioned service quidelines and requirements. The fist requirement is for the service to get itself registered with the SCM and provide Service Main Entry Point, which is done by calling <strong><code>StartServiceCtrlDispatcher()</code></strong>. It will get you the entry point to Service Main. Afterwards, you should expect the Service Main to call <strong><code>RegisterServiceCtrlHandler()</code></strong> and <strong><code>SetServiceStatus()</code></strong>. Since <strong><code>RegisterServiceCtrlHandler()</code></strong> runs in context of Service Main and blocks Service Main thread, it should be handled properly as well. In addition, you should think of a way to control/monitor the service worker thread(s) by "watching" for <strong><code>CreatThread()</code></strong>(<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682453%28v=vs.85%29.aspx" rel="nofollow noreferrer">MSDN</a>) within Service Main. </p>
2235
2013-06-11T22:01:06.090
<p>I'm trying to work out the internals of how a Windows process starts and maintains communication with <code>services.exe</code>. This is on Windows 8 x64, but if you have tips for Windows 7 that is fine too.</p> <p>So far I figure out <code>services.exe</code> does something approximately like this:</p> <pre><code>PROCESS_INFORMATION pi; TCHAR szExe[] = _T("C:\\Program Files\\TestProgram\\myWindowsService.exe"); PROCESS_INFORMATION process_information = {0}; HKEY hOpen; DWORD dwNumber = 0; DWORD dwType = REG_DWORD; DWORD dwSize = sizeof(DWORD); STARTUPINFOEX startup_info; SIZE_T attribute_list_size = 0; ZeroMemory(&amp;startup_info, sizeof(STARTUPINFOEX)); // can see EXTENDED_STARTUPINFO_PRESENT is used, but couldn't figure out if any/what attributes are added BOOL status = InitializeProcThreadAttributeList(nullptr, 0, 0, &amp;attribute_list_size); PPROC_THREAD_ATTRIBUTE_LIST attribute_list = (PPROC_THREAD_ATTRIBUTE_LIST)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, attribute_list_size); startup_info.StartupInfo.cb = sizeof(STARTUPINFOEX); startup_info.lpAttributeList = attribute_list; startup_info.StartupInfo.dwFlags = STARTF_FORCEOFFFEEDBACK; startup_info.StartupInfo.wShowWindow= SW_HIDE; if(CreateProcess( NULL, szExe, NULL, NULL, FALSE, CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT | DETACHED_PROCESS | EXTENDED_STARTUPINFO_PRESENT, NULL, NULL, &amp;startup_info.StartupInfo, &amp;pi)) { HANDLE hEvent; hEvent=CreateEvent(NULL,FALSE,FALSE,NULL); // I traced this call during service sstartup; no idea what purpose it serves? ResumeThread(pi.hThread); </code></pre> <p>Now my question is, how does the actual "Start" get communicated to the service? I know the service itself does something like this:</p> <ol> <li>main entry point (à la console program)</li> <li>Call <code>advapi!StartServiceCtrlDispatcher</code></li> <li>Goes to <code>sechost!StartServiceCtrlDispatcher</code></li> <li>This jumps into <code>sechost!QueryServiceDynamicInformation</code></li> </ol> <p>I'm trying to figure out what method in <code>services.exe</code> is used to hook into this start process. Ideally I want to be able to write a PoC code that can "launch" a simple Windows service and get it to start, without it being registered as a Windows Service, i.e. wrapped inside a "stand alone service control manager". I'm looking for some tips of what best to look for next.</p> <p>There is also a reference to <code>services.exe</code> in <code>\\pipe\ntsvcs</code>. The <a href="http://en.wikipedia.org/wiki/Service_Control_Manager">Wikipedia article about SCM</a> refers to <code>\Pipe\Net\NtControlPipeX</code> being created, but as far as I can tell, that is in Windows 2000 (maybe XP) but I can't see this happening on Windows 8.</p>
How does services.exe trigger the start of a service?
|windows|
<p>Often times malware and/or obfuscated code (such as unpacking stubs) will do something such as the following:</p> <ol> <li>Set up an exception handler.</li> <li>Throw an exception.</li> <li>See if the exception handler caught the exception.</li> </ol> <p>If the exception handler didn't catch the exception then the debugged code knows that a debugger was attached and "swallowed" the exception, thus indicating that the code is being debugged. In order to hide your debugger from such detection techniques, you always want to pass exceptions to the application when dealing with malware and/or obfuscated code.</p>
2238
2013-06-12T03:12:40.930
<p>I came across some malware that raised an exception while I was single stepping through it. IDA gives me the option to pass the exception to the application or not. What exactly is going on here? When would I not want to pass the exception to the application?</p>
How to handle exceptions in a debugger when reversing malware?
|malware|debuggers|
<p>I was digging a bit into this, and found <a href="https://stackoverflow.com/questions/1515661/gdb-not-hitting-breakpoints">this question</a> on SO by mrduclaw (link in the original article is dead, but <a href="http://web.archive.org/web/20090611150423/http://sourceware.org/gdb/current/onlinedocs/gdb_5.html#SEC29" rel="nofollow noreferrer">web archive has it</a>). He has the exact same problem like I do, and exactly the same motivation for finding a solution.</p> <p>So I was digging around some more and it turns out freebsd until recently didn't have support for forks in it's ptrace. There was a <a href="http://lists.freebsd.org/pipermail/freebsd-toolchain/2012-April/000370.html" rel="nofollow noreferrer">patch submitted</a> but I can't really figure out if it's applied. Will try to apply it myself and see if it will start working then. </p>
2241
2013-06-12T16:04:52.383
<p>Long time ago I noticed that using</p> <blockquote> <p>set follow-fork-mode child</p> </blockquote> <p>in GDB on FreeBSD doesn't really work. This problem occurs very often with some challenges on various Capture The Flag contests. For example, a server will spawn a child which would handle the connection. The child code has a vulnerability which I would like to debug, but gdb just never follows the childs execution and I can't really observe the vulnerability being triggered.</p> <p>So far, I've solved this problem in two ways:</p> <ol> <li><p>Making a connection, waiting for a child to spawn and than attaching GDB to it.</p> <p>This works since the spawned child has it's own PID to which I can attach, but is rather painful since first I have to make a connection from one session, attach with GDB in another, and then send the payload/continue the connection in the first.</p> </li> <li><p>Patching the binary after the fork call to continue the execution in the parent process instead of the child.</p> <p>This is also painful since then I have to restart the whole parent process to create another debugging session.</p> </li> </ol> <p>There are some other tricks that can be employed, but these are enough to illustrate my point.</p> <p>Now I know there have been some limitations on FreeBSD in the past regarding this but has anything improved?</p> <p>Is there any way to patch GDB to add this functionality? Any suggestions for an easier way of overcoming this?</p>
gdb on FreeBSD and follow-fork-mode child
|gdb|exploit|debugging|multi-process|
<p>In the static context, this is known as "data flow analysis". For example, Hex-Rays incorporates the return-location information for function calls into its representation of the function so as to determine into which other locations that data flows. You don't give a lot of detail on what you want to do with this information, but off the top of my head I'd say it could be worthwhile to investigate writing a Hex-Rays plugin.</p>
2242
2013-06-12T17:12:41.647
<p>I wrote a simple IDA plugin that, after a function call, looks for <code>mov MEM_LOCATION eax</code> and adds a name for the memory where the return value is stored. I limit my search to only a few instructions after the function call and bail out if I see another call before the return value is stored. Is there a more rigorous way to track where the return value goes besides these heuristics?</p>
Tracking What Is Done With a Function's Return Value
|ida|
<p><a href="https://reverseengineering.stackexchange.com/a/2253/2676">DCoder's answer</a> is a good one. To expand somewhat, I most often use DLL injection in the context of forcing an existing process to load a DLL through CreateRemoteThread. From there, the entrypoint of the DLL will be executed by the operating system once it is loaded. In the entrypoint, I will then invoke a routine that performs in-memory patching of all of the locations within the original binary that interest me, and redirects their execution into my DLL via a variety of modifications. If I am interested in modifying or observing the process' interaction with some imported function, then I will overwrite the IAT (Import Address Table) entry for that function and replace it with a pointer to something that I control. If I want to do the same with respect to some function that exists within the binary, I will make some sort of detours-style patch at the beginning of the function. I can even do very surgical and targeted hooks at arbitrary locations, akin to old-school byte patching. My DLL does its business within the individual hooks, and then is programmed to redirect control back to the original process.</p> <p>DLL injection provides a platform for manipulating the execution of a running process. It's very commonly used for logging information while reverse engineering. For example, you can hook the IAT entry for a given imported operating system library function, and then log the function arguments onto disk. This provides you a data source that can assist in rapidly reverse engineering the target.</p> <p>DLL injection is not limited to logging, though. Given the fact that you have free reign to execute whatever code that you want within the process' address space, you can modify the program in any way that you choose. This technique is frequently used within the game hacking world to code bots. </p> <p>Anything that you could do with byte patching, you can do with DLL injection. Except DLL injection will probably be easier and faster, because you get to code your patches in C instead of assembly language and do not have to labor over making manual modifications to the binary and its PE structure, finding code caves, etc. DLL injection almost entirely eliminates the need for using assembly language while making modifications to a binary; the only assembly language needed will be small pieces of code nearby the entrance and exit to a particular hook to save and restore the values of registers / the flags. It also makes binary modification fast and simple, and does not alter cryptographic signatures of the executable that you are patching. (The comment about cryptographic signatures applies to the executable on disk, not in memory; of course, altering the contents in memory would affect a cryptographic signature computed on the altered memory contents.)</p> <p>DLL injection can be employed to solve highly non-trivial reverse engineering problems. The following example is necessarily vague in some respects because of non-disclosure agreements.</p> <p>I had a recurring interest in a program that was updated very frequently (sometimes multiple times daily). The program had a number of sections in it that were encrypted on disk after compilation time and had to be decrypted at run-time. The software included a kernel module which performed the run-time encryption/decryption. To request encryption or decryption of a given section, the program shipped with a DLL that exported a function which took as arguments the number of the section and a Boolean that indicated whether the section should be encrypted or decrypted. All of the components were digitally signed.</p> <p>I employed a DLL injection-based solution that worked as follows:</p> <ul> <li>Create the process suspended.</li> <li>Inject the DLL.</li> <li>DLL hooks GetProcAddress in the program's IAT.</li> <li>GetProcAddress hook waits for a specific string to be supplied and then returns its own hooked version of that function.</li> <li>The hooked function inspects the return address on the stack two frames up to figure out the starting address of the function (call it Func) that called it.</li> <li>The hooked function then calls Func for each encrypted section, instructing it to decrypt each section. To make this work, the hooked function has to pass on the calls to the proper function in the DLL for these calls.</li> <li>After having done so, for every subsequent call to the hooked function, it simply returns 1 as though the call was successful.</li> <li>Having decrypted all the sections, the DLL now dumps the process' image onto the disk and reconstructs the import information.</li> <li>After that it does a bunch of other stuff neutralizing the other protections.</li> </ul> <p>Initially I was doing all of this by hand for each new build. That was way too tedious. One I coded the DLL injection version, I never had to undertake that substantial and manual work ever again.</p> <p>DLL injection is not widely known or used within reverse engineering outside of game hacking. This is very unfortunate, because it is an extremely powerful, flexible, and simple technique that should be part of everyone's repertoire. I have used it dozens of times and it seems to find a role in all of my dynamic projects. The moment my task becomes too cumbersome to do with a debugger script, I switch to DLL injection.</p> <p>In the spectrum of reverse engineering techniques, every capability of DLL injection is offered by dynamic binary instrumentation (DBI) tools as well, and DBI is yet more powerful still. However, DBI <a href="http://blog.coresecurity.com/2012/06/22/recon-2012-presentation-detecting-dynamic-binary-instrumentation-frameworks/" rel="noreferrer">is not stealthy</a> and incurs a serious overhead in terms of memory consumption and possibly performance. I always try to use DLL injection before switching to DBI.</p>
2252
2013-06-14T15:07:25.390
<p>I was reading a discussion about dumping a processes part of a process's memory and someone suggested using DLL injection to do this. I'll be honest in that I don't really understand. How does DLL injection work and what kinds of reversing tasks can you do with it?</p>
What is DLL Injection and how is it used for reversing?
|dll|dll-injection|
<p>Looking at it in <a href="http://www.ollydbg.de/" rel="noreferrer">OllyDbg</a> it looks like a heavy task. Looks like a custom database with encrypted and (custom?) compressed data. This or the like would usually be the case in such applications. A flat file with structured data is not part of this one.</p> <p>Anyhow. As a starter:</p> <p>A quick check after trying out some general compression tools like 7z or binwalk, (have not tested it), can be to use <a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx" rel="noreferrer">ProcMon</a> from Sysinternals. Start ProcMon, then your application and set filter on the application in ProcMon. You quickly find that:</p> <p>In short it reads in chunks of varying size, but for main data processing it reads chunks of 16384 bytes. The process in steps:</p> <ol> <li>Generate seed map of 256 integers. (Done once at application start.)</li> <li>Loop:<br /> 2.1 Read 16384 bytes into buffer from .dat file.<br /> 2.2 XOR routine on buffer using offset and last four bytes of buffer as base.<br /> 2.3 Checksum on XOR'ed buffer using seed map from step 1.<br /> 2.4 Parse buffer and read out data.</li> </ol> <p>The application also reads same chunks multiple times.</p> <hr /> <h1>2.1:</h1> <p>Example:</p> <pre><code>013D0010 D4 9E BE BF 1C 1C 0B D4 C5 E7 11 B5 09 48 87 FA Ôž¾¿ÔÅçµ.H‡ú 013D0020 29 4C 03 C9 DE 4A 2B 71 74 7F D2 48 E7 13 94 4E )LÉÞJ+qtÒHç”N ... 013D3FF0 6A D1 55 92 E2 16 60 53 69 89 86 7D D9 D8 10 BC jÑU’â`Si‰†}Ùؼ 013D4000 90 F3 D1 48 28 47 34 EC 39 36 EC 4D 69 2A 7D E5 óÑH(G4ì96ìMi*}å |_____._____| | Last DWORD aka checksum --+ </code></pre> <hr /> <p><em>Steps and details in order of discovery:</em></p> <p>Split the .dat file in chunks of 16384 bytes and also generate a hex-dump of each file for easy search and comparison. To be honest I use Linux for this part with <code>dd</code>, <code>xxd -ps</code>, <code>grep</code>, <code>diff</code> etc.</p> <p>Start OllyDbg, open the application, locate <code>CreateFile</code> and set breakpoint:</p> <pre><code>00401220 $-FF25 18825000 JMP DWORD PTR DS:[&lt;&amp;kernel32.CreateFileA&gt;; kernel32.CreateFileA </code></pre> <p>Press <code>F9</code> until filename (in <code>EAX</code>) is .dat file. Set/enable breakpoint on <code>ReadFile</code>. <code>F9</code> and when read is done start stepping and looking at what is done.</p> <hr /> <p>Looking at it:</p> <h1>2.2:</h1> <p>After read it first modify the buffer by using offset as &quot;magic&quot; starting at:</p> <pre><code>0045F5EC /$ 53 PUSH EBX ; ALGO 2: XOR algorithm - post file read. ... 0045F6B6 \. C3 RETN ; ALGO 2: RETN </code></pre> <p>At least two of the actions taken seems to be <a href="https://bitbucket.org/hbhzwj/imalse/src/74e53be30a75/tools/inet-3.0/libj_random.c#cl-350" rel="noreferrer">libj_randl1()</a> and <a href="https://bitbucket.org/hbhzwj/imalse/src/74e53be30a75/tools/inet-3.0/libj_random.c#cl-364" rel="noreferrer">libj_randl2()</a>. <em>(This would be step 2.2 in list above.)</em></p> <p>Simplified:</p> <pre><code>edx = memory address of buffer ecx = offset / 0x4000 edi = edx ebx = ecx * 0x9b9 esi = last dword of buffer &amp; 0x7fffffff ecx = 0 i = 0; while (i &lt; 0x3ffc) { /* size of buffer - 4 */ manipulate buffer } </code></pre> <p>The whole routine translated to C code:</p> <pre><code>int xor_buf(uint8_t *buf, long offset, long buf_size) { int32_t eax; int32_t ebx; int32_t esi; long i; buf_size -= 4; ebx = (offset / 0x4000) * 0x9b9; /* Intel int 32 */ esi = ( (buf[buf_size + 3] &lt;&lt; 24) | (buf[buf_size + 2] &lt;&lt; 16) | (buf[buf_size + 1] &lt;&lt; 8) | buf[buf_size + 0] ) &amp; 0x7fffffff; for (i = 0; i &lt; buf_size /*0x3ffc*/; ++i) { /* libj_randl2(sn) Ref. link above. */ ebx = ((ebx % 0x0d1a4) * 0x9c4e) - ((ebx / 0x0d1a4) * 0x2fb3); if (ebx &lt; 0) { ebx += 0x7fffffab; } /* libj_randl1(sn) Ref. link above. */ esi = ((esi % 0x0ce26) * 0x9ef4) - ((esi / 0x0ce26) * 0x0ecf); if (esi &lt; 0) { esi += 0x7fffff07; } eax = ebx - 0x7fffffab + esi; if (eax &lt; 1) { eax += 0x7fffffaa; } /* Modify three next bytes. */ buf[i] ^= (eax &gt;&gt; 0x03) &amp; 0xff; if (++i &lt;= buf_size) { buf[i] ^= (eax &gt;&gt; 0x0d) &amp; 0xff; } if (++i &lt;= buf_size) { buf[i] ^= (eax &gt;&gt; 0x17) &amp; 0xff; } } return 0; } </code></pre> <hr /> <p>Then a checksum is generated of the resulting buffer, (minus last dword), and checked against last dword. Here it uses a buffer from BSS segment that is generated upon startup, <em>step 1. from list above</em>. (Offset <code>0x00505000</code> + <code>0x894</code> and using a region of <code>4 * 0x100</code> as it is 256 32 bit integers). This seed map seems to be constant (never re-generated / changed) and can be skipped if one do not want to validate the buffer.</p> <h1>1.</h1> <p>Code point in disassembly (Comments mine.):</p> <pre><code>0045E614 . 53 PUSH EBX ; ALGO 1: GENERATE CHECKSUM MAGICK BSS ... 0045E672 . C3 RETN ; ALGO 1: RETN </code></pre> <p>The code for the BSS numbers can simplified be written in C as e.g.:</p> <pre><code>int eax; /* INT NR 1, next generated number to save */ int i, j; unsigned int bss[0x100] = {0}; /* offset 00505894 */ for (i = 0; i &lt; 0x100; ++i) { eax = i &lt;&lt; 0x18; for (j = 0; j &lt; 8; ++j) { if (eax &amp; 0x80000000) { eax = (eax + eax) ^ 0x4c11db7; } else { eax &lt;&lt;= 1; } } bss[i] = eax; } </code></pre> <hr /> <h1>2.3:</h1> <p>That bss int array is used on the manipulated buffer to generate a checksum that should be equal to the last integer in the 16384 bytes read from file. <em>(Last dword, the one skipped in checksum routine and XOR'ing.)</em>. <em>This would be step 2.3 in list above.</em></p> <pre><code>unsigned char *buf = manipulated file buffer; unsigned char *bss = memory dump 0x00505894 - 0x00505C90, or from code above eax = 0x13d0010; /* Memory location for buffer. */ edx = 0x3ffc; /* Size of buffer - 4 bytes (checksum). */ ... </code></pre> <p>At exit <code>ecx</code> is equal to checksum.</p> <p>Code point in disassembly (Comments mine.):</p> <pre><code>0045E5A8 /$ 53 PUSH EBX ; ALGO 3: CALCULATE CHECKSUM AFTER ALGORITHM 2 ... 0045E5E0 \. C3 RETN ; ALGO 3: RETN (EAX=CHECKSUM == BUFFER LAST 4 BYTES) </code></pre> <p>Shortened to a C routine it could be something like:</p> <pre><code>int32_t checksum(int32_t map[0x100], uint8_t *buf, long len) { int i; int32_t k, cs = 0; for (i = 0; i &lt; len; ++i) { k = (cs &gt;&gt; 0x18) &amp; 0xff; cs = map[buf[i] ^ k] ^ (cs &lt;&lt; 0x08); } return cs; } </code></pre> <hr /> <p>It is checked to be OK and then checksum in buffer is set as: two least significant bytes = 0, two most significant bytes are set to some number (chunk number in file or read number, (starting from 0)).</p> <pre><code>0045F9BF . C680 FC3F0000 &gt;MOV BYTE PTR DS:[EAX+3FFC],0 ; Set two lower bytes of checksum in dat buf to 0 0045F9C6 . C680 FD3F0000 &gt;MOV BYTE PTR DS:[EAX+3FFD],0 ; follows previous 0045F9CD . 66:8B4D F8 MOV CX,WORD PTR SS:[EBP-8] ; Set CX to stack pointer value of addr EBP - 8 (counter of sorts) 0045F9D1 . 66:8988 FE3F00&gt;MOV WORD PTR DS:[EAX+3FFE],CX ; Set .dat buffer higher bytes like CX. </code></pre> <hr /> <p>Now after all this is done the actual copying of data starts with even more algorithms. <strong>Here the real work starts</strong>. Identifying data types, structures, where and what etc. Found some <em>routines</em> that extracted names etc. But everything being Finnish didn't help on making it easier to grasp ;).</p> <p>The data above could be a start.</p> <p>Some breakpoints that might be of interest to begin with:</p> <pre><code>Breakpoints Address Module Active Disassembly Comment 0045E5A8 Kirjaus5 Disabled PUSH EBX ALGO 3: CALCULATE CHECKSUM AFTER ALGORITHM 2 0045E5E0 Kirjaus5 Disabled RETN ALGO 3: RETN (EAX=CHECKSUM == BUFFER LAST 4 BYTES) 0045E614 Kirjaus5 Disabled PUSH EBX ALGO 1: GENERATE CHECKSUM MAGIC BSS 0045E672 Kirjaus5 Disabled RETN ALGO 1: RETN 0045F5EC Kirjaus5 Disabled PUSH EBX ALGO 2: FILE POST XOR READ ALGORITHM 0045F6B6 Kirjaus5 Disabled RETN ALGO 2: RETN </code></pre> <hr /> <p><em>Some notes:</em></p> <p>Keep a backup of the .dat file you are working with. If you abort the application the file often gets corrupted as it, as noted by <a href="https://reverseengineering.stackexchange.com/users/1924/blabb">@blabb</a>, write data back to file. The .dat file also seem to be <em>live</em> so a new download of it would result in different data.</p>
2260
2013-06-15T15:45:41.703
<p>I want to open finnish sports league "data file" used for bookkeeping. It includes all statistics for few decade, so it's interesting data file.</p> <p>The file is here: <a href="http://www.bittilahde.fi/Tietokanta.dat" rel="noreferrer">http://www.bittilahde.fi/Tietokanta.dat</a> (Database.dat in english)</p> <p>The book keeping program is here: <a href="http://www.pesistulokset.fi/Kirjaus504.exe" rel="noreferrer">http://www.pesistulokset.fi/Kirjaus504.exe</a></p> <p>What I've found out:</p> <ul> <li>The histogram of database file is completely flat</li> <li>There's no header I could recognize in database file</li> <li>The .exe is compiled with Delphi 4</li> <li>I can find some data structures with <a href="http://kpnc.org/idr32/en/index.htm" rel="noreferrer">IDR</a>, but cannot figure out how uncompress the file.</li> </ul> <p>What could be the next step? </p>
Reverse engineering compressed file, where to start?
|file-format|
<p>There are multiple ways that you can use which <em>might</em> work (and see below for the reasons why they might not). Here are two:</p> <ul> <li>A process can debug itself, and then it will receive notifications of DLL loading.</li> <li>A process can host a TLS callback, and then it will receive notifications of thread creation. That can intercept thread creation such as what is produced by CreateRemoteThread. If the thread start address is LoadLibrary(), then you have a good indication that someone is about to force-load a DLL.</li> </ul> <p>Other than that, you can periodically enumerate the DLL name list, but all of these techniques can be defeated by a determined attacker (debugging can be stopped temporarily; thread notification can be switched off; the injected DLL might not remain loaded long enough because it might use dynamically-allocated memory to host itself and then unload the file, etc).</p>
2262
2013-06-15T22:58:17.680
<p>In <a href="https://reverseengineering.stackexchange.com/questions/2252/what-is-dll-injection-and-how-is-it-used-for-reversing">this question on DLL injection</a> multiple answers mention that DLL injection can be used to modify games, perhaps for the purposes of writing a bot. It seems desirable to be able to detect DLL injection to prevent this from happening. Is this possible?</p>
How can DLL injection be detected?
|dll|dll-injection|
<p>Apart from the compiler, because they dont have remedy for RE security. You can use obfuscation and anti debugger tricks. If you want there are lots of good packer, use them </p>
2266
2013-06-16T13:59:56.810
<p>This is similar in nature to <a href="https://reverseengineering.stackexchange.com/q/118/2044">this question</a> and <a href="https://reverseengineering.stackexchange.com/a/58/2044">this question</a>; I'm interested in what compiler settings to enabled/disable to make a Visual C++ harder to reverse engineer.</p> <p>Here's a few compiler flags I've already got which I believe should be set:<br> <code><a href="http://msdn.microsoft.com/en-us/library/vstudio/k1ack8f1.aspx" rel="nofollow noreferrer">/Ox</a></code> Full optimization. This appears to be the equivalent of gcc's -O3<br> <code><a href="http://msdn.microsoft.com/en-us/library/vstudio/k1ack8f1.aspx" rel="nofollow noreferrer">/Oy</a></code> Omit frame pointers. (x86 only)<br> <code><a href="http://msdn.microsoft.com/en-us/library/vstudio/we6hfdy0.aspx" rel="nofollow noreferrer">/GR-</a></code> Disable Run Time Type Information<br> <code><a href="http://msdn.microsoft.com/en-us/library/vstudio/2kzt1wy3.aspx" rel="nofollow noreferrer">/MT</a></code> flag is used to static link the various libraries.</p> <p>Visibility - I don't think the MSVC compiler has any options to turn off visibility like <code>-fvisibility=hidden</code> offered in gcc, but is this necessary for MSVC since the debugging symbols are stored in the PDB file?</p> <p>Are there any other things I should include to ensure minimal information is distrubuted in the application?</p> <p>(I might add that I am creating a standalone executable)</p>
Making Visual C++ harder to reverse engineer
|windows|obfuscation|c++|
<p>There are couple of ways that I could think of.</p> <p><strong>First off</strong>, you could use <a href="http://www.cuckoosandbox.org" rel="nofollow"><strong>Cuckoo Sandbox</strong></a>. It is an automated malware analysis system. It is open source and its modules are written in <a href="http://python.org" rel="nofollow"><strong>Python</strong></a>. To quote the website: </p> <blockquote> <p>Malware! Tear it apart, discover its ins and outs and collect actionable threat data. Cuckoo is the leading open source automated malware analysis system.</p> </blockquote> <p>Pretty exciting, isn't it? I believe, it will capture dropped files by default. Once a malware sample is submitted to <strong><a href="http://www.cuckoosandbox.org" rel="nofollow">Cuckoo Sandbox</a></strong> and analysis is completed, user gets analysis report. Certain sub-directory of the analysis report will contain files <strong>Cuckoo</strong> was able to dump. For more information check out <strong><a href="https://cuckoo.readthedocs.org/en/latest/usage/results/index.html?highlight=dropped" rel="nofollow">Cuckoo's Analysis Result</a></strong> page. </p> <p>In addition, you could create your own custom module to process dropped files. What are <strong>processing modules</strong>? Per <a href="https://cuckoo.readthedocs.org/en/latest/customization/processing/index.html" rel="nofollow"><strong>Cuckoo Doc Website</strong></a>: </p> <blockquote> <p>Cuckoo’s processing modules are Python scripts that let you define custom ways to analyze the raw results generated by the sandbox and append some information to a global container that will be later used by the signatures and the reporting modules. You can create as many modules as you want, as long as they follow a predefined structure...</p> </blockquote> <p>I am pretty sure there are other automated sandboxes out there as well. However, you have to remember, there is no 100% guarantee a sandbox will process your malware just the way it would execute in real life environment. </p> <p><strong>Second method</strong>. You really need to know <strong>HOW</strong> dropped files are deleted for this method to work. I have already mentioned it in the comments above. You could also patch your executable. Let's say <strong><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa363915%28v=vs.85%29.aspx" rel="nofollow">DeleteFile()</a></strong> is used. If patching malware is not an option, you could hook <strong><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa363915%28v=vs.85%29.aspx" rel="nofollow">DeleteFile()</a></strong> function system wide. It is standard Windows API used to delete a file. This function is exported by <strong>Kernel32.dll</strong>. There is a lot written about system wide or global hooks and ways to accomplish it. I will not go in details about it here. However, there is one thing worth mentioning, you have to make sure you "trick" malware into "thinking" file is indeed delete by returning appropriate values. That's why, there could be a problem with using ACL directly. What if malware checks a return of <strong>DeleteFile()</strong> (or whatever it uses to delete the dropped file), and gets <strong>ERROR_ACCESS_DENIED</strong>? It might very well divert it from the regular "desired" execution path. </p> <p>In addition, there are debuggers out there, that you help you make this process rather semi-automated. To mention few: <a href="http://debugger.immunityinc.com" rel="nofollow"><strong>Immunity Debugger</strong></a> by <a href="http://www.immunityinc.com" rel="nofollow"><strong>Immunity Inc</strong></a>. It employs very well supported Python API for automation and scripting. There are other option out there as well.</p> <p>What I would like to mention at the end is that you are absolutely right. You might need to look into creating a little tool of your own. There is no "one-fits-all" solution. Some automated solutions might work better then others. From time to time you will have to dig in. Remember, getting your hands "dirty" gives you great and in-depth understanding of things happening behind the "curtain". I personally love such an involvement, and find it to be a really great learning experience.</p>
2274
2013-06-16T20:24:40.950
<p>Can anyone suggest a tool to prevent a malware from deleting itself on Windows x64? The purpose is to collect all the components of the whole process of infection.</p> <p>I've looked at CaptureBat, but its drivers are only 32-bit. I also thought about using file recovery utilities for this.</p>
Prevent malware from deleting itself during installation on Windows x64
|windows|malware|digital-forensics|
<p>Thank you all so much for your answers and comments. While reading your comments and preparing to update my question, I found the answer. </p> <p>I must give credit to <a href="https://reverseengineering.stackexchange.com/users/60/igor-skochinsky">Igor Skochinsky</a>, who asked me to provide functions' prolog instructions. Both functions use the <a href="http://en.wikipedia.org/wiki/X86_calling_conventions#cdecl" rel="nofollow noreferrer">cdecl calling convention</a>. However, calling convention has nothing to do with this buffer. This is what the prolog looks like:</p> <pre><code>push ebp mov ebp, esp sub esp, &lt;size of local vars&gt; push ebx push esi push edi </code></pre> <p>This buffer reflects <strong>three push instructions</strong> for registers EBX, ESI, EDI. These registers are categorized as <strong>Callee Saved Registers</strong> and this "buffer" is called <strong>Non-Volatile Register Save Area</strong>. </p> <p>In accordance to x86 convention (it is also applicable to x64), registers are divided into <strong>Caller Saved Registers</strong> and <strong>Callee Saved Registers</strong>. </p> <p>Caller saved registers are also known as volatile registers. Those are core CPU registers such as EAX, EDX, and ECX. A calling function (Caller) is responsible for saving volatile registers onto usually runtime stack before making a call. </p> <p>Callee saved registers are known as non-volatile registers. Those are core CPU registers such as EBX, ESI, EDI, ESP, and EBP. It is assumed by convention, that values in those registers will be preserved by a callee function. In case any of the non-volatile registers are going to be used within a callee, the callee is responsible to save the registers onto runtime stack. In addition, the callee is responsible to restore those registers before returning to a caller function.</p> <p>The way volatile and non-volatile registers used is rather compiler driven. The following paper <a href="http://www.cs.virginia.edu/~evans/cs216/guides/x86.html" rel="nofollow noreferrer"><strong>x86 Assembly Guide</strong></a> describes Caller and Callee rules in more detail. </p>
2283
2013-06-19T02:00:31.260
<p>IDA Pro displays certain buffer or padding above (at lower addresses) local variables in stack frame view. For instance:</p> <p><strong>Example 1.</strong><br> The following screen shot of stack frame view shows 12 bytes (included in the red box) buffer: </p> <p><img src="https://i.stack.imgur.com/wB1ok.png" alt="enter image description here"></p> <p><strong>Example 2.</strong><br> The following screen shot of a different stack frame view shows 12 bytes buffer again:</p> <p><img src="https://i.stack.imgur.com/ForTX.png" alt="enter image description here"></p> <p>I understand that IDA marked it as <strong><code>db ?; undefined</code></strong> because it couldn't figure out how it was used. I also realize that IDA automatically calculates size of a stack frame by monitoring ESP. I would assume it might have something to do with non-volitile register save area. However, in <strong>Example 1</strong> it clearly shows <strong><code>Saved regs: 0</code></strong> and in <strong>Example 2</strong> it shows <strong><code>Saved regs: 4</code></strong>. I am puzzled, and here go my questions:</p> <p>Why does IDA Pro display certain buffer or padding above (at lower addresses) local variables in stack frame view? Is it a coincidence that both views show exactly <strong>12 bytes</strong> buffer? Is it something particular to certain calling convention or complier? </p>
IDA Pro function stack frame view
|disassembly|static-analysis|ida|calling-conventions|
<p>if you determined the argv and argc and values in there you gone half of the way . from value of argc you can understand how many arguments you should pass and from values in argv you can determine what you "should" pass.</p> <p>i wrote a very simple example for you</p> <pre><code>70 _main proc near ; CODE XREF: _main_0j .text:00401070 .text:00401070 var_44 = byte ptr -44h .text:00401070 var_4 = dword ptr -4 .text:00401070 arg_0 = dword ptr 8 .text:00401070 arg_4 = dword ptr 0Ch .text:00401070 .text:00401070 push ebp .text:00401071 mov ebp, esp .text:00401073 sub esp, 44h .text:00401076 push ebx .text:00401077 push esi .text:00401078 push edi .text:00401079 lea edi, [ebp+var_44] .text:0040107C mov ecx, 11h .text:00401081 mov eax, 0CCCCCCCCh .text:00401086 rep stosd .text:00401088 cmp [ebp+arg_0], 2 .text:0040108C jge short loc_4010A0 .text:0040108E push offset aCheckUsage ; "check usage" .text:00401093 call _printf .text:00401098 add esp, 4 .text:0040109B or eax, 0FFFFFFFFh .text:0040109E jmp short loc_4010DB </code></pre> <p>as you can see there is <code>cmp [ebp+arg_0], 2</code> it means at least we have to pass one "argument" then there is jqe (jump if greater or equal) .</p> <p>so we will call program with one argument to pass this condition so we will be in <code>loc_4010A0</code> and here is the code .</p> <pre><code>0 loc_4010A0: ; CODE XREF: _main+1Cj .text:004010A0 push offset Str2 ; "n00b" .text:004010A5 mov eax, [ebp+arg_4] .text:004010A8 mov ecx, [eax+4] .text:004010AB push ecx .text:004010AC call _strcmp .text:004010B1 add esp, 8 .text:004010B4 mov [ebp+var_4], eax .text:004010B7 cmp [ebp+var_4], 0 .text:004010BB jle short loc_4010CC .text:004010BD push offset aWrongPassword ; "wrong password !!!" .text:004010C2 call _printf .text:004010C7 add esp, 4 .text:004010CA jmp short loc_4010D9 </code></pre> <p>now as you can see we have another compare here this time using strcmp and before that we will push our str and <code>arg_4</code> and here is our actual argument vector . </p> <p>you can really easily analysis arguments using static and dynamic analysis but there is a few notes you have to keep in your mind .</p> <ol> <li>how many arguments we have to pass</li> <li>type of arguments</li> <li>location of arguments (argv)</li> </ol> <p>also there is additional note here , sometime maybe we "DO NOT" use argc/argv for getting command line arguments we can use windows API like <code>GetCommandLine</code> and so on too. you have to check how arguments are received and parsed too.</p>
2299
2013-06-20T04:16:38.990
<p>I am working on a console windows executable. So far what I figured out is that the executable checks number of command line arguments. Afterwards, it branches out depending on the number of arguments passed (argv). The jumps are looked up using some sorts of jump table, which is constructed dynamically. It seems to be a daunting task try to figure out all of the possible command line arguments. It looks like the binary only executes only when certain number of particular arguments is parsed. I have collected some possible options using <code>strings</code> utility. </p> <p>Is there a general road map for reversing command line arguments? What are possible approaches to reversing them? Are there any tools that could be employed?</p>
How to reverse command line arguments?
|disassembly|binary-analysis|ida|c|c++|
<p>The strategy used by Metasm is referenced in the peer-reviewed literature on their website. Look at <a href="http://metasm.cr0.org/docs/sstic08-metasm-jcv.pdf" rel="nofollow">the article published in the Journal of Computer Virology in 2008</a>, in section 3.1. To quote them, </p> <blockquote> <p>Standard disassembly. </p> <p>Out of the box, the disassembly engine in Metasm works this way :</p> <ol> <li>Disassemble the binary instruction at the instruction pointer.</li> <li>Analyse the effects of the instruction.</li> <li>Update the instruction pointer.</li> </ol> </blockquote> <p>That sounds more like recursive traversal to me, and less like linear sweep. The engine disassembles the next instruction based upon the effects of the previous instruction, which would allow the disassembly engine to follow branches in the logic, etc.</p> <p>Also, I have not examined their code in-depth, but in <code>metasm/disassemble.rb</code> it looks like they maintain some sort of autoanalysis queue for addresses to continue analyzing. Look for functions referencing backtracing - it definitely seems like recursive traversal.</p>
2302
2013-06-20T09:06:48.170
<p><a href="http://metasm.cr0.org/" rel="nofollow">Metasm</a> is an assembly manipulation suite written in Ruby. It does provide a quite extensive API for disassembling and extracting a CFG representation from a binary program.</p> <p>I would like to know what algorithm is used to extract the CFG. Is this usual linear sweep or recursive traversal, or is another algorithm?</p>
What algorithm does Metasm use to dissassemble binary code?
|disassembly|
<p>The short answer is "Yes." In fact, if you experiment by generating machine language op codes directly you will discover that there is a whole range of operations that are effectively NOPs, all of which take a single processor cycle to execute.</p> <p>While they are not technically "Documented," you will find that very close to the 0x90,</p> <ul> <li><code>XCHG EAX, EAX</code></li> <li><code>XCHG EBX, EBX</code></li> <li><code>XCHG ECX, ECX</code></li> <li><code>XCHG EDX, EDX</code></li> </ul>
2304
2013-06-20T15:47:39.810
<p>I have recently learned that <code>nop</code> instruction is actually <code>xchg eax, eax</code>... what it does is basically exchanges <code>eax</code> with itself. </p> <p>As far as CPU goes, does the exchange actually happen?</p>
NOP instruction
|assembly|x86|
<p>You might be interested in the Dr. Gadget IDAPython script (screenshots <a href="http://www.openrce.org/blog/view/1570/Dr._Gadget_IDAPython_plugin">here</a>, code <a href="https://github.com/patois/DrGadget">here</a>).</p> <blockquote> <p>This little IDAPython plugin helps in writing and analyzing return oriented payloads. It uses IDA's custom viewers in order to display an array of DWORDs called 'items', where an item can be either a pointer to a gadget or a simple 'value'.</p> </blockquote>
2308
2013-06-21T02:05:30.857
<p>How are <a href="http://cseweb.ucsd.edu/~hovav/talks/blackhat08.html">return-oriented programs</a> decompiled/reverse engineered ?</p> <p>Any pointers to any papers or reports would be appreciated.</p>
Decompiling return-oriented programs
|decompilation|exploit|
<p>Well you have to first Undefine the code using U key and they select the code and right click you will have some options like C (code) and so on. IDA almost give you ability of doing anything wih obfuscated code to help you to understand code correctly.</p> <p><em>Addendum</em> After converting to C (code), do Alt+P to create/edit function. In addition, rebuild layout graph by go to Layout view, right clicking empty space and selecting "Layout graph".</p>
2309
2013-06-21T03:31:25.453
<p>I am working on an obfuscated binary. IDA did pretty good job distinguishing code from junk. However, I had started messing around with a function changing from <code>code</code> to <code>data</code> and vice versa and completely messed the function up and destroyed the way it looked like. I don't want to start new database on the executable and re-do all my work. </p> <p>Is there a way to re-analyse a single function and return it to the way it looked like after initial analysis?</p>
How to re-analyse a function in IDA Pro?
|disassembly|ida|
<p>This option has limited value.</p> <hr /> <blockquote> <p>IDA produces executable files only for:</p> <ul> <li>MS DOS .exe</li> <li>MS DOS .com</li> <li>MS DOS .drv</li> <li>MS DOS .sys</li> <li>general binary</li> <li>Intel Hex Object Format</li> <li>MOS Technology Hex Object Format</li> </ul> <p>-- <em>IDA Help file</em></p> </blockquote> <hr /> <blockquote> <p>While this is the most promising menu option, it unfortunately is also the most crippled. In a nutshell, it doesn't work for most file types...</p> <p>-- <em><a href="http://nostarch.com/idapro.htm" rel="noreferrer">The IDA Pro Book</a>, Chapter 14</em></p> </blockquote> <p>That chapter goes into more detail why this option is not very useful. For starters, IDA doesn't parse and save contents of sections such as <code>.rsrc</code>, and doesn't have a way to rebuild import/export tables back into their original format.</p> <p>Read this book. Not just for this question, it's a good and useful read.</p>
2315
2013-06-24T13:15:36.283
<p>I have come across <code>File -&gt; Create EXE file...</code> option in IDA. I thought one couldn't use IDA for patching. I have tried playing with it. However, it gives me the following error: <strong><code>This type of output files is not supported.</code></strong></p> <p>What is this option for? What is possible usage of it?</p>
IDA Pro: What does "Create EXE file..." option do?
|disassembly|ida|patching|
<p>I personally recommend <a href="http://www.ntcore.com/exsuite.php" rel="nofollow noreferrer">CFF Explorer</a> for reversing purposes as it provides a large volume of additional information on a binary.</p> <p><img src="https://i.stack.imgur.com/GkpUa.png" alt="CFF Explorer"></p>
2319
2013-06-25T08:20:30.947
<p>I am using Resource Hacker as a tool to extract out resources like icon, images, etc. from <code>.dll</code> or <code>.exe</code> file. In addition, I am using it to crack some small Windows application. However, it does not work with all Win32 Application, especially with those that are zipped by <code>.exe</code> compressor.</p> <p>Are there any other open source applications, that I can use to crack and extract resources out of <code>.dll</code> and <code>.exe</code> files?</p>
Freely available resource hacking applications
|tools|windows|dll|executable|pe-resources|
<p>The classic work on the decompilation is Cristina Cifuentes' PhD thesis <a href="http://zyloid.com/recomposer/files/decompilation_thesis.pdf">"Reverse Compilation Techniques"</a>. She describes generation of C code in Chapter 7.</p> <p>The author of the REC decompiler also has a nice summary about the decompilation process, though it's more informal:</p> <p><a href="http://www.backerstreet.com/decompiler/introduction.htm">http://www.backerstreet.com/decompiler/introduction.htm</a></p> <p>For completeness, here's Ilfak's whitepaper on the Hex-Rays decompiler, though he glances over this specific issue, only mentioning that it's "Very straightforward and easy" :):</p> <p><a href="http://www.hex-rays.com/products/ida/support/ppt/decompilers_and_beyond_white_paper.pdf">http://www.hex-rays.com/products/ida/support/ppt/decompilers_and_beyond_white_paper.pdf</a></p>
2320
2013-06-25T08:41:28.930
<p>I have been interested in automatic vulnerability assessment and decompilation of code for a while now. And as a result I have been building parsers in Python that reads a bin, disassembles it instruction by instruction while tracing the execution (the way IDA does it).</p> <p>I have been tracing the polluted registers (polluted as in user input) to check when such registers allow us to setup a call or a jump. </p> <p>This research has grown to the point, where I want to transform it to a decompiler. I had a look at boomerang and other open source decompilers. I have also had a quick peek inside the dragon book (I don't own it). I would like to hear what you guys think about this idea. Below is my outline:</p> <ol> <li>Open the binary file to decompile.</li> <li>Detect a filetype (PE or ELF) to select the EP and memory layout.</li> <li>Jump to the EP and follow execution path of the code while disassembling. I use udis86 for it. This execution is in a libemu kind of way.</li> <li>Parse the resulting assembly an middle language. To get simpler instructions, (e.g. always remove things like <code>SHL EAX, 0x02</code> and change those things to <code>MUL</code> instructions). </li> <li>Parse it into a Abstract Syntax Tree. </li> <li>Optimize the AST (although, I have no idea how). </li> <li>Transform the AST to something that looks like C.</li> </ol> <p>I am having issues with the last 2 steps. How does someone parse AST to a real language or something that looks like it? How do you optimize ASTs? Are there build C or Python libraries to accomplish it?</p>
How do you optimise AST's or convert them to a real language
|decompilation|decompiler|ast|
<p>What immediately comes to mind is some type of virtualization layer accessing an IAT or IVT. I absolutely agree with the previous answer that this is a call to a function vector in an array of function pointers. I also agree that it does not look like a switch statement. That's what takes me down the interrupt vector table/address table.</p>
2326
2013-06-25T15:18:55.567
<p>I have come across the following instructions:</p> <pre><code>mov ecx, [ebp + var_4] imul ecx, 4 call dword_1423d4[ecx] </code></pre> <p>Can someone explain to me what it possibly means or point me in the right direction? Why is the call made to a variable?</p>
Call to variable address
|disassembly|
<p>An alternative answer is that you are looking at hand coded assembly and there is actually no effort to deceive the disassembler.</p> <p>When I hand code assembly, regardless of what good practice is, if it is a small bit of code I will very frequently set the Data Selector to match the Code Selector and simply embed my data right inside of the code segment. I especially do this if I'm writing a real mode boot loader, for example, or some other short lived piece of code.</p> <p>Another place I would do this and still not be trying to obfuscate things is in a piece of exploit code. This allows me to have variables that I can reference reliably and still have a really tight piece of shell code.</p>
2328
2013-06-25T17:01:57.607
<p>I have recently seen the following code obfuscation method: </p> <pre><code>... jump loc_1234 ;------------------------- Bunch of junk ;------------------------- loc_1234: code continued... </code></pre> <p>The logic behind the obfuscation mechanism looks pretty straight forward. Bunch of junk is inserted into code with jump instructions to jump over it. I guess, the purpose is to confuse linear sweep disassemblers and obfuscate file in general. I would like to learn more about it. Does anyone know what it is called? How effective is this method against modern day anti-virus software?</p>
What is this obfuscation method called?
|disassembly|malware|obfuscation|
<p>Developer console.,</p> <p>Once you open your internet go to the settings and to find developer console. What ever is on the page will be provided in the source code. You just have to find it. Some sites block this info from viewers being able to see the things like location, dates, times. But depending on what site you're visiting you may be able to find this information. As long as the site isn't high security, like government or porn..... You should be able to find the original links and everything else to be honest. You will be surprised at the amount of information that can be pulled from this. If you ask me, This is the smartest and most simplistic way to do it. You don't have to build any code or use anyone's else's code. Your just simply phishing for the information you need on the websites source code.</p>
2331
2013-06-25T18:19:19.183
<p>Some sites like The Free Dictionary, and many other translation and pronunciation services, offers a <a href="http://www.thefreedictionary.com/hacker">little icon next to the word</a> so you could hear its pronunciation.</p> <p>How can I figure out the source for an audio\video embedded file on a webpage? Where do I start?</p>
How do I get the location of the original audio/video file embedded on a webpage?
|embedded|
<p>CPLDs are frequently used for glue logic. They are quite limited compared to FPGAs and implement a sea of gates design rather than more general LUTS found in FPGAs. Although that probably isn't always the case some CPLDs may be nothing more than a tiny FPGA with a built in ROM. </p> <p>CPLDs usually have a built in ROM making them harder or near impossible to RE. Since there is no external configuration.</p> <p>FPGAs are often equivalent to a million+ gates. Whereas CPLDs are at most in the tens of thousands of gates. They might be more accurately called Simple Programmable Logic Devices!</p> <p>If there is no identification on the package you are going to have a hard time doing anything with it.</p> <p>Though, sometimes its sufficient to see what is connected to the IO pins of the CPLD to tell what it is used for. </p>
2338
2013-06-26T11:34:19.687
<p>Sometimes you can find a CPLD (Complex Programmable Logic Device) on a circuit board.</p> <ul> <li>What can you do to find out what it is for?</li> <li>What are the limits and capabilities?</li> <li>What are common applications for a CPLD?</li> </ul>
What can you find out about an unknown CPLD?
|hardware|fpga|
<p>I do not know any real-life opaque predicate. But there is a very constructive predicate obfuscator in the paper <a href="http://rosaec.snu.ac.kr/meet/file/20090204paperc.pdf" rel="nofollow">Limits of Static Analysis for Malware Detection</a>. It is proved to be NP-hard for precise static analysis.</p>
2340
2013-06-26T11:45:31.437
<p>Opaque predicate are used to disrupt automatic analysis of the binary code by reaching the limits of what can do an analyzer.</p> <p>Can somebody give an example (or a few examples) of an opaque predicate found in a real-life case ? And, what are the methods used to build new opaque predicates ?</p>
How to design opaque predicates?
|obfuscation|
<p>I have decided to post my answer not to overthrow Igor's answer, but to have an addition to it. I was not comfortable with editing his post either. I am pretty new to the forum and not sure how it is taken by other members. </p> <p>There is a little theory I have recently learned, which I would like to share. Anyways, what I have taken in about IDA Pro from <a href="http://nostarch.com/idapro.htm">The IDA Pro Book</a> (Part I, Section 1) is that it uses <strong><code>Recursive Descent Disassembly</code></strong>, which is based on the concept of control flow. The key element to this approach is the analysis of each instruction in order to determine if it is referenced from any other location. Each instruction is classified according to how it interacts with EIP. There are several main classifications:</p> <ol> <li><strong>Sequential Flow Instuctions</strong>. Those are instruction that pass execution to the next instruction to follow such as <code>add</code>, <code>mov</code>, <code>push</code>, <code>pop</code>, etc. Those instructions are disassembled with <strong>linear sweep</strong></li> <li><strong>Conditional Branching Instructions</strong>. Those are <em>True/False</em> conditional instructions such as <code>je</code> and such. Conditional instructions only offer 2 possible branches of execution. If condition is <em>False</em> and jump is not taken disassembler proceeds with <strong>linear sweep</strong>, and adds jump target instruction to a list of deferred code to be disassembled at later time using <strong>recursive descent algorithm</strong></li> <li><strong>Unconditional Branching Instructions</strong>. Those instruction can cause particular problems for recursive descent disassemblers in case the jump target is calculated at runtime. Unconditional branches do not follow linear flow. If possible, disassembler will attempt to add the target of the unconditional jump for further analysis. If target is not determined, there is going to be no disassembly for the particular branch.</li> <li><strong>Function Call Instructions</strong>. Call instructions are mostly treated as Unconditional Branching Instructions with expectation that execution would return to the instruction following the call as soon as function completes. The target address address of the call instruction is queued for deferred disassembly, and the instruction following the call is processed as linear sweep. However, it is not always possible to determine target of the call (e.g. <code>call eax</code>). </li> <li><strong>Return Instructions</strong> Return instructions do not offer any information to disassembler about what to execute next. Disassemblers cannot pop the return address from the top of the stack. All of that brings disassembler to stop. At this point disassembler turns to the saved list of deferred targets to follow next. That is exactly why it is called <strong><em>recursive</em></strong>.</li> </ol> <p>To summarize, I would like to quote <a href="http://nostarch.com/idapro.htm">The IDA Pro Book</a>:</p> <blockquote> <p>One of the principle advantages of the recursive descent algorithm is its superior ability to distinguish code from data. As a control flow-based algorithm, it is much less likely to incorrectly disassemble data values as code. The main disadvantage of recursive descent is the inability to follow indirect code paths, such as jumps or calls, which utilize tables of pointers to look up a target address. However, with the addition of some heuristics to identify pointers to code, recursive descent disassemblers can provide very complete code coverage and excellent recognition of code versus data.</p> </blockquote>
2347
2013-06-26T15:34:43.370
<p>Disassembling binary code is a quite difficult topic, but for now only two (naive) algorithms seems to be broadly used in the tools.</p> <ul> <li><strong>Linear Sweep</strong>: A basic algorithm taking all the section marked as <em>code</em> and disassembling it by reading the instructions one after each other.</li> <li><strong>Recursive Traversal</strong>: Refine the linear sweep by remembering when (and where) a <code>call</code> has been taken and returning to the last <code>call</code> when encountering a <code>ret</code>.</li> </ul> <p>Yet, the description of these algorithms are quite vague. In real-life tools, they have been a bit refined to improve the accuracy of the disassembling. </p> <p>For example, <code>objdump</code> perform a linear sweep but will start from all the symbols (and not only the beginning of the sections marked as <code>code</code>.</p> <p>So, can somebody give a more realistic description of the recursive traversal algorithm (<em>e.g.</em> as it is coded in IDAPro) ?</p>
What is the algorithm used in Recursive Traversal disassembly?
|disassemblers|
<p>Old question, but as of IDA 6.5, there is a new menu option <code>Edit/Export data...</code> that handles this situation for you. First select the data you wish to export then, via the menu option, choose the output format and file name in which to save the data.</p>
2351
2013-06-27T03:23:36.630
<p>While disassembling a malware binary, I came across several arrays of shorts. The size of each array is 1024 members. I would like to export them to C style arrays, as:</p> <pre><code>short array1[1024] = { 2, 5, 8, ... , 4}; /* This is just an example */ </code></pre> <p>I could definitely do <em>Copy/Paste</em> and edit the whole thing by hand. However, it seems to be pretty tedious. I wonder, is there a better approach to achieve it? Could it be done with script/plugin? </p>
IDA Pro: How to export data to C style array?
|disassembly|ida|ida-plugin|
<p>Cubesuite+ can disassemble hex files.</p> <p>1) Download and install <a href="http://www.renesas.com/products/tools/ide/ide_cubesuite_plus/index.jsp" rel="nofollow noreferrer">Cubesuite+ from Renesas</a>. V2.0.0 was used in this instance.</p> <p>2) Start Cubesuite+</p> <p>3) Go to Project -> Create New Project</p> <p><img src="https://i.stack.imgur.com/C6QLK.png" alt="Cubesuite+"></p> <p>4) Change the Microcontroller to the correct one.</p> <p>5) Change the Kind of Project to "Debug Only".</p> <p><img src="https://i.stack.imgur.com/E7qLx.png" alt="Project setup"></p> <p>6) Once the project has been created, in the Project Tree, right click on Download files and go to Add</p> <p>7) Find your hex or bin file and load it.</p> <p><img src="https://i.stack.imgur.com/HdQg2.png" alt="Add download file"></p> <p>8) Go to Debug -> Build and Download</p> <p>9) The 78K0R simulator starts and the disassembly is visible.</p> <p>I have yet to work out how to denote instruction and data segments.</p>
2354
2013-06-27T06:33:15.577
<p>Another slightly esoteric microcontroller in a product I'm looking at - the NEC 78K0R microcontroller. This is a 16-bit extension of the 78K0. The 78K0 can be disassembled in IDA Pro, but not the 78K0R.</p> <p>Renesas Cubesuite allows viewing of disassembly of code compiled/assembled through it, as does IAR Workbench, but I can't see a way of loading a bin or hex file into these for disassembly.</p> <p>KPIT GNU binutils has support for the RL78, which has a lot in common with the 78K0 instruction set, but is still very different.</p> <p>Is there a free disassembler for these microcontrollers?</p>
Are there any free disassemblers for the NEC 78K0R family of processors?
|tools|disassembly|nec-78k0r|
<p>You can attach to the process <code>non invasive</code> and use !<code>chkimg !chkallimg !chksym</code> commands.</p> <p>Look for <code>non invasive check box</code> in the attach to process dialog in <code>windbg</code> or use <code>.attach -v "pid"</code></p> <p>Attaching in a non invasive way minimizes debugger interference and in most cases will not trigger the anti-debugging routines.</p>
2355
2013-06-27T15:16:48.137
<p>A common anti-debugging practice is to overwrite functions such as DbgUiRemoteBreakin within ntdll.dll. </p> <p>Since in-memory representation of common libraries is always the same on each platform, it should be possible for an external tool to connect to a process and compare in-memory library code with a reference in order to find any manipulations done by the process itself.</p> <p>Does anybody know such a tool for Windows?</p>
Tool for checking for in-memory code modifications of loaded DLLs
|tools|windows|dll|
<p>Section names don't mean anything to the PE loader and you can set them manually or change them using hex editors. So the only real way of knowing the section's real properties is by checking <code>IMAGE_SECTION_HEADER</code>'s <code>Characteristics</code> field. Use a PE dumping utility like dumpbin and check to see if the section is marked as executable.</p>
2359
2013-06-27T20:05:38.347
<p>I have a file that among other sections has:</p> <ul> <li><code>code</code></li> <li><code>.text</code></li> <li><code>.bss</code></li> </ul> <p>And this file was not crafted manually, so I suspect. </p> <p>The question is what could be the meaning of <code>code</code> and <code>.text</code> sections? As far as I know, executable code is located in <code>.text</code> section, so why compiler would add the other one? </p> <p>If you need more information for answer I'll try to provide as much as I can.</p>
Question regarding sections in PE image
|pe|
<p>I haven't done a lot with NFC, but I recommend starting the same way I did. Start at the hardware level and then work up. </p> <p>Hardware: + BladeRF (I think it works with NFV)</p> <ul> <li>Misc Extra tags (get different ones from different vendors)</li> </ul> <p>Software: + nfcinteractor (android)</p> <p>Also check out: www.securitytube.net/video/8029</p> <p>It's a really good talk on NFC related research.</p>
2372
2013-06-28T10:04:32.957
<p>I recently stumbled on a <a href="http://www.reddit.com/r/ReverseEngineering/comments/1ep2ur/reverse_engineering_a_mass_transit_ticketing/" rel="nofollow">talk</a> from Ruxcon 2012 explaining the reverse of a mass transit ticketing system. </p> <p>Basically, they focused on paper tickets reverse engineering with a skimmer and a lot of brain activity. This seems to be quite amusing and interesting. But, nowadays a big part of the ticketing system is also using NFC (Near Field Communication) or RFID (Radio Frequency IDentification) especially for people who are subscribing for a month or more.</p> <p>I found a few websites (like <a href="http://users.skynet.be/marc.sel/index-MTC.html" rel="nofollow">this one</a> or <a href="http://wiki.yobi.be/wiki/MOBIB" rel="nofollow">this one</a>), trying to gather knowledge about how all this ticketing system works. But, nothing really global and fully furnished (from the paper ticket system up to the NFC/RFID system). I would like to know how to set up such a lab.</p> <ul> <li>What hardware is required (skimmer, NFC/RFID/Smartcard reader, the needed computing power to gather, ...) ?</li> <li>What is, approximately, the cost, in time for setting such a lab (and getting the necessary material to work on) ?</li> <li>How to proceed once the lab has been set-up and the material gathered ?</li> <li>Is there some tricks that can lower the cost/time that you spend on it ?</li> </ul>
How to set-up a lab for reversing a mass transit ticketing system?
|hardware|smartcards|
<p>The first law is, "Don't reverse what you don't own". When you pirate software, and then reverse it you do something that will bite you in the ass. </p> <h2>United States</h2> <p>In the United States even if an artifact or process is protected by trade secrets, reverse-engineering the artifact or process is often lawful as long as it is obtained legitimately. Patents, on the other hand, need a public disclosure of an invention, and therefore, patented items do not necessarily have to be reverse-engineered to be studied. (However, an item produced under one or more patents could also include other technology that is not patented and not disclosed.) One common motivation of reverse engineering is to determine whether a competitor's product contains patent infringements or copyright infringements. The reverse engineering of software in the US is generally a breach of contract as most EULAs specifically prohibit it, and courts have found such contractual prohibitions to override the copyright law which expressly permits it; see Bowers v. Baystate Technologies. Sec. 103(f) of the DMCA (17 U.S.C. § 1201 (f)) says that if you legally obtain a program that is protected, you are allowed to reverse-engineer and circumvent the protection to achieve interoperability between computer programs (i.e., the ability to exchange and make use of information). The section states: (f) Reverse Engineering.—</p> <ol> <li>Notwithstanding the provisions of subsection (a)(1)(A), a person who has lawfully obtained the right to use a copy of a computer program may circumvent a technological measure that effectively controls access to a particular portion of that program for the sole purpose of identifying and analyzing those elements of the program that are necessary to achieve interoperability of an independently created computer program with other programs, and that have not previously been readily available to the person engaging in the circumvention, to the extent any such acts of identification and analysis do not constitute infringement under this title.</li> <li>Not withstanding the provisions of subsections (a)(2) and (b), a person may develop and employ technological means to circumvent a technological measure, or to circumvent protection afforded by a technological measure, in order to enable the identification and analysis under paragraph (1), or for the purpose of enabling interoperability of an independently created computer program with other programs, if such means are necessary to achieve such interoperability, to the extent that doing so does not constitute infringement under this title.</li> <li><p>The information acquired through the acts permitted under paragraph (1), and the means permitted under paragraph (2), may be made available to others if the person referred to in paragraph (1) or (2), as the case may be, provides such information or means solely for the purpose of enabling interoperability of an independently created computer program with other programs, and to the extent that doing so does not constitute infringement under this title or violate applicable law other than this section.</p></li> <li><p>For purposes of this subsection, the term 「interoperability」 means the ability of computer programs to exchange information, and of such programs mutually to use the information which has been exchanged.</p></li> </ol> <h2>European Union</h2> <p>Article 6 of the 1991 EU Computer Programs Directive allows reverse engineering for the purposes of interoperability, but prohibits it for the purposes of creating a competing product, and also prohibits the public release of information obtained through reverse engineering of software. In 2009, the EU Computer Program Directive was superseded and the directive now states:[29] (15) The unauthorised reproduction, translation, adaptation or transformation of the form of the code in which a copy of a computer program has been made available constitutes an infringement of the exclusive rights of the author. Nevertheless, circumstances may exist when such a reproduction of the code and translation of its form are indispensable to obtain the necessary infor­mation to achieve the interoperability of an indepen­dently created program with other programs. It has therefore to be considered that, in these limited circum­stances only, performance of the acts of reproduction and translation by or on behalf of a person having a right to use a copy of the program is legitimate and compatible with fair practice and must therefore be deemed not to require the authorisation of the right­holder. An objective of this exception is to make it possible to connect all components of a computer system, including those of different manufacturers, so that they can work together. Such an exception to the author's exclusive rights may not be used in a way which prejudices the legitimate interests of the rightholder or which conflicts with a normal exploitation of the program.</p> <p>Source:Wikipedia</p> <h2>Conclusion</h2> <p>Anyway, reversing a ticketing system will most probably be seen as illegal as there is nothing to gain expect from free travel exploitation. If you represent a university you might get this done legally.</p>
2373
2013-06-28T10:18:03.607
<p>Following the question about "<a href="https://reverseengineering.stackexchange.com/questions/2372/how-to-set-up-a-lab-for-reversing-a-mass-transit-ticketing-system">How to set-up a lab for reversing a mass transit ticketing system?</a>", I would like to know what are the legal issues about setting up such a lab.</p> <p>It seems clear that, depending on the country (or the continent: America/Europe), you might encounter a few problems just looking at such system. But, is there ways to work around or just to not get caught ? And, what is really really strictly forbidden ?</p>
What are the legal issues when trying to reverse a mass transit ticketing system?
|law|
<p>I am using IDA for about 10 years and I have been using Hopper for a few months (on Kubuntu and Windows).</p> <p>It depends what you want to do, what budget you have and whether it's hobby or professional.</p> <p>Clearly, IDA is more powerful in most aspects. It supports a wider ranger of processors, has more loaders and a plugin system as well as two powerful scripting languages (IDC/Python).</p> <p>Given the price tag, Hopper is <strong>well worth</strong> the purchase. Indeed, I can confirm that the decompiler is more simplistic than even the Hex-Rays decompiler in its beta some years back (I have never used it again since then). If someone wants to start with reverse engineering, I am clearly recommending IDA Freeware for those that work only with Windows PE files (and outside a commercial context) and Hopper if the hobbyist is willing to shell out a few bucks.</p> <p>There are a few things to consider: do you look for a decompiler or a disassembler and what's your budget? From daily use I'd say that the disassembler for x86 and x64 is pretty much equivalent for ELF (Linux) and PE (Windows) files from my point of view.</p> <p>All features in Hopper seem to function as well as you'd expect from a fairly new product (meaning the time of development that went into it overall) and the price tag. It is being improved all the time, so you'll be able to get feature updates.</p> <p>However, the biggest - by far - <strong>disadvantage</strong> for me is the "learning curve". A lot of the features in Hopper have different shortcuts or slightly different work flows, but one can clearly see how the author must be aware of IDA and recent developments in IDA (notably since about IDA version 5.0). Although I come from the other side, I think someone starting with Hopper will benefit from it when later going professional and switching to paid IDA.</p> <hr> <p>Last but not least a note about decompilers. Being more acquainted with disassemblers I actually found results of Hex-Rays confusing and ambiguous in many cases in the past. The same holds for decompilation results of Hopper. If you are a seasoned reverser, disassembly sometimes tends to be "clearer" (albeit less convenient) the more experience you have.</p>
2378
2013-06-28T23:19:52.047
<p><a href="http://www.hopperapp.com/" rel="noreferrer">Hopper</a> seems to be focused on Mac, but how does its capabilities on Windows or Linux compares with the free version of IDA for reversing x86/x64 executables? </p> <p><a href="http://www.hopperapp.com/" rel="noreferrer">Hopper</a> seems to have all the major features IDA has; a graph view, ability to rename objects, and a Python API, yet IDA is still the standard.</p> <p>Are these features in Hopper as effective as in IDA? Are there any known deficiencies in Hopper? </p>
How is Hopper on Windows or Linux?
|tools|
<p>I'm not sure that this is the right place -- StackOverflow would have been a fine place to ask -- but I'll answer anyway. Essentially the issue is that <code>%x</code> treats the argument as an unsigned int. So the value <code>f8ba38ae</code> is the two's complement representation of the original signed int.</p> <p>You can convert it back easily, though, for example with this Python snippet:</p> <pre><code>&gt;&gt;&gt; import struct &gt;&gt;&gt; struct.unpack('&gt;i', 'f8ba38ae'.decode('hex'))[0] -122013522 </code></pre>
2379
2013-06-29T01:55:39.363
<p>Sorry if this is the wrong place to ask this but I'm stumped. I'm looking at iOS code as follows. </p> <pre><code>- (NSString *)currentE6Location { CLLocationCoordinate2D loc = [AppDelegate instance].mapView.centerCoordinate; return [NSString stringWithFormat:@"%08x,%08x", (int)(loc.latitude*1E6), (int)(loc.longitude*1E6)]; } </code></pre> <p>So it's pretty simple.. From my understanding is they are taking a lat/lon and changing it from a float to an int then converting the int to a hex that is 0 padded in the front. So the hex value is 8 chars in length. The issue I'm having is do the same thing in python..</p> <p>So the iOS app sends hex values like</p> <pre><code>36.968772,-122.013498 "0234194f,f8ba38ae" </code></pre> <p>The first set are lat/long and the 2nd are roughly their hex values</p> <p>The lat works just fine</p> <pre><code>0234194f = 36968783 </code></pre> <p>So 36968783 / 1e6 = 36.968783 (like I said its a rough estimate between the two)</p> <p>But the 2nd one is odd</p> <pre><code>f8ba38ae = 4172953774 </code></pre> <p>The seem to use a 4 there if it's a - value for lon since you can't have a negative int has a hex value. So dropping the 4</p> <pre><code>172953774 / 1e6 = 172.953774 (so knowing the 4 is there it would be -172.953774) </code></pre> <p>So I'm a bit stumped on why it works fine for the lat but not the lon..</p> <p>Again sorry if this is the wrong site for this.. please close if it is. </p>
Converting hex value to lat/long
|hex|
<p>"Hacker Protection Factor" is a geeky play of words on "Sun Protection Factor" -- how much longer can an application be attacked before being damaged. The numbers are based on empirical evidence ("<em>Based on our experience,...</em>"). I thought it was cute; it is not an industry standard, but it does serve as a simple indication that an application processed with ProGuard is more difficult to reverse-engineer than the original application, and an application processed with DexGuard is <em>a lot</em> more difficult to reverse-engineer.</p> <p>(I am the developer of ProGuard and DexGuard)</p>
2384
2013-06-30T20:50:12.677
<p><a href="http://www.saikoa.com/dexguard" rel="noreferrer">Dexguard</a> claims a "hacker protection factor" of 35 without any explanation of where the number comes from or what it means. I figure the actual statement is meaningless, but I'm very curious to see who is assessing these protection factors. </p> <p>A Google search didn't turn up anything, so I thought that the Dexguard authors probably made it up themselves. But <a href="https://twitter.com/nflnfl/status/241442557580673024" rel="noreferrer">this Twitter post</a> implies that there are other "hacker protection factors", out there which 35 can be compared with. </p> <p>Does anyone know what the deal with this is? Is it just more pointless puffery? Is there an actual group that is assigning these numbers?</p>
Origin of "Hacker Protection Factor"
|obfuscation|
<p>for vc++ name demangling you can use </p> <p><a href="http://ishiboo.com/~danny/Projects/vc++filt/" rel="nofollow">vc++filt</a></p> <p>it is a small wrapper over dbghelp Function UnDecorateSymbolname() that takes the mangled string and prints out demangled names back to the console see below for a snippet</p> <pre><code>??3@YAXPAX@Z void __cdecl operator delete(void *) ?AFXSetTopLevelFrame@@YAXPAVCFrameWnd@@@Z void __cdecl AFXSetTopLevelFrame(class CFrameWnd *) </code></pre> <p>snippet </p> <pre><code>int _tmain(int argc, _TCHAR* argv[]) { char buff[0x100]; UnDecorateSymbolName("??3@YAXPAX@Z",buff,0xf0,UNDNAME_COMPLETE); printf("%s\n",buff); return 0; } </code></pre> <p>output</p> <pre><code>void __cdecl operator delete(void *) </code></pre>
2388
2013-07-01T15:03:23.287
<p>When reversing binaries and parsing memory, I often run across strings like <code>"@YAXPAX@"</code> used to reference procedures. Is there a name for this type of convention?</p> <p>I believe theses strings are symbol references.</p>
Artifacts similar to "@YAXPAX@" within memory and IDA sessions
|disassembly|ida|
<p>Any obfuscation technique (or its formalization) targets one or more assumptions made by some class of analyses A -- in essence, the obfuscation transforms a program P0 into a different representation P1 that has the same execution behavior as P0 but which violates the assumptions made by the analyses A. In doing so, the obfuscation necessarily defines a class of attacks that it is effective against; it says nothing about attacks that don't fall within that class.</p> <p>Abstract interpretation is a formalization of program analysis that assumes sound static analysis (e.g., consider the requirements imposed on the abstract domain and abstraction/concretization functions). So abstract interpretation serves to formalize obfuscations that make those assumptions and helps us reason about analyses/attacks that meet those assumptions. It doesn't describe all possible obfuscations --- e.g., any obfuscation that relies on runtime code generation or modification --- and doesn't speak to attacks that don't meet those assumptions. Thus, as you propose, an attacker who uses dynamic analysis or potentially unsound techniques essentially side-steps the rules assumed by abstract interpretation.</p>
2391
2013-07-01T23:35:25.503
<p>My question is related to <a href="https://reverseengineering.stackexchange.com/questions/1669/what-is-an-opaque-predicate">this question</a> with the excellent answer of @Rolf Rolles. Since <a href="http://profs.sci.univr.it/~dallapre/AMAST06.pdf" rel="nofollow noreferrer">the paper of M.D. Preda et al</a> is quite technique so I wonder whether I understand their idea or not. The following phrase is quoted from the paper: </p> <blockquote> <p>The basic idea is to model attackers as abstract interpretations of the concrete program behaviour, i.e., the concrete program semantics. In this framework, an attacker is able to break an opaque predicate when the abstract detection of the opaque predicate is equivalent to its concrete detection.</p> </blockquote> <p>As fas as I understand, they have given a formal model of attacker as someone trying to obtain the properties of program using a sound approximation as abstract interpretation (AI). The attacker will success if the AI procedure is complete (informally speaking, the fixed-point obtained in the abstract domain "maps" also back to the fixed-point in the concrete domain).</p> <p>Concretely speaking, their model can be considered as an AI-based algorithm resolving the opaque predicate. In fact, this idea spreads everywhere (e.g. in <a href="https://www.cs.ox.ac.uk/people/leopold.haller/papers/sas2012.pdf" rel="nofollow noreferrer">this paper</a>, the authors have proven that the DPLL algorithm used in SMT solvers is also a kind of abstract interpretation).</p> <p>Obviously, in the worst case where the abstract interpretation is not complete then the attacker may never recover the needed properties (e.g. he can approximate but he will never recover the exact solution for a well-designed opaque predicate).</p> <p>So I wonder that the model of attacker as abstract domains may have some limits, because we still not sure that all attacks can be modelled in AI. Then a straitghtforward question comes to me is <em>"What happens if the attacker uses some other methods to resolve the opaque predicate ?."</em></p> <p>For a trivial example, the attacker can simply use the dynamic analysis to bypass the opaque predicate (he accepts some incorrectness, but finally he may be able to get the properties he wants).</p> <p>Would anyone please give me some suggestions ?</p>
Formal obfuscation
|obfuscation|deobfuscation|
<p>You can do it using Sark (<a href="https://github.com/tmr232/Sark" rel="nofollow">code</a>, <a href="http://sark.readthedocs.org/en/latest/index.html" rel="nofollow">docs</a>):</p> <pre><code>import sark # Get the segment segment = sark.Segment(ea=0x00400000) # Set the permissions segment.permissions.write = True </code></pre> <p><em>Disclaimer: I am the author of Sark.</em></p>
2394
2013-07-02T05:53:22.130
<p>Sometimes when you load a binary manually in IDA you wind up with segments that have unknown read write and execute flags. You can see them under the Segments subview (<kbd>Shift</kbd> + <kbd>F7</kbd>). Is there a way to change these flags from within the GUI of IDA without running a script and modifying them? </p> <p>It seems like such a basic piece of functionality which is very important for the proper operation of the Hex Rays decompiler. I've been using the class to express segment rights which just seems wrong considering these flags exist.</p> <p>Although I would appreciate the question being answered in the general case, in this particular case I'm dealing with flat binary ARM files with code and data intermixed. All page level permissions are set up by the software when it loads by directly mapping them via the MMU.</p>
How can I change the Read/Write/Execute flags on a segment in IDA?
|ida|segmentation|
<p>Also, while permissions are more or less standardized and can inform you about the types of data/code found in a segment, remember that if you're talking about malware analysis there is no guarantee that the permissions on a segment are what you would expect.</p> <p>Not to mention that there is often a fair amount of header tampering in addition to non-standard memory utilization. In fact, this is often how you can tell whether something was written in assembly, mangled with a tool or compiled from some other language.</p>
2400
2013-07-02T15:53:33.987
<p>As per <a href="https://www.hex-rays.com/products/ida/support/idadoc/517.shtml" rel="nofollow">IDA Online Help</a>:</p> <blockquote> <p>The segment class name identifies the segment with a class name (such as CODE, FAR_DATA, or STACK). The linker places segments with the same class name into a contiguous area of memory in the runtime memory map.</p> </blockquote> <p>IDA has the following predefined segment class names:</p> <pre><code> CODE - Pure code DATA - Pure data CONST - Pure data BSS - Uninitialized data STACK - Uninitialized data XTRN - Extern definitions segment </code></pre> <p>As far as I could tell permission on a segment already offer all relevant information. What is the exact purpose(or applicable usage) of <em>Segment Class Name</em>? How does IDA utilize it internally?</p>
IDA: Segment Class Name
|disassembly|ida|
<p>File-->Produce file-->Create C header file</p> <p>This will export all defined structures and enums. Please note that in all IDA versions before IDA 6.5 you'll possibly need to reorder structures if you want to use created file for compilation of your own source.</p>
2408
2013-07-03T21:36:35.133
<p>It is possible to import structures and enums declarations from C files in IDA. However, is it possible to export structures and enums to C?</p>
Exporting structures and enums in IDA
|ida|
<p>For IDA v7.0 you can use: </p> <pre><code>ida_idp.is_align_insn(ScreenEA()) </code></pre>
2415
2013-07-05T18:05:47.107
<p>Some compilers will add useless bytes in functions or in between functions. In the below block of code at 0040117C we can see the "align" keyword that was inserted by IDA. </p> <pre><code>.text:00401176 mov eax, [edx+4] .text:00401179 call eax .text:0040117B .text:0040117B locret_40117B: ; CODE XREF: sub_401160+Dj .text:0040117B retn .text:0040117B sub_401160 endp .text:0040117B .text:0040117B ; --------------------------------------------------------------------------- .text:0040117C align 10h .text:00401180 .text:00401180 ; =============== S U B R O U T I N E ======================================= .text:00401180 .text:00401180 ; Attributes: bp-based frame .text:00401180 .text:00401180 ; int __stdcall sub_401180(void *Src) </code></pre> <p>If we were to view this in hex mode in this example we would see "<code>CC CC ..</code>". With other compilers we might see "<code>90 90 ..</code>". The obvious hint of what this is being used for is the "align" keyword. </p> <p><strong>Question:</strong> how can I tell if a specific byte at an address is marked as <code>align</code> in IDAPython? Example code would be appreciated. </p> <p>I have found a couple of functions and data types such as <code>FF_ALIGN</code> and <code>idaapi.is_align_insn(ea</code> that looked positive but I have yet to figure out a working example or results that confirm yes or no. I would prefer to rely on IDA types or functions rather than use string parsing for the keyword "align". </p>
Accessing Data Marked as Alignment Bytes in IDA
|ida|compilers|idapython|
<p>compiler may insert dumb null_sub randomly between directions, in order to confuse IDA decompiler. So that IDA may generate meaningless variable names, increase reverse engineer's effort to understand the workflow, to connect to dots...</p>
2420
2013-07-06T10:24:56.467
<p>In nearly every dis-assembly created by IDA, there are several functions that are marked <code>nullsub_</code> which according to IDA, return <del><code>null</code></del> nothing (just <code>ret</code> instruction). </p> <p>So, what are those and why are they in the database?</p>
What are nullsub_ functions in IDA?
|disassembly|ida|
<p>There is also <a href="http://www.openrce.org/downloads/" rel="nofollow">http://www.openrce.org/downloads/</a> Though it does not have specific tools you are looking for, it has lots of plugins for IDA and OllyDbg. It is trustworthy source as well.</p>
2427
2013-07-07T20:39:05.067
<p>I am looking for a reliable source to download RE tools such as:</p> <ol> <li>Lordpe</li> <li>Imprec</li> <li>Peid</li> </ol> <p>but it seems all the links in google are not safe, where can I buy or download it from a reliable not malwared source. Can I trust <a href="http://www.woodmann.com/">http://www.woodmann.com/</a> ?</p>
Where can I get reliable tools for RE?
|tools|
<p>Yes, the riddle was solved. See <a href="http://www.home.aone.net.au/~byzantium/found/found4.html" rel="noreferrer">http://www.home.aone.net.au/~byzantium/found/found4.html</a></p> <p>As for +ORC himself, there's some more info at <a href="http://www.woodmann.com/crackz/Orc.htm" rel="noreferrer">http://www.woodmann.com/crackz/Orc.htm</a></p> <p>The last time I spoke with Fravia+ about +ORC, Fravia+ said that +ORC became obsessed with the pyramids in Egypt and went there to study them. He contracted some kind of illness while there and died rather suddenly. If I remember correctly, Fravia+ learned of +ORC's death through +ORC's son.</p>
2428
2013-07-07T21:07:13.747
<p>I have heard countless stories on the Old Red Cracker, also known as +ORC, being the founding father of reverse engineering tutorials.</p> <p>I also read somewhere that he left some riddles to find his "secret page" and he disappeared into thin air.</p> <p>Did anyone <em>really</em> solve these riddles? Is the identity, or some of the background, of that person known?</p>
Who was the Old Red Cracker?
|history|
<p><a href="https://reverseengineering.stackexchange.com/users/262/dcoder">@DCoder</a> has certainly answered this, so here is only some notes, or, at least it started out as a short note, and ended up as a <strong>monster</strong>.</p> <hr> <p>OllyDbg uses <code>MASM</code> by default (with some extension). In other words:</p> <pre><code>operation target, source </code></pre> <p>Other syntaxes are available under (depending on version):</p> <ul> <li>Options->Debugging Options->Disasm</li> <li>Options->Code</li> </ul> <p>E.g. <code>IDEAL</code>, <code>HLA</code> and <code>AT&amp;T</code>.</p> <p>There is also quite a few other options for how the disassembled code looks like. Click around. The changes are instantaneously so easy to find the <em>right one</em>.</p> <p>Numbers are always hex, but without any notation like <code>0x</code> or <code>h</code> (for compactness sake I guess – and the look is cleaner (IMHO)). Elsewhere, like the instruction details below disassembly, one can see e.g. base 10 numbers – then denoted by a dot at end. E.g. 0x10 (16.)</p> <hr> <p><em>(And here I stride off …)</em></p> <h2>When it comes to reading the code</h2> <p>(Talking Intel)</p> <p>First off tables like the ones at <a href="http://ref.x86asm.net" rel="nofollow noreferrer">x86asm.net</a> and the <a href="http://www.sandpile.org/" rel="nofollow noreferrer">Sandpile</a> are definitively valuable assets in the work with assembly code. However one should also have:</p> <ul> <li>Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1: Basic Architecture.</li> <li>Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2 (2A, 2B &amp; 2C): Instruction Set Reference, A-Z.</li> <li>… etc. (There are also some collection volumes.)</li> </ul> <p>From <a href="http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html" rel="nofollow noreferrer">Intel® 64 and IA-32 Architectures Software Developer Manuals</a>.</p> <p>There is a lot of good sections and descriptions of how a system is stitched together and how operations affect the overall system as in registers, flags, stacks etc. Read e.g. <code>6.2 STACKS</code>, <code>3.4 BASIC PROGRAM EXECUTION REGISTERS</code>, <code>CHAPTER 4 DATA TYPES</code> from the <em>"Developers"</em> volume.</p> <hr> <p>As mentioned x86amd and Sandpile are good resources, but when you wonder about an instruction the manual is a good choice as well; <em>"Instruction Set Reference A-Z"</em>.</p> <p>Your whole line is probably something like:</p> <pre><code>00406ED6 8B46 14 MOV EAX,DWORD PTR DS:[ESI+14] ; or 00406ED6 8B46 14 MOV EAX,DWORD PTR [ESI+14] </code></pre> <p>(Depending on <em>options</em> and <em>Always show default segment</em>.)</p> <p>In this case we can split the binary as:</p> <pre><code>8B46 14 | | | | | +---&gt; Displacement | +------&gt; ModR/M +--------&gt; Opcode </code></pre> <p><em>Note that there can be prefixes before opcode and other fields as well. For detail look at manual. E.g. "CHAPTER 2 INSTRUCTION FORMAT" in A-Z manual.</em></p> <hr> <p>Find the <code>MOV</code> operation and you will see:</p> <h2>MOV – move</h2> <pre><code>Opcode Instruction Op/En 64-bit Compat Description … 8B /r MOV r32,r/m32 RM Valid Valid Move r/m32 to r32. | | | +---&gt; source +-------&gt; destination … </code></pre> <p><strong>Instruction Operand Encoding</strong></p> <pre><code>Op/En Operand1 Operand2 Operand3 Operand4 RM ModRM:reg (w) ModRM:r/m (r) NA NA </code></pre> <p>Read <em>"3.1 INTERPRETING THE INSTRUCTION REFERENCE PAGES"</em> for details on codes.</p> <p>In short <em>MOV – mov</em> table say:</p> <pre><code>8B : Opcode. /r : ModR/M byte follows opcode that contains register and r/m operand. r32 : One of the doubleword general-purpose registers. r/m32: Doubleword general-purpose register or memory operand. RM : Code for "Instruction Operand Encoding"-table. </code></pre> <p>The <em>Instruction Operand Encoding</em> table say:</p> <pre><code>reg : Operand 1 is defined by the reg bits in the ModR/M byte. (w) : Value is written. r/m : Operand 2 is Mod+R/M bits of ModR/M byte. (r) : Value is read. </code></pre> <hr> <h2>The too deep section</h2> <p><em>OK. Now I'm going to deep here, but can't stop myself.</em> (Often find that knowing the building blocks help understand the process.)</p> <p>The ModR/M byte is <code>0x46</code> which in binary form would be:</p> <pre><code> 7,6 5,4,3 2,1,0 (Bit number) 0x46: 01 000 110 | | | | | +---&gt; R/M | +-----------&gt; REG/OpExt +------------------&gt; Mod </code></pre> <ol> <li>The value <code>000</code> of REG field translates to <code>EAX</code></li> <li>Mod+R/M translates to <code>ESI+disp8</code></li> </ol> <p>(Ref. <em>"2.1.5 Addressing-Mode Encoding of ModR/M and SIB Bytes"</em> table 2-2, in A-Z ref.).</p> <p>Pt. 2. tells us that a 8-bit value, 8-bit displacement byte, follows the ModR/M byte which should be added to the value of <code>ESI</code>. In comparison, if there was a 32-bit displacement or register opcode+ModR/M's would be:</p> <pre><code>32-bit displacement General-purpose register +-----&gt; MOV r32,r/m32 +-----&gt; MOV r32,r/m32 | | 8Bh 86h 8Bh C1h | +--&gt; EAX | +--&gt; EAX | | | | +---&gt; 10 000 110 b +---&gt; 11 000 001 b | | | | +---+---+ +---+---+ | | v v ESI + disp32 ECX </code></pre> <hr> <p>As we have a <code>disp8</code> the next byte is a 1-byte value that should be added to the value of ESI. In this case <code>0x14</code>.</p> <p>Note that this byte is signed so e.g. <code>0xfe</code> would mean <code>ESI - 0x02</code>.</p> <h2>Segment to use</h2> <p>ESI is pointer to data in segment pointed to by DS.</p> <p>A segment selector is comprised of three values:</p> <pre><code> 15 - 3 2 1 - 0 (Bits) |-------------|-----------------|---------------------------| | Index | Table Indicator | Requested Privilege Level | +-------------+-----------------+---------------------------+ </code></pre> <p>So say selector = 0x0023 we have:</p> <pre><code>0x23 0000000000100 0 11 b | | | | | +----&gt; RPL : 3 = User land, (0 is kernel) | +-------&gt; TI : 0 = GDT (GDT or LDT) +---------------&gt; Index: 4 Multiplied by 8 and added to TI </code></pre> <ul> <li>GDT = Global Descriptor Table</li> <li>LDT = Local Descriptor Table</li> </ul> <p>The segment registers (CS, DS, SS, ES, FS and GS) are designed to hold selectors for code, stack or data. This is to lessen complexity and increase efficiency.</p> <p>Each of these registers also have a <em>hidden part</em> aka <em>"shadow register"</em> or <em>"descriptor cache"</em> which holds <em>base address</em>, <em>segment limit</em> and <em>access control information</em>. These values are automatically loaded by the processor when a segment selector is loaded into the visible part of the segment registers.</p> <pre><code> | Segment Selector | Shadow Register | +------------------+--------------------------+ | Idx | TI | RPL | BASE | Seg Lim | Access | CS, SS, DS, ES, FS, GS +------------------+--------------------------+ </code></pre> <p>The BASE address is a linear address. ES, DS and SS are not used in 64-bit mode.</p> <hr> <h2>Result</h2> <p>Read a 32-bit value from segment address ESI+disp8. Example:</p> <pre><code>ESI = 0x005056A0 Dump of DS segment: 0 1 2 3 4 5 6 7 8 9 a b c d e f 005056A0 00 00 00 00 9C 8F 41 7E 4C 1F 42 00 C0 1E 42 00 ....œA~LB.ÀB. 005056B0 E0 1F 42 00 70 20 42 00 48 21 42 00 4A A8 42 7E àB.p B.H!B.J¨B~ ESI + 0x14 = 0x005056B4 =&gt; 70 20 42 00 … EAX = (DWORD)70 20 42 00 = 00 42 20 70 (4333680.) </code></pre> <hr> <h2>Simulate in C</h2> <p>One problem with your example is that <code>esi</code> is an integer (strictly speaking). The value, however, can be that one of a segment address. Then you have to take into consideration that each segment has a <em>base address</em>, (offset), – as in:</p> <pre><code>seg = malloc(4096); seg[0] | +---&gt; at base address, e.g. 0x505000 +----------------+ | | | | … 505000 | | seg[00 - 0f] 505010 | | seg[10 - 1f] 505020 | | seg[20 - 2f] … </code></pre> <p>In this case, as it is ESI, that segment would be the one pointed to by DS.</p> <hr> <p>To simulate this in C you would need variables for the general-purpose registers, but you would also need to create segments (from where to read/write data.) Roughly such a code <strong>could</strong> be something like:</p> <pre><code>void dword_m2r(uint32_t *x, struct segment *seg, uint32_t offset) { *x = *((uint32_t*)(seg-&gt;data + (offset - seg-&gt;base))); } dword_m2r(&amp;eax, &amp;ds, esi + 0x14); </code></pre> <p>Where <code>struct segment</code> and <code>ds</code> are:</p> <pre><code>struct segment { u8 *data; u32 base; u32 size; u32 eip; }; struct segment ds; ds.base = 0x00505000; ds.size = 0x3000; ds.data = malloc(ds.size); ds.eip = 0x00; </code></pre> <p>To further develop on this concept you could create another <code>struct</code> with registers, use defines or variables for registers, add default segments etc.</p> <p>For Intel-based architecture that could be something in the direction of this (as a not to nice beginning):</p> <pre><code>#include &lt;stdint.h&gt; #define u64 uint64_t #define u32 uint32_t #define u16 uint16_t #define u8 uint8_t union gen_reg { u64 r64; u32 r32; u16 r16; u8 l8; }; struct CPU { union gen_reg accumulator; u8 *ah; union gen_reg counter; u8 *ch; … struct segment s_stack; struct segment s_code; struct segment s_data; … u32 eflags; u32 eip; … }; #define RAX CPU.accumulator.rax #define EAX CPU.accumulator.eax #define AX CPU.accumulator.ax #define AH *((u8*)&amp;AX + 1) #define AL CPU.accumulator.al … /* and then some variant of */ ESI = 0x00505123; dword_m2r(&amp;EAX, &amp;DS, ESI + 0x14); </code></pre> <p>For a more compact way, ditching ptr to <code>H</code> register etc. have a look at e.g. the code base of <a href="http://www.virtualbox.org/svn/vbox/trunk/src/VBox/Additions/x11/x11include/xorg-server-1.14.0/regs.h" rel="nofollow noreferrer">virtualbox</a>. <strong><em>Note:</em></strong> require some form of pack directive for most compilers to prevent filling of bits in structs – so that e.g. AH and AL really align up with correct bytes of AX.</p>
2432
2013-07-08T16:15:23.567
<p>This is probably a pretty simple question as I'm not too used to how the syntax looks for OllyDBG's disassembler. </p> <p>Does this following assembler statement:</p> <pre><code>MOV EAX, DWORD PTR [ESI + 14] </code></pre> <p>Be roughly translated to this C code:</p> <pre><code>eax = *(esi + 0x14); </code></pre> <p>Have I understood the syntax correctly or am I misunderstanding this? </p>
OllyDBG's disassembled syntax and c-equivalent
|disassembly|assembly|x86|ollydbg|
<p><strong>Ida Free 5</strong></p> <pre><code>Edit -&gt; Segments -&gt;CreateSegment </code></pre> <p>in the dialog</p> <pre><code>segment name = seg001....seg00n start = &lt;start address viz 0x0A end = &lt;end address viz 0x1e base = 0x0 class = some text viz 32one,32two,16three radio button = 32 bit segment or 16 bit segment as needed click yes to a cryptic dialog </code></pre> <p>example the binary stream contains 16 bit dos puts routine and 32 bit random pushes intermixed</p> <pre><code>C:\Documents and Settings\Admin\Desktop&gt;xxd -g 1 1632blob.bin 0000000: b4 01 cd 21 88 c2 b4 02 cd 21 68 78 56 34 12 68 ...!.....!hxV4.h 0000010: 0d d0 37 13 68 be ba 37 13 68 00 0d db ba b4 01 ..7.h..7.h...... 0000020: cd 21 88 c2 b4 02 cd 21 68 78 56 34 12 68 0d d0 .!.....!hxV4.h.. 0000030: 37 13 68 be ba 37 13 68 00 0d db ba b4 01 cd 21 7.h..7.h.......! 0000040: 88 c2 b4 02 cd 21 68 78 56 34 12 68 0d d0 37 13 .....!hxV4.h..7. 0000050: 68 be ba 37 13 68 00 0d db ba h..7.h.... C:\Documents and Settings\Admin\Desktop&gt; </code></pre> <p>loading this blob as binary file moving to <code>offset 0</code> and pressing <code>c</code> would disassemble all bytes as <code>16 bit</code> </p> <p>now you can move to <code>offset 0x0a</code> and create a <code>32 bit segment</code> with start as <code>0x0a end as 0x1e base as 0x0 class as 32one use 32bitsegment radio button</code> and press <code>c</code> again to create 32 bit disassembly</p> <p>see below</p> <pre><code>seg000:0000 ; seg000:0000 ; +-------------------------------------------------------------------------+ seg000:0000 ; ¦ This file is generated by The Interactive Disassembler (IDA) ¦ seg000:0000 ; ¦ Copyright (c) 2010 by Hex-Rays SA, &lt;support@hex-rays.com&gt; ¦ seg000:0000 ; ¦ Licensed to: Freeware version ¦ seg000:0000 ; +-------------------------------------------------------------------------+ seg000:0000 ; seg000:0000 ; Input MD5 : AEB17B9F8C4FD00BF2C04A4B3399CED1 seg000:0000 seg000:0000 ; --------------------------------------------------------------------------- seg000:0000 seg000:0000 .686p seg000:0000 .mmx seg000:0000 .model flat seg000:0000 seg000:0000 ; --------------------------------------------------------------------------- seg000:0000 seg000:0000 ; Segment type: Pure code seg000:0000 seg000 segment byte public 'CODE' use16 seg000:0000 assume cs:seg000 seg000:0000 assume es:seg005, ss:seg005, ds:seg005, fs:seg005, gs:seg005 seg000:0000 B4 01 mov ah, 1 seg000:0002 CD 21 int 21h seg000:0004 88 C2 mov dl, al seg000:0006 B4 02 mov ah, 2 seg000:0008 CD 21 int 21h seg000:0008 seg000 ends seg000:0008 seg001:0000000A ; --------------------------------------------------------------------------- seg001:0000000A seg001:0000000A ; Segment type: Regular seg001:0000000A seg001 segment byte public '32one' use32 seg001:0000000A assume cs:seg001 seg001:0000000A ;org 0Ah seg001:0000000A assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:nothing seg001:0000000A 68 78 56 34 12 push 12345678h seg001:0000000F 68 0D D0 37 13 push 1337D00Dh seg001:00000014 68 BE BA 37 13 push 1337BABEh seg001:00000019 68 00 0D DB BA push 0BADB0D00h seg001:00000019 seg001 ends seg001:00000019 seg002:001E ; --------------------------------------------------------------------------- seg002:001E seg002:001E ; Segment type: Pure code seg002:001E seg002 segment byte public 'CODE' use16 seg002:001E assume cs:seg002 seg002:001E ;org 1Eh seg002:001E assume es:seg005, ss:seg005, ds:seg005, fs:seg005, gs:seg005 seg002:001E B4 01 mov ah, 1 seg002:0020 CD 21 int 21h seg002:0022 88 C2 mov dl, al seg002:0024 B4 02 mov ah, 2 seg002:0026 CD 21 int 21h seg002:0026 seg002 ends seg002:0026 seg003:00000028 ; --------------------------------------------------------------------------- seg003:00000028 seg003:00000028 ; Segment type: Regular seg003:00000028 seg003 segment byte public '32two' use32 seg003:00000028 assume cs:seg003 seg003:00000028 ;org 28h seg003:00000028 assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:nothing seg003:00000028 68 78 56 34 12 push 12345678h seg003:0000002D 68 0D D0 37 13 push 1337D00Dh seg003:00000032 68 BE BA 37 13 push 1337BABEh seg003:00000037 68 00 0D DB BA push 0BADB0D00h seg003:00000037 seg003 ends seg003:00000037 seg004:003C ; --------------------------------------------------------------------------- seg004:003C seg004:003C ; Segment type: Pure code seg004:003C seg004 segment byte public 'CODE' use16 seg004:003C assume cs:seg004 seg004:003C ;org 3Ch seg004:003C assume es:seg005, ss:seg005, ds:seg005, fs:seg005, gs:seg005 seg004:003C B4 01 mov ah, 1 seg004:003E CD 21 int 21h seg004:0040 88 C2 mov dl, al seg004:0042 B4 02 mov ah, 2 seg004:0044 CD 21 int 21h seg004:0044 seg004 ends seg004:0044 seg005:00000046 ; --------------------------------------------------------------------------- seg005:00000046 seg005:00000046 ; Segment type: Regular seg005:00000046 seg005 segment byte public '32three' use32 seg005:00000046 assume cs:seg005 seg005:00000046 ;org 46h seg005:00000046 assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:nothing seg005:00000046 68 78 56 34 12 push 12345678h seg005:0000004B 68 0D D0 37 13 push 1337D00Dh seg005:00000050 68 BE BA 37 13 push 1337BABEh seg005:00000055 68 00 0D DB BA push 0BADB0D00h seg005:00000055 seg005 ends seg005:00000055 seg005:00000055 seg005:00000055 end </code></pre>
2440
2013-07-09T20:36:51.017
<p>I am trying to reverse engineer a binary blob I expect to transition from 16-bit real mode into 32-bit protected mode (it is boot time code), so I expect the code to contain code of both sorts.</p> <p>When I launch IDA, I am given the option of 16 or 32-bit code, but not mixed.</p> <p>How do I instruct IDA to attempt to disassemble data at a given address as 32-bit mode?</p> <p>I can using the 16-bit analyzer deduce the initial jump (unoriginally) and IDA happily analyses the code from there. I can see where the 32-bit code jumps to (far jump, so IDA doesn't try to analyze it), but IDA treats this as 16-bit when I hit <kbd>C</kbd>.</p> <p>Other than launching a 16, and a 32-bit dissasmbly session, can I do this in one?</p>
Mixed 16/32-bit code reversing using IDA
|ida|x86|
<pre><code>ollydbg radasm.exe view windows (W Icon) sort class and look for Mdi class like mdiEditChild / dialog etc </code></pre> <p>example</p> <pre><code>Windows, item 96 Handle=000704EE Title=C:\testrad\Html\Projects\testrad\testradinc3.html Parent=000203E4 ID=0000FDEA (65002.) Style=56CF0001 WS_CHILD|WS_GROUP|WS_TABSTOP|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_VISIBLE|WS_SYSMENU|WS_THICKFRAME|WS_CAPTION|1 ExtStyle=00000340 WS_EX_MDICHILD|WS_EX_WINDOWEDGE|WS_EX_CLIENTEDGE Thread=Main ClsProc=00xxxxxx RadASM.00xxxxxx Class=MdiEditChild </code></pre> <p>right click message breakpoint on class proc</p> <p>in the dialog</p> <pre><code>choose window creation and destruction never pause radio button log winproc args always </code></pre> <p>you should be able to capture the <code>WM_CLOSE</code> sent by ctrl+f4</p> <pre><code>Log data Address Message 00XXXXXX CALL to Assumed WinProc from USER32.7E418731 hWnd = 000704EE ('C:\testrad\Html\Projects\test...',class='MdiEditChild',parent=000203E4) Message = WM_CLOSE wParam = 0 lParam = 0 </code></pre> <p>The <strong>patch</strong> below should pop up a <code>Messagebox</code> when you hit Middle Mouse Button on the <code>SysTabControl</code></p> <pre><code>004071A7 |&gt; \90 NOP ; Default case of switch 004070B6 004071A8 |. 90 NOP 004071A9 |. 90 NOP 004071AA |. E8 5D1F0400 CALL RadASMWM.0044910C 00449100 &lt;STRING&gt; . 57 4D 5F 4D 42 5&gt;ASCII "WM_MB_CLICK",0 0044910C &lt;WM_MB_CLICK_HANDLER&gt; /$ 60 PUSHAD ; CALL FROM 4071AA 0044910D |. 9C PUSHFD 0044910E |. 3D 07020000 CMP EAX, 207 ; WM_MB 00449113 |. 75 13 JNZ SHORT &lt;RadASMWM.RETTOORIGHANDLER&gt; 00449115 |. 6A 00 PUSH 0 ; /Style = MB_OK|MB_APPLMODAL 00449117 |. 68 00914400 PUSH &lt;RadASMWM.STRING&gt; ; |Title = "WM_MB_CLICK" 0044911C |. 68 00914400 PUSH &lt;RadASMWM.STRING&gt; ; |Text = "WM_MB_CLICK" 00449121 |. 6A 00 PUSH 0 ; |hOwner = NULL 00449123 |. E8 A2FBFFFF CALL &lt;JMP.&amp;user32.MessageBoxA&gt; ; \MessageBoxA 00449128 &lt;RETTOORIGHANDLER&gt; |&gt; 9D POPFD 00449129 |. 61 POPAD 0044912A |. 8B45 08 MOV EAX, DWORD PTR SS:[EBP+8] ; RadASMWM.&lt;ModuleEntryPoint&gt; 0044912D |. E8 F7B8FBFF CALL &lt;RadASMWM.ORIGINAL HANDLER&gt; 00449132 \. C3 RETN </code></pre>
2460
2013-07-13T20:45:04.423
<p>I am trying to modify RadASM so that Ctrl+W will close the tab, instead of Ctrl+F4, and also make it so that if you middle mouse click the tab, it will close. The context menu for a tab is just a copy of the "Windows" menu bar item. The problem is, I can not figure out which library or even function is used to create menu bars and its items. I can not find any relevant strings in OllyDBG, and I've tried making breakpoints for just about every call I thought it might be, but I can't get anything.</p> <p>Can anybody point me in the right direction? I couldn't locate the function in RadASM for determining which hotkeys/shortcuts do what either.</p> <p>I know all about code caves and injecting DLLs, so adding a function like the middle mouse click shouldn't be impossible; I just need to know where to start since I'm quite new to reverse engineering.</p>
Change RadASM hotkey and add middle mouse click hotkey
|assembly|ollydbg|
<p>You can try Netzob tool. This is a tool dedicated to reverse engineering protocols.</p> <ul> <li>You can download it here : <a href="http://www.netzob.org/">http://www.netzob.org/</a></li> <li>A great example w/ ZeroAccess C&amp;C protocol : <a href="http://www.netzob.org/documentations/presentations/netzob_29C3_2012.pdf">http://www.netzob.org/documentations/presentations/netzob_29C3_2012.pdf</a></li> </ul> <p>You can also take a look at CANAPE : <a href="http://www.contextis.com/research/tools/canape/">http://www.contextis.com/research/tools/canape/</a></p>
2474
2013-07-14T22:31:51.387
<p>I have a DVR that sends video over Ethernet using its own propriety TCP protocol. I want to write a VLC module to view the video, rather than the supplied DxClient.exe. I have captured traffic in wireshark and attempted to reverse engineer the client with IDA Pro, from what I can tell the client does some kind of handshake authentication, the DVR then sends 2 network packets (always 1514 bytes long), the client sends a TCP ACK and 2 more packets are transmitted, etc.etc... forever. From what I can tell the client uses Microsoft's AVIFIL32 library to decompress the packets to what essentially become AVI file frames.</p> <p>The problem is I don't understand how these frames are encoded or if they even are AVI frames. Can anyone help me, here is the data payload from 2 packets:</p> <p><a href="http://pastebin.com/2VDu2Tc2">http://pastebin.com/2VDu2Tc2</a></p> <p><a href="http://pastebin.com/L3Zi3VqU">http://pastebin.com/L3Zi3VqU</a></p>
Reversing network protocol
|file-format|sniffing|wireshark|
<p>If you goal is ultimately to control the service, it make more sense to reverse it versus reversing control panel. Who knows, you might find functionality you were not aware of. The key part of reversing windows service is to realize that it runs within the context of the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms685150%28v=vs.85%29.aspx" rel="nofollow noreferrer"><strong>Service Control Manager</strong></a>, and simply running the executable will not work. There are several major components of any windows service, that you need to be aware of. I have already given an answer to <a href="https://reverseengineering.stackexchange.com/questions/2235/how-does-services-exe-trigger-the-start-of-a-service/2237#2237"><strong>How does services.exe trigger the start of a service?</strong></a> question. It describes inner workings of a windows service.</p> <p>It is very much possible to reverse a Windows service both dynamically and statically as long as you understand underlining concepts. If you run your service in context of command prompt, it will fail. Every Windows service by design has to call to Service Control Manager, if that call fails it means the service is not executed within the SCM. It is expected to fail being executed outside of the SCM. If services expects input, you will have to figure out what it needs. Firstly, you will need to locate Service Worker Thread. Thereafter, locating part of the way it communicates to control panel should be easy. </p>
2475
2013-07-14T22:55:17.453
<p>I'm trying to reverse engineer a driver that consists of 2 components, a windows service and a control panel application. My goal of reverse engineering is to replace the control panel with my own program.</p> <p>Now as far as I can see I have a few possible approaches:</p> <ol> <li>I try to reverse engineer the control panel, and discover the calls sent. But this panel consists of a lot of bloatware.</li> <li>I try to reverse engineer the service, and discover the input needed. But this service also handles other (unknown) functions.</li> <li>I try to catch the communication between the panel and the service.</li> </ol> <p>Now 3 would be the easiest approach, but I have no idea if this is technically possible. Then I tried option 2, but i can only statically analyze the exe, Since dynamic analysis causes it to crash prematurely. Option 1 seems to be the most logical one, and this was the first I tried, but I can't really find an interesting starting point.</p> <p>Is there anyone who can point me in the right direction. I have some reverse engineering experience from crackme's and applications, but this is my first attempt at reversing a driver.</p>
Reverse engineering windows service
|windows|ida|ollydbg|
<p>this is not entirely true. Dalvik bytecode will also be verified on the device, but this happens during installation time, not runtime. A verified and optimized version of the dex file will be stored on the system, protected by file system permission (you cannot change it afterwards unless you have rooted your device).</p> <p>The trick that was used in the blog post is that you can set a specific flag within the class header which tells the verifier to skip this class.</p>
2479
2013-07-15T05:26:23.847
<p>One of the things that makes Java bytecode (.class) so easy to reverse engineer is that the JVM's verifier ensures that bytecode can always be disassembled via linear sweep. Instructions have to be consecutive starting at offset 0, and you can't jump into the middle of an instruction.</p> <p>However <a href="http://www.dexlabs.org/blog/bytecode-obfuscation">this post</a> implies that Dalvik does not do such bytecode verification. The authors do all the usual x86 shenanigans like jumping into the middle of an instruction, which is apparently allowed. Is this true? Do Android VMs actually perform any kind of loadtime bytecode verification? If not, why?</p>
Android bytecode verifier
|disassembly|android|byte-code|
<p>IDA Pro offers two tracing options:</p> <ol> <li><strong>Instruction tracing</strong> <kbd>Debugger->Tracing->Instruction Tracing</kbd> It is very slow tracing process, since IDA monitors registers and has to record the address, the instruction, and changes values of registers, that were changed by the instruction.</li> <li><strong>Function tracing</strong> <kbd>Debugger->Tracing->Function Tracing</kbd>. It is a subcategory of instruction tracing, where only function calls are logged. </li> </ol> <p>There are also three types of tracing events: execution traces, write traces, and read/write traces. </p> <p>A trace in IDA Pro could by replayed by using <em>Trace replayer</em>. It is located within <em>Debuggers</em> submenu. You could switch to <em>Trace-replayer</em> by going to <kbd>Debugger->Switch Debugger...->Trace replayer</kbd></p> <p><img src="https://i.stack.imgur.com/0Hbix.png" alt="enter image description here"></p> <p>One thing to remember that you have to have trace created before you can replay it. In order to create a trace you will need to do the following:</p> <ol> <li>Set a breakpoint at the point where you want you trace started. </li> <li>Run the program with the debugger of your choice. </li> <li>Whenever it breaks, select desired tracing <em>style</em> (Instruction or Function)</li> <li>Run as far as necessary. You could set a second breakpoint to stop the trace.</li> <li>You can optionally save the trace.</li> <li>Replay the trace by switching debugger to <em>Trace replayer</em>. </li> </ol>
2486
2013-07-15T22:50:55.317
<p>I have been looking for the equivalent of the "Run Trace" option of OllyDbg in IDA Pro. Can anyone mention if there is one and how to use it ?</p>
Is there an equivalent of 'Run trace' as in OllyDbg for IDA PRO?
|ida|ollydbg|ida-plugin|
<p>I'm not sure whether this is along the lines you're looking for (and quite possibly you've already figured out all of this and more), but here's a crude formalization and then some implementation thoughts. Conceptually, this tries to separate what it <em>means</em> to entangle several values from how entangled values are <em>represented</em>. </p> <h3>Formalization</h3> <p>Conceptually, entangled values can be thought of as <em>aggregates</em> where the different components retain their values, don't interfere with each other, and can be independently extracted. A convenient way to think of such aggregates is as <em>n</em>-tuples of values; for simplicity I assume <em>n</em> = 2 here. Also, I assume that we have operations to construct tuples from a collection of values, and to extract the component values from a tuple.</p> <p>We now need to be able to carry out operations on tuples. For this, for each operation <strong>op</strong> in the original program we now have 2 versions: <strong>op1</strong>, which operates on the first component of a 2-tuple, and <strong>op2</strong>, which operates on the second component:</p> <blockquote> &lt;a1,b1&gt; <b>op1</b> &lt;a2,b2&gt; = if (b1 == b2) then &lt;(a1 <b>op</b> a2), b1&gt; else undefined<br> &lt;a1,b1&gt; <b>op2</b> &lt;a2,b2&gt; = if (a1 == a2) then &lt;a1, (b1 <b>op</b> b2)&gt; else undefined<br> </blockquote> <p>Finally (and this is where the obfuscation comes in), we need a way to encode tuples as values and decode values into tuples. If the set of values is S, then we need two functions <strong>enc</strong> and <strong>dec</strong> that must be inverses of each other:</p> <blockquote> <b>enc</b>: S x S --> S (encode pairs of values as a single entangled value)<br> <b>dec</b>: S --> S x S (decode an entangled value into its components)<br> <p> <b>enc</b>(<b>dec</b>(x)) = x for all x<br> <b>dec</b>(<b>enc</b>(x)) = x for all x </blockquote> <p>Examples: </p> <ul> <li><p><strong>enc</strong> takes a pair of 16-bit values and embeds them into a 32-bit value w such that x occupies the low 16 bits of w and y occupies the high 16 bits of w; <strong>dec</strong> takes a 32-bit value and decodes them into a pair where x is the low 16 bits and y is the high 16 bits.</p></li> <li><p><strong>enc</strong> takes a pair &lt;x,y&gt; of 16 bit values and embeds them into a 32-bit word w such that x occupies the even-numbered bit positions of w and y occupies the odd-numbered bit positions of w (i.e., their bits are interlaced); <strong>dec</strong> takes a 32-bit value w and decodes them into a pair &lt;x,y&gt; such that x consists of the even-numbered bits of w and y consists of the odd-numbered bits of w.</p></li> </ul> <h3>Implementation considerations</h3> <p>From an implementation perspective, we'd like to be able to perform operations directly on encoded representations of values. For this, corresponding to each of the operations <strong>op1</strong> and <strong>op2</strong> above, we need to define "encoded" versions <b>op1*</b> and <b>op2*</b> that must satisfy the following soundness criterion:</p> <blockquote> <p>for all x1, x2, and y: x1 <b>op1*</b> x2 = y IFF <b>enc</b>( <b>dec</b>(x1) <b>op1</b> <b>dec</b>(x2) ) = y</p> </blockquote> <p>and similarly for <b>op2*</b>.</p> <p>A lot of details are omitted (mostly easy enough to work out), and this basic approach could be prettified in various ways, but I don't know whether this is along the lines you were asking for and also whether maybe this is pretty straightforward and you've already worked it all out for yourself. Anyway, I hope this is useful.</p> <hr> <p>From @perror's comment (below) it seems clear that the formalization above is not powerful enough to capture the obfuscation he has in mind (though it might be possible to get a little mileage from generalizing the encoding/decoding functions <strong>enc</strong> and <strong>dec</strong>).</p> <p>I had forgotten about this paper, which discusses a transformation that seems relevant (see Sec. 6.1, "Split variables"):</p> <blockquote> <p>Christian Collberg, Clark Thomborson, and Douglas Low. Breaking Abstractions and Unstructuring Data Structures. <em>IEEE International Conference on Computer Languages</em> (ICCL'98), May 1998. (<a href="http://www.cs.arizona.edu/~collberg/content/research/papers/collberg98breaking.pdf" rel="nofollow">link</a>)</p> </blockquote>
2489
2013-07-16T11:50:18.653
<p>I don't know the exact name of this obfuscation, so I call it <strong>variable entanglement</strong> for now.</p> <p>I already saw this principle in a few binaries but I never found a complete description of what was possible and what was not.</p> <p>The idea is to confuse the reverser by mixing two values together and performing the operations on the mixed values. Once all operations have been performed, one can recompose the results by some simple operations. For example, a naive example could be:</p> <pre><code>int foo (int a, int b) { long long x = 0; // Initial entanglement x = (a &lt;&lt; 32) | b; // Performing operations on both variables x += (12 &lt;&lt; 32) &amp; 72; ... // Final desentanglement a = (int) (x &gt;&gt; 32); b = (int) (((int) -1) &amp; x); } </code></pre> <p>Of course, here, we mix everything in one variable (and I did not take care of <em>details</em> such as the overflows). But, you can imagine way more complex initial entanglement where you re-split everything in two variables (or more), <em>e.g.</em> by xoring them together. </p> <p>Operations such as addition, multiplication, ... have to be redefined for this new format, so it can mislead the reverser.</p> <p>My question now, does anyone know about different such schema of variable entanglement (the one I gave is really basic) ? And, maybe, can give pointers or publication about it ?</p>
Where and how is variable entanglement obfuscation used?
|obfuscation|whitebox-crypto|
<p>While in the Text View of the disassembly window, press <kbd>Alt + T</kbd>. In the Text Search window, search for <code>shl</code> and check <code>Find all occurrences</code>:</p> <p><img src="https://i.stack.imgur.com/OR0Mt.png" alt="Text Search window"></p> <p>Press <code>OK</code> and you will get a list of all functions that contain <code>shl</code>:</p> <p><img src="https://i.stack.imgur.com/dCWjK.png" alt="Occurrences of: shl"></p>
2493
2013-07-17T04:51:41.077
<p>I have a DLL with a large number of functions in IDA Pro. I would like to make a script that can scan the instructions within each of the functions looking for a specific instruction. For my specific case right now, I am looking for functions that shift left (shl). I am not sure which register is being shifted so I would like to keep it versatile. I do know that it is only shifting one place in this specific case.</p> <p>I know python on a very basic level, and I know IDA-Python on a non-existent level. Please help me with suggestions on how to access this data inside IDA.</p> <p>Edit:<br> I have read through <a href="https://stackoverflow.com/questions/8860020/is-there-a-way-to-export-function-names-from-ida-pro?rq=1">this question</a> and it says that there is no direct access to the list of functions that have been discovered by IDA. You have to specify a starting function address. Is there any better way to list functions?</p>
IDA Pro List of Functions with Instruction
|ida|idapython|
<p>I also just started to learn more about this topic and managed to write down the following lines of code.</p> <p>I guess all my comments in the code are good enough as answer. I dont know much more then that anyway.</p> <pre><code> ' #!/usr/bin/env python import immlib import struct from immlib import STDCALLFastLogHook DESC="FastLoogHook" def main(args): """ Will hook and run its own assembly code then return to the process Usage: First run the script to install hook, then run it again to get results ^^ """ imm = immlib.Debugger() Name = "hippie" # Get stored data on second script run fast = imm.getKnowledge(Name) if fast: # Get a list of all the things we saved hook_list = fast.getAllLog() # Log result imm.log(str(hook_list)) # unpack list (func_addr, (esp1, esp2)) = hook_list[0] # Log argument imm.log(imm.readString(esp2)) return "Parsing results done" # Find strcpy address strcpy = imm.getAddress("msvcrt.strcpy") # Building the hook fast = immlib.FastLogHook(imm) # This function is required and returns # the address of the original instruction fast.logFunction(strcpy) # Offset fast.logBaseDisplacement("ESP", 4) fast.logBaseDisplacement("ESP", 8) # Set hook fast.Hook() # Save data for later use imm.addKnowledge(Name, fast, force_add = 1) return "FastLogHook installed for strcpy"' </code></pre>
2502
2013-07-20T03:23:53.260
<p>I am a newbie in python programming for Debugging . I wrote a code for using the function FastLogHook() in immlib but i am not able to figure out the exact problem with my code as it is not working :(</p> <p><b> Here is My code </b></p> <pre><code>#!/usr/bin/env python import immlib from immlib import FastLogHook DESC = "FastLogHook Basic Demo" def showresult(imm, a,addr): if a[0]==addr: imm.Log("(0x%08x &gt;&gt; 0x%08x , 0x%08x)%(a[1][0], a[1][1], a[1][2]) ") return "done" def main(args): imm = immlib.Debugger() Name = 'fasty' fast = imm.getKnowledge( Name ) functionToHook = "msvcrt.strcpy" functionAddress = imm.getAddress(functionToHook) imm.log(str(functionAddress) + 'pf') if fast: hook_list = fast.getAllLog() imm.log(str(hook_list)) for a in hook_list: ret = showresult( imm, a, functionAddress ) return"Logged: %d hook hits." % len(hook_list) imm.pause() fast = FastLogHook(imm) fast.logFunction(functionAddress) fast.logBaseDisplacement('ESP', 0x4) fast.logBaseDisplacement('ESP', 0x8) fast.logRegister("ESP") fast.Hook() imm.addKnowledge(Name, fast, force_add = 1) return "Success!!" </code></pre> <p>I am running this code in Immunity Debugger but continuously getting error . I searched , googled but due to the limitation of documentation regarding this I am unable to correct it .</p>
Use of FastLogHook function in immlib?
|python|immunity-debugger|
<p>ollydbg 2.0 supports AT&amp;T syntax also</p> <pre><code>CPU Disasm Address Command Comments 01002C0C CMPL %ESI, %DS:notepad.fUntitled ; Case 3 of switch notepad.1002BBE 01002C12 MOVL %DS:notepad.g_ftOpenedAs, %EAX 01002C17 MOVL %EAX, %DS:notepad.g_ftSaveAs 01002C1C JNE $notepad.01002C37 01002C1E PUSHL %ESI ; /Arg3 = 0B1F01 01002C1F PUSHL $OFFSET notepad.szFileName ; |Arg2 = notepad.szFileName 01002C24 PUSHL %DS:notepad.hwndNP ; |Arg1 = 0 01002C2A CALL $notepad.SaveFile ; \notepad.SaveFile </code></pre>
2505
2013-07-20T14:30:52.657
<p>So I understand that there are many assemblers such as MASM, FASM, NASM, etc.</p> <p>But which version is the disassembler in OllyDbg and Cheat Engine?</p>
Which version of assembly does OllyDbg disassemble binary to?
|disassembly|assembly|disassemblers|
<p>I will assume you are talking about Windows Sockets and IPv4, since you have not mentioned otherwise. <code>sockaddr</code> is very well described in <a href="https://i.stack.imgur.com/8cNC8.png" rel="noreferrer">MSDN</a>. It is defined as for IPv4 as follows:</p> <pre><code>struct sockaddr { ushort sa_family; char sa_data[14]; }; struct sockaddr_in { short sin_family; u_short sin_port; struct in_addr sin_addr; char sin_zero[8]; }; </code></pre> <p>I will use simple server application for demonstration purposes. Firstly let's set breakpoint on <code>bind()</code> and see what stack looks like:</p> <p><img src="https://i.stack.imgur.com/8cNC8.png" alt="enter image description here"></p> <p>As you can see, <code>pSockAddr</code> is a pointer to <code>sockaddr</code> structure is pushed on to stack as a second argument to the function. Let's go a little further and examine the <code>sockaddr</code> at <code>0x0031F840</code>:</p> <p><img src="https://i.stack.imgur.com/0hdv7.png" alt="enter image description here"></p> <p>One very important thing to note is that <code>sin_port</code> and <code>sin_addr</code> are stored using <a href="http://en.wikipedia.org/wiki/Endianness" rel="noreferrer"><em>big-endian</em></a> byte order, meaning the most significant part stored first.</p> <p>Now let's jump in and get <a href="https://www.corelan.be/index.php/2010/01/26/starting-to-write-immunity-debugger-pycommands-my-cheatsheet/" rel="noreferrer">pyCommand</a> created in order to automate it with <a href="http://www.immunityinc.com/products-immdbg.shtml" rel="noreferrer">Immunity Debugger</a>. For this purpose I will use <code>BpHook</code>:</p> <pre><code># bindtrace PyCommand by PSS from immlib import * NAME = "bindtrace" class BindBpHook(BpHook): def __init__(self): BpHook.__init__(self) def run(self, regs): imm = Debugger() imm.log(" ") imm.log("Bind() called:") # Read sockaddr structure address sockaddr = imm.readLong(regs["ESP"] + 8) # Read 2 bytes of sin_family member sockaddr_sin_family = imm.readShort(sockaddr) # Read 2 bytes of sin_port and calculate port number # since it is stored as big-endian portHiByte = ord(imm.readMemory(sockaddr + 2, 1)) portLowByte = ord(imm.readMemory(sockaddr + 3, 1)) sockaddr_sin_port = portHiByte * 256 + portLowByte # Read 4 bytes of sin_addr since it is stored as big-endian ipFirstByte = ord(imm.readMemory(sockaddr + 4, 1)) ipSecondByte = ord(imm.readMemory(sockaddr + 5, 1)) ipThirdByte = ord(imm.readMemory(sockaddr + 6, 1)) ipForthByte = ord(imm.readMemory(sockaddr + 7, 1)) # Print results to Log View window imm.log("---&gt; Pointer to sockaddr structure: 0x%08x" % sockaddr) imm.log("---&gt; sockaddr.sin_family: %d" % sockaddr_sin_family) imm.log("---&gt; sockaddr.sin_port: %d" % sockaddr_sin_port) imm.log("---&gt; sockaddr.sin_addr: %d.%d.%d.%d" % \ (ipFirstByte,ipSecondByte,ipThirdByte,ipForthByte)) imm.log(" ") imm.log("Press F9 to resume") def main(args): imm = Debugger() functionToHook = "ws2_32.bind" # Find address of the function to hook functionAddress = imm.getAddress(functionToHook) # Create and install our hook myHook = BindBpHook() myHook.add(functionToHook, functionAddress) imm.log("Hook for %s installed at: 0x%08x" % (functionToHook, functionAddress)) return "[*] Hook installed." </code></pre> <p>Installation of the script is very simple. All pyCommands are stored in ./pyCommands folder of Immunity Debugger installation. I named my file <code>bindtrace.py</code>.</p> <p>Thereafter, we load our executable into Immunity Debugger. Debugger will break automatically at entry point. Right after that we invoke the above pyCommand by typing <code>!bindtrace</code>, and run the executable by pressing <kbd>F9</kbd>. As soon as breakpoint hits, we get the result in Log windows, which can be accessed through <kbd>Alt + L</kbd>:</p> <p><img src="https://i.stack.imgur.com/7j7pm.png" alt="enter image description here"></p>
2507
2013-07-20T17:54:16.717
<p>How do I get IP address and port number out of bind function in Server application. Can it be achieved with hooks like bphook in immunity debugger?</p> <p>My problem is that I don't know how to unpack struct psockaddr/sockaddr or how sockaddr is saved on the stack.</p>
Server-side bind() function, immlib
|python|immunity-debugger|
<p>To add to @jvoisin's answer, you can have a look at <a href="https://github.com/kholia/checksec" rel="nofollow">checksec</a> - python implementation of checksec.sh</p> <p>Both these scripts are simple (compared to mona.py) and should help you get started. </p>
2510
2013-07-20T23:31:00.197
<p>How to check if DEP, ASLR and SafeSEH defense mechanism are enabled or not in a program using <code>immlib</code> library of Python in Immunity Debugger ? </p> <p>Actually I am looking for small code snippet for each.</p>
Check DEP , ASLR and SafeSEH enabled or not , immlib
|debuggers|python|immunity-debugger|seh|
<p>There were a lot of saying in replays, but I'd like to stress on some answers from the practical point of view:</p> <ul> <li><strong>network connection</strong> - a while ago I would agree that simply disconnecting the vm from the network will solve the problem of spreading through the network. Today, there are more and more malwares that will work only when the connection to CnC has been established or at least it can ping to the outer world, so I'd suggest that you should think about more serious solution than just disconnecting the cable: <ul> <li>setup another vm which will function as a gateway, this will also help you to log the traffic</li> <li>use network simulation software like iNetSim which can help in some cases when you need to fake the result returned by the CnC</li> <li>setup firewall and try not to use network shares or at least make them read only </li> </ul></li> <li><strong>VM setup</strong> - not installing vm tools is of cause a way to hide vm from the malware but it is really hard to work on such vm. The very least that you should do, is setup the VM in a more stealthy way. I've found a couple of links that may help with this, but there are many more other solutions: <ul> <li><a href="http://www.unibia.com/unibianet/systems-networking/bypassing-virtual-machine-detection-vmware-workstation" rel="nofollow">Bypassing Virtual Machine Detection on VMWare Workstation</a> - you can find here vmware configuration options for stealthier work and some other stuff.</li> <li><a href="http://www.simonganiere.ch/2012/11/20/malware-anti-vm-technics/" rel="nofollow">Malware anti-VM technics</a> - some explanations about what helps the malware to detect vm</li> <li>the next step is to develop different proprietary tools that can help you with research and more advanced anti-vm techniques.</li> <li>try to setup your environment is such a way, so that the host and the guest are different OSs - host is linux/unix/osx and the guest is windows. This will further minimize the risk of host infection.</li> </ul></li> <li><strong>physical machines</strong> - from practical point of view the use of physical machines is pretty annoying and consumes time and demands much accuracy especially when dealing with unknown malwares and I'm not event talking about the restore overhead after the machines were infected.</li> </ul> <p>Hope this will help :)</p>
2513
2013-07-22T00:48:28.517
<p>Once I perform static analysis on a malware sample, I next run it in a virtual machine.</p> <ul> <li>Does this give the malware a chance to spread to the real machine?</li> <li>Does this give the malware a chance to spread across networks?</li> <li>What steps/tips can I follow to prevent the malware from spreading from the VM?</li> </ul> <p>I use VMwareW.</p>
Malware in virtual machines
|malware|virtual-machines|
<p>Your choice of decompiler can greatly affect the outcome. You should try either JODE, or Fernflower (which I believe goes by Androchef).</p> <p>Before decompiling, it might be a good idea to do some simple deobfuscation yourself. For example, you could try</p> <ul> <li><p>Remapping of Java keywords that have been used as class/method/variable names to legal Java identifiers. This task is very easy to do by using the Remapping adapters provided by the ASM library, <a href="http://asm.ow2.org/asm40/javadoc/user/org/objectweb/asm/commons/RemappingClassAdapter.html" rel="nofollow">http://asm.ow2.org/asm40/javadoc/user/org/objectweb/asm/commons/RemappingClassAdapter.html</a></p></li> <li><p>Some simple reorganization of blocks. Many obfuscators will stick gotos into awkward places that would be "within a single expression" in the Java source code, e.g. pushing something to the stack, then jumping, then storing it to a local variable in the destination is perfectly viable in bytecode, but understanding that the bytecode is simply doing var = value might give some decompilers a hard time.</p></li> </ul>
2521
2013-07-22T21:20:59.370
<p>I compiled some [relatively complex] Java code into a .class file, then used jad to decompile it back into java. Of course, the code was obfuscated, which was to be expected. However, given that I had the original code, I thought I'd be able to look through the decompiled code fairly easily. However, I noticed differences in the code, such as where certain variables were defined (including differences of scope).</p> <p>Is there any main reason for this? I imagine it's one of those things that just happen in decompilation of code, but I'm more curious about what factors cause the change (e.g. complexity of code, whether it refers to other files, etc.).</p> <p>Could someone provide me with a good explanation on what factors cause the differences in the code before and after?</p> <h3>Edit</h3> <p>Technically, the .class file is pulled from a jar. I extracted the contents and used the .class file in there.</p> <p>As far as which obfuscator I used, I used the Retroguard obfuscator with the following options (I'm currently just exploring obfuscation and finding out what each thing does to the final result):</p> <pre><code>.option Application .option Applet .option Repackage .option Annotations .option MapClassString .attribute LineNumberTable .attribute EnclosingMethod .attribute Deprecated </code></pre> <p>Documentation for the script can be found on <a href="http://www.retrologic.com/rg-docs-scripting.html" rel="nofollow noreferrer">their site</a>. It's a little unorganized, but you should be able to find adequate explanations in there. It's also noteworthy that I stripped the generics and the local variable table.</p> <p>I have now also set up a way (inspired by the creators of the Minecraft Coder Pack) to rename the sources using data from a file (or files), which is passed to a dictionary of lists for packages, classes, methods, and fields.</p> <pre><code># snippet from the MCP version (mine's slightly different) (all in Python): srg_types = {'PK:': ['obf_name', 'deobf_name'], 'CL:': ['obf_name', 'deobf_name'], 'FD:': ['obf_name', 'deobf_name'], 'MD:': ['obf_name', 'obf_desc', 'deobf_name', 'deobf_desc']} parsed_dict = {'PK': [], 'CL': [], 'FD': [], 'MD': []} </code></pre> <p>A line is then parsed from the file, and it is passed into the <code>parsed_dict</code> and then used to rename everything (back and forth). Implemented after compiling than decompiling the first time (after I noticd differences).</p>
Why are there (sometimes major) differences between java source code and its decompiled result?
|decompilation|java|
<p>The answer lays within the comments, read Binary Diffing by Nicolas A. Economou (CoreImpact) 2009 to see why.</p> <p>Good Binary Diffing is in fact a way harder subject that does a lot more than compare bytes or bits. </p> <p>Making a Binary Diff with objdump and meld is really not the way to go. Read the CoreImpact document and it will show some of the issues with binary diffing.</p>
2529
2013-07-23T14:13:21.980
<p>Does any of you know of a recent tool to bindiff using ImmunityDebugger? I know about BinDiff by Zynamics and PatchDiff for IDA. But I really want a tool like this in ImmDBG. I also know about Radare's bindiffer and the feature in <code>mona.py</code> (but this is more with memory regions).</p> <p>Now I use a HexEditor and diff using this. Then I'll lookup the offset + base address using Immunity. This is not really feasible any more as I've recently started reversing bigger patches.</p> <p>(Just to be a complete reference, for Firmware Updates I use Binwalk. And you should too :)) </p>
Reversing Patches (Binary Diffing)
|immunity-debugger|patch-reversing|bin-diffing|
<p>It's an undocumented non-exported function. Hex-Rays output is:</p> <pre><code>RPC_STATUS __stdcall BindW(RPC_WSTR *StringBinding, RPC_BINDING_HANDLE *Binding) { RPC_STATUS result; // eax@1 result = RpcStringBindingComposeW(0, L"ncalrpc", 0, L"protected_storage", 0, StringBinding); if ( !result ) result = RpcBindingFromStringBindingW(*StringBinding, Binding); return result; } </code></pre>
2538
2013-07-26T16:39:41.280
<p>I am looking at a windows library in IDA pro and I came across a function call <pre><code>BindW(ushort **, void **)</code></pre></p> <p>IDA pro adds the comments <em>Binding</em> and <em>StringBinding</em> respectively to the parameters when they are pushed.</p> <p>What is this function?</p>
What is *BindW*?
|windows|
<p>To answer to this question, we have first to rephrase it a bit. The real question can be stated like this: </p> <blockquote> <p><em>What are the symbols that cannot be removed from an ELF binary file ?</em></p> </blockquote> <p>Indeed, <code>strip</code> removes quite a bit of information from the ELF file, but it could do a bit more (see the option <code>--strip-unneeded</code> from <code>strip</code> or the program <a href="http://www.muppetlabs.com/~breadbox/software/elfkickers.html"><code>sstrip</code></a> for more about this). So, my original question was more about what symbols can be assumed to be in the executable file whatever modifications have been made on the ELF file.</p> <p>In fact, there is only one type of symbols that you need to keep whatever happen, we call it <strong>dynamic symbols</strong> (as opposed at <em>static symbols</em>). They are a bit different from the static ones because we never know in advance where they will be pointing to in memory. Indeed, as they are supposed to point to external binary objects (libraries, plugin), the binary blob is dynamically loaded in memory while the process is running and we cannot predict at what address it will be located.</p> <p>If the static symbols are stored in the <code>.symbtab</code> section, the dynamic ones have their own section called <code>.dynsym</code>. They are kept separate to ease the operation of <strong>relocation</strong> (the operation that will give a precise address to each dynamic symbol). The relocation operation also relies on two extra tables which are namely: </p> <ul> <li><code>.rela.dyn</code> : Relocation for dynamically linked objects (data or procedures), if PLT is not used.</li> <li><code>.rela.plt</code> : List of elements in the PLT (Procedure Linkage Table), which are liable to the relocation during the dynamic linking (if PLT is used).</li> </ul> <p>Somehow, put all together, <code>.dynsym</code>, <code>.rela.dyn</code> and <code>.rela.plt</code> will allow to patch the initial memory (<em>i.e.</em> as mapped in the ELF binary), in order for the dynamic symbols to point to the right object (data or procedure).</p> <p>Just to illustrate a bit more the process of relocation of dynamic symbols, I built examples in i386 and amd64 architectures.</p> <h2>i386</h2> <pre><code>Symbol table '.dynsym' contains 6 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 FUNC GLOBAL DEFAULT UND perror@GLIBC_2.0 (2) 2: 00000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.0 (2) 3: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 4: 00000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (2) 5: 080484fc 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_used Relocation section '.rel.dyn' at offset 0x28c contains 1 entries: Offset Info Type Sym.Value Sym. Name 08049714 00000306 R_386_GLOB_DAT 00000000 __gmon_start__ Relocation section '.rel.plt' at offset 0x294 contains 4 entries: Offset Info Type Sym.Value Sym. Name 08049724 00000107 R_386_JUMP_SLOT 00000000 perror 08049728 00000207 R_386_JUMP_SLOT 00000000 puts 0804972c 00000307 R_386_JUMP_SLOT 00000000 __gmon_start__ 08049730 00000407 R_386_JUMP_SLOT 00000000 __libc_start_main </code></pre> <h2>amd64</h2> <pre><code>Symbol table '.dynsym' contains 5 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.2.5 (2) 2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (2) 3: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND perror@GLIBC_2.2.5 (2) Relocation section '.rela.dyn' at offset 0x368 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000600960 000300000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0 Relocation section '.rela.plt' at offset 0x380 contains 4 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000600980 000100000007 R_X86_64_JUMP_SLOT 0000000000000000 puts + 0 000000600988 000200000007 R_X86_64_JUMP_SLOT 0000000000000000 __libc_start_main + 0 000000600990 000300000007 R_X86_64_JUMP_SLOT 0000000000000000 __gmon_start__ + 0 000000600998 000400000007 R_X86_64_JUMP_SLOT 0000000000000000 perror + 0 </code></pre> <p>A few interesting web pages and articles about dynamic linking:</p> <ul> <li><a href="http://www.technovelty.org/linux/plt-and-got-the-key-to-code-sharing-and-dynamic-libraries.html">PLT and GOT - the key to code sharing and dynamic libraries</a>;</li> <li><a href="http://www.technovelty.org/linux/stripping-shared-libraries.html">Stripping shared libraries</a>;</li> <li><a href="http://www.codeproject.com/Articles/70302/Redirecting-functions-in-shared-ELF-libraries">Redirecting functions in shared ELF libraries</a>;</li> <li><a href="http://fluxius.handgrep.se/2011/10/20/the-art-of-elf-analysises-and-exploitations/">The Art Of ELF: Analysis and Exploitations</a>;</li> <li><a href="http://bottomupcs.sourceforge.net/csbu/x3824.htm">Global Offset Tables</a>;</li> </ul>
2539
2013-07-26T17:24:18.553
<p>I am currently looking at the ELF format, and especially at stripped ELF executable program files.</p> <p>I know that, when stripped, the symbol table is removed, but some information are always needed to link against dynamic libraries. So, I guess that there are other symbols that are kept whatever the executable has been stripped or not. </p> <p>For example, the dynamic symbol table seems to be always kept (actually this is part of my question). It contains all the names of functions coming from dynamic libraries that are used in the program.</p> <p>Indeed, taking a stripped binary and looking at the output of <code>readelf</code> on it will give you the following output:</p> <pre><code>Symbol table '.dynsym' contains 5 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.2.5 (2) 2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (2) 3: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND perror@GLIBC_2.2.5 (2) </code></pre> <p>My question is, what are all the symbol tables that the system always need to keep inside the executable file, even after a strip (and what are they used for) ?</p> <p>Another part of my question, would also be about how to use these dynamic symbols. Because, they are all pointing to zero and not to a valid address. You do we identify, as <code>objdump</code> does, their respective links to the code stored in the PLT. For example, in the following dump I got from <code>objdump -D</code>, we can see that the section <code>.plt</code> is split, I assume that this is thanks to symbols, into subsections corresponding to each dynamic function, I would like to know if this is coming from another symbol table that I do not know or if <code>objdump</code> rebuild this information (and, then, I would like to know how):</p> <pre><code>Disassembly of section .plt: 0000000000400400 &lt;puts@plt-0x10&gt;: 400400: ff 35 6a 05 20 00 pushq 0x20056a(%rip) 400406: ff 25 6c 05 20 00 jmpq *0x20056c(%rip) 40040c: 0f 1f 40 00 nopl 0x0(%rax) 0000000000400410 &lt;puts@plt&gt;: 400410: ff 25 6a 05 20 00 jmpq *0x20056a(%rip) 400416: 68 00 00 00 00 pushq $0x0 40041b: e9 e0 ff ff ff jmpq 400400 &lt;puts@plt-0x10&gt; 0000000000400420 &lt;__libc_start_main@plt&gt;: 400420: ff 25 62 05 20 00 jmpq *0x200562(%rip) 400426: 68 01 00 00 00 pushq $0x1 40042b: e9 d0 ff ff ff jmpq 400400 &lt;puts@plt-0x10&gt; 0000000000400430 &lt;__gmon_start__@plt&gt;: 400430: ff 25 5a 05 20 00 jmpq *0x20055a(%rip) 400436: 68 02 00 00 00 pushq $0x2 40043b: e9 c0 ff ff ff jmpq 400400 &lt;puts@plt-0x10&gt; 0000000000400440 &lt;perror@plt&gt;: 400440: ff 25 52 05 20 00 jmpq *0x200552(%rip) 400446: 68 03 00 00 00 pushq $0x3 40044b: e9 b0 ff ff ff jmpq 400400 &lt;puts@plt-0x10&gt; </code></pre> <p><strong>Edit</strong>: Thanks to Igor's comment, I found the different offsets allowing to rebuild the information in <code>.rela.plt</code> (but, what is <code>.rela.dyn</code> used for ?).</p> <pre><code>Relocation section '.rela.dyn' at offset 0x368 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000600960 000300000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0 Relocation section '.rela.plt' at offset 0x380 contains 4 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000600980 000100000007 R_X86_64_JUMP_SLO 0000000000000000 puts + 0 000000600988 000200000007 R_X86_64_JUMP_SLO 0000000000000000 __libc_start_main + 0 000000600990 000300000007 R_X86_64_JUMP_SLO 0000000000000000 __gmon_start__ + 0 000000600998 000400000007 R_X86_64_JUMP_SLO 0000000000000000 perror + 0 </code></pre>
What symbol tables stay after a strip In ELF format?
|elf|dynamic-linking|
<p>Here is something directly from Microsoft.</p> <p><a href="https://github.com/Microsoft/microsoft-pdb">https://github.com/Microsoft/microsoft-pdb</a></p>
2548
2013-07-28T00:05:01.357
<p>Where I can find such information? I've already read the undocumented windows 2000 secrets explanation of it but it isn't complete. For example the 3rd stream format isn't explained. I have looked at <a href="https://code.google.com/p/pdbparser/" rel="nofollow">this</a>, where some general info about the streams is given but nothing more.</p>
PDB v2.0 File Format documentation
|file-format|pdb|
<p>To Unpack a file you must have quite a lot of experience in reversing binaries..</p> <p>Remember there exists no universal method that works for all the packers.</p> <p>These steps will work in unpacking 97% of binaries;</p> <ol> <li>You must be aware of the code that usually lies at the start of entry point in binaries compiled by well known compilers VC++, VB, Borland Delphi and other compilers. You should also be aware of the difference in code near entry point in binaries compiled in different compiler versions. This will eventually help you in finding the OEP.</li> <li>You must have abundance patience to follow all the virtual memory allocation and virtual memory freeing.</li> <li>Dump the memory blocks and look for visible strings after execution of a decryption code.</li> <li>Learn about debugger detection, virtual environment detection and anti-debugging techniques.</li> <li>Start with simple packers at first. I will recommend you to try UPX older versions.</li> <li>Last but not the least "Play with your favorite debugger at-least for 14 hours a day."</li> </ol> <p>All the best and Happy reversing!!!</p>
2552
2013-07-28T17:27:08.943
<p>As I am just getting started in RE, I've mostly faced files packed with a single-layer of packing , such as UPX, ASPack, etc.</p> <p>Unpacking these protections is fully documented online. The problem begins when I deal with <strong>multiple layers of packing</strong>, especially concerning malware. I have followed some tutorials though they're usually not detailed enough. They seem to go through a <strong>tedious process</strong> to find the OEP. For example, they start by dealing with common packers (which is the easy part) and then they begin to set breakpoints everywhere "<strong>in calls and jumps</strong>" and tracing through the file here and there, which is for me the <strong>hard part</strong> that I have described above. At this point, I have no clue for what they are seeking or for what they are aiming, and then after some work, they find the OEP! </p> <p>So what logic did they follow in that process? Also, because I know that the subject is broad, I'm also interested in some keywords.</p>
How to unpack files packed with multiple packers?
|malware|unpacking|
<p>The output from the file utility, as you've probably guessed, is a false positive. The beginning of the firmware.bin file contains what looks to be a basic header (note the "SIG" string near the beginning of the file), and a bunch of MIPS executable code, which is likely the bootloader:</p> <pre><code>DECIMAL HEX DESCRIPTION ------------------------------------------------------------------------------------------------------------------- 196 0xC4 MIPS instructions, function epilogue 284 0x11C MIPS instructions, function epilogue 372 0x174 MIPS instructions, function epilogue 388 0x184 MIPS instructions, function epilogue 416 0x1A0 MIPS instructions, function epilogue 424 0x1A8 MIPS instructions, function prologue 592 0x250 MIPS instructions, function epilogue 712 0x2C8 MIPS instructions, function epilogue 720 0x2D0 MIPS instructions, function prologue 832 0x340 MIPS instructions, function epilogue 840 0x348 MIPS instructions, function prologue 912 0x390 MIPS instructions, function epilogue 920 0x398 MIPS instructions, function prologue 976 0x3D0 MIPS instructions, function epilogue 984 0x3D8 MIPS instructions, function epilogue 1084 0x43C MIPS instructions, function epilogue 1192 0x4A8 MIPS instructions, function epilogue 1264 0x4F0 MIPS instructions, function epilogue ... </code></pre> <p>Running strings on the firmware.bin binary seems backup this hypothesis, with many references to checksum and decompression errors:</p> <pre><code>checksum error! (cal=%04X, should=%04X) signature error! (Compressed) start: %p unmatched objtype between memMapTab and image! Length: %X, Checksum: %04X Version: %s, Compressed Length: %X, Checksum: %04X memMapTab Checksum Error! (cal=%04X, should=%04X) memMapTab Checksum Error! %3d: %s(%s), start=%p, len=%X %s Section: memMapTab: %d entries, start = %p, checksum = %04X $USER Section: signature error! ROMIO image start at %p code length: %X code version: %s code start: %p Decompressed image Error! Decompressed image Checksum Error! (cal=%04X, should=%04X) ROM length(%X) &gt; RAM length (%X)! Can't find %s in $ROM section. Can't find %s in $RAM section. RasCode </code></pre> <p>A quick examination of the strings in the two decompressed LZMA files you found shows that the smaller one (at offset 0x14C33) appears to contain some debug interface code, likely designed to be accessed via the device's UART:</p> <pre><code> UART INTERNAL LOOPBACK TEST UART EXTERNAL LOOPBACK TEST ERROR ======= HTP Command Listing ======= &lt; press any key to continue &gt; macPHYCtrl.value= MAC INTERNAL LOOPBACK TEST MAC EXTERNAL LOOPBACK TEST MAC INTERNAL LOOPBACK MAC EXTERNAL LOOPBACK LanIntLoopBack ... Tx Path Full, Drop packet:%d 0x%08x tx descrip %d: rx descrip %d: %02X %08X: &lt; Press any key to Continue, ESC to Quit &gt; 0123456789abcdefghijklmnopqrstuvwxyz 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ &lt;NULL&gt; ) Register Dump ***** ***** ATM SAR Module: VC( Reset&amp;Identify reg = Traffic Sched. TB reg= TX Data ctrl/stat reg= RX Data ctrl/stat reg= Last IRQ Status reg = IRQ Queue Entry len = VC IRQ Mask register = TX Data Current descr= RX Data Current descr= TX Traffic PCR = TX Traffic MBS/Type = TX Total Data Count = VC IRQ CC Mask reg = TX CC Current descr = TX CC Total Count = RX Miss Cell Count = ***** ATM SAR Module: Common Register Dump ***** </code></pre> <p>The second larger file (at offset 0x55433) appears to contain the ThreadX RTOS, by Green Hills:</p> <pre><code>RTA231CV Reserved String anonymous www.huawei.com 1000 tc-e4f6ed2f5b87&lt; MSFT 5.07 user&lt; MSFT 5.07 LXT972 "AC101L CIP101 RTL8201 CAC201 jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj jjjjjjjj jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj jjjjjjjj jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj System Timer Thread Copyright (c) 1996-2000 Express Logic Inc. * ThreadX R3900/Green Hills Version G3.0f.3.0b * </code></pre> <p>If you aren't familiar with RTOS's, they typically are just one big kernel with no concept of user space vs kernel space or what you would think of as a normal file system, although they will contain things like images and HTML files for this device's Web interface (see <a href="http://www.devttys0.com/2011/06/mystery-file-system/" rel="nofollow">here</a> for an example of how these types of files are stored/accessed in some VxWorks systems). </p> <p>I'd say that you already pretty much have this firmware extracted into its basic parts. To further analyze the bootloader or the two extracted LZMA files, you will need to start disassembling those files, which entails determining the memory address where they are loaded at boot time, identifying code/data sections, looking for possible symbol tables, identifying common functions, and probably writing some scripts to help with all of the above.</p>
2557
2013-07-29T16:48:39.017
<p>I'm trying to unpack this firmware image but I'm getting some issues understanding the structure.</p> <p>First of all I have one image which I called firmware.bin, and the file command shows me that it's a LIF file:</p> <pre><code>firmware.bin: lif file </code></pre> <p>After that I analyze it with binwalk:</p> <pre><code>DECIMAL HEX DESCRIPTION ------------------------------------------------------------------------------------------------------- 84992 0x14C00 ZynOS header, header size: 48 bytes, rom image type: ROMBIN, uncompressed size: 65616, compressed size: 16606, uncompressed checksum: 0xBA2A, compressed checksum: 0x913E, flags: 0xE0, uncompressed checksum is valid, the binary is compressed, compressed checksum is valid, memory map table address: 0x0 85043 0x14C33 LZMA compressed data, properties: 0x5D, dictionary size: 8388608 bytes, uncompressed size: 65616 bytes 128002 0x1F402 GIF image data, version 8"9a", 200 x 50 136194 0x21402 GIF image data, version 8"7a", 153 x 55 349184 0x55400 ZynOS header, header size: 48 bytes, rom image type: ROMBIN, uncompressed size: 3113824, compressed size: 733298, uncompressed checksum: 0x3B9C, compressed checksum: 0xBBBA, flags: 0xE0, uncompressed checksum is valid, the binary is compressed, compressed checksum is valid, memory map table address: 0x0 349235 0x55433 LZMA compressed data, properties: 0x5D, dictionary size: 8388608 bytes, uncompressed size: 3113824 bytes </code></pre> <p>As you can see there are 2 LZMA, 2 ZynOS (LZMA also once cut) and 2 images. Once I extract the LZMA I uncompress it and the first one is a single binary, but the second one is another LZMA file with 127 files in it, and each one of those files have a lot of new files inside.</p> <p><img src="https://i.stack.imgur.com/l7AbK.png" alt="File content sample"></p> <p>I guess that I'm not following the correct steps to unpack it, so I'm wondering how could I get the main filesystem clean?.</p>
Unpack Billion 5102 firmware
|firmware|unpacking|mips|
<p>I still wonder should I add a comment on this because my knowledge on the cryptography is extremely limited. The paper on the jigsaw obfuscation uses a term named <em>functional encryption</em>, that means with the private key in hand the obfuscator can design some functions working on the encrypted data. And someone without the private key can use these functions on the encrypted data, but still know nothing about the data. </p> <p>For example, the obfuscator designs a function plus1 satisfying: </p> <blockquote> <p>plus1(encrypted(x)) = encrypted(x+1)</p> </blockquote> <p>the attacker will know that if he uses plus1, he can increase x by 1, but he does not know anything about the value of x. </p> <p>Now with the jigsaw obfuscation, given a program P with some input a, the obfuscator will encrypt the obfuscated program p as p = encrypt(P), then design a function F with input is some pair (p, a) satisfying: </p> <blockquote> <p>F(p,a) = decrypt(p)(a) = P(a)</p> </blockquote> <p>(note that F satisfies the equivalence above but the design of F is not trivial like that), and that means the attacker can always use F and p to get the output P(a), but he does not know anything about P.</p>
2586
2013-08-05T08:51:07.677
<p>You must have heard about it, it all over the on-line newspapers. Some researchers from UCLA claims to have achieved a <a href="http://newsroom.ucla.edu/portal/ucla/ucla-computer-scientists-develop-247527.aspx">breakthrough in software obfuscation</a> through 'mathematical jigsaw puzzles'. </p> <p>Their <a href="http://eprint.iacr.org/2013/451.pdf">scientific paper</a> can be found on <a href="http://eprint.iacr.org/2013/451">IACR eprint website</a>.</p> <p>Can someone sum-up what is really the content of the paper (and does is really worth it) ?</p>
What is this 'mathematical jigsaw puzzles' obfuscation?
|obfuscation|cryptography|whitebox-crypto|
<p>Expanding on my comment:</p> <p>The Freeware IDA Pro doesn't support MIPS, so you won't be able to use it. If you can't use the paid versions of IDA, there are <a href="https://reverseengineering.stackexchange.com/questions/1817/is-there-any-disassembler-second-to-ida">free alternatives</a>.</p> <p>As an example, using <code>radare2</code> as an example, on the Debian MIPS <code>binutils</code> port:</p> <pre><code>$ file bin/objdump bin/objdump: ELF 32-bit MSB executable, MIPS, MIPS-II version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=d1d228509874377d7339cfd5b2f15db020e53b7b, stripped </code></pre> <p>Following <a href="http://radare.org/y/?p=examples&amp;f=graph" rel="nofollow noreferrer">this example</a>, we get something like this:</p> <pre><code>[0x00403300]&gt; af@sym.main [0x00403300]&gt; ag &gt; foo.dot foo.dot created [0x00403300]&gt; !dot -Tpdf -o foo.pdf foo.dot [0x00403300]&gt; !open foo.pdf </code></pre> <p><img src="https://i.stack.imgur.com/f0Goi.png" alt="Part of the graph"></p> <p>Note that the PDF this churns out is enormous, so you might want to just use <code>pdf</code> instead of <code>ag</code> produce textual output rather than <code>dot</code> files.</p>
2587
2013-08-05T09:58:08.400
<p>I'm trying to load a CGI file to IDA in order to disassemble it and understand it's behaviour but I can't do it.</p> <p>According to the strings command I can see some interesting words like system, sprintf, etc. And I know it's a MIPS file, But I'm not able to get something comprehensible in IDA.</p> <p>Could anyone guide me to achieve this? Regards. </p>
How to reverse CGI file for MIPS?
|ida|firmware|radare2|mips|
<p>Jump two bytes forward from current position when zero flag == NULL Opcode for this <code>74 00</code> which is two bytes </p> <pre><code>seg000:00000000 74 00 jz short $+2 seg000:00000002 74 00 jz short $+2 </code></pre> <p>so effectively it will jump to next instruction whether the condition is met or not garbage mostly used in obfuscation </p>
2590
2013-08-05T15:17:50.767
<p>What does the dollar symbol mean in</p> <pre><code>jz $+2 </code></pre> <p>(This is IDA output.)</p>
What does `jz $+2` do? (jump if zero to dollar plus two)
|disassembly|ida|assembly|
<p>Slightly modified version from pydasm's <a href="https://code.google.com/p/libdasm/source/browse/trunk/pydasm/README.txt?r=2">README.txt</a></p> <pre><code>import pydasm import binascii # Open, and read 200 bytes out of the file, # while converting buffer to hex string with open('file.bin','r') as f: buffer = binascii.hexlify(f.read(200)) # Iterate through the buffer and disassemble offset = 0 while offset &lt; len(buffer): i = pydasm.get_instruction(buffer[offset:], pydasm.MODE_32) print pydasm.get_instruction_string(i, pydasm.FORMAT_INTEL, 0) if not i: break offset += i.length </code></pre> <p>ADDED:</p> <p>You also can play with <code>seek()</code> to go to certain position of the file, and then read from there. It is particular useful if you want to read shellcode embedded into some file and you know relative position. You will have to <code>open()</code> the file with "b" option for it to work. Consult <a href="http://docs.python.org/release/2.4.4/lib/bltin-file-objects.html">Python File Object Library Reference</a> for details.</p>
2596
2013-08-06T21:05:43.440
<p>How to disassemble first 200 bytes of an executable code using <a href="https://code.google.com/p/libdasm/" rel="nofollow">pydasm library</a> in Python? I want to know how to set size of buffer to disassemble it.</p>
Pydasm: Disassembling limited length executable shellcode
|disassembly|python|disassemblers|shellcode|
<p>if you are using <code>IDA FREE</code> then this and several other type libraries are not available </p> <p>and if you intend to </p> <pre><code>create them yourself and export them somehow (would have to figure out how). </code></pre> <p>this walk through provides few hints on how to accomplish it</p> <p>os winxp sp3 vm </p> <pre><code>(all opaque structures like EPROCESS can vary from os to os / hotfix to hotfix patch tuesday to patch tuesday ) </code></pre> <p>supposing you are reversing PsGetProcessId() in ntkrnlpa.exe </p> <pre><code> ; Exported entry 872. PsGetProcessId ; Attributes: bp-based frame ; __stdcall PsGetProcessId(x) public _PsGetProcessId@4 _PsGetProcessId@4 proc near 8B FF mov edi, edi 55 push ebp 8B EC mov ebp, esp 8B 45 08 mov eax, [ebp+8] 8B 80 84 00 00 00 mov eax, [eax+84h] &lt;----- 5D pop ebp C2 04 00 retn 4 _PsGetProcessId@4 endp </code></pre> <p>and you find out 84 is EPROCESS->Pid and want to impart this information to the disassembly</p> <p>make a text file named <code>EPROCESS.h</code> </p> <p>type the following in the text file and save it for accessing it later</p> <pre><code>typedef struct EPROCESS { BYTE unknown[0x84]; DWORD Pid; } EPROCESS, *EPROCESS; </code></pre> <p>go to <code>ida free -&gt;File-&gt;Load File-&gt;Parse Header File</code> or shortcut <code>ctrl+f9</code> browse to the <code>EPROCESS.h</code> </p> <p>you should see this is <code>ida information window</code> on being successful</p> <pre><code>The initial autoanalysis has been finished. C:\Documents and Settings\Admin\Desktop\EPROCESS.h: `successfully compiled` </code></pre> <p>view-><code>open subviews-&gt;structures</code> or shortcut <code>shift+f9</code> press <code>insert</code> key click <code>add standard structure</code> start typing <code>peb</code> and you should see the window scrolling and showing you the structure you just added</p> <pre><code>00000000 EPROCESS struc ; (sizeof=0x88, standard type) 00000000 unknown db 132 dup(?) 00000084 Pid dd ? 00000088 EPROCESS ends </code></pre> <p>go to idaview select <code>84h</code> / <code>right click-&gt;select structure offset</code></p> <p>and apply the <code>Eprocess.Pid</code> </p> <p>disassembly will become a bit more readable</p> <pre><code>8B 80 84 00 00 00 mov eax, [eax+EPROCESS.Pid] </code></pre> <p>start adding other discovered offset to this eprocess.h and load it again for updated structure definitions</p> <p>many of the structures definitions can be viewed via windbg</p> <p>for example peb and peb_ldr_data can be viewed like this</p> <pre><code>dt nt!_PEB dt nt!_PEB_LDR_DATA </code></pre> <p>Additional Details</p> <p>if you modify the .h file to add another structure member like this</p> <pre><code>typedef struct EPROCESS { BYTE unknown[0x84]; DWORD Pid; BYTE unk2[0xbc-0x88]; DWORD DebugPort; BYTE unknown1[0x174-0xc0]; BYTE ImageFileName[16]; } EPROCESS, *PEPROCESS; </code></pre> <p>Be Aware you would need to delete the earlier definitions before parsing the header file again and this implies all your earlier work will be lost on reloading so save your work</p>
2610
2013-08-10T00:42:12.860
<p>When reversing shellcode, we see the PEB walk fairly often at various stages. I am curious however, if there is any pre-defined standard structure for this in IDA? If so, what is it called? After looking and googling around I haven't been able to find anything. I would also be very interested in definitions for PEB_LDR_DATA and RTL_USER_PROCESS_PARAMETERS.</p> <p>I could create them myself and export them somehow (would have to figure out how). But before doing that I am really curious if there is just something I am missing amongst the standard structure definitions in IDA.</p>
Structure Definitions for PEB in IDA
|ida|shellcode|
<p>there are 2 loops in the code:</p> <blockquote> <p>0x40109d mov $0x2,%ecx<br> <strong><em>0x4010a2</em></strong> mov %ecx,%esi<br> 0x4010a4 mov $0x3,%ecx<br> <strong>0x4010a9</strong> mov $0x2,%ebx<br> ...<br> first loop<br> ...<br> 0x4010c4 <strong>loop 0x4010a9</strong><br> 0x4010c6 mov %esi,%ecx<br> second loop<br> 0x4010c8 <strong><em>loop 0x4010a2</em></strong> </p> </blockquote> <ul> <li>first goes three times as <strong>3</strong> was moved into <strong>%ecx</strong> at 0x4010a4 </li> <li>second loop will go two times as 2 was moved into <strong>%ecx</strong> at 0x40109d and saved at %esi before %ecx was used further inside the first loop.</li> </ul> <p>In addition here is information about <a href="http://pdos.csail.mit.edu/6.828/2006/readings/i386/LOOP.htm" rel="nofollow">LOOP</a> opcode </p> <blockquote> <p>0x4010ba lea 0xffffffd8(%ebp),%eax</p> </blockquote> <p>This mean that %eax got the address from calculating %ebp+0xffffffd8 </p> <blockquote> <p>0x4010bd lea (%ebx,%edx,4),%ebx</p> </blockquote> <p>This one is where %ebx = %ebx + %edx * 4</p> <blockquote> <p>0x4010c0 add %ebx,%eax</p> </blockquote> <p>Here %ebx is added to %eax</p> <blockquote> <p>0x4010c2 mov (%eax),%edi</p> </blockquote> <p>Finally %edi gets the data that %eax points to.</p> <p>A <a href="http://en.wikipedia.org/wiki/X86_assembly_language" rel="nofollow">small asm</a> reference. </p>
2620
2013-08-11T20:43:36.953
<p>I am having trouble understanding how this code knows when to stop looping. I am supposed to figure out what values are put into %edi. But I can't figure out how many times it loops.</p> <pre><code>0x40106e movl $0x2b,0xffffffdc(%ebp) 0x401075 movl $0x31,0xffffffe4(%ebp) 0x40107c movl $0x74,0xffffffec(%ebp) 0x401083 movl $0x19,0xffffffe8(%ebp) 0x40108a movl $0x7,0xffffffd8(%ebp) 0x401091 movl $0x14,0xffffffe0(%ebp) 0x401098 mov $0xdead,%edi 0x40109d mov $0x2,%ecx 0x4010a2 mov %ecx,%esi 0x4010a4 mov $0x3,%ecx 0x4010a9 mov $0x2,%ebx 0x4010ae sub %esi,%ebx 0x4010b0 imul $0xc,%ebx,%ebx 0x4010b3 mov $0x3,%edx 0x4010b8 sub %ecx,%edx 0x4010ba lea 0xffffffd8(%ebp),%eax 0x4010bd lea (%ebx,%edx,4),%ebx 0x4010c0 add %ebx,%eax 0x4010c2 mov (%eax),%edi 0x4010c4 loop 0x4010a9 0x4010c6 mov %esi,%ecx 0x4010c8 loop 0x4010a2 0x4010ca mov $0xbeef,%edi </code></pre> <p>Edit: I now understand the looping logic. However I am having a hard time following all the values getting moved around. I am stuck here <code>lea 0xffffffd8(%ebp),%eax</code> How do I know what %ebp is?</p>
Understanding assembly loop
|assembly|
<h2>Initialization of local variables with movabs</h2> <p>Yes this instruction should move absolute hardcoded data embedded into instruction itself into register, or data from absolute address. But I got into this instruction only recently when I wanted to know where constant data for initialization of local variables are because I didnt find them in <em>.rodata</em> ELF section.</p> <p>So basically GCC uses this instruction to initialize automatic variables on stack!</p> <p>Lets dive into code to find out how this instruction is used. As we see in this code example we have local variable <em>test</em> initialized:</p> <p><a href="https://i.stack.imgur.com/TdZka.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TdZka.png" alt="enter image description here" /></a></p> <p>We know that local variables are put in stack and I was interested to know where and how local variables get initialized.</p> <p>When we dump .text section with objdump we see that this constant <em>0x41414141414141</em> is realy embedded in the code itself:</p> <pre><code>000000000000116c &lt;get_message2&gt;: 116c: f3 0f 1e fa endbr64 1170: 55 push %rbp 1171: 48 89 e5 mov %rsp,%rbp 1174: 48 83 ec 10 sub $0x10,%rsp 1178: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 117f: 00 00 1181: 48 89 45 f8 mov %rax,-0x8(%rbp) 1185: 31 c0 xor %eax,%eax 1187: 48 b8 41 41 41 41 41 movabs $0x41414141414141,%rax 118e: 41 41 00 </code></pre> <hr /> <p>As we see disassembled function and register content from GDB:</p> <p><a href="https://i.stack.imgur.com/exmLP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/exmLP.png" alt="enter image description here" /></a></p> <p>So when we look at code we see that this string <em>test</em>, in HEX notation <em>0x0x41414141414141</em> is hardcoded in <strong>movabs</strong> instruction, and is put in <strong>rax</strong> register, and then content of <strong>rax</strong> register is put on address in <strong>rbp</strong> minus offset 0x10:</p> <pre><code> 0x000055555555517d &lt;+27&gt;: movabs $0x41414141414141,%rax 0x0000555555555187 &lt;+37&gt;: mov %rax,-0x10(%rbp) </code></pre> <p>So this local string will be placed on address <strong>0x7fffffffdde0</strong> - <strong>0x10</strong> We see that this local string is placed in stack frame of function on address <strong>0x7fffffffddd0</strong>, and this we see when we dump the stack:</p> <pre><code>(gdb) x/16gx $sp 0x7fffffffddd0: 0x0041414141414141 0x6a8574f1d6812b00 0x7fffffffdde0: 0x00007fffffffddf0 0x000055555555515b 0x7fffffffddf0: 0x0000000000000001 0x00007ffff7daad90 </code></pre> <p>So we ended with initialized local string on a stack just as we expected.</p>
2627
2013-08-12T16:00:50.820
<p>I just found a strange instruction by assembling (with <code>gas</code>) and disassembling (with <code>objdump</code>) on a <code>amd64</code> architecture.</p> <p>The original <code>amd64</code> assembly code is:</p> <pre><code>mov 0x89abcdef, %al </code></pre> <p>And, after <code>gas</code> compiled it (I am using the following command line: <code>gcc -m64 -march=i686 -c -o myobjectfile myassemblycode.s</code>), <code>objdump</code> gives the following code:</p> <pre><code>a0 df ce ab 89 00 00 movabs 0x89abcdef, %al </code></pre> <p>My problem is that I cannot find any <code>movabs</code>, nor <code>movab</code> in the Intel assembly manual (not even a <code>mova</code> instruction).</p> <p>So, I am dreaming ? What is the meaning of this instruction ? My guess is that it is a quirks from the GNU binutils, but I am not sure of it.</p> <p>PS: I checked precisely the spelling of this instruction, so it is NOT a <code>movaps</code> instruction for sure.</p>
What is the meaning of movabs in gas/x86 AT&T syntax?
|x86|amd64|
<p>You'd be better off using IDC functions like <a href="https://www.hex-rays.com/products/ida/support/idadoc/274.shtml" rel="noreferrer">GetMnem()</a>, <a href="https://www.hex-rays.com/products/ida/support/idadoc/276.shtml" rel="noreferrer">GetOpType()</a>, <a href="https://www.hex-rays.com/products/ida/support/idadoc/277.shtml" rel="noreferrer">GetOperandValue()</a>, etc. to extract IDA's disassembly than exporting to JSON/XML.</p> <p>You can use <a href="https://www.hex-rays.com/products/ida/support/idadoc/417.shtml" rel="noreferrer">command-line switches</a> to run IDA in batch-mode with your IDC script to automate the entire process.</p>
2632
2013-08-12T21:16:13.600
<p>Does anyone know of projects that parse the disassembly from IDA Pro using a lexer and/or parser generator library? But I would also totally be fine with JSON or XML format. So far, I have been able to produce HTML from the GUI, but I am looking for a command line tool that will parse disassembly files produced by IDA Pro. </p>
Parsing IDA Pro .asm files
|disassembly|ida|
<p>In fact, they do not claim at all to evade from any virtual machine. But, by using the MMU fault handler mechanism to perform computation, they expect to render the encapsulation of their program unpractical. Indeed, the point is to find unexpected primitives to perform computation, doing so only a few virtual machine environments will be able handle such specific programs. And, even if they do, a virtual machine is managed by an hypervisor which will probably be overwhelmed by the handling of all the interrupt signals that such a program requires. </p> <p>So, in fact, they propose a way of programming that is as powerful as C (Turing-complete) but that will be extremely tedious to run in a virtualized environment.</p> <p>Of course, the goal of this is to slow down the analysis of the program when run in a virtual machine (this is to be compared to the anti-debug techniques to avoid dynamic analysis).</p>
2640
2013-08-14T14:51:22.127
<p>The <a href="https://github.com/jbangert/trapcc/" rel="noreferrer" title="link">trapcc project</a> on Github by Sergey Bratus and Julian Bangert claims that using the Turing complete capabilities of x86 MMU it is possible for a code to escape the virtual machine using a single instruction (Move, Branch if Zero, Decrement). It does so by page faults and double faults. I tried to read the paper but it seemed too puzzling. Is the idea feasible?</p>
Virtual Machine escape through page faults
|virtual-machines|
<p>At a <em>very</em> high level...</p> <p>Reverse engineering typically focuses on recovering the functional specifications of code.</p> <p>Digital forensics typically focuses on recovering data.</p>
2652
2013-08-17T14:15:30.363
<p>I am not able to understand exact difference in Digital Forensic and Reverse Engineering. Will Digital Forensic has anything to do with decompilation, assembly code reading or debugging?</p>
What is difference between Digital Forensic and Reverse Engineering
|tools|disassembly|decompilation|debuggers|digital-forensics|
<p>All Hex-Rays macros are defined in <strong>&lt;IDA directory&gt;\plugins\defs.h</strong>. It's also available at <a href="https://github.com/nihilus/hexrays_tools/blob/master/code/defs.h" rel="nofollow noreferrer">https://github.com/nihilus/hexrays_tools/blob/master/code/defs.h</a></p> <p>For <code>BYTE3(x)</code>:</p> <pre><code>... #define BYTEn(x, n) (*((_BYTE*)&amp;(x)+n)) ... #define BYTE3(x) BYTEn(x, 3) ... </code></pre> <p>So <code>BYTE3(x)</code> yields <code>(*((_BYTE*)&amp;(x)+3))</code>, which effectively means the fourth byte of the value <code>x</code>.</p>
2657
2013-08-18T10:05:41.350
<p>I've got a program that i'm trying to debug a little bit by trying to make sense of a function or two, there's already some info that i've downloaded via a idb file and it's helped me get somewhere. But i'm kind of stuck on a part where i've got something like this:</p> <pre><code>BYTE3(v1) = 0; </code></pre> <p>This is from the ida hex-rays plugin which has made some nice c-pseudo code for me. I can't double click the function and get it translated in some way so i don't really know how to understand what it does, my guess is that it takes either the third or fourth byte of an int. So my question is, how would i be able to find this function and look at it's disassembly at least if it can't be translated by hex-rays? The signature if that helps at all looks like this according to ida: <code>_BYTE __fastcall(int)</code></p>
BYTE3, does it mean the third or fourth byte of an int? IDB file that's already supplied
|disassembly|ida|c|c++|