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>Fuzzing finds by far the majority of buffer overflows. Reverse engineering can both help the fuzzing and find additional issues on its own. If the fuzzer knows about 'special' values that will cause the code to branch differently or exit parsing earlier without their presence, it can weight the inclusion of those values, guarantee that the input will get past a certain point, or fill in a CRC to always be correct.</p> <p>On it's own, reverse engineering can be very good if you start with an idea of what kind of defect you want to find. For example, if you start with the idea that people who use atoi() will not expect negative numbers, it is easy to find those places in the code and flow forward to see what happens with the data. Another example might be to start with the assumption that memory allocation size could be integer overflowed so, look at each call to the allocation and see if the computation preceding it has the necessary checks. If not, see if the input can influence the allocation to reach a defect.</p> <p>Another way to use reverse engineering is to let someone else do the defect finding for you. Just compare what was patched when the vendor releases an update and you'll see what was repaired.</p> <p>As Jason said, the people writing the malware are not typically the same people that are finding the defects or even developing the exploits.</p>
3212
2013-12-17T09:17:23.577
<p>I hope this question is not OT for RE, but I'm rather curious as to how vulnerabilities are usually found.</p> <p>Of course I'm aware that companies are doing code audits to identify security problems but I doubt that the results of such audits are publicly made available. Another way to find potential attacks is of course thinking about the details of a particular technique and finding its weakness (a timing attack would probably qualify as such).</p> <p>However, in the case of buffer overruns, I'm always wondering how people find out about it. I mean, if there is a release of some software, reversing it and hoping to find a buffer overflow this way seems rather hopeless to me, considering how much work this is. If your software crashes because of some special input, then of course this can be analyzed and might result in a security vulnerability. So are malware author just monitoring various sources (bug reporting site or similar) in the hope of hearing about such cases to look into it? Somehow I can't believe it.</p>
How are vulnerabilities (especially buffer overruns) found in the wild?
|exploit|
<p>The netapi.dll might have loaded the dnsapi.dll in order to do some network inspection, and then freed the DLL on completion. However, the shlwapi.dll might hold some handles to objects open for whatever reason, or have a non-zero reference count because of circular loading, and thus remain in memory even after the other DLLs have unloaded. A request to unload does not guarantee that it will be honored, nor does it prevent the requester from unloading first. user32.dll is another DLL that usually displays this behavior.</p>
3221
2013-12-18T14:02:24.863
<p>Using volatility to inspect a services.exe process in a memory dump, I built a list of dll's that are loaded in the process space. (The modules are from the InLoadOrder module list)</p> <p>This is just an excerpt (full list: <a href="http://pastie.org/8560797">http://pastie.org/8560797</a>):</p> <pre><code>0x5b860000 netapi32.dll FileObject @8a3cb028, Name: \WINDOWS\system32\netapi32.dll 0x77f60000 shlwapi.dll FileObject @8a3e0df0, Name: \WINDOWS\system32\shlwapi.dll </code></pre> <p>As you can see there is a shlwapi.dll loaded in the process.Thanks to DependencyWalker (looking at the imports of services.exe) I found out how shlwapi.dll is loaded. ( -> means imports )</p> <p>netapi.dll -> dnsapi.dll -> iphlpapi.dll -> mprapi.dll -> setupapi.dll -> shlapi.dll </p> <p>But only netapi.dll is loaded. dnsapi.dll is not loaded, there is no entry for it in the InLoadOrder module list, neither is any of the other dlls from the from the above "dependency chain" loaded. </p> <p>This is not only for shlapi.dll but for many other dll's that are loaded as well. For example: shell32.dll, psapi.dll... Neither does this only happen for services.exe process.</p> <p>Any ideas why these dlls are loaded into the process?</p> <p>Any help is most appreciated, regards!</p>
Modules that exist in a process address space
|windows|memory|digital-forensics|
<p>From what I remember, both XP and Win7 always had this format:</p> <p><code>object_directory_followed</code> by <code>object_header</code> whose <code>_QUAD</code> part (opaque do not use this field) points to the <code>OBJECT</code></p> <p>If you did <code>dt nt!_Object_header_name_info &lt;address of object&gt; - 0x28</code>:</p> <pre><code>kd&gt; !devobj \Device\Beep;dt nt!_OBJECT_HEADER_NAME_INFO 86884db8-28 Device object (86884db8) is for: Beep \Driver\Beep DriverObject 86e703b8 Current Irp 00000000 RefCount 0 Type 00000001 Flags 00000044 Dacl e1020c34 DevExt 86884e70 DevObjExt 86884ec8 ExtensionFlags (0000000000) Device queue is not busy. +0x000 Directory : 0xe100d670 _OBJECT_DIRECTORY +0x004 Name : _UNICODE_STRING "Beep" +0x00c QueryReferences : 1 kd&gt; !devobj \Device\00000013 Device object (86fe7cd0) is for: 00000013 \Driver\PnpManager DriverObject 86fe9328 Current Irp 00000000 RefCount 0 Type 00000004 Flags 00001040 Dacl e1020c34 DevExt 86fe7d88 DevObjExt 86fe7d90 DevNode 86fe7b88 ExtensionFlags (0x00000010) DOE_START_PENDING Device queue is not busy. kd&gt; dt nt!_OBJECT_HEADER_NAME_INFO 86fe7cd0-28 +0x000 Directory : 0xe100d670 _OBJECT_DIRECTORY +0x004 Name : _UNICODE_STRING "00000013" +0x00c QueryReferences : 1 </code></pre>
3233
2013-12-20T16:13:34.177
<p>I'm using WinDbg to try enumerate drivers and their associated devices. Getting the driver name is very easy. It is found in the <a href="http://msdn.moonsols.com/win7rtm_x86/DRIVER_OBJECT.html" rel="nofollow">_DRIVER_OBJECT</a> structure. Unfortunately, the <a href="http://msdn.moonsols.com/win7rtm_x86/DEVICE_OBJECT.html" rel="nofollow">_DEVICE_OBJECT</a> does not contain the name of the device. </p> <p>Using the <code>!devobj</code> command I can see the name of the device, but I would like to find the table/structure that contains the name.</p>
Find the kernel structure that contains device name
|windows|windbg|kernel-mode|
<p>Since it uses HID class, you should probably check the <a href="http://www.usb.org/developers/devclass_docs/HID1_11.pdf" rel="nofollow">USB HID Spec</a> from USB.org. The relevant part seems to be the section 8, "Report Protocol":</p> <blockquote> <h1>8.1 Report Types</h1> <p>Reports contain data from one or more items. Data transfers are sent from the device to the host through the <strong>Interrupt In</strong> pipe in the form of reports. Reports may also be requested (polled) and sent through the Control pipe or sent through an optional <strong>Interrupt Out</strong> pipe. A report contains the state of all the items (Input, Output or Feature) belonging to a particular Report ID. The software application is responsible for extracting the individual items from the report based on the Report descriptor.</p> </blockquote> <p><code>Ii</code> in the usbmon log refer to "Interrupt In", so these are "reports" from the device. Looks like the changing bytes in the data packets (such as 22, 27, 1e, 1f) correspond to keyboard keys. It seems that to figure out the mapping you need to parse the "Report Descriptor", which can be done by <code>lsusb</code> if you <a href="http://libusb.6.n5.nabble.com/How-to-dump-HID-report-descriptor-under-Linux-td5971.html" rel="nofollow">first detach the default driver</a>.</p>
3237
2013-12-20T22:17:39.027
<p>I have a Magtek magstripe card reader. Here's more information than you'd ever want about the device:</p> <pre><code># lsusb -v Bus 001 Device 003: ID 0801:0001 MagTek Mini Swipe Reader (Keyboard Emulation) Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 1.10 bDeviceClass 0 (Defined at Interface level) bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 64 idVendor 0x0801 MagTek idProduct 0x0001 Mini Swipe Reader (Keyboard Emulation) bcdDevice 1.00 iManufacturer 1 (error) iProduct 2 (error) iSerial 3 (error) bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 34 bNumInterfaces 1 bConfigurationValue 1 iConfiguration 0 bmAttributes 0x80 (Bus Powered) MaxPower 100mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 3 Human Interface Device bInterfaceSubClass 1 Boot Interface Subclass bInterfaceProtocol 1 Keyboard iInterface 0 HID Device Descriptor: bLength 9 bDescriptorType 33 bcdHID 1.01 bCountryCode 0 Not supported bNumDescriptors 1 bDescriptorType 34 Report wDescriptorLength 76 Report Descriptors: ** UNAVAILABLE ** Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0008 1x 8 bytes bInterval 1 Device Status: 0x0000 (Bus Powered) </code></pre> <p>This is a USB keyboard emulation device, so when you swipe a card, the data on tracks 1 and 2 are typed on the screen into whatever program you have open at the time.</p> <p>I'm trying to learn about USB reverse engineering, so I'm trying to understand how this device sends data to my computer. After swiping a card and seeing the data on the screen, I try to find that data in the USB requests that go back and forth between my computer and the device. To do this, I use <a href="https://www.kernel.org/doc/Documentation/usb/usbmon.txt" rel="nofollow">usbmon</a>:</p> <pre><code># cat /sys/kernel/debug/usb/usbmon/1u </code></pre> <p>I've read up on the output of <code>usbmon</code> and I've also tried looking at the data using <a href="http://vusb-analyzer.sourceforge.net/" rel="nofollow">vusb-analyzer</a>, but I can't find any of the data I expect to see in the data stream.</p> <p>Here is an example of the output on the screen and the output from <code>usbmon</code> after swiping an old (inactive) ID card from Oakland University.</p> <p>Output on screen:</p> <pre><code>%000127138,6361380000058657,SINGH,?;6361380000058657=123456789012?+000127138? </code></pre> <p>Usbmon Output:</p> <pre><code>ffff88008954e900 3348888805 C Ii:1:003:1 0:1 8 = 02002200 00000000 ffff88008954e900 3348888878 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348889671 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348889709 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348890693 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3348890719 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348892689 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348892712 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348893689 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3348893714 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348894689 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348894714 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348895688 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3348895713 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348896662 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348896686 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348897689 C Ii:1:003:1 0:1 8 = 00001e00 00000000 ffff88008954e900 3348897714 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348898690 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348898715 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348899686 C Ii:1:003:1 0:1 8 = 00001f00 00000000 ffff88008954e900 3348899709 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348900687 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348900710 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348901692 C Ii:1:003:1 0:1 8 = 00002400 00000000 ffff88008954e900 3348901716 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348902689 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348902710 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348903689 C Ii:1:003:1 0:1 8 = 00001e00 00000000 ffff88008954e900 3348903711 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348904691 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348904713 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348905692 C Ii:1:003:1 0:1 8 = 00002000 00000000 ffff88008954e900 3348905719 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348906665 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348906697 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348907696 C Ii:1:003:1 0:1 8 = 00002500 00000000 ffff88008954e900 3348907726 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348908687 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348908716 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348909688 C Ii:1:003:1 0:1 8 = 00003600 00000000 ffff88008954e900 3348909717 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348910688 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348910717 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348911688 C Ii:1:003:1 0:1 8 = 00002300 00000000 ffff88008954e900 3348911717 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348912687 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348912705 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348913687 C Ii:1:003:1 0:1 8 = 00002000 00000000 ffff88008954e900 3348913706 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348914688 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348914706 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348915686 C Ii:1:003:1 0:1 8 = 00002300 00000000 ffff88008954e900 3348915705 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348916688 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348916715 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348917691 C Ii:1:003:1 0:1 8 = 00001e00 00000000 ffff88008954e900 3348917718 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348918691 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348918717 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348919690 C Ii:1:003:1 0:1 8 = 00002000 00000000 ffff88008954e900 3348919717 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348920694 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348920718 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348921693 C Ii:1:003:1 0:1 8 = 00002500 00000000 ffff88008954e900 3348921716 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348922663 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348922679 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348923692 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3348923721 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348924659 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348924678 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348925660 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3348925675 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348926659 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348926674 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348927662 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3348927680 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348928675 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348928701 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348929688 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3348929714 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348930687 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348930713 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348931688 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3348931715 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348932689 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348932720 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348933677 C Ii:1:003:1 0:1 8 = 00002200 00000000 ffff88008954e900 3348933690 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348934676 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348934687 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348935680 C Ii:1:003:1 0:1 8 = 00002500 00000000 ffff88008954e900 3348935692 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348936664 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348936675 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348937663 C Ii:1:003:1 0:1 8 = 00002300 00000000 ffff88008954e900 3348937674 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348938664 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348938676 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348939664 C Ii:1:003:1 0:1 8 = 00002200 00000000 ffff88008954e900 3348939674 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348940661 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348940671 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348941660 C Ii:1:003:1 0:1 8 = 00002400 00000000 ffff88008954e900 3348941670 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348942661 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348942670 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348943673 C Ii:1:003:1 0:1 8 = 00003600 00000000 ffff88008954e900 3348943685 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348944676 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348944700 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348945675 C Ii:1:003:1 0:1 8 = 02001600 00000000 ffff88008954e900 3348945687 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348946661 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348946672 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348947661 C Ii:1:003:1 0:1 8 = 02000c00 00000000 ffff88008954e900 3348947673 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348948661 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348948672 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348949664 C Ii:1:003:1 0:1 8 = 02001100 00000000 ffff88008954e900 3348949677 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348950665 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348950676 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348951666 C Ii:1:003:1 0:1 8 = 02000a00 00000000 ffff88008954e900 3348951677 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348952666 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348952677 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348953666 C Ii:1:003:1 0:1 8 = 02000b00 00000000 ffff88008954e900 3348953678 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348954665 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348954677 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348956665 C Ii:1:003:1 0:1 8 = 00003600 00000000 ffff88008954e900 3348956680 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348957680 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348957696 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348958677 C Ii:1:003:1 0:1 8 = 02003800 00000000 ffff88008954e900 3348958692 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348959663 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348959678 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348960663 C Ii:1:003:1 0:1 8 = 00003300 00000000 ffff88008954e900 3348960674 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348961669 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348961699 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348962670 C Ii:1:003:1 0:1 8 = 00002300 00000000 ffff88008954e900 3348962697 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348963663 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348963678 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348964664 C Ii:1:003:1 0:1 8 = 00002000 00000000 ffff88008954e900 3348964676 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348965667 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348965678 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348966667 C Ii:1:003:1 0:1 8 = 00002300 00000000 ffff88008954e900 3348966678 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348967671 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348967681 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348968674 C Ii:1:003:1 0:1 8 = 00001e00 00000000 ffff88008954e900 3348968703 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348969673 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348969701 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348970670 C Ii:1:003:1 0:1 8 = 00002000 00000000 ffff88008954e900 3348970697 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348971672 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348971698 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348972676 C Ii:1:003:1 0:1 8 = 00002500 00000000 ffff88008954e900 3348972705 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348973678 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348973688 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348974668 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3348974694 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348975669 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348975695 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348976667 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3348976695 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348977670 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348977700 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348978669 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3348978695 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348979670 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348979699 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348980669 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3348980694 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348981674 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348981702 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348982678 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3348982704 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348983687 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348983714 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348984682 C Ii:1:003:1 0:1 8 = 00002200 00000000 ffff88008954e900 3348984709 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348985675 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348985702 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348986679 C Ii:1:003:1 0:1 8 = 00002500 00000000 ffff88008954e900 3348986707 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348987682 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348987712 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348988685 C Ii:1:003:1 0:1 8 = 00002300 00000000 ffff88008954e900 3348988714 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348989679 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348989707 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348990678 C Ii:1:003:1 0:1 8 = 00002200 00000000 ffff88008954e900 3348990706 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348991686 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348991715 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348992686 C Ii:1:003:1 0:1 8 = 00002400 00000000 ffff88008954e900 3348992714 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348993681 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348993690 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348994667 C Ii:1:003:1 0:1 8 = 00002e00 00000000 ffff88008954e900 3348994692 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348995668 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348995684 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348996668 C Ii:1:003:1 0:1 8 = 00001e00 00000000 ffff88008954e900 3348996682 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348997670 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348997684 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348998713 C Ii:1:003:1 0:1 8 = 00001f00 00000000 ffff88008954e900 3348998750 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3348999678 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3348999709 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349000690 C Ii:1:003:1 0:1 8 = 00002000 00000000 ffff88008954e900 3349000721 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349001690 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349001721 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349002689 C Ii:1:003:1 0:1 8 = 00002100 00000000 ffff88008954e900 3349002720 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349003692 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349003724 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349004687 C Ii:1:003:1 0:1 8 = 00002200 00000000 ffff88008954e900 3349004717 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349005688 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349005718 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349006687 C Ii:1:003:1 0:1 8 = 00002300 00000000 ffff88008954e900 3349006717 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349007675 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349007701 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349008687 C Ii:1:003:1 0:1 8 = 00002400 00000000 ffff88008954e900 3349008715 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349009682 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349009712 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349010681 C Ii:1:003:1 0:1 8 = 00002500 00000000 ffff88008954e900 3349010711 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349011681 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349011710 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349012690 C Ii:1:003:1 0:1 8 = 00002600 00000000 ffff88008954e900 3349012719 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349013673 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349013682 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349014697 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3349014727 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349015678 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349015706 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349016692 C Ii:1:003:1 0:1 8 = 00001e00 00000000 ffff88008954e900 3349016721 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349017699 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349017727 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349018679 C Ii:1:003:1 0:1 8 = 00001f00 00000000 ffff88008954e900 3349018706 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349020676 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349020703 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349021688 C Ii:1:003:1 0:1 8 = 02003800 00000000 ffff88008954e900 3349021720 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349022673 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349022683 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349023676 C Ii:1:003:1 0:1 8 = 02002e00 00000000 ffff88008954e900 3349023706 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349024670 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349024680 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349025670 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3349025680 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349026671 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349026679 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349027670 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3349027678 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349028677 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349028705 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349029681 C Ii:1:003:1 0:1 8 = 00002700 00000000 ffff88008954e900 3349029707 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349030680 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349030706 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349031693 C Ii:1:003:1 0:1 8 = 00001e00 00000000 ffff88008954e900 3349031721 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349032680 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349032707 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349033685 C Ii:1:003:1 0:1 8 = 00001f00 00000000 ffff88008954e900 3349033713 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349034681 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349034707 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349035679 C Ii:1:003:1 0:1 8 = 00002400 00000000 ffff88008954e900 3349035706 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349036676 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349036703 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349037690 C Ii:1:003:1 0:1 8 = 00001e00 00000000 ffff88008954e900 3349037718 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349038677 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349038703 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349039691 C Ii:1:003:1 0:1 8 = 00002000 00000000 ffff88008954e900 3349039719 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349040677 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349040704 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349041692 C Ii:1:003:1 0:1 8 = 00002500 00000000 ffff88008954e900 3349041720 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349042677 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349042704 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349043690 C Ii:1:003:1 0:1 8 = 02003800 00000000 ffff88008954e900 3349043721 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349044684 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349044698 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349045681 C Ii:1:003:1 0:1 8 = 00005800 00000000 ffff88008954e900 3349045710 S Ii:1:003:1 -115:1 8 &lt; ffff88008954e900 3349046682 C Ii:1:003:1 0:1 8 = 00000000 00000000 ffff88008954e900 3349046709 S Ii:1:003:1 -115:1 8 &lt; </code></pre> <p>As you can see, the characters 'SINGH' (my last name) appear in the on-screen output, but I can't find those ASCII values anywhere in the data. How should I go about reverse engineering this device?</p> <p><strong>EDIT:</strong> Thanks to Igor's answer I got the Report Descriptors, but I'm not quite sure how to make use of them:</p> <pre><code> Report Descriptor: (length is 76) Item(Global): Usage Page, data= [ 0x01 ] 1 Generic Desktop Controls Item(Local ): Usage, data= [ 0x06 ] 6 Keyboard Item(Main ): Collection, data= [ 0x01 ] 1 Application Item(Global): Usage Page, data= [ 0x07 ] 7 Keyboard Item(Local ): Usage Minimum, data= [ 0xe0 ] 224 Control Left Item(Local ): Usage Maximum, data= [ 0xe7 ] 231 GUI Right Item(Global): Logical Minimum, data= [ 0x00 ] 0 Item(Global): Logical Maximum, data= [ 0x01 ] 1 Item(Global): Report Size, data= [ 0x01 ] 1 Item(Global): Report Count, data= [ 0x08 ] 8 Item(Main ): Input, data= [ 0x02 ] 2 Data Variable Absolute No_Wrap Linear Preferred_State No_Null_Position Non_Volatile Bitfield Item(Global): Report Count, data= [ 0x01 ] 1 Item(Global): Report Size, data= [ 0x08 ] 8 Item(Main ): Input, data= [ 0x03 ] 3 Constant Variable Absolute No_Wrap Linear Preferred_State No_Null_Position Non_Volatile Bitfield Item(Global): Report Count, data= [ 0x05 ] 5 Item(Global): Report Size, data= [ 0x01 ] 1 Item(Global): Usage Page, data= [ 0x08 ] 8 LEDs Item(Local ): Usage Minimum, data= [ 0x01 ] 1 NumLock Item(Local ): Usage Maximum, data= [ 0x05 ] 5 Kana Item(Main ): Output, data= [ 0x02 ] 2 Data Variable Absolute No_Wrap Linear Preferred_State No_Null_Position Non_Volatile Bitfield Item(Global): Report Count, data= [ 0x01 ] 1 Item(Global): Report Size, data= [ 0x03 ] 3 Item(Main ): Output, data= [ 0x03 ] 3 Constant Variable Absolute No_Wrap Linear Preferred_State No_Null_Position Non_Volatile Bitfield Item(Global): Report Count, data= [ 0x06 ] 6 Item(Global): Report Size, data= [ 0x08 ] 8 Item(Global): Logical Minimum, data= [ 0x00 ] 0 Item(Global): Logical Maximum, data= [ 0x66 ] 102 Item(Global): Usage Page, data= [ 0x07 ] 7 Keyboard Item(Local ): Usage Minimum, data= [ 0x00 ] 0 No Event Item(Local ): Usage Maximum, data= [ 0x66 ] 102 Power (not a key) Item(Main ): Input, data= [ 0x00 ] 0 Data Array Absolute No_Wrap Linear Preferred_State No_Null_Position Non_Volatile Bitfield Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255 Item(Global): Usage Page, data= [ 0x00 0xff ] 65280 (null) Item(Local ): Usage, data= [ 0x20 ] 32 (null) Item(Global): Report Count, data= [ 0x18 ] 24 Item(Main ): Feature, data= [ 0x02 0x01 ] 258 Data Variable Absolute No_Wrap Linear Preferred_State No_Null_Position Non_Volatile Buffered Bytes Item(Main ): End Collection, data=none </code></pre>
Reverse engineering a USB magstripe card reader
|usb|
<p>When I started with Malware Analyses at some anti-virus vendor. I only had reversed a couple of aspects of video games and created a number of tools to extract graphics etc. I also knew a fair bit of malware culture etc.. Read a lot of Malware source code (vxheavens) and all that jazz.</p> <p>I however, didn't know about Obfuscation, unpacking, shellcode etc. This is something I learned over the course of a few years while on the job.</p> <p>However, a SOLID understanding of x86 and your debugging / dis-assembler is required!</p>
3261
2013-12-22T16:17:18.743
<p>I am a C/C++ developer and I have started learning assembly language programming with the goal to become a malware analyst. </p> <p>I know it is not enough to just know how to read assembly to become a malware analyst. But won't it help a lot and make the remaining things easier?</p>
Is learning assembly enough to become a malware analyst?
|malware|assembly|binary-analysis|vulnerability-analysis|
<p>Standard exploitation of SEH based BoF will try to point the SE Handler to a POP/POP/RET instruction. This is not always the case depending on enabled memory protections. (use Mona plugin for Immunity to check this using the command <code>!mona mod</code>, or simply inspect the vulnerable binary characteristics)</p> <p>If your SE Handler is pointing to <code>0x384c5c36</code>, you should put a break point at that address and hit <kbd>Shift</kbd>+<kbd>F9</kbd> to continue execution up to your breakpoint.</p> <p>The rest will greatly vary on the nature of the exploit and the kind of limitations it has to bypass. As it an image viewer, I doubt the exploit will use any techniques like heap spraying as it can execute any code that will spray the heap, like JavaScript, but you never know.</p> <p>For more information on SEH based overflows, I would strongly recommend the <a href="https://www.corelan.be/index.php/2009/07/25/writing-buffer-overflow-exploits-a-quick-and-basic-tutorial-part-3-seh/" rel="nofollow">Corelan Tutorial</a>.</p>
3277
2013-12-25T01:56:13.093
<p>I recently acquired an exploit for an image viewer program and started analyzing.</p> <p>Specific details cannot be given, but basically it is a SEH overwrite exploit using malicious image file. </p> <p>Using immunity dbg, I saw that SEH being overwritten by 38 4c 5c 36. But dbg fails to execute that memory address. </p> <p>Exploit executes calc just fine, but by attaching a debugger to the viewer program, it hangs trying to execute 38 4c 5c 36.</p> <p>I tried to jump to that address but dbg says it is a unspecified address. I have a few questions about this memory address</p> <ol> <li><p>what kind of data is loaded in memory address near 38 4c 5c 36 ? (looking at the memory map it is between loaded dll files and nothing is loaded it seems)</p></li> <li><p>is 38 4c 5c 36 where the exploit is loaded in the memory or am I making a wrong guess?</p></li> <li><p>If it is where exploit is loaded, what should I do to further analyze using a debugger?</p></li> </ol> <p>Thank you in advance :)</p>
Need help analyzing an image viewer exploit
|exploit|seh|
<p>open calc.exe in ollydbg <code>c:\ollydbg.exe calc.exe</code><br> press <code>Ctrl + G and type GetMessageW</code><br> press <code>F2</code> to set a breakpoint and press <code>F9</code> until it breaks<br> when it is broken press <code>ctrl+f9</code> to run until return<br> press <code>shift+f4</code> to set a conditional log breakpoint<br> in the expression edit box type <code>[esp+4]</code><br> in the decode value of expression <code>select pointer to MSG structure (UNICODE)</code><br> set radio button pause to <code>never</code><br> set radio button log expression to <code>Always</code><br> hit <code>ok</code><br> now look at log window for all the messages that are handled<br> refine your conditional breakpoint to handle only the cases you want to examine for example this condition will log only mouseup and wm_char messages</p> <pre><code>Breakpoints, item 1 Address=7E41920E Module=USER32 Active=Log when [[esp+4]+4] == WM_KEYDOWN || [[esp+4]+4] == WM_LBUTTONUP Disassembly=RETN 10 </code></pre> <p>like results posted below notice the hwnd for each button you can refine to a multiple condition with a specifc Window Handle hWnd 2e048a etc</p> <pre><code>\Log data Message COND: 0007FEE8 WM_LBUTTONUP hw = 2E048A ("C") Keys = 0 X = 57. Y = 14. COND: 0007FEE8 WM_LBUTTONUP hw = 10053E ("And") Keys = 0 X = 22. Y = 10. COND: 0007FEE8 WM_LBUTTONUP hw = 200404 ("Xor") Keys = 0 X = 22. Y = 18. COND: 0007FEE8 WM_LBUTTONUP hw = 270402 ("M+") Keys = 0 X = 22. Y = 11. COND: 0007FEE8 WM_LBUTTONUP hw = D036A ("Sta") Keys = 0 X = 27. Y = 15. COND: 0007FEE8 WM_LBUTTONUP hw = 1B04F0 ("x^2") Keys = 0 X = 18. Y = 17. COND: 0007FEE8 WM_KEYDOWN hw = 1B04F0 ("x^2") Key = 35 ('5') KeyData = 60001 COND: 0007FEE8 WM_KEYDOWN hw = 4303EC (class="Edit") Key = 42 ('B') KeyData = 300001 COND: 0007FEE8 WM_KEYDOWN hw = 4303EC (class="Edit") Key = 41 ('A') KeyData = 1E0001 </code></pre> <p>to simulate same in windbg put this commands in a txt file and run windbg (you should have skywings sdbgext extension loaded for verbose display )</p> <pre><code>bp user32!GetMessageW "pt;gc" g bc * .load sdbgext bp @eip ".if (poi(poi(esp+4)+4) == 0x202) {!hwnd poi(poi(esp+4));gc } .else {gc}" g windbg -c "$$&gt;a&lt; ......\wtf.txt" calc Window 00600438 Name And Class Button WndProc 00000000 Style WS_OVERLAPPED ExStyle WS_EX_NOPARENTNOTIFY WS_EX_LEFT WS_EX_LTRREADING WS_EX_RIGHTSCROLLBAR HInstance 01000000 ParentWnd 00490534 Id 00000056 UserData 00000000 Unicode TRUE ThreadId 00000df0 ProcessId 00000f68 Window 00150436 Name Xor Class Button WndProc 00000000 Style WS_OVERLAPPED </code></pre>
3288
2013-12-26T09:46:38.627
<p>I am trying to find what a button does, so I want to set a breakpoint to catch button click event. Is that possible?</p> <p>Any tools or tricks to assist in this?</p>
How can I set a breakpoint for a button click?
|windows|ollydbg|
<p>It is an encrypted firmware of the GBR2851T Freeview HD Digital Receiver, so you cannot extract it without the proper encryption key.<br> If you are interested in i-CAN (ADB) internals, see the following vulnerability report <a href="http://www.security-explorations.com/materials/se-2011-01-adb.pdf" rel="nofollow">http://www.security-explorations.com/materials/se-2011-01-adb.pdf</a>.</p>
3296
2013-12-27T11:34:58.947
<p>I need extract this firmware file. I tried <code>firmwaremodkit</code> and <code>binwalk</code>. It founds two trx headers, but cannot open it.( delete start in hexedit and untrx throws segfault, fmk found nothing)... </p> <p>Interesting is the constant repetition of the sequence: 00 00 11 53 48 44 52</p> <p>Some tips how extract it?</p> <p><a href="http://uloz.to/xY4X3cPh/download-dwn" rel="nofollow">http://uloz.to/xY4X3cPh/download-dwn</a></p>
How extract this firmware file?
|firmware|
<p>ollydbg command line plugin accepts <code>BP for Address</code> and <code>BPX for labels</code></p> <p>so if you require that breakpoint be set in Address use <code>bp CreateWindowExW</code></p> <p>if you used bpx and no calls existed plugin will open a search for intermodular calls window for you to manually search for the interested api</p> <p>if you have a call like this</p> <pre><code>010020ED FF15 A4110001 CALL NEAR DWORD PTR DS:[&lt;&amp;USER32.CreateWindow&gt;; USER32.CreateWindowExW </code></pre> <p>plugin will set a break on this call with BPX style for bp style you would need to use <code>bp 10020ED</code></p>
3305
2013-12-28T19:51:11.293
<p>I attached Ollydbg to a process, and try to set breakpoint on <code>CreateWindowExW</code>. I typed</p> <pre><code>bpx CreateWindowExW </code></pre> <p>in command line. Then I checked the Breakpoints window and found it's totally empty.</p> <p>The same thing works smoothly in IDA pro -- I attached IDA pro to the process I'm going to debug, then in "Modules" window, I choose <code>user32.dll</code> and right click on <code>CreateWindowExW</code> and choose "Add breakpoint".</p> <p>Actually, I found setting breakpoint on Win32 API in Ollydbg is very very hard to use. Based on all information I got by Google, I only need to run <code>bpx xxxxx</code> to set this kind of breakpoints, but in fact, it's rarely success. Most of time, no breakpoints were set by this.</p> <p>Did I miss something?</p> <p>BTW: The process I debugged loaded a lot of DLLs dynamically. Is this the problem?</p>
Setting breakpoint on Win32 API does not work in Ollydbg
|ollydbg|
<p>You can save the graph as a .gdl file. You can then use <a href="http://search.cpan.org/~tels/Graph-Easy/bin/graph-easy" rel="noreferrer">graph-easy</a> to convert the GDL file to an image file such as SVG, PNG, JPG etc.</p> <pre><code>graph-easy --from gdl --input=graph.gdl --png --output=graph.png </code></pre>
3322
2013-12-29T23:33:04.030
<p>How Can I save <code>IDA Pro</code>'s normal graph view as image?<br> Is there any tool or plugin for that?</p>
Saving IDA graphs as image
|ida|ida-plugin|
<p>Fooling <code>upx -d</code> can be as simple as one byte patch here is a small sample.</p> <p>Pack the MS-Windows standard <code>calc.exe</code>, hexedit one byte and result is an undepackable executable with <code>upx -d</code> (this is <strong>not</strong> <code>corrupting</code> the exe, the exe will run and can be unpacked manually). Only unpacking with the <code>-d</code> switch wont work.</p> <ol> <li><p>create a new folder <code>foolupx</code>:</p> <pre><code> foolupx:\&gt;md foolupx </code></pre> </li> <li><p>copy <code>calc.exe</code> to the newly created folder:</p> <pre><code> foolupx:\&gt;copy c:\WINDOWS\system32\calc.exe foolupx\upxedcalc.exe 1 file(s) copied. </code></pre> </li> <li><p>pack the renamed <code>calc.exe</code>:</p> <pre><code> foolupx:\&gt;upx .\foolupx\upxedcalc.exe Ultimate Packer for eXecutables Copyright (C) 1996 - 2011 UPX 3.08w Markus Oberhumer, Laszlo Molnar &amp; John Reiser Dec 12th 2011 File size Ratio Format Name -------------------- ------ ----------- ----------- 114688 -&gt; 56832 49.55% win32/pe upxedcalc.exe Packed 1 file. </code></pre> </li> <li><p>Create a duplicate of the packed <code>calc.exe</code> for hexediting and compare the files. The difference is one byte in the PE header section named <code>UPX0</code> changed to <code>BPX0</code>:</p> <pre><code> foolupx:\&gt;copy .\foolupx\upxedcalc.exe .\foolupx\modupxedcalc.exe 1 file(s) copied. foolupx:\&gt;fc .\foolupx\upxedcalc.exe .\foolupx\modupxedcalc.exe Comparing files .\FOOLUPX\upxedcalc.exe and .\FOOLUPX\MODUPXEDCALC.EXE 000001E8: 55 42 </code></pre> </li> <li><p>Uncompress both files with the <code>-d</code> switch. One will be unpacked, the other will not be unpacked:</p> <pre><code> foolupx:\&gt;upx -d .\foolupx\modupxedcalc.exe Ultimate Packer for eXecutables Copyright (C) 1996 - 2011 UPX 3.08w Markus Oberhumer, Laszlo Molnar &amp; John Reiser Dec 12th 2011 File size Ratio Format Name -------------------- ------ ----------- ----------- upx: .\foolupx\modupxedcalc.exe: CantUnpackException: file is modified/hacked/protected; take care!!! Unpacked 0 files. foolupx:\&gt;upx -d .\foolupx\upxedcalc.exe Ultimate Packer for eXecutables Copyright (C) 1996 - 2011 UPX 3.08w Markus Oberhumer, Laszlo Molnar &amp; John Reiser Dec 12th 2011 File size Ratio Format Name -------------------- ------ ----------- ----------- 114688 &lt;- 56832 49.55% win32/pe upxedcalc.exe Unpacked 1 file. foolupx:\&gt; </code></pre> </li> </ol>
3323
2013-12-30T11:04:58.020
<p>I recently read a <a href="https://twitter.com/corkami/status/417604202236350464/photo/1" rel="noreferrer">tweet</a> from <a href="https://reverseengineering.stackexchange.com/users/188/ange">Ange</a> about a technique to fool UPX when the option <code>-d</code> (decompress) is called.</p> <p>I would like to know how this is working and, what are the technique to prevent an UPX packed executable to be decompressed through <code>upx -d</code> (if possible for, both, Linux and Windows).</p>
How to prevent "upx -d" on an UPX packed executable?
|packers|upx|
<p>With the now free <a href="https://www.zynamics.com/software.html" rel="nofollow">BinDiff 4.2</a> you can do batch analysis with a bit of work.</p> <p>In the BinDiff installation directory (<code>zynamics/BinDiff 4.2</code>), you will find <code>bin/differ.exe</code> and <code>bin/differ64.exe</code>. Those are binaries for batch diffing of IDBs and <code>.BinExport</code> files.</p> <p>The basic usage would be:</p> <pre><code>differ --primary=&lt;directory-with-IDBs&gt; --output-dir=&lt;output-directory&gt; </code></pre> <p>Sadly, this does not work (at least on my machine) as <code>differ.exe</code> fails to find IDA's executable and tries to execute the directory instead.</p> <p>To solve this, we will export IDBs using the following command:</p> <pre><code>"&lt;path-to-idaq.exe&gt;" -A -OExporterModule:&lt;result-directory&gt; -S"&lt;path-to-export-script&gt;" "&lt;path-to-idb&gt;" </code></pre> <p>The <code>export-script</code> is an <code>.idc</code> with the following code:</p> <pre><code>#include &lt;idc.idc&gt; static main() { Batch(0); Wait(); Exit(1 - RunPlugin("zynamics_binexport_8", 2)); } </code></pre> <p>Once you have all your <code>.BinExport</code> files in one directory, run the original <code>differ.exe</code> command on that directory (give it the directory with the <code>.BinExport</code> files instead of the <code>.idb</code> files), and you'll get <code>.BinDiff</code> files for all possible diffs. Those can either be opened up in IDA, or manually parsed (they are SQLite databases).</p>
3327
2013-12-30T17:38:03.020
<p>I have been trying to use IDA Pro (with bindiff) via IDAPython to automate the analysis process of a bios.dump file while outputting the results to a .txt / .asm file. From here I want to use the bindiff functions to compare this database with another database and output any differences to a file. Any recommendations? </p>
IDA Pro/IDAPython automation through IDAPython
|ida|idapython|ida-plugin|bin-diffing|tool-bindiff|
<p>This feature is supported since Hex-Rays 1.6:</p> <p><a href="http://www.hexblog.com/?p=544" rel="noreferrer">http://www.hexblog.com/?p=544</a></p> <p>(see section 3. CONTAINING_RECORD macro)</p>
3331
2013-12-31T02:29:55.723
<p>How do I fix structures in IDA PRO so they show up properly in Hex-Rays plugin (C decompiler).</p> <p>Similar question to: (But the solution doesn't work for me)<br> <a href="https://reverseengineering.stackexchange.com/questions/2991/struct-with-negative-offset-in-ida-possible">Struct with negative offset in IDA possible</a></p> <p>Pretty much what happened is I compiled a very good program and it works right, after that I did many changes to it and now it works worse then the older version, I'm trying to figure out what I did wrong (since I lost the source code now) to revert back to the old version. (I also added below the original piece of the code written in C++, which didn't change between both versions).</p> <p>Structure's addresses somehow optimized in IDA PRO Such as that</p> <pre><code>*(_BYTE *)(shipsStruct + 279) = 1; //Ships[i].used = true; </code></pre> <p>should really be <code>[10x4]=40+255= 295</code></p> <pre><code>*(_BYTE *)(shipsStruct + 295) = 1; //Ships[i].used = true; </code></pre> <p>You can tell the structure size right here (<code>shipsStruct += 296;</code>)</p> <p>I'm guessing somehow the un-used structure members are stripped out (but why is the structure size valid?).<br> Seems the assembly somehow is offset wrongly (how do I add the proper offset deltas to the struct to fix this)?</p> <p>When I try this tip <a href="http://www.hexblog.com/?p=63" rel="nofollow noreferrer">http://www.hexblog.com/?p=63</a> My whole IDA PRO freezes up when I select the line <code>mov edi, offset dword_10004C38</code> and press T (IDA PRO 6.1)</p> <p><img src="https://i.stack.imgur.com/GBJzX.png" alt="structoffset"></p> <p>Seems I made my struct incorrectly?<br></p> <p>Here is how the code decompiled code looks like (without applying structure)</p> <pre><code> if ( playerListBaseAddress &amp;&amp; !IsBadReadPtr(playerListBaseAddress, 4u) ) { shipsStruct = (int)dword_10004C38; while ( 1 ) { playerPointer = (struct_v3 *)*((_DWORD *)playerListBaseAddress + maxPlayers); if ( !playerPointer ) break; if ( IsBadReadPtr(playerPointer, 4u) ) break; *(_DWORD *)(shipsStruct - 4) = playerPointer-&gt;ssXCoord; *(_DWORD *)shipsStruct = playerPointer-&gt;ssYCoord; *(_DWORD *)(shipsStruct + 4) = playerPointer-&gt;ssXSpeed; *(_DWORD *)(shipsStruct + 8) = playerPointer-&gt;ssYSpeed; *(_DWORD *)(shipsStruct - 8) = playerPointer-&gt;ssFreq; *(_DWORD *)(shipsStruct + 20) = playerPointer-&gt;ssShipNum; if ( playerPointer-&gt;ssPlayerName ) strcpy_s((char *)(shipsStruct + 24), 0xFFu, &amp;playerPointer-&gt;ssPlayerName); *(_BYTE *)(shipsStruct + 279) = 1; if ( v37 == playerPointer ) break; shipsStruct += 296; ++maxPlayers; v37 = playerPointer; if ( shipsStruct &gt;= (signed int)&amp;unk_10017310 ) goto finish; } v34 = maxPlayers; if ( maxPlayers &lt; 255 ) { v4 = (int)((char *)&amp;unk_10004D4F + 296 * maxPlayers); do { *(_BYTE *)v4 = 0; v4 += 296; } while ( v4 &lt; (signed int)&amp;unk_10017427 ); } </code></pre> <p>Here is the orginal code (not decompiled written in C++)</p> <pre><code>double currentTimer = GetTimer(); double timeElapsed = currentTimer - lastTimer; int maxPlayers = 0; DWORD lastPlayerPtr = 0; if (playerListBaseAddress != NULL &amp;&amp; !IsBadReadPtr((void *) playerListBaseAddress, sizeof(ULONG_PTR))) { for (int i = 0; i &lt; 255; i++) { //populate player ship list. DWORD playerPtr = *(DWORD *) (playerListBaseAddress + (i * 4)); if (playerPtr != NULL &amp;&amp; !IsBadReadPtr((void *) playerPtr, sizeof(ULONG_PTR))) { Ships[i].XCoordinate = *(DWORD *) (playerPtr + 0x4); Ships[i].YCoordinate = *(DWORD *) (playerPtr + 0x8); Ships[i].XSpeed = *(signed long *) (playerPtr + 0x10); Ships[i].YSpeed = *(signed long *) (playerPtr + 0x14); Ships[i].Freq = *(DWORD *) (playerPtr + 0x58); Ships[i].ShipNum = *(BYTE *) (playerPtr + 0x5C) //memcpy(&amp;(Ships[i].Name), (void*)((DWORD)playerPtr+0x6D), 19); if (!*(BYTE *) (playerPtr + 0x6D) == NULL) strcpy_s(Ships[i].Name, (char *) ((DWORD) playerPtr + 0x6D)); Ships[i].used = true; if (lastPlayerPtr == playerPtr) goto finishList; lastPlayerPtr = playerPtr; } else { finishList: maxPlayers = i; for (int j = i; j &lt; 255; j++) Ships[j].used = false; break; } } </code></pre> <p>Here is before and after (applying my custom struct)<br> I did the custom struct by doing a bunch of Arrays (* key), then setting proper sizes. (Guessing this isn't the proper way to make a structure in IDA PRO?) <img src="https://i.stack.imgur.com/c5OBF.png" alt="struct"> <br>Before:<br> <img src="https://i.stack.imgur.com/u2VGH.png" alt="before"> <br>After:<br> <img src="https://i.stack.imgur.com/p96Au.png" alt="after"> <br>ASM:<br> <img src="https://i.stack.imgur.com/wQXTP.png" alt="asm"> <br>Edit Function<br> <img src="https://i.stack.imgur.com/2rANk.png" alt="edit function"> <br>Double clicked local variable<br> <img src="https://i.stack.imgur.com/9vKkW.png" alt="dbl click local variables"></p>
IDA PRO Structures Defining negative offset -4 -8 offset repair asm Hex-Rays
|ida|struct|
<p>It's very easy to prevent the UPX tool to unpack an UPX compressed file. If you take a look to the source code you will see that it checks for the magic string <code>UPX_MAGIC_LE32</code> in <code>p_lx_interp.cpp</code>. So, I simply changed all matches of the string (in binary chunks) "<code>UPX!</code>" to "<code>AAA!</code>". I copied <code>/bin/ls</code> (ELF64) to another folder and packed with UPX. Then I edited it like this:</p> <pre> $ pyew ls ELF Information (...) [0x00000000]> /s UPX # Search for the string UPX HINT[0x000000b4]: UPX!........p...p...8.............!..ELF......>...E@..e....p HINT[0x0000abcc]: UPX!.........S...USQRH..VH..H..1.1.H....P.....t.....H....... HINT[0x0000ad3b]: UPX executable packer http://upx.sf.net $..$Id: UPX 3.07 Cop HINT[0x0000ad6b]: UPX 3.07 Copyright (C) 1996-2010 the UPX Team. All Rights Re HINT[0x0000ad90]: UPX Team. All Rights Reserved. $....^j._j.X..j._j....N...p...I....... [0x00000000]> s 0xb4 # Seek to the specified offset in the file [0x000000b4:0x000000b4]> edit # Open the file for editing [0x000000b4:0x000000b4]> wx 414141 # Patch in hexadecimal [0x000000b4:0x000000b4]> s 0xabcc [0x0000abcc:0x0000abcc]> wx 414141 [0x0000abcc:0x0000abcc]> s 0xafe7 [0x0000afe7:0x0000afe7]> wx 414141 [0x0000afe7:0x0000afe7]> s 0xb3ac [0x0000b3ac:0x0000b3ac]> wx 414141 [0x0000b3ac:0x0000b3ac]> q # And quit $ ./ls (...lots of files...) $ upx -d ./ls Ultimate Packer for eXecutables Copyright (C) 1996 - 2010 UPX 3.07 Markus Oberhumer, Laszlo Molnar & John Reiser Sep 08th 2010 File size Ratio Format Name -------------------- ------ ----------- ----------- upx: ls: NotPackedException: not packed by UPX Unpacked 0 files. </pre> <p>That's all. Anyway, remember that you're only preventing this tool to unpack UPX compressed files. UPX is a compressor that anyone with basic knowledge about packers can uncompress with little to no effort.</p>
3335
2013-12-31T21:43:59.333
<p>Still on my way to understand how to prevent the usage of the <code>-d</code> (decompress) option of UPX (see this <a href="https://reverseengineering.stackexchange.com/questions/3323/how-to-prevent-upx-d-on-an-upx-packed-executable">question</a>), I try to identify the header file of UPX in ELF executable files.</p> <p>Looking at the code, all the sources seems to be in the files <code>lx_elf.h</code> and <code>lx_elf.cpp</code> (stands for <em>Linux Elf</em>). I tried to follow the code but I got lost in it...</p> <p>I also did take a look at the beginning of an UPX compressed executable file (amd64), visualized in 8-bytes per line mode for more clarity (and thanks to <a href="http://code.google.com/p/corkami/wiki/ELF101" rel="nofollow noreferrer">Corkami ELF-101</a>):</p> <pre><code>00000000: 7f45 4c46 0201 0103 .ELF.... 00000008: 0000 0000 0000 0000 ........ 00000010: 0200 3e00 0100 0000 ..&gt;..... 00000018: 0831 4200 0000 0000 .1B..... ELF HEADER 00000020: 4000 0000 0000 0000 @....... 00000028: 0000 0000 0000 0000 ........ 00000030: 0000 0000 4000 3800 ....@.8. 00000038: 0200 4000 0000 0000 ..@..... 00000040: 0100 0000 0500 0000 ........ 00000048: 0000 0000 0000 0000 ........ 00000050: 0000 4000 0000 0000 ..@..... 00000058: 0000 4000 0000 0000 ..@..... PROGRAM HEADER TABLE 00000060: f438 0200 0000 0000 .8...... 00000068: f438 0200 0000 0000 .8...... 00000070: 0000 2000 0000 0000 .. ..... 00000078: 0100 0000 0600 0000 ........ 00000080: 487d 0500 0000 0000 H}...... 00000088: 487d 6500 0000 0000 H}e..... 00000090: 487d 6500 0000 0000 H}e..... 00000098: 0000 0000 0000 0000 ........ 000000a0: 0000 0000 0000 0000 ........ UPX HEADER (???) 000000a8: 0000 2000 0000 0000 .. ..... 000000b0: a298 b634 5550 5821 ...4UPX! 000000b8: f407 0d16 0000 0000 ........ 000000c0: 1676 0500 1676 0500 .v...v.. 000000c8: 0002 0000 bd00 0000 ........ 000000d0: 0200 0000 fbfb 21ff ......!. 000000d8: 7f45 4c46 0201 0100 .ELF.... 000000e0: 0200 3e00 0d70 2840 ..&gt;..p(@ 000000e8: 0f1b f26d 1605 00e8 ...m.... ELF HEADER (again) 000000f0: 6d05 0013 01eb be7b m......{ 000000f8: 3800 0805 1c00 1b00 8....... 00000100: 060f 0527 9b90 27ec ...'..'. 00000108: 4000 4007 c001 0008 @.@..... ....8&lt;.... </code></pre> <p>My guess is that the second ELF header (always located at an offset of <code>0xd8</code>) is the header of the compressed executable. And indeed, when looking at the original ELF header of the executable (before applying <code>upx</code>) we find:</p> <pre><code>00000000: 7f45 4c46 0201 0100 0000 0000 0000 0000 .ELF............ 00000010: 0200 3e00 0100 0000 7028 4000 0000 0000 ..&gt;.....p(@..... 00000020: 4000 0000 0000 0000 e86d 0500 0000 0000 @........m...... 00000030: 0000 0000 4000 3800 0800 4000 1c00 1b00 ....@.8...@..... 00000040: 0600 0000 0500 0000 4000 0000 0000 0000 ........@....... 00000050: 4000 4000 0000 0000 4000 4000 0000 0000 @.@.....@.@..... 00000060: c001 0000 0000 0000 c001 0000 0000 0000 ................ 00000070: 0800 0000 0000 0000 0300 0000 0400 0000 ................ 00000080: 0002 0000 0000 0000 0002 4000 0000 0000 ..........@..... </code></pre> <p>A few fields have been omitted in the compressed version but the header is mainly preserved. So, lets assume this is just a short version of the original ELF header.</p> <p>But, what I would like to understand are the fields of the first header:</p> <pre><code>00000080: 487d 0500 0000 0000 H}...... 00000088: 487d 6500 0000 0000 H}e..... 00000090: 487d 6500 0000 0000 H}e..... 00000098: 0000 0000 0000 0000 ........ 000000a0: 0000 0000 0000 0000 ........ UPX HEADER (???) 000000a8: 0000 2000 0000 0000 .. ..... 000000b0: a298 b634 5550 5821 ...4UPX! 000000b8: f407 0d16 0000 0000 ........ 000000c0: 1676 0500 1676 0500 .v...v.. 000000c8: 0002 0000 bd00 0000 ........ 000000d0: 0200 0000 fbfb 21ff ......!. </code></pre> <p>So, my question is about discovering the location and the meaning of the fields of the UPX header. If somebody knows about UPX internals any hint would be appreciated.</p>
Decoding the UPX ELF header file
|elf|packers|upx|
<p>I'll list some ways to do it. Obviously there are many others and most likely other fellows here will add. Start with those as they are ones of the mostly used.</p> <ol> <li>While debugging a malicious process, BP on <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms681674%28v=vs.85%29.aspx" rel="nofollow">WriteProcessMemory</a>/NtMapViewOfSection API. Those are used to copy/map potential DLL into the remote process. Before the copying or mapping is done, you can dump the buffer to disk. Check the manual of the above APIs to find the local buffer which will be copied to remote process.</li> <li>Alternatively, if you have s little understanding what malicious code is doing you can follow it by inspecting the log of <a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx" rel="nofollow">procmon</a>. Once you see something in the log that is 100% done by the mal-DLL, you can open that log line and inspect the stack. The stack will tell you at what page the mal-DLL resides. If you know at what memory page the DLL resides in the infected process, you can use for example <a href="http://processhacker.sourceforge.net/" rel="nofollow">Process Hacker</a> for dumping this specific memory page by clicking on the process and inspecting memory tab.</li> <li>Alternatively, you can dump the whole memory of the infected machine and use tool - <a href="https://code.google.com/p/volatility/" rel="nofollow">Volatility</a> to inspect the memory of a specific process or all the processes.</li> </ol>
3336
2014-01-01T06:24:13.160
<p>I am trying to reverse engineer a DLL that may contain malware. One thing I noticed is that it hides itself from the DLL <code>LDR_MODULE</code> list. So, when I use Ollydbg or smiler tools I do not see it and cannot dump it. </p> <p>I don't have the DLL file. I just have an executable file that injects the DLL into a certain process.</p>
How to dump a DLL not listed using Process Explore and similar tools
|malware|ollydbg|dll|
<p>Zynamics replied, they said that they removed the to text functionality as it was mostly used for debugging. However the .BinDiff results are essentially an SQLite file and can be handled as one. Firefox has a plug-in to read these SQLite files found <a href="https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/" rel="nofollow">here</a>. For linux I have found that <a href="http://sqliteman.com/" rel="nofollow">Sqliteman</a> works well. </p>
3340
2014-01-02T14:42:46.873
<p>I have been using BinDiff as a plug-in for IDA Pro. I understand it is not possible to run this plug-in via terminal/batch mode. Is there a way I can export the results to a more readable format such as a .pdf or a .txt? I need a more readable format then the .BinDiff and .BinExport formats that it generates. </p>
Formatting BinDiff results to a .txt
|ida|idapython|ida-plugin|tool-bindiff|
<p>Easy enough. In your case what you most likely want is <a href="http://www.sourceware.org/gdb/onlinedocs/gdb.html#Break-Commands" rel="noreferrer"><code>commands</code></a> which can be used to create "routines" that run whenever a breakpoint is hit. For your case roughly:</p> <pre><code>break boost::uuids::detail::sha1::process_bytes commands 1 x/s $rcx continue end </code></pre> <p>Problem is that you need to hardcode the breakpoint number. Depending on the GDB version you may get around this using the <code>$bpnum</code> convenience variable. So:</p> <pre><code>break boost::uuids::detail::sha1::process_bytes commands $bpnum x/s $rcx continue end </code></pre> <p>Also see <a href="https://stackoverflow.com/a/11019683/476371">this</a> concerning the last example.</p> <p><strong>Note:</strong> using this method can be quite taxing on the CPU depending on how often this gets called and whether a hardware breakpoint could be used by GDB.</p> <hr> <p>You can also use the conditional form of breakpoints. Check out the actual authoritative reference <a href="http://www.sourceware.org/gdb/onlinedocs/gdb.html#Set-Breaks" rel="noreferrer">here</a>. The form looks like this:</p> <pre><code>break ... if cond </code></pre> <p>You can also set the condition independent of setting the breakpoint, if you know the breakpoint number. Use <code>info break</code> to get the number of the breakpoint and then use that as <code>bnum</code> in:</p> <pre><code>condition bnum expression </code></pre>
3342
2014-01-03T04:45:56.790
<p>I'd like to automate the following in my <code>.gdbinit</code>:</p> <pre><code>break boost::uuids::detail::sha1::process_bytes # When execution stops at the above breakpoint, # I want to display the contents of `rcx` as a string: x/s $rcx c # do not stop here </code></pre> <p>How do I automate this?</p> <h3>UPDATE: Here's a better <code>.gdbinit</code> example:</h3> <pre><code># Our custom-built libcurl, with debugging symbols enabled: set environment LD_PRELOAD=./curl/curl-7.34.0/lib/.libs/libcurl.so # File that connects to the evil server: file ./evil # Make sure we get notified when it connects! break curl_easy_setopt commands $bpnum clear curl_easy_setopt # to avoid recursion call curl_easy_setopt(curl, CURLOPT_VERBOSE) continue end </code></pre> <p>This hooks in to the evil binary, and when it initialises its curl handle, we set set it to verbose so we get lots of output about what's going on.</p> <p>Thanks for the answer.</p>
Run command on breakpoint without stopping
|gdb|
<p>You would need to create a Loader plugin for them. See the <code>ldr</code> directory in the IDA Pro SDK.</p> <p>Once the Loader is built, you would copy it to the <code>loaders</code> subdirectory under IDA Pro's directory.</p> <p>Here's a nice blog entry on writing IDA Pro file loaders in higher level languages: <a href="http://www.hexblog.com/?p=110" rel="nofollow">http://www.hexblog.com/?p=110</a></p>
3352
2014-01-03T16:31:47.230
<p>I am trying to disassemble some various files, and IDA does not recognize them. Is there anyway to add more file types to IDA Pro? I am running ida 6.5</p>
IDA Pro only recognizes my files as BINARY
|ida|binary-analysis|ida-plugin|idapro-sdk|
<p>(blatant plug)</p> <p>protectionid (pid.gamecopyworld.com) reports the compiler info (turn it on in the configuration)</p> <p>to do it, its a multitude of things</p> <p>checking for byte patterns</p> <p>checking imports (mscoree.dll, msvcr*.dll and so on)</p> <p>checking entrypoint code</p> <p>checking mz stub</p> <p>checking linker version</p> <p>and a few other things</p> <p>example output</p> <p>Scanning -&gt; C:\ProtectionID.source\problematic.files\solved\detected\Agile.NET 6.2.0.16.AgileNETUnpackMe\AgileUnpackMe.exe</p> <p>File Type : 32-Bit Exe (Subsystem : Win GUI / 2), Size : 7680 (01E00h) Byte(s)</p> <p>[File Heuristics] -&gt; Flag : 00000100000001001101000000110000 (0x0404D030)</p> <p>[Entrypoint Section Entropy] : 5.25 (section #0) &quot;.text &quot; | Size : 0x1288 (4744) byte(s)</p> <p>[DllCharacteristics] -&gt; Flag : (0x8540) -&gt; ASLR | DEP | NOSEH | TSA</p> <p>[ImpHash] -&gt; f34d5f2d4577ed6d9ceec516c1f5a744</p> <p>[SectionCount] 3 (0x3) | ImageSize 0x8000 (32768) byte(s)</p> <p>[VersionInfo] Product Name : AgileUnpackMe</p> <p>[VersionInfo] Product Version : 1.0.4999.25574</p> <p>[VersionInfo] File Description : AgileUnpackMe</p> <p>[VersionInfo] File Version : 1.0.4999.25574</p> <p>[VersionInfo] Original FileName : AgileUnpackMe.exe</p> <p>[VersionInfo] Internal Name : AgileUnpackMe.exe</p> <p>[VersionInfo] Legal Copyrights : Copyright 2013</p> <p>[Debug Info] (record 1 of 1) (file offset 0x1414)</p> <p>Characteristics : 0x0 | TimeDateStamp : 0x522C69AD | MajorVer : 0 / MinorVer : 0 -&gt; (0.0)</p> <p>Type : 2 (0x2) -&gt; CodeView | Size : 0x57 (87)</p> <p>AddressOfRawData : 0x3230 | PointerToRawData : 0x1430</p> <p>CvSig : 0x53445352 | SigGuid A75CE0F5-0D67-4FC4-A2C612B95C81F742</p> <p>Age : 0x6 | Pdb : c:\AgileUnpackMe\AgileUnpackMe\obj\x86\Debug\AgileUnpackMe.pdb</p> <p>[!] AgileDotNet detected</p> <p>[CompilerDetect] -&gt; .NET</p> <p>[.] .Net Info -&gt; v 2.5 | x86 managed (/platform:x86) | Flags : 0x00000003 -&gt; COMIMAGE_FLAGS_ILONLY | COMIMAGE_FLAGS_32BITREQUIRED |</p> <p>[.] Entrypoint (Token) : 0x06000006</p> <p>[.] MetaData RVA : 0x00002184 | Size : 0x00000C0C (3084)</p> <p>[.] MetaData-&gt;Version 1.1 -&gt; v2.0.50727</p> <p>[.] Flags : 0x0 | Streams : 0x5 (5)</p> <ul> <li>Scan Took : 0.156 Second(s) [00000009Ch (156) tick(s)] [539 scan(s) done]</li> </ul>
3362
2014-01-05T07:02:16.673
<p>How to understand if exe/dll is written in C++/.Net/Java or in any other language. I tried to use Dependency walker but not able to get required information.</p>
How to know in which language/technology program (.exe) is written?
|disassembly|windows|binary-analysis|static-analysis|executable|
<p>These are 64-bit OLE date format, but they are not the dates you're thinking they are. I took all of your samples and sorted them into the order you posted them (from top to bottom). I then decoded the 8-byte strings starting from byte 11 of each sample as a double in IEEE format and then dumped the floating-point number in text form. (I wrote a quick C++ program, but one could do that with many other methods.) I then put those into a spreadsheet (I used Libre Office, but one could also use Excel) to interpret them as Microsoft's 64-bit OLE date formats which are number of seconds from 30 December 1899 0:00:00 and got the following (mm/dd/yyyy format):</p> <pre><code>01/05/2014 00:35:48 41644.02486 01/05/2014 01:21:34 41644.05664 01/05/2014 01:22:25 41644.05723 01/05/2014 01:25:32 41644.0594 01/05/2014 15:22:37 41644.64071 01/05/2014 15:24:14 41644.64183 01/05/2014 15:24:36 41644.64208 </code></pre> <p>It looks like the last three samples were sequentially created within two minutes, which makes sense to me. So they are indeed dates, but not the ones you think they are. Look elsewhere for changes in the file for 8-byte sequences ending with 0x40.</p>
3367
2014-01-05T14:40:15.913
<p>I've been writing a small library to allow parsing of the data files used by Sage Accounts 50, but I'm really confused by how it is storing dates. </p> <p>I'm fairly sure that there will be a date created and date modified. </p> <p>This should contain a modified date of 05/01/2014</p> <pre><code>01 00 00 00 01 00 00 27 00 00 00 65 87 A9 CB 80 55 E4 40 EA 7D BC E5 1B 55 E4 40 65 87 A9 CB 80 55 E4 40 00 </code></pre> <p>12/02/2014:</p> <pre><code>01 00 00 00 01 00 00 29 00 00 00 72 11 06 D0 81 55 E4 40 EA 7D BC E5 1B 55 E4 40 72 11 06 D0 81 55 E4 40 00 </code></pre> <p>16/06/2014:</p> <pre><code>01 00 00 00 01 00 00 2B 00 00 00 6A F8 DB D4 81 55 E4 40 EA 7D BC E5 1B 55 E4 40 6A F8 DB D4 81 55 E4 40 00 </code></pre> <p>12/12/2013:</p> <pre><code>01 00 00 00 01 00 00 2D 00 00 00 F8 F1 96 E6 81 55 E4 40 EA 7D BC E5 1B 55 E4 40 F8 F1 96 E6 81 55 E4 40 00 </code></pre> <p>Any help would be really appreciated. I've already tried looking for unix time stamps and also <code>struct tm</code>, without any luck.</p> <p>Thanks</p> <h2>EDIT</h2> <p>As requested here are some dates which are more sequential:</p> <pre><code>01/12/13 - 01 00 00 00 01 00 00 2F 00 00 00 7C E8 A9 80 94 55 E4 40 EA 7D BC E5 1B 55 E4 40 7C E8 A9 80 94 55 E4 40 00 02/12/13 - 01 00 00 00 01 00 00 31 00 00 00 81 59 DC 89 94 55 E4 40 EA 7D BC E5 1B 55 E4 40 81 59 DC 89 94 55 E4 40 00 03/12/13 - 01 00 00 00 01 00 00 33 00 00 00 BF 58 F2 8B 94 55 E4 40 EA 7D BC E5 1B 55 E4 40 BF 58 F2 8B 94 55 E4 40 00 </code></pre>
What is the format of this date time?
|binary-analysis|
<p>Call to hard-coded addresses will not work for different reasons, the most obvious is ASLR, which randomizes the base address of every DLL, which means that the function address will be different at every boot.</p> <p>Solving this issue is far from simple as the use of <code>LoadLibrary</code> and <code>GetProcAddress</code>, classically used by developers to dynamically import DLL will also have a dynamic address, so you can't use them to determine the address of your sought function.</p> <p>To solve this issue you have to use shellcode techniques; in other words you will have to include assembly code that parse the <code>PEB</code> structure to determine the base address of Kernel32 address, search for your function in export table and finally use the it.</p> <p>Another more advanced techniques for more complex usage is the use of reflective DLL injection, but it is a bit far from what you are looking for.</p>
3374
2014-01-07T00:49:33.363
<p>I need some help regarding calls in assembly with Ollydbg. I'm messing around with a simple application. So far, so good, I created a codecave for myself to add some code.</p> <p>But whenever I try to create a call to a function outside my debugged executable module to, for example, a <code>kernel32</code> or <code>msvcrt</code> function, it messes everything up.</p> <p>Let's look at some random call in the application:</p> <pre><code>0041D654 FF15 DC714200 CALL DWORD PTR DS:[&lt;&amp;KERNEL32.GetCommandLineA&gt;] </code></pre> <p>When I double click it, it shows me <code>CALL DWORD PTR DS:[4271DC]</code> So, <code>4271DC</code> seems to point to <code>76FB496D</code>, which is, indeed:</p> <pre><code>76FB496D &gt;-FF25 60070177 JMP DWORD PTR DS:[&lt;&amp;api-ms-win-core-processenvironment-l1-2-0.Get&gt; ;KERNELBA.GetCommandLineA </code></pre> <p>Well, I just stole that from the application itself. Now I want to create a call to <code>kernel32</code> myself. I assemble a line and enter <code>CALL DWORD PTR DS:[Kernel32.GetCommandLineA]</code> Now it's saying:</p> <pre><code>0041D654 FF15 6D49FB76 CALL DWORD PTR DS:[KERNEL32.GetCommandLineA] </code></pre> <p>Looking good!</p> <p>Assemble the line <code>CALL DWORD PTR DS:[76FB496D]</code>. Giving this a run works fine ofcourse, but whenever I run it like this on another pc, all hell breaks loose.</p> <p>My question is: How can I make such an pointer <code>CALL DWORD PTR DS:[4271DC]</code>, so the code runs on all pc's?</p> <p>I can of course use <code>CALL DWORD PTR DS:[4271DC]</code> in the application to call the function <code>getcomandlineA</code> whenever I want, but I don't know the (dynamic?) pointer to, let's say, <code>kernel32.lstrcpy</code>.</p>
Cannot call function (properly) in ollydbg
|ollydbg|
<p>You may find other people code useful and metasplot is good to test and understand how things can be exploited. </p> <p>For reversing there are alot of videos and sildes that other people have released explaining how they achieved there goals</p>
3379
2014-01-07T03:46:19.910
<p>I learned basis of assembly language with, both, AT&amp;T and Intel style. After that I gone through buffer overflow and how to use shellcode with it. Should I go for <a href="http://www.metasploit.com/" rel="nofollow">Metasploit</a> now?</p>
Does learning Metasploit help me in reverse engineering and malware analysis?
|disassembly|malware|assembly|buffer-overflow|metasploit|
<p>The structure is fully documented by Microsoft on their MSDN site. I also created a blog post a while ago, regarding this data structure which can be found here - <a href="http://bsodtutorials.blogspot.co.uk/2013/11/devobj-and-deviceobject.html" rel="nofollow">http://bsodtutorials.blogspot.co.uk/2013/11/devobj-and-deviceobject.html</a></p>
3385
2014-01-07T10:38:21.537
<p>I'm looking for information on the <a href="http://msdn.moonsols.com/winxpsp3_x86/DEVICE_OBJECT.html" rel="nofollow">_DEVICE_OBJECT</a>-><a href="http://msdn.moonsols.com/winxpsp3_x86/DEVOBJ_EXTENSION.html" rel="nofollow">_DEVOBJ_EXTENSION</a> structure.</p> <p>I'd like to know a bit more about this structure in genernal, like what it's actually used for. But specifically, I'd like to know about the <code>_DEVICE_OBJECT* AttachedTo</code> member and the difference between that and the <code>_DEVICE_OBJECT* AttachedDevice</code> member in the <code>_DEVICE_OBJECT</code> structure.</p> <p>Google is proving fruitless, and I can't find any reference to it in the Windows Internals book. Any resources or information would be greatly appreciated.</p> <p>EDIT:<br> Ok... After a bit of staring at WinDbg I found that the <code>AttachedTo</code> field seems to point to the device object at the top of the device tree. Can anyone confirm this?</p>
_DEVOBJ_EXTENSION structure information
|windows|kernel-mode|
<p>Unfortunately this IDA feature doesn't always work as needed especially if you define your objects in Hex-Rays.</p> <p>If your problem is around using Hex-Rays, you can use the <a href="https://github.com/EiNSTeiN-/hexrays-python-plugins/blob/master/xrefs/xrefs.py" rel="nofollow">XRefs</a> plugin with the <a href="https://github.com/EiNSTeiN-/hexrays-python" rel="nofollow">hexrays-python</a> API in IDA 6.4.</p> <p>As far as I understand latest version of IDAPython with support of IDA 6.5 at google code already contains these bindings in IDA API module, but it is not fully operational yet (at least I'm not succeeded to make it work). </p>
3387
2014-01-07T13:58:09.897
<p>I'ld like to see which functions are operating with certain object's fields that I already processed, meaning I created the structure and assigned it to the correct places in the functions in IDA, without having to run a dynamic debugger. (for example, I would like to see a list of the functions accessing/writing/reading the <em>Foo</em> data field of the <em>Bar</em> object), but as far as I know it's not implemented in IDA. </p>
Cross-referencing object fields
|ida|ida-plugin|idapython|struct|
<p>I would do something like this in IDAPython:</p> <pre><code># I didn't check this code, please use carefully !This code will pass through all defined segments and will try to make code on any unexplored area # IDAPython documentation is at https://www.hex-rays.com/products/ida/support/idapython_docs/ import idautils import idc for ea in idautils.Segments(): segend = idc.GetSegmentAttr(ea, idc.SEGATTR_END) start = ea while start &lt; segend: idc.MakeCode(start) start = idc.FindUnexplored(start+1, idc.SEARCH_DOWN) </code></pre> <p>You can run it with <a href="https://www.hex-rays.com/products/ida/support/idadoc/417.shtml" rel="nofollow">-S</a> command line switch as stated in previous answer</p>
3388
2014-01-07T13:58:48.743
<p>I am loading various files that read into IDA as binary. Once I have the GUI in front of me I am able to go through the segments and hit "c" in order to convert to instruction/code.</p> <p>However, I am primarily trying to do all my ida work via linux terminal (using the command line <code>./idal -B input-file</code>). Is there a command line flag, or another method, to automate the generating of instructions from the binary files? Or is this something I will have to manually do every time?</p>
IDA Pro converting to instruction functionality: how to automate.
|ida|linux|ida-plugin|idapython|
<p>Here it is. Run it with idal -c -A -S./script.py ./test.bin</p> <pre><code># I didn't check this code, please use carefully ! # IDAPython documentation is at https://www.hex-rays.com/products/ida/support/idapython_docs/ import idautils import idc for ea in idautils.Segments(): segend = idc.GetSegmentAttr(ea, idc.SEGATTR_END) start = ea while start &lt; segend: idc.MakeCode(start) start = idc.FindUnexplored(start+1, idc.SEARCH_DOWN) idc.GenerateFile(idc.OFILE_ASM, idc.GetInputFile()+".asm", 0, idc.BADADDR, 0) idc.Exit(0) </code></pre>
3395
2014-01-07T17:09:11.397
<p>I am using IDA Pro 6.5 and running it via terminal with the following command line switches:</p> <ol> <li>-B (to run in batch mode, should automatically generate a .asm file containing results)</li> <li>-S running a script in which the only functionality is to convert all of the binary into instruction.</li> </ol> <p>When I ran in batch mode prior to the script, it would generate a .asm file that I would then be able to manipulate. However, now this file doesn’t appear. Is there a quick fix or any IDA Python methods I can include in order to create an output file?</p>
IDA Pro/IDA Python, producing file via terminal
|ida|ida-plugin|idapython|idapro-sdk|
<p>Generally Antivirus companies follow the naming convention proposed by CARO (Computer Antivirus Research Organization).</p> <p>A malware usually gets a name based on the strings found in it. In some cases based on Mutex/ file name/server name/registry keys and very rarely based on its action.</p> <p>In some AV companies they give certain names to track the detections made by generic/ heuristic detection methods (eg:Obfuscated_A, WS.Reputation.1)</p>
3399
2014-01-07T18:39:53.240
<p>While analyzing a binary online through the virustotal service , I found out that different AVs named the binaries differently.For instance, for that same binary Norman named it Obfuscated_A, Symantec named it WS.Reputation.1 and another AV named it Malware-Cryptor.General.2 .Is there any specific naming convention adopted by the AVs?</p>
How antiviruses name malwares
|malware|
<p>In normal condition <code>alt+f9 execute till user code</code> should get you back to user code</p>
3405
2014-01-08T08:24:33.500
<p>I'm debugging an application in OllyDbg, I pause the program at a specific place. Now I am deep inside ntdll and other gui related module calls, judging from the stack. <strong>I'ld like to break as soon as the application returns to any function within a specified (the main) module.</strong> Is there such breakpoint condition? How can I do this? </p>
Break on returning to a specific module
|ollydbg|debugging|memory|callstack|
<p><code>rECX = (rECX &amp; 0xFFFFFF00) | ((rECX &amp; 0xFF) &gt;&gt; 1)</code></p>
3412
2014-01-08T19:35:49.777
<p>I want to convert this to C:</p> <pre>SHR CL,1</pre> <p>rECX is the name of the (32bit unsigned int)register variable. It should be simple, but I can't figure out the proper pointer magic :/</p>
How to convert this one-liner asm to C
|assembly|decompilation|c|
<p>I try to give my idea about reversing, not an answer, because I myself hope that I can find it, moreover I am quite sure that any expert here may say that what I think is crappy but I beg a generosity from the community.</p> <p>The "reverse engineering" a program is rather to <em>verify whether the program has some properties or not</em>, than to <em>reverse from binary code to source code</em> (we can imagine that there are some properties that we can observe easily in the source code but not in the binary code), then the "obfuscation" is to prevent the program from such an algorithmic verification. </p> <p>In the perfect (i.e. theoretical) world, some very general results assert several things. First, the <a href="http://fr.wikipedia.org/wiki/Th%C3%A9or%C3%A8me_de_Rice" rel="nofollow">Rice's theorem</a> (as previously mentioned by @perror) and a more constructive result of <a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.35.9722" rel="nofollow">Landi. W</a> assert that a general verificator does not exist, that means we cannot write a verificator V so that when we gives V an arbitrary program P and a non-trivial property p (a trivial property is one that exists in all programs, e.g. the magic byte MZ exists in all PE files is a trivial property), V can answer P has p or not. So that means the perfect obfuscation exists ?, the answer is trivially No, that is because we never require a such strong verificator (that gives deterministic answer for all programs), we need only a verificator for some useful classes of programs. </p> <p>Second, <a href="http://www.wisdom.weizmann.ac.il/~oded/PS/obf4.pdf" rel="nofollow">Barak et al</a> (as previously mentioned also by @perror) asserts a somehow contradict result: there are some classes of programs that cannot be obfuscated, namely no matter what they are obfuscated, that is easy to write a verificator to answer these programs have a given property p (or not). There is actually no contradiction here because the Rice's theorem applies in the context of "all programs" and the result of Barak et al applies for the context of "several programs", indeed we have:</p> <p>Third, the result of <a href="http://www.cs.columbia.edu/~hoeteck/pubs/obf-point-stoc05.pdf" rel="nofollow">Wee. H</a> says that we can always hide (i.e. obfuscate) some properties given a class of special programs named <em>point functions</em>. Again, that does not mean the obfuscation is possible in general because this result applies in the context of "several programs".</p> <p>Fourth, the result of <a href="http://eprint.iacr.org/2013/451.pdf" rel="nofollow">Garg. S et al</a> says that we can obfuscate any program so that any property computed from the obfuscated one is "trivial". So that means the perfect obfuscator exists?, and if it exists then it contradict to the result of <a href="http://www.wisdom.weizmann.ac.il/~oded/PS/obf4.pdf" rel="nofollow">Barak et al</a>?, obviously No, because the two results have used actually two different definitions of triviality, in the first one a property is trivial if it exists in all programs having the same semantics (so this definition is weaker than in the second one).</p> <p>In the real (i.e. practial) world, I have so little experience that I cannot give any useful idea. But I doubt that the game obfuscator vs de-obfuscator will evolve in some very clever ways and we still have many gaps to work in (as an obfuscator or as a de-obfuscator).</p>
3414
2014-01-09T05:44:16.573
<p>I know that reverse engineering from binary to source code (e.g. C++) is generally considered hard or impossible but has any computer scientist actually proven "mathematically" that it's impossible or possible to reverse engineer (any) binary to source code? Is reverse engineering simply a very hard puzzle or are there binary out there that is simply impossible to reverse whether by hand or via decompiler?</p> <p>NOTE: I know the answer might be "it depends on platform and programming language" so I am going to assume the language used is C++ since it's generally considered impossible to reverse it.</p>
Is it "theoretically" possible/impossible to reverse any binary?
|disassembly|decompilation|c++|
<p>From <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2008-March/012953.html" rel="nofollow">http://lists.cs.uiuc.edu/pipermail/llvmdev/2008-March/012953.html</a>:</p> <blockquote> <p>During Google Summer of Code 2007 I was working on llvm-qemu, which translates from <strong>ARM machine code to LLVM IR</strong> (at basic block level) and via the LLVM JIT to x86 machine code. All source architectures supported by qemu (x86, x86-64, ARM, SPARC, PowerPC, MIPS, m68k) can be translated to LLVM IR this way (e.g. adding support for x86 to llvm-qemu should be almost trivial).</p> <p>You can find llvm-qemu at <a href="http://code.google.com/p/llvm-qemu/" rel="nofollow">http://code.google.com/p/llvm-qemu/</a></p> </blockquote>
3421
2014-01-09T10:02:26.683
<p>Is there publicly available solution for translation of ARM assembly to LLVM IR?</p>
Translation from ARM assembly to LLVM IR
|disassembly|
<p>OllyDbg is nice, and it has some cool features but it still doesn't support x64 native debugging on Window (it is in Alpha though!)</p> <p>If you want to debug x64, then WinDbg seems to be the way to go.</p>
3430
2014-01-09T23:20:54.887
<p>I am fairly familiar with WinDbg and didn't know about OllyDbg before. From the statistics in this forum, it seems that OllyDbg is twice as popular as WinDbg. Sometimes WinDbg can be frustrating, so I wonder whether I should switch.</p> <p>To make this question less opinion based, these are my requirements:</p> <ul> <li>be able to debug .NET. From my research it seems that OllyDbg might not be as good as WinDbg with SOS and SOSEX</li> <li>do scripting. Here it seems OllyDbg is better. There are many scripts archived in a single place, which is not the case for WinDbg.</li> <li>analyze mini dump files. This could be a blocker: while the OllyDbg website states something about post mortem dump, I was unable to find an option to open a dump immediately (File/Open).</li> <li>record logs of what I'm doing to be able to give it to the customer. From the Google picture search I only see screenshots from registers, memory etc. I have not seen something similar to the WinDbg command output window.</li> </ul> <p><strong>Given these core requirements, should I give OllyDbg a try?</strong></p> <p>Version information: OllyDbg 2.01</p>
Should I switch from WinDbg to OllyDbg?
|tools|ollydbg|windbg|
<p>It's cl.exe that's inserting the jump thunk. It has some advantages, such as making it easier to redirect a function during runtime after load and makes it so that the loader only has to do a single relocation for that function. The other option would be to use an indirect call through an address. Neither is really optimal for performance due to the distance between the call and the jump or the address, which can hurt caching. You can <a href="http://msdn.microsoft.com/en-us/library/4khtbfyf%28VS.80%29.aspx">disable the jump thunk by disabling incremental linking</a>.</p> <p>That said, what you're doing is probably a bad idea. IDA is not really made to produce code that can be reassembled. What's normally done is that you extend the last section or add a new section with the patched code then redirect the original code to the patch through a call or a jump.</p>
3435
2014-01-11T01:33:36.070
<p>Test platform is windows 32 bit. IDA pro 64</p> <p>So, basically I use IDA pro to disassemble a PE file, and do some transformation work on the asm code I get, to make it <strong>re-assemblable</strong>.</p> <p>In the transformed code I generated, the system function call like <code>printf</code> will be written just as the usual way.</p> <pre><code>extern printf .... .... call printf </code></pre> <p>I use this to reassemble the code I create:</p> <pre><code>nasm -fwin32 --prefix _ test.s cl test.obj /link msvcrt.lib </code></pre> <p>I got a PE executable file, and basically it works fine (Like a hello world program, a quick sort program and others).</p> <p>But then, as I use <strong>IDA pro to re-disassemble the new PE executable file I create</strong>, strange things happened.</p> <p>IDA pro generates function call like this:</p> <p><img src="https://i.stack.imgur.com/2ttKz.png" alt="IDA pro"></p> <p>and when I use:</p> <pre><code>idaq.exe -B test.exe </code></pre> <p>to generate new assembly code, in the printf function call part, it generate this:</p> <pre><code>call j_printf </code></pre> <p>Without the <code>j_printf proc near</code> function define...</p> <p>So basically I am wondering if anyone know how do deal with this, to let IDA pro generate </p> <pre><code>call printf </code></pre> <p>or </p> <pre><code>call _printf </code></pre> <p>again or any other solution?</p>
Why IDA Pro generated a "j_printf" function call?
|ida|disassembly|windows|reassembly|
<p><strong>All the statements below are xp-sp3 based</strong> </p> <p>windbg can also be used to parse for RWX pages in VadTree<br> Copy paste following lines to <code>**.txt and run the script $$&gt;a&lt; path to **.txt</code> </p> <p>script contents needs grep in path for text parsing </p> <pre><code>aS proc @#Process ; aS procname @@c++( (char *)(((nt!_EPROCESS *) @#Process ))-&gt;ImageFileName ) ; aS procvad @@c++( (((nt!_EPROCESS *) @#Process ))-&gt;VadRoot ) ; .block { !for_each_process ".printf \"%20ma\t%p\t%p\n\n\",${procname}, ${proc} , ${procvad}; .echo \n;.shell -ci \"!vad ${procvad}\" grep \"EXECUTE_READWRITE\"" } ; ad * </code></pre> <p>and then set the process context to approriate process and examine the memory from StartVpn to EndVpn</p> <p>iirc Winlogon and csrss always had a few RWX pages<br> the csrss RWX page always seemed to contain lots of initialization _UNICODE_STRING<br> most of the pages wont be available for viewing you may need to live debug in Phase1Init Stage </p> <pre><code>sxe ibp;.reboot </code></pre> <p>on reboot set <code>bp NtCreateProcessEx</code> until csrss is about to be created<br> <code>bc * ; gu ;!vad on csrss _EPROCESS</code> csrss process at this point wont have the RWX page<br> only 4 vads will exist in csrss VadTree<br> you may need to follow from here and catch the allocation / writes and executions</p> <pre><code> csrss.exe 86acebe0 86d62660 86d39250 ( 4) 7f6f0 7f7ef 0 Mapped EXECUTE_READWRITE Pagefile-backed section </code></pre> <p>this oneliner will fetch you most of the strings in that page</p> <pre><code>.foreach (place { s -[1]b 7f6f0000 l?7000 0x7f } ) { r $t0 = place ; dS @$t0-7} </code></pre> <p>output of the above line</p> <pre><code>7f6f2170 "C:\WINDOWS" 7f6f2190 "C:\WINDOWS\system32" 7f6f21c0 "\BaseNamedObjects" 7f6f2208 ".罯...罯" 7f6f22b0 ".罯...罯" 7f6f221c "Autorun.inf" 7f6f2300 ".罯02.罯Software\Microsoft\Clock" 7f6f226c "DoesNotExist" 7f6f2260 ".罯" 7f6f2368 "ヘ罯...罯.罯" 7f6f22c4 "Clock.ini" 7f6f23d8 ".罯68.罯Control Panel\Color Scheme" 7f6f2418 "s" 7f6f230c "Software\Microsoft\Clock" </code></pre> <p>the winlogon RWX pages will contain Executble code most of them will start with <code>push cx push ax</code> sequence and end with an indirect call to somehwre via <code>jmp eax</code> and some intermediate calls to unviewable / non existing locations may need live analysis </p> <p>never observed rwx pages in clean explorer / iexplore / services.exe processos they exist only if some antivirus etc are installed</p> <p>see below for an <code>Avasted RWX</code> page in explorer.exe patching <code>RtlSetCurrentDirectory_U</code> and loading <code>snxhk.dll using LdrLoadDll()</code> this same patch can also be observed in iexplore.exe</p> <pre><code>.shell dir /b scan*vad* scanvad4rwx.txt lkd&gt; $$&gt;a&lt; scanvad4rwx.txt System 86fc6830 86fbfa90 smss.exe 86b0e020 86dfd008 csrss.exe 86acebe0 86f4e4d0 86d39250 ( 4) 7f6f0 7f7ef 0 Mapped EXECUTE_READWRITE Pagefile-backed section winlogon.exe 86d7b918 86d58930 86ae8ee0 ( 8) 9550 9553 4 Private EXECUTE_READWRITE 86340690 ( 7) 29c90 29c93 4 Private EXECUTE_READWRITE 86f370d0 ( 6) 2a4f0 2a4f3 4 Private EXECUTE_READWRITE 86b13a38 ( 5) 46580 46583 4 Private EXECUTE_READWRITE 86da2a00 ( 6) 497c0 497c3 4 Private EXECUTE_READWRITE services.exe 86b0a020 86ec15c8 86da7c20 (12) 380 380 1 Private EXECUTE_READWRITE lsass.exe 86b2a6b8 86b21110 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX explorer.exe 86241260 86b86768 86b13d28 (13) 90 90 1 Private EXECUTE_READWRITE 86545e50 (11) 2b0 2b0 1 Private EXECUTE_READWRITE 86aa6878 (12) 2c0 2ca 11 Private EXECUTE_READWRITE 86b056a0 (10) 2d0 2da 11 Private EXECUTE_READWRITE 86b3b9c8 (12) 2e0 2ea 11 Private EXECUTE_READWRITE AvastUI.exe 86315a00 860fc008 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX iexplore.exe 86aaf020 861b3f00 862ae9f8 (16) 150 150 1 Private EXECUTE_READWRITE </code></pre> <p>on rereading i noticed the below output is from a differnt session so splitting </p> <pre><code>and examine the memory using lkd&gt; .process /p /r 862543e8 &amp; lkd&gt; uf 150000 00150000 50 push eax 00150001 60 pushad 00150002 bd42001500 mov ebp,150042h 00150007 8b7d10 mov edi,dword ptr [ebp+10h] 0015000a 8b4518 mov eax,dword ptr [ebp+18h] 0015000d 8b5d1c mov ebx,dword ptr [ebp+1Ch] 00150010 8907 mov dword ptr [edi],eax 00150012 895f04 mov dword ptr [edi+4],ebx 00150015 897c2420 mov dword ptr [esp+20h],edi 00150019 8d454c lea eax,[ebp+4Ch] 0015001c 50 push eax 0015001d ff7548 push dword ptr [ebp+48h] 00150020 8d4550 lea eax,[ebp+50h] 00150023 50 push eax 00150024 8d4540 lea eax,[ebp+40h] 00150027 50 push eax 00150028 6aff push 0FFFFFFFFh 0015002a ff5508 call dword ptr [ebp+8] 0015002d 85c0 test eax,eax 0015002f 750f jne 00150040 00150031 33c9 xor ecx,ecx 00150033 8d4538 lea eax,[ebp+38h] 00150036 50 push eax 00150037 8d4528 lea eax,[ebp+28h] 0015003a 50 push eax 0015003b 51 push ecx 0015003c 51 push ecx 0015003d ff5500 call dword ptr [ebp] 00150040 61 popad 00150041 c3 ret </code></pre> <p>put the commands in one line </p> <pre><code>? @$t1+10 ; ? poi(@$t1+10) ; ln poi(@$t1+10); db (@$t1+18) l8; u (@$t1+18) l3; ? poi(@$t1+4c) ; ? poi(@$t1+48) ; ? poi(@$t1+50) ;? poi(@$t1+40) ; lm m ntdll* ; ln poi(@$t1+8) ; ? poi(@$t1+38); db (@$t1+28) l8; du /c 40 poi(@$t1+2c) ; ? poi(@$t1); ln poi(@$t1);.echo patches RtlSetCurwith pattern and sets return address [esp+20]to patched instruction calls ntvirtproct for a pagein ntdll on successloads a dll using LdrLoadDll; Evaluate expression: 1376338 = 00150052 Evaluate expression: 2089936810 = 7c91e7aa (7c91e7aa) Exact matches: ntdll!RtlSetCurrentDirectory_U 0015005a 6a 6c 68 78 e9 91 7c e8 jlhx..|. 0015005a 6a6c push 6Ch 0015005c 6878e9917c push offset ntdll!`string'+0x34 (7c91e978) 00150061 e81501ffff call 0014017b Evaluate expression: 64 = 00000040 Evaluate expression: 32 = 00000020 Evaluate expression: 4096 = 00001000 Evaluate expression: 2089934848 = 7c91e000 start end module name 7c900000 7c9b2000 ntdll (pdb symbols) f:\symbols\ntdll.pdb (7c90d6ee) Exact matches: ntdll!NtProtectVirtualMemory Evaluate expression: 1691353088 = 64d00000 0015006a 60 00 60 00 9a 00 15 00 `.`..... 0015009a "C:\Program Files\Alwil Software\Avast5\snxhk.dll" Evaluate expression: 2089903043 = 7c9163c3 (7c9163c3) Exact matches: ntdll!LdrLoadDll = &lt;no type information&gt; patches RtlSetCurwith pattern and sets return address [esp+20] to patched instruction calls ntvirtproct for a page in ntdll on success loads a dll using LdrLoadDll </code></pre> <p><strong>UPDATE</strong></p> <p>the rwx page in csrss.exe is being created during CSRSRV initialization seems to be heap</p> <p>i set a conditional break after csrss.exe is created on NtAllocateVirtualMemory to print the VadTree on every allocation<br> and i see that the rwx page is inserted while CSRSRV init and a CreateSharedSection is observed in call stack </p> <pre><code>sxe ibp;.reboot </code></pre> <p>on reboot <code>bp NtCreateprocessEx and hit g;kb</code> till csrss.exe is about to be created<br> you can glean the process being created by looking at the unicode_string passed to RtlCreateUserProcess api in the callstack printed<br> dS should print ........................../csrss.exe<br> enter <code>gu</code> go up to allow the process to be created<br> <code>!process 0 1 csrss.exe</code> save eprocess to scratch pad<br> !vad VadRoot<br> you should observe 4 vads in csrss vad tree </p> <p>now set this conditional breakpoint (<code>substitute the saved eprocess inplace of 0x81160020</code> note <code>use 0x notation</code> )<br> bp </p> <pre><code>bp nt!NtAllocateVirtualMemory "!vad @@c++(((nt!_EPROCESS *) 0x81160020)-&gt;VadRoot);kb;.echo \n;dd poi(@esp+8);" </code></pre> <p>if you persist with an access breakpoint you can catch when the rwx page is being added to the ProcessHeapList</p> <p>see below</p> <p>ntdll!RtlCreateHeap+0x5b9: 001b:7c9253de e8a6000000 call <code>ntdll!RtlpAddHeapToProcessList</code> (7c925489)</p> <p>kd> <code>!heap</code> HEAPEXT: Unable to get address of *ntdll!RtlpGlobalTagHeap. Index Address Name Debugging options enabled<br> 1: 00160000<br> 2: 00260000<br> kd> </p> <pre><code>p step over the call </code></pre> <p>ntdll!RtlCreateHeap+0x5be: 001b:7c9253e3 8b45e4 mov eax,dword ptr [ebp-1Ch]</p> <pre><code>kd&gt; !heap </code></pre> <p>Index Address Name Debugging options enabled<br> 1: 00160000<br> 2: 00260000<br> 3: <code>7f6f0000</code> </p> <pre><code>kd&gt; `!process 0 1 csrss.exe` PROCESS `81160020` SessionId: 0 Cid: 01c4 Peb: 7ffde000 ParentCid: 014c DirBase: 06e30000 ObjectTable: e14a7f38 HandleCount: 10. Image: csrss.exe VadRoot `812275c0 Vads 13` </code></pre> <p>dump vadtree</p> <pre><code>kd&gt; `!vad 812275c0` VAD level start end commit 812201d8 ( 1) 0 ff 0 Private READWRITE 812280e8 ( 2) 100 100 1 Private READWRITE 81229dd0 ( 3) 110 110 1 Private READWRITE 81222a88 ( 4) 120 15f 4 Private READWRITE 811f30b8 ( 5) 160 25f 3 Private READWRITE 81223b80 ( 6) 260 26f 6 Private READWRITE 812275c0 ( 0) 4a680 4a684 2 Mapped Exe EXECUTE_WRITECOPY \WINDOWS\system32\csrss.exe 811f4fd8 ( 2) 75b40 75b4a 2 Mapped Exe EXECUTE_WRITECOPY \WINDOWS\system32\csrsrv.dll 811cced0 ( 1) 7c900 7c9b1 5 Mapped Exe EXECUTE_WRITECOPY \WINDOWS\system32\ntdll.dll 8121f440 ( 3) `7f6f0 7f7ef 0 Mapped EXECUTE_READWRITE` Pagefile-backed section 81167108 ( 2) 7ffb0 7ffd3 0 Mapped READONLY Pagefile-backed section 811e1d30 ( 4) 7ffdd 7ffdd 1 Private READWRITE 811e21b0 ( 3) 7ffde 7ffde 1 Private READWRITE Total VADs: 13 average level: 3 maximum depth: 6 </code></pre> <p>dump call stack </p> <pre><code>kd&gt; kb ChildEBP RetAddr Args to Child 0015fda4 75b437b8 00007008 7f6f0000 00100000 ntdll!RtlCreateHeap+0x5be 0015fe28 75b42f9a 001626dd 00000000 00000000 CSRSRV!CsrSrvCreateSharedSection+0x23f 0015ff74 75b430f3 0000000a 001624f0 7c90dc9e CSRSRV!CsrParseServerCommandLine+0x255 0015ff88 4a68115d 0000000a 001624f0 00000005 CSRSRV!CsrServerInitialization+0x95 0015ffa8 4a6818d7 0000000a 001624f0 0016251c csrss!main+0x4f 0015fff4 00000000 7ffde000 000000c8 00000166 csrss!NtProcessStartup+0x1d2 </code></pre> <p>list of breakpoints</p> <pre><code>kd&gt; bl 0 e 8058124c 0001 (0001) nt!NtCreateProcessEx 1 e 805691ea 0001 (0001) nt!NtAllocateVirtualMemory "!vad @@c++(((nt!_EPROCESS *) 0x81160020)-&gt;VadRoot);kb;.echo \n;dd poi(@esp+8);" 2 e 7f6f0000 w 1 0001 (0001) </code></pre> <p>you can follow this methodology with winlogon further below in the chain</p> <p><strong>update to answer comment</strong> </p> <p>the breakpoint @NtAllocateVirtualMemory did not catch the allocation of vad 12<br> which was RWX allotment from vad11 my breakpoint got hit only when vad 13 was allocated<br> and printing vadtree i found that the vads had increased by 2 and one of them was the 7f6f0000 rwx page so maybe another way is used to add the vad to vad tree insted of NtAllocateVirtualMemory it is possible that rwx needs to be reset and isnt being reset needs investigation</p> <p>i can only confirm that the page is indeed HEAP and seems to mapped in almost every process with EXECUTE_READ permissions on all the process vads except in csrss where it is RWX</p> <pre><code>lkd&gt; .logopen c:\check7f6f0page.txt Opened log file 'c:\check7f6f0page.txt' lkd&gt; !for_each_process ".process /p /r @#Process ; !grep -c \"!vad @@c++( ( ( nt!_EPROCESS *) @#Process )-&gt;VadRoot)\" -e \"7f6f0\"" lkd&gt; .logclose Closing open log file c:\check7f6f0page.txt </code></pre> <p>results show this page is mapped in all process</p> <pre><code>lkd&gt; .shell grep "7f6f0 7f7ef 0 Mapped" c:\check7f6f0page.txt &lt;.shell waiting 1 second(s) for process&gt; 86d39250 ( 4) 7f6f0 7f7ef 0 Mapped EXECUTE_READWRITE Pagefile-backed section 86d39250 ( 4) 7f6f0 7f7ef 0 Mapped EXECUTE_READWRITE Pagefile-backed section 86e87fd8 ( 4) 7f6f0 7f7ef 0 Mapped EXECUTE_READ Pagefile-backed section 86e87fd8 ( 4) 7f6f0 7f7ef 0 Mapped EXECUTE_READ Pagefile-backed section 86b96d10 ( 3) 7f6f0 7f7ef 0 Mapped EXECUTE_READ Pagefile-backed section 86b96d10 ( 3) 7f6f0 7f7ef 0 Mapped EXECUTE_READ Pagefile-backed section 86abfe80 ( 3) 7f6f0 7f7ef 0 Mapped EXECUTE_READ Pagefile-backed section 86abfe80 ( 3) 7f6f0 7f7ef 0 Mapped EXECUTE_READ Pagefile-backed section 86eaf3a8 ( 3) 7f6f0 7f7ef 0 Mapped EXECUTE_READ Pagefile-backed section 86eaf3a8 ( 3) 7f6f0 7f7ef 0 Mapped EXECUTE_READ Pagefile-backed section 86b3fda8 ( 4) 7f6f0 7f7ef 0 Mapped EXECUTE_READ Pagefile-backed section 86e77b20 ( 2) 7f6f0 7f7ef 0 Mapped EXECUTE_READ Pagefile-backed section </code></pre> <p>and confirms to structure _HEAP</p> <pre><code>lkd&gt; dt -r nt!_HEAP 0x7f6f0000 +0x000 Entry : _HEAP_ENTRY +0x000 Size : 0xc8 +0x002 PreviousSize : 0 +0x000 SubSegmentCode : 0x000000c8 Void +0x004 SmallTagIndex : 0x1e '' +0x005 Flags : 0x1 '' +0x006 UnusedBytes : 0 '' +0x007 SegmentIndex : 0 '' +0x008 Signature : 0xeeffeeff +0x00c Flags : 0x7008 +0x010 ForceFlags : 8 +0x014 VirtualMemoryThreshold : 0xfe00 +0x018 SegmentReserve : 0x100000 </code></pre> <p>dump of 7f6f0000</p> <pre><code>lkd&gt; dd 7f6f0000 l1c/4 7f6f0000 000000c8 0000011e eeffeeff 00007008 7f6f0010 00000008 0000fe00 00100000 </code></pre> <p>and you can confirm this pattern is indeed heap if you look at ntdll!RtlCreateHeap </p> <pre><code>lkd&gt; !grep -c "uf ntdll!RtlCreateHeap" -e "ebp-24h" 7c925dcd c745dc88050000 mov dword ptr [ebp-24h],588h 7c925de7 c745dcc0050000 mov dword ptr [ebp-24h],5C0h 7c925e87 8145dc80000000 add dword ptr [ebp-24h],80h 7c925eb1 8b75dc mov esi,dword ptr [ebp-24h] 7c93c079 0145dc add dword ptr [ebp-24h],eax </code></pre> <p>dis assemble where the address is used </p> <pre><code>lkd&gt; u 7c925eb1 ntdll!RtlCreateHeap+0x421: 7c925eb1 8b75dc mov esi,dword ptr [ebp-24h] 7c925eb4 83c607 add esi,7 7c925eb7 83e6f8 and esi,0FFFFFFF8h 7c925eba 8bc6 mov eax,esi 7c925ebc c1e803 shr eax,3 7c925ebf 8b4de4 mov ecx,dword ptr [ebp-1Ch] 7c925ec2 668901 mov word ptr [ecx],ax </code></pre> <p>evaluate the expression</p> <pre><code>lkd&gt; ? ((588 + 80 &gt;&gt; 3) + 7) &amp; 0x0fffffff8 Evaluate expression: 200 = 000000c8 </code></pre> <p><strong>update</strong> </p> <p>the RWX page in csrss is <code>_CsrSrvSharedSectionHeap</code> == <code>_CsrSrvSharedSectionBase</code><br> that specifc value is queried from registry and mapped with NtMapViewOfSection<br> or a Section Created using NtCreateSection all of this happens under<br> <code>csrss!main -&gt;csrsrv.dll -&gt;CsrsrvCreateSharedSection</code> </p> <pre><code>reg query "hklm\system\currentcontrolset\control\session manager\subsystems\csrss" ! REG.EXE VERSION 3.0 HKEY_LOCAL_MACHINE\system\currentcontrolset\control\session manager\subsystems\csrss CsrSrvSharedSectionBase REG_DWORD 0x7f6f0000 </code></pre>
3440
2014-01-11T16:48:14.380
<p>On a clean Windows XP SP2 installation running inside a VirtualBox VM, when doing a snapshot with <code>vboxmangage debugvm --dumpguestcore</code> and analyzing it in Volatility, I always find 9 VADs with <code>PAGE_EXECUTE_READWRITE</code> permissions in <code>winlogon.exe</code> process and 1 VAD with the same permission in <code>csrss.exe</code> process. Sometimes there is one in <code>explorer.exe</code> process as well.</p> <p>This is the same for two different Machines one with VirtualBox tools installed and one without.</p> <p>Where do these come from? What are the write permission useful for? Any help is mostly appreciated, thank you!</p>
VADs with RWX permission in winlogon and csrss processes
|windows|digital-forensics|
<p>Another OpenSource library that might of interest.</p> <p><a href="http://www.capstone-engine.org" rel="nofollow noreferrer">Capstone Engine</a></p> <p>It supports several architectures, such as x86 (+AMD64), ARM, PowerPC and SPARC.</p>
3443
2014-01-12T22:56:08.513
<p>One of the major hurdles of x86 disassembly is separating code from data. All available open-source disassembly library only perform a straight line disassembly (starts from the top and skips errors by 1 byte), compared with OllyDBG which apparently uses a control flow disassembly (using opcodes like CALL and JMP) or IDA using heuristics and emulation. However these two aren't open-source.</p> <p>My question is, is there any open-source library or project that uses a better technique than simple straight line disassembly (control flow or heuristics based) ?</p> <p>I stumbled upon a paper using a machine learning approach ? is there an open-source implementation of this approach ?</p>
Open-Source library for Complete Binary Disassembly
|disassembly|x86|
<p>start is the address that IDA pulls from the file header. For PE files this corresponds to (AddressOfEntryPoint + ImageBase). start != main, main is language (C/C++) specific requirement, not all languages require "main".</p> <p>One of the jobs of the code that executes between start and main is to setup all the arguments that main expects (argc, argv, envp) in the manner that main expects to receive them according to the calling conventions of the platform for which the binary was built.</p> <p>IDA attempts to locate main for you because you are often not interested in the code between start and main which is generally just compiler boiler plate code. In some cases IDA will note that there is a symbol named main and just drop you there. In other cases, IDA does what is effectively signature matching against the start code to pick out the address of main. Compilers tend to have unique ways of reaching main, so if (a big if) IDA has a signature for a specific compiler, then it may be able to pick main out for you.</p> <p>You don't mention whether you are using IDA on the Debug or Release version of your binary. In my experience with IDA/Visual Studio, IDA will have a tough time finding main on Debug builds and does a better job on Release builds. If you compare the two different .exe files, you will see that they are vastly different. Specifically flow through Debug builds is much more complicated than through Release builds.</p>
3444
2014-01-13T02:36:33.147
<p>I have newbie question that concerns IDA pro and Visual studio 2010. Basically I started a new "Empty Project" in VS 2010 and added a main function to the .cpp file. Then I compiled it to binary and opened up the binary using IDA Pro. However, I could not locate the main function. Why is that?</p>
Could not find main function in IDA pro?
|ida|disassembly|windows|
<p>I published some tools on github which can do just that: <a href="https://github.com/nlitsme/pyidbutil" rel="noreferrer">https://github.com/nlitsme/pyidbutil</a> and <a href="https://github.com/nlitsme/idbutil" rel="noreferrer">https://github.com/nlitsme/idbutil</a>. The first is written in python, the second in C++, both have similar functionality.</p> <p><code>pyidbutil</code> provides the most low level recovery options: using <code>--pagedump</code> you can dump each page in the file without the need of an intact logical file structure.</p>
3451
2014-01-13T17:11:10.477
<p>I'm reversing an application with IDA. My VM crashed and left the IDA database in a corrupted unpacked state. </p> <p>The next time I tried to load it back, IDA gave me the following error message: <code>The input database is corrupted: CRC32 mistmatch. Continue?</code> a few times, then it quit with the error <code>bTree error: index file is bad</code>. Google-ing these error messages gave no useful results, which is unusual. </p> <p>I'ld like restore the database, or at least extract the data somehow. </p> <p>I've already tried the following:</p> <ul> <li>Zynamics bindiff (couldn't open the IDB, said it's probably opened in another IDA instance, which I guess Is a result of the corrupted data)</li> <li>Manual hex diff - I just can't interpret the output.</li> </ul> <p>At this point I'm thinking of somehow <strong>parsing the IDB</strong> and then diffing that output manually.</p> <p><strong>So, how can I parse/extract data from IDB files?</strong></p> <p><a href="https://reverseengineering.stackexchange.com/questions/3452/how-do-you-manage-backup-your-ida-database">Related.</a></p>
Parsing/Rescuing corrupted IDA database
|ida|binary-analysis|file-format|struct|hex|
<p>The recently added <a href="http://www.hexblog.com/?p=415" rel="noreferrer">database snapshot feature</a> allows you to set up periodical snapshots of your database.</p> <p><img src="https://i.stack.imgur.com/NDVrj.png" alt="IDA Database snapshot manager"></p>
3452
2014-01-13T17:15:33.590
<p>Recently I lost an important IDA database. Up until now, I manually made a copy of my work IDB every day, but that's obviously not a good backup technique. I was wondering how do you manage/backup your IDB. Like make a copy of the current IDB every minute or something like that.</p>
How do you manage/backup your IDA database?
|ida|
<p>try use <a href="https://github.com/drvink/epanos" rel="nofollow">https://github.com/drvink/epanos</a><br> from project page <code>ElectroPaint Automatic No-source Object reaSsembler (a MIPS to C decompiler) This is a very dumb MIPS to C static translator. Consider it a proof of concept, as it has successfully worked</code> The decompiler depends on IDA pro </p> <p>best way is use IDA PRO &amp; your brain </p>
3457
2014-01-14T12:50:48.203
<p><a href="https://www.hex-rays.com/products/ida/" rel="nofollow">IDA</a> can disassemble to assembly. But, reading large assembly blocks with byte shifts, etc, is tedious work. I rather would read pseudo-code. </p> <p>Are there any documents, tutorials or tools for this work targeting MIPS platform? What methods are you people using ? Sorry if this question is off-topic but normal Google search didn't yield much for MIPS.</p> <p>Edit: I try to decompile modem firmware image and look for default telnet password actually since WebUI passwords dont work and my ISP does not know it too.</p>
Is it possible to convert MIPS ASM to code?
|ida|assembly|decompiler|mips|
<p>opening a vc commandprompt using </p> <pre><code>start-&gt;programs-&gt;vc-&gt;vc command prompt </code></pre> <p>Setting environment for using Microsoft Visual Studio 2010 x86 tools. creating a tempdir in desktop for compiling and linking</p> <pre><code>C:\Program Files\Microsoft Visual Studio 10.0\VC&gt;cd "c:\Documents and Settings\Admin\Desktop" C:\Documents and Settings\Admin\Desktop&gt;md pran C:\Documents and Settings\Admin\Desktop&gt;cd pran C:\Documents and Settings\Admin\Desktop\pran&gt;copy con prankasum.cpp ^Z 1 file(s) copied. C:\Documents and Settings\Admin\Desktop\pran&gt;write prankasum.cpp C:\Documents and Settings\Admin\Desktop\pran&gt;type prankasum.cpp #include &lt;stdio.h&gt; int pranit = 2; int&amp; sumit = pranit; int main(int argc, char** argv) { sumit++; return sumit; } C:\Documents and Settings\Admin\Desktop\pran&gt;dir /b prankasum.cpp C:\Documents and Settings\Admin\Desktop\pran&gt;cl /nologo /Zi prankasum.cpp /link /RELEASE prankasum.cpp C:\Documents and Settings\Admin\Desktop\pran&gt;dir /b prankasum.cpp prankasum.exe prankasum.obj prankasum.pdb vc100.pdb </code></pre> <p>opening the exe in ollydbg and navigating to main<br> tab the comment column to show source and in debugging options ask ollydbg to use recogneized args and locals</p> <pre><code>C:\Documents and Settings\Admin\Desktop\pran&gt; ollydbg prankasum.exe 00401000 &gt;PUSH EBP ; { 00401001 MOV EBP, ESP 00401003 MOV EAX, DWORD PTR DS:[sumit] ; sumit++; 00401008 MOV ECX, DWORD PTR DS:[EAX] 0040100A ADD ECX, 1 0040100D MOV EDX, DWORD PTR DS:[sumit] 00401013 MOV DWORD PTR DS:[EDX], ECX 00401015 MOV EAX, DWORD PTR DS:[sumit] ; return sumit; 0040101A MOV EAX, DWORD PTR DS:[EAX] 0040101C POP EBP ; } 0040101D RETN </code></pre> <p>or in windbg</p> <pre><code>prankasum!main: 00401000 55 push ebp 0:000&gt; uf @eip prankasum!main [c:\documents and settings\admin\desktop\pran\prankasum.cpp @ 5]: 5 00401000 55 push ebp 5 00401001 8bec mov ebp,esp 6 00401003 a104b04000 mov eax,dword ptr [prankasum!sumit (0040b004)] 6 00401008 8b08 mov ecx,dword ptr [eax] 6 0040100a 83c101 add ecx,1 6 0040100d 8b1504b04000 mov edx,dword ptr [prankasum!sumit (0040b004)] 6 00401013 890a mov dword ptr [edx],ecx 7 00401015 a104b04000 mov eax,dword ptr [prankasum!sumit (0040b004)] 7 0040101a 8b00 mov eax,dword ptr [eax] 8 0040101c 5d pop ebp 8 0040101d c3 ret 0:000&gt; dv argc = 0n1 argv = 0x00033ba8 0:000&gt; ?? sumit int * 0x0040b000 0:000&gt; ?? pranit int 0n2 0:000&gt; pct 0040101d c3 ret 0:000&gt; ?? sumit int * 0x0040b000 0:000&gt; ?? pranit int 0n3 0:000&gt; x /t /v /q prankasum!sumit prv global 0040b004 4 int * @!"prankasum!sumit" = 0x0040b000 0:000&gt; x /t /v /q prankasum!pranit prv global 0040b000 4 int @!"prankasum!pranit" = 0n3 </code></pre> <p><strong>update</strong></p> <p>explanation for tabbing through comment column </p> <p>each mdi window in ollydbg has a bar in top it can be hidden or shown</p> <pre><code>right click -&gt; appearance -&gt; show bar / hide bar </code></pre> <p>each of the bars have columns and many of the colums can be configured to show different items in cpu window if you <code>repeatedly click the comment column</code> it will cycle through </p> <pre><code>comment / profile/ and source </code></pre> <p>comment will show all the </p> <pre><code>analysis comments / user comments </code></pre> <p>profile will show all the <code>run trace / hittrace/ module and global profile statistics</code></p> <p>for example this <code>strcpy_s</code> was called 50 times during crt initialisation</p> <pre><code>004019EC |. &gt;|CALL prankasu.strcpy_s ; 50. </code></pre> <p>inside this call this loop was called ~2700 times</p> <pre><code>00403D45 /MOV CL, BYTE PTR DS:[EAX] ; 2787. 00403D47 |MOV BYTE PTR DS:[ESI+EAX], CL ; 2787. 00403D4A |INC EAX ; 2787. 00403D4B |TEST CL, CL ; 2787. 00403D4D |JE SHORT prankasu.00403D52 ; 2787. 00403D4F |DEC EDI ; 2737. 00403D50 \JNZ SHORT prankasu.00403D45 ; 2737. 00403D52 TEST EDI, EDI ; 50. </code></pre> <p>if you cycle through to source column</p> <pre><code>strcpy_s is from vc\crt\stdenvp.c:133. _ERRCHECK(_tcscpy_s(*env, cchars, p)); </code></pre> <p>see below</p> <pre><code>004019E9 |PUSH ESI ; _ERRCHECK(_tcscpy_s(*env, cchars, p)); 004019EA |PUSH EBX 004019EB |PUSH EAX 004019EC |CALL prankasu.strcpy_s 004019F1 |ADD ESP, 0C </code></pre> <p>loop is from <code>vc\crt\tcscpy_s_inl</code></p> <pre><code>00403D41 MOV ESI, EDX ; while ((*p++ = *_SRC++) != 0 &amp;&amp; --available &gt; 0) 00403D43 SUB ESI, EAX 00403D45 /MOV CL, BYTE PTR DS:[EAX] 00403D47 |MOV BYTE PTR DS:[ESI+EAX], CL 00403D4A |INC EAX 00403D4B |TEST CL, CL 00403D4D |JE SHORT prankasu.00403D52 </code></pre> <p>cycling to comment back you see</p> <pre><code>004019E9 |. 56 |PUSH ESI ; /Arg3 = 7C90DE6E 004019EA |. 53 |PUSH EBX ; |Arg2 = 00000000 004019EB |. 50 |PUSH EAX ; |Arg1 = 00000000 004019EC |. E8 1D&gt;|CALL prankasu.strcpy_s ; \strcpy_s </code></pre> <p><code>options-&gt;debugging options-&gt;cpu-&gt;select show symbolic address</code> will make <code>XXXXXX [40xxxx]</code> to be shown as </p> <pre><code>xxxxxx [sumit] </code></pre> <p><code>options -&gt;debugging options-&gt;analysis-&gt;select show args and locals in procedure</code> will make all <code>ebp+XX</code> to <code>arg.1 arg.2</code> and all <code>ebp-XX</code> to <code>local.1 local.2</code> </p> <pre><code>both ollydbg 1.10 and 2.01 behave similarly </code></pre> <p><code>full</code> or <code>partial (stripped down )</code>symbolic information in any acceptable format (<code>map tds pdb dbg</code> ) is <code>**mandatory**</code> <code>**requirement**</code> </p>
3468
2014-01-16T03:48:21.593
<p>In Visual Studio I have written simple code,</p> <pre><code>int pranit = 2; int&amp; sumit = pranit; int main(int argc, char** argv) { sumit++; return sumit; } </code></pre> <p>I used OllyDbg to Disassamble, but I am not able to find where <code>sumit</code>, <code>pranit</code> are defined in assembly. Though doing some string search I got following details:</p> <pre><code>Names in ConsoleA, item 313 Address=013B8004 Section=.data Type=Library Name=sumit Names in ConsoleA, item 257 Address=013B8000 Section=.data Type=Library Name=pranit </code></pre> <p>How to find, where and how it is used in assembly code. Also, I want to find out both address and value of these global variables. </p>
How to find how global variables defined in binary
|disassembly|debuggers|binary-analysis|c++|
<p>First, your platform is very important ( mine is Windows )</p> <p>In Windows WinDbg + <code>!exploitable</code> is one of fast analyze options. it is <a href="http://msecdbg.codeplex.com/" rel="nofollow">here</a></p> <p>Additionally I use WinDbg + <code>!analyze</code> to determine standard name of bug... it is default WinDbg extension.</p> <p>Finally, as the nature of bugs is unknown (in your case) it is not an easy way to detect root cause.</p>
3471
2014-01-16T13:52:56.277
<p>My daily job is analyzing reported proof of concept files that exploits document viewers. People who report vulnerabilities in document viewers just give me the PoC and vulnerable version number. They usually fuzz stuff and find offset that leads to stack overflows etc. Which means they do not give me info about the root cause of the vuln. So only with the vulnerable binary and the PoC, I need to analyze following things:</p> <ol> <li><p>Does the PoC actually work?</p></li> <li><p>In which part of the binary is vulnerable? (ex. no argument checking in function A ... blah blah; I need to know this because I have to contact the vendor to fix the vuln)</p></li> </ol> <p>I am new to this field and currently this is how I do it(I analyze in XP).</p> <ol> <li><p>Run the PoC</p></li> <li><p>look at the call stack when there is a exception->follow them</p></li> <li><p>Check whether SEH is corrupted -> set breakpoint on the corrupted SEH to find the instruction that overflows the stack</p></li> </ol> <p>By playing around I can find the assembly instruction that triggers the exploit. However, it is hard to backtrack all the way to the root cause. Assembly instruction that overflows is usually in the library but the vuln is not the library, it is the user program that maliciously called the library right? </p> <p>I don't know if I made my point clear but need some tips doing this kind of reverse engineering. </p>
Do you have tips analyzing reported PoC(exploit) files?
|exploit|vulnerability-analysis|seh|
<p>I actually don't think that there was any mix up. In fact, there exist two disassembly techniques : static &amp; dynamic. The definitions provided here come from this 2003 publication on code obfuscation : <a href="http://www.cs.arizona.edu/solar/papers/CCS2003.pdf" rel="noreferrer">http://www.cs.arizona.edu/solar/papers/CCS2003.pdf</a></p> <ul> <li><p><strong>Static disassembly</strong> is where the file being disassembled isn't executed during the course of disassembly.</p></li> <li><p><strong>Dynamic disassembly</strong> is where the file is being executed on some input and the execution is being monitored by an external tool (debugger, ...) to identify the instructions being executed.</p></li> </ul> <p>This link (<a href="http://www.maqao.org/publications/madras_techreport.pdf" rel="noreferrer">http://www.maqao.org/publications/madras_techreport.pdf</a>) provides an interesting coverage of techniques used by some disassemblers &amp; binary instrumenters. Though it is not exhaustive and doesn't directly answer your question, you'll find more references to check.</p> <p>About dynamic &amp; static binary analysis, these two techniques are mainly performed for profiling applications. The purpose is to acquire information about hot spots, memory access patterns, ... </p> <ul> <li><p>The <strong>static analysis</strong> is usually based on analyzing the program without the need to execute it. It is mostly based on finding patterns, counting memory references, ... The Wikipedia page about <em>Static program analysis</em> is, from my point of view, incomplete but still a good read.</p></li> <li><p>The <strong>dynamic analysis</strong>, on the other hand, involves executing the program and requires instrumentation of basic blocks such as loops, functions, ... The instrumentation consists of inserting probes at the entry and exit of a basic block which will measure the time according to a certain metric (CPU cycles, time in µs, ...). The information gathered after analysis is usually used to optimize the application by performing loop unrolling with a suitable unroll factor, vectorization if possible (SSE, AVX, Altivec, ...), etc.</p></li> </ul> <p>Many tools perform both the latter techniques : Intel's VTune, MAQAO, DynInst, gprof, ...</p> <p>I myself have written a <strong>GCC</strong> plugin, which you can find on my Github under the path <strong>/yaspr/zebuprof</strong>, which does instrumentation at the source level and performs static &amp; dynamic analysis.</p> <p>I hope this clarifies things a bit.</p>
3473
2014-01-17T19:16:10.480
<p>I am told that tools like <strong>IDA Pro</strong> are static disassembly tool, and tools like <strong>OllyDbg</strong> are dynamic disassembly tool.</p> <p>But from the using experiences on these tools, I don't think there is any difference between the tools in <strong>disassembly</strong> procedure.</p> <p>Basically all you need to do is load binary file into IDA or OllyDbg, and they will use certain recursive disassembly algorithm to disassembly the binary and give you the output.</p> <p>Am I wrong..? Then what is the difference between static disassembly and dynamic disassembly..?</p> <p>Thank you!</p>
What is the difference between static disassembly and dynamic disassembly?
|ida|disassembly|ollydbg|disassemblers|
<p>All of them are feasible. By definition obfuscating code transformation is transformation that preserves functional equivalency of obfuscated program, so there is no any difference between multi-thread and single-thread programs from this point of view.</p>
3476
2014-01-18T21:06:45.170
<p>According to my knowledge, several obfuscation strategies are widely used(or at least described in academic) like:</p> <ul> <li><p>complicating control flow</p> <ol> <li>inserting bogus control-flow</li> <li>control-flow flattening</li> <li>jump through branch functions</li> <li>opaque values from array aliasing</li> </ol></li> <li><p>Opaque Predicates</p> <ol> <li>opaque predicates from pointer aliasing</li> </ol></li> <li><p>dynamic obfuscation</p> <ol> <li>self-modifying state machine</li> <li>code as key material</li> </ol></li> </ul> <p>From the examples they give when introducing these obfuscation ways, multi-thread program has not been talked.</p> <p>So I am wondering whether these strategies are feasible(or even feasible, but not very practical) in multi-thread programs?</p>
What is the difficulty/advantage to obfuscate a multi-thread program?
|obfuscation|deobfuscation|multi-process|
<p>There are CPU instructions and OS APIs that can achieve this, such as</p> <pre><code>RDPMC RDTSC GetLocalTime GetSystemTime GetTickCount KiGetTickCount QueryPerformanceCounter timeGetTime </code></pre> <p>The result is achieved by requesting the current time, performing some kind of CPU-intensive operation (or requiring that someone debugging the code does so, such as single-stepping), requesting the time again, and then calculating the delta between the two. If the delta is significantly larger than you would expect in native execution mode, then it suggests the presence of the debugger. Note, however, that this is far from an accurate method, since that result is indistinguishable from a system under heavy load.</p> <p>This is covered in some detail in section "(C) Execution Timing" in my "Ultimate" Anti-Debugging Reference (<a href="http://pferrie.host22.com/papers/antidebug.pdf" rel="nofollow">http://pferrie.host22.com/papers/antidebug.pdf</a>)</p>
3477
2014-01-19T05:55:16.910
<p>I have seen several anti-debug strategies, and I am wondering if there are some anti-debugger methods that can evaluate the program running time, thus detecting the exist of debugger.</p>
How to detect a debugger using some "time" checking strategies?
|debuggers|anti-debugging|
<p>I'd say it's a very useful tool to have in the arsenal, but your use of it will depend upon your ultimate goals. Personally, I use it a fair bit on binary application assessments, but that's not the case for everyone. As I said, it largely depends on what you want to be doing.</p> <p>At the end of the day, you will see cryptography being used in applications if you end up doing reverse engineering work. Understanding and breaking that cryptography may or may not be part of your job, but it's always nice to have at least a basic understanding of the field. It's always a nice +1 on your resume, too.</p> <p>In terms of <em>what</em> you should learn, I'd say avoid the "classic cipher" stuff and go straight for the meat and potatoes. I can count on one hand the number of times I've had to break a simple custom transposition cipher or substitution cipher in a real product. They're just not used in reality, and if the client is using such awful "crypto" then that's already a major issue to flag to them - breaking it becomes a moot point.</p> <p>You want to be looking into:</p> <ul> <li>Simple xor ciphers (one-time pad, two-time pad, repeated key xor)</li> <li>Stream ciphers</li> <li>Use of initialisation vectors (IVs) to avoid key re-use issues</li> <li>Stream cipher malleability</li> <li>Block ciphers</li> <li>Block cipher padding</li> <li>Block cipher modes of operation (Cipher Block Chaining especially)</li> <li>Issues with Electronic Code Book (ECB) mode</li> <li>IVs in block ciphers</li> <li>Malleability in CBC</li> <li>Padding oracle attacks</li> <li>Compression oracle attacks (e.g. CRIME)</li> <li>Hash functions (MD5, SHA1, etc.)</li> <li>Hash collisions and the birthday paradox</li> <li>Message Authentication Codes (e.g. HMAC construction)</li> <li>Asymmetric cryptography (e.g. RSA)</li> <li>Key exchange mechanisms (e.g. Diffie-Hellman)</li> <li>Hybrid cryptosystems (i.e. using asymmetric to send key, symmetric to encrypt)</li> <li>The list of common issues around SSL/TLS and PKI: <ul> <li>Not validating CA properly</li> <li>Not validating common name properly</li> <li>Not validating expiry or valid from dates</li> <li>Allowing weak ciphers (e.g. NULL, DES)</li> <li>Allowing weak certificate signatures (e.g. MD5)</li> <li>etc... (see OWASP for more)</li> </ul></li> </ul> <p>The list is pretty big, but it's stuff you can pick up from Wikipedia and other various places online at your own pace. If you understand half of the topics above at a level strong enough to identify a weak implementation, then you're very much on track. Almost every single product I've ever done work that has used crypto has had an issue in that list.</p>
3480
2014-01-19T11:00:44.017
<p>Is understanding of Cryptography really important for a reverse engineer? </p> <p>Thanks.</p>
How much Cryptography knowledge is important for reverse engineering?
|cryptography|
<p>The reason for targeting the RWX pages is that the injected code most often carries data in the same region as the code, and requires that the data are writable. Thus the W flag is needed. The X flag is required to support DEP, in case the process opted in, or if the system enforces it for everyone. The R flag is entirely optional when requesting the page. Windows will ensure that it is set anyway. It is of course possible for malware to allocate two regions, one [R]X and one [R]W, and write only to the writable section, but I don't recall ever seeing this technique being used. For one thing, it complicates the injected code.</p>
3482
2014-01-19T11:57:18.490
<p>I've seen a few memory forensics tutorials, which start by looking for injected code in the "victim's" process memory. They always seem to find the injected code in pages which have RWX access (i.e. PAGE_EXECUTE_READWRITE). </p> <p>Does this assumption always hold? Does code injected (e.g. by malware) into the process memory of a "victim", always belong to a page with RWX access? Or can the page access be changed, by the code that is injected? If so, how can this change be done via winapi?</p>
Does code injected into process memory always belong to a page with RWX access?
|windows|memory|winapi|
<p>One way that a process can detect the presence of injected threads is by the use of Thread Local Storage. When a thread is injected, the host's Thread Local Storage callbacks will be called unless the injector takes care to disable that. If the callbacks are called, then the host can query the start address of the new thread and determine if it is within the host's defined code region (which only the host would know) See the Thread Local Storage section in my "Ultimate" Anti-Debugging Tricks paper (<a href="http://pferrie.host22.com/papers/antidebug.pdf">http://pferrie.host22.com/papers/antidebug.pdf</a>) for an example of that.</p> <p>While this does not detect everything (some malware use cavities within the host's existing code section in order to perform the injection), it will certainly catch some things.</p> <p>However, the short answer to your question is actually "no". There isn't a way for a process to "know" in <em>all</em> cases that something has been injected. It is "yes" for most cases, but not all of them.</p>
3487
2014-01-19T18:48:44.367
<p>There are many tutorials which show how to detect injected code into process memory. However, this generally requires using a debugger. </p> <p>Is it possible for a process to somehow detect if it has been injected by another process using winapi? If so, how?</p> <p>More specifically, are there any "fixed/likely" characteristics of injected code? For instance, from <a href="https://reverseengineering.stackexchange.com/questions/3482/does-code-injected-into-process-memory-always-belong-to-a-page-with-rwx-access">this question</a> it appears that injected code can be characterized by always appearing in pages that have the following protection flags set: PAGE_READWRITE_EXECUTE, PAGE_EXECUTE_READ, PAGE_EXECUTE_WRITECOPY and possibly (but unlikely) PAGE_EXECUTE. Can you point out other characteristics of injected code?</p>
Can a Windows process check if it has been injected by another process?
|windows|memory|winapi|
<p>I'd suggest taking a look at <a href="http://x64dbg.com/#start" rel="nofollow noreferrer">x64dbg</a>. Despite what the dumb name might suggest, there <em>is</em> a 32 bit version. With that out of the way, I would give <a href="https://github.com/x64dbg/ScyllaHide" rel="nofollow noreferrer">ScyllaHide</a> a try.</p>
3489
2014-01-19T19:49:39.587
<p>Title says it all. I'm trying to RE a video game which is packed with Themida and the second I attach OllyDbg it crashes. When on XP, I can use StrongOD and PhantOm but neither of these work properly on Windows 7. I could use the XP machine via RDP but my Win 7 machine is much less irritating to use. </p> <p>Does anybody have any suggestions? </p>
Are there any OllyDbg anti-debug/anti-anti-debug plugins what work with Windows 7 / NT 6.x?
|windows|ollydbg|anti-debugging|packers|
<p><a href="https://hexinator.com/" rel="nofollow noreferrer">Hexinator</a> </p> <ul> <li><p>has a similar feature to binary templates of 010 Editor that is called a "grammar". It allows to insert numbers, strings, structs and binary blobs. If that's not enough, it has scripting capabilities in Python and Lua</p></li> <li><p>the values can then be edited nicely (e.g. in decimal instead of hex). The hex area can be highlighted.</p></li> </ul> <p>Drawbacks:</p> <p>at the time of writing it seems to have issues with more than one open grammar + one open file. When opening a second file for the same grammer, it crashed. Save early and save often.</p> <p>Screenshot of a partially analyzed file:</p> <p><a href="https://i.stack.imgur.com/OaHcn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OaHcn.png" alt="Screenshot"></a></p>
3495
2014-01-20T04:45:41.053
<h1>Problem Statement</h1> <p>I have a file composed entirely of data structures; I've been trying to find a tool that will enable me to open this file, and declare (perhaps) a type and offset such that i may work with the presumed primitive data type individually.</p> <p>e.g. I declare the 4 bytes located at offset 0x04 to be a 32-bit unsigned integer, and would like to inspect the value at this location (read as big-endian perhaps) and then work with this integer individually (perhaps see what it looks like encoded as a 4-byte ascii string and attempt to read it, etc.)</p> <h1>Specifics</h1> <p>I have a 4096 byte file containing C-structs with member elements as integers ranging from 16-64 bits in length; the following is an example:</p> <pre><code>struct my_struct { uint_32 magic } // sizeof(my_struct) == 0x04 </code></pre> <p>In this case, magic = 'ball', and so when the file is opened in a text editor it reads as 'llab...', and obviously can also be represented as a 32-bit integer</p> <h1>Question</h1> <p>Is there a tool that enables static analysis of flat data structure files?</p> <h1>What I've considered thus far as a solution</h1> <p>I've considered writing a command line tool in Python to do this, but if something already exists I'd prefer to save time, and perhaps learn more about this topic by using a tool designed by someone more experienced. If it seems to you that I am going about this incorrectly (this is my first serious exploration into this kind of reversing) please guide my understanding, thanks.</p> <h1>Where I have already researched</h1> <p>Googled 'reverse engineering tools' and browsed the links</p> <p>Checked wikipedia's reverse engineering pages</p> <p>Tried some first principles reasoning</p> <p>Checked pypi</p> <h1>Results</h1> <p>There are three completely valid and correct answers, but I've marked the most detailed and least expensive of them as correct, because it is the most accessible to members of the community reviewing this question.</p>
What tools exist for excavating data structures from flat binary files?
|disassembly|tools|static-analysis|
<p>I lack 9 reputation points, so sadly I can't comment the great answer by w_s. ;)</p> <p>Just for completeness, the concept described is known in graph theory as "Tarjan's Algorithm" for finding strongly connected components. </p> <p><a href="https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm" rel="nofollow noreferrer">Wikipedia</a> has a nice animation that helps following the steps.<img src="https://zippy.gfycat.com/ActualSinfulConch.gif" alt="Tarjan&#39;s Algorithm"></p> <p>For study, here is another (more formal) <a href="http://www.logarithmic.net/pfh-files/blog/01208083168/tarjan.py" rel="nofollow noreferrer">Python implementation</a>, it's the one I have used for finding loops in functions in <a href="https://bitbucket.org/daniel_plohmann/simplifire.idascope/src/f353158d25b331c69e1b6ac360aa46cfff672dd3/idascope/core/helpers/Tarjan.py?at=master" rel="nofollow noreferrer">IDAscope</a> but it's easily adapted for finding recursive functions.</p>
3498
2014-01-20T12:49:03.350
<p>How can I detect/mark recursive functions in IDA?</p> <p>Trivial method would be to check every function's call list and if it calls itself then it's recursive. I'ld like to put a comment or some kind of indicator that would help me distinguish these functions. </p>
Detecting recursive functions in IDA
|ida|ida-plugin|functions|callstack|automation|
<p>This seems like a security ex question instead of one about reverse engineering. Therefore I'd keep my answer short.</p> <p>This <em>should</em> not be possible. Simply as malware would abuse this, what you could do if you want this is find a 0day in kernel space and get SYSTEM privileges. Back in 2010 there was someone from China who has posted a method on the code project(if I recall correctly). It's now hosted on the exploit-db..</p> <p><a href="http://www.exploit-db.com/bypassing-uac-with-user-privilege-under-windows-vista7-mirror/" rel="nofollow">http://www.exploit-db.com/bypassing-uac-with-user-privilege-under-windows-vista7-mirror/</a></p> <p>Goodluck on your research.</p>
3501
2014-01-20T15:32:35.123
<p>Is it possible for a running process to turn off User Account Control (UAC) via a Windows API call? If so, which API calls are needed? </p> <p>I found this <a href="https://stackoverflow.com/questions/852867/disable-vista-uac-per-application-or-elevate-privileges-without-prompt">interesting question/answer</a> on stackoverflow, however, I'm interested if there is some other way to do it.</p>
Can a process disable UAC via WinAPI without prompting the user?
|windows|winapi|
<p>I worked with some types of symbol tables. All these types are very different and can not be defined as something that allows automatic detection. It can be some kind of list of tuples like (pointer to name, type, pointer to object, [something else]). There are a lot of other variants also. Any time I succeeded to recognize symbol table it was done by manual inspection of analyzed dump. </p> <p>My methodology to find such symbol table is as follows (assuming that IDA didn't find it automatically):</p> <p>1 - Find all strings in the binary, sort them and inspect results. If you see a lot of potential object names (function names, global variable names etc) you can suspect that you can use it and it is possible that there is symbol table in the binary. </p> <p>2 - Choose some strings from the set. Check references to them. If you find these references in something that looks like array of structures or any other regular data structure it might be your symbol table.</p> <p>3 - When you understand what is the structure of your symbol table you can rename your objects with simple IDAPython script.</p>
3503
2014-01-21T00:24:41.743
<p>Is there a practical way to find if the raw binary (firmware image for example) has symbol table ? Finding start or end of it ? And if it exists is it a single block or can it be seperate multiple blocks with another data inbetween ? </p>
How to determine if binary has symbol table
|disassembly|firmware|symbols|
<p>This is probably a bit further outside the normal reverse engineer's toolchest, but still a possibility. <a href="http://www.chromium.org/developers/design-documents/software-updates-courgette" rel="nofollow">Courgette</a> is the codename of the update mechanism behind Chromium and thus Chrome. Quote:</p> <blockquote> <p>Courgette transforms the program into the primitive assembly language and does the diffing at the assembly level:</p> <pre><code>server: asm_old = disassemble(original) asm_new = disassemble(update) asm_new_adjusted = adjust(asm_new, asm_old) asm_diff = bsdiff(asm_old, asm_new_adjusted) transmit asm_diff client: receive asm_diff asm_old = disassemble(original) asm_new_adjusted = bspatch(asm_old, asm_diff) update = assemble(asm_new_adjusted) </code></pre> </blockquote> <p>Of course this is limited by the number of CPU architectures. You didn't state your requirements (unless it was written with invisible pixels ;))</p>
3507
2014-01-21T16:31:55.710
<p>I know some binary diff tool like VBinDiff and others.</p> <p>Currently I have a large number of binary, around 500.</p> <p>So I am looking for a binary tool to quantitatively evaluate the difference of binaries..</p> <p>Like evaluate the difference of binary 10 and binary 100 is 56%. Difference of binary 50 and binary 200 is 78%.</p> <p>Is there any tool like this? </p> <p>Thank you!</p>
Is there any tool to quantitatively evaluate the difference of binary?
|binary-analysis|bin-diffing|
<p><code>bp abpatch ".if mm3 = aaaaaa0000000000 {} .else {gc}"</code></p>
3510
2014-01-21T21:37:51.397
<p>i am analysing a crash, the crash occurs in a function that its always on use, if set a break point in this function always stop the program.</p> <p>When the crash occurs, overwrite mm3 register, i want when overwrite mm3 with my values use the breakpoint.</p> <p>the original estate of mm3 register its 0:0:e3cb:f144, when crash its aaaa:aa00:0:0.</p> <p>when try this :</p> <pre><code>bp abpatch ".if @mm3 = aaaa:aa00:0:0 {} .else {gc}" </code></pre> <p>error, i cant use ":" on bp</p> <p>if try this:</p> <pre><code>bp abpatch ".if @mm3 = aaaaaa000:0 {} .else {gc}" </code></pre> <p>or</p> <pre><code>bp abpatch ".if (@mm3 &amp; 0x0`ffffffff) = 0x0`aaaaaa0000 {} .else {gc}" </code></pre> <p>Program crash and dont stop.</p> <p>commonly i analyse the crash with -4 at the address that function crash, but now this function is always running on the program.</p> <p>I put aaaa for easy location.</p> <p>I think too need stop just before mm3 have got this values, but i don't know :( </p> <p>How I can put a break point on a mm3 register?? any other solution for this ??</p> <p>Any help or suggestion? . Thank you in advanced.</p> <p>Regards</p>
Specifying an MMX register's value in WinDbg
|windbg|
<blockquote> <p><a href="https://github.com/deresz/funcap" rel="noreferrer"><strong><code>funcap</code></strong></a> uses IDA's debugging API to record function calls in a program together with their arguments (before and after).</p> <p>This is very useful when dealing with malware which uses helper functions to decrypt their strings, or programs which make many indirect calls.</p> </blockquote> <p><img src="https://i.stack.imgur.com/gtH5U.png" alt="a"></p>
3516
2014-01-23T10:56:31.777
<p>What I'm doing now is placing an awful lot of comments about function variable values, global variable values as comments in my IDA database, which I find ugly after a while and obviously not a best practice. </p> <p>I was wondering if it's possible to store runtime variable values of your target process from a dynamic debugging session in your IDA database(or any other storage/tool) in some way. For example you run IDA debugger, or some external tool like olly/immunity, and store the encountered values (globals, function parameters) in IDA, so you can see actual values when doing your static analysis in IDA (for example on mouse over).</p> <p>I don't know if anybody done this before, but it think it would be a really helpful feature.</p> <p><strong>Is this possible, any similar tool/solution out there you know of? How do you process static+dynamic data of the reversed application?</strong> </p> <p>I'm not tied to IDA, but I find that environment to be most fitting for storing my result data. I'm interested in any solution.</p>
Static analysis data combined with dynamic analysis knowledge
|ida|binary-analysis|static-analysis|dynamic-analysis|debugging|
<p>As you may suspect, it very much depends on the hardware. In general, you are correct, JTAG and/or UARTs can be often be used to get a copy of the firmware (downloading a firmware update from the vendor is usually the easiest way of course, but I'm assuming that is not what you mean). </p> <p>JTAG implementations typically allow you to read/write memory, and flash chips are typically "mapped" into memory at some pre-defined address (finding that address is usually a matter of Googling, experience, and trial and error); thus, you can use tools like <a href="http://urjtag.org/" rel="noreferrer">UrJTAG</a> and <a href="http://openocd.sourceforge.net/" rel="noreferrer">OpenOCD</a> to read the contents of flash.</p> <p>UART is just a serial port, so what interface or options it provides (if any) is entirely up to the developer who created the system; most bootloaders (e.g., <a href="http://www.denx.de/wiki/U-Boot" rel="noreferrer">U-Boot</a>) do allow you to read/write flash/memory, and will dump the ASCII hex to your terminal window. You then would need to parse the hexdump and convert it into actual binary values. Again, YMMV and there may be no way to dump memory or flash via the UART.</p> <p>Other devices may have other mechanisms that provide similar functionality; for example, Microchip's PIC microcontrollers use <a href="http://en.wikipedia.org/wiki/In-circuit_serial_programming" rel="noreferrer">ICSP</a> (In Circuit Serial Programming) interfaces to read, write, and debug firmware. Such interfaces are usually proprietary, and may or may not be documented (Microchip's is well known).</p> <p>Vendors may take steps to protect or disable debug interfaces such as JTAG, UART and ICSP, but often you can <a href="https://reverseengineering.stackexchange.com/questions/2337/how-to-dump-flash-memory-with-spi">dump the flash chip</a> directly (this is usually faster than JTAG/UART, but may require some de/soldering). For devices such as microcontrollers that have the flash chip built-in (i.e., the flash chip is not exposed to you), you may need to resort to <a href="http://www.bunniestudios.com/blog/?page_id=40" rel="noreferrer">more advanced techniques</a> for defeating such copy-protections.</p> <p>Personally, since I don't deal much with microcontroller based systems, dumping the flash chip directly is usually my go-to for grabbing a copy of the firmware from the device.</p>
3526
2014-01-23T16:55:36.967
<p>Appreciate it's a broad question, but despite days of Googling I haven't found straight forward explanation of the general principle of how to "capture" or copy an unkown firmware from a piece of hardware. </p> <p>I gather once you have it you can begin to use various tools to analyse it, but what I want to understand is how to get it in the first place. </p> <p>From what i understand you need to connect to it via a JTAG or UART connection , after that I'm a bit lost.</p>
How do I extract a copy of an unknown firmware from a hardware device?
|hardware|firmware|
<p>It was classified as exploitable because it's a write access-violation to a non-null address. In theory, an attacker may be able to exploit this vulnerability to write arbitrary code to an arbitrary address.</p>
3529
2014-01-23T18:17:48.977
<p>I have a crash that is exploitable, the information is this:</p> <pre><code> Exploitability Classification: EXPLOITABLE Recommended Bug Title: Exploitable - User Mode Write AV starting at myfunction!mycomponet+0x0000000000018204 (Hash=0xad0842a8.0x0as0d4ca) User mode write access violations that are not near NULL are exploitable. </code></pre> <p>I only have experience on stack overflow, and here don't see eip overwrite.</p> <p>I know that fault, is when pass to vulnerable function a value greater than 80000001, the crash occurs.</p> <p>But I don't know which type of vulnerability is it, heap overflow, integer, format string , command injection etc.. </p> <p>My question, with the exploitable response indicate the vulnerabilities ??? I don't understand the exploitable response.</p> <p>Any suggestion or indication ?</p> <p>Sorry for my newbie question, I am a beginner in exploiting.</p>
Help on Exploitable response
|exploit|windbg|
<p>Since we're talking windows (and 5 years later) how about this: intall the program, go to the install dir and get the jar(s) from there. Now you can decompile the jar directly.</p>
3532
2014-01-24T07:42:44.657
<p>Is there any way to get a jar file from a jar wrapped using a exe wrapper. I have an exe file and I know that it was wrapper using exe wrapper (<a href="http://launch4j.sourceforge.net/">launch4j</a> to be precise). How do I unwrap this jar to get back the jar. I have seen that I can unwrap it in Linux using <a href="http://fileroller.sourceforge.net/">fileroller</a>, how do I do it in windows</p> <pre><code>ADD : How is it different if it wrapped using wrappers other than launch4j </code></pre>
Get jar back from wrapped(into exe) jar
|decompilation|executable|jar|
<p>Yes, it's because of pipelining.</p> <p>From <a href="http://winarm.scienceprog.com/arm-mcu-types/how-does-arm7-pipelining-works.html" rel="nofollow noreferrer">http://winarm.scienceprog.com/arm-mcu-types/how-does-arm7-pipelining-works.html</a> --</p> <blockquote> <p><img src="https://i.stack.imgur.com/sIrwO.gif" alt="ARM pipelining"></p> <p>PC (Program Counter) is calculated <strong>8 bytes ahead</strong> of current instruction.</p> </blockquote>
3541
2014-01-24T12:12:47.157
<p>I was just disassembling and debugging an ARM binary for fun and I noticed something unusual. Consider the following set of instructions:-</p> <pre><code> 0x00008058 &lt;+4&gt;: mov r1, pc 0x0000805c &lt;+8&gt;: add r1, r1, #24 0x00008060 &lt;+12&gt;: mov r0, #1 </code></pre> <p>I tried setting a breakpoint at <code>0x0000805c</code> and checked the value of the register <code>r1</code>. I was expecting to see <code>0x0000805c</code> -- however, interestingly the value is <code>0x8060</code>.</p> <p>Why is this? Is this because of some sort of instruction pipelineing? </p>
ARM debugging interesting behavior
|debugging|arm|
<p>Sorry this should be a comment but dont have enough reputation.</p> <p>This is too vague for people to help you. Do you have the disassembly around the crash? It only crashes when what is 8000000001? That makes it sound like potentially an integer overflow. Where is it writing? Can you control the address that its writing to? Do you have control of what is being written?</p>
3544
2014-01-24T18:02:26.497
<p>I have found a vulnerability that write access-violation to a non-null address, but I don't know how exploit.</p> <p>I know that fault, is when pass to vulnerable function a value greater than 80000001, the crash occurs.</p> <p>But my problem, I only know typical buffer stack overflow, and need learn how exploit this, and knowing what is vulnerability (heap, format string, integer overflow, etc).</p> <p>I am confused because only crash when is 800000001 (negative), not with 80000000 or 80000002. With this response:</p> <pre><code>Exploitability Classification: EXPLOITABLE Recommended Bug Title: Exploitable - User Mode Write AV starting at myfunction!mycomponet+0x0000000000018204 (Hash=0xad0842a8.0x0as0d4ca) User mode write access violations that are not near NULL are exploitable. </code></pre> <p>What vulnerability is and how exploit ? Any suggestion or recommended lecture ?</p>
How exploit write access-violation to a non-null address
|exploit|windbg|
<p>Yes, it is different. Binary exploitation intended to change behaviour of the binary, and reverse engineering intended to understand how it works.</p> <p>BInary exploitation requires some reverse engineering, reverse engineering doesn't necessarily requires binary exploitation.</p> <p>The best example I know about it is overcoming DRM protections of media content. It requires a lot of reverse engineering and almost not requires binary exploitation.</p>
3550
2014-01-25T11:34:23.220
<p>I am a beginner in Reverse Engineering and am trying to improve my skill by participating in any CTF's I can and solving CrackMe's. I am trying to find out why Binary Exploitation and Reverse Engineering are always separated as two different topics.</p> <p>My Question is simple:</p> <blockquote> <p>Is Reversing different from Binary Exploitation?</p> </blockquote>
Difference Between Binary Exploitation and Reverse Engineering?
|ida|ollydbg|binary-analysis|
<p>The ASEC file is a TwoFish encrypted container which in turn is a dm-crypt volume that gets mounted by Linux's device mapper at /mnt/asec/[app_id] (The AppID is based on the package name). The 128-bit key to the container can be found in /data/misc/systemkeys but this file requires root access for reading. You can read exactly how the encryption works <a href="http://nelenkov.blogspot.com.br/2012/07/using-app-encryption-in-jelly-bean.html" rel="noreferrer">here</a>. Moving on, the mounted volume will contain an unencrypted apk of the application. In order to change the desired data, it's necessary to understand where the data is stored and how it is done. For that, the application will have to be reverse-engineered by either decompilation - <a href="https://reverseengineering.stackexchange.com/questions/42/decompiling-android-application/46#46">list of tools</a> - or by disassembly to smali and posterior debugging using tools such as <a href="https://code.google.com/p/android-apktool/" rel="noreferrer">apktool</a> and <a href="https://code.google.com/p/androguard/" rel="noreferrer">androguard</a>. </p> <p>Sometimes, these steps can be bypassed as the app uses a database file in it's directory (usually /data/data//) that you can edit with any SQLite editor, such as <a href="https://play.google.com/store/apps/details?id=oliver.ehrenmueller.dbadmin" rel="noreferrer">SQLite Debugger</a> or using the sqlite3 set included by default in Android, or keeps the relevant information in memory in a way that is trivial to change it with a memory editor such as <a href="http://gameguardian.net/" rel="noreferrer">GameGuardian</a>. However, the data can be stored server-side and transmitted through the network when app is started and then kept in memory in a not easily modifiable way so that in order to be able to change it, you will need to not only reverse-engineer the application but also to intercept and modify the traffic it receives in order to transmit the new information to the application.</p>
3558
2014-01-26T09:36:22.437
<p>How to edit .asec or compare two .asec files witch are stored by app at location mnt/.android_souce/app name.asec. This file get updated whenever data connection is on / while using app to upload and download app data . This folder not able to access on non rooted Phone but can able to access on pc with usb . What are capable software that can read and writing easily .asec file ?</p>
How to edit .asec file?
|android|java|hex|
<p>Use either <a href="http://sourceware.org/binutils/docs/binutils/readelf.html" rel="nofollow">readelf</a> utility with -w (or --debug-dump) command line switch or <a href="https://sourceware.org/binutils/docs/binutils/nm.html" rel="nofollow">nm</a> utility with -a command line switch.</p>
3569
2014-01-28T01:18:24.130
<p>I recently read that GCC annotates the source-code into the debug symbols it produces, although I haven't found any examples on how to retrieve this. </p> <p>If this is true, how can I view the data in the debug symbols, mainly the code annotations.</p> <p>What would be the steps I need to complete starting with a gcc compiled dll with debug symbols.</p>
How to extract information from dll compiled in gcc with debug symbols?
|decompilation|debuggers|dll|debugging|compilers|
<p>That should really say "the identifier of the process that is hosting the thread", since that's what it is. The snapshot that is created by the Toolhelp APIs is system-wide, so in order to understand where a thread lives, you need its process ID. That would be meaningless if it said process A, if process A created a remote thread in process B and then exited. In that case, the PID belonging to process A at the time of creation might end up being reused by the next process that is created, and obviously be completely unrelated to the thread.</p> <p>Consider this a different way: creating a remote thread is merely making a request to the remote process to create the thread, so the remote process is the one who creates thread. There is no concept of who made the request.</p>
3589
2014-01-31T08:30:03.253
<p>The <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms686735%28v=vs.85%29.aspx" rel="nofollow"><code>THREADENTRY32</code> structure</a> contains a member called <code>th32OwnerProcessID</code>, which is described as: </p> <blockquote> <p>The identifier of the process that created the thread.</p> </blockquote> <p>I'm not sure if I understand how the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682437%28v=vs.85%29.aspx" rel="nofollow"><code>CreateRemoteThread</code> function</a> works. However, I would expect that the thread created by <em>Process A</em> via <code>CreateRemoteThread</code>, in the address space of <em>Process B</em>, would have the <code>th32OwnerProcessID</code> equal to the ID of <em>Process A</em> (if we were to take the description of the <code>th32OwnerProcessID</code> as quoted above). I was a bit surprised to see that it is actually equal to the ID of <em>Process B</em>.</p> <p>Could someone please explain why this is so? And how to get the ID of the actual creator of the thread, i.e. <em>Process A</em> in my example?</p>
How to get the PID of the a thread's creator (not owner, not host)
|winapi|thread|multi-process|
<p>Every compressed chunk in the config.bin file is prepended by a small 3-DWORDs header containing the following information: </p> <ol> <li>the length of the uncompressed xml chunk. This value is 0x10000 for all but the last chunk</li> <li>the length of the compressed zlib chunk</li> <li>the cumulative length of the file after the chunk is appended. This value is 0x0 for the last chunk.</li> </ol> <p>These headers can be used to avoid false positives during the detection of the chunks: valid chunks will have either a 0x10000 on the first field or a 0x0 on the third field. The headers can also be used to verify the uncompressed data size.</p> <pre><code>import re import zlib import struct def extract_config_xml(config_bin): config_xml = b'' for zlib_chunk in re.finditer('\x78\xda', config_bin): zlib_chunk_start = zlib_chunk.start() zlib_chunk_header = config_bin[zlib_chunk_start - 12: zlib_chunk_start] xml_chunk_length, zlib_chunk_length, config_bin_length = \ struct.unpack('&gt;LLL', zlib_chunk_header) if xml_chunk_length == 0x10000 or config_bin_length == 0: zlib_chunk_end = zlib_chunk_start + zlib_chunk_length zlib_chunk = config_bin[zlib_chunk_start: zlib_chunk_end] xml_chunk = zlib.decompress(zlib_chunk) assert xml_chunk_length == len(xml_chunk) config_xml += xml_chunk return config_xml with open('config.bin', 'rb') as f: print extract_config_xml(f.read()) </code></pre>
3593
2014-02-01T03:51:19.833
<p>so I have backup from my router its zte zxv10h201l and its linux based but I can not identify type of compression of this file. Here is couple of first &quot;lines&quot; of it</p> <pre><code> 00000000 99 99 99 99 44 44 44 44 55 55 55 55 aa aa aa aa |....DDDDUUUU....| 00000010 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 |................| 00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 |...............@| 00000040 00 01 00 00 00 00 00 80 00 00 23 90 00 00 00 00 |..........#.....| 00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000080 04 03 02 01 00 00 00 00 00 00 00 0b 5a 58 56 31 |............ZXV1| 00000090 30 20 48 32 30 31 4c 01 02 03 04 00 00 00 00 00 |0 H201L.........| 000000a0 01 4c 54 00 00 23 78 00 00 20 00 40 34 b7 80 e9 |.LT..#x.. .@4...| 000000b0 80 47 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 |.G..............| 000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000000d0 00 00 00 00 00 20 00 00 00 03 d0 00 00 04 18 78 |..... .........x| 000000e0 da ed 58 61 53 da 30 18 fe be 5f c1 f1 03 b0 29 |..XaS.0..._....)| 000000f0 88 db 4e 77 07 6d d1 de 00 3b e8 64 b7 2f 5e 6c |..Nw.m...;.d./^l| 00000100 23 e6 2c 49 2f 4d 11 f6 eb 97 da 56 0b da 34 45 |#.,I/M.....V..4E| 00000110 77 d3 13 94 2b 94 27 6f 9e be 79 f2 bc 6f 7b 6c |w...+.'o..y..o{l| 00000120 f6 bf 7d 6a 88 d7 b1 7b 15 34 08 5c a0 93 a6 d9 |..}j...{.4.\....| 00000130 ef c3 08 35 1b 13 7a 67 d0 98 f0 93 26 68 a6 a0 |...5..zg....&h..| 00000140 7b a0 38 dd 18 d3 93 a6 56 38 79 ff 83 39 ca 02 |{.8.....V8y..9..| 00000150 d8 03 9b 5c d3 66 63 09 03 01 03 e2 4f 17 ef 8e |...\.fc.....O...| 00000160 96 be 80 d6 d5 40 27 fd a6 03 fd 30 3b 7d 98 fc |.....@'....0;}..| 00000170 92 1e f5 ec d8 4e 8e cd 83 c2 dc 07 62 f2 8c ef |.....N......b...| </code></pre> <p>Afer that I connected ttl-rs232 to router and when backup button is pressed on my router web UI this show up in log</p> <pre><code> =~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2014.01.31 22:58:29 =~=~=~=~=~=~=~=~=~=~=~= 04:15:12 [webd][Info] [upload.c(1138)my_upload_file] Enter my_upload_file. 04:15:12 [webd][Info] [upload.c(1343)my_upload_file] Begin download file.(filetype : config) 04:15:12 [DB][Info] [dbc_mgr_file.c(1644)dbGetBinFile] DB get cfg start 04:15:12 [FLASHRW][Info] [proc_file_mod.c(1204)file_open] open file: /proc/cfg/db_user_cfg.xml 04:15:12 [FLASHRW][Info] [proc_file_mod.c(1334)file_close] close file: /proc/cfg/db_user_cfg.xml 04:15:12 [DB][Info] [dbc_mgr_file_en(570)dbcCfgFileIsEnc] FileIsEncry return 0 04:15:12 [FLASHRW][Info] [proc_file_mod.c(1204)file_open] open file: /proc/cfg/db_user_cfg.xml 04:15:12 [FLASHRW][Info] [proc_file_mod.c(1334)file_close] close file: /proc/cfg/db_user_cfg.xml 04:15:12 [DB][Info] [dbc_mgr_file_si(198)dbcCfgFileSign] SignFile return 0 04:15:12 [DB][Info] [dbc_mgr_file_ve(277)dbcCfgFileVersi] add FileVersion return 0 04:15:12 [DB][Warn] [dbc_mgr_file.c(1708)dbGetBinFile] DB download cfg(iRet:0) 04:15:12 [webd][Info] [upload.c(644)create_config_f] user cfg path:/var/tmp/version-cfg </code></pre> <p>So I searched router firmware for srings of text like above and found this line</p> <blockquote> <p>deflate 1.1.4 jean loup gailly</p> </blockquote> <p>nearby some of strings, after quick google it seams that this is zlib and its used for compression of &quot;something&quot;, after that with my little knowlage I tried to decompress it with comands like this</p> <blockquote> <p>printf &quot;\x1f\x8b\x08\x00\x00\x00\x00\x00&quot; |cat - zlib.raw |gzip -dc</p> <p>cat /tmp/data | openssl zlib -d</p> </blockquote> <p>but with no luck, later on I found similar file on web with no compression on it, so I take a look and it seams that header of file and couple more &quot;byts&quot; are the same as my compressed file and Im not sure how I can skip these first &quot;byts&quot; and try to decompress rest of &quot;data&quot;, also from log u can see some type of &quot;Sign&quot; which are also need to be skiped, here is how similar file which is not compressed look like</p> <pre><code> 00000000 99 99 99 99 44 44 44 44 55 55 55 55 aa aa aa aa |....DDDDUUUU....| 00000010 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 |................| 00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 |...............@| 00000040 00 02 00 00 00 00 00 80 00 04 5e 85 00 00 00 00 |..........^.....| 00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000080 3c 44 42 3e 0a 3c 54 62 6c 20 6e 61 6d 65 3d 22 |&lt;DB&gt;.&lt;Tbl name="| 00000090 44 42 42 61 73 65 22 20 52 6f 77 43 6f 75 6e 74 |DBBase" RowCount| 000000a0 3d 22 31 22 3e 0a 3c 52 6f 77 20 4e 6f 3d 22 30 |="1"&gt;.&lt;Row No="0| 000000b0 22 3e 0a 3c 44 4d 20 6e 61 6d 65 3d 22 49 46 49 |"&gt;.&lt;DM name="IFI| 000000c0 6e 66 6f 22 20 76 61 6c 3d 22 30 31 30 31 30 32 |nfo" val="010102| 000000d0 30 31 30 34 30 30 30 30 30 30 30 31 30 36 30 31 |0104000000010601| 000000e0 30 34 30 30 30 30 30 32 31 32 35 30 30 30 30 30 |0400000212500000| 000000f0 30 30 35 30 30 31 30 30 30 30 35 30 30 32 30 30 |0050010000500200| 00000100 30 30 35 30 30 33 30 30 30 30 22 2f 3e 0a 3c 2f |0050030000"/&gt;.&lt;/| 00000110 52 6f 77 3e 0a 3c 2f 54 62 6c 3e 0a 3c 54 62 6c |Row&gt;.&lt;/Tbl&gt;.&lt;Tbl| 00000120 20 6e 61 6d 65 3d 22 45 54 48 22 20 52 6f 77 43 | name="ETH" RowC| 00000130 6f 75 6e 74 3d 22 34 22 3e 0a 3c 52 6f 77 20 4e |ount="4"&gt;.&lt;Row N| 00000140 6f 3d 22 30 22 3e 0a 3c 44 4d 20 6e 61 6d 65 3d |o="0"&gt;.&lt;DM name=| 00000150 22 56 69 65 77 4e 61 6d 65 22 20 76 61 6c 3d 22 |"ViewName" val="| 00000160 49 47 44 2e 4c 44 31 2e 45 54 48 31 22 2f 3e 0a |IGD.LD1.ETH1"/&gt;.| 00000170 3c 44 4d 20 6e 61 6d 65 3d 22 4c 44 57 44 56 69 |&lt;DM name="LDWDVi|</code></pre> <p><a href="https://www.dropbox.com/s/562nctdc7r8xhmo/default-config.bin/" rel="nofollow noreferrer">Here</a> u can find compressed backup.</p> <p>Edit: On picture u can see comparasion of two files db_user_cfg.xml (file from log) on (left side) and that &quot;same file&quot; but when is &quot;backedup&quot; on right side</p> <p><img src="https://i.stack.imgur.com/7Mjd5.png" alt="Zte compare" /></p>
RE Compressed backup file,router linux based so is it compresed with zlib?
|linux|
<p>Meanwhile Hex Rays does have an x64 Decompiler (adding this answer for people reading now, at the time of Jason's answer the decompiler was not yet available), see the <a href="https://www.hex-rays.com/products/decompiler/news.shtml" rel="nofollow noreferrer">news</a> page:</p> <blockquote> <p>2014/06/04 The x64 decompiler has arrived!</p> </blockquote> <p>And from the <a href="https://www.hex-rays.com/products/ida/order.shtml" rel="nofollow noreferrer">order</a> page:</p> <blockquote> <p>The Decompiler software is available for 5 platforms: x86, x64, ARM32, ARM64, and PowerPC. While x64, ARM64, and PowerPC decompilers can run only on top of IDA Pro, the x86 and ARM32 decompilers can run on top of both IDA Starter or IDA Pro</p> </blockquote>
3594
2014-02-01T19:52:07.403
<p>I have a 64 bit program im debugging. I found the function i need to learn more about to potentially "fix" the problem (there is no source code available for the program).</p> <p>To speed things up, i wanted to decompile and go over it in pseudocode as my assembler is still quite weak. However i did not find any working solutions that would work with x64.</p> <p>I am using only x64 windows platform so linux/mac solutions wont work (hopper is only 32 bit on windows). Hex-rays is x86 as well. There was ida-decompiler python scripts that i didn't get to work no matter what i did ( no output or pseudocode was generated).</p> <p>Is there any other solutions i could try that does support x64 and has pseudocode support?</p>
64 bit Pseudocode decompiler
|tools|decompiler|x86-64|
<ol> <li><p>IDA will use this variable name if you renamed it somehow. This variable name is local for the function because it is a stack offset. </p></li> <li><p>There is no better way than name modification. You can solve this specific kind of error by writing script that renames anything in <code>.rodata</code> section by applying <code>g_</code> prefix to any object in it.</p></li> </ol> <p>The code will look like this:</p> <pre><code>#Use carefully, I didn't check this code #beware errors import idautils import idc prefixes = {".rodata": "g_ro_", ".data": "g_"} #Passing over all non default names for (ea, name) in idautils.Names(): seg_name = idc.SegName(ea) # if the name is in required segment if seg_name in prefixes: if not name.startswith(prefixes[seg_name]): # renaming it by adding required prefix # if the prefix is not added yet name = prefixes[seg_name] + name idc.MakeName(ea, name) </code></pre>
3596
2014-02-01T21:44:23.937
<p>I use IDA Pro 6.1 to disassembly ELF file, which is compiled on 32 bit Linux, gcc 4.6.3</p> <p>I modified the code and try to make it reassemble, and I find a problem here(this is directly created by IDA Pro):</p> <pre><code>main proc near ...... mov dword ptr [esp+4], offset msgid ...... ...... foo proc near msgid = dword ptr -18d ...... mov [esp+1Ch+msgid], 1 section .rodata msgid db 'extra operand %s',0 </code></pre> <p>So if I do some modify work and assembly it use <strong>nasm</strong>, it will produce this error:</p> <pre><code>error: label or instruction expected at start of line </code></pre> <p>targeting on this line:</p> <pre><code>msgid db 'extra operand %s',0 </code></pre> <p>If I modify it like this:</p> <pre><code>main proc near ...... mov dword ptr [esp+4], offset msgid111 ...... ...... foo proc near msgid = dword ptr -18d ...... mov [esp+1Ch+msgid], 1 section .rodata msgid111 db 'extra operand %s',0 </code></pre> <p>Then no error in this part.</p> <p>So my questions are:</p> <ol> <li>Why IDA Pro will use variable name as the macro name?</li> <li>Is there any better way to bypass this error than modify the variable name?</li> </ol> <p>Thank you!</p>
Why IDA Pro will generate this kind of code(mess up macro name and variable name)?
|ida|disassembly|assembly|nasm|
<p>You are looking at binary that is compiled as position-independent code. The <code>call _i686_get_pc_thunk_bx</code> and the following addition to <code>ebx</code> shows just that. If you take a look at the disassembly, you'll see that the address of the <code>add ebx, 292Eh</code> plus 0x292E will result in the first address of the GOT. That why in the next line, _dso_handle_ptr is addressed in such a "funny" way.</p> <p>IDA however is nice enough to show you this in the disassembly as you would normally only see 0xSOMEADDR[ebx]. </p> <p>In terms of the second question: that line retrieves a global variable, puts it into <code>eax</code> and then checks if it is zero or not. So, you should not just "delete" that line since then the <code>test eax, eax</code> would use some old value of <code>eax</code> (which I am sure you will not like all that much).</p>
3597
2014-02-01T22:03:52.943
<p>Test platform is Linux 32 bit.</p> <p>I use IDA Pro to disassembly the basename from coreutils 8.5 compiled by gcc 4.6.3</p> <p>Here is a code snippet generated by IDA Pro</p> <pre><code> call _i686_get_pc_thunk_bx add ebx, 292Eh sub esp, 18h mov eax, ds:(__dso_handle_ptr - 804DFF4h[ebx] test eax, eax jz short loc_804B6F8 mov eax, [eax] loc_804B6DB: mov [esp+1Ch+var_14], eax mov eax, [esp+1Ch+arg_0] mov dword [esp+1Ch+var_18], 0 mov [esp+1Ch+var_1C], eax call __cxa_atexit add esp, 18h pop ebx retn loc_804B6F8: xor eax, eax jmp short loc_804B6DB </code></pre> <p>I don't understand this line:</p> <pre><code>mov eax, ds:(__dso_handle_ptr - 804DFF4h[ebx] </code></pre> <p>and after searching the code, I can only find this:</p> <pre><code> __dso_handle dd 0 </code></pre> <p>in the .data section.</p> <p>So my questions are:</p> <ol> <li>What is the meaning of this line..? Is it like a version checking stuff..?</li> <li>Can I just safely remove this line without affecting the functionality of the code..?</li> </ol>
What is the meaning of this code generated by IDA Pro?
|ida|disassembly|assembly|disassemblers|nasm|
<p>For the <code>.bss</code> section something like the following may work for you:</p> <pre><code>import idaapi import idc print "section .bss" start = idaapi.get_segm_by_name(".bss").startEA end = idaapi.get_segm_by_name(".bss").endEA item = idc.NextHead(start - 1, end) while item != BADADDR: next = idc.NextHead(item, end) if next != BADADDR: print "%s: resb %d" % (idc.Name(item), next - item) else: print "%s: resb %d" % (idc.Name(item), end - item) item = next </code></pre> <p>although in practice, <code>NextHead</code> does not seem to pick up anything named as <code>unk_XXXX</code>, so you may need to further iterate over the section to determine whether there are any cross references to an address to decide whether to associate a declaration with it.</p> <p>For the <code>.data</code> and <code>.rodata</code> sections you will need to change to <code>db/dw/dd/...</code> as appropriate and additionally dump the content of the related items. The challenge for items in these sections is to properly determine the size of each item and correctly choose <code>db/dw/dd/...</code> Dumping raw bytes with <code>db</code> may be the simplest approach here.</p>
3603
2014-02-02T15:07:21.333
<p>test Platform is 32 bit Linux ELF and 32 bit Windows PE.</p> <p>I use IDC script to extract all the functions from binary and dump into a file, then do the analysis based on the examples in IDA Pro book.</p> <p>But I don't know how to extract .data .rodata and .bss sections from ELF file using IDC script.</p> <p>Currently I use IDA Pro to create a asm file, and use Python script to do the string parser work, extracting .data .rodata and .bss sections from this asm file.</p> <p>Basically It works fine, but a really tedious modification work is required, and as my test base is relatively large(notepad++ and others..), I have to spend lots of time do modify work to correctly extract this three sections.</p> <p>My question is "is there any idc script/idapython script can extract .data .rodata and .bss sections from ELF file?" and any solutions on Windows are also welcomed.</p> <p>Thank you!</p>
How to extract all the rodata data and bss section using IDC script in IDA Pro?
|ida|disassembly|ida-plugin|idapython|
<p>Z3 is an SMT solver. Its job is to decide the satisfiability of formulas passed in by a user, where the formulas may mix terms from the various theories that Z3 supports. Coincidentally, in order to make its own job easier by producing a "simpler" formula than the one passed in by the user, it implements a simplifier which is not very sophisticated technologically and largely consists of term rewriting rules.</p> <p>Although the user could pose a query regarding the equivalence of two expressions, Z3's only involvement would be to solve the formula. I.e. Z3 will not generate candidates for you. It is your job as the user to provide the candidates and query an SMT solver as to their satisfiability.</p> <p>In general, synthesizing functions is a challenging task in program synthesis. These queries are naturally posed in second-order logic, but modern SMT solvers support only restrictions of first-order logic. To sidestep this problem, some published work takes the route of eliminating most candidates from consideration ahead of time, thereby keeping the number of equivalence queries small. See for example <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.93.8843&amp;rep=rep1&amp;type=pdf">this paper</a> or <a href="http://spinroot.com/spin/Workshops/ws13/spin2013_submission_16.pdf">this one</a>. Another approach is to specify a template describing what the candidate functions are allowed to look like; a simple example is <a href="http://theory.stanford.edu/~ataly/Papers/pldi12.pdf">this paper</a>. These approaches keep the formula to first-order logic, or even quantifier-free.</p> <p>In general, you should research program synthesis.</p>
3606
2014-02-02T17:57:00.803
<p>I would like to know if there are efficient ways to simplify arithmetic formula expression over bit-vectors with <a href="http://z3.codeplex.com/" rel="nofollow">Microsoft Z3</a>. But, first, I would like to explain a bit the problem. Lets start with an example:</p> <pre><code>x + y == (x ^ y) + 2 * (x &amp; y) </code></pre> <p>Both <code>x + y</code> and <code>(x ^ y) + 2 * (x &amp; y)</code> are, in fact, coding the addition over bit-vectors. Of course, the right hand formula is used to confuse a reverser when found in the binary program. I try to find tools and techniques to simplify the obfuscated formula and find the simpler form of the formula (left-hand).</p> <p>For this, I looked at the Python interface of Z3, trying to see what I can get out of it. So, defining the obfuscated formula is done like this:</p> <pre><code>&gt;&gt;&gt; from z3 import * &gt;&gt;&gt; x = BitVec('x', 32) &gt;&gt;&gt; y = BitVec('y', 32) &gt;&gt;&gt; fun1 = (x ^ y) + 2 * (x &amp; y) </code></pre> <p>Now, lets try to simplify this function with the help of the built-in function <code>simplify</code>:</p> <pre><code>&gt;&gt;&gt; simplify((x ^ y) + 2 * (x &amp; y)) (x ^ y) + 2*~(~x | ~y) </code></pre> <p>Not really convincing... But, lets try to prove the equivalence with <code>x + y</code>:</p> <pre><code>&gt;&gt;&gt; prove((x ^ y) + 2 * (x &amp; y) == x + y) proved &gt;&gt;&gt; prove((x ^ y) + 2 * (x &amp; y) == x - y) counterexample [y = 2164268032, x = 2139094080] </code></pre> <p>I added a negative result to show that it is also possible to disqualify a formula.</p> <p>So, if the <code>simplify</code> function is not really convincing, it is still possible to try, in a brute-force manner to compare the unknown formula with a list of simpler and usual formula one after one. But, this way seems extremely inefficient to me. I guess I am missing some smarter algorithms to simplify formula.</p> <p>I would like to know if there are some already existing tools or well-known techniques to perform in a more efficient manner than the brute-force approach. So, if someone has some hints or comments about this, it would be more than welcome.</p>
How to efficiently simplify obfuscated formula in QF_BV logic with Z3?
|deobfuscation|
<p>I do not think code morphism is <em>the</em> or <em>an</em> answer to this question. </p> <p>What the question was about is obfuscating the algorithm implementation by using less common or undocumented assembly instructions. This can actually be done by some compilers when extensive optimizations are turned on. For example compilers like the <strong>Intel C Compiler</strong>, <strong>GCC</strong>, or <strong>PGI</strong> can autovectorize loops when matched to some internal patterns (<em>reductions</em>, <em>matrix multiplications</em>, ...) and when the target architecture supports vectorization. Other optimizations can lead to extremely tricky assembly code but still, it can always be reversed since the compiler performs no <strong>explicit</strong> obfuscation and because most of what the compiler does is pattern matching. Of course if you associate a high level pattern to a low level one, well, you lose the obfuscation and your code can easily be reversed. Thus techniques as the one you're looking for can only be performed by hand either by writing high level code using compiler intrinsics and alternative constructs or at the assembly level. </p> <p>If you are really interested in obfuscation techniques I recommend you going over Jan CAPPAERT's PhD thesis : <a href="https://www.cosic.esat.kuleuven.be/publications/thesis-199.pdf">https://www.cosic.esat.kuleuven.be/publications/thesis-199.pdf</a>, it covers some nice techniques used not only on malware but on industrial software too. The bibliography is quite rich. You can also check this talk given by Sean Taylor at Defcon on how to make the compiler do the obfuscation : <a href="https://www.defcon.org/images/defcon-17/dc-17-presentations/defcon-17-sean_taylor-binary_obfuscation.pdf">https://www.defcon.org/images/defcon-17/dc-17-presentations/defcon-17-sean_taylor-binary_obfuscation.pdf</a>.</p> <p>About polymorphism, it is a nice obfuscation technique though it is rarely used in malware nowadays, and for many reasons. One of them is that few, if none, malware authors write code in assembly anymore, and most use frameworks and engines. You have to keep in mind that writing obfuscated assembly code is an art ... and that now it is used to harden the reverse engineering process for profit not for the challenge.</p> <p>I've been working on a <strong>GCC</strong> plugin that adds an optimization pass which performs code obfuscation on the IR - internal representation (GIMPLE) - of a code before applying another obfuscation pass at the assembly level. The interesting thing about this approach is that you have the CFG (Control Flow Graph) of the program at compile time, and you can apply many obfuscation algorithms and techniques in order to break it into other equivalent CFGs and then assess which suites best and use it throughout the remaining compilation phases.</p> <p>Hope my post helps.</p>
3617
2014-02-04T10:07:14.080
<p>Is there any kind of software or research or paper which discusses replacement of frequent x86 instructions with ones which are less common and thus less understandable to the attacker (floating point/SSE/Virtualization/undocumented) while still maintaining the functionality?</p> <p>For example, I wan to replace this</p> <pre><code> PUSH EBP MOV EBP,ESP ... PUSH DWORD [0x0BEE] PUSH 3 CALL &lt;check&gt; TEST EAX,EAX JE &lt;0xabcd&gt; PUSH &lt;text1&gt; PUSH [EBP+5] CALL &lt;MessageBox&gt; 0xabcd: PUSH &lt;text2&gt; PUSH [EBP+5] CALL &lt;MessageBox&gt; </code></pre> <p>with this</p> <pre><code> AESKEYGENASSIST VFMSUBADDPD MOVLPS PMADDUBSW RET FLDL2T CMPXCHG8B AESKEYGENASSIST VFMSUBADDPD MOVLPS CMPXCHG8B STOSW VMLAUNCH etc etc </code></pre> <p>while still performing the same operation.</p>
Replacing common x86 instructions with less known ones
|obfuscation|x86|
<p>As 3asm_ suggested, it would be best to try API Monitor first.</p> <p>If that doesn't work, though, an alternative would be to attach to IE with a debugger and set logging breakpoints on the entrypoint of each method in the OCX. You can then see the order in which IE calls them and the arguments that are passed.</p>
3621
2014-02-05T10:17:30.453
<p>I have a OCX control which is loaded in Internet Explorer (used to show stream from IP camera). To see live video I have to properly connect to server etc. using methods of created object. The best idea will be to monitor which methods are called from IE. <strong>Is there any possibility to monitor these calls</strong> and parameters with for example plug-in for IE or some API monitor program?</p> <p><img src="https://i.stack.imgur.com/9Dy2r.png" alt="OCX information in OLEView"> <img src="https://i.stack.imgur.com/vNGuJ.png" alt="Methods details"></p>
OCX methods execution monitoring
|com|
<ol> <li>You can write your hooking library (DLL) which will patch the API you are targeting. This patch will just print to file/console the parameters and continue back to the original function. There will be no stops on the way. To actually hook the APIs you will need to inject the DLL into the target application. You can use <a href="http://research.microsoft.com/en-us/projects/detours/" rel="nofollow">Detours from Microsoft</a> as and example which is a software package for re-routing Win32 APIs underneath applications. <ol> <li><a href="http://www.codeproject.com/Articles/2082/API-hooking-revealed" rel="nofollow">API hooking revealed</a> - an article on <strong>CodeProject</strong> with examples. But you can find on the net endless examples for this technique.</li> <li><a href="http://www.codeproject.com/Articles/30140/API-Hooking-with-MS-Detours" rel="nofollow">API Hooking with MS Detours</a></li> </ol></li> <li><a href="http://www.rohitab.com/apimonitor" rel="nofollow">API Monitor</a> - API Monitor is a free software that lets you monitor and control API calls made by applications and services. Its a powerful tool for seeing how applications and services work or for tracking down problems that you have in your own applications.</li> <li><a href="http://en.wikipedia.org/wiki/Instrumentation_%28computer_programming%29" rel="nofollow">Process instrumentation</a> - <code>instrumentation refers to an ability to monitor or measure the level of a product's performance, to diagnose errors and to write trace information.</code> <ol> <li><a href="http://en.wikipedia.org/wiki/Pin_%28computer_program%29" rel="nofollow">Pin is a platform for creating analysis tools</a> - <code>A pin tool comprises instrumentation, analysis and callback routines.</code> <a href="http://resources.infosecinstitute.com/pin-dynamic-binary-instrumentation-framework/" rel="nofollow">Here</a> you can find an intro to writing pintool which you can extend to your needs. This is pretty powerful technique and more hard to adapt among all that I've listed here. The original site from <a href="http://software.intel.com/en-us/articles/pintool/" rel="nofollow">Intel</a> and specifically at <a href="http://software.intel.com/sites/landingpage/pintool/docs/62732/Pin/html/index.html#FunctionArguments" rel="nofollow">Finding the Value of Function Arguments</a> can help you with what you are looking for.</li> </ol></li> </ol>
3623
2014-02-05T11:46:52.193
<p>I'm reversing an application written in C. I have a certain function that I want to log runtime, without pausing/stopping the application. </p> <p>My desired values of that function are: </p> <ul> <li><code>[ESP + 4]</code> which is the length of a buffer </li> <li><code>[ESP + 8]</code> which is a <em>pointer</em> to a string buffer</li> </ul> <p>Then I want to read the buffer and write it into a file.</p> <p>First thing I was told to use is Immunity's <code>LogBpHook</code>, which worked great, but it stops the application and it becomes really slow due to this, because it's a frequently called function. </p> <p>Then I tried to setup <code>FastLogHook</code> which sounds more like what I'm after. It injects a log stub and stores encountered values, but as far as I know it can not perform further memory readings like the one I described above anyway (if it can please tell me). Also it constantly crashed my application so it's out of the question.</p> <p>So I left with the idea of injecting a customized code stub that would take care of further readings and logging of the values into a file. Is there any tool that could do this, or I have to manually write+inject this assembly?</p> <p><strong>How can I log function parameters runtime, without stopping the application?</strong></p>
Runtime memory reading with injection
|assembly|memory|immunity-debugger|functions|callstack|
<p>Try</p> <pre><code>main(){ Wait(); open_log(); do_analysis(); close_log(); Exit(0); } </code></pre>
3634
2014-02-07T00:50:10.930
<p>In my IDC script I open a log file, do some analysis, write in the file and close the file like this:</p> <pre><code>main(){ open_log(); do_analysis(); close_log(); } </code></pre> <p>Currently I am using this script on command line, and I am trying to close the GUI after analysis(or be more exact, don't not open GUI while analyzing)</p> <p>Here is command line I use:</p> <pre><code>"z:\ida6.1\idaq.exe -A -SfunctionEnumeration.idc z:\Linux\targetfile" </code></pre> <p>I modified my script like this:</p> <pre><code>main(){ open_log(); do_analysis(); close_log(); Wait(); Exit(0); } </code></pre> <p>Currently it will generate the log file, but no content in it..</p> <p>It seems that IDA Pro is closed before the write operation(or close operation) on the log file, but I don't understand why because Wait() is called in my script...</p> <p>I read the IDC manual and haven't find anything useful...</p> <p>Could anyone give me some help? Thank you!</p>
Why the Wait() in idc script can not work on IDA Pro?
|ida|
<p>in odbg version 1.10 that will only <code>log eax</code> not the string<br> in the expression box put either <code>STRING [EAX]</code> or <code>UNICODE [eax]</code> as the case may be<br> or with plain eax select <code>pointer to ascii or unicode string</code> in <code>decode expression as</code> dropdown box to log strings </p> <p>Log data, item 0 Message=eax = 1001590 [eax] = 74636868 string [eax] = hhctrl.ocx unicode [eax] =</p> <p><code>odbg 210</code> will decode expression automatically </p> <pre><code>01012475 INT3: plain eax = 1001590 ASCII "hhctrl.ocx" dword ptr eax = 74636868 (1952671848.) ascii string ptr eax = hhctrl.ocx </code></pre>
3639
2014-02-07T14:22:53.713
<p>Given a breakpoint at an expression <code>MOV EDI, EAX</code>, how can you automatically log/write to file the referenced string whenever the breakpoint is hit?</p>
OllyDbg: Automatically extract string when breakpoint is hit
|ollydbg|debuggers|
<p>Since you are only interested in variables that are read from, not written to, I'll assume you're talking about global variables since it makes no sense to have a local variable that's never written to.</p> <p>You can write an IDC script to iterate through each global variable and use <a href="https://www.hex-rays.com/products/ida/support/idadoc/313.shtml" rel="nofollow"><code>RfirstB</code>, <code>RnextB</code>, and <code>XrefType</code></a> to determine which global variables are read from, written to, or both.</p>
3642
2014-02-07T21:14:43.947
<p>Analysing a bootmanager : I'm trying to track all variables which are only read from, and not written to... which will give me the external variables it uses...</p> <p>Is there any such functionality in IDA pro free? Can I write a plugin for it in the free version? Any other options for this purpose? Any other tool which can do this?</p>
How to find memory addresses which are read from but not written to
|ida|disassembly|static-analysis|memory|
<p>What is the target program? Is it known to have an antihack? (If so, who makes it?) Are you on a 32-bit or 64-bit OS?</p> <p>Use GMER/<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682619%28v=vs.85%29.aspx" rel="nofollow"><code>EnumDeviceDrivers()</code></a>/etc and check for drivers that "antihack.dll" might be loading. If there is a driver, load its binary into IDA and start reversing, and if you're on 32-bit grab an anti-rootkit program (GMER, kernel detective, XueTr) and remove their hooks.</p> <blockquote> <p>"they tell something about 'antihack.dll', for which, though, I don't found any reference to using Dependency walker and Pe Explorer"</p> </blockquote> <p>Maybe the antihack.dll is loaded into a seperate process? Try monitoring process creation or just use taskmanager and see if there's a seperate process that is killing your Olly. Alternatively, it could just be a delayed LoadLibrary call. Also, the program might be injecting antihack.dll into your process instead of loading it (unlikely in this case).</p> <p>If you're on a 32-bit OS, PhantOm with driver enabled should be enough to protect your Olly. If it isn't, try looking for other plugins that hide Olly. On a 64-bit OS, you would need to write your own driver, though with PatchGuard around even that will probably not be enough since they could be detecting your Olly by its window names/positions/hierarchy.</p> <p>If you want to attach to a program with an antihack feature you would preferably partially or completely disable the antihack first. Stealthing an invasive debugger to get it to attach to an already running protected process is not a nice approach. Start with static analysis in IDA, find a way to start the program in Olly and debug the startup process, or start with less invasive dynamic analysis (Cheat Engine).</p>
3649
2014-02-08T18:12:38.997
<p>I want to run an OllyDbg and attach it to some starting later process.</p> <p>But the problem is, that process is very aggressive: it kills OllyDbg on start, and I also can't run OllyDbg later because that process then crashes with some invective message written in some moonspeak language (there are symbols that can be read, and they tell something about 'antihack.dll', for which, though, I don't found any reference to using Dependency walker and Pe Explorer).</p> <p>So, is there any way how to prevent this aggressive process from killing any working app and connect it somehow to OllyDbg?</p> <p>P.S. Now is some crazy stuff going on. Even if rum without debugger in background process fails after some time with an memory access error (and I even replaced an .exe with the original one in case of some arbitrary overwrites).</p>
How to prevent application from killing OllyDbg
|ollydbg|anti-debugging|
<p>I do mainly refer to the first answer and add:</p> <p><strong>Retargetable Decompiler</strong> is indeed working fine, tested it with ARM Binarys. It's only anvailable online.</p> <p><strong>SmartDec</strong> has moved to a new site: <a href="http://decompilation.info/" rel="nofollow">http://decompilation.info/</a> but is not currently able of decompiling ARM Platform.</p>
3654
2014-02-10T11:07:34.727
<p>I'm trying to use IDA Pro v6.5 <s>(freeware)</s> (demo) to decompile an objective-c library compiled for ARM7-7S. I tried Hopper v2.8.8 (freeware) with no success. <br><br> I had no problem until I tried to display a pseudocode. In fact, I can't find the option for that as you can see on this screenshot : <img src="https://i.stack.imgur.com/0x93j.png" alt="enter image description here"><br> I believe to know that I can do it because IDA should support ARM decompilation... So my question is : How to decompile an objective-c library ? Or, Am I missing something ?</p>
How to decompile an Objective-C static library (for iOS)?
|ida|decompilation|arm|
<p>MapFileChecksum is used to calculate the checksum of the executable that's stored in the IMAGE_OPTIONAL_HEADER structure using Microsoft's custom checksum. It's usually used to re-calculate the checksum value once the executable has been modified, since the windows kernel checks the checksum before it loads drivers and system files. But in case of your application, the application might be using any kind of checksum (crc32, adler, e.t.c.) or might even be using hash functions. So just breaking on MapFileChecksum might not be enough. Since it has to read it's own binary to calculate the checksum/hash, break on the file manipulation functions and go from there.</p>
3658
2014-02-10T22:12:24.690
<p>I am using ollydbg and a Hex editor. I confirmed that once the application is edited in any way it behaves different than normal.</p> <p>My first thought was that the file is checking the checksum value so I looked at the intermodular calls in olly and did not see anything about checksum. I was specifically looking for <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms680355%28v=vs.85%29.aspx" rel="nofollow">MapFileAndCheckSum</a></p> <p>But I am trying to reason this out, I am thinking that a checksum value has to be hard coded in the file so it can be compared to the actual checksum. So I am wondering from the developers point of view how is it possible to get the checksum value to be hard code when the application is not complete/compiled</p> <p>Which brings me to the question. What ways is there for an application to detect that it has been modified?</p> <p>------- EDIT ------- Additional Information ------</p> <p>I have been doing some testing and I have to say I'm baffled as to where the checksum value is being stored.</p> <ol> <li>There are no connections to the internet.</li> <li>Only one dll comes with the application (I extracted the installer files manually) the dll file is old and was last modified prior to the application. I even compared it to an earlier version of the application that did not have this checksum check and the dll is identical.</li> <li>I taught that maybe the checksum value would be entered in the registry by the installer so I extracted the .exe and .dll to a separate computer that has never used the installer. Changes are still being detected!</li> <li>It is definitely a checksum test, as I have changed a single byte of padding by from 00 to 20 and the change is detected. If I edit back to 00 to application performs normally.</li> </ol> <p>So now I am wondering would it be possible to calculate what the checksum is going to be before entering the hard coded checksum value? I do realize that the actual checksum value will change when changing the hard coded checksum value. I want to know if there is any method to predetermine a checksum value when hard coding and finding a match. Seems impossible but I cannot think of any other means considering the situation.</p>
What ways is there for an application to detect that it has been modified?
|ollydbg|hex|
<p>it's compressed with LZS ( Lempel-Ziv-Stack ). </p> <p>I was trying to do the password extraction the pythonic way, it's enought to take a look at this shell script and small piece of c code:</p> <p><a href="https://github.com/MrNasro/scripts/blob/master/exploits/rom0x/" rel="nofollow">shell + C solution</a></p> <p><a href="https://gist.github.com/FiloSottile/4663892" rel="nofollow">way of extraction LZS with python</a></p> <p>and to replace 'dd' usage in same python script:</p> <pre><code> def romcutter(fname): import sys fpos=8568 fend=8788 fhandle=file(fname) fhandle.seek(fpos) chunk="*" amount=221 while fpos &lt; fend: if fend-fpos &lt; amount: amount = fend-fpos chunk = fhandle.read(amount) fpos += len(chunk) return chunk </code></pre> <h2>take rom-0, cut it with cutter, and extract result LZS....</h2>
3662
2014-02-11T05:15:27.283
<p>So I have this rom-0 file from Zyxel router P-660HW-T3 v3 and I would like to decompress it, I tried many tools, one of them <a href="http://git.kopf-tisch.de/?p=zyxel-revert;a=summary" rel="nofollow">you can find here</a> the tool using lzs for decompression which works for some rom-0 files (smaller ones around 16 kB), but on mine it does not, mine has around 50 kB and has few differences.Here is "normal" file </p> <pre><code> 00000000 01 01 00 01 19 48 64 62 67 61 72 65 61 00 00 00 |.....Hdbgarea...| 00000010 00 00 00 00 18 00 00 00 01 48 00 00 00 00 00 00 |.........H......| 00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000160 00 00 00 00 00 00 00 00 52 ca c0 ea de ad be af |........R.......| 00000170 00 00 00 0e 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000180 05 03 00 ad 52 c9 a4 e5 80 46 e7 50 ff ff a1 f4 |....R....F.P....| 00000190 00 00 00 19 00 00 00 00 05 03 00 d4 52 c9 a4 e5 |............R...| 000001a0 80 46 e7 50 ff ff 9e 08 00 00 00 64 80 09 89 ac |.F.P.......d....| 000001b0 04 03 00 d5 52 c9 bb 21 80 46 eb b8 ff ff a2 30 |....R..!.F.....0| 000001c0 00 09 3a c9 00 00 00 00 04 03 00 d6 52 c9 bb 21 |..:.........R..!| 000001d0 80 46 eb b8 ff ff a2 2f 00 09 3a c9 00 00 00 00 |.F...../..:.....| 000001e0 04 03 00 d7 52 c9 ba 49 80 46 eb b8 ff ff a2 35 |....R..I.F.....5| 000001f0 52 c9 ba 49 00 00 00 00 04 03 00 d8 52 c9 ba 49 |R..I........R..I| </code></pre> <p>and <pre><code> 00000410 80 46 e7 50 ff ff 9e 08 00 00 00 64 80 09 8b 3c |.F.P.......d...&#60;| 00000420 55 55 55 55 00 00 00 00 00 00 00 00 00 00 00 00 |UUUU............| 00000430 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 000006d0 00 00 00 00 55 55 55 55 00 00 00 00 80 41 00 00 |....UUUU.....A..| 000006e0 00 00 00 00 00 00 00 0e 00 00 00 00 00 00 00 01 |................| 000006f0 00 00 00 00 ff ff ff fe 00 00 ff 14 00 00 00 01 |................| 00000700 00 00 00 30 00 00 00 01 80 45 cc f0 00 00 00 01 |...0.....E......| 00000710 00 00 00 01 00 00 00 63 80 41 4c 78 00 00 00 01 |.......c.ALx....| </pre></code> and <pre><code> 00002000 02 94 00 03 1f fc 62 6f 6f 74 00 00 00 00 00 00 |......boot......| 00002010 00 00 00 00 00 20 00 0c 01 48 73 70 74 2e 64 61 |..... ...Hspt.da| 00002020 74 00 00 00 00 00 00 00 1a b0 13 52 01 68 61 75 |t..........R.hau| 00002030 74 6f 65 78 65 63 2e 6e 65 74 00 00 01 f4 01 dc |toexec.net......| 00002040 1c 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00002050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| </pre></code> Here is mine <pre><code> 00000000 01 01 00 01 00 00 19 48 64 62 67 61 72 65 61 00 |.......Hdbgarea.| 00000010 00 00 00 00 00 00 00 00 18 00 00 00 00 00 00 00 |................| 00000020 01 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |.H..............| 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000150 00 00 00 00 00 00 00 05 00 00 00 01 00 00 00 02 |................| 00000160 00 00 00 03 00 00 00 01 00 00 00 00 de ad be af |................| 00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000180 03 03 00 30 38 6d 46 1a 00 00 00 18 ff ff a1 f4 |...08mF.........| 00000190 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001b0 00 00 00 00 00 00 00 00 05 03 00 5c 38 6d 46 1a |...........\8mF.| 000001c0 00 00 00 18 ff ff 9e 08 00 00 00 64 80 09 e0 5c |...........d...\| 000001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 000001f0 05 03 00 32 38 6d 46 2a 00 00 00 20 ff ff a1 f4 |...28mF*... ....| 00000200 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000210 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000220 00 00 00 00 00 00 00 00 04 03 00 5d 38 6d 46 2a |...........]8mF*| 00000230 00 00 00 20 ff ff a2 29 00 00 00 00 00 00 00 00 |... ...)........| 00000240 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| </pre></code></p> <p><pre><code> 00000ea0 04 03 00 2e 38 6d 45 ee 00 00 00 20 ff ff a1 f4 |....8mE.... ....| 00000eb0 00 00 00 0b 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000ec0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000ed0 00 00 00 00 00 00 00 00 04 03 00 59 38 6d 45 ee |...........Y8mE.| 00000ee0 00 00 00 20 ff ff a2 33 00 00 00 00 00 00 00 00 |... ...3........| 00000ef0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000f10 04 03 00 5a 38 6d 45 ee 00 00 00 20 ff ff a2 2e |...Z8mE.... ....| 00000f20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000f40 00 00 00 00 00 00 00 00 03 03 00 5b 38 6d 45 f7 |...........[8mE.| 00000f50 00 00 00 15 ff ff a5 fc ff ff f4 47 80 9a e2 98 |...........G....| 00000f60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000f80 55 55 55 55 00 00 00 00 00 00 00 00 00 00 00 00 |UUUU............| 00000f90 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00001b90 00 00 00 00 55 55 55 55 00 00 00 00 ff ff ff ff |....UUUU........| 00001ba0 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 |................| </pre></code></p> <p><pre><code> 00001fd0 80 7a 00 00 bf c0 5f 90 80 66 00 00 00 00 00 00 |.z...._..f......| 00001fe0 80 5e 05 b4 80 40 11 c8 00 00 00 00 00 00 00 00 |.^...@..........| 00001ff0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00002000 02 c8 00 03 00 00 9f fc 62 6f 6f 74 00 00 00 00 |........boot....| 00002010 00 00 00 00 00 00 00 00 00 20 00 00 00 0c 00 00 |......... ......| 00002020 01 48 73 70 74 2e 64 61 74 00 00 00 00 00 00 00 |.Hspt.dat.......| 00002030 00 00 9a b0 00 00 3f 6c 00 00 01 68 61 75 74 6f |......?l...hauto| 00002040 65 78 65 63 2e 6e 65 74 00 00 00 00 01 f4 00 00 |exec.net........| 00002050 01 52 00 00 9c 18 00 00 00 00 00 00 00 00 00 00 |.R..............| 00002060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| </pre></code></p> <p><pre><code></p> <p></pre></code></p> <p>I separated some parts of the files as u may see above, so what Binwalk says on "normal" file</p> <pre><code> $ binwalk rom-0 DECIMAL HEXADECIMAL DESCRIPTION ------------------------------------------------------------------------------------------------------------------------------------------------------ 0 0x0 ZyXEL rom-0 configuration block, name: "dbgarea", compressed size: 0, uncompressed size: 6144, data offset from start of block: 344 8212 0x2014 ZyXEL rom-0 configuration block, name: "spt.dat", compressed size: 4946, uncompressed size: 6832, data offset from start of block: 376 8232 0x2028 ZyXEL rom-0 configuration block, name: "autoexec.net", compressed size: 476, uncompressed size: 500, data offset from start of block: 7208 </code></pre> <p>and what on mine</p> <pre><code> $ binwalk rom-4.51 DECIMAL HEXADECIMAL DESCRIPTION ------------------------------------------------------------------------------------------------------------------------------------------------------ 2 0x2 ZyXEL rom-0 configuration block, name: "dbgarea", compressed size: 6144, uncompressed size: 0, data offset from start of block: 16 7319 0x1C97 LZMA compressed data, properties: 0xD0, dictionary size: 33554432 bytes, uncompressed size: 31360 bytes 8220 0x201C ZyXEL rom-0 configuration block, name: "spt.dat", compressed size: 39600, uncompressed size: 0, data offset from start of block: 16 8246 0x2036 ZyXEL rom-0 configuration block, name: "autoexec.net", compressed size: 500, uncompressed size: 0, data offset from start of block: 16 </code></pre> <p>LZMA header is "incorrect" it cant be decompressed, maybe its modified do not know, so file has dbgarea, spt.dat, autoexec.net standard block but is it comoressed with "modified" lzs can u tell ?</p> <blockquote> <p><a href="http://www.hakim.ws/huawei/rom-0/kender.html" rel="nofollow">Here</a> are some notes from RE of "old" rom-0 </p> </blockquote> <hr> <p>so I see that righnt now there "is no help" so I will post whole file so u can see whole picture </p> <p>Heh I have limitation to 30000 chars so here is link of file <a href="http://pastebin.com/2X00B6rJ" rel="nofollow">http://pastebin.com/2X00B6rJ</a> Can any one help me to "reveal" what they did (changed) to lzs compresion, I asume its lzs</p> <p>Many tnx in advice, cheers</p>
backup from ZynOS but, can not be decompressed with LZS
|static-analysis|unpacking|
<p><code>UIApp</code> is a shorthand for <code>[UIApplication sharedApplication]</code>.</p> <p>As this is not an iOS app, but an OS X app you need to use <code>[NSApplication sharedApplication]</code> instead.</p>
3668
2014-02-12T17:11:23.043
<p>I recently found out about a tool called cycript that apparently does runtime analysis of binaries written with Objective-C. I have a Mac OS X binary that is compiled as x86_64 and is intended to run on Intel Macs. I know cycript is intended to for iOS applications but I wouldn't mind using it on this binary to poke around and see what is going on inside the binary. Most instructions I see for cycript state to start off with UIApp, and then investigating further objects from there.</p> <p>My problem is when I try to investigate UIApp with cycript I get the following error message,</p> <p><code>ReferenceError: hasProperty callback returned true for a property that doesn't exist.</code></p> <p>I am assuming I am getting this error message because the binary does not have a UIApp class / method in it because it is a Mac OS X binary and not an iOS.</p> <p>Where would be a good starting point for using cycript with a Mac OS X binary?</p>
How to use cycript to investigate a mach-o x86_64 binary?
|osx|
<p>You can use Heads function from idautils module. So your code will look like that:</p> <pre><code>import idautils seg_list = [] for seg in Segments(): seg_list.append(seg) # logic will be added to remove section that are code later seg_list.reverse() for seg in seg_list: start = SegStart(seg) end = SegEnd(seg) for ea in idautils.Heads(start, end): gen_xrefs = XrefsTo(ea, 0) for xx in gen_xrefs: print hex(ea), hex(xx.frm) </code></pre>
3669
2014-02-12T17:49:51.747
<p>What is the best method to enumerate all xrefs to addresses in a particular segment? I came up with a brute-force approach (as seen below). The code scans each address in a segment and checks for an XrefTo the address. </p> <pre><code>seg_list = [] for seg in Segments(): seg_list.append(seg) # logic will be added to remove section that are code later seg_list.reverse() for seg in seg_list: start = SegStart(seg) end = SegEnd(seg) while start &lt; end: gen_xrefs = XrefsTo(start, 0) for xx in gen_xrefs: print hex(start), hex(xx.frm) start += 1 </code></pre> <p>This approach is very time consuming if I have multiple large segments. IDA adds <code>DATA XREF</code> comments when viewing the data manually. Are these xrefs stored in an accessible way from IDAPython or is there another more practical approach to find the xrefs to a segment? </p> <pre><code>mem_15d:00973000 dd 1C8h dup(0) mem_15d:00973720 dword_973720 dd 101011Ch, 1000h ; DATA XREF: mem_f08:00970678o mem_15d:00973728 off_973728 dd offset off_970178 ; DATA XREF: mem_f08:off_970178o mem_15d:00973728 ; mem_f08:0097017Co </code></pre> <p><em>Note: Enumerating all xrefs from the code is not an option.</em> </p>
Enumerate all XefsTo a Segment in IDAPython
|idapython|
<p>DCoder already referenced <a href="https://reverseengineering.stackexchange.com/a/3169/245">his own answer</a> in a comment.</p> <p>The chunks in the control flow graph are usually referred to as basic blocks or extended basic blocks. The reason why they are being reordered has to with <a href="http://en.wikipedia.org/w/index.php?title=Optimizing_compiler&amp;oldid=592712045#Other_optimizations" rel="nofollow noreferrer">optimizations performed by the compiler</a>.</p> <p>There are several terms for what you are asking about:</p> <ul> <li>function chunking</li> <li>basic block reordering</li> <li>partition interleaving</li> </ul> <p>I strongly suggest that if you are interested in this topic, you read up on compiler design. In particular I would suggest reading "the dragon book" ("Compilers - Principles, Techniques, &amp; Tools" by Aho, Lam, Sethi and Ullman) and there the parts about optimization. Here I refer to the second edition from 2007 (ISBN: 0-321-48681-1).</p> <p>Check out the sections 8.4 ("Basic Blocks and Flow Graphs") and 8.5 ("Optimization of Basic Blocks") and in the latter 8.5.7 ("Reassembling Basic Blocks From DAGs"). But that's only the beginning. Chapter 9 is equally important as a whole and so is section 11.10 ("Locality Optimizations"). Quoting one of the reasons for the kind of optimization you're asking about from the introductory paragraph of the subsection on partition interleaving:</p> <blockquote> <h2>11.10.3 Partition Interleaving</h2> <p>Different partitions in a loop often read the same data, or read and write the same cache lines. [...]</p> </blockquote> <p>quoted from <strong>"Compilers - Principles, Techniques, &amp; Tools"</strong> by Aho, Lam, Sethi and Ullman.</p> <p>This boils down to what DCoder has already mentioned in his/her comment to your question.</p> <p>Oh and the book <strong>"Reversing: Secrets of Reverse Engineering"</strong> is also a good read that discusses this in part. However, it's more focused on the "how does it look" than the "why is it done".</p>
3676
2014-02-13T07:20:17.697
<p>The control flow graph below is from a single function in Notepad (Win7 64-bit). Why is the linker (or the compiler) separating the basic blocks of a single function into multiple, discontinuous ( not contiguous ) chunks?</p> <p><img src="https://i.stack.imgur.com/GM19m.png" alt="Function CFG"> </p>
Chunked function (discontinuous chunks of code comprising a function)
|c|compilers|
<h1>The question is wrongly placed</h1> <p>You are asking the wrong question. Literally. The question is by no means why it isn't possible (it <em>is</em> possible in many cases). The better question is: <strong>why it isn't practical?</strong></p> <p>It's interesting to ask it, nevertheless.</p> <h2>Why not use hardware assisted virtualization?</h2> <p>For starters I've had arguments in the past with certain colleagues (I work in the AV industry) and tried to get across that in certain hardware virtualization methods you gain speed without losing security compared to own emulation implementations. Some of these colleagues held that malware must never we executed natively on a machine without an air gap. Personally I consider this a questionable statement because of the existing proliferation of malware and because todays hardware virtualization features offer (near-)native execution anyway. But I guess it's a matter of taste and politics in the end.</p> <p>Aside from that you'll have to have privileged access to the system in order to control the hypervisor. This may be fine in the context of a file system filter, which runs in kernel mode, but will not be an option in other purely user mode scenarios (like a command line scanner).</p> <p>And then you have only "emulated" the machine, not the (operating system) environment in which the harmless or malicious code would normally be running.</p> <h2>Speed matters in AV</h2> <p>However, concerning the practicality the problem mostly boils down to speed. If you consider that AV file system filters scan every object at least once, that's a lot.</p> <p>Now the AV engines will usually try to make sure that there are static unpackers for certain executable packers so that this won't have to be emulated and so on. There are also other heuristics and static methods in place before it gets down to emulation.</p> <p>But still in this case there will be a sizable fraction of the overall scanned files that will have to be emulated, even if just in part. Since emulation is usually at least an order of magnitude slower than native execution, this adds up quickly, even if only parts of the overall code get emulated in the end.</p> <h2>Which system to emulate?</h2> <p>Now this seems to be an easy one at surface. Always emulate the one on which you're running.</p> <p>The problem then becomes how to put a whole OS installation into your engine. Now you may counter: "why don't you use the libraries of the OS you're running on", to which I will respond that this works only for this particular use case above. But how do I emulate Win32 APIs when running on a PowerPC under AIX? Or in your Android phone on an ARM processor?</p> <p>Our scanners are expected to run across a variety of operating systems and processor architectures and that limits what's possible while maintaining the necessary speed when scanning files/objects.</p> <h2>How closely should the emulator follow the real environments' behavior?</h2> <p>If you have ever tried <a href="http://reactos.org/">ReactOS</a> - an open source project that aims to reimplement the binary interfaces of Windows XP and 2003 Server true to the last detail - with anything but the stuff that comes on the CD image, you'll know that it has all kinds of glitches. <a href="http://www.winehq.org">Wine</a> as well has a lot of glitches (ReactOS and Wine share a lot of code).</p> <p>AV emulation usually takes many more shortcuts than Wine, because a lot of the functionality isn't required. Let a function succeed or fail and it's fine. The problem is in the very fine details of the Win32 API. And there are loads of those.</p> <h2>Windows 95, 98, Me, NT 4, 2000, XP, 2003, Vista, 2008, 7, 2008 R2, 8, 2012, 8.1, 2012 R2</h2> <p>... and then you should care for Linux and Mac malware, too? And what about other circumstances like certain hardware configurations (think Stuxnet and how it was "tied" to certain USB keys).</p> <p>Basically if you "emulate" an executable to find certain indicators for maliciousness or goodness your requirements are different from when you emulate a whole operating system or a machine on which you can run the operating system as if it ran on real hardware.</p> <h2>Conclusion: an approximation is enough</h2> <p>So an approximation of the real environment is usually enough. Besides you should keep in mind that many of the evasion attempts themselves can be detected, are suspicious and will raise flags.</p>
3677
2014-02-13T08:52:06.807
<p>Antiviruses and similar analysis engines often face the problem of identifying whether the file is harmful. They often do so with the use of (partial)emulation and as a result often fall prey to the tricks (anti-emulation) used by the binary.Is it possible to emulate a binary to such an extent that it becomes impossible for it to identify whether it is running in a virtual environment? </p>
Why is true emulation not possible?
|binary-analysis|emulation|
<p>The stack frame structure is not created unless necessary (i.e. the function accesses a stack argument or local variable), so these stub functions get skipped by your <code>(ret == -1)</code> check.</p>
3682
2014-02-14T00:04:54.897
<p>Test platform is Linux 32 bit, ELF file, GNU coreutils.</p> <p>Basically I am trying dump all the functions using IDC script, here is part of my IDC script:</p> <pre><code>for (addr = NextFunction(addr); addr != BADADDR; addr = NextFunction(addr)) { name = Name(addr); end = GetFunctionAttr(addr, FUNCATTR_END); locals = GetFunctionAttr(addr, FUNCATTR_FRSIZE); frame = GetFrame(addr); ret = GetMemberOffset(frame, " r"); if (ret == -1) continue; firstArg = ret + 4; args = GetStrucSize(frame) - firstArg; dumpFunction(name, addr, end); } </code></pre> <p>I am using it to test GNU coretuils, and I find some functions like </p> <pre><code> public qset_acl qset_acl proc near jmp chmod_or_fchmod qset_acl endp </code></pre> <p>which can not be found by this script.</p> <p>Am I doing something wrong? Could any one give me some help?</p> <p>Thank you!</p>
Why this IDC script can not find all the functions?
|ida|ida-plugin|
<p>This aligns the stack pointer to 8 byte boundary. This is done by the compiler to improve performance, as reads from non-aligned addresses results in performance degradation.</p>
3683
2014-02-14T02:25:11.427
<p>I have de-assembled a x86 application use ida, it generates the following code</p> <pre><code>.text:1084FF10 push ebp .text:1084FF11 mov ebp, esp .text:1084FF13 and esp, 0FFFFFFF8h .text:1084FF16 sub esp, 0D4h .text:1084FF1C mov eax, ___security_cookie .text:1084FF21 xor eax, esp </code></pre> <p>What does the instruction "and esp, 0FFFFFFF8h" do here?</p>
understanding the stack
|ida|assembly|x86|
<p>Your script is OK. IDA possibly doesn't recognize your function as a function during auto-analysis and that's a possible problem. If you will go to the address of this function in IDA pro, press P in disassembly view on this address and rerun the script you'll possibly have your function dumped.</p> <p>There is a very incorrect solution for this problem (incorrect means that it is not always provide good/correct results). If you will pass on any non-function area and create functions automatically with the script below everything that was not defined as function before will be dumped with your script, but I'm not sure for correctness of these results. </p> <pre><code>#I didn't check this code, run on your own risk, #use carefully, beware errors import idaapi import idc segm = idaapi.get_segm_by_name(".text") start = segm.startEA end = segm.endEA while start &lt; end: start = idaapi.find_not_func(start, 1) print "Attempt to create function at", hex(start) idc.MakeFunction(start) start += 1 # for a case of any error </code></pre>
3686
2014-02-14T23:41:31.530
<p>On Linux 32 bit, I use IDA Pro + IDC script to dump all the functions. Here is part of the script:</p> <pre><code>addr = 0; for (addr = NextFunction(addr); addr != BADADDR; addr = NextFunction(addr)) { name = Name(addr); end = GetFunctionAttr(addr, FUNCATTR_END); Message("%s:\n", name); dumpFunction(name, addr, end); } </code></pre> <p>Certain functions, like <code>close_stdin</code> defined in GNU coreutils static library, can not be found in this script but I can find those functions in <code>File-&gt;Produce File-&gt;Create ASM File...</code></p> <p>Is there something wrong with my script? Can I use it to find out all the functions?</p>
Why I can not find all the functions using this IDC script?
|ida|idapython|ida-plugin|
<p>If you take a look at the specific opcodes for those instructions, they are the same. To be more precise, "stos m8" and stob have the same opcode (0xAA) as do "STOS m16" , "STOS m32", "STOSW" and "STOSD" (0xAB). To quote the manual:</p> <blockquote> <p>At the assembly-code level, two forms of this instruction are allowed: the "explicit-operands" form and the "no-operands" form. The explicit-operands form (specified with the STOS mnemonic) allows the destination operand to be specified explicitly. Here, the destination operand should be a symbol that indicates the size and location of the destination value. The source operand is then automatically selected to match the size of the destination operand (the AL register for byte operands, AX for word operands, and EAX for doubleword operands). This explicit-operands form is provided to allow documentation; however, note that the documentation provided by this form can be misleading. That is, the destination operand symbol must specify the correct type (size) of the operand (byte, word, or doubleword), but it does not have to specify the correct location. The location is always specified by the ES:(E)DI registers, which must be loaded correctly before the store string instruction is executed.</p> </blockquote> <p>And from the <a href="https://www.hex-rays.com/products/ida/support/idadoc/274.shtml">GetMnem</a> documentation:</p> <blockquote> <p>note: this function may not return exactly the same mnemonics as you see on the screen.</p> </blockquote>
3694
2014-02-16T20:21:46.203
<p>So basically I use a IDC script to dump the instructions one by one using IDA Pro 6.1, windows 32 bit. PE file format</p> <p>I use try to dump one opcode instructions like </p> <pre><code>stosd stosb stosq movsd </code></pre> <p>in this way:</p> <pre><code>for (addr = funcStart; addr != BADADDR; addr = NextHead(addr, funcEnd)) { ...... auto code; line = GetDisasm(addr); mnem = GetMnem(addr); ....... if (strstr(line, mnem) != 0) { mnem = line; } line = form("%-8s", mnem); </code></pre> <p>But to my surprise, when meets one opcode instructions like those, <strong>mnem</strong> get things like</p> <pre><code>stos stos stos movs movs movs </code></pre> <p>By checking the directly dumped asm file ** File->Produce File->Create ASM File...**, I find those error instructions should be </p> <pre><code>stosd stosd stosd movsd movsd movsd </code></pre> <p>Which means the results API GetMnem generated is wrong...</p> <p>Could anyone give me some help? THank you! </p>
Why the API GetMnem can not deal with instructions like "stosd", "movsd" in IDA Pro?
|ida|
<blockquote> <p><strong>Question 1:</strong> Why isn't the EBP pointing to <code>1B05FFFC</code>?</p> </blockquote> <p>Because <code>1B05FFFC</code> is not the base address of the stack frame.</p> <p>The only reason that OllyDbg shows <code>1B05FFFC</code> as the last address in the stack-view is that it's the address of the last DWORD in the stack's memory page.</p> <blockquote> <p><strong>Question 2:</strong> What do the first 16 bytes on the stack represent?</p> </blockquote> <p>It depends on the debugger.</p> <p>For example, from my limited testing...</p> <p>When attaching WinDbg to a 32-bit EXE on Windows 7 x64, <code>[ESP]</code> is the return address back into <code>ntdll!DbgUiRemoteBreakin</code> from the call to <code>ntdll!DbgBreakPoint</code>.</p> <p>When attaching OllyDbg v2.01 to a 32-bit EXE on Windows 7 x64 or Windows 7 x86, the debugger suspends the debuggee in the middle of an executing debuggee thread, so the value of <code>ESP</code> is whatever <code>ESP</code> was in the debuggee's thread at the moment OllyDbg attached to it.</p>
3701
2014-02-17T17:05:51.803
<p>Whenever I attach a process in OllyDbg v1.10 on my Windows 7 64-bit machine, I notice that the first saved EBP on the stack doesn't point to the very base of the stack. Instead it points 16 bytes before it.</p> <p>To illustrate what I mean, see the following screenshot: <img src="https://i.stack.imgur.com/VYfxb.png" alt="screen-shot of OllyDbg stack window"></p> <p>The EBP (highlighted in gray), which is right above the <code>RETURN to ntdll.76FC9F45</code>, is pointing to <code>1B05FFEC</code>. Note that this address ends with <strong><code>EC</code></strong>, not <code>FC</code>.</p> <p><strong>Question 1:</strong> Why isn't the EBP pointing to <code>1B05FFFC</code>?</p> <p><strong>Question 2:</strong> What do the first 16 bytes on the stack represent?</p> <p><strong>Question 3:</strong> Is the number of bytes (16), which are between <code>StackBase</code> and the address to where the first <code>EBP</code> points to, fixed for Windows OSs?</p>
What do the first 16 bytes on the stack represent?
|windows|ollydbg|debuggers|x86|callstack|
<p>I'd recommend loading the dll file into PE Explorer (View->Export), which will undecorate the names for you and show you the corresponding parameters/return value/calling convention.</p> <p>You may also want to check out <a href="https://stackoverflow.com/questions/9177591/how-to-undecorate-name-from-decorated-name">this question</a>.</p>
3704
2014-02-17T19:39:57.633
<p>I use <a href="http://processhacker.sourceforge.net/" rel="nofollow noreferrer">ProcessHacker</a> version 2.33 to inspect the functions which are exported by DLLs in running processes. In the screen-shot below you can see a few exported functions from a C++ application, along with their Ordinal number and virtual address (VA):</p> <p><img src="https://i.stack.imgur.com/a2kFv.png" alt="enter image description here"></p> <p>This is a pretty cool feature of ProcessHacker, which I was not able to find in ProcessExplorer. However, regarding the entries you can see in this screen-shot, I was not able to find what do the <code>?</code> (question marks) and the number, which prefixes the names of the functions, mean. Also, I'm not sure what the single and double <code>@</code> (at) symbols in the name, followed by a group of capital letters or number, mean.</p> <p><strong>Question 1:</strong> What do the symbols (<code>?, @</code>), number-prefix and capital letter suffixes represent? How can one interpret them?</p> <p><strong>Question 2:</strong> What does the "Ordinal" column mean?</p> <p><strong>Question 3:</strong> Does the "VA" column show the offset of the procedure entry point, with respect to the base address of the <code>.text</code> segment of the DLL? If not, what does it represent?</p> <p><strong>Question 4:</strong> How can one compute the absolute address of any function from the Exports tab?</p>
How to interpret entries from Exports tab in ProcessHacker
|dll|libraries|processhacker|
<p>seems to be a struct from some internal microsoft floating point conversion code possibly from windbg source tree </p> <p>seems to be defined like</p> <pre><code>typedef struct { int max_exp; // maximum base 2 exponent (reserved for special values) int min_exp; // minimum base 2 exponent (reserved for denormals) int precision; // bits of precision carried in the mantissa int exp_width; // number of bits for exponent int format_width; // format width in bits int bias; // exponent bias } FpFormatDescriptor; </code></pre> <p>Double </p> <pre><code>static FpFormatDescriptor DoubleFormat = { 0x7ff - 0x3ff, // 1024, maximum base 2 exponent (reserved for special values) 0x0 - 0x3ff, // -1023, minimum base 2 exponent (reserved for denormals) 53, // bits of precision carried in the mantissa 11, // number of bits for exponent 64, // format width in bits 0x3ff, // exponent bias }; </code></pre> <p>Float</p> <pre><code>static FpFormatDescriptor FloatFormat = { 0xff - 0x7f, // 128, maximum base 2 exponent(reserved for special values) 0x0 - 0x7f, // -127, minimum base 2 exponent (reserved for denormals) 24, // bits of precision carried in the mantissa 8, // number of bits for exponent 32, // format width in bits 0x7f, // exponent bias }; </code></pre>
3716
2014-02-18T21:36:43.910
<p>Basically I us IDA Pro 6.1 on Windows 32 bit, dealing with binaries from SPEC 2006.</p> <p>I use IDA Pro to generate asm code from the binaries, and in the .data section, I see data define like this:</p> <pre><code>GS_ExceptionRecord _EXCEPTION_RECORD &lt;?&gt; GS_ContextRecord _CONTEXT &lt;?&gt; lclcritsects _RTL_CRITICAL_SECTION 0Eh dup(&lt;?&gt;) ..... DoubleFormat FpFormatDescriptor &lt;400h, 0FFFFFC01h, 35h, 0Bh, 40h, 3FFh&gt; FloatFormat FpFormatDescriptor &lt;80h, 0FFFFFF81h, 18h, 8, 20h, 7Fh&gt; </code></pre> <p>Basically I can not find the definition of <strong>_EXCEPTION_RECORD</strong> ,<strong>_CONTEXT</strong> ,<strong>_RTL_CRITICAL_SECTION</strong>, <strong>FpFormatDescriptor</strong> in the generated asm code.</p> <p>And in the code, they will be used like:</p> <pre><code>mov edi, DoubleFormat.precision mov eax, DoubleFormat.min_exp sub ecx, DoubleFormat.precision mov edi, FloatFormat.precision mov edi, offset lclcritsects mov GS_ContextRecord._Eax, eax mov word ptr GS_ContextRecord.SegSs, ss pop GS_ContextRecord.EFlags </code></pre> <p>So basically my questions are:</p> <ol> <li><p>How can I find the definition of these stuff?</p></li> <li><p>Basically I use <strong>File-->Produce File-->Create ASM File</strong> to generate asm code for analysis, then how can I dump these definitions from IDA Pro's Structures window into this asm code?</p></li> </ol> <p>And what's more, it seems that I can not find the definition in Structures window even if I expand them....</p> <p><img src="https://i.stack.imgur.com/gxynq.png" alt="enter image description here"></p>
Why IDA Pro generate define-lack code like this?
|ida|disassembly|winapi|nasm|
<p>This comes down to the type of bug you are exploiting. If your payload cant contain null bytes (a vulnerable strcpy), this can become an issue, however not all bugs have this constraint. Take for example a bug in how a filetype is parsed, which allows null bytes. </p> <p>Also there is the possibility of a series of bugs to be used, for example, the idea of heap spraying. Generally you spray the heap doing other "legitimate" things, such as in <a href="https://www.corelan.be/index.php/2011/12/31/exploit-writing-tutorial-part-11-heap-spraying-demystified/">this write up</a> by corelancoder. His shell code, which would be your ROP chain, is part bitmap files that he consecutively loads to "spray the heap", while the bug is actually triggered by javascript and doesn't actually contain the shellcode.</p> <p>If you want to just work on ROP, and not worry about byte limitations, i'd suggest writing a simple harness to test your shellcode.</p> <p><strong>EDIT</strong> Sorry wrong harness. This one is clearly 64-bit specific.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int data[10000000]; void start_rop(char * rop) { __asm("mov (%rax),%rsp"); //move contents of first argument into the stack pointer } int main(int argc, char * argv) { char code[] = "AAAAAAAA"; char * malloc_code = (char *)malloc(sizeof(code)); memcpy(malloc_code,&amp;code,sizeof(code)); start_rop(malloc_code); free(malloc_code); return 0; } </code></pre>
3726
2014-02-20T08:01:52.190
<p>I am working on return oriented programming exploitation on a x86_64 Linux. However, my research leads to impossibility of ROP exploitation in 64-bit Linux machine because all of code segments are loaded in null byte leading addresses. Is it true?</p> <pre><code>Gdb,Sections: (gdb) i file `/home/******/Desktop/BOF/lib64', file type elf64-x86-64. Entry point: 0x400ffc 0x0000000000400190 - 0x00000000004001b0 is .note.ABI-tag 0x00000000004001b0 - 0x00000000004001d4 is .note.gnu.build-id 0x00000000004001d8 - 0x00000000004002f8 is .rela.plt 0x00000000004002f8 - 0x0000000000400312 is .init 0x0000000000400320 - 0x00000000004003e0 is .plt 0x00000000004003e0 - 0x0000000000494808 is .text 0x0000000000494810 - 0x000000000049614c is __libc_freeres_fn 0x0000000000496150 - 0x00000000004961f8 is __libc_thread_freeres_fn 0x00000000004961f8 - 0x0000000000496201 is .fini 0x0000000000496220 - 0x00000000004b6224 is .rodata 0x00000000004b6228 - 0x00000000004b6230 is __libc_atexit 0x00000000004b6230 - 0x00000000004b6288 is __libc_subfreeres 0x00000000004b6288 - 0x00000000004b6290 is __libc_thread_subfreeres 0x00000000004b6290 - 0x00000000004c32ac is .eh_frame 0x00000000004c32ac - 0x00000000004c33b9 is .gcc_except_table 0x00000000006c3ea0 - 0x00000000006c3ec0 is .tdata 0x00000000006c3ec0 - 0x00000000006c3ef8 is .tbss 0x00000000006c3ec0 - 0x00000000006c3ed0 is .init_array 0x00000000006c3ed0 - 0x00000000006c3ee0 is .fini_array 0x00000000006c3ee0 - 0x00000000006c3ee8 is .jcr 0x00000000006c3f00 - 0x00000000006c3ff0 is .data.rel.ro 0x00000000006c3ff0 - 0x00000000006c4000 is .got 0x00000000006c4000 - 0x00000000006c4078 is .got.plt 0x00000000006c4080 - 0x00000000006c56f0 is .data 0x00000000006c5700 - 0x00000000006c8308 is .bss 0x00000000006c8308 - 0x00000000006c8338 is __libc_freeres_ptrs 0x0000000000400190 - 0x00000000004001b0 is .note.ABI-tag 0x00000000004001b0 - 0x00000000004001d4 is .note.gnu.build-id 0x00000000004001d8 - 0x00000000004002f8 is .rela.plt 0x00000000004002f8 - 0x0000000000400312 is .init 0x0000000000400320 - 0x00000000004003e0 is .plt 0x00000000004003e0 - 0x0000000000494808 is .text 0x0000000000494810 - 0x000000000049614c is __libc_freeres_fn 0x0000000000496150 - 0x00000000004961f8 is __libc_thread_freeres_fn 0x00000000004961f8 - 0x0000000000496201 is .fini 0x0000000000496220 - 0x00000000004b6224 is .rodata 0x00000000004b6228 - 0x00000000004b6230 is __libc_atexit 0x00000000004b6230 - 0x00000000004b6288 is __libc_subfreeres 0x00000000004b6288 - 0x00000000004b6290 is __libc_thread_subfreeres 0x00000000004b6290 - 0x00000000004c32ac is .eh_frame 0x00000000004c32ac - 0x00000000004c33b9 is .gcc_except_table 0x00000000006c3ea0 - 0x00000000006c3ec0 is .tdata 0x00000000006c3ec0 - 0x00000000006c3ef8 is .tbss 0x00000000006c3ec0 - 0x00000000006c3ed0 is .init_array 0x00000000006c3ed0 - 0x00000000006c3ee0 is .fini_array 0x00000000006c3ee0 - 0x00000000006c3ee8 is .jcr 0x00000000006c3f00 - 0x00000000006c3ff0 is .data.rel.ro 0x00000000006c3ff0 - 0x00000000006c4000 is .got 0x00000000006c4000 - 0x00000000006c4078 is .got.plt 0x00000000006c4080 - 0x00000000006c56f0 is .data 0x00000000006c5700 - 0x00000000006c8308 is .bss 0x00000000006c8308 - 0x00000000006c8338 is __libc_freeres_ptrs </code></pre>
ROP exploitation in x86_64 linux
|exploit|buffer-overflow|x86-64|
<p>You've got some kind of <a href="https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem">XY-problem</a>.</p> <p>The truth is: it's IDA who so to say "changes" the name of (something she thinks is) a function from absolutely nothing to <code>sub_{address}</code>. Why on earth would <code>PE-file</code> have non-exported symbols stored in it? Some kind of masochism? To give a candy to reversers?</p> <p>Thus, you have at least three ways of dealing with your problem:</p> <ul> <li>pray and hope that IDA's <a href="https://www.hex-rays.com/products/ida/tech/flirt/in_depth.shtml" rel="nofollow">FLIRT</a> will heuristically recognize <code>printf</code>;</li> <li><code>link</code> your program with debug-info: <a href="http://msdn.microsoft.com/en-us/library/aa235413.aspx" rel="nofollow"><code>-debug</code></a> which tells linker to generate <a href="http://en.wikipedia.org/wiki/Program_database" rel="nofollow"><code>pdb</code></a>-file which IDA will query for all the symbols stored for your application;</li> <li>tell linker to <a href="http://msdn.microsoft.com/en-us/library/aa235424.aspx" rel="nofollow"><code>-export:printf</code></a> so that it's name will be in export directory and you can get it's address easily even programmatically.</li> </ul>
3733
2014-02-20T18:01:06.187
<p>So basically I my nasm syntax asm code, I use some extern functions like this:</p> <pre><code>extern _printf extern __imp__Sleep@4 .... call _printf call [__imp__Sleep@4] </code></pre> <p>Then I use nasm to assemble it into obj:</p> <pre><code>nasm -f win32 test.asm </code></pre> <p>Then I use IDA Pro to disassemble test.obj, I can see code like this:</p> <p><img src="https://i.stack.imgur.com/awMR3.png" alt="enter image description here"> </p> <p>See, extern function name like <strong>_printf</strong> has been kept.</p> <p>But when I link this obj file:</p> <pre><code>cl /MT z:\\windows\\test.obj /link kernel32.lib libcmt.lib /SUBSYSTEM:CONSOLE </code></pre> <p>Then I use IDA Pro to disassemble test.exe, I can see code like this:</p> <p><img src="https://i.stack.imgur.com/oGiwm.png" alt="enter image description here"></p> <p>See, the function name of <strong>_printf</strong> has been changed.</p> <p>I know basically after static link, the code of _printf has been put into the test.exe, in the subroutine of <strong>sub_409C9B</strong></p> <p>But basically <strong>I have to make the name of extern declared functions unchangeable</strong>, because I need to reverse engineering the test.exe and do some modify/remove towards those functions, and once PE exe lost the name info, I can not locate those targeting functions.</p> <p>So my question is:</p> <p>Why cl.exe will change the name of those functions, and is there any way to stop the change(I mean keep the function name unchangeable during the link time)?</p>
Why cl.exe change the extern function name used in my code?
|ida|winapi|nasm|
<p>After some more research I found <a href="http://www.codeproject.com/Articles/27606/Opening-Jars-with-C" rel="nofollow noreferrer">this tutorial</a> and <a href="https://stackoverflow.com/questions/3217732/how-to-edit-a-binary-files-hex-value-using-c-sharp">this answer</a> about patching class files inside jars using the <a href="http://www.icsharpcode.net/OpenSource/SharpZipLib/" rel="nofollow noreferrer">SharpZipLib</a> library.</p>
3741
2014-02-22T12:17:53.460
<p>Being a beginner in <strong>C#</strong> I wonder if it is possible to patch a <strong><em>.class</strong> file inside a <strong></em>.jar</strong>?</p> <p>Since jar files tend to act like "zip" files, the approach I think might work is to decompress the jar, <strong>patch the hex offset</strong> in the *.class then zip back the jar and overwrite the original.</p> <p>Any examples or tutorials showing how to do this? is there a better approach?</p>
Patch a Java class inside a jar using C#
|java|hex|patching|jar|c#|
<p>There's also <a href="https://github.com/frranck/asm2c" rel="nofollow noreferrer">asm2c</a> that works on assembly source code instead of executables or objects files.</p> <blockquote> <p>Tool to convert DOS Assembly code to C code Edit</p> </blockquote>
3748
2014-02-24T08:18:37.010
<p>I have the following assembly code over Linux distro:</p> <pre><code># using the .data section for write permission # instead of .text section .section .data .globl _start _start: # displaying some characters for watermarking :-) xor %eax,%eax # clear eax by setting eax to 0 xor %ebx,%ebx # clear ebx by setting ebx to 0 xor %edx,%edx # clear edx by setting edx to 0 push %ebx # push ebx into the stack, base pointer # for the stack frame push $0xa696e55 # push U-n-i characters push $0x4d555544 # push M-U-U-D characters push $0x414d4841 # push A-M-H-A characters movl %esp,%ecx # move the sp to ecx movb $0xf,%dl # move 15 to dl (low d), it is the string length, # notice the use of movb - move byte, this is to avoid null movb $0x4,%al # move 4 to al (low l), # 4 is system call number for # write(int fd, char *str, int len) int $0x80 # call kernel/syscall # setuid(0) xor %eax,%eax # clear eax by setting eax to 0 xor %ebx,%ebx # clear ebx by setting ebx to 0 xor %ecx,%ecx # clear ecx by setting ecx to 0 movb $0x17,%al # move 0x17 into al - setuid(0) int $0x80 # call kernel/syscall jmp do_call # jump to get the address with the call trick jmp_back: pop %ebx # ebx (base pointer=stack frame pointer) has # the address of our string, use it to index xor %eax,%eax # clear eax by setting eax to 0 movb %al,7(%ebx) # put a null at the N or shell[7] movl %ebx,8(%ebx) # put the address of our string (in ebx) into shell[8] movl %eax,12(%ebx) # put the null at shell[12] our string now looks something like # "/bin/sh\0(*ebx)(*0000)" xor %eax,%eax # clear eax by setting eax to 0 movb $11,%al # put 11 which is execve # syscall number into al leal 8(%ebx),%ecx # put the address of XXXX i.e. (*ebx) into ecx leal 12(%ebx),%edx # put the address of YYYY i.e. (*0000) into edx int $0x80 # call kernel/syscall do_call: call jmp_back shell: .ascii "/bin/shNXXXXYYYY" </code></pre> <p>How is it possible to convert it to C code?</p>
Converting assembly code to c
|disassembly|decompilation|linux|c|exploit|
<p>(on behalf of the OP)</p> <p>Solved it. It was because my system was missing one update.</p> <p>Check the error details and solution <a href="http://support.microsoft.com/kb/917607" rel="nofollow">here</a>. Modern Windows versions have no more built-in support for the old Windows help format, so that needs to be installed explicitly.</p>
3750
2014-02-24T08:33:31.503
<p>I pointed the API help file to <code>WIN32.HLP</code> (Help -> Select API File -> win32.hlp -> Open)</p> <p>But when I right click on API and click 'Help on Symbolic name' 'Windows Help and Support' comes up and shows me 'Why can't I get Help from this program? '.</p> <p>What is the problem here...I'm using win 7, 64 Bit.</p>
OllyDgb1.10 API help file not working
|ollydbg|
<p>As for C compiler (gcc), first make sure you do not make a mistake of compiling it with <code>-g</code> option (adds symbols for debugging, basically whole source code).</p> <blockquote> <p>-g Produce debugging information in the operating system's native format</p> </blockquote> <p>Secondly, try with <code>-s</code> option:</p> <blockquote> <p>-s Remove all symbol table and relocation information from the executable.</p> </blockquote> <p>Without function names is would be harder to reverse engineer it. Take a look at <code>man strip</code>. I haven't tried it, but something like</p> <blockquote> <p>strip --strip-debug objfile</p> </blockquote> <p>or:</p> <blockquote> <p>strip --strip-unneeded objfile</p> </blockquote> <p>on your object files could be useful.</p> <p>Turn on as much optimisation as you can <code>-O3</code>. It is really hard to read an optimized assembly, making it another impediment. There is really no good way of preventing disassembly and reverse-engineering, but it makes it harder.</p> <p>As for Python, it is absolutely OK to ship only <code>.pyc</code> bytecode files. It is compiled version of source code for Python Virtual Machine. <a href="http://effbot.org/pyfaq/how-do-i-create-a-pyc-file.htm" rel="nofollow">How do I create a .pyc file?</a>. Try this one, maybe it is what you need. User can run bytecode file using <code>python</code> just as easily as a source code file.</p> <p>Lastly, try to google for code obfuscation. It makes no sense to obfuscate C++ code, but maybe someone knows if code obfuscation is a good strategy for Python.</p>
3752
2014-02-24T09:38:01.077
<p>I want to know if there are ways to compile C, C++ and Python code in order to not be able to reverse engineering it over Linux or not?</p> <p>I have heard there are some ways over Windows to do it, but I am working on Linux. </p> <p>I want to compile my code securely, as released or final version.</p> <p><strong>UPDATE</strong> </p> <p>At least I want to make it hard for usual users to disassemble, </p> <p>I am using GCC for C and C++, also I would be thankful if you introduce me best compiler for Python. </p>
How to compile c, cpp and python code as "Released/Final" version?
|python|c|c++|compilers|software-security|
<p>It looks like that $LN28_0 is local label, not subroutine. Find it, rename it manually, regenerate the file.</p>
3762
2014-02-26T04:35:09.867
<p>I use IDA Pro 6.1 to disassemble static linked binary on Windows 32bit</p> <p>See, in the interactive screen, this subroutine (which is in one library function) can be found:</p> <p><img src="https://i.stack.imgur.com/BjLOg.png" alt="IDAPro asm display"></p> <p>But as I use these two ways to generate asm code:</p> <ol> <li>File->Produce->Create ASM File</li> <li>IDC script to iterate all the functions</li> </ol> <p>In both ways I can find this library function, but I can not find the definition of the subroutine <code>$LN28_0</code>. Which means in the generated asm code, all the <code>jmp $LN28_0</code> is undefined.</p> <p>So, I am wondering if it is a bug of IDA Pro? Or, do I need to configure some things? </p>
Why IDA Pro can not generate this subroutine's code?
|ida|
<p>Here is the complete answer to everyone who may encounter compressed GIM file of simular compression. Basicly the file starts like this: [magic number 10 00 00 00] [Integer with uncompressed size of file] After this the compressed file begin. The compression basicly functions like this: (in terms of decompression)</p> <p><strong>-> Take the next 2 bytes.</strong></p> <p><strong>-> Is the second byte equals zero?</strong></p> <ul> <li>Write first byte to decompressed output.</li> </ul> <p><strong>-> Is the second byte higher than 0?</strong></p> <p>This is a pointer whose job is to make use of bytes used before. The position it points to is equals the unsigned short value of: [first byte, second byte minus 1]*2 + 8. When a pointer reads at the position it points to, it will read the next 4 bytes and not just the next 2 bytes. If the bytes at the pointed location is: 00 02 0C 01, then the decompressed output would be 02 ?? where ?? would be the result of the first two bytes of what its pointing at. In other words, if we pointed to 0C 01 02 00, then the output 0C 01 would be replaced by the result whatever its pointing to.Lets say it points to 08 00 00 00, then the output of the last pointer would be 08 00 00 00, which would replace 0C 01 and become: 08 00 00 00 02 00, which lastly would output 08 00 02 to decompressed output. *Notice that a pointer placed as the second byte cannot be replaced by four bytes, but only by the first two bytes of what would normally have been the result. If the second byte is pointing to the first byte, then it will simply be given the result of the first byte.</p> <p>Examples from the image from the first post (Black.gim): In the first image: 0c 01 points to 00 00 0C 01, which outputs 00 00. In the first image 0d 01 points to 0C 01 0C 01, which outputs 00 00 00. &lt;- notice how only the first two bytes at a pointed position has the right to extend the result of what pointed to it by two bytes. In the first image: 0F 01 points to 02 00 0D 01, which outputs 02 00</p> <p><strong>-> do this until no bytes remains..</strong></p> <p>About the suggested LZJB, I'll check right away. In case its right, I have still gotten quite the experience about reverse engineering files.</p>
3764
2014-02-26T18:43:59.927
<p>I am doing a translation project for the PSP version of a game released by Prototype (Japanese company), but I am having trouble with some GIM files (image files). Now the actual problem is not with the gim format, but a compression that has been placed on the gim files, but before that I will clarify a few things. Some of the GIM's work, however sometimes a GIM file appears that neither puyotools or GimConv (software that converts gim to png) can handle. The GIM that doesn't work is a little different in appearance. I know its a GIM file because it starts with: MIG.00.1PSP, though to be exact, its a little different and written like this:</p> <p><code>[integer equals 16, signature?] [integer equals 131792] [MIG.00.1PSP, but where a 00 HEX is placed between each hex byte] </code></p> <p>like this:</p> <p><code>10 00 00 00 D0 02 02 00 4D 00 49 00 47 00 2E 00 30 00 30 00 2E 00 31 00 50 00 53 00 50 00 00 00</code></p> <p>Each of the compressed GIM files starts with these two integers values (however an image I have with smaller resolution has a different second integer). I have allready tried removing these two integers and also tried replacing M(00)I(00)G(00).(00)0(00)0(00).(00)1(00)P(00)S(00)P(00), with simply MIG.00.1PSP, but that just ended up making GIMConv saying: wrong chunk data.</p> <p>Also I have tried analyzing the file with signsrch and TrID to look for hints of some sort, but signsrch finds nothing and TrID only finds: "100 .0% (.) LTAC compressed audio (v1.61) (1001/2)"</p> <p>Here is the file called: black.gim (a black image) <img src="https://i.stack.imgur.com/Quc5S.png" alt="enter image description here"></p> <p>Here is a random CG: <img src="https://i.stack.imgur.com/W1UrT.png" alt="enter image description here"></p> <p>Here is a random gim file for refference to how an uncompressed version should look like. Notice that the first 4 bytes of the second line indicates the file size minus 16. Another thing is the int after MIG.001.PSP, which I from different sources has found to be the version number. Therefore, all the compressed files should problably get that int there too. <img src="https://i.stack.imgur.com/pTza1.png" alt="enter image description here"> Update: I believe this is some kind of lz compression, but I haven't figured out which one yet. Tried lz01,lz00,lz10,lz11,CXLZ, lzss . It seems to me that it begins with a 10 byte like lz, it makes MIG.001.PSP become seperated by 00, due to the compression relying on value, key pair, where I believe the key 0 means that values should be directly send to the output. &lt;- if you are confident that its one of the compressions I have tried, please say so too as it could very well just be the tools I used to try those compressions that was wrong with. GZIP and deflate was tried using .NET's System.IO.Compression in C# and the others has been tried using something called Puyo tools.</p> <p>Update: It seams like I have it almost figured out, basicly a key equals zero outputs value to decompressed data. If key is higher than zero, then get the short value of [Value,key-1]. This short plus 8 times two gives the byte it has to write out twice to decompressed data. In other words, 00 00 08 01 would output 00 00 00. The only problem with this is that 0f 01 in my black.gim example at line 3. This would point to 15 which would be position (15 + 8)*2 equals byte 46 which should be 02 00 in line two. This is however incorrect! Since I expect it to place zeroes there, not output 02 02..</p> <p>In short in the black.gim example I have found that: 0C 01 should output 00 00 0D 01 should output 00 00 00 0F 01 should output 00 00</p> <p>Any suggestions?</p> <p>I'll be really happy if anybody could give me some input or lead :)</p>
identification/reverse engineer lz compression
|file-format|
<p><a href="https://github.com/wjp/idados">IDA DOSBox plugin</a> by Eric Fry.</p> <p>Note that it requires a modified DOSBox build.</p>
3766
2014-02-27T10:17:38.380
<p>Does anybody know something hack to debug 16bit DOS program in IDA 6.1?</p>
DOS program debug in IDA?
|ida|debugging|dos|