Answer
stringlengths
38
29k
โŒ€
Id
stringlengths
1
5
CreationDate
stringlengths
23
23
Body
stringlengths
55
28.6k
Title
stringlengths
15
145
Tags
stringlengths
3
68
<p>The large integer that is added to ESP is negative and is used to move the stack pointer to a an address that allows 0x44 bytes on the stack for the current function.</p> <p>At this point, ESP=EBP-0x44. So, EBP-0x44 is essentially, [ESP]. It is equivalent to <code>PUSH EAX</code>, as a parameter for the <code>CALL</code> that comes next.</p> <p>The <code>ss:</code> is a selector which indicates that the "base" of the mentioned address is on the stack. In a linear memory system it has no practical meaning.</p>
23481
2020-03-21T01:01:07.017
<p>I need to see how a DLL was written and I am using a x32dbg to do it at run-time. I am a newbie to this reversing stuff, so I am confused with this piece of code:</p> <pre><code>push ebp ; DllMain entry point mov ebp, esp add esp, FFFFFFBC xor eax, eax mov dword ptr ss:[ebp-44], eax mov eax, module.8BC3980 call module.8BB8D54 xor eax, eax </code></pre> <p>Wikipedia says the following about function prologues:</p> <blockquote> <p>A function prologue typically does the following actions if the architecture has a base pointer (also known as frame pointer) and a stack pointer:</p> <p>Pushes current base pointer onto the stack, so it can be restored later.</p> <p>Assigns the value of stack pointer (which is pointed to the saved base pointer) to base pointer so that a new stack frame will be created on top of the old stack frame.</p> <p>Moves the stack pointer further by decreasing or increasing its value, depending on whether the stack grows down or up. On x86, the stack pointer is decreased to make room for the function's local variables.</p> <p>[...]</p> <p>As an example, hereโ€ฒs a typical x86 assembly language function prologue as produced by the GCC</p> <pre><code>push ebp mov ebp, esp sub esp, N </code></pre> </blockquote> <p>But I have encountered an <code>add esp, N</code> directive which adds a huge number to <code>esp</code> register. It seems something is wrong here, what should I understand from the code exactly?</p> <p>And the second question is about <code>mov dword ptr ss:[ebp-44], eax</code> directive. Why it is 44 that is subtracted from <code>ebp</code> address (11 ints!) and what does the <code>ss</code> item here?</p> <p>PS I suspect that the DLL is written in Delphi, but not 100% sure.</p>
Function Prologue, add esp directive
|dll|x64dbg|delphi|
<p>Thanks to @julian's comment, I was able to search for more relevant terms.</p> <p>For this particular case, I decided to use <a href="https://github.com/rc0r/afl-fuzz/blob/master/dictionaries/README.dictionaries" rel="nofollow noreferrer">AFL's</a> <a href="https://lcamtuf.blogspot.com/2015/01/afl-fuzz-making-up-grammar-with.html?m=1" rel="nofollow noreferrer">dictionary mode</a>, where you can give it a list of words that make up the target application's accepted syntax.</p> <p>For example, let's pretend the target application is an interactive calculator, which supports all basic mathmatical operators, e.g. <code>4 + 5</code> or <code>500 / 2</code>. For this, I would create a dictionary file with the following contents:</p> <pre><code>"+" "-" "*" "/" "^" ... </code></pre> <p>In addition to a typical set of input cases, this file (or a directory of files with one valid piece of syntax each) would be passed to AFL with the <code>-x</code> option, and AFL will try to create valid syntax to improve fuzzing coverage.</p>
23499
2020-03-22T23:13:15.020
<p>I have an IoT system that has a command-line-based interactive shell that can be used to configure the system. While examining the disassembly/decompilation, I realized that there is a lot of functionality/code to the CLI and a lot of possible logical paths in the program. As such, I have not outright identified any memory corruption vulnerabilities, but I suspect that there may be edge cases that could result in a bug. This is where I would normally apply fuzzing to bolster my coverage.</p> <p>However, I am having trouble identifying an approach to creating a suitable input corpus to fuzz with. The CLI supports a number of commands, and some of them even spawn their own interactive CLI with many levels of namespaces. It may take several commands to reach certain parts of the program. </p> <p>I have two thoughts on how to go about this:</p> <ol> <li>Create a comprehensive corpus, including a large number of commands and possible paths. Will be tedious to construct; impossible to cover everything.</li> <li>No input corpus; use entirely feedback-driven fuzzing (if even possible in this case). Seems like this would be very inefficient, as there would be many paths for the fuzzer to learn.</li> </ol> <p>I am able to run the binary through the fuzzer and I believe the fuzzer is passing input to it correctly, so that's not an issue. I was planning on using honggfuzz for this, but I don't think that really matters for the question. I don't have source code, so this will be black box and un-instrumented fuzzing.</p> <p>My question is, how should I approach creating an input corpus to fuzz a black-box program that has many possible inputs?</p>
Approach for fuzzing interactive CLI
|fuzzing|
<p>It just doesn't print anything on the the screen but set's internal value. You can be verifie that by looking at the source code <a href="https://github.com/radareorg/radare2/blob/75f6f28bb0226b4bd2af9f8f20b2d82202903343/libr/core/cmd_flag.c#L1548" rel="nofollow noreferrer">here</a>.</p> <p>What it does tell you to do is to run <code>??</code> which is actually printing that value as can be seen in the help</p> <pre><code>| ?? show value of operation </code></pre> <p>Additionally based on the result you can run the operation or not.</p> <pre><code>| ?! [cmd] run cmd if $? == 0 | ?? [cmd] run cmd if $? != 0 [0x00000000]&gt; f?non-existent-flag [0x00000000]&gt; ?? ?E exists //&lt;- action is not executed [0x00000000]&gt; f?myflag [0x00000000]&gt; ?? ?E exists โ•ญโ”€โ”€โ•ฎ โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ โ”‚ _โ”‚ โ”‚ โ”‚ โ”‚ O O &lt; exists โ”‚ โ”‚ โ”‚โ•ญ โ”‚ โ”‚ โ”‚โ”‚ โ”‚โ”‚ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ โ”‚โ””โ”€โ”˜โ”‚ โ•ฐโ”€โ”€โ”€โ•ฏ </code></pre>
23500
2020-03-23T06:08:44.427
<pre><code>PS C:\_&gt; r2 -v radare2 4.3.1 6 @ windows-x86-64 git.4.3.1 commit: 54ac837b5503f10f91e2069ac357791f7a3e635a build: Fri 03/06/2020__15:52:24.93 PS C:\_&gt; r2 -- -- 99 bugs, take one down pass it around. 100 bugs... [0x00000000]&gt; f myflag [0x00000000]&gt; f* fs * f myflag 1 0x00000000 [0x00000000]&gt; f?myflag ;expect an output here [0x00000000]&gt; f?~exists | f?flagname check if flag exists or not, See ?? and ?! </code></pre> <p>The command <code>f?myflag</code> doesn't print any output as if the flag doesn't exist. Why does it happen?</p> <p>As a bonus question :), what does <code>See ?? and ?!</code> mean?</p>
Command "f?flagname" doesn't work as expected in radare2
|radare2|
<p>Here's my go to in Python3: <code>bytes.fromhex('020a0d')</code></p> <p>From there you can interpret how you'd like.</p> <pre><code>Python 3.7.6 (default, Dec 30 2019, 19:38:26) &gt;&gt;&gt; hex_str = '020a0d' &gt;&gt;&gt; bytes.fromhex(hex_str) b'\x02\n\r' &gt;&gt;&gt; </code></pre> <p>As an aside, I've found that storing things as ASCII Hex is one of the better RE habits I've gotten into. You can share the data with others, mark it up, examine it in any editor or IDE. Much better than pushing around an actual binary file.</p>
23518
2020-03-24T15:21:47.607
<p>I recently extracted a bunch of raw bytes (from wireshark) into a regular <code>.txt</code> file. <br> Because these raw bytes are stored in a text file, all those hex-digits are actually written as ASCII characters on the disk.</p> <p>Now, I want to interpret the ASCII encoded hex-digits as raw bytes, because they actually represent a <code>.jpeg</code> image.</p> <p>I alredy tried to copy paste the digits into ghex, (I work on Ubuntu) but ghex only allows you to paste data into the interpreted area, not into the byte-manipulation area.</p> <p>Is there a simple way to do this?</p>
Convert series of hex digits represented as ASCII-characters stored in a .txt file to raw bytes
|binary-analysis|file-format|hex|binary-editing|
<p><strong>TL;DR:</strong></p> <ul> <li>This is not an error from Ghidra. The values are just a naming convention, and the real instructions are correctly disassembled.</li> <li>Ghidra assigns variable names based on the function entry point, and displays offsets based on that.</li> <li>It seems Ghidra behaviour is like this to have a universal way to assign names, independently from the compiler.</li> </ul> <hr> <p>As pointed by R4444, Ghidra shows variable offsets relative to the <code>entry stack-pointer</code> and are not <code>frame-based</code> offsets.</p> <p>Herein, Ghidra assigns variable names based on <code>ESP</code> (or corresponding stack pointer) <strong>at the time the function is entered</strong>, without considering the coming <code>PUSH EBP</code>, basically following this:</p> <pre><code>0019FF58 $-C 0019FF58 00000002 LOCAL 2 0019FF5C $-8 0019FF5C 00000001 LOCAL 1 0019FF60 $-4 0019FF60 0019FF80 will store the OLD EBP 0019FF64 $ ==&gt; 0019FF64 | 00401025 return to layout.00401025 from layout.sub_40102C 0019FF68 $+4 0019FF68 | 00000041 PARAM 1 0019FF6C $+8 0019FF6C | 0000BABE PARAM 2 0019FF70 $+C 0019FF70 | 0000CAFE PARAM 3 </code></pre> <p>This is <strong>how</strong> Ghidra obtained the values:</p> <pre><code>Stack[0x4] -&gt; param_1 Stack[0x8] -&gt; param_2 Stack[0xc] -&gt; param_3 Stack[-0x8] -&gt; local_8 Stack[-0xc] -&gt; local_c </code></pre> <p>It must be considered that this is just a <strong>variable naming</strong>, the actual instruction is addressing the data with the correct offset. If we navigate to one of the offensive instructions, we can see that Ghidra provides the correct instruction at the bottom right corner, in this case, <code>EBP-4</code> for the named variable <code>local_8</code> (<code>[-0x8]</code>):</p> <p><a href="https://i.stack.imgur.com/oWScT.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/oWScT.jpg" alt="Ghidra stack-pointer relative to entry"></a></p> <p>This default Ghidra behavior can be modified permanently via: <code>Edit &gt; Tool Options &gt; Listing Fields &gt; Operands Field &gt; Markup Stack Variable References</code>, and then Ghidra will display:</p> <pre><code> undefined4 Stack[0x4]:4 param_1 XREF[1]: 00401040 (R) undefined4 Stack[0x8]:4 param_2 XREF[1]: 00401043 (R) undefined4 Stack[0xc]:4 param_3 XREF[1]: 00401046 (R) undefined4 Stack[-0x8]:4 local_8 XREF[1]: 00401032 (W) undefined4 Stack[-0xc]:4 local_c XREF[1]: 00401039 (W) 00401032 C745FC01000000 MOV dword ptr [EBP + -0x4 ]=&gt; local_8 ,0x1 00401039 C745F802000000 MOV dword ptr [EBP + -0x8 ]=&gt; local_c ,0x2 00401040 8B5D08 MOV EBX ,dword ptr [EBP + 0x8 ]=&gt; param_1 00401043 8B4D0C MOV ECX ,dword ptr [EBP + 0xc ]=&gt; param_2 00401046 FF7510 PUSH dword ptr [EBP + 0x10 ]=&gt; param_3 </code></pre> <p>This is the <strong>REASON</strong> for the values mismatch and the <strong>HOW</strong> the values are obtained, but <strong>WHY</strong> is Ghidra naming variables based on the function entry? @emteere explains that:</p> <blockquote> <p>The choice of stack variable offsets based on the frame variable versus stack variables based on the stack pointer can cause some confusion. What it allows is ignoring the stack frame variable and just creating references to the stack wherever they occur however they occur. <strong>There are many examples of the stack pointer loaded into alternate registers without a frame</strong>, so a universal base of the stack at entry seemed like a good choice and less confusing when there is and isn't a frame pointer in two different functions. When debug information is loaded the conversion to SP at entry needs to be done. In addition, many compilers have gotten rid of the use of a stack frame register all together.</p> </blockquote> <p>So, I imagine that the explanation is that one normally would wish to have frame-based variable naming, like seen in IDA, at least for some of the most extended architectures/compilers. However, Ghidra names variables with a general policy, and they decided to harmonise behaviour of different architectures/compilers by offseting variables based on the stack-pointer at the time the function is entered.</p> <hr> <p>Sources:</p> <ul> <li><a href="https://github.com/NationalSecurityAgency/ghidra/issues/998" rel="noreferrer">Suspected incorrect FP stack variables in ARM</a></li> <li><a href="https://github.com/NationalSecurityAgency/ghidra/issues/223" rel="noreferrer">local variable's ebp offset doesn't match</a></li> <li>Ghidra help: "Function Signature, Attributes and Variables"</li> </ul>
23540
2020-03-26T21:10:12.077
<p>Why is Ghidra interpreting this incorrectly? The example is very simple.</p> <p>In this stack:</p> <pre><code>0019FF58 $-8 0019FF58 00000002 LOCAL 2 0019FF5C $-4 0019FF5C 00000001 LOCAL 1 0019FF60 $ ==&gt; 0019FF60 0019FF80 OLD EBP 0019FF64 $+4 0019FF64 | 00401025 return to layout.00401025 from layout.sub_40102C 0019FF68 $+8 0019FF68 | 00000041 PARAM 3 0019FF6C $+C 0019FF6C | 0000BABE PARAM 2 0019FF70 $+10 0019FF70 | 0000CAFE PARAM 1 </code></pre> <p>Ghidra obtains:</p> <pre><code>undefined4 Stack[0x4]:4 param_1 XREF[1]: 00401040 (R) undefined4 Stack[0x8]:4 param_2 XREF[1]: 00401043 (R) undefined4 Stack[0xc]:4 param_3 XREF[1]: 00401046 (R) undefined4 Stack[-0x8]:4 local_8 XREF[1]: 00401032 (W) undefined4 Stack[-0xc]:4 local_c XREF[1]: 00401039 (W) 00401032 C745FC01000000 MOV dword ptr [EBP + local_8 ],0x1 00401039 C745F802000000 MOV dword ptr [EBP + local_c ],0x2 00401040 8B5D08 MOV EBX ,dword ptr [EBP + param_1 ] 00401043 8B4D0C MOV ECX ,dword ptr [EBP + param_2 ] 00401046 FF7510 PUSH dword ptr [EBP + param_3 ] </code></pre> <p>Whereas IDA correctly gets:</p> <pre><code>.text:0040102C var_8 = dword ptr -8 .text:0040102C var_4 = dword ptr -4 .text:0040102C arg_0 = dword ptr 8 .text:0040102C arg_4 = dword ptr 0Ch .text:0040102C arg_8 = dword ptr 10h .text:00401032 mov [ebp+var_4], 1 .text:00401039 mov [ebp+var_8], 2 .text:00401040 mov ebx, [ebp+arg_0] .text:00401043 mov ecx, [ebp+arg_4] </code></pre>
Ghidra interpreting stack pointers wrongly
|ghidra|stack-variables|
<p>The question is not clear. Are you asking about</p> <ol> <li>an approach to finding a single input that results in "Correct" being printed? or</li> <li>an approach to deriving a method that will generate correct inputs for you (e.g. keygenning)?</li> </ol> <p>If it is 1, then the answer is as simple as using a calculator.</p> <p>If it is 2, then many options exist, such as using a constraint solver (z3, angr, KLEE).</p>
23554
2020-03-28T09:49:21.440
<p><strong>Background:</strong> I'm a beginner reverse engineer and I wanted to try writing my own c++ programs and reverse-engineering them. I wrote something and I'm not sure a smart way of reversing it. Usually, I can think of it as a math formula and just do it in reverse to figure out the algorithm but I can't think of any other way than brute-forcing for this scenario.</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main() { char key[9]; int total = 0; cout &lt;&lt; "Enter Key: "; cin &gt;&gt; key; for (char item : key) { total = total + (int)item; } if (total == 895) { puts("Correct"); } else { puts("Sorry buddy"); } return 0; } </code></pre> <p>btw sorry if my c++ isn't very good. I am new to this language haha</p> <p><strong>Main Goal:</strong> I want to know if there is a smarter way of going about this or is brute force the only way. Thanks!</p>
Smart approach or Brute force?
|c++|
<p>As suggested in one of the answers, it's because of the base address, I used <a href="https://github.com/sgayou/rbasefind" rel="nofollow noreferrer">rbasefind</a> to find the base_address of the firmware, and edited it to find the address of the bootloader as there was only two strings plus 11 false string positives.</p>
24565
2020-03-30T01:12:08.060
<p>In this <a href="https://github.com/ExtReMLapin/Foretrex601_Research/raw/master/Unknown.bin" rel="nofollow noreferrer">firmware</a> that is ARM Little endian.</p> <p>There is two strings : </p> <pre><code>0x00006953 : Foretrex 701 0x00006960 : Foretrex 601 </code></pre> <p>The issue, is there is no direct Xreft to any of thoses strings ? </p> <p>For the firmware, it's pretty much the same.</p> <p><img src="https://i.stack.imgur.com/fuD10.png" alt=""></p> <p>As IDA cannot find the entry point, to start analyzing the binary (after setting CPU to arm little endian) select all the code (with CTRL+SHIFT+PAGE_DOWN) press C, then "Analyze"</p> <p><img src="https://i.stack.imgur.com/J3Ohq.png" alt=""></p>
In IDA, cannot find xrefs to string in ARM little-endian bootloader/firmware
|ida|binary-analysis|arm|
<p><code>check</code> is a symbol name inside your binary - meaning it's just a name of the function the Ghidra can recognize. </p>
24577
2020-03-31T06:47:10.617
<p>I have disassembled the crackme0x06 challenge (<a href="http://security.cs.rpi.edu/courses/binexp-spring2015" rel="nofollow noreferrer">http://security.cs.rpi.edu/courses/binexp-spring2015</a> inside challenges.zip). It's an ELF 32bit unstripped binary. The decompiled C code using Ghidra looks like :</p> <pre><code>undefined4 main(undefined4 param_1,undefined4 param_2,undefined4 param_3) { undefined local_7c [120]; printf("IOLI Crackme Level 0x06\n"); printf("Password: "); scanf("%s",local_7c); check(local_7c,param_3); return 0; } </code></pre> <p>Intel x86 looks like : </p> <pre><code> ************************************************************** * FUNCTION * ************************************************************** undefined main(undefined param_1, undefined param_2, und undefined AL:1 &lt;RETURN&gt; undefined Stack[0x4]:1 param_1 undefined Stack[0x8]:1 param_2 undefined4 Stack[0xc]:4 param_3 XREF[1]: 08048651(R) undefined[120] Stack[-0x7c] local_7c XREF[2]: 0804863e(*), 08048658(*) undefined4 Stack[-0x9c]:4 local_9c XREF[2]: 08048641(W), 08048654(W) undefined4 Stack[-0xa0]:4 local_a0 XREF[4]: 08048626(*), 08048632(*), 08048645(*), 0804865b(*) main XREF[2]: Entry Point(*), _start:08048417(*) 08048607 55 PUSH EBP 08048608 89 e5 MOV EBP,ESP 0804860a 81 ec 88 SUB ESP,0x88 00 00 00 08048610 83 e4 f0 AND ESP,0xfffffff0 08048613 b8 00 00 MOV EAX,0x0 00 00 08048618 83 c0 0f ADD EAX,0xf 0804861b 83 c0 0f ADD EAX,0xf 0804861e c1 e8 04 SHR EAX,0x4 08048621 c1 e0 04 SHL EAX,0x4 08048624 29 c4 SUB ESP,EAX 08048626 c7 04 24 MOV dword ptr [ESP]=&gt;local_a0,s_IOLI_Crackme_Level = "IOLI Crackme Level 0x06\n" 63 87 04 08 0804862d e8 86 fd CALL printf int printf(char * __format, ...) ff ff 08048632 c7 04 24 MOV dword ptr [ESP]=&gt;local_a0,s_Password:_0804877c = "Password: " 7c 87 04 08 08048639 e8 7a fd CALL printf int printf(char * __format, ...) ff ff 0804863e 8d 45 88 LEA EAX=&gt;local_7c,[EBP + -0x78] 08048641 89 44 24 04 MOV dword ptr [ESP + local_9c],EAX 08048645 c7 04 24 MOV dword ptr [ESP]=&gt;local_a0,DAT_08048787 = 25h % 87 87 04 08 0804864c e8 47 fd CALL scanf int scanf(char * __format, ...) ff ff 08048651 8b 45 10 MOV EAX,dword ptr [EBP + param_3] 08048654 89 44 24 04 MOV dword ptr [ESP + local_9c],EAX 08048658 8d 45 88 LEA EAX=&gt;local_7c,[EBP + -0x78] 0804865b 89 04 24 MOV dword ptr [ESP]=&gt;local_a0,EAX 0804865e e8 25 ff CALL check undefined check(undefined4 param ff ff 08048663 b8 00 00 MOV EAX,0x0 00 00 08048668 c9 LEAVE 08048669 c3 RET </code></pre> <p>My Question is what is "check" keyword? I have run ltrace and strace on the binary, so I know its neither some library function nor system-call. What is it then?</p>
"check:" keyword in Ghidra
|assembly|decompilation|elf|ghidra|decompile|
<p>It looks to be MODBUS messages. The bytes at the end are a CRC in exactly the format MODBUS uses. See <a href="http://modbus.org/docs/PI_MBUS_300.pdf" rel="nofollow noreferrer">Modicon Modbus Protocol Reference Guide</a></p> <p>The backslash sequences like "\F6" are hexadecimal escapes. Other characters are literal ASCII.</p> <p>Here is a Python script that decodes the data and calculates the CRC (which you will see matches):</p> <pre><code>import re import crcmod.predefined stuff = r''' to 12.03.2020 08:04:15 &lt; '7"\05\04\02\16\F6\C6\D6"'#0D to 12.03.2020 08:04:15 &gt; '7S"\05\04\00\02\00\01\91\8E"'#0D to 12.03.2020 08:04:15 &lt; '7"\05\04\02 \22\D1)"'#0D to 12.03.2020 08:04:15 &gt; '7S"\05\04\00\05\00\01\20\4F"'#0D to 12.03.2020 08:04:16 &lt; '7"\05\04\02\19e\83K"'#0D to 12.03.2020 08:04:16 &gt; '7S"\05\04\00\07\00\01\81\8F"'#0D to 12.03.2020 08:04:16 &lt; '7"\05\04\02\00z\C9\13"'#0D to 12.03.2020 08:04:16 &gt; '7S"\01\03\00\00\00\05\85\C9"'#0D to 12.03.2020 08:04:16 &lt; '7"\01\03\0A\00\00\05\DC\00"'#0D to 12.03.2020 08:04:16 &lt; '7"\02\00\00\00\01AD"'#0D to 12.03.2020 08:04:16 &gt; '7S"\01\01\00\00\00\10\3D\C6"'#0D to 12.03.2020 08:04:16 &lt; '7"\01\01\02\00\03\F9\FD"'#0D to 12.03.2020 08:04:16 &gt; '7S"\05\04\00\00\00\01\30\4E"'#0D to 12.03.2020 08:04:16 &lt; '7"\05\04\02\17\03\07\01"'#0D to 12.03.2020 08:04:16 &gt; '7S"\05\04\00\01\00\01\61\8E"'#0D to 12.03.2020 08:04:16 &lt; '7"\05\04\02\16\F6\C6\D6"'#0D to 12.03.2020 08:04:16 &gt; '7S"\05\04\00\02\00\01\91\8E"'#0D ''' modbus_crc = crcmod.predefined.mkCrcFun('modbus') for line in stuff.splitlines(keepends=False): if not line: continue data = line.split('"', 1)[1][:-5].encode('ASCII') data = re.sub(br'\\(..)', lambda m: bytes([int(m.group(1), 16)]), data) print(format(modbus_crc(data[:-2]), '04x'), data.hex()) </code></pre> <p>Output:</p> <pre><code>d6c6 05040216f6c6d6 8e91 050400020001918e 29d1 0504022022d129 4f20 050400050001204f 4b83 0504021965834b 8f81 050400070001818f 13c9 050402007ac913 c985 01030000000585c9 1186 01030a000005dc00 009c 02000000014144 c63d 0101000000103dc6 fdf9 0101020003f9fd 4e30 050400000001304e 0107 05040217030701 8e61 050400010001618e d6c6 05040216f6c6d6 8e91 050400020001918e </code></pre> <p>I'm not sure about the other content.</p>
24579
2020-03-31T09:49:52.153
<p>I have logfiles in the following format without any documentation:</p> <pre><code>to 12.03.2020 08:04:15 &lt; '7"\05\04\02\16\F6\C6\D6"'#0D to 12.03.2020 08:04:15 &gt; '7S"\05\04\00\02\00\01\91\8E"'#0D to 12.03.2020 08:04:15 &lt; '7"\05\04\02 \22\D1)"'#0D to 12.03.2020 08:04:15 &gt; '7S"\05\04\00\05\00\01\20\4F"'#0D to 12.03.2020 08:04:16 &lt; '7"\05\04\02\19e\83K"'#0D to 12.03.2020 08:04:16 &gt; '7S"\05\04\00\07\00\01\81\8F"'#0D to 12.03.2020 08:04:16 &lt; '7"\05\04\02\00z\C9\13"'#0D to 12.03.2020 08:04:16 &gt; '7S"\01\03\00\00\00\05\85\C9"'#0D to 12.03.2020 08:04:16 &lt; '7"\01\03\0A\00\00\05\DC\00"'#0D to 12.03.2020 08:04:16 &lt; '7"\02\00\00\00\01AD"'#0D to 12.03.2020 08:04:16 &gt; '7S"\01\01\00\00\00\10\3D\C6"'#0D to 12.03.2020 08:04:16 &lt; '7"\01\01\02\00\03\F9\FD"'#0D to 12.03.2020 08:04:16 &gt; '7S"\05\04\00\00\00\01\30\4E"'#0D to 12.03.2020 08:04:16 &lt; '7"\05\04\02\17\03\07\01"'#0D to 12.03.2020 08:04:16 &gt; '7S"\05\04\00\01\00\01\61\8E"'#0D to 12.03.2020 08:04:16 &lt; '7"\05\04\02\16\F6\C6\D6"'#0D to 12.03.2020 08:04:16 &gt; '7S"\05\04\00\02\00\01\91\8E"'#0D </code></pre> <p>This snippet from a log file probably represents the current state and operations of our manufacturing machine. Is there something meaningful in the codes to the right of the time stamp?</p> <p>Some observations:</p> <ul> <li>"to" corresponds to "thu" (for Thursday) in our language.</li> <li>It is not hexidecimal since it occasionally contains "83K", Gs, etc. And "\00" corresponds to "null" in ascii.</li> <li>The log code starts with <code>&lt; '7"</code> or <code>&gt; '7S"</code> and ends with <code>"'#0D</code> on all lines. Except occasionally saying something like <code>&gt; '3V1018'#0D</code></li> <li>The space in the third line above is an unknown character, displaying as a rectangle in Notepad++.</li> </ul>
Decoding unknown logfile format
|file-format|
<p>I'm not sure about tools specifically for your first question, but as for your second question, yes, definitely!</p> <p>Decompilation is useful for <em>understanding</em> code, but it is terrible for <em>modifying</em> code. Compilation and decompilation are both lossy processes. Also, there's a lot of things you can do in bytecode that have no Java equivalent, so you shouldn't expect obfuscated bytecode to even decompile cleanly in the first place.</p> <p>Disassembly and assembly by contrast doesn't lose any information and can cleanly roundtrip even to obfuscated bytecode, at least if you use a good disassembler like <a href="https://github.com/Storyyeller/Krakatau" rel="nofollow noreferrer">Krakatau</a>. So if you are comfortable working with bytecode and are working with highly obfuscated bytecode, I would strongly recommend using Krakatau. For regular or moderately obfuscated bytecode (the most common case), other tools such as ASM will work as well, in case you want to use that instead. There are some bytecode quirks that ASM doesn't support properly, but I am not aware of any obfuscators in the wild that exploit them, so this is unlikely to be an issue in practice. </p> <p>Note that the code you are working with may also be using introspection to try to detect tampering, so watch out for that. For example, some old versions of Stringer that I looked at would load themselves and count the number of constant pool entries in the classfile, so modifications would likely break them. (Krakatau makes it possible to avoid adding or removing constant pool entries if you're careful, but your best bet is to just analyze the code to find and remove the tamper checks)</p>
24598
2020-04-03T09:44:29.827
<p>I'm new to Java and working on cleaning up a fairly large Java .jar sample where the obfuscator has renamed symbols into invalid names. For example: </p> <pre><code>import org.lib.00.0.2; public final class 90 extends 2 { public 90() { 90 iiIIiiiiiIiIi; 90 v0 = iiIIiiiiiIiIi; ... } </code></pre> <p>Using Recaf I am renaming these symbols that are using numbers but after doing so Recaf isn't able to find the renamed classes/packages and subsequent compiles with my code changes fail.</p> <p>Are there any tools that will automate restoring the symbols to legal names? If not, how can I rename things in a way that won't break package/class paths?</p> <p>Additionally, I'm considering if I should be using the decompiler at all and maybe just altering the ASM/instructions. I'm pretty comfortable with regular assembly and it seems this might dodge some of the obfuscation measures?</p> <p>Thanks.</p>
Reverse Engineering Java - Deobfuscating symbols
|disassembly|obfuscation|java|deobfuscation|decompile|
<p>You can specify the input you want to pass to the program when executing "run" via GDB:</p> <pre><code>(gdb) r &lt;&lt;&lt; $(python -c "print 'A' * 10") </code></pre> <p>Example:</p> <pre><code>(gdb) r &lt;&lt;&lt; $(python -c "print 'A' * 10") Starting program: /media/sf_CTFs/stackoverflow/24610/test &lt;&lt;&lt; $(python -c "print 'A' * 10") AAAAAAAAAA [Inferior 1 (process 953) exited normally] (gdb) </code></pre> <p>[Edit, based on comment]</p> <p>If you want to be able to interactively decide what the next input you want to send is, without scripting the whole thing beforehand (and assuming that you can't or don't want to use a library such as <code>pwntools</code> to automate the decision process), you might be able to make use of named pipes. However I can't promise that this is the best or most convenient way. At the very least, this method is OS dependent. </p> <p>First, create a named pipe:</p> <pre><code>root@kali:~# mkfifo my_pipe </code></pre> <p>Then, open two shells. </p> <p>On one shell, redirect GDB's input as the pipe's output:</p> <pre><code>root@kali:/media/sf_CTFs/stackoverflow/24610# gdb -nh test &lt; ~/my_pipe </code></pre> <p>On the other shell, open a Python REPL and connect to the named pipe:</p> <pre><code>&gt;&gt;&gt; f = open("/root/my_pipe", "w") </code></pre> <p>The moment you open the pipe, you should see GDB get unblocked on the first shell:</p> <pre><code>Reading symbols from test... (No debugging symbols found in test) (gdb) </code></pre> <p>Now, define the following function in the Python REPL:</p> <pre><code>&gt;&gt;&gt; def cmd(f, s): f.write(s); f.write("\n"); f.flush() ... </code></pre> <p>You should be able to enter input for GDB using the newly defined <code>cmd</code> command. For example, to run the program, enter:</p> <pre><code>&gt;&gt;&gt; cmd(f, "r") </code></pre> <p>This will run the program in the other shell:</p> <pre><code>(gdb) Starting program: /media/sf_CTFs/stackoverflow/24610/test Please enter input </code></pre> <p>You can break GDB with CTRL+C, just remember that all commands need to be entered via <code>cmd</code>.</p> <p>When the time is right, you can send your Python command:</p> <pre><code>&gt;&gt;&gt; cmd(f, 'A' * 10) </code></pre> <p>It will be received in the other side:</p> <pre><code>(gdb) Continuing. AAAAAAAAAA [Inferior 1 (process 1187) exited normally] </code></pre> <p>Don't forget to close the named pipe when you're done:</p> <pre><code>&gt;&gt;&gt; f.close() </code></pre> <p>If this works for you, you can go ahead and create a Python script that acts as an interactive shell, instead of using the REPL.</p>
24610
2020-04-04T14:00:46.133
<p>I am trying to learn GDB to better understand buffer overflows but I can't find an answer to my problem which is how can I send a Python-generated output to the program when the program asks for user input (the <b>gets</b> function in my code below). I can type CTRL+C to send SIGINT but I have not found any way to send the output back to the program.</p> <p>Sample program (disregard the buffer overflow):</p> <pre>#include int main(int argc, char **argv) { char buf[8]; <b>gets(buf);</b> printf("%s\n", buf); return 0; } </pre> <p>Sample Python script I want to do:</p> <pre> python -c "print 'A' * 10" </pre> <p>The Python output I want the <b>gets</b> function to read:</p> <pre> AAAAAAAAAA </pre>
GDB - Send Python output to the program after SIGINT
|gdb|python|
<p>I continued to mess with it some more and found a way. I correct the signature to have a pointer of argv:</p> <pre><code>int main(int argc, char **argv) </code></pre> <p>But I don't really know why the pointer works and the standard C signature didn't. Hope for someone to clarify this.</p>
24612
2020-04-04T17:20:18.317
<p>I'm new to ghidra. I download the easy_reverse from <a href="https://crackmes.one/crackme/5b8a37a433c5d45fc286ad83" rel="nofollow noreferrer">crackme.one</a> and open the executable file in ghidra.</p> <p>When I'm trying to edit the <code>main</code> function signature I get an error: <code>Can't parse name: argv[]</code>. I searched for this error but found nothing on Google/GitHub and I run out of ideas what to do next to solve it. I would appreciate any help!</p> <p>Here is a screenshot (I use mac): <a href="https://i.stack.imgur.com/md7Nh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/md7Nh.png" alt="enter image description here"></a></p>
Ghidra error when edit main signature function
|c|ghidra|functions|
<p>You can use <a href="https://ghidra.re/ghidra_docs/api/ghidra/program/database/function/FunctionManagerDB.html" rel="noreferrer"><code>FunctionManager</code></a> to get all the functions in the current program and then, from it iterate and get signatures of each.</p> <pre><code>fm = currentProgram.getFunctionManager() functions = fm.getFunctions(True) for f in functions: print(f.getSignature().getPrototypeString()) </code></pre> <p>The output:</p> <pre><code>Signatures.py&gt; Running... char * strcpy(char * __dest, char * __src) int mkdir(char * __path, __mode_t __mode) int fclose(FILE * __stream) int printf(char * __format, ...) void * memset(void * __s, int __c, size_t __n) void * memcpy(void * __dest, void * __src, size_t __n) FILE * fopen(char * __filename, char * __modes) char * strcat(char * __dest, char * __src) ... </code></pre>
24614
2020-04-04T19:04:29.853
<p>I have been trying to extract the function prototypes from a binary file using Ghidra. Up till now what I have done was to use Ghidra's included "Decompile" script and filtered out the function prototypes through the produced text file using python. However, this approach seems to be cumbersome and sometimes it fails to produce the intended results when the compiler options are changed. I feel that there may be a quicker way to get these. Given a binary, my requirement is to get all the function prototypes such as <code>float strtof_l(char *__nptr,char **__endptr,__locale_t __loc)</code> without the function bodies. Is there any existing script to do this? Or is there a method in the API that I could loop upon. Thank you very much. </p>
Way to get all the function prototype using Ghidra
|binary-analysis|firmware|radare2|ghidra|
<p>After investigating a lot I found that there is only one software able to communicate with this ECU. It is the ancient <strong>PCHUD</strong> from Delco which is mentioned in the manual of the Delphi MT05.</p> <p>But this program has been written in 1993 for Windows 3. It does not run on a 64 bit Windows which is the standard nowadays. It is quite primitive and does not support ELM 327 adapters (which did not exist in 1993)</p> <p>So I began to reverse engineer this old software (which was difficult to find) and wrote my own program which now replaces it: <strong>HUD ECU Hacker</strong></p> <p>I designed HUD ECU Hacker as &quot;community software&quot;. This means that the program is 100% configurable by the user in an XML file. This &quot;parameter file&quot; contains the commands sent to the ECU and how to interpret the responses. This allows to adapt HUD ECU Hacker also to other ECU's.</p> <p>Meanwhile also the Liteon MC21, Lifan EFI 9 and Yeson 28S ECUs have been added. Also support for <strong>CAN bus</strong> (OBD2 scanning and sniffing) has been added. Supported protocols: ISO9141, ISO14230, ISO15765, CAN Raw.</p> <p>The program is still growing. I added lots of new features in the last months.</p> <p>Now it can also download the <strong>flash memory</strong> from the MT05 ECU with the calibration tables, correct the checksum and program the flash memory (tuning).</p> <p>HUD ECU Hacker finds <strong>calibration tables</strong> automatically in a flash memory file. It finds approx 170 tables and 500 scalar values. Calibration tables can also be displayed as 3D model.</p> <p>Download and detailed description here: <a href="https://netcult.ch/elmue/HUD%20ECU%20Hacker/" rel="nofollow noreferrer">https://netcult.ch/elmue/HUD%20ECU%20Hacker/</a></p> <p><a href="https://i.stack.imgur.com/XTK5s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XTK5s.png" alt="HUD ECU Hacker Control" /></a></p> <p><a href="https://i.stack.imgur.com/poGcy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/poGcy.png" alt="HUD ECU Hacker Dashboard" /></a></p> <p><a href="https://i.stack.imgur.com/tX8PI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tX8PI.png" alt="HUD ECU Hacker Graph" /></a></p> <p><a href="https://i.stack.imgur.com/tIzbr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tIzbr.png" alt="HUD ECU Hacker Delphi MT05 Calibration Table Tuning" /></a></p> <p><a href="https://i.stack.imgur.com/Z0N7f.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z0N7f.png" alt="HUD ECU Hacker Delphi MT05 Calibration Table Tuning 3D" /></a></p>
24629
2020-04-06T15:28:02.437
<p>The ECU (Engine Control Unit) MT05 from Delphi is used today in many motorbikes and ATV's:</p> <ul> <li>Regal Raptor (Raptor, Daytona and Spider 350)</li> <li>AJP (PR7)</li> <li>Benelli (BN600)</li> <li>CFmoto (Terralander X8)</li> <li>Zongshen (RX3)</li> <li>Zhejiang (TR125)</li> <li>Hyosung (GT650RC)</li> <li>Scomadi scooters</li> <li>Riya scooters</li> <li>Quadro scooters</li> <li>and more... </li> </ul> <p>But this ECU is not OBD2 compliant and so all current OBD2 scanner software will fail to read even the most basic parameters like "Engine speed".</p> <p>I want to read the current fault code (DTC). How can I do this?</p> <p><a href="https://i.stack.imgur.com/5ziY0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5ziY0.jpg" alt="Delphi MT05 ECU"></a></p>
How to scan the ECU Delphi MT05?
|ecu|
<p>The issue turned out that the directories I was working in were mounted as a share in a VirtualBox guest. By default symbolic linking is not enabled on a shared folder as the host OS might not be able to understand a symbolic link. More information can be found here in the second comment: <a href="https://www.virtualbox.org/ticket/18572?cversion=0&amp;cnum_hist=2" rel="nofollow noreferrer">https://www.virtualbox.org/ticket/18572?cversion=0&amp;cnum_hist=2</a></p> <p>My problem was solved once enabling symbolic linking for my shared drive and then creating a symbolic link from squashfs-root/lib/ld-uClibc-0.9.29.so to squashfs-root/lib/ld-uClic.so.0</p>
24634
2020-04-06T20:35:58.293
<p>BLUF: When executing <code>sudo chroot . ./qemu-mipsel-static ./bin/busybox</code> from the squashfs-root folder the error <code>/lib/ld-uClibc.so.0: No such file or directory</code> is returned. Failing to figure out how to fix the error.</p> <p>I am in the early stages of analyzing a firmware update for a consumer router. Busybox is included with the firmware and I am trying to see what I can run with it in an emulated environment. </p> <p>I see that a version of the uClibc library is included with the firmware: <code>/lib/ld-uClibc-0.9.29.so</code></p> <p>I tried symlinking ld-uClibc-0.9.29.so to ld-uClibc.so.0 but I receive <code>ln: failed to create symbolic link 'ld-uClibc.so.0': Operation not permitted</code> so my understanding of the symbolic linking process in this context is certainly coming up short.</p> <p>How can I get qemu-mipsel-static to recognize the library? Do I need to install a different library?</p>
ld-uClibc.so.0: No Such file or directory when running qemu-mipsel-static
|qemu|
<p>Consider a function like this:</p> <pre><code>int func1(int x) { int y; char buf[16]; y = x; buf[0]=x&amp;0xff; return y+buf[0]; } </code></pre> <p>If the compiler uses a naive variable allocation algorithm and does not try to use registers for variables, it will likely lay out the variables sequentially in the stack:</p> <pre><code>off| 00 | y dd ? 04 | buf db 16 dup ? </code></pre> <p>Which can be thought of as a structure:</p> <pre><code> struct frame_func1 { int y; char buf[16]; }; </code></pre> <p>In reality, the "base" of the structure will not be <code>ebp</code>, since usually it points between local variables and incoming arguments, i.e "after" this pseudo-structure.</p> <p>I'm not quite sure why the paper goes to the conclusion mentioned in your quote. Maybe the authors mean that detecting local variables which are structures would be akin to detecting structure members in a structure an thus out of scope? Not sure....</p>
24637
2020-04-07T03:52:47.227
<p>While reading <a href="https://link.springer.com/article/10.1134/S0361768809020066" rel="nofollow noreferrer">this</a> paper on type recovery from executables, I came across following paragraph:</p> <blockquote> <p>It is worth noting that the domain of parameters of a function can be considered as a structure placed on the stack; in this case, the register %ebp points to the beginning of this structure. For that reason, the automatic detection of the structured types located at the stack (local variables and function parameters of a structured type) is very complicated and is not considered in this paper.</p> </blockquote> <p>And they mentioned that they don't consider such structures in their analysis. Do they simply mean programs like these?</p> <pre><code>#include &lt;stdio.h&gt; struct P { int a; int b; }; int main() { struct P p, *pp; pp = &amp;p; pp-&gt;a = 4; printf("%d\n", pp-&gt;a); return 0; } </code></pre> <p>Or is there any other way which resonates their statement?</p>
structures defined on stack?
|decompilation|type-reconstruction|
<p>getReferencesTo takes an address</p> <p>toAddr() converts a string to Address you can combine both </p> <p>like this</p> <pre><code>&gt;&gt;&gt; getReferencesTo(toAddr("ZwCreateKey")) array(ghidra.program.model.symbol.Reference, [ From: 14095680c To: 1401b33c0 Type: DATA Op: 0 IMPORTED, From: 140a22fbd To: 1401b33c0 Type: DATA Op: 0 DEFAULT, From: Entry Point To: 1401b33c0 Type: EXTERNAL Op: -1 DEFAULT, From: 140628dc5 To: 1401b33c0 Type: UNCONDITIONAL_CALL Op: 0 DEFAULT, From: 1407478dd To: 1401b33c0 Type: UNCONDITIONAL_CALL Op: 0 DEFAULT, From: 1406bdfcd To: 1401b33c0 Type: UNCONDITIONAL_CALL Op: 0 DEFAULT, From: 1408db10c To: 1401b33c0 Type: UNCONDITIONAL_CALL Op: 0 DEFAULT, From: 1406f5dec To: 1401b33c0 Type: UNCONDITIONAL_CALL Op: 0 DEFAULT, From: 1407c7190 To: 1401b33c0 Type: UNCONDITIONAL_CALL Op: 0 DEFAULT, From: 1407d01da To: 1401b33c0 Type: UNCONDITIONAL_CALL Op: 0 DEFAULT, From: 1405a8745 To: 1401b33c0 Type: UNCONDITIONAL_CALL Op: 0 DEFAULT, </code></pre> <p>the function limits its display to max 4096 refs if there are more use the recommended ReferenceManager</p> <pre><code>&gt;&gt;&gt; refs = currentProgram.referenceManager.getReferencesTo(toAddr("ZwCreateKey")) &gt;&gt;&gt; for i in refs: ... print i ... From: 14095680c To: 1401b33c0 Type: DATA Op: 0 IMPORTED From: 140a22fbd To: 1401b33c0 Type: DATA Op: 0 DEFAULT From: Entry Point To: 1401b33c0 Type: EXTERNAL Op: -1 DEFAULT From: 140628dc5 To: 1401b33c0 Type: UNCONDITIONAL_CALL Op: 0 DEFAULT From: 1407478dd To: 1401b33c0 Type: UNCONDITIONAL_CALL Op: 0 DEFAULT From: 1406bdfcd To: 1401b33c0 Type: UNCONDITIONAL_CALL Op: 0 DEFAULT From: 1408db10c To: 1401b33c0 Type: UNCONDITIONAL_CALL Op: 0 DEFAULT </code></pre>
24650
2020-04-08T08:04:09.647
<p>What is the best way to get calling x-refs for a specific function?</p> <p>I am aware of the following method: </p> <pre><code>func = getFirstFunction() while func is not None: func_name = func.getName() if func_name == &lt;my_func&gt;: entry_point = func.getEntryPoint() references = getReferencesTo(entry_point) func = getFunctionAfter(func) </code></pre> <p>Is there a way to do that without iterating through all the functions? </p>
Ghidra Python - Get x-refs of a specific function
|python|ghidra|
<p>As commented, incrementing a maximum value indeed wraps back to 0. However, Iโ€™d like to explain a little about why the code looks like this. The original source probably looked similar to:</p> <pre><code>int pos = 0; while (buf[pos]==0) pos++; </code></pre> <p>Now, a naive/literal translation to assembly would have the check and conditional jump out of the loop at the start and an unconditional jump backwards at the end. However, by converting it into a do-while loop you can get rid of the unconditional jump and have only the conditional one at the end:</p> <pre><code>int pos = -1; do { pos++; } while (buf[pos]==0); </code></pre> <p>While a minor optimization, it can improve branch prediction and over a bug binary result in substantial performance improvements. This is most likely why you see the initial value of -1 which is represented as 0FFFFFFFFh. </p>
24656
2020-04-08T15:52:26.083
<p>I am looking at some assembly code and can't get my head around it. The code below is shown in IDA. My question revolves on what happens in the loop.</p> <p>Let me explain what I exactly don't understand in the loop: Above the little loop <code>eax</code> is set to be <code>FFFFFFFFh</code>, which is basically "1" in all the 32 bits in <code>eax</code>(?). In the little loop <code>eax</code> is incremented. But <code>eax</code> is at max value? What happens when I increment <code>eax</code>? Will it go back to 0?</p> <p><a href="https://i.stack.imgur.com/Nvjpq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Nvjpq.png" alt="enter image description here"></a></p>
increment a register which has maximal value?
|ida|assembly|
<p><code>code</code> does mean that something is interpreted as code to execute (most likely a function)</p> <p>But more can be recovered from this snippet than just that something is executed:</p> <h2>Step 1: <code>(**(code **)(*plVar5 + 0x10))</code></h2> <p>This is most likely a C++ vtable call.</p> <p><code>plVar5</code> should be some variable containing a C++ object, or rather a pointer that should be interpreted as a C++ object. At offset 0 (which is just written <code>*plVar5</code>) is the pointer to the vtable of the object. The element at offset 0x10 in the vtable is some function. If this is the 3rd (vtable[2]) or the 5th (vtable[4]) depends on the pointer size, but let's pretend this is 64bit for this explanation ). This means that this is the 3rd entry, which is typically the first true vtable function after the constructor and destructor at vtable[0] and vtable[1]. Lets call this function <code>prepare_buffer</code>.</p> <p>So the more understandable translation would be</p> <p><strong><code>plVar5-&gt;vtable-&gt;prepare_buffer</code></strong></p> <h2>Step 2: <code>(byte *)plVar5-&gt;vtable-&gt;prepare_buffer(plVar5,(ulonglong)(numBytes + 1))</code></h2> <p>After substituting our previous result into <code>(byte *)(**(code **)(*plVar5 + 0x10))(plVar5,(ulonglong)(numBytes + 1))</code></p> <p>Because this is C++ function of an object the first parameter is the <code>self</code> parameter, which has to be present for non static functions. So the only true argument is <code>(ulonglong)(numBytes + 1)</code>. The result is assigned to a variable of type <code>byte *</code> and casted as such.</p> <h2>Step 3: <code>memcpy(__dest,param_2,numBytes + 1);</code></h2> <p>This is indeed just a memcopy to the buffer returned by the previous function. Because the only real argument of that previous function call was the number of bytes copied I am assuming it was setting up this buffer (and called it <code>prepare_buffer</code>). If you can find out the class of the variable <code>plVar5</code> you can find the vtable for this class, and then find the actual function that is called here to confirm this.</p> <h2>Further Reading</h2> <p>If you want to learn more about this I suggest <a href="https://alschwalm.com/blog/static/2016/12/17/reversing-c-virtual-functions/" rel="nofollow noreferrer">https://alschwalm.com/blog/static/2016/12/17/reversing-c-virtual-functions/</a> (which I skimmed to explain this) and looking at the Ghidra Advanced Course at <a href="https://ghidra.re/online-courses/" rel="nofollow noreferrer">https://ghidra.re/online-courses/</a> that includes a Chapter on "Virtual Function Tables" which covers the Ghidra specifics of getting proper decompiler output for such cases.</p>
24661
2020-04-09T13:19:36.713
<p><code>__dest = (byte *)(**(code **)(*plVar5 + 0x10))(plVar5,(ulonglong)(numBytes + 1)); memcpy(__dest,param_2,numBytes + 1);</code></p> <p>Can someone please explain what the first line does step by step? I get that it's preparring a byte array for the memcpy function but I'm confused by the rest, especially that "code" type. Is that an opcode or something ?</p>
What does this decompiled line mean?
|c++|arm|ghidra|
<p>As @blabb says undname is correct so it's your other tool that is 'incorrect'. However, it's worth looking at this in more detail as it's probably not as incorrect as you think.</p> <p>To understand this though you have to delve a little into ABIs and think how a C++ function call works in practice.</p> <p>Firstly, a C++ member function is in some sense like a C function with a 'hidden' <code>this</code> pointer passed as the first parameter. (This is what <code>__thiscall</code> is saying behind the scenes.)</p> <pre><code>// this function void class::member(); // is really void __thiscall class::member(); // and works like void __stdcall class_member( Class* this ); </code></pre> <p>Secondly, the caller of function returning a ('complicated') struct/class is responsible for allocating the memory for the struct/class and passing the function a pointer to this memory. The function can then write the relevant details there. Hence -</p> <pre><code>// this function complex_struct_return_type function(); // works like void function( complex_struct_return_type * ); </code></pre> <p>Putting these together (and ignoring accessiility specifiers)-</p> <pre><code>// this function FName __thiscall User::GetClassNameW( int param ); // works like void __stdcall User_GetClassNameW( User* this, FName* pointer_to_return_value, int param ); </code></pre> <p>You will see this is very similar is essence to your other tool's output. I'd just observe that -</p> <ul> <li>it is still labelling the function as <code>__thiscall</code>. This doesn't quite make sense but is probably being done to indicate that the first parameter has special treatment in 32-bit code.</li> <li>it is changing the case of the initial letters. This again is strictly incorrect.</li> </ul> <hr> <p>How these parameters get passed (by msvc) depends on whether it's compiled for 32 or 64-bit .</p> <ul> <li>For 32-bit code, <code>this</code> has special treatment and is passed in <code>ecx</code> with the rest of the parameters on the stack.</li> <li>For 64-bit code, <code>this</code> is treated as like the other parameters and hence, being the first of up to 4 parameters being passed in registers will be in <code>rcx</code></li> </ul>
24663
2020-04-09T17:34:55.123
<p>I've discovered undname.exe today and tried it on several functions. I got some incorrect results and I'm wondering why. I see two main reasons that could do that:</p> <ul> <li>The mangling can change between msvc versions and I should find the version of undname.exe that fit my target</li> <li>The tool I use to extract the function names gives inaccurate results</li> </ul> <p>Here's an example of a wrong result: </p> <pre><code>Undecoration of :- "?GetClassNameW@User@@QAE?AVFName@@H@Z" is :- "public: class FName __thiscall User::GetClassNameW(int)" </code></pre> <p>After trying this signature and receiving a stack error, I looked at the disassembled code of <code>GetClassNameW</code> and realised the function signature actually was <code>void(__thiscall* user_getClassNameW)(User*, FName*, int);</code> </p> <p>I do not know the exact version of msvc used to compile the example and it seems that the only way to download undname.exe is to install visual studio, so I can't easily test this.</p> <p>Any idea where the problem could come from?</p>
undname.exe: invalid undecorated names
|c++|msvc|name-mangling|
<p>In angr, there are multiple ways to print out what you want. You can reference functions or basic blocks. All you need to print out disassembly is an address:</p> <pre><code>import angr p = angr.Project("/bin/true",auto_load_libs=False) block = p.factory.block(p.entry) block.pp() </code></pre> <p>In this case, I load the <code>true</code> binary, excluding its dynamic libraries, and I ask it for the disassembly at the entry address of the binary. The <code>pp</code> function stands for pretty print, and it will allow you to print assembly in a pretty format. </p> <p>Now getting every disassembled address in a linear format, like objdump, is much more hacky in angr. It would be much more advisable to use <a href="https://github.com/angr/angr-management" rel="nofollow noreferrer">angr-management</a> and copy the linear disassembly from the GUI, but for the sake of this question, here is a hacky script to get every basic blocks disassembly:</p> <pre><code>import angr p = angr.Project("/bin/true",auto_load_libs=False) cfg = p.analyses.CFGFast() cfg.normalize() for func_node in cfg.functions.values(): if func_node.name.startswith("__"): continue else: for block in func_node.blocks: block.pp() </code></pre> <p>It is important to note that the disassembly may not be in order, though it will specify it's address -- this is because we disassemble in the order angr discovers functions. </p>
24664
2020-04-09T17:55:32.350
<p>I would like to know how to export angr's disassembly in say txt file.</p> <p>I looked at the angr documentation - <a href="https://angr.io/api-doc/angr.html#module-angr.analyses" rel="nofollow noreferrer">https://angr.io/api-doc/angr.html#module-angr.analyses</a></p> <p>I found that there are some endpoints like - Disassembly, cfgfast under proj.analyses. I want to get objdump like disassembled input. <a href="https://www.usenix.org/system/files/conference/usenixsecurity16/sec16_paper_andriesse.pdf" rel="nofollow noreferrer">This</a> paper says that they used cfgfast for their analysis. So, I checked that class, but couldn't find particular methods to print the assembly. For e.g. in radare2, I can do -</p> <pre><code>r2.cmd('aaa') r2.cmd(f'pd $s &gt; {filename+"_radare.txt"}') </code></pre> <p>to get the disassembly after analysis.</p>
How to export disassembly using angr
|angr|
<p>I don't know how any examples how you could get the line like Ghidra would render it, but as a start you can look at <a href="https://github.com/schlafwandler/ghidra_ExportToX64dbg" rel="nofollow noreferrer">https://github.com/schlafwandler/ghidra_ExportToX64dbg</a>.</p> <p>The basic idea is to walk the C-AST and extract the ClangStatements that have a corresponding RVA.</p> <p>This has limitations, namely:</p> <blockquote> <p>At the moment the source code export is limited to elements that appear as <code>ClangStatement</code> in the <code>ClangTokenGroup</code> returned by <code>getCCodeMarkup()</code>. This works fine for most variable assignments and function calls, but excludes most control flow altering constructs (like <code>if</code>, <code>for</code> or <code>while</code>).</p> </blockquote> <p>If you really need the line and not the ClangStatement, my first idea is to search for the Ghidra code that renders the AST, find the part where a line is rendered and extend it to retain a mapping from a line to a list of ClangStatements used in that line. Then you can iterate over the lines and filter for those that use a statement that has the RVA you are interested in.</p>
24685
2020-04-11T10:23:48.977
<p>Is there a way in Ghidra Python to get the corresponding decompile line by <code>RVA</code>? </p> <p>Or the opposite - get the corresponding <code>RVA</code> from a given line in a decompile?</p>
Ghidra Python - Get Decompile Line Text by RVA
|decompilation|python|ghidra|
<p>I think your confusion stems from the fact that quoted part of the spec is talking about the <em>process entry point</em> which is a different concept from the C <code>main</code> function. The <code>main</code> is called by the C library startup code so it will follow the standard calling sequence rather than "Initial process stack layout". For 386, it means that <code>argc</code> will be the first value passed on the stack after the return address, and <code>argv</code> will be the second. I.e. at the beginning of <code>main</code>, the layout will look like this</p> <pre><code>| | +----------------+ | argv | &lt;-- esp+8 +----------------+ | argc | &lt;-- esp+4 +----------------+ | return address | &lt;-- esp +----------------+ </code></pre> <p>If the compiler decides to use the frame pointer, then <code>argc</code> will be typically accessed as <code>[ebp+8]</code> due to the extra 4 bytes taken by the saved <code>ebp</code>.</p>
24694
2020-04-12T21:36:51.367
<p>According to the <a href="http://www.sco.com/developers/devspecs/abi386-4.pdf" rel="nofollow noreferrer">System V ABI for x86</a>, <code>esp</code> should be pointing at <code>argc</code> when entering <code>main</code>. However, I've seen many binaries where <code>argc</code> instead is retrieved from <code>esp + 4</code>, or <code>esp + 8</code>. Is this correct, or am I missing something? Also, why do these offset differ?</p> <p><a href="https://i.stack.imgur.com/X2FWQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X2FWQ.png" alt="Figure 3-31"></a></p>
x86 ELF - argc location on stack?
|assembly|x86|
<p>Firstly, let's understand what goes into <em>edx</em>. <em>edx</em> contains the first argument passed to this function which is a pointer the data that we want to compute its MD5 hash. Looking at images, stack frame of the current function is like:</p> <pre><code>esp + 0x0 --&gt; | local_var_8 | esp + 0x4 --&gt; | local_var_4 | esp + 0x8 --&gt; | return_addr | esp + 0xC --&gt; | arg_0 | </code></pre> <p>At the beginning of the function, <em>sub esp, 8</em> reserves 8 bytes on the stack for two local variables. Then you have the return address and arguments coming afterward. All those pushes that are used to pass arguments to <em>CryptCreateHash</em> will be poped back by that function before it returns to the current function, so the previous position of the stack will be preserved.</p> <p>I believe true reverse engineering consists of understanding the code, not blind trace. Instead of tracing a value on the stack, it is better to look for the caller of this function, understand who has called this function and wherein the code is this function called, and then what is the parameter sent to this function.</p> <p>Answering the second part of your question, you can customize breakpoints in IDA using some Python skills. You can create a conditional breakpoint for example and disable the break action as you have done. Whenever you hit this breakpoint, you can log the content of <em>eip</em> to find which instruction or wherein the code is this data accessed. If it is before this function, just log the data in, if it is after, you can enable break action again.</p> <p>For that you need to consider some matters:</p> <ol> <li>You have to practice IDA python APIs. e.g. for getting a register content you have to call GetRegValue. <a href="https://www.hex-rays.com/products/ida/debugger/scriptable/" rel="nofollow noreferrer">This</a> will help you to begin. <a href="https://www.hex-rays.com/products/ida/support/idapython_docs/" rel="nofollow noreferrer">Here</a> also you can find the list of all IDA python APIs.</li> <li>If you set a breakpoint on a data that is passed to a lot of windows APIs such as crypt APIs, you will hit this breakpoint within a lot of library codes. Always look at the address space and if you are not inside your main program, skip them to avoid reversing library functions that are irrelevant to your main program.</li> </ol>
24699
2020-04-13T20:14:39.307
<p>I am reversing Cryptex.exe 1.0 from Eldad.</p> <p><a href="https://i.stack.imgur.com/3hjS9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3hjS9.png" alt="enter image description here"></a></p> <p>There is unknown-data buffer address stored in edx which gets used as parameter for CryptHashData, which will hash 20 Bytes from there. Now I want to find which function actually writes this buffer (edx stores 0019F578 at this point of debugging) I don't get smart with [esp+C], because esp should be the last push exc, and counting from there it should be push 0?</p> <p>What I want to try is setting a breakpoint on .data 0019F578 without break (since it gets used alot by the program in general) and tracing all functions called till the breakpoint ds:CryptHashData. But that doesn't work in IDA. IDA will not recognize other breakpoints with break after I set up this. I'm glad to learn new methods about tracing, since it's very important to know. <a href="https://i.stack.imgur.com/MC445.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MC445.png" alt="enter image description here"></a></p>
Trace back regularly used .data variable in IDA
|breakpoint|tracing|
<p>Ghidra renamed EAX as <code>param_1</code> because it is a parameter for the current function. This calling convention is similar to <code>fastcall</code>, although not quite the same. Selecting how to pass arguments to functions is up to the compiler, so long as the code belong to the same program.</p> <p>At the beginning of your code, <code>param_1</code> (EAX) contains a pointer to a <code>OLECHAR</code> object. Later, it is saved to <code>local_8</code>.</p> <p><code>@2af4 MOV param_1,EDI</code>. This sets the first parameter to the <em>next</em> call, @2af6.</p> <p>Because EAX is used as parameter for many other functions inside your code, it may be correct to name it <code>param_x</code> even when the value is clearly not the same. On 2b04, the saved original parameter is loaded into EAX, again, being the first parameter for the <em>next</em> call.</p> <p>Personally, I like to use register names and not renaming them, but what you see here does make sense.</p> <p>Edit: You can see that when calling <em>external</em> functions, like <code>FindResourceW</code> the calling convention changes and <code>param_1</code> is now on the stack. This is where it is shown in Green rather than Yellow.</p>
24708
2020-04-15T12:25:40.230
<p>Ghidra is renaming <code>EAX</code> as <code>param_1</code>. Why is this happening? I find it very confusing since it is clearly not a parameter and different uses of <code>EAX</code> are named as if they held the same value.</p> <p><a href="https://i.stack.imgur.com/HxFMX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HxFMX.jpg" alt="enter image description here"></a></p>
Ghidra renaming EAX
|ghidra|
<p>While you can potentially prove that two pieces of binary code are <em>equivalent</em> (i.e. they produce the same results given the same input), this does not by itself mean that the source code was the same. For example, the following two snippets will likely be compiled to the same binary even though the source is different:</p> <pre><code> int f(int x) { return x+1; } int g(int y) { return ++y; } </code></pre> <p>(check on <a href="https://godbolt.org/" rel="nofollow noreferrer">https://godbolt.org/</a>)</p> <p>That said, if you do want to prove that (for example) two functions are equivalent, you can try many different approaches, e.g.:</p> <ul> <li>manual comparison of assembly code/binary diffing (may not work if very different compilers or optimizations settings were used)</li> <li>decompile both functions and compare outputs (same caveat)</li> <li>if the input state is not huge, you can run both functions with all possible inputs and compare outputs</li> <li>in some cases things like symbolic execution or <a href="https://yurichev.com/news/20200410_CBMC_etc/" rel="nofollow noreferrer">SMT solvers</a> can be applied</li> </ul> <p>A more generic problem of detecting authorship of arbitrary code is called "code provenance" and there are several papers on the topic, e.g.:</p> <ul> <li><em>Who Wrote This Code? Identifying the Authors of Program Binaries</em> (Nathan Rosenblum et al.)</li> <li><em>BinPro: A Tool for Binary Source Code Provenance</em> (Dhaval Miyani et al.)</li> </ul>
24713
2020-04-15T17:40:31.247
<p>Let's suppose I have two programs in assembly code. And I want to check if they both came from the same source code, but one was compiled with optimizations. Is there a tool that can do this? Or some general process that can verify this?</p>
Way to check if two assembly programs (one possibly compiled with optimizations) come from the same C source code?
|assembly|compiler-optimization|
<p>you can use intel syntax if you prefer in gas and use $+1 to jump into the middle of the instruction </p> <p>$ cat foo.s</p> <pre><code>.intel_syntax noprefix .global start _start: jz $+1 .byte 0x25,0x45,0x33,0x40,0x00 </code></pre> <p>assemble </p> <pre><code>$ as -o foo.o foo.s </code></pre> <p>disassemble </p> <pre><code>$ objdump.exe -d foo.o foo.o: file format pe-x86-64 Disassembly of section .text: 0000000000000000 &lt;_start&gt;: 0: 74 ff je 1 &lt;_start+0x1&gt; 2: 25 45 33 40 00 and $0x403345,%eax 7: 90 nop 8: 90 nop </code></pre> <p>link </p> <pre><code>$ ld -m i386pep -o foo foo.o </code></pre> <p>debug</p> <pre><code>$ gdb ./foo GNU gdb (GDB) 8.2.1 (gdb) break _start Breakpoint 1 at 0x100401000 (gdb) r Starting program: [New Thread 7876.0x2614] Breakpoint 1, 0x0000000100401000 in __rt_psrelocs_start () (gdb) x/2i $rip =&gt; 0x100401000 &lt;__rt_psrelocs_start&gt;: je 0x100401001 &lt;__rt_psrelocs_start+1&gt; 0x100401002 &lt;__rt_psrelocs_start+2&gt;: and $0x403345,%eax (gdb) si 0x0000000100401001 in __rt_psrelocs_start () (gdb) x/2i $rip =&gt; 0x100401001 &lt;__rt_psrelocs_start+1&gt;: jmpq *0x403345(%rip) # 0x10080434c 0x100401007 &lt;__rt_psrelocs_start+7&gt;: nop (gdb) </code></pre>
24715
2020-04-15T18:13:29.463
<p>I have an asm program made with intel syntax. In this program, I am using this syntax <code>jz $+1</code> from INTEL (+gcc), that means that I jump into the <code>jz</code> instruction (which is 2 bytes). I jump 1 byte further the current instruction. I am trying to find what is the correct syntax to do the same thing in GAS AT&amp;T syntax, but I can't find the information. Does anyone know that?</p>
What is the equivalent of the dollar sign from jmp $+1 in GAS syntax?
|assembly|intel|gas|
<p>These wrappers are used in classes with virtual destructors to cover two situations:</p> <ol> <li><p>ensure that the correct <code>operator delete</code> is called after the object's destruction via <code>delete pClass;</code> statement</p></li> <li><p>deletion of arrays allocated via <code>new Class[N]</code> expression in the <code>delete [] class_array;</code> statement to ensure the correct number of items gets deleted using the correct <code>operator delete</code> and handle potential exceptions during the process</p></li> </ol> <p>From <a href="http://www.openrce.org/articles/full_view/23" rel="nofollow noreferrer">my old article</a>:</p> <blockquote> <p>When class has a virtual destructor, compiler generates a helper function - deleting destructor. Its purpose is to make sure that a proper <code>operator delete</code> gets called when destructing a class. Pseudo-code for a deleting destructor looks like following: </p> <pre><code>virtual void * A::'scalar deleting destructor'(uint flags) { this-&gt;~A(); if (flags&amp;1) A::operator delete(this); }; </code></pre> <p>The address of this function is placed into the vftable instead of the destructor's address. This way, if another class overrides the virtual destructor, <code>operator delete</code> of that class will be called. Though in real code <code>operator delete</code> gets overriden quite rarely, so usually you see a call to the default delete().</p> <p>Sometimes compiler can also generate a <em>vector deleting destructor</em>. Its code looks like this: </p> <pre><code>virtual void * A::'vector deleting destructor'(uint flags) { if (flags&amp;2) //destructing a vector { array = ((int*)this)-1; //array size is stored just before the this pointer count = array[0]; 'eh vector destructor iterator'(this,sizeof(A),count,A::~A); if (flags&amp;1) A::operator delete(array); } else { this-&gt;~A(); if (flags&amp;1) A::operator delete(this); } }; </code></pre> </blockquote> <p>For more details see also <a href="http://www.openrce.org/articles/files/jangrayhood.pdf" rel="nofollow noreferrer"><em>C++: Under the Hood</em></a> by Jan Gray, one of the main developers of Visual C++.</p> <p>I also recommend you to make some classes with custom operators new/delete and check the generated code.</p>
24721
2020-04-16T03:16:59.317
<p>I'm reversing a program which I assume was compiled with MSVC. It's seeming like the first entry in each vtable is the class' destructor. However, when I look at the disassembly and decompilation, it seems like the destructors all take a second argument, and that the object's memory is only freed if that second argument is nonnull.</p> <p>What is the purpose for this second argument? I would think that, if it's a destructor, the class should always be destructed and its memory freed. So why the second argument which could prohibit the memory from being freed up?</p>
MSVC Destructors with 2 Arguments
|msvc|
<blockquote> <p>How come there are entire rows of other data between the 3 stack strings?</p> </blockquote> <p>First of all, in <code>x64</code> Linux code, the stack should be aligned to <code>16</code> bytes before any function call, so you can expect that <code>rsp</code> will be aligned as such in compiler generated code.</p> <p>Now, it's just a compiler's decision how many bytes it will use for item allocation. In GCC, for instance, you can set the alignment of stack items to any power <code>n</code> of <code>2</code>, using <code>-mpreferred-stack-boundary=n</code> option, according to <a href="https://stackoverflow.com/questions/1061818/stack-allocation-padding-and-alignment">accepted answer</a>.</p> <blockquote> <p>Why is my first stack string actually on top of the stack? I would think if I had 3 stack strings in succession, the string coming first in the C program would be at the bottom of the stack, and the last string pushed would be at the top.</p> </blockquote> <p>Again, it's a compiler's decision how it will organise local variables on the stack as long as it produces code compliant with <code>C</code> standard. I agree, that the natural way is to put the arguments in order of declarations on the stack, but as you see, you cannot assume this in general. If you want to force this order, you can put them in a struct, according to <a href="https://stackoverflow.com/questions/1102049/order-of-local-variable-allocation-on-the-stack/1102165#1102165">this answer</a>.</p>
24728
2020-04-17T07:27:39.933
<p>I wrote the following small C program and you can also see the stack in the screenshot.<a href="https://i.stack.imgur.com/0JLE8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0JLE8.png" alt="C stack"></a> My question is twofold:</p> <ol> <li>How come there are entire rows of other data between the 3 stack strings?</li> <li>Why is my first stack string actually on top of the stack? I would think if I had 3 stack strings in succession, the string coming first in the C program would be at the <em>bottom</em> of the stack, and the last string pushed would be at the top.</li> </ol>
Why does this x64 stack have other bytes and seems to be in reverse order?
|c|gdb|stack|
<p>Yes it is!</p> <p>After puzzling over this for a day and a bit I figured it out after posting the question here.</p> <p>Instead of using <strong>File/Import</strong> use <strong>File/Add To Program</strong></p> <p>From there it seems to work as expected.</p>
24739
2020-04-18T02:40:07.880
<p>1980s arcade video games generally had multiple ROM chips.</p> <p>I suppose these often mapped into a single address space and often may have been bank switched in and out of sections of a single address space, and often a mix of the two.</p> <p>Conceptually either should be possible in Ghidra's Memory Map window, using "Overlay" with "File Bytes". Even though I can import a second file into a window that already has a file open, going into the Memory Map, even though there's a dropdown menu for "File Bytes", it's only populated with one file.</p> <p>Is there some way I haven't been able to find that lets me load two ROMs into a single address space? It's certainly useful for many other scenarios than just old arcade games.</p>
Is it possible to load multiple files into a single Ghidra memory map?
|ghidra|
<p>Both files are prepended with a 4 bytes large number; apparently the total size of the data that follows. I am ignoring it because the file sizes seem fixed. (Also, for the images the <em>other</em> important data, its width and height, are not stored in the file.)</p> <h2>Palette</h2> <p>The palette is a 5 bits per channel BGR, with the highest bit unused. The two bytes are stored in little-endian order. Converting to True Color RGB is therefore a matter of bit shifting; you end up with 16 RGB color triplets.</p> <h2>Image</h2> <p>The image is stored in 16 x 16 blocks, each 8 x 8 pixels, and every two consecutive pixels are packed into a single byte, right pixel first. Every pixel value ranges from 0..15 and maps immediately to the palette.</p> <p>To unpack a single 8x8 block, all it takes is</p> <pre><code>for y in range(8): for x in range(4): print (img[4*y+x]]) </code></pre> <p>which yields a series of 2-pixel data. I found it more convenient, below, to unpack each two nibbles immediately into 2 separate pixels; then it's a matter of looping over the right x and y axis to reassemble the entire image in a coherent, linear, 128x128 pixel bitmap.</p> <p>The code below then stores the RGB values for each pixel in a True-color PNG image; alternatively, you could save it as a palettized PNG image as well (or really any other image format you'd like).</p> <h2>Python 3.x code</h2> <p>This code needs <a href="https://pypi.org/project/pypng/" rel="nofollow noreferrer"><code>pypng</code></a>. Adjust the fixed part of the path to your folder structure -- it should end with a slash. Save as <code>cookie2png.py</code> and call from a command line with</p> <pre><code>python cookie2png.py Rose/bu_strawberry_LZ.bin\bu_strawberry_anger </code></pre> <p>i.e., leave off the parts <code>_pal.bin</code> and <code>_spr.bin</code> so the script can find them on its own.</p> <pre><code>import sys,png from struct import unpack path = "/Sprites/Character files/" # base = 'bu_strawberry2' base = sys.argv[1] with open (path+base+'_pal.bin', 'rb') as p: pal = p.read() pal = unpack('&lt;I16H', pal)[1:] pal = [bin(p)[2:].zfill(15) for p in pal] rgb = [(int(p[10:15]+p[10:13],2),int(p[5:10]+p[5:8],2),int(p[0:5]+p[0:3],2)) for p in pal] print ('rgb palette', *['%02x%02x%02x' % (r,g,b) for r,g,b in rgb]) with open (path+base+'_spr.bin', 'rb') as i: img = i.read() # Strip header img = img[4:] # Convert nibbles to bytes img = [[b &amp; 0x0f,b &gt;&gt; 4] for b in img] # Unpack list img = [b for a in img for b in a] # Linearize image target = [] for y in range(16): for yy in range(8): for x in range(16): for xx in range(8): target.append(rgb[img[16*64*y+64*x+8*yy+xx]]) # Convert from palettized into True color target = [color for rgb in target for color in rgb] # Split into rows, required by pypng target = [target[i:i + 3*128] for i in range(0, len(target), 3*128)] w = png.Writer(128, 128, greyscale=False, bitdepth=8) with open(path+base+'.png', 'wb') as f: w.write(f, target) </code></pre> <p>and the results are as expected. Here is your <code>bu_strawberry</code>, and a smattering of interesting others:</p> <p><a href="https://i.stack.imgur.com/kQKFz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kQKFz.png" alt="bu_strawberry"></a> <a href="https://i.stack.imgur.com/JFd1e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JFd1e.png" alt="bu_bitter"></a> <a href="https://i.stack.imgur.com/ACh2i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ACh2i.png" alt="bu_crunchy"></a> <a href="https://i.stack.imgur.com/jO7i3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jO7i3.png" alt="bu_maccha"></a> <a href="https://i.stack.imgur.com/OMeQX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OMeQX.png" alt="bu_opera"></a></p>
24742
2020-04-18T08:13:04.007
<p>I am currently trying to rip the sprites from an Nintendo DS game called Cookie Shop - Create Your Dream Shop but they are all in _LZ.bin files.</p> <p>When I've unpacked its compression, I could see lots of files titles spr.bin and pal.bin <a href="https://i.stack.imgur.com/KExdL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KExdL.png" alt="Figure 1: The file list after unpacking the _LZ.bin"></a></p> <p>I know that these files are the sprites as well as their corresponding palettes but I had zero idea to open them.</p> <p>I tried using CrystalTile2, but all it came out was garbled mess, both the palette and sprite.</p> <p>Here are the hexadecimals for the palettes and sprites respectively. <a href="https://i.stack.imgur.com/CpHSe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CpHSe.png" alt="Figure 2: Palette hex"></a> <a href="https://i.stack.imgur.com/hhuCN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hhuCN.png" alt="Figure 3(1): Sprite hex"></a> <a href="https://i.stack.imgur.com/PdfoB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PdfoB.png" alt="Figure 3(2): Sprite hex (continued)"></a></p> <p>Now this is what the sprite and pallete looked like in NO$GBA. <a href="https://i.stack.imgur.com/Xkih1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xkih1.png" alt="Figure 4: Output sprite"></a> <a href="https://i.stack.imgur.com/GVQcP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GVQcP.png" alt="Figure 5: Output palette"></a></p> <p>Pallette table OBP C (from left to right, RGB Format) 001010 0F0604 130B09 191311 1D1816 1A0C10 1C1013 1F1518 1F1C1D 1F1F1F 0F1808 151E0D 130508 1A0A0F 1D0F12 000000 (not used)</p> <p>Also, the max color hex is 1F, not FF. 001010 is used as a transparency filter if I assume.</p> <p>I also found sprites that were never used in the game, and I went to change the names of the characters, but it ended up freezing the game after I pressed continue.</p> <p>Is it possible to extract the sprites? Because I want to use it to create a sprite sheet, as well as creating a story using these characters.</p>
Trying to rip the sprites of this game
|binary|binary-format|binary-editing|
<p><em>Rewriting my answer:</em></p> <p>The resource editors (like ResTuner) find strings in resources, generally in the .rsrc section. This section is very easy to edit because it contains a tree of pointer/size to data. If you want to edit a string and you do not have enough space for the longer string - you can move it to some other address and fix the pointer and size.</p> <p>If you <em>can</em> find the strings, but they are in .data (or some other section) then they are referenced in code by their offset. If you are lucky, the offsets are hardcoded in the program (i.e. you can see xrefs in RE tools), you can modify them. In this case, write your longer string where you have enough space, like at the end of the section and modify the hard-coded offset to point to the new area.</p> <p>Resizing and moving sections around the binary files is also possible, in case you don't have enough space at the section end.</p> <p>If the offsets to your strings are not hardcoded (i.e. they have no xrefs in RE tools) then they are dynamic and you will have to dig deeper in the code to find where they are referenced.</p>
24746
2020-04-18T17:00:46.353
<p>I would like to replace some hard-coded strings in a compiled exe (in .data) which is in chinese (with no possibility to put it in other languages). I managed to replace strings in hexadecimal with other ones of same lenght, but I face some issues of course when I want to replace strings with longer ones...First option - overwrite - will overwrite next bytes, and second option - insertion - will mess up my .exe probably because of his structure and so one.</p> <p>What possibilities do I have ?</p> <p>Already tried radar2;ResEdit; ResTuner which founds most of strings (string tables) but not the ones which needs interaction in the exe. For example if I click on a button a dialog appears, which is not found by those tools. That's why no I'm in need to replace those strings directly with an hexadecimal editor.</p> <p>After some reasearch it seems that those softwares found string in .rsrc but not in .data</p> <p><strong>EDIT1</strong></p> <p>Now I succeed. It seems that there is some kind of check of string length or something like this but not on all strings...</p> <p>Here is a replaced string with his correct size: <a href="https://i.stack.imgur.com/qZVd1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qZVd1.png" alt="enter image description here"></a> ant it's function: <a href="https://i.stack.imgur.com/SoYUb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SoYUb.png" alt="enter image description here"></a> Here another with length issues:</p> <p><a href="https://i.stack.imgur.com/M23GE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M23GE.png" alt="enter image description here"></a> and it's local function: <a href="https://i.stack.imgur.com/bqHPM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bqHPM.png" alt="enter image description here"></a> Here what I replaced : <a href="https://i.stack.imgur.com/pNTP8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pNTP8.png" alt="enter image description here"></a></p> <p>It seems that ther is probably a check of string length somewhere...where do I need to give an eye ? Thanks!</p> <p><strong>EDIT2</strong> Here sub_41A974 (I tried to understand what this fct is doing but I still don't understand: <a href="https://i.stack.imgur.com/nwmZZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nwmZZ.png" alt="enter image description here"></a></p> <p>The fct sub_4028E0 sets font style :(1/2)</p> <p><a href="https://i.stack.imgur.com/XiCl9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XiCl9.png" alt="enter image description here"></a></p> <p>(2/2):</p> <p><a href="https://i.stack.imgur.com/RKUUE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RKUUE.png" alt="enter image description here"></a></p> <p><strong>EDIT3</strong></p> <p>Seems that doesn't have to deal with any of this. Directly after started the software, my data is trunked (Windbg comfirmed it I only started and exit the software) : <a href="https://i.stack.imgur.com/nRNTE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nRNTE.png" alt="enter image description here"></a></p>
Replace string in hexa with a longer one in .bin without destroying the structure (in .data)
|binary-analysis|radare2|executable|strings|
<p>So, <code>objdump</code>'s <code>-d</code> will only disassemble <em>known</em> code sections, usually <code>.text</code> and possibly other sections marked executable. If the section table is corrupted or missing, this will fail. </p> <p>However, the section table is <a href="https://github.com/BR903/ELFkickers/tree/master/sstrip" rel="nofollow noreferrer">not actually required</a> for a file to be executable by the OS, so it can be removed or modified without affecting the file's behavior. In such cases, you can use <code>-b binary -D</code> to tell <code>objdump</code> to disassemble <strong>all</strong> bytes in the file, ignoring any file structure. This will try to disassemble everything, including <em>file headers</em>, <em>data sections</em>, <em>string tables</em> etc. You will need to make sense out of the resulting disassembly by distinguishing actual code from nonsense produced by disassembling unrelated data. Alternatively, you can figure out the actual executable parts of the file and <a href="https://reverseengineering.stackexchange.com/a/6604/60">disassemble just that</a>.</p>
24750
2020-04-19T02:51:15.780
<p>So I have started to digging in malware analysis and I came across with some malware samples that I couldn't disassembly with objdump. More specifically I use</p> <pre><code>objdump -dS /path/to/malware </code></pre> <p>and I got the output</p> <pre><code>malwareFile: file format pei-i386 objdump: Reading section .text failed because: File truncated </code></pre> <p>With a little search I found</p> <p><a href="https://reverseengineering.stackexchange.com/questions/6598/">Unable to dump malware assembly using objdump</a></p> <p>So I use</p> <pre><code>objdump -b binary -D -m i386 /path/to/malware </code></pre> <p>and I got its mnemonic codes but I cannot understand what happen even after reading from the Linux man page. Does with this way, the data, bss and code segment be treated as a whole? Can I really depend on this solution for my research?</p>
What does objdump -b binary means?
|disassembly|malware|objdump|
<p>If you need null bytes, you can write them to a file and use the file as input for the program, e.g.:</p> <blockquote> <p>echo -e -n &quot;\x00\xFF\xAB&quot; &gt; file.bin</p> <p>program &lt; file.bin</p> </blockquote> <p>You can use also use <a href="https://linux.die.net/man/1/xxd" rel="noreferrer"><code>xxd</code></a> to convert hex to binary:</p> <blockquote> <p>echo &quot;00 FF AB&quot; | xxd -r -p | program</p> </blockquote>
24755
2020-04-19T08:48:57.430
<p>I want to pass raw bytes to a (C) program using the Linux Bash shell. I find that when I try to pass for example "\x00\xFF\xAB", the program receiving the input actually gets the <strong>ASCII character codes</strong> for the string, rather than interpret them as the raw bytes.</p> <p>One way I've seen people accomplish this is by calling <code>python -c 'print("\x00\xFF\xAB")'</code> and piping output to the program under test. Is there a way to do this without using Python by just using the Bash shell?</p>
What are some ways to pass raw bytes to a program via the Linux terminal?
|binary-analysis|binary|fuzzing|
<p>I would add information to the first answer. </p> <p>The switch of the mode from Wow64 to 64bit, aka "Heaven's Gate", is in <code>wow64cpu.dll</code>. <code>offset j_Wow64Transition</code> is a part of <code>wow64cpu.dll</code>.</p> <p><a href="https://www.slideshare.net/YardenShafir/jumping-into-heavens-gate" rel="nofollow noreferrer">These slides</a> helps you to understand the procedure of executing 64bit syscall from Wow64 process with assembly codes as a example.</p>
24758
2020-04-19T10:03:27.073
<p>I've been reading about the way syscalls are called in windows.<br> The general theme in all the articles I read is:<br> 64bit- called inside ntdll<br> 32bit- from ntdll jumping to KiFastSystemcall<br> but when I opened IDA with ntdlls from both 64 and 32 bit to verify these articles this is what I saw:<br> (32bit)</p> <pre><code>NtCreateFile proc near mov eax, 55h ; syscall num mov edx, offset j_Wow64Transition call edx ; weird stub is called instead of KiFastSystemcall. ; I couldn't find anything about it.perhaps a wrapper around KiFastSystemcall? retn 2Ch NtCreateFile endp </code></pre> <p>(64bit)</p> <pre><code>NtCreateFile proc near mov r10, rcx ; NtCreateFile mov eax, 55h test byte ptr ds:7FFE0308h, 1 ; some test to decide wether to use int 0x2E or syscall? ; I don't know why int 0x2E be used. I thought it causes overhead? jnz short loc_18009CB15 syscall retn loc_18009CB15: int 2Eh retn NtCreateFile endp </code></pre> <p>if anyone knows why the system calls are called like this I would love to know.<br> to summarize:<br> (32 bit) why is j_Wow64Transition there instead of KiFastSystemcall?<br> (64 bit) what is being compared and why?<br> thanks. </p>
Windows - syscalls being called in a strange way?
|ida|windows|kernel-mode|kernel|system-call|
<p>From <a href="https://sourceware.org/gdb/onlinedocs/gdb/Continuing-and-Stepping.html" rel="nofollow noreferrer">GDB documentation</a>:</p> <blockquote> <p>Warning: If you use the step command while control is within a function that was compiled without debugging information, execution proceeds until control reaches a function that does have debugging information.</p> </blockquote> <p>and:</p> <blockquote> <p><code>next [count]</code></p> <p>Continue to the next source line in the current (innermost) stack frame. This is similar to step, but function calls that appear within the line of code are executed without stopping.</p> </blockquote> <p>The file you are analysing was not compiled with debug information - GDB in fact tells you that by:</p> <p>&quot;<em>Single stepping until exit from function <code>main</code>, which has no line information.</em>&quot;</p> <p>According to the same GDB docs, to step over one assembly line, which, I assume is what you want to do, you can use <code>nexti</code> (<code>ni</code>) command.</p>
24759
2020-04-19T10:12:23.617
<p><a href="https://i.stack.imgur.com/jfH22.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jfH22.png" alt="enter image description here"></a>My question is, when i dont use any breakpoint it show the message saying "You made it, now keygen me!", but when i put a breakpoint in the main, or any other place it will show a message about __libc_start_main, and will not show the message saying "You made it, now keygen me!", why this happens because of the breakpoint?</p> <p><a href="https://i.stack.imgur.com/vhlcK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vhlcK.png" alt="when i run with break"></a><a href="https://i.stack.imgur.com/ceaGq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ceaGq.png" alt="When i run without break"></a></p>
GDB disassembly - breakpoint problem
|disassembly|gdb|
<p>The first thing I'd do is look at a hexdump. The manufacturer provides firmware updates and specifically I've looked at the file ES08_040.SYS.</p> <p>This clear shows some very readable text scattered throughout the file. Here's some examples -</p> <pre><code>00010e10: 00 02 01 02 02 02 03 02 01 01 00 00 01 01 01 01 ................ 00010e20: 01 00 00 00 20 20 20 4b 41 57 41 49 20 20 45 53 .... KAWAI ES 00010e30: 38 20 20 20 20 44 69 67 69 74 61 6c 20 50 69 61 8 Digital Pia 00010e40: 6e 6f 20 20 44 65 73 74 3a 20 56 65 72 23 20 3a no Dest: Ver# : 00010e50: 20 43 53 20 00 00 00 00 20 20 20 20 20 20 20 20 CS .... 00010e60: 20 20 20 20 20 20 20 20 00 00 00 00 ff ff ff ff ........ 000540f0: 30 00 00 00 00 00 00 00 52 49 46 46 00 00 00 00 0.......RIFF.... 00054100: 57 41 56 45 66 6d 74 20 10 00 00 00 01 00 02 00 WAVEfmt ........ 00054110: 44 ac 00 00 10 b1 02 00 04 00 10 00 64 61 74 61 D...........data 00054120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0006aca0: 31 20 54 6f 75 63 68 20 43 75 72 76 65 20 32 2d 1 Touch Curve 2- 0006acb0: 31 20 c0 af c1 b6 b0 cc de 20 20 20 20 20 32 2d 1 ....... 2- 0006acc0: 32 20 56 6f 69 63 69 6e 67 20 20 20 20 20 32 2d 2 Voicing 2- </code></pre> <p>These strongly suggest that the firmware update file is not encrypted or compressed.</p> <p>The most useful though is here -</p> <pre><code>00001530: 43 6f 70 79 72 69 67 68 74 20 28 43 29 20 32 30 Copyright (C) 20 00001540: 30 30 20 28 32 30 30 38 29 20 52 65 6e 65 73 61 00 (2008) Renesa 00001550: 73 20 54 65 63 68 6e 6f 6c 6f 67 79 20 43 6f 72 s Technology Cor 00001560: 70 2e 20 61 6e 64 20 52 65 6e 65 73 61 73 20 53 p. and Renesas S 00001570: 6f 6c 75 74 69 6f 6e 73 20 43 6f 72 70 2e 20 41 olutions Corp. A 00001580: 6c 6c 20 72 69 67 68 74 73 20 72 65 73 65 72 76 ll rights reserv 00001590: 65 64 2e 48 49 37 30 30 30 2f 34 28 52 30 52 34 ed.HI7000/4(R0R4 000015a0: 30 37 30 30 54 78 57 30 32 78 29 56 2e 32 2e 30 0700TxW02x)V.2.0 000015b0: 32 2e 30 34 dd 0d 30 d1 60 62 20 f6 6f 03 d0 0c 2.04..0.`b .o... </code></pre> <p>Google suggest that this is an RTOS for SuperH cores.</p> <p>To confirm the architecture, I tried disassembling the first part of the dump that looks like code (i.e. at offset <code>0x00000800</code>) This produces very plausible code confirming SH.</p> <pre><code>00000800 7ffc add #-4, r15 00000802 d60a mov.l 0x0000082c, r6 00000804 d20a mov.l 0x00000830, r2 00000806 3268 sub r6, r2 00000808 e500 mov #0, r5 0000080A a005 bra 0x00000818 0000080C 2f22 mov.l r2, @r15 0000080E 6053 mov r5, r0 00000810 468b mov.b r0, @r6+ 00000812 61f2 mov.l @r15, r1 00000814 ... 00000824 000b rts </code></pre> <p>Most interesting though is the instruction at offset 0x00000810. This is only a valid instruction in the <code>SH-2A</code> architecture. (For short sequences, there are online disassemblers that let you easily change architectures so you can see which work.)</p> <p>Given we know that it's SH-2A, this <a href="https://www.renesas.com/us/en/products/microcontrollers-microprocessors/superh.html" rel="nofollow noreferrer">page</a> seems to indicate that the MCU is likely to be from one of <code>SH72xx</code> families.</p> <p>To dig further in to the code, it helps to understand more about the MCU in terms of memory maps, embedded peripherals. In your case, as you have the hardware, opening it up and having a look at the PCB inside will probably give you the ids of the MCU and other key components.</p> <hr> <p>If you key objective is changing data (e.g. chord progressions) this is, in theory, easier than anything other than trivial modifications to code.</p> <p>You do however need to identify where in the firmware this info is stored. Understanding the code itself can help with this.</p> <p>Another challenge you may face is how to persuade the firmware update process to accept your modified firmware. You will probably have to play with version numbers and may have to reverse engineer some form of integrity check (e.g. checksum)</p> <p>This may be harder if the relevant validation code is in a bootloader, not in firmware. Again, reading the relevant MCU manuals may help. In addition, getting hold of the relevant Renesas SDK/Build Tools would help too.</p> <p>You might want to try making a trivial modification to one of the early UI messages in the firmware (e.g. 1 character) and try upload this. Whether this works or not will give you a good idea of the amount of effort you are getting yourself into.</p> <p>Finally, it is possible to badly mess-up firmware updates and 'brick' you device enough that it will need returning to the manufacturer for repair. Do this at your own risk.</p> <hr> <p>There are tools that can help with much of this process. e.g. <code>binwalk</code> will find the RTOS name and <code>binwalk -A</code> fill identify a few sequences of SuperH instructions.</p>
24792
2020-04-22T15:19:28.897
<p>I'm curious if anyone has any insight on how I can manipulate or mod the code for the built-in software of a digital piano (specifically the Kawai ES8 - or really any digital piano with a display screen). Like if I wanted to change the default chord progressions for the backing tracks, etc.</p> <p>Note that I don't want to connect it to my computer and read the MIDI data (latency issues) - I want to be able to mod the built-in code directly on the digital piano. I'm getting no luck googling so wanted to see if anyone could point me in the right direction.</p> <p>Much appreciated!</p>
How can I mod the built-in software of my digital piano?
|patching|
<p><code>CALL</code>s and <code>JMP</code> (<code>Jxx</code>) are relative.</p> <p>In your first code block the "jumper" code jumps forward <em>0e</em> bytes, which is "0e 00 00 00" in little endian.</p> <p>In your second code, "jumper" appears <em>after</em> "shellcode", so the <code>CALL</code> backwards is a negative int, and results in your case in "df ff ff ff".</p>
24800
2020-04-23T00:14:37.200
<p>I'd like to know why NASM generates different opcodes for the same code, when it's in the begin or end of the program? This question is important because I found NULL characters when I compile the jumper label in the begin of the program, but when I write the same code in the end, it changes and there's no NULL character there. Could anyone give me a hint about it? I have here the NASM code, and the output of objdump.</p> <p>NASM code (jumper label in the begin of code):</p> <pre><code>global _start section .text jumper: call shellcode msg: db "Hello World",0xA _start: jmp short jumper shellcode: xor edx, edx mov dl, 0xc pop ecx xor ebx, ebx inc bl xor eax, eax times 0x04 inc al int 0x80 xor ebx, ebx xor eax, eax inc eax int 0x80 </code></pre> <p>It has NULL characters as we can see... (objdump results) Generate with above code:</p> <pre><code>hello-shellcode: file format elf32-i386 Disassembly of section .text: 08049000 &lt;jumper&gt;: 8049000: e8 0e 00 00 00 call 8049013 &lt;shellcode&gt; 08049005 &lt;msg&gt;: 8049005: 48 dec eax 8049006: 65 6c gs ins BYTE PTR es:[edi],dx 8049008: 6c ins BYTE PTR es:[edi],dx 8049009: 6f outs dx,DWORD PTR ds:[esi] 804900a: 20 57 6f and BYTE PTR [edi+0x6f],dl 804900d: 72 6c jb 804907b &lt;shellcode+0x68&gt; 804900f: 64 fs 8049010: 0a .byte 0xa 08049011 &lt;_start&gt;: 8049011: eb ed jmp 8049000 &lt;jumper&gt; 08049013 &lt;shellcode&gt;: 8049013: 31 d2 xor edx,edx 8049015: b2 0c mov dl,0xc 8049017: 59 pop ecx 8049018: 31 db xor ebx,ebx 804901a: fe c3 inc bl 804901c: 31 c0 xor eax,eax 804901e: fe c0 inc al 8049020: fe c0 inc al 8049022: fe c0 inc al 8049024: fe c0 inc al 8049026: cd 80 int 0x80 8049028: 31 db xor ebx,ebx 804902a: 31 c0 xor eax,eax 804902c: 40 inc eax 804902d: cd 80 int 0x80 </code></pre> <p>Now I'll change the jumper label to the end:</p> <pre><code>global _start section .text _start: jmp short jumper shellcode: xor edx, edx mov dl, 0xc pop ecx xor ebx, ebx inc bl xor eax, eax times 0x04 inc al int 0x80 xor ebx, ebx xor eax, eax inc eax int 0x80 jumper: call shellcode msg: db "Hello World",0xA </code></pre> <p>(objdump generate with above code) It hasn`t NULL character:</p> <pre><code>objdump -d hello-shellcode -M intel hello-shellcode: file format elf32-i386 Disassembly of section .text: 08049000 &lt;_start&gt;: 8049000: eb 1c jmp 804901e &lt;jumper&gt; 08049002 &lt;shellcode&gt;: 8049002: 31 d2 xor edx,edx 8049004: b2 0c mov dl,0xc 8049006: 59 pop ecx 8049007: 31 db xor ebx,ebx 8049009: fe c3 inc bl 804900b: 31 c0 xor eax,eax 804900d: fe c0 inc al 804900f: fe c0 inc al 8049011: fe c0 inc al 8049013: fe c0 inc al 8049015: cd 80 int 0x80 8049017: 31 db xor ebx,ebx 8049019: 31 c0 xor eax,eax 804901b: 40 inc eax 804901c: cd 80 int 0x80 0804901e &lt;jumper&gt;: 804901e: e8 df ff ff ff call 8049002 &lt;shellcode&gt; 08049023 &lt;msg&gt;: 8049023: 48 dec eax 8049024: 65 6c gs ins BYTE PTR es:[edi],dx 8049026: 6c ins BYTE PTR es:[edi],dx 8049027: 6f outs dx,DWORD PTR ds:[esi] 8049028: 20 57 6f and BYTE PTR [edi+0x6f],dl 804902b: 72 6c jb 8049099 &lt;msg+0x76&gt; 804902d: 64 fs 804902e: 0a .byte 0xa </code></pre> <p>First shellcode: "\xe8\x0e\x00\x00\x00\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x0a\xeb\xed\x31\xd2\xb2\x0c\x59\x31\xdb\xfe\xc3\x31\xc0\xfe\xc0\xfe\xc0\xfe\xc0\xfe\xc0\xcd\x80\x31\xdb\x31\xc0\x40\xcd\x80"</p> <p>Second shellcode: "\xeb\x1c\x31\xd2\xb2\x0c\x59\x31\xdb\xfe\xc3\x31\xc0\xfe\xc0\xfe\xc0\xfe\xc0\xfe\xc0\xcd\x80\x31\xdb\x31\xc0\x40\xcd\x80\xe8\xdf\xff\xff\xff\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x0a"</p>
NULL character (same code) different locations
|shellcode|nasm|
<p>It looks like a USB GSM/UMTS modem. The kernel logs are compatible. It is (was?) used to connect to internet from a PC using a SIM.</p> <p>This is one such product: <a href="https://m.tomtop.com/it/p-c2070.html" rel="nofollow noreferrer">https://m.tomtop.com/it/p-c2070.html</a></p> <p>The MicroSD is used to store user data, to use it as a memory stick, or sometimes used to provide management software for the modem</p> <p>Here superuser question a regarding the MicroSD functionality <a href="https://superuser.com/questions/781844/why-mobile-internet-sticks-have-a-microsd-slot">https://superuser.com/questions/781844/why-mobile-internet-sticks-have-a-microsd-slot</a></p> <p>With the case il looks like this:</p> <p><a href="https://sc01.alicdn.com/kf/HTB1o2ZobpyZBuNjt_jJq6zDlXXaT.jpg_350x350.jpg" rel="nofollow noreferrer"><img src="https://sc01.alicdn.com/kf/HTB1o2ZobpyZBuNjt_jJq6zDlXXaT.jpg_350x350.jpg" alt="Example USB dongle 1"></a> <a href="https://i.ebayimg.com/images/g/heIAAMXQqfZRoiag/s-l400.jpg" rel="nofollow noreferrer"><img src="https://i.ebayimg.com/images/g/heIAAMXQqfZRoiag/s-l400.jpg" alt="Example USB dongle 2"></a></p>
24823
2020-04-25T09:12:31.083
<p>I have this USB stick that seems to have a slot for a SIM and for a SD card. I don't know nothing else about this module. Searching the codes on internet I didn't find anything.</p> <p><a href="https://i.stack.imgur.com/2oQ0M.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2oQ0M.jpg" alt="One side"></a> <a href="https://i.stack.imgur.com/1TF8M.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1TF8M.jpg" alt="The other side"></a></p> <p>How could I find something out about this? And maybe use it in some way?</p> <p>EDIT: It is recognized by the operative system (lsusb output <code>Bus 001 Device 009: ID 0b3c:c003 Olivetti Techcenter</code>)</p> <p>And the kernel logs are:</p> <pre><code>[ 5956.949288] usb 1-1.2: new high-speed USB device number 8 using ehci-pci [ 5956.981766] usb 1-1.2: New USB device found, idVendor=0b3c, idProduct=f000, bcdDevice= 0.00 [ 5956.981773] usb 1-1.2: New USB device strings: Mfr=3, Product=2, SerialNumber=4 [ 5956.981778] usb 1-1.2: Product: HSPA Data Card [ 5956.981781] usb 1-1.2: Manufacturer: USBModem [ 5956.981785] usb 1-1.2: SerialNumber: 1234567890ABCDEF [ 5956.984482] usb-storage 1-1.2:1.0: USB Mass Storage device detected [ 5956.984793] scsi host4: usb-storage 1-1.2:1.0 [ 5958.011311] scsi 4:0:0:0: Direct-Access USBModem MMC Storage 2.31 PQ: 0 ANSI: 2 [ 5958.012120] scsi 4:0:0:1: CD-ROM USBModem MMC Storage 2.31 PQ: 0 ANSI: 2 [ 5958.013018] scsi 4:0:0:0: Attached scsi generic sg2 type 0 [ 5958.018397] sr 4:0:0:1: [sr1] scsi-1 drive [ 5958.019526] sd 4:0:0:0: [sdb] Attached SCSI removable disk [ 5958.020236] sr 4:0:0:1: Attached scsi CD-ROM sr1 [ 5958.020807] sr 4:0:0:1: Attached scsi generic sg3 type 5 [ 5958.323118] usb 1-1.2: USB disconnect, device number 8 [ 5958.545345] usb 1-1.2: new high-speed USB device number 9 using ehci-pci [ 5958.577667] usb 1-1.2: New USB device found, idVendor=0b3c, idProduct=c003, bcdDevice= 0.00 [ 5958.577674] usb 1-1.2: New USB device strings: Mfr=3, Product=2, SerialNumber=4 [ 5958.577678] usb 1-1.2: Product: HSPA Data Card [ 5958.577682] usb 1-1.2: Manufacturer: USBModem [ 5958.577685] usb 1-1.2: SerialNumber: 1234567890ABCDEF [ 5958.580800] option 1-1.2:1.0: GSM modem (1-port) converter detected [ 5958.581066] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB0 [ 5958.581601] option 1-1.2:1.1: GSM modem (1-port) converter detected [ 5958.582001] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB1 [ 5958.582423] option 1-1.2:1.2: GSM modem (1-port) converter detected [ 5958.582890] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB2 [ 5958.583337] option 1-1.2:1.3: GSM modem (1-port) converter detected [ 5958.583616] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB3 [ 5958.583812] usb-storage 1-1.2:1.4: USB Mass Storage device detected [ 5958.586890] scsi host4: usb-storage 1-1.2:1.4 [ 5958.587195] option 1-1.2:1.5: GSM modem (1-port) converter detected [ 5958.587354] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB4 [ 5959.610911] scsi 4:0:0:0: Direct-Access USBModem MMC Storage 2.31 PQ: 0 ANSI: 2 [ 5959.611878] sd 4:0:0:0: Attached scsi generic sg2 type 0 [ 5959.619357] sd 4:0:0:0: [sdb] Attached SCSI removable disk </code></pre>
Misterious USB dongle
|hardware|usb|dongle|
<p>You can use Hex Rays decompiler. But you won't get C# code.</p> <ul> <li><a href="https://www.hex-rays.com/products/decompiler/compare_vs_disassembly" rel="nofollow noreferrer">https://www.hex-rays.com/products/decompiler/compare_vs_disassembly</a></li> </ul>
24827
2020-04-25T17:03:08.790
<p>I heard about dnSpy or ILSpy for decompiling .net files.</p> <p>But how about those files that was NOT written by .net!?</p> <p>Probably those files previous to XP.</p> <p>Is there any tools to decompile it to, preferably, C#!?</p> <p>Much appreciated!</p>
Decompiling tools for "Old" exe files?
|decompiler|
<p>When debugging, IDA uses the actual content of the memory as well as the runtime memory layout and permissions. If the data you loaded into the IDB is not present at runtime, or loaded at a different address/permissions, it will be ignored. </p> <p>Just because you added something to the IDB will not make it appear magically in the debugger, since the OS uses the data from the file on disk and doesn't know anything about IDB. The only exception to this is the <a href="https://www.hex-rays.com/products/ida/support/idadoc/1331.shtml" rel="nofollow noreferrer">Bochs debugger IDB mode</a> which does use data from IDB, but it's a pretty limited emulation environment which is not suitable for debugging full executables.</p>
24834
2020-04-26T11:51:04.747
<p>So i dumped a PE file after it was unpacked, but the problem is it references another section in the memory map, so i dumped that section and added it to IDA just like this question :</p> <p><a href="https://reverseengineering.stackexchange.com/questions/21919/ida-pro-load-data-in-manually-created-segment">IDA Pro - Load data in manually created segment</a></p> <p>and set the segment as read write, everything seems fine</p> <p>but it seems like the change is not reflected in the binary during execution, because even tho i can see the segment content and it seems fine, any instruction that tries to access this segment will raise an exception as if there is no segment there : </p> <p>456BAD: The instruction at 0x456BAD referenced memory at 0x19A650. The memory could not be read -> 0019A650 (exc.code c0000005, tid 756)</p> <p>but even during execution i can see that the content of the memory address 0x19A650 is fine, i think this might be because the binary is not changed or something, but how can i do that? tried saving patches or reloading the database and saving but didnt work!</p> <p>checked the segment access rights and its read write as well</p>
IDA fails to recognize the new added segment during execution and seems to think its empty?
|ida|unpacking|
<p>It's possible that the <em>pyc</em> file is obfuscated/malformed in a way that it trips uncompyle6. Rather than decompiling you can try disassembling the file instead.</p> <p>The <a href="https://docs.python.org/3/library/dis.html" rel="nofollow noreferrer"><code>dis</code></a> module can disassemble Python bytecode. You can use it as follows.</p> <pre><code>import marshal, dis f = open("flag.pyc", "rb") f.seek(16) # Skip 16 byte header (for Python 3.8) co = marshal.load(f) print(dis.dis(co)) </code></pre> <p>There also exists other Python disassemblers libraries like <a href="https://github.com/rocky/python-xdis" rel="nofollow noreferrer"><code>xdis</code></a>. After installing the package (<code>pip install xdis</code>) you can simply run <code>pydisasm flag.pyc</code> to disassemble the <em>pyc</em>.</p> <p>Once you have figured out the reason it trips uncompyle6, you can remove those parts and re-assemble a corrected <em>pyc</em> using <a href="https://github.com/rocky/python-xasm" rel="nofollow noreferrer">xasm</a> which can then be decompiled.</p>
24835
2020-04-26T13:58:43.797
<p>i am doing the CTF-like challenges. One of these tasks need us to decompiling <strong>Python bytecode 3.8</strong> (.pyc file) into py file. However, the py file that generated by pyc file is 0 byte The original file's name is <code>flag.py</code> Here are my procedures.</p> <ol> <li><p>Rename the file: <code>flag.py</code> -> <code>flag.pyc</code></p></li> <li><p>Use <code>uncompyle6</code>tool and type command: <code>uncompyle6 flag.pyc &gt; flag.py</code> </p></li> <li><p>It will generate <code>flag.py</code> file, however it is <strong>0 byte</strong>. And <strong>after several hours</strong>, it is still <strong>0 byte</strong>.</p></li> <li><p>If i interrupt the command line tool by keyboard, the <code>flag.py</code> file will have the comment:</p></li> </ol> <pre><code> uncompyle6 version 3.6.6 Python bytecode 3.8 (3413) Decompiled from: Python 3.8.0 [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] Embedded file name: flag.o.py Compiled at: 2020-04-24 16:09:51 Size of source mod 2**32: 2476187 bytes </code></pre> <p>My environment is MacOS, Python 3.8.0. </p> <p>The .pyc file is small and I've already checked the magic number of the file's header, it is Python 3.8.0. The unusual thing of this pyc file is that there are several thousands of <code>ff 00</code> at the end of the file. </p> <pre><code>55 0d 0d 0a 00 00 00 00 ... ff 00 ff 00 ff 00 ff 00 ... ff 00 ff 00 ff 00 ff 00 b9 01 0c 06 0a 01 08 01 </code></pre> <p>Any Suggestions?</p>
Decompiling .pyc file to 0 byte .py file
|python|decompile|
<p>All action callbacks receive a context pointer with various information pre-filled:</p> <pre><code> ea_t cur_ea; ///&lt; the current EA of the position in the view uval_t cur_value; ///&lt; the possible address, or value the cursor is positioned on func_t *cur_func; ///&lt; the current function func_t *cur_fchunk; ///&lt; the current function chunk struc_t *cur_struc; ///&lt; the current structure member_t *cur_strmem; ///&lt; the current structure member enum_t cur_enum; ///&lt; the current enum segment_t *cur_seg; ///&lt; the current segment </code></pre> <p>(from <code>kernwin.hpp</code>)</p> <p>So you can just use <code>ctx.cur_value</code> (or its Python synonym, <code>cur_extracted_ea</code>) to directly get the address/value/identifier under cursor, without having to resolve it yourself.</p>
24842
2020-04-26T20:28:57.617
<p>I'm using the following code to get the address of the selected function/variable:</p> <pre><code>hightlight = idaapi.get_highlight(idaapi.get_current_viewer()) screen_ea = idaapi.get_screen_ea() ea = idaapi.get_name_ea(screen_ea, name) </code></pre> <p>It works like a charm except until you meet demangled name in IDA View :( </p> <p>For example, for this line </p> <pre><code>.text:00406744 call KBTickCount(void) </code></pre> <p>idaapi.get_name_ea call would never return the proper address, because the real name is ?KBTickCount@@YIJXZ.</p> <p>I know that I can just change demangled names representation in IDA Pro, but I'm working on a public plugin and I'm thinking about end users.</p> <p>And I also want to make it work in Pseudocode view, where all names are demangled.</p> <p>Any ideas on how to get the address of the selected function/variable for a particular line?</p>
IDAPython: idaapi.get_highlight for demangled names
|ida|idapython|idapro-sdk|ida-plugin|
<p>Based on how you have laid it out, you look to have it mostly mapped out correctly, </p> <p>The preamble (control device wake up) would be a general broadcast message to all units on the data bus, (The pull down bus means it can be multi-master) as such it does not need an acknowledge,</p> <p>The other messages follow a command + acknowledge scheme, </p> <p>The check is a generic sum from the command byte to end of destination, (38 + 31 + 09 + 38 + 25 + 31 + 45 + 11 + 1e) = 0x174, cut that down to 1 byte, = 0x74</p> <p>I would suspect if you power cycle the devices you may also find more commands while the devices handshake with each other (the addresses may not be fixed, but randomly chosen on power up) </p> <p><a href="https://i.stack.imgur.com/wC3c2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wC3c2.png" alt="enter image description here"></a></p>
24843
2020-04-27T12:18:43.623
<p>I'm trying to reverse engineer the protocol used by a fairly old video intercom. Using a UART logic analyser was able to guess the baud rate, data bits, start/stop bit. It idles at 14v and pulls to GND for 0.</p> <p>when I press the same sequence repeatedly of buttons I get the following bytes:</p> <pre><code>PREAMBLE (sent when waking up unit): 0x02 0x16 0x10 0x10 0x10 0x10 0x10 0x10 0x11 0x11 0x18 0x03 VIDEO ON: 0x02 0x3c 0x31 0x09 0x38 0x25 0x11 0x6f 0x00 0x1e 0x71 0x03 0x02 0x3d 0x11 0x6f 0x00 0x1e 0x31 0x09 0x38 0x25 0x72 0x03 MIC ON: 0x02 0x4a 0x31 0x09 0x38 0x25 0x11 0x6f 0x00 0x1e 0x7f 0x03 0x02 0x4c 0x11 0x6f 0x00 0x1e 0x31 0x09 0x38 0x25 0x01 0x03 UNLOCK DOOR: 0x02 0x38 0x31 0x09 0x38 0x25 0x31 0x45 0x11 0x1e 0x74 0x03 0x02 0x3a 0x31 0x09 0x38 0x25 0x11 0x6f 0x00 0x1e 0x6f 0x03 </code></pre> <p>Does this appear to be a protocol standard of any kind of control system?</p> <p>EDIT: Here is the best I could understand: <a href="https://docs.google.com/spreadsheets/d/e/2PACX-1vQRyUafqa6CEMd9BOOyAWO4OKGXNKsGLvs6epR5PjqnqBRMbpWOqz2-ij51mFDz4lBUOcVSR7jxK505/pubhtml?gid=1867863786&amp;single=true" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/e/2PACX-1vQRyUafqa6CEMd9BOOyAWO4OKGXNKsGLvs6epR5PjqnqBRMbpWOqz2-ij51mFDz4lBUOcVSR7jxK505/pubhtml?gid=1867863786&amp;single=true</a></p> <p>It seems as though the format is as follows: BYTE1 = STX BYTE2 = COMMAND BYTE3,4,5,6 = SRC BYTE7,8,9,10 = DST BYTE11 = SUM of BYTE2 BYTE10 trimmed to 8-bit</p>
Reverse engineering 12-byte serial packets from doorbell
|serial-communication|
<ol> <li><p>CGI binary files are just regular executables that export functions that can be called from the outside, like a library file. The most common use for CGI is processing data from a web server.</p></li> <li><p>Don't have a particular one. My advice is to take a RE program, loading the code and start reading instructions, looking up the ones you don't know.</p></li> <li><p>MIPS assembly differs from x86 assembly by quite a bit, but consider it a different programming language. Once you learn the concepts of programming in one language, transforming the knowledge to another language is easier. x86 is what most computers run so it is the most common, also, they can run on a PC without complicated emulations.</p></li> <li><p>Don't know of any, but MIPS is common enough so I'll say that there certainly are.</p></li> <li><p>Many run on MIPS. Many others run on ARM. Other architectures exist. From my own experience, they are pretty rare for this use.</p></li> <li><p>IPTVs, Routers and the like, especially older ones, have unprotected executables. Don't bother yourself with learning about obfuscators before you can handle plain assembly.</p></li> <li><p>Yes, the disassembler is not affected by the underlying processor. Besides, AMD and Intel are compatible.</p></li> <li><p>Radare2 and Ghidra are good and free alternatives for IDA. Emulating a hardware device requires a lot more than just the binary you have at hand, there are hardware components (peripherals), addresses that need to be properly configured and additional filesystems that may exist.</p></li> <li><p>You don't have to explain your intentions. What you do with the information is your choice and responsibility.</p></li> </ol>
24844
2020-04-27T13:05:38.933
<p>Hi everyone,<br> I saw this video on youtube as regards as reversing IPTV cameras and finding security vulnerabilities: <a href="https://www.youtube.com/watch?v=B8DjTcANBx0" rel="nofollow noreferrer">Black Hat 2013 - Exploiting Network Surveillance Cameras Like a Hollywood Hacker</a></p> <p>I have a basic knowledge of C, C++ and Python.</p> <p>I have some other questions related to this field:<br> <ol> <li>I've seen that the speaker reverses CGI programs, is this the only filetype involved in reversing MIPS?</li> <li>if someone who has a lot of experience could give me some advices on what to do, where to start, books to buy and courses I would be very very grateful;</li> <li>the assembly code that I get disassembling a MIPS binary has something in common as the one I get when disassembling a x86 program? (I thought that I might learn first x86 assembly and then move on learning MIPS assembly since the former is much more covered on the internet and in textbooks);</li> <li>I would like to know if there are ad-hoc crackmes (I can only find some related to x86 and x86_64) for MIPS architecture;</li> <li>are routers and other IoT devices such as IPTV cameras and so on based exclusively on the MIPS architecture? Or there are other architectures as well?</li> <li>what about obfuscated binaries, of course I don't want to rush and everything but I would like to know more;</li> <li>if I decompile a MIPS firmware on my Intel-powered computer and let's say, in the future I buy an AMD-powered computer, the output of the disassembled program will be the same? With output I mean instruction names and so on;</li> <li>I'm not trying to be a script kiddie but, from what I know, when talking about disassembling tools play a fundamental role. I've seen that IDA PRO is a good choice, however going to their webpage their price is just too much for a student, but there are other free alternatives such as Radare; the other night I tried to emulate a router's firmware using QEMU but I failed and I gave up; I hate copying and pasting things because you never learn anything and sometimes it doesn't work; are there some tools (other than Radare and Qemu) that may aid in reversing and disassembling MIPS firmware and related documentation?</li> <li>last but not least, I'm not trying to be the "hollywood hacker" or be the "bad guy", I'm just trying to expand my knowledge.</li> </ol></p> <p>I know that these questions might be completely dumb, but everyone has been there. I googled everything I could but there are a lot of things and I always get lost. Just to point out, it's not the first time that I try to do reversing in general but I always get demotivated given how hard it is so I though about asking here and getting some advice.</p> <p>Thanks for your time and everything!</p>
Need some help and advices as regards as reverse engineering IoT devices
|disassembly|assembly|binary-analysis|firmware|mips|
<p>The manufacturer's <a href="https://www.elotouch.com/touchscreen-components.html" rel="nofollow noreferrer">website</a> suggests that at least their recent touch screen controllers are either serial and/or USB.</p> <p>The controller picture has the laptop model name (B320) on it which suggests it's a custom version produced by Elo for Lenovo.</p> <p>Looking at the driver files for hardware devices can be one way of understanding how they work. The Windows XP drivers can be found <a href="https://support.lenovo.com/gb/en/downloads/ds018695-elo-touch-panel-driver-for-microsoft-windows-xp-ideacentre-b320" rel="nofollow noreferrer">here</a> on Lenovo's website.</p> <p>This download actually contains both USB and Serial drivers, but these are not Lenovo specific. Instead it looks like the file <code>EloOptions.ini</code> is used to specify exactly which driver to install. This file is clearly customized for Lenovo and confirms that it's the USB driver that is needed.</p> <pre><code>[Setup Options] ; For Lenovo, set all but USB to 0 AutoDetect = 0 AllowInstallApr = 0 AllowInstallSerial = 0 AllowInstallUsb = 1 CalibrateAfterInstall = 0 BaseMode = 0 </code></pre> <p>The <code>EloMTUsb.inf</code> file also suggests that it's installed as a USB HID class device. If so, there's a good chance that you won't have to do too much reverse engineering as it should follow the relevant USB HID standards.</p> <p>The <code>Readme.doc</code> file list various controller part numbers which might also be helpful.</p>
24858
2020-04-28T19:09:05.943
<p>I have taken apart an old non-functional Lenovo IdeaCentre (B320) computer.</p> <p>I would like to get the glass touch panel to 'work' (I would consider anything from simply being able to sniff the x,y coordinates to be 'working').</p> <p>There is a single cable coming from the glass, this cable plugs into a module. The module has only one other connection. This connection has four wires and is connected to the motherboard of the computer. The black and red wires are ground and 5V respectively, this I confirmed by powering on the computer and measuring. The remaining two wires are a mystery, they are (for what it's worth) brown and orange.</p> <p>Following the traces on the module, I can see they are connected to an STM32F102C6 (LQFP48). The two wires are connected to pin 32 (brown) and 33 (orange). I downloaded the datasheet for the MCU, from this I can see pin 32, 33 corresponds to PA11 and PA12 respectively.</p> <p>PA11 has the alternate function 'USART1_CTS/USB_DM'</p> <p>PA12 has the alternate function 'USART1_RTS/USB_DP'</p> <p>I did some googling and it seems that CTS and RTS are only used for data flow control, considering there are no other data wires I assumed the USB protocol is the most likely (even though the wire colors are not conventional to USB). I wired up a USB cable and plugged it into my computer and nothing happened (absolutely nothing).</p> <p>I'm stuck for ideas now. Could it be performing some kind of communication over the USART pin functions or possibly even some kind of bit-banged protocol over the GPIO's? Perhaps the module is dead and that's why the USB isn't detected by the computer.</p> <p>What further steps could I take to reverse engineer this module?</p> <p><a href="https://i.stack.imgur.com/eE7wA.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eE7wA.jpg" alt="Top side of the module, cable from glass pannel detatched"></a></p> <p><a href="https://i.stack.imgur.com/8bwjs.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8bwjs.jpg" alt="Under side of the module, STM MCU visible"></a></p>
Touch screen driver module - Determine comunication protocol
|protocol|usb|
<p>The presence or absence of exports alone is not enough to tell if a file is packed or unpacked. Most executables have no or very few exports but there are also legitimate executables with many exports. Packing can hide exports but might also leave them visible so itโ€™s not a reliable indicator either way. </p> <p>Itโ€™s better to use other means of detecting packed files: entropy, signatures, runtime analysis and so on. </p>
24872
2020-04-30T15:07:11.883
<p>I am new to reverse engineering and I am learning about packed files. I saw that most of the time I can recognize a packed file with a little number of import functions in PE file and not many strings but can the export functions in PE file can give me hint if a file been packed?</p>
PE file export functions of packed file
|static-analysis|packers|
<p>ELF model doesnโ€™t bind symbols to a specific library, so the first module providing a specific symbol is used. You can try to check into which address range the symbolโ€™s value falls. </p> <p>Note, however, that at the beginning most symbols point into the executableโ€™s PLT (program linkage table) so you might need to wait until theyโ€™re actually called to get the resolved addresses. Another option is to put a breakpoint on a symbol and then step into it to see what library you end up in. </p>
24885
2020-05-02T00:12:33.377
<p>I have a stripped-down Linux-based embedded system where a closed-source program(32-bit <code>ELF</code> binary for MIPS) depends on several shared libraries. Two of those libraries are actually the same <code>libcurl</code> library, but compiled differently. I need to know which one the program is actually using.</p> <p>I can't install anything on that embedded system and the file system is read-only. Fortunately, there is a <code>gdb</code> available. When I execute the program and <a href="https://sourceware.org/gdb/onlinedocs/gdb/Attach.html" rel="nofollow noreferrer">attach</a> to it with <code>gdb</code> and print the loaded shared libraries with <code>info sharedlibrary</code>, then both libraries seem to be loaded:</p> <pre><code>(gdb) info sharedlibrary From To Syms Read Shared Object Library /* output removed for brevity */ 0x28c6a8b0 0x28caf770 Yes /usr/lib//libcurl-jke.so.1 0x28d81150 0x28d86260 Yes /usr/lib//libcurl-kkw.so.3 /* output removed for brevity */ </code></pre> <p>Also, when I check the functions or variables with <code>info functions</code> or <code>info variables</code>, then I see items from <code>libcurl</code> under <code>Non-debugging symbols</code>. However, I don't know if those are from <code>libcurl-jke.so.1</code> or from <code>libcurl-kkw.so.3</code>.</p> <p>When I <code>step</code> through the program the debugger never shows that those libraries are used, but I know that they are because I see a HTTP GET request from this embedded system. What might cause this? Is there a way to see all the functions the program executes and files where those functions originate from using <code>gdb</code>?</p> <p>Also, I could download this program and analyze it with <code>radare2</code> if this helps.</p>
How to detect which shared libraries a binary is actually using?
|radare2|gdb|
<p>A Process Has N Number of Modules<br> And these Modules can Load At Different Base Address<br> so using Addresses Like 0x0052BD7E may yield Wrong Results </p> <p>Enumerate The Modules<br> Find The Correct Base Address<br> Add The Relative Virtual Address<br> Read From Those Address </p> <p>here is a small python code that reads the first 10 bytes of Calculator Metro app's ApplicationFrameHost.exe in windows 10 try adapting the concept</p> <pre><code>from ctypes import * import win32con import win32process import win32api calwnd = windll.user32.FindWindowW(None,"Calculator") if(calwnd != None): calpid = c_uint32(0) windll.user32.GetWindowThreadProcessId(calwnd,byref(calpid)) if(calpid.value != 0): process_handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS,False,calpid.value) if(process_handle != None): module_handles = win32process.EnumProcessModules(process_handle) print("Total No of Module = %d" % len(module_handles)) print("base Address Of First Module = %x" % module_handles[0]) print("Mod1=%s" % win32process.GetModuleFileNameEx(process_handle, module_handles[0])) buf = create_string_buffer(16) tmp = c_void_p(module_handles[0]) bread = c_int() windll.kernel32.ReadProcessMemory(process_handle.handle,tmp,byref(buf),16,byref(bread)) for i in range(0,16,1): print(buf[i],end=" ") </code></pre> <p>executing </p> <pre><code>D:\pyt&gt;python writeproc.py Total No of Module = 65 base Address Of First Module = 7ff728780000 Mod1 = C:\WINDOWS\system32\ApplicationFrameHost.exe b'M' b'Z' b'\x90' b'\x00' b'\x03' b'\x00' b'\x00' b'\x00' b'\x04' b'\x00' b'\x00' b'\x00' b'\xff' b'\xff' b'\x00' b'\x00 </code></pre>
24894
2020-05-02T16:18:00.690
<p>I've successfully reversed and patched an application on windows, but patching the executable on disk triggers a CRC check and prevents it from loading. I've used x64dbg and have the addresses I need (they are static and don't change on reruns). However, if the unmodified executable is already loaded and running, and then the patches are applied, everything will work fine. My question is how can I write a simple loader to patch those memory addresses after execution? I've been searching for this all over the Internet and can't get my head around it. The boiler plate codes I've found are giving me headaches as fixing the c++ code errors is so confusing.</p> <p>Here is my code:</p> <pre><code>#include &lt;windows.h&gt; #include &lt;stdio.h&gt; #include &lt;tchar.h&gt; #include &lt;iostream&gt; using namespace std; int main() { int newValue = 0x24; uint8_t readTest; byte num_char[16]; HWND hwnd = FindWindowA(NULL, "Playback password authentication"); if (hwnd == NULL) { cout &lt;&lt; "Cannot find window" &lt;&lt; endl; Sleep(3000); exit(-1); } else { DWORD procID; GetWindowThreadProcessId(hwnd, &amp;procID); HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID); if (procID == NULL) { cout &lt;&lt; "Cannot obtain process." &lt;&lt; endl; Sleep(3000); exit(-1); } else { ReadProcessMemory(handle, (PBYTE*)0x0052BD7E, &amp;num_char, sizeof(num_char), 0); // WriteProcessMemory(handle, (LPVOID)0x0052BD7E, &amp;newValue, sizeof(newValue), 0); cout &lt;&lt; num_char &lt;&lt; endl; Sleep(10000); } } } </code></pre> <p>First I need the code to actually read and print the hex bytes at those addresses so I can make sure the addresses and their values are actually correct. If this returns the correct values, then I think I using WriteProcessMemory won't be that hard. But the problem is the values returned for my addresses are not those I expect and see in x64dbg.</p>
Patching memory
|c++|x64dbg|patch-reversing|
<blockquote> <p>Is <code>movq rax, xmm0</code> buggy in Radare2?</p> </blockquote> <p>No, it's just not fully implemented in all debuggers yet.</p> <h2>Native Debugger Works!</h2> <p>This instruction works fine using the native debugger. The native debugger is launched with <code>r2 -d yourFileGoesHere</code>. Alternatively, if you are already in <code>r2</code> looking at the file, but <code>r2</code> wasn't launched with the <code>-d</code> switch, the file can be reopened in debug mode with the <code>r2</code> command <code>ood</code> (o_pen o_penned file with the d_ebugger ?).</p> <h2><a href="https://radare.gitbooks.io/radare2book/disassembling/esil.html" rel="nofollow noreferrer">ESIL</a> <a href="https://radare.gitbooks.io/radare2book/analysis/emulation.html" rel="nofollow noreferrer">Emulator</a> doesn't fully support SIMD yet.</h2> <p>See Github issues <a href="https://github.com/radareorg/radare2/issues/4327" rel="nofollow noreferrer">#4327</a> and <a href="https://github.com/radareorg/radare2/issues/11421" rel="nofollow noreferrer">#11421</a></p> <p>The &quot;bug&quot; noted in the question was actually demonstrating that the ESIL Emulator doesn't fully support the <code>xmm0</code> register yet.</p> <h2>Summary</h2> <p>The native debugger accurately executes the <code>movq rax, xmm0</code> instruction. The ESIL Emulator does not accurately emulate the <code>movq rax, xmm0</code> instruction <em>yet</em>.</p>
24895
2020-05-02T16:57:30.640
<p>Why doesn't <code>rax</code> get loaded from <code>xmm0</code> here? <code>radare2</code> bug?</p> <p>GitHub issue <a href="https://github.com/radareorg/radare2/issues/16778" rel="nofollow noreferrer">`movq rax, xmm0` doesn't work in native debugger</a> filed.</p> <pre><code>[0x0003b0e0]&gt; drr role reg value ref โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€• SN rax 0 0 R 0x3010102464c457f rbx 0 0 R 0x3010102464c457f A3 rcx 0 0 R 0x3010102464c457f A2 rdx 7ff0000000000000 A1 rsi 0 0 R 0x3010102464c457f A0 rdi 0 0 R 0x3010102464c457f A4 r8 0 0 R 0x3010102464c457f A5 r9 0 0 R 0x3010102464c457f A6 r10 0 0 R 0x3010102464c457f A7 r11 0 0 R 0x3010102464c457f r12 0 0 R 0x3010102464c457f r13 0 0 R 0x3010102464c457f r14 0 0 R 0x3010102464c457f r15 0 0 R 0x3010102464c457f PC rip 3b0ee 241902 (.text) sym.finite R X 'movq rax, xmm0' BP rbp 10078000 268926976 R W 0x0 --&gt; 0 R 0x3010102464c457f rflags 0 0 R 0x3010102464c457f SP rsp 10078000 268926976 R W 0x0 --&gt; 0 R 0x3010102464c457f [0x0003b0e0]&gt; dr xmm0 0xaaaaaaaaaaaaaaaa5555555555555555 [0x0003b0e0]&gt; ds [0x0003b0e0]&gt; drr role reg value ref โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€•โ€• SN rax 8000000000000000 rbx 0 0 R 0x3010102464c457f A3 rcx 0 0 R 0x3010102464c457f A2 rdx 7ff0000000000000 A1 rsi 0 0 R 0x3010102464c457f A0 rdi 0 0 R 0x3010102464c457f A4 r8 0 0 R 0x3010102464c457f A5 r9 0 0 R 0x3010102464c457f A6 r10 0 0 R 0x3010102464c457f A7 r11 0 0 R 0x3010102464c457f r12 0 0 R 0x3010102464c457f r13 0 0 R 0x3010102464c457f r14 0 0 R 0x3010102464c457f r15 0 0 R 0x3010102464c457f PC rip 3b0f3 241907 (.text) sym.finite R X 'and rax, rdx' BP rbp 10078000 268926976 R W 0x0 --&gt; 0 R 0x3010102464c457f rflags 0 0 R 0x3010102464c457f SP rsp 10078000 268926976 R W 0x0 --&gt; 0 R 0x3010102464c457f [0x0003b0e0]&gt; </code></pre>
Is `movq rax, xmm0` buggy in Radare2?
|radare2|debuggers|x86-64|emulation|
<p>There are probably better answers I'd love to know about but let's say you're looking for instructions that have 0x10 as second operand like:</p> <pre><code>cmp eax, 10 mov esi, 10 </code></pre> <p>You could do something like:</p> <pre><code>for func in idautils.Functions(): flags = idc.get_func_attr(func, FUNCATTR_FLAGS) if flags &amp; FUNC_LIB or flags &amp; FUNC_THUNK: continue dism_addr = list(idautils.FuncItems(func)) for cur in dism_addr: if "10h" in idc.print_operand(cur, 1): print "0x%x" % cur, idc.generate_disasm_line(cur, 0) </code></pre> <p>As IDA disassembles 0x10 as 10h, this would work for any instruction where this constant appears. If you need to check other operands I think it's easy to start from the code above. You could also match the mnemonic (CMP, MOV, etc) using <code>idc.print_insn_mnem(cur)</code> if needed.</p> <p>Additionally, I've included a check to make sure the code ignores library and thunk functions as you're probably not interested on them. Feel free to remove the check if you want. ;-)</p>
24913
2020-05-04T13:28:38.990
<p>So lets say i have these type of instructions in functions :</p> <p>x == constant value</p> <p>x = constant value</p> <p>x > constant value</p> <p>no matter if its just an assignment or compare or anything, i want to get the constant values in all functions from main onward </p> <p>tried googling but couldn't find anything that helps me with this, is this possible? </p>
Is there any way to write a IDA script that finds constant values used in all functions, no matter the instruction?
|ida|malware|idapython|
<p>You can't load 32bit Dlls in 64bit Processes</p> <p>Solution: build a 32bit App or write an external 32bit prozess(yes a EXE) that loads the DLL and communication with that process using Pipes or TCP/IP from your 64bit app</p> <p>btw: the first Dlls name is FileAnalyzer.dll, in the Code is FileDataCtrl.dll?</p>
24917
2020-05-05T02:13:04.953
<p>I'm new here so I'm sorry if this isn't the right section for my question.</p> <p>I'm reverse engineering a software that's written in .net 3.5 c# which loads a weird dynamic dll, which has an important functionality of decrypting / encrypting strings. I tried to make a c# program and import the dlls but visual studio complains about invalid / unsupported dll.</p> <p>Here is some output and info:</p> <pre><code>targetframework: .Net Framework v3.5 </code></pre> <pre><code>FileAnalyzer.dll: PE32 executable (DLL) (GUI) Intel 80386, for MS Windows </code></pre> <p>the .net software loads it and hooks its functions like this:</p> <pre><code> public class FileDataCtrlWrap { [DllImport("FileDataCtrl.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] private static extern bool GetPersonalSettingsFolder(byte[] buffer, uint type); [DllImport("FileDataCtrl.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] private static extern bool GetSettingsFolder(byte[] buffer, uint type); [DllImport("FileDataCtrl.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] private static extern bool GetSnapShotFolder(byte[] buffer); [DllImport("FileDataCtrl.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] private static extern bool GetSnapShotPath(string cameraName, byte[] buffer); [DllImport("FileDataCtrl.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] private static extern int Encrypt(string intput, StringBuilder output); ... ... ..etc </code></pre> <ol> <li>How is this .net program loading a pe32 dll? </li> <li>Is it possible to replicate this behavior? If not what are the alternatives?</li> </ol> <p>the dll file can be found <a href="https://filebin.net/sqxsz86tmh63fdq2" rel="nofollow noreferrer">here</a></p>
Loading a PE32 executable DLL Intel 80386 into a c# program
|dll|c#|dll-injection|pe32|
<p>This problem is not unique to <code>call eax</code> but potentially any indirect call or a call to a function with wrong type information. The possible causes and solutions are described in the <a href="https://www.hex-rays.com/products/decompiler/manual/failures.shtml#11" rel="nofollow noreferrer">Hex-Rays Decompiler manual</a>.</p> <p>One common cause is the stack adjustment of the call not being correctly detected by IDA (e.g. the called function is stdcall with arguments but IDA detected that stack change is 0). This can be fixed by specifying the correct stack change value via the <kbd>Alt+K</kbd> shortcut (4 for each push is a good rule of thumb).</p>
24924
2020-05-05T11:45:50.950
<p>I know that there is a similar question but the answers didn't provide any fix for that problem.</p> <p>I am decompiling a .dll file, and I have found out the subroutine that I needed, but it's throwing a "call analysis failed" at line <code>call eax</code>.</p> <p>My question is: Can I properly decompile the subroutine with this <code>call eax</code> line, or can I change it to something else, or simply ignore it? Working in ASM is really tough because I need to take out the code itself, not patch, and manually converting assembly code into pseudocode will be really hard to do.</p>
How to decompile "call eax" in IDA Pro?
|ida|assembly|dll|dll-injection|
<p>the function toString Returns a Qstring in rax<br> doing db poi(@rax) should show you the string after you step over the function </p> <p>a small automated breakpoint</p> <p>setting a conditional breakpoint that sets another one shot breakpoint on return address and prints the content of rax and continues </p> <pre><code>0:006&gt; bl (should be in one line ) 0 e Disable Clear 00000000`5ffd7220 0001 (0001) 0:**** Qt5Core!QT::QVariant::toString "bp /1 @$ra \"db poi(@rax) l30;.echo ========;gc\";gc" 0:006&gt; g 0000027c`ca346580 02 00 00 00 05 00 00 00-06 00 00 00 00 00 00 00 ................ 0000027c`ca346590 18 00 00 00 00 00 00 00-73 00 74 00 61 00 72 00 ........s.t.a.r. 0000027c`ca3465a0 74 00 00 00 00 00 00 00-d8 be 55 86 00 45 02 80 t.........U..E.. ======== 0000027c`d0feb620 02 00 00 00 10 00 00 00-11 00 00 00 00 00 00 00 ................ 0000027c`d0feb630 18 00 00 00 00 00 00 00-30 00 30 00 30 00 30 00 ........0.0.0.0. 0000027c`d0feb640 30 00 30 00 30 00 30 00-30 00 30 00 34 00 30 00 0.0.0.0.0.0.4.0. ======== 0000027c`ca45a750 02 00 00 00 0c 00 00 00-0d 00 00 00 00 00 00 00 ................ 0000027c`ca45a760 18 00 00 00 00 00 00 00-5b 00 6d 00 61 00 69 00 ........[.m.a.i. 0000027c`ca45a770 6e 00 20 00 65 00 6e 00-74 00 72 00 79 00 5d 00 n. .e.n.t.r.y.]. ======== 00000000`60093038 ff ff ff ff 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000000`60093048 18 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000000`60093058 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ ======== 0000027c`ca343040 02 00 00 00 04 00 00 00-05 00 00 00 01 00 00 00 ................ 0000027c`ca343050 18 00 00 00 00 00 00 00-4e 00 61 00 6d 00 65 00 ........N.a.m.e. 0000027c`ca343060 00 00 61 74 69 6f 6e 00-84 bb 01 83 00 29 01 90 ..ation......).. ======== 0000027c`ca3433d0 02 00 00 00 07 00 00 00-08 00 00 00 01 00 00 00 ................ 0000027c`ca3433e0 18 00 00 00 00 00 00 00-41 00 64 00 64 00 72 00 ........A.d.d.r. 0000027c`ca3433f0 65 00 73 00 73 00 00 00-bd bb 48 83 00 3c 01 95 e.s.s.....H..&lt;.. ======== </code></pre>
24927
2020-05-05T15:27:50.900
<p>I'm debugging a Qt App and trying to view QT string object data within debugger. I'm referring to this <a href="https://0cch.com/2019/07/30/windbg-with-qt4-natvis/" rel="nofollow noreferrer">blog</a> which shows how to do that however ,i dont have access to source code. windbg lacks the ability to display basic QT data. In windbg I want to see what all QtStrings are being passed to any Qt-API.</p> <p>In following disassembly string object returned by toString() are being passed to setHttpUserAgent API, arguments are placed on rcx and rdx registers. I want to view those strings in windbg / any debugger.</p> <pre><code>.text:00000001400424CC lea rdx, [rbp+57h+var_90] .text:00000001400424D0 mov rcx, rax .text:00000001400424D3 call cs:?toString@QVariant@@QEBA?AVQString@@XZ ; QVariant::toString(void) .text:00000001400424D9 nop .text:00000001400424D9 ; } .text:00000001400424DA mov rdx, rax .text:00000001400424DD mov rcx, r14 .text:00000001400424E0 call cs:?setHttpUserAgent@QWebEngineProfile@@QEAAXAEBVQString@@@Z ; QWebEngineProfile::setHttpUserAgent(QString const &amp;) .text:00000001400424E6 nop .text:00000001400424E6 ; } </code></pre> <p>To do this i believe i need to have better understanding of Qt string's memory layout. If there is any document which can help me figure that out please let me know.</p> <p>Thanks in Advance.</p>
Viewing QT String Object Data under Windbg
|qt|
<p>The syscall instruction is always invoked in long mode, by the 64-bit <code>ntdll</code> (there are two <code>ntdll</code> in a wow64 process), so the return to <em>user mode</em> should be there. The <code>jmp fword ptr [r14]</code> instruction jumps back to <strong>x86</strong> code from x64. </p> <p>When dealing with mixed mode stacks in WinDbg, the wow64ext extension is useful, e.g.:</p> <pre><code>!load wow64ext !wow64exts.info !wow64exts.k </code></pre>
24932
2020-05-06T11:29:49.747
<p>I'm debugging some 32-bit process using windbg kernel debugger. This process calls some syscalls, so I set few breakpoints at kernel functions like nt!NtQuerySystemInformation. So after breakpoint hit, what's the easiest way to trace back from kernel function to place where syscall was called in user-mode process? It's wow64 so call stack doesn't help, this is how it looks like:</p> <pre><code>[0x0] nt!NtQuerySystemInformation [0x1] nt!KiSystemServiceExitPico + 0x25e [0x2] ntdll!NtQuerySystemInformation + 0x14 [0x3] wow64!whNT32QuerySystemInformation + 0x34 [0x4] wow64!whNtQuerySystemInformation + 0xb4 [0x5] wow64!Wow64SystemServiceEx + 0x15a [0x6] wow64cpu!ServiceNoTurbo + 0xb [0x7] wow64cpu!BTCpuSimulate + 0x9 [0x8] wow64!RunCpuSimulation + 0xd [0x9] wow64!Wow64LdrpInitialize + 0x12d [0xa] ntdll!LdrpInitializeProcess + 0x193e [0xb] ntdll!_LdrpInitialize + 0x4cd95 [0xc] ntdll!LdrpInitialize + 0x3b [0xd] ntdll!LdrInitializeThunk + 0xe </code></pre> <p>I don't want to set breakpoints at usermode modules, have to trace it back from kernel. I've found out that <code>jmp fword ptr [r14]</code> at the end of wow64cpu!RunSimulatedCode is used to jump back to usermode. However RunSimulatedCode isn't always called, some functions use something else. Moreover, after jumping back to usermode windbg cannot retrieve user mode call stack.</p>
Get return address from syscall
|windows|debugging|windbg|kernel|
<p>I just needed to cast to array buffer:</p> <pre><code> var b = Java.use('[B') var buffer = Java.cast(retval, b); var result = Java.array('byte', buffer); var str_ = ""; for (var i=0; i &lt; result.length; i++) { str_ += String.fromCharCode(result[i]); } console.log("String: " + str_) }``` </code></pre>
24940
2020-05-06T23:24:33.877
<p>I'm trying to get the return value of a android native function call using Frida but with no success:</p> <pre><code>Interceptor.attach(Module.getExportByName('lib.so', 'Token'), { onEnter: function(args) { }, onLeave: function(retval) { console.log(retval); } }); </code></pre> <p>I know that the value is a bytearray but I can't find a way to read it from the native pointer.</p> <p>Can anyone point me in the right direction? What should I do the get the value from retval? I already tried to use cast, but it didn't work.</p> <p>thanks</p>
Read bytearray from retval on onLeave event
|android|frida|
<p>There are multiple possibilities how this might happen.</p> <ol> <li><p>The code is loaded dynamically at run-time, e.g. for an [obfuscated/encrypted] dex file that is present in the APK file but does not follow the standard naming scheme <code>/classes*.dex</code>. In case the whole application code is located in such external code files most likely an &quot;APK packer&quot; tool (like DxShield, DexProtector, ..) has been applied on the application. You can try to use <a href="https://github.com/rednaga/APKiD" rel="nofollow noreferrer">APKiD</a> to identify the used packer.</p> </li> <li><p>The code is downloaded from an web-server and then loaded dynamically.</p> </li> <li><p>The code is generated on-the-fly at run-time. This can happen if e.g. based on an interface some proxy-classes are automatically generated using other code as base (e.g. for handling HTTP-[JSON]-RPC calls that are automatically translated to method calls). But usually this code is not located in a new package.</p> </li> </ol> <p>As your question includes the Frida tag you should try to use it (if it works on that application) and check the application at run-time what classes are loaded. You can hook the various classloader methods that allow to load (dex) byte code at run-time and dump/save the loaded byte code.</p> <p>Alternatively there are some tools and tutorials online that claim to be able to defeat Android packers and dump all Dex classes.</p>
24941
2020-05-07T07:16:41.093
<p>I have been diving into an apk's source code, doing both static analysis with Jadx (same as dex2jar) and dynamic analysis with Frida.</p> <p>I am trying to replicate the method that signs HTTP requests "signRequest". The thing is that it is only declared in an interface and nowhere in the code is there an actual implementation of that method. When I use Frida to get the instance that uses this method, I can run the method and make it work. The instance in question is like this: com.xxx.yyy.zzz@24d6bf8 but the thing is that the class com.xxx.yyy.zzz, and even the module com.xxx.yyy, do not exist in the source code.</p> <p>Do you have any idea how this might happen?</p> <p>EDIT: I've had a hunch and thought that maybe, since I had encountered "antidex2jar" classes in the source code, maybe there were protections against dex2jar making it throw errors, therefore preventing it from decompiling the classes, as I had read somewhere. However, even the smali code on Android-Studio doesn't contain the class.</p>
Dynamic analysis (Frida) reveals instance of a class that doesn't exist in the source code (dex2jar)
|static-analysis|java|dynamic-analysis|frida|
<p>Though objdump is a good utility I would recommend using some better utilities to disassemble, like radare2, ghidra or idafree70. </p> <p>But if you would prefer objdump, pass it the -C command to demangle those names.</p> <pre><code>E:\5e4ec05c33c5d4439bb2dbea&gt;f:\msys64\usr\bin\objdump.exe --start-address=0x401012 --stop-address=0x401043 -M intel -d -C Sh4ll10.1.bin Sh4ll10.1.bin: file format elf64-x86-64 Disassembly of section .text: 0000000000401012 &lt;main&gt;: 401012: 55 push rbp 401013: 48 89 e5 mov rbp,rsp 401016: 53 push rbx 401017: 48 81 ec 88 00 00 00 sub rsp,0x88 40101e: 89 bd 7c ff ff ff mov DWORD PTR [rbp-0x84],edi 401024: 48 89 b5 70 ff ff ff mov QWORD PTR [rbp-0x90],rsi 40102b: 83 bd 7c ff ff ff 01 cmp DWORD PTR [rbp-0x84],0x1 401032: 7e 47 jle 40107b &lt;main+0x69&gt; 401034: be 50 17 40 00 mov esi,0x401750 401039: bf 00 22 60 00 mov edi,0x602200 40103e: e8 ed fd ff ff call 400e30 &lt;std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::operator&lt;&lt; &lt;std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, char const*)@plt&gt; </code></pre>
24953
2020-05-09T10:14:28.747
<p>I'm doing a really easy crackmes exercise (<a href="https://crackmes.one/crackme/5e4ec05c33c5d4439bb2dbea" rel="nofollow noreferrer">https://crackmes.one/crackme/5e4ec05c33c5d4439bb2dbea</a>) and I can't figure out what the binary is doing because functions have extremely weird names. </p> <p>Here's a small fragment of the main function disassembly code.</p> <pre><code>... 0x000000000040102b &lt;+25&gt;: cmpl $0x1,-0x84(%rbp) 0x0000000000401032 &lt;+32&gt;: jle 0x40107b &lt;main+105&gt; 0x0000000000401034 &lt;+34&gt;: mov $0x401750,%esi 0x0000000000401039 &lt;+39&gt;: mov $0x602200,%edi 0x000000000040103e &lt;+44&gt;: callq 0x400e30 &lt;_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@plt&gt; 0x0000000000401043 &lt;+49&gt;: mov $0x400ec0,%esi 0x0000000000401048 &lt;+54&gt;: mov %rax,%rdi 0x000000000040104b &lt;+57&gt;: callq 0x400ea0 &lt;_ZNSolsEPFRSoS_E@plt&gt; 0x0000000000401050 &lt;+62&gt;: mov $0x401780,%esi 0x0000000000401055 &lt;+67&gt;: mov $0x602200,%edi 0x000000000040105a &lt;+72&gt;: callq 0x400e30 &lt;_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@plt&gt; ... </code></pre> <p>How should I approach this code?</p>
Weird function names in disassembly (crackmes)
|crackme|
<p>If you want proof-of-concept VM based obfuscator, you can actually skip the virtualization step and bytecode generation step. You can write an interpreter of x86 instructions in x86 assembler so that the implementation is easy. You can add custom instructions one by one later through assembler macros, for example. This is much less complicated process than writing a full-blown VM.</p> <p>The most trivial "VM" that runs some x86 instructions can be found here:</p> <p><a href="https://github.com/Barebit/trivial-vm" rel="nofollow noreferrer">https://github.com/Barebit/trivial-vm</a></p> <p>The vm1.c merely copies an x86 instruction to a buffer and runs it. It is not even an interpreter. The vm2 does the same but interprets few branch instructions that can't be run directly.</p>
24956
2020-05-09T12:04:03.223
<p>I want to implement a VM based simple proof-of-concept obfuscator. It should take an exe file as input and produce a new pe file with appended vm section. For simplicity let's say the exe file is compiled as a 32 bit pe.</p> <p>The problem is that most materials I've found online explain only how to crack and not how to implement such a solution, or just explain how to implement a simple VM with a very limited number of instructions.</p> <p><strong>Architecture</strong></p> <p>I want to build such an architecture as described in <a href="https://www.sciencedirect.com/science/article/pii/S0167404818300270" rel="nofollow noreferrer">this</a> (Enhance virtual-machine-based code obfuscation security through dynamic bytecode scheduling) paper:</p> <p><a href="https://i.stack.imgur.com/bpEW5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bpEW5.jpg" alt="enter image description here"></a></p> <p>Let me quote it:</p> <pre><code>Fig.โ€‰1. A classical process for VM-based code obfuscation. To obfuscate the code, we first dissemble the code region to be protected into native assembly code (1). The assembly code will be mapped into our virtual instructions (2) which will then be encoded into a bytecode format (3). Finally, the generated byecode will be inserted into a specific region of the binary which is linked with a VM library (4). </code></pre> <p><strong>Question</strong></p> <p>Let's say I have implemented a very basic virtual machine with a set of 20 instructions as presented in this<a href="https://www.youtube.com/watch?v=OjaAToVkoTw" rel="nofollow noreferrer"> [presentation]</a>:</p> <pre><code>iadd, isub, imul, ilt, ieq, br addr, brt addr, brf addr, iconst value, load addr, gload addr, store addr, gstore addr, print, pop, call addr, numArgs ret hlt </code></pre> <p>In step 2 (Virtualization), I have to somehow map the extracted Intel instruction set to my virtualized instructions. The Intel instruction set is huge (over 200 instructions). And I have completely no idea how to do this. Starting with the fact that my virtual machine uses fewer of registers then Intel does. </p>
Virtual machine code obfuscation implementation details
|obfuscation|deobfuscation|virtual-machines|
<p>The compiler creates the code block by block, each line of the source code can correspond to one or several blocks. In the case of optimized code, sometimes several blocks of source code can turn into one.</p> <p>This basic block of code can be divided into the following logical blocks</p> <pre><code>; block #1 mov edi, offset _Z3strB5cxx11 call basic_string::length() ; // sorry I'm too lazzy to type the correct function name mov cs:strLength, eax ; block #2 mov eax, cs:strLength cmp eax, 3 jbe loc_4011C6 ; // below-or-equal, unsigned operation, so cs:strLength is of type size_t </code></pre> <p>First block stores result of basic_string::length() in the global variable. The second block is produced from "if" statement. So the source code looks like that:</p> <pre><code>size_t strLength; // global variable ... void someFunc() { ... strLength = str.length(); // block #1 if (strlength &lt;= 3) { // block #2 // statements at the address 0x4011C6 } // statements after jbe ... } </code></pre> <p>Optimization flags -O1, -O2, -O3 will remove the extra move operation.</p> <p>About your second question. First of all let's check the demangled name (I used <a href="https://demangler.com/" rel="nofollow noreferrer">https://demangler.com/</a>). It's equal to the 'str[abi:cxx11]'. The ABI is stands for the application binary interface. It is necessary to link 2 or more binary modules. I donโ€™t see the whole code, but by string object name I can guess you can't see it's value, cause it's external std::string. It's value should be analyzed in other module (other DLL or EXE file). So, it's not global variable only, but exported or imported value (in C++ with 'extern' keyword).</p>
24967
2020-05-10T09:41:40.143
<p>first of all I'm new to reverse engineering so here's a noob question hahaha, I'm trying to solve a crackme and I found this set of instructions: <a href="https://i.stack.imgur.com/ENhwN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ENhwN.png" alt="enter image description here"></a></p> <p>Why would it move the content of eax into cd:strLength and then do in the inverse way? It doesn't make much sense to me... I would appreciate any help. Thank you all for you time.</p> <p>Also, I can't find the value of offset _Z3strB5cxx11, is it because it's a relocation and its value won't be resolved until the dynamic linker resolves it during runtime or am I going crazy? Thanks for your time. </p>
Problem with set of instructions in dissasembly
|ida|assembly|
<p>You are already passing <code>1000</code> to a <code>decompileFunction</code> so according to the <a href="https://ghidra.re/ghidra_docs/api/ghidra/app/decompiler/DecompInterface.html#decompileFunction(ghidra.program.model.listing.Function,int,ghidra.util.task.TaskMonitor)" rel="nofollow noreferrer">documentation</a> an exception should be thrown if it takes more time than that. Though, the timeout is in seconds and you set it to pretty high value - probably assuming it's in <code>ms</code>. Change to <code>1</code> and check if it will be cancelled with an exception if the time has passed.</p> <p>Alternatively, you use the <code>monitor</code> object that you are passing also to the <code>decompileFunction</code> method. It contains <code>cancel()</code> function that can cancel the action it has been passed to. You can read more about this object <a href="https://ghidra.re/ghidra_docs/api/ghidra/util/task/TaskMonitor.html" rel="nofollow noreferrer">here</a>.</p>
24984
2020-05-11T16:00:57.933
<p>The way to decompile a function in Ghidra Python is:</p> <pre><code> decomp = DecompInterface() decomp.openProgram(currentProgram) decompile = decomp.decompileFunction(func, 1000, monitor) </code></pre> <p>However, in some cases, probably due to an error or corner case situations, the decompilation takes much more than expected. </p> <p>Any ideas on how is it possible to cancel a decompilation task, using any kind of timeout, in Ghidra Python? I know that it's possible in the GUI. <a href="https://i.stack.imgur.com/CRlxq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CRlxq.png" alt=""></a></p>
Ghidra Python - cancel decompilation task
|decompilation|python|ghidra|
<ol> <li><p>Private flag is indicator that the particular range of memory isn't shared with any other process</p></li> <li><p>Reserved section means that the region of virtual memory is reserved, but not commited yet. This means that the virtual memory region isn't mapped to the physical memory but any other memory allocation calls won't occupy that space until it's released. You may also notice that the debugger doesn't show any protection on the reserved memory regions, this is because the memory needs to be commited in order to be used. To commit the memory you may call the <code>VirtualAlloc</code> again, this time with the MEM_COMMIT flag, now you can access the commited memory and then it will be allocated.</p></li> </ol>
24992
2020-05-12T16:41:17.013
<p>So in xdbg in the memory map, i can see that some segments are mapped and some are private, at first i thought maybe mapped means it has a corresponding file on disk and its the mapped version of that, but there are so many mapped segments which don't have a corresponding file, some of which are reserved</p> <p>so i have two questions:</p> <ol> <li><p>What is the difference between mapped and private segments?</p></li> <li><p>What are these (reserved) sections? what does reserved mean?</p> <p><a href="https://i.stack.imgur.com/W8ae9.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W8ae9.jpg" alt="enter image description here"></a></p></li> </ol>
What is the difference between mapped and private memory segments in xdbg? and what is a reserved segment?
|windows|debugging|memory|
<p>In this instance, <code>packageInfo.signatures</code> is the first signature that you find in the APK. Meaning, this is the first signature file that the Android system has read from the <code>META-INF/</code> folder inside the APK.</p> <p>Basically, what you'll need to do is unzip the APK, look inside the <code>META-INF/</code> and grab whatever file has the extension <code>.RSA</code> (unlikely, but it could be <code>.DSA</code>). This essentially what the <code>packageInfo.signatures[0]</code> is returning, with the <code>.toByteArray()</code> making a <code>ByteArray</code> object of the data.</p> <p>If you have any doubts, or are having issues further, I'd sugged using Frida to hook this function call and watch what is actually returned.</p>
24994
2020-05-12T21:00:33.863
<p>Are there anyways I can learn what packageInfo.signatures[0] is so I can use it to apply the same algorithm in Python.</p> <p>To further explain:</p> <pre><code> private static SecretKeySpec a(Context context) { try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 64); if (!(packageInfo == null || packageInfo.signatures == null || packageInfo.signatures.length &lt;= 0)) { return new SecretKeySpec(Arrays.copyOf(packageInfo.signatures[0].toByteArray(), 16), "AES"); } } catch (NameNotFoundException e2) { ThrowableExtension.a(e2); } return null; } </code></pre> <p>This android app is sending some sort of a key that is changing based on timestamp with every request it is sending. And it is using the above code for creating a SecretKeySpec which then gets used in below.</p> <pre><code> @NonNull private synchronized String d(String str) { byte[] digest; try { byte[] bytes = str.getBytes("UTF-8"); &gt;&gt;&gt;&gt;&gt;&gt;&gt; this.r.init(2, this.l); byte[] doFinal = this.r.doFinal(this.k); byte[] a2 = Bytes.a(doFinal, this.j, bytes, doFinal, this.n.a().getBytes("UTF-8")); digest = this.q.digest(a2); Arrays.fill(a2, 0); Arrays.fill(doFinal, 0); } catch (Exception e2) { throw new RuntimeException(e2); } return jl.a(digest); } </code></pre> <p>So, I know that the function argument <code>str</code> is for some reason <code>currentTimeMillis * 1151</code> which gets used in <code>byte[] a2 = ...</code> line then gets hashed with sha1 there comes the time based changing part. What I can't find is what signatures[0] is in this context and how can I achieve it, in the construction of the class, <code>this.l</code> is assigned with SecretKeySpec ( signature[0] ). <code>this.r</code> is an AES Cipher. From the readings I made, I think the "2" in <code>init(2, this.l)</code> means decode mode.</p> <p>And Can you please explain to me what is the effect of filling <code>a2</code> and <code>doFinal</code> variables with <code>0(zeroes)</code> in this context as it doesn't get used anywhere else.</p>
Android packageInfo signature
|android|encryption|apk|
<p>Any switches after the input filename are ignored. Just move the filename to the end.</p>
25000
2020-05-13T09:54:30.113
<p>I'm trying to generate IDB files from the command-line using the <code>-o</code> flag of IDA, something like this: <code>ida.exe -B input.dll -oC:\Results\input.idb</code>. However, it seems that the value of the <code>-o</code> arguments are completely ignored.</p> <p>I've tried this with <code>ida.exe</code>, <code>ida64.exe</code>, <code>idat.exe</code>, and <code>idat64.exe</code>. I've tried adding <code>-c</code> and also tried removing <code>-B</code> flags. None of these work.</p>
How to specify path of output database in IDA Pro?
|ida|command-line|
<p>You can use <a href="https://github.com/horsicq/pex64dbg" rel="nofollow noreferrer">pex64dbg</a> plugin, but that will only show you view of the main module. It looks like this:</p> <p><a href="https://i.stack.imgur.com/IEm6B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IEm6B.png" alt="PE Viewer"></a></p>
25008
2020-05-14T06:04:36.667
<p>In ollydbg you can view the PE header of a module, by going into memory map and double clicking on the PE headers, but i couldn't find a way to do this in XDBG, is it possible? </p>
Is it possible to view PE headers in xdbg just like ollydbg?
|debugging|ollydbg|
<p>Use the following from idapython:</p> <pre><code>import ida_dbg ida_dbg.edit_manual_regions() </code></pre>
25013
2020-05-14T18:16:25.300
<p>when I open the debug dump (IDA x64) , I don't have the memory ranges. Exactly like in this question: </p> <p><a href="https://reverseengineering.stackexchange.com/questions/16049/esp-out-of-range-of-stack-view-in-ida">ESP out of range of &quot;Stack View&quot; in IDA</a></p> <p>It used to be fine, but I don't have the menu edit-> "manual memory regions" as I am on IDA 7.4. (I guess) </p> <p>I tried to add a segment and it didn't work! </p> <p>windbg 10.0.18362.1 </p>
bad memory mapping in case of MEMORY dump IDA <-> WinDbg
|ida|windbg|memory-dump|
<p>Assuming nothing is cryptographically signed, that should be possible. You simply need to follow your steps in reverse. If you used <code>binwalk</code>'s extract option, that made it too easy; you'll want to figure out how to unpack/pack the image manually (maybe the verbose option will provide more info on the steps taken). I realize this is a generic sounding answer, but without knowing the exact firmware structure it is difficult to speculate.</p> <p>You'll also need to watch out for any checksums/hashes that will need to be modified if you change anything.</p> <p>However, you could brick the device if you try to flash improper firmware. It may be a good idea to see if it supports any firmware recovery modes, or if there are hardware debug ports on the board to assist in recovery.</p>
25015
2020-05-15T02:44:09.680
<p>I've been trying to figure out how to modify the firmware on a DVR I bought for cheap recently. The built in software isn't great and doesn't offer any option for exporting video other than plugging a USB drive in and running an export through their UI. Ideally I'd like to modify it to export over FTP or NFS or something on a schedule.</p> <p>You can upgrade the firmware on the device by putting the manufacturer provided upgrade image on a USB drive, plug it in, power on the device, then let it do it's thing to upgrade the firmware.</p> <p>So I downloaded the firmware and ran binwalk on it. It was able to extract the roofs and I can see that it's running a flavor of embedded Linux. Here is the output that came with the files I extracted:</p> <pre><code> Scan Time: 2020-05-15 02:16:35 Target File: /vagrant/rootfs-3531dv100 MD5 Checksum: 18a010179a1e5ae03c260ccc9609ddbc Signatures: 404 DECIMAL HEXADECIMAL DESCRIPTION -------------------------------------------------------------------------------- 0 0x0 uImage header, header size: 64 bytes, header CRC: 0xCB1642A1, created: 2019-09-26 01:53:07, image size: 9761796 bytes, Data Address: 0x0, Entry Point: 0x0, data CRC: 0x35F26A52, OS: Linux, CPU: ARM, image type: Filesystem Image, compression type: none, image name: "hirootfs" 64 0x40 JFFS2 filesystem, little endian </code></pre> <p>In the files on the rootfs I found the init scripts that get run. Funny enough there's a call in there to start telnetd that's commented out. There's also a password for the root user set in /etc/passwd.</p> <p>My question is this: if I modify the init script to uncomment that line so it runs telnetd at boot and generate a new password hash for the root user in /etc/password, how do I package it back up into a bootable image that I can drop onto a USB drive? Will that even work?</p>
Unpacking, modifying, repacking and flashing a firmware
|linux|flash|binwalk|
<p>After posting the question, I started to think about the difference in the libc I was using. I compiled the basic test binary again but with musl, and also saw the unexpected behavior there. This seems to be due to the <code>printf</code> implementation in <a href="https://github.com/bminor/musl/blob/master/src/stdio/vfprintf.c#L464" rel="nofollow noreferrer">musl</a>:</p> <pre><code> if (isdigit(s[1]) &amp;&amp; s[2]=='$') { l10n=1; argpos = s[1]-'0'; s+=3; } </code></pre> <p>It only uses direct parameters if there is exactly one digit following the <code>%</code>, followed by a <code>$</code>. This explains why I was unable to print any larger stack offsets.</p> <p><strong>Edit:</strong> This seems <a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html" rel="nofollow noreferrer">standard</a>-compliant:</p> <blockquote> <p>"%n$", where n is a decimal integer in the range [1,{NL_ARGMAX}], giving the position of the argument in the argument list.</p> </blockquote> <p>Then, looking at <a href="https://pubs.opengroup.org/onlinepubs/7908799/xsh/limits.h.html" rel="nofollow noreferrer">the definition</a> of NL_ARGMAX:</p> <blockquote> <p>NL_ARGMAX </p> <p>Maximum value of digit in calls to the printf() and scanf() functions. Minimum Acceptable Value: 9</p> </blockquote> <p>So it appears that the implementation is indeed following the standard by allowing the minimum value of 9, which is certainly inconvenient for writing compact format string exploits.</p>
25019
2020-05-15T13:03:07.210
<p>I am investigating a format string vulnerability on arm64 (linked against musl libc), and am encountering some odd behavior while debugging the output.</p> <p>From the decompilation, the program has a classic format string vulnerability that boils down to:</p> <pre><code>fprintf(stdout, user_controlled_data); </code></pre> <p>Using repetitive format specifiers (e.g. <code>%p%p%p%p</code>), I can dump massive swaths of memory by including thousands of these characters. That works as expected.</p> <p>The problem arises when I try direct parameter access. For some reason, <code>%1$p</code> works but not <code>%2$p</code>, but 3 up to about 12 works, and everything I've tried after that fails. By "fails", I mean no values are printed, except the newline automatically added to my string earlier in code is eaten somehow. In the debugger, <code>fprintf</code> returns -1, and <code>errno</code> is set to 0x16, which I believe is EINVAL.</p> <p>For this particular scenario, I need the ability to read/write a particular stack offset in the thousands. But I cannot print it to confirm since direct parameter access does not work. I <em>can</em> see the target parameter by using repeated characters, but I need direct parameters to work going forward due to other constraints.</p> <p>Now, I understand this is in "undefined behavior" territory, but I compiled a vulnerable test binary (statically linked against Glibc, I should probably try against musl) on the system that works as expected with no issues (e.g. <code>%9000$p</code> prints something).</p> <p>Is there something that would cause this behavior, or something I am missing? I can provide further information if needed.</p>
Format String Direct Parameter Behavior
|exploit|arm64|
<p>Select an address, then type "E".</p> <p>This will set the address as the end of the function that exists before it.</p>
25023
2020-05-15T15:29:43.650
<p>So in a malware sample (Shelter) IDA doesn't include some parts of the function in the function itself, and puts the endp in an earlier part, so for example the function really ends at 0x401080 but it thinks it ends at 0x401050 for some reason even tho the last instruction isn't ret and its just a SUB instruction, and the next instruction is a valid and instruction and I'm not sure why its not detecting it</p>
How to manually change the end of function and extend it in IDA pro?
|ida|
<p>Kevin,</p> <p><code>ls</code> comes in coreutils. The best way to experiment with these programs is to download and manually build the binaries (in this way you can give your favorite options like -g, -O3 during compilation).</p> <p>Anyways, coming back to your question, assuming you want to decompile /usr/bin/ls (that's what I get from your comments on Pawel's answer), then open ghidra gui, analyse the binary, click on file -> export program -> and export as a C/C++ file.</p>
25030
2020-05-16T06:44:59.727
<p>How to decompile the following assembly instructions ?</p> <p>Note: this could be reproduced using <em>/usr/bin/ls</em> <a href="https://gist.githubusercontent.com/promach/fa989fbd4ff74dcbed37aff0d39d1a9f/raw/3ca6889632b2f322fefa6060b6725b4832a98c73/ls" rel="nofollow noreferrer">binary</a> inside ghidra</p> <p><a href="https://i.stack.imgur.com/Q3UT6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q3UT6.png" alt="ghidra decompilation of ls"></a></p>
How to decompile /usr/bin/ls
|disassembly|decompilation|ghidra|decompile|decompiler|
<p>Your physical RAM size doesn't say too much about what your memory addresses will look like. What matters is your system <em>architecture</em> and <em>how many bits</em> there are (usually 64 or 32). Virtual memory also makes RAM insignificant; each process has <a href="https://en.wikipedia.org/wiki/Virtual_address_space" rel="nofollow noreferrer">virtual memory space</a> covering possibly the entire address space but mapped to a limited section of physical memory. Even on a 64-bit system where there are theoretically 2^64 bytes (an unrealistic 16 exibytes) of mappable addresses, you can still have a system with under 1GB of RAM and still have access to the virtual address space (which is much less than 2^64 in reality but still possibly larger than your physical RAM).</p> <p>What you are seeing in radare (0x004011d0) are addresses within the executable itself, and are still 64-bit but leading zeros are often omitted in various tools for convenience (actual address is 0x00000000004011d0). While they are mapped into the process's virtual memory table, those addresses are actually burned into the executable at compile time (unless it is compiled with PIE). Those addresses are usually around that general area and are typically the lowest section of virtual memory.</p> <p>If you want to see your 64-bit address space at work, look at pointers in registers and on the stack (or the stack addresses themselves), which will be much larger.</p>
25035
2020-05-16T13:57:36.853
<p>I'm totally new to reverse engineering, when I start debugging my c program with radare2, and start showing assembly, I found that addresses are only <code>8 hexa</code> digits, which means <code>16^8</code> = <code>4294967296</code> bytes, which is <code>4G RAM</code>. But I have <code>16G RAM</code>, which is <code>17179869184</code> bytes, which needs <code>9 digits</code> not 8</p> <p>This is part of the assembly as radare2 views:</p> <pre><code>0x004011d0 750e jne 0x4011e0 0x004011d2 488d3d410e00. lea rdi, str.Acess_granted ; 0x40201a ; "Acess granted!" ; const char *s </code></pre> <p>I think I misunderstand something here, can someone clarify? Thanks in advance.</p>
Why there are only 8 hexa memory digits while my RAM is 16G
|disassembly|assembly|radare2|memory|disassemblers|
<p>You can actually compile this with NASM depends on your preferred architecture, example command is below (I used linux):</p> <pre><code>nasm -f elf64 -o ./sample.asm ./sample.o ld -o ./sample ./sample.o global _start section .text _start: push rbp mov rbp, rsp mov DWORD [rbp-4], edi mov DWORD [rbp-8], esi mov edx, DWORD [rbp-4] mov eax, DWORD [rbp-8] add eax, edx pop rbp ret </code></pre> <p>After compiling and linking, I used IDA with pseudo-code support as what @macro_controller mentioned above.</p> <p><a href="https://i.stack.imgur.com/BSPFr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BSPFr.png" alt="enter image description here"></a></p> <p>Here is the result.</p> <p><a href="https://i.stack.imgur.com/vk1qz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vk1qz.png" alt="enter image description here"></a></p>
25039
2020-05-16T21:02:29.717
<p>I'm looking into a way to generate pseudo-code from snippet of assembly,</p> <p>let's assume I have this ASM</p> <pre><code> push rbp mov rbp, rsp mov DWORD PTR [rbp-4], edi mov DWORD PTR [rbp-8], esi mov edx, DWORD PTR [rbp-4] mov eax, DWORD PTR [rbp-8] add eax, edx pop rbp ret </code></pre> <p>is there is a way to turn it into pseudo-code using the available decompilers?</p> <p>if there is any exported API?</p>
asm snippet to pseudo-code
|ida|decompilation|radare2|ghidra|hexrays|
<p>So I finally solved my problem. Here a quick explanation on how I did it:</p> <p>The original problem was that I used "fixed" addresses for the <code>PUSH</code> meaning that it <em>pushes</em> always the same address (which should be the address of the ASCII). But ASLR randomizes the base address upon creating the EXE which means that the address becomes invalid as it points now to a totally different place than before. The workaround was to determine the address more "relatively" rather than absolute.</p> <p>The main idea was to somehow get the current address (<code>EIP</code>) and subtract a specific number from it so that now it points to the ASCII. This is possible by creating a function which is called. Every time a <code>CALL</code> is executed the address of the next instruction will be pushed on the stack. In this function the address is saved in <code>EAX</code> with <code>POP</code> and later pushed back so that the <code>RET</code> still knows where to return.</p> <p>I added a <code>CALL</code> after the string to retrieve the address and subtracted <code>10h</code> from it. Now I had the address of the ASCII in <code>EAX</code> then follows the same code as before where <code>WinExec</code> is called only with the difference that now <code>EAX</code> is pushed onto the stack rather than the "absolute" address. Before calling <code>WinExec</code> I saved the address of <code>WinExec</code> in <code>EAX</code> (because the address for WinExec stays the same even with ASLR and the problem with ASLR is that the Address is going to modified and thus it won't corresponding to <code>WinExec</code> anymore). Then I just made a <code>CALL EAX</code> to run <code>WinExec</code> and the rest is the same.</p> <p>Here is the full code:</p> <pre><code>Entrypoint: JMP &lt;address of the first CALL in injected code&gt; POP EAX (Puts address of next instruction into EAX) PUSH EAX (Copies address back to the stack so that RET knows where to go) RET ASCII "inject.exe" CALL &lt;address of the routine above&gt; (puts address of next instruction into EAX) SUB EAX,0x10 (SUB EAX,&lt;this number depends on the size of the executable name. Just subtract the address of this instruction with the address of the ASCII&gt;) PUSH 1 PUSH EAX PUSH WinExec (Puts address of WinExec onto stack so that the address won't change because of ASLR) POP EAX CALL EAX (execute WinExec) CALL __security_init_cookie (replace this instruction with the instruction that will be overwritten by the JMP instruction to this code cave. In my case it's this call) JMP &lt;address of second Instruction at Entrypoint&gt; </code></pre>
25054
2020-05-18T06:46:05.910
<p>I'm kind of new to this sort of thing so I hope someone can help me. I'm currently trying to understand how most malwares infect other files/modify an exe. Using Visual Studio 2017 I made an exe (with c++) that only does 2 things: print "Injection didn't work!" and after that runs "pause>NUL". I compiled it in x86 Release mode. Then I made a second exe which only prints "Injection worked". My main goal was to inject code into the first/target exe so that it runs the second exe first and then itself. So the final output after the injection should look something like this: "Injection worked. Injection didn't work!". My idea was to use OllyDBG. I opened the target exe and I added the following code into the code cave at the end of the code: </p> <pre><code>ASCII "inject.exe" PUSH 1 PUSH 008B1F7C (Address of ASCII "inject.exe") Call WinExec Call __security_init_cookie (This is the assembly code at the entrypoint which I overwrote with a JMP instruction to this codecave) JMP 008B1572 (JMP back to next instruction after entrypoint) </code></pre> <p>And the entrypoint looks like this:</p> <pre><code>JMP 008B1F87 (JMP to codecave) </code></pre> <p>This code should execute inject.exe which is the second exe I made (and this exe is located in the same folder as the target exe). When I run this in OllyDBG it works and it gives me the desired output but as soon as I save it to an exe (Copy to exectuable -> All modifications -> Copy All -> Save as InjectionTestPatched.exe) it won't run anymore and crashes before printing anything. I also checked the %errorlevel% after execution which was -1073741819 and not 0. I don't really understand why the code worked in OllyDBG but not when I save it as an exe.</p> <p>Does someone know what is going on here? (Please excuse my bad English as I'm not a native english speaker)</p> <p>EDIT: I think I figured out WHY it is behaving like this but I don't know how to fix it. When I debug the Patched EXE every address seems to be correct but the address to the ASCII isn't. all JMP/CALL addresses adjust accordingly to the offset but the address to the ASCII remains static (the PUSH 008B1F7C doesnt change). Could ASLR be the source of my problems? And if yes, how can I bypass this...</p> <p><a href="https://i.stack.imgur.com/tduYV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tduYV.jpg" alt="OllyDBG"></a></p> <p>Here the address in red should point to the ASCII but it is the same as it was before (the addresses changed after the exe was made). What I don't understand is that the JMP address changed to the right address but the PUSH not. Why does that happen, how can I fix this? (EDIT2: Problem solved)</p> <p>EDIT2: So I figured out a way to push the ASCII address on the stack correctly everytime by loading the EIP into EAX and sub it. This seems to work beacause the ASCII address is always on the stack when I reload the code. But now I have the next problem which is that WinExec doesnt seem to work anymore after reloading. OllyDBG doesn't even recoginze this instruction anymore as it shows it as 4 individual DB lines and not as CALL WinExec. How could I solve this?</p> <p>EDIT3: PROBLEM SOLVED! the Call for WinExec seemed to have been changed due to ASLR even tho the address is always the same. I solved it by loading the static address to EAX and then with a CALL EAX i can call a static address which is not affected by ASLR. My Injection worked now.</p>
OllyDBG saved executable crashes
|ollydbg|patching|
<p>In the SleighDevTools folder, there is a <code>pcodetest</code> folder, with a README.txt (which is unfortunately very brief).</p> <p>The documentation on SLEIGH can be found in <code>&lt;ghidra install dir&gt;/docs/languages/index.html</code>, which explains what goes in the .slaspec file for your new processor.</p> <p>Some documentation on what goes in the other files like .cspec, .ldefs, .., can be found in <code>&lt;ghidra install dir&gt;/Ghidra/Framework/SoftwareModeling/data/languages</code>.</p> <p>There is also an Eclipse plugin, GhidraSleighEditor, that is currently (Ghidra 9.1.2) separate from the GhidraDev eclipse plugin and must be manually installed. It can be found at <code>&lt;ghidra install dir&gt;/Extensions/Eclipse/GhidraSleighEditor/</code>, and has some documentation in the <code>GhidraSleighEditor_README.html</code> in that folder.</p> <p>As for your question on good documentation besides the Ghidra docs:</p> <ol> <li><p><a href="https://www.cs.tufts.edu/%7Enr/pubs/specifying.pdf" rel="nofollow noreferrer">Here</a> is the original paper on SLED, which later in modified form became SLEIGH.</p> </li> <li><p>These <a href="https://guedou.github.io/talks/2019_BeeRump/slides.pdf" rel="nofollow noreferrer">slides</a> go through an example of adding a processor to Ghidra</p> </li> <li><p>There's also this <a href="https://www.reddit.com/r/ghidra/comments/bhhrt0/quick_guide_to_creating_a_processor_in_ghidra/" rel="nofollow noreferrer">high level guide</a> to adding a processor.</p> </li> <li><p>(thanks to mumbel for pointing this out) <a href="https://www.reddit.com/r/ghidra/comments/f5lk42/my_experience_writing_processor_modules/" rel="nofollow noreferrer">This reddit post</a> provides valuable details on adding a processor.</p> </li> <li><p>(thanks to Heiko) <a href="https://spinsel.dev/" rel="nofollow noreferrer">This blog</a> contains tutorials on how to put together SLEIGH, pcode, and related concepts.</p> </li> </ol>
25070
2020-05-20T02:35:50.300
<p>I am working on adding a processor to Ghidra (I have no idea what I'm doing, just working my way through based off the documentation).</p> <p>I've seen SleighDevTools mentioned in the 9.1 release as being "support of processor module development", which sounds like it would be helpful to me. However, I can't find any documentation on what it does or how to use it. All, I've found is the source code for it in the Ghidra repo (no readme), and a single mention of it on reddit.</p> <p>Is there documentation on SleighDevTools? If so, where is it? If not, are there any good resources for processor development besides the official Ghidra docs?</p> <p>Thank you!</p>
Is there documentation on the Ghidra 9.1 SleighDevTools?
|ghidra|
<p>reading your question several times and the discussion in the comments i did not understand what you're trying to get/obtain, so i will be answering to parts that i think that are relevant according to the problems you posed. maybe other and more experienced people here would help elaborate and improve:</p> <p>if you're trying to "reverse" an interpreted code, .net in this case, i think the best way to do so is using dnspy, as it gives you pretty much all that you need to understand the logic, patch and change things accordingly and deal with obfuscation and similar operations.</p> <p>now you said you're struggling with obfuscation, but obfuscation is just a way to mislead the user doing the reversing. meaning you can, sometimes with great effort, to understand what's going on behind the scenes, change variable names and function names accordingly, to make it more "logical" to you. using a decompiler can also help you see the bigger image, but it's mostly about filling the gaps, bit and bit. what i usually do in situations like that, i try to find the calling functions and trying to understand what they do, the logic behind them, what parameters they use and why, and i go with the simplest path, meaning: sometimes if function contains a lot misleading paths, but it's easier to infer the logic from the variables, you can understand what the function does, name the variables correctly, and then go over to understand the function and its implementation to avoid wasting time on dead paths(though you can check coverage to understand what parts of the code are usually used). sometimes it's just the other way around, going with the function, understanding a bit of it's logic, understanding the parameters, and then fixing the parameters and the function, but it's mostly goes down to experience with similar tasks and going with your gut, but understanding it can be wrong(hard part is knowing when to stop before going too deeply in the wrong path).</p> <p>in regards to encryption or coding, sometimes going dynamically debugging might help you a lot with understand how it translates and checks your input, or the mechanism behind the encryption. but usually it goes down to many basic encryption/coding algorithms or custom implementation of them, that can be spotted with some experience, and then it's easier. if you coded the application and it's not a malware(though you should have snapshots), then there's nothing wrong if you do "bad things", just to understand which functions the program is calling, how it handles information, common program paths, apis, obfuscation and finally dealing with the encryption scheme you're facing. sometimes you don't need to face the encryption if it's not done correctly, you can, at times, just avoid it.</p> <p>you said you wanted to crack the application, so i don't understand what you mean by that, i thought you meant like a crackme kind of task. if you really want to "crack" applications, you should know that there are lot of other defensive mechanisms such as checksums, different signatures, sometimes server verification and similar, but it all goes down to understand the logic behind what's happening. though i really don't think "cracking" is not a good path to walk at, i think that you should find better ways to use your skills for good, for instance malware analysis or hardening software/binaries by identifying weak implementations and similar.</p> <p>anyways, since you did not provide a problem but a general issue, my best answer is to go with your guts, fail, and then learn why you failed to try it again and again until you understand how it works. it will help you understand and develop "hunch". then it's easier to understand how to defeat obfuscation and encryption and similar mechanisms.</p> <p>bottom line is simple, ask yourself simple question, what does it do? is it obfuscated? is it encrypted? why is it encrypted? how does it encrypt? what does it encrypt? how does it check what is correct/wrong? does it matter if i input the correct information or can i bypass it somehow? but the easiest way is just understanding the goal, and going backwards, and thus tackling only what actually interferes with your progress, and not meaningless things that you solved, but could have avoided.</p> <p><a href="https://stackoverflow.com/a/24391998">this answer</a> would introduce some tools for debugging C# application</p> <p>hope i helped a bit and good luck</p>
25076
2020-05-20T22:47:10.137
<p>i'm trying to learn reverse engineering for penetration testing my codes and i believe i won't learn unless i can do some practical so I'm trying to crack an application that is written in C# and all i wanna do is to find the assembly location of the <code>if</code> statement that checks for a license file which i believe i can bypass the license, just jumping over the <code>if</code> statement but i can't figure out how to do with <strong>IDA Pro</strong> or <strong>X64dbg</strong>. i'm not sure if i can do that or not because C# is byte code but i think <strong>IDA Pro</strong> and <strong>X64dbg</strong> are only for opcode applications right? and beside, bypassing it through assembly may cause other crashes in the application. i tried <strong>dnSpy</strong> and <strong>ILSpy</strong> thanks to <code>morsisko</code> in the comments.</p> <p>i was able to decompile the application and access the codes and i even found the <code>if</code> statement in the decompiled codes with JetBrains dotpeek and Visual Studio but i can't compile it again because of the errors in the image below</p> <p><strong>verbose mode:</strong> this application first checks for license and then checks for a hardware lock and i believe i can bypass them by <code>jmp</code> and <code>nop</code> in assembly cause after decompiling the application i spotted where the application looks for license and hardware lock and i saw <a href="https://guidedhacking.com/" rel="nofollow noreferrer">guided hacking</a> did the same using x64dbg. the problem is i don't know the tools to do it for C# application and the codes are like hashed! <a href="https://i.stack.imgur.com/eTm36.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eTm36.jpg" alt="decompiled source screenshot" /></a> this is the reason i can't compile the code again</p>
Debug and crack .NET executable PE
|ida|assembly|debugging|x64dbg|c#|
<p>Youโ€™re in for a wild ride but it can be achieved if you persist and in any case you will learn a lot. </p> <p>I would probably start like this:</p> <ol> <li><p>Check what programs are run by <code>autoexec.bat</code></p></li> <li><p>Run them in DOSBox and observe the output. </p></li> <li><p>Step through the code in DOSBox debugger (you may need to make your own build to enable it) and try to identify accesses to the serial port and what it expects to receive</p></li> <li><p>Either try to provide necessary input via the ports or patch the code so it works with what there is. </p></li> </ol> <p>The problem is somewhat exacerbated by the presumed use of Basic. It means that most of the code executed would be the code of the interpreter and not the actual program. It might be worth figuring out how the interpreter works and trying to extract the original Basic code to understand the logic better. However thatโ€™s a whole another adventure in itself so might be left as a backup option if the other attempts fail. </p> <p>This question may offer some hints for dealing with DOS Basic binaries: <a href="https://reverseengineering.stackexchange.com/q/1503/60">Reverse engineer an old DOS QBasic executable</a></p>
25078
2020-05-21T08:40:28.140
<p><strong>Background</strong></p> <p>Since some time we've been in the possession of a greenhouse. It was build around 1990 and had an automated system for climate control. However most of the installation has been removed when that greenhouse was sold, so there no longer is equipment for moisture control, heating, ... This causes the existing automated climate control system to no longer work.</p> <p>Thing is though, since it's a greenhouse - it does get really hot in the summer. We use it for storing goods and vehicles, so a high temperature is not desired. We can manually open the roof, but the desire is there to have this automated.</p> <p>There is a computer with software that is connected to the installation via a D-sub DC-37 plug. However since a lot of the equipment is no longer installed, the software does not operate as it should because it gets no signal from these removed components, and it's algorithm clearly does not like that.</p> <p>What is still available in the greenhouse is indoor temperature measurement, outdoor temperature measurement, windspeed measurement and rain measurement. The engines to open and close the roof panels are still there and there is still a sunscreen that is operational.</p> <hr> <p><strong>Question</strong></p> <p>I would like to figure out in some way what signals / instructions the software sends over the DC-37 connector. This way, I can write my own program that opens the roof windows if the temperature is too high, and the wind speed is below the safety maximum speed.</p> <p>The software is rather old software (from 1992) designed to run on DOS. It might be a BASIC program, since the floppy disk containing it also has a file BRUN30.exe, which according to a quick google search is needed by DOS to run compiled Basic programs.</p> <p>None of the executables are (understandably) working on Windows 10. It also contains COM files.</p> <p>The actual program executable the contains the algorithm I believe is the 'BL270690.EXE' file. It might also be that the 'SETUPIO.EXE'contains the code to send data / instructions over the DC-37 port. <a href="https://i.stack.imgur.com/R2ig0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R2ig0.png" alt="list of files of the program"></a></p> <p>What would be the best approach for me to determine what instructions I need to send to Read the wind speed, open the roof windows, ...</p> <p>What possibilities are there to reverse engineer these old executables / COM files?</p> <p>Thanks in advance, finding a solution would mean a lot to me!</p>
How to determine commands sent over DC-37 port by software from 1992
|disassembly|serial-communication|dos|dos-com|
<p>It could be done with a script but for occasional use a text search will do the trick: </p> <ol> <li><kbd>Alt-T</kbd></li> <li>String: XREF</li> <li>[x] Search Up</li> </ol> <p>Because text search looks in whole disassembly, including comments, it should find the line with the text 'xref' in the comment.</p>
25086
2020-05-21T21:30:10.887
<p>I'm working on an executable. I've searched by string, and found my string appears once in something that looks like table of localized strings + keys. Now I want to find the function which accesses the table and retrieves a localized string. The problem is that the table is big. VERY big. I tried scrolling up until I find XRef, but either I scroll too fast or too slow and I'll never finish. Instead, I'd like for IDA to find the nearest XRef <strong>before</strong> an address. Is there any way to do that?</p> <p><strong>P.S.</strong> If you're think I'm doing this wrong, please let me know (I'm still a beginner in reverse engineering) - but answer my question too, nevertheless.</p>
Find Nearest Address Which Has XRef in IDA
|ida|
<p>I think your approach is generally correct. You probably can't connect to the Bluetooth because your additional code throws an exception somewhere. The best idea would be to check it during dynamic analysis. You can do it using for example Android Studio and <a href="https://github.com/JesusFreke/smalidea" rel="nofollow noreferrer">smalidea</a> plugin.</p> <p>As far as I see you don't store the result of your <code>ByteArrayToString</code> function call. You also pass only one parameter to the <code>android.util.Log.d</code> function (in your case <code>v5</code>) but it actually requires two parameters.</p> <p>You can hook and intercept functions in android applications using for example dynamic instrumentation. Good tool for this purpose is named <a href="https://frida.re/docs/home/" rel="nofollow noreferrer">frida</a>. Thanks to this tool you can hook various functions and change the behavior during runtime (for example add logging feature) without repacking the application. You don't need to mess with smali code, instead you can just use their easy JavaScript API. </p> <p>If you are interested in the Bluetooth data logging there is even better way. You can use bulit-in Android function called <code>Bluetooth HCI snoop log</code>. You can enable it in developer options on your phone. After you enable the option all the bluetooth communication made between those devices will be recorded and saved onto internal storage. You can later copy the <code>btsnoop_hci.log</code> and possibly all files with the <code>.cfa</code> extension to further examination. Those files can be loaded into for example popular program named <a href="https://www.wireshark.org/" rel="nofollow noreferrer">WireShark</a> and inspected similar to PCAP files.</p>
25088
2020-05-22T06:44:19.137
<p>I have separately decompiled apk to smali/dalvik and to java classes. As apk is not obfuscated java code is pretty good to read and I can pretty easily see corresponding smali code. So far I was able to do successfully:</p> <ul> <li>modify code for checking license file (change comparison for year)</li> <li>add logging to some basic data. Logger function was already in apk to I just call it and everything works fine. I use adb to read logs. </li> </ul> <p>What I was trying to add next was to add logging for byte array. Why? Because this apk connects to Bluetooth device from which it receives the data. I wanted to know what data it receives. As I didn't know how to do that this is what I did:</p> <p>I've made simple Android app with static function which gets byte array and returns string (copied some snipped). It was using BigInteger. Then I compiled it and decompiled using apktool.</p> <pre><code> .method public static ByteArrayToString([B)Ljava/lang/String; .locals 2 .param p0, "data" # [B .line 16 new-instance v0, Ljava/math/BigInteger; const/4 v1, 0x1 invoke-direct {v0, v1, p0}, Ljava/math/BigInteger;-&gt;&lt;init&gt;(I[B)V const/16 v1, 0x10 invoke-virtual {v0, v1}, Ljava/math/BigInteger;-&gt;toString(I)Ljava/lang/String; move-result-object v0 .line 17 .local v0, "hexaString":Ljava/lang/String; return-object v0 .end method </code></pre> <p>I copied that whole function to my decompiled apk (the same class from which I wanted to call it/log data) and called that function.</p> <pre><code> invoke-static {v0}, Lxx/xxxx/xxxxx/xx/xxxx/xxxxxx;-&gt;ByteArrayToString([B)Ljava/lang/String; const-string v5, ":: MY RAW DATA: " invoke-static {v5}, Landroid/util/Log;-&gt;d(Ljava/lang/String;Ljava/lang/String;)I move-result-object v4 invoke-static {v4}, Lorg/apache/log4j/helpers/LogLog;-&gt;debug(Ljava/lang/String;)V </code></pre> <p>Unfortunately it didn't work. Application compiled succesfully, it installed and lunched without a crash. However it didn't connect to my bluetooth device (bluetooth communication is essential). </p> <p>So here are some questions (edited):</p> <ul> <li>Is my approach correct?</li> <li>What may be the reason for application not to work with bluetooth anymore?</li> <li>Where should I put additional logic? Is the same class OK?</li> <li>What about importing? For example in my new logic I had to import java.math.BigInteger; Will my function has this import somehow embedded in its logic?</li> <li>Is there any better approach than mine?</li> </ul> <p><strong>EDIT:</strong></p> <p>I've solved my initial problem, now I'm trying to figure out the rest. Answers are:</p> <ul> <li><p>Yes, my approach is correct and it works. I just used wrong log function (as it was mentioned in comment below).</p></li> <li><p>Probably using this function (instead of adding new method) is sufficient:</p></li> </ul> <pre><code>invoke-static {v0}, Ljava/util/Arrays;-&gt;toString([B)Ljava/lang/String; </code></pre> <ul> <li>Strangely my problems with discovering Bluetooth devices has been solved by enabling GPS. Not 100% sure, but looks that way. I also saw this in logs:</li> </ul> <pre><code>BluetoothUtils: packagename is xx.xxxxx.xxxx ,and its permission is false </code></pre>
Modifying (adding new logic) decompiled apk to log different kind of data causing problems (crash/bluetooth connection)
|android|apk|dalvik|
<p>Generally you are doing almost all correct, there are however two simple mistakes.</p> <p>First and probably most important is here </p> <pre><code>DWORD_PTR pebOffset = (DWORD_PTR)pbi.PebBaseAddress + 10; </code></pre> <p>The offset to <code>ImageBaseAddress</code> is not <code>10</code>, it's <code>0x10</code> (16 in DEC). So you need to do it like this</p> <pre><code>DWORD_PTR pebOffset = (DWORD_PTR)pbi.PebBaseAddress + 0x10; </code></pre> <p>Secondly, are you sure that sizeof <code>LPVOID</code> is 16? At least on my compiler it is 8, not 16, so you are mostly like overwriting data on the stack. That's why I propose this approach</p> <pre><code>ReadProcessMemory(pi.hProcess, (LPCVOID)pebOffset, &amp;imageBase, sizeof(LPVOID), NULL); </code></pre> <p>instead of</p> <pre><code>ReadProcessMemory(pi.hProcess, (LPCVOID)pebOffset, &amp;imageBase, 16, NULL); </code></pre>
25097
2020-05-23T08:05:27.403
<p>Okay, so in the following code-snippet I am starting a <code>notepad.exe</code> process in a suspended state and trying to get the AddressOfEntryPoint of the process. Problem is I can't seem to find the actual <code>codeEntry</code>.</p> <p>Both the application and the <code>notepad.exe</code> process is 64-bit.</p> <p>What am I doing wrong?</p> <p>Here is the commented code-snippet:</p> <pre><code>#include &lt;iostream&gt; #include &lt;windows.h&gt; #include &lt;winternl.h&gt; #pragma comment(lib, "ntdll") using namespace std; int main() { STARTUPINFOA si; si = {}; PROCESS_INFORMATION pi = {}; PROCESS_BASIC_INFORMATION pbi = {}; DWORD returnLength = 0; CreateProcessA(0, (LPSTR)"c:\\windows\\system32\\notepad.exe", 0, 0, 0, CREATE_SUSPENDED, 0, 0, &amp;si, &amp;pi); // get target image PEB address and pointer to image base NtQueryInformationProcess(pi.hProcess, ProcessBasicInformation, &amp;pbi, sizeof(PROCESS_BASIC_INFORMATION), &amp;returnLength); DWORD_PTR pebOffset = (DWORD_PTR)pbi.PebBaseAddress + 10; // get target process image base address LPVOID imageBase = 0; ReadProcessMemory(pi.hProcess, (LPCVOID)pebOffset, &amp;imageBase, 16, NULL); // read target process image headers BYTE headersBuffer[4096] = {}; ReadProcessMemory(pi.hProcess, (LPCVOID)imageBase, headersBuffer, 4096, NULL); // get AddressOfEntryPoint PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)headersBuffer; PIMAGE_NT_HEADERS64 ntHeader = (PIMAGE_NT_HEADERS64)((DWORD_PTR)headersBuffer + dosHeader-&gt;e_lfanew); LPVOID codeEntry = (LPVOID)(ntHeader-&gt;OptionalHeader.AddressOfEntryPoint + (DWORD_PTR)imageBase); // Do something with the AddressOfEntryPoint(print to console in this case) cout &lt;&lt; codeEntry &lt;&lt; endl; return 0; } </code></pre>
Finding AddressOfEntryPoint for a 64-bit process
|c++|winapi|
<p>The function prologue (<code>push ebp</code>, etc.) is common in assembly, but not required. <code>ebp</code> is often used for local varible access, but can as well be used as a general purpose register, just like <code>eax</code>.</p> <p>Assembly allows the code to manipulate stack pointer at any place and doesn't force it to follow any convention - as long as there are no exceptions, CPU will not care; it will simply execute the instructions pointed by <code>eip</code> register. It will not stop you from accessing (even modifying) other function's memory as long as your program has enough privileges to do that. I think this answers your first two questions.</p> <p>Regarding your third question, in general, it is not possible. However, usually, you can look for the instructions modifying <code>esp</code> (like <code>push</code>, <code>pop</code>, etc.) and infer it from them. If you showed us the entire function, it would be easier to tell the size in this particular case.</p> <p>In fact, the instructions you have shared with us don't seem to access local variables of this function or of any other either. I don't know what are the values stored in <code>edi</code> and <code>ebp</code> registers, but I guess they point to some dynamically allocated data on heap.</p>
25100
2020-05-23T15:16:14.290
<p>I am trying to reverse engineer software to extend its functionality as expected of me. So I don't have the source code with me. Anyways, I am used to seeing codes that start like the one below, and is clear to me what is actually going on there. </p> <pre><code>push ebp mov ebp,esp sub esp,10h </code></pre> <p>But my worries came when I saw one that looks like this below</p> <pre><code>mov edi,dword ptr [0E9A474h]; imul eax,dword ptr [edi+5AF4h],70h; cmp dword ptr [ebp+eax-35DCh],0h; je some_location </code></pre> <p>And the prologue for the function doesn't have any instruction like this</p> <pre><code>sub esp,10h </code></pre> <p>At least I could have known the size of the stack the function is using for local variable storage.</p> <p>And additional question is:</p> <ol> <li>Is this a good programming as far as assembly language is a concern?</li> <li>Can there be any collision in memory between this function and another?</li> <li>Is it possible to know the limit of this function in the stack? Either the Size</li> </ol>
How's this code able to make use of the stack?
|assembly|x64dbg|
<p>using windbg you can set an sxe ld:Modname event break</p> <p>assuming you are running this which will pop up a help gui for printers </p> <pre><code>rundll32.exe printui.dll PrintUIEntry /? </code></pre> <p>if you want to Break on this printUI.dll's CrtMain or AddressOfEntryPoint you can do it like this </p> <pre><code>C:\WINDOWS\system32&gt;cdb rundll32.exe printui.dll PrintUIEntry /? Microsoft (R) Windows Debugger Version 10.0.17763.132 AMD64 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ntdll!LdrpDoDebuggerBreak+0x30: 00007ffc`b725121c cc int 3 0:000&gt; sxe ld:printui.dll 0:000&gt; .sxcmds sxe ld:printui.dll ; 0:000&gt; g ModLoad: 00007ffc`a04e0000 00007ffc`a058d000 C:\WINDOWS\system32\printui.dll ntdll!NtMapViewOfSection+0x14: 00007ffc`b721c5c4 c3 ret 0:000&gt; .lastevent Last event: 1d84.293c: Load module C:\WINDOWS\system32\printui.dll at 00007ffc`a04e0000 debugger time: Mon May 25 23:55:59.235 2020 0:000&gt; .shell -ci "!dh 00007ffc`a04e0000" findstr /I Entry 3CA0 address of entry point .shell: Process exited 0:000&gt; bp 00007ffc`a04e0000+3ca0 0:000&gt; bl 0 e 00007ffc`a04e3ca0 0001 (0001) 0:**** printui!DllMainCRTStartup 0:000&gt; g ModLoad: 00007ffc`b5950000 00007ffc`b59f3000 C:\WINDOWS\System32\ADVAPI32.dll xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Breakpoint 0 hit printui!DllMainCRTStartup: 00007ffc`a04e3ca0 48895c2408 mov qwordptr[rsp+8],rbx ss:0000009a`5918edd0=0000000000000000 </code></pre> <p>and you can see the call stack to find all the responsible calls that leads to this break</p> <pre><code>0:000&gt; k Child-SP RetAddr Call Site 0000009a`5918edc8 00007ffc`b71a50a1 printui!DllMainCRTStartup 0000009a`5918edd0 00007ffc`b71e9405 ntdll!LdrpCallInitRoutine+0x65 0000009a`5918ee40 00007ffc`b71e91f8 ntdll!LdrpInitializeNode+0x1b1 0000009a`5918ef80 00007ffc`b71aaa97 ntdll!LdrpInitializeGraphRecurse+0x80 0000009a`5918efc0 00007ffc`b71a2591 ntdll!LdrpPrepareModuleForExecution+0xbf 0000009a`5918f000 00007ffc`b71a22a8 ntdll!LdrpLoadDllInternal+0x199 0000009a`5918f080 00007ffc`b71a1764 ntdll!LdrpLoadDll+0xa8 0000009a`5918f230 00007ffc`b43e56f0 ntdll!LdrLoadDll+0xe4 0000009a`5918f320 00007ff7`ff62356e KERNELBASE!LoadLibraryExW+0x170 0000009a`5918f390 00007ff7`ff623aff rundll32!_InitCommandInfo+0x82 0000009a`5918f7e0 00007ff7`ff6262d9 rundll32!wWinMain+0x1ef 0000009a`5918fa50 00007ffc`b6287bd4 rundll32!__wmainCRTStartup+0x1c9 0000009a`5918fb10 00007ffc`b71eced1 KERNEL32!BaseThreadInitThunk+0x14 0000009a`5918fb40 00000000`00000000 ntdll!RtlUserThreadStart+0x21 </code></pre>
25111
2020-05-25T11:07:49.993
<p>I'm trying to debug a dll file using Ida disassembler and Windbg. I'm debugging rundll32.exe and passing the target dll (debugee) as an argument. I'm able to have a breakpoint on each Dll load &amp; unload, but I'm looking for a way to debug the target dll Main function. I want to put a breakpoint on the dispatcher of the dll main function in the loader (ntdll.dll) in order to do this. What is the routine responsible for dll main dispatching? My environment is windows 10 version 1809.</p>
what routine in ntdll.dll is responsible of dispatching DllMain function of loaded dll?
|ida|windows|dll|
<p>There can be multiple reasons.</p> <ol> <li><p>the FLIRT signatures which have been loaded automatically do not have a pattern for this specific function. You can check which signatures have been applied and try loading additional ones via Signatures view (<kbd>Shift-F5</kbd>).</p></li> <li><p>the function pattern was conflicting with another function(s) and has been dropped from the final signature file. If you have the original library with the function, you can try creating your own signature.</p></li> <li><p>The function has been modified from the standard one so the matching failed</p></li> </ol> <p>You can try enabling FLIRT diagnostic output by stating IDA with <code>-z4</code> <a href="https://www.hex-rays.com/products/ida/support/idadoc/417.shtml" rel="nofollow noreferrer">command line switch</a> and observe if the address in question is mentioned in the log. Maybe that will give some clues about why it hasn't been matched. </p>
25113
2020-05-25T12:01:55.707
<p>I'm trying to find <code>libc</code> symbols in some Windows 32-bit application. For some reason, Ida autoanalysis didn't recognized code that comes from <code>libc</code> as "library function", but as a "regular function". Let me make it more clear with some screenshots.</p> <p>My tutor got the following result (sorry for the low quality, I describe whats in it after the shot): <a href="https://i.stack.imgur.com/jobXw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jobXw.png" alt="enter image description here"></a> This is the same image and you (maybe) can see that the <code>malloc</code> function at <code>0xE0E5DE</code> is recognized as library function. The whole neighborhood is recognized as library function, since this section is for static-linked <code>libc</code> symbols.</p> <p>But when I'm loading the image its a "regular function", and of course it doesn't resolve as <code>malloc()</code>: <a href="https://i.stack.imgur.com/R1iiJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R1iiJ.png" alt="enter image description here"></a></p> <p>I tried to re-autoanalyze the code (<code>Options --&gt; General --&gt; Reanalyze Program</code>) but it didn't help. Hence I'm asking for help:</p> <ol> <li>Is there another automatic way to make IDA "notice" this code comes from static linking of a library?</li> <li>Maybe there is a manual way to do it? like: marking a code chunk as library function and compare it against <code>libc</code>?</li> </ol> <p><strong>P.S: the app was once packed with UPX, I decompress it. I don't believe it has anything to do with this problem, but maybe it has so I'm mentioning it</strong></p>
ida identifies library function as regular function
|ida|static-analysis|symbols|libraries|
<p>In my case it was a flaky connection. I was originally just using jumper wires to make contact into the through holes on the board and hook it up to the bus pirate. I soldered header pins to it and now I can see the output totally clearly.</p>
25120
2020-05-26T07:12:24.887
<p>I've been probing this CCTV DVR board trying to find a serial port to see if I can get console access to it. I found a set of 4 through holes with no headers that looked like a good candidate. I hooked up to my Bus Pirate in UART mode at a baud rate of 115200 and it seemed promising at first:</p> <pre><code>System startup U-Boot 2010.06 (Dec 27 2018 - 17:06:41) Check Flash Memory Controller v100 ... Found SPI Nor(cs 0) ID: 0xc2 0x20 0x18 Block:64KB Chip:16MB Name:"MX25L128XX" SPI Nor total size: 16MB *** Warning - bad CRC, using default environment In: serial Out: serial Err: serial </code></pre> <p>Then things get weird. The next line has legible text but some garbage in it, then after that nothing but garbage:</p> <pre><code>๏ฟฝP๏ฟฝ๏ฟฝ๏ฟฝStarting the controller +*/๏ฟฝ)))!) ๏ฟฝ!๏ฟฝ+!%) ! ๏ฟฝ)*+๏ฟฝ๏ฟฝ %+๏ฟฝ๏ฟฝ๏ฟฝ5๏ฟฝ! -๏ฟฝ๏ฟฝ5๏ฟฝ! !๏ฟฝ! +-๏ฟฝ๏ฟฝ๏ฟฝ !๏ฟฝ๏ฟฝ๏ฟฝ ๏ฟฝ% %!- ๏ฟฝ)๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ+๏ฟฝ๏ฟฝ+ ! %!!5!!๏ฟฝ)!+! +) %%๏ฟฝ+ %!5 ) ๏ฟฝ๏ฟฝ)5 !5)!) % ๏ฟฝ)!% - %) ) 5)๏ฟฝ-๏ฟฝ ! )๏ฟฝ๏ฟฝ!๏ฟฝ ! - )! %- !%! ! ! !๏ฟฝ๏ฟฝ %)!๏ฟฝ% %%)! !๏ฟฝ ๏ฟฝ %!๏ฟฝ)) !)!)!)!%- ๏ฟฝ-))! ๏ฟฝ๏ฟฝ ๏ฟฝ๏ฟฝ)))!! ๏ฟฝ๏ฟฝ% ๏ฟฝ%!)๏ฟฝ!)%)๏ฟฝ))% ๏ฟฝ) %-%+๏ฟฝ ๏ฟฝ) !๏ฟฝ5๏ฟฝ ! ๏ฟฝ ! -!! )%! ๏ฟฝ๏ฟฝ)๏ฟฝ)%๏ฟฝ)๏ฟฝ๏ฟฝ๏ฟฝ) </code></pre> <p>Is this because the baud rate is suddenly changing? Or is it more likely that the output is switching to some proprietary format?</p> <p>I also didn't have a super solid connection to the board when trying this, could it be that the connection dropped and then reconnected out of sync or something?</p>
Can a UART port change baud rate at runtime?
|hardware|serial-communication|
<p>The function you (or IDA) labeled <code>start</code> is commonly called <code>__x86.get_pc_thunk.bx</code> and is used by GCC and other compilers to calculate the current execution address for <em>Position independent code</em> (PIC). Usually the <code>add</code> instruction after the call results in <code>ebx</code> gettng the value of the GOT (Global offset table) so that external calls can be done without extra setup (the PLT stubs for external calls in PIC executables assume that <code>ebx</code> points to the GOT), but also global data can be addressed using a fixed offset relative to the GOT. This way the code can run regardless of the actual address at which it has been loaded by the OS (i.e. it is position independent).</p>
25136
2020-05-28T09:25:52.890
<p>While reversing some <code>x86</code> executables, I came across a pattern of addressing globals, that I don't familiar with, but it looks like IDA is, and I would like to know more about it.</p> <pre><code>.text:00002560 public start .text:00002560 start proc near .text:00002560 mov ebx, [esp+0] .text:00002563 ret .text:0001D233 push ebx .text:0001D234 call start ; ebx is initialized here .text:0001D239 add ebx, 1805Bh .text:0001D25A lea edi, (aLsi_0 - 35294h)[ebx] ; "lsi" &lt;---- Ida recognizes here an access to global string. </code></pre> <p>I saw this pattern in many different binaries. Does anyone know what is the name of this kind of access and where can I read more about it?</p>
X86 access to global strings pattern
|ida|disassembly|x86|
<p>After compilation, a pointer to a C struct will be pointing to its first element. In your example, <code>[ebp + 8]</code> is a pointer to <code>member1</code> and you can access a pointer to <code>member2</code> like this: </p> <pre><code>mov eax, [ebp + 8] ; eax contains pointer to struct and its first member mov eax, [eax + 4] ; eax contains a pointer to member2 </code></pre> <p>When in any doubt, you can always write a simple program, compile it and check the resulting assembler code. In your case, you could write something like this:</p> <pre><code>#include &lt;stdio.h&gt; struct example { int member1; void* member2; }; void initialiseStruct(struct example* e) { e-&gt;member1 = 1; e-&gt;member2 = NULL; } int main() { struct example e; initialiseStruct(&amp;e); return 0; } </code></pre> <p>And then compile it and run <code>objdump -dM intel FILENAME</code> to get a snippet like the following one:</p> <pre><code>0000054d &lt;initialiseStruct&gt;: 54d: 55 push ebp 54e: 89 e5 mov ebp,esp 550: e8 6b 00 00 00 call 5c0 &lt;__x86.get_pc_thunk.ax&gt; 555: 05 83 1a 00 00 add eax,0x1a83 55a: 8b 45 08 mov eax,DWORD PTR [ebp+0x8] 55d: c7 00 01 00 00 00 mov DWORD PTR [eax],0x1 ; e-&gt;member1 = 1 563: 8b 45 08 mov eax,DWORD PTR [ebp+0x8] 566: c7 40 04 00 00 00 00 mov DWORD PTR [eax+0x4],0x0 ; e-&gt;member2 = NULL 56d: 90 nop 56e: 5d pop ebp 56f: c3 ret </code></pre> <p>Regarding your second question: you should view <code>[]</code> in assembly like <code>*</code> in C in case of <code>mov</code>. </p> <p>If <code>member2</code> points to <code>int</code>, you can access this integer this way (I've added C equivalents next to each assembly instruction):</p> <pre><code>mov eax, [ebp + 8] ; eax = e - remember, in my example e is a pointer mov eax, [eax + 4] ; eax = *(e + 4) = e-&gt;member2, so now eax contains the memory address at e-&gt;member2 mov ecx, [eax] ; ecx = *(e-&gt;member2) - ecx contains the integer value </code></pre>
25147
2020-05-29T10:05:49.583
<p>I am reading a book on reversing and I am curious about one of the assembly snippet i have read in it.</p> <p>There is a simple disassembly of the function RtlNumberGenericTableElements and it looks like this:</p> <pre><code>push ebp mov ebp, esp mov eax, dword ptr [ebp+8] mov eax, dword ptr [eax+14] pop ebp ret 4 </code></pre> <p>And it occured to me, say there is a member of a structure that is a pointer to some other structure. How would I go about dereferencing that member?</p> <pre><code>struct example { int member1; *object member2; }; </code></pre> <p>Would I be dereferencing member 2 like so (pointer to struct comes as first param):</p> <pre><code>mov eax, [ebp+8] mov eax, dword ptr [eax] mov eax, [eax+8] ; this would get me the pointer to member2??? </code></pre> <p>any input appreciated</p> <p>EDIT:</p> <p>I see, your explanation was understandable, thank you, I appreciate it.</p> <p>I have one more question that popped up from my mind. Say in your example, member 2 is a pointer to an int, then </p> <pre><code>mov eax, [ebp + 8] ; eax contains pointer to struct and its first member mov eax, [eax + 4] ; eax contains a pointer to member2 (this is a pointer to an int) </code></pre> <p>Say i would like to get the value of member to into ecx i would carry on like this:</p> <pre><code>mov eax, [eax] mov ecx, [eax] </code></pre> <p>So the whole thing would read like so:</p> <pre><code>mov eax, [ebp + 8] ; eax contains pointer to struct and its first member mov eax, [eax + 4] ; eax contains a pointer to member2 (this is a pointer to an int) mov eax, [eax] ; dereferenfce the pointer that is pointing to member2 mov ecx, [eax] ; dereference member2 itself that is a pointer to an int </code></pre> <p>Is this correct?</p>
dereferencing structure members
|disassembly|assembly|
<p>Looks like no function has been created at that address for whatever reason. Try jumping to it manually(<kbd>G</kbd> shortcut) and create code/function there. </p>
25161
2020-05-30T03:00:01.537
<p>I found an address of a function from the game AssaultCube, and the address is <code>0045BCA0</code>. In IDA, I disassembled ac_client.exe as a portable executable and tried to search for that address in the subview window with no results. This address is definitely in the actual game. How would I make IDA include more subview addresses so I can find that function address?</p> <p><strong>Can't Find Address</strong></p> <p><a href="https://i.stack.imgur.com/nQ9xk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nQ9xk.png" alt="Missing Addresses"></a></p>
IDA No Search Results in Subview For Viable Address
|ida|
<h2>Binary</h2> <p>MIDI data bytes are 7 bits, meaning they can have decimal values from 0 to 127.</p> <p>In a 7-bit binary number:</p> <ul> <li>the bit on the right represents a decimal value of 1.</li> <li>the next bit to the left represents a decimal value of 2.</li> <li>the next bits to the left represent decimal values of 4, 8, 16, 32, and 64.</li> </ul> <p>Decimal values from 0 to 127 can be expressed in seven bits, where each bit is a 0 or 1.</p> <pre><code>binary decimal 0000001 1 = 1 0000010 2 = 2 0000011 3 = 2 + 1 0000100 4 = 4 0000101 5 = 4 + 1 0000110 6 = 4 + 2 0000111 7 = 4 + 2 + 1 0001000 8 = 8 0001001 9 = 8 + 1 ... 1111111 127 = 64 + 32 + 16 + 8 + 4 + 2 + 1 </code></pre> <h2>Pattern</h2> <p>From the results you described, I suspect the turntable only cares about the lowest 4 bits in each byte. In other words, only the bits with decimal values of 1, 2, 4, and 8 will have an effect on the tempo display. This means only byte values 0 to 15 are useful.</p> <p>I suspect the turntable is using the following pattern:</p> <pre><code>B1 B2 B3 B4 tempo display 0 0 0 0 .00 .0 0 0 0 1 .01 " 0 0 0 2 .02 " 0 0 0 3 .03 " 0 0 0 4 .04 " 0 0 0 5 .05 " 0 0 0 6 .06 " 0 0 0 7 .07 " 0 0 0 8 .08 " 0 0 0 9 .09 " 0 0 0 10 .10 .1 0 0 0 11 .11 " 0 0 0 12 .12 " 0 0 0 13 .13 " 0 0 0 14 .14 " 0 0 0 15 .15 " 0 0 1 0 .16 " 0 0 1 1 .17 " 0 0 1 2 .18 " 0 0 1 3 .19 " 0 0 1 4 .20 .2 ... </code></pre> <p>The byte values represent tempo values in .01 units, but when the turntable displays the tempo, it hides the last digit.</p> <p>This hidden digit explains why turning on multiple bytes doesn't always produce the sum of the tempos displayed by the individual byte values.</p> <pre><code>B1 B2 B3 B4 tempo display 1 0 0 0 40.96 40.9 0 0 1 0 .16 .1 1 0 1 0 41.12 41.1 </code></pre> <h2>Bitwise math</h2> <p>When only some bits are used, bitwise math is indeed useful.</p> <p>For example, here's some Javascript to convert a tempo to the needed byte values:</p> <pre><code>t = 123.4; v = 100 * t; b1 = (v &gt;&gt; 12) &amp; 15; b2 = (v &gt;&gt; 8) &amp; 15; b3 = (v &gt;&gt; 4) &amp; 15; b4 = v &amp; 15; console.log(b1, b2, b3, b4); </code></pre> <p><code>x &amp; 15</code> is a <strong>bitwise AND</strong>, in this case, to keep only the lowest four bits.</p> <p><code>x &gt;&gt; 4</code> is a <strong>right shift</strong>, in this case shifting the value 4 bits to the right, which discards the lowest four bits. This has the same effect as dividing by 16 and discarding the remainder.</p> <p>Here's some Javascript to convert the byte values to the displayed tempo:</p> <pre><code>b1 = 3; b2 = 0; b3 = 3; b4 = 4; b1 = b1 &amp; 15; b2 = b2 &amp; 15; b3 = b3 &amp; 15; b4 = b4 &amp; 15; v = 16*16*16*b1 + 16*16*b2 + 16*b3 + b4; t = parseInt(v / 10) / 10; console.log(t); </code></pre> <p>In your web browser, you can go to about:blank, then press F12 and go to Console to enter these small Javascript calculations. (For your safety, enter about:blank in the address box, and never run code from strangers if you don't understand it.)</p>
25162
2020-05-30T05:51:10.757
<p>I'm sending MIDI messages to a proprietary turntable that has an LCD screen on it. The normal software sends out updates via MIDI SysEx to display the current tempo on the LCD. The MIDI is being received on a MKL25Z128VLK4, Cortex-M0+/ARMv6-M device. (I did disassemble the firmware .bin after digging in its guts for the type of chip it's using, but the result of that was ~30k lines of assembly) The LCD model number is inaccessible without desoldering</p> <p>At this point, I can successfully update the screen but I'm having trouble figuring out the pattern from a given number and I'm hoping someone else has experience with this.</p> <p>Here's what I have found so far:</p> <p>Setting a single byte to anything from 9-126 results in 00.0</p> <pre><code> BPM B1 B2 B3 B4 00.0 0 0 0 0 00.0 0 0 0 1 00.0 0 0 0 2 00.0 0 0 0 3 00.0 0 0 0 4 00.0 0 0 0 5 00.0 0 0 0 6 00.0 0 0 0 7 00.0 0 0 0 8 00.0 0 0 0 16 00.0 0 0 0 32 00.0 0 0 0 64 00.1 0 0 0 127 00.1 0 0 1 0 00.3 0 0 2 0 00.4 0 0 3 0 00.6 0 0 4 0 00.8 0 0 5 0 00.9 0 0 6 0 01.1 0 0 7 0 01.2 0 0 8 0 00.0 0 0 16 0 00.0 0 0 32 0 00.0 0 0 64 0 02.4 0 0 127 0 02.5 0 1 0 0 05.1 0 2 0 0 07.6 0 3 0 0 10.2 0 4 0 0 12.8 0 5 0 0 16.3 0 6 0 0 17.9 0 7 0 0 20.4 0 8 0 0 00.0 0 16 0 0 00.0 0 32 0 0 00.0 0 64 0 0 38.4 0 127 0 0 40.9 1 0 0 0 81.9 2 0 0 0 122.8 3 0 0 0 163.8 4 0 0 0 204.8 5 0 0 0 245.7 6 0 0 0 286.7 7 0 0 0 327.6 8 0 0 0 00.0 16 0 0 0 00.0 32 0 0 0 00.0 64 0 0 0 614.4 127 0 0 0 </code></pre> <p>Turning on multiple bytes adds them together with sometimes strange results</p> <pre><code> 40.9 1 0 0 0 00.1 0 0 1 0 41.1 1 0 1 0 81.9 2 0 0 0 00.1 0 0 1 0 82.0 2 0 1 0 </code></pre> <p>I'm wondering if there's some floating point or bitwise maths going on that I'm just not well versed in, and if so what are the real numbers and data types used for the calculations? I feel understanding this is crucial to solving this problem without a massive lookup table or gutting it and writing my own controller</p>
Construct a number from 0-999.9 using 5 data bytes of a MIDI SysEx message
|debugging|hardware|patching|embedded|math|
<p>You can <code>e scr.prompt.vi = true</code> to enable a limited form of vi key bindings for command line editing. However, this is <em>very</em> limited; it's even missing basic movement commands such as <kbd>f</kbd> and <kbd>t</kbd>, and some commands such as <kbd>cw</kbd> do not appear to work properly. Searching with vi keybindings is unavailable; you must still use the Emacs <kbd>Ctrl-R</kbd> syntax to search backwards in your history. And a special warning: <kbd>Enter</kbd> in command mode will do nothing; you must enter insert mode and press <kbd>Enter</kbd> to enter the command you've just brought up or edited.</p> <p>(I found the setting by searching the configuration variables using <code>e scr. ~vi</code>; thanks to @blabb for mentioning this to me.)</p> <p>Radare2 uses its own command line editing code, in <code>libr/cons/dietline.c</code>.</p>
25165
2020-05-30T11:01:32.683
<p>The Radare2 command line (I believe it's called "interactive mode"?) allows bringing back history and editing it with the arrow keys. However, I prefer to use vi/vim keybindings for this. How do I configure this?</p> <p>I do have a <code>$HOME/.inputrc</code> file which contains <code>set editing-mode vi</code>, and this works for many programs (presumably all that use GNU Readline or a compatible library).</p> <p>Alternatively, is there an option available to build Radare2 with Readline?</p>
How do I use vi keybindings at the command line in Radare2?
|radare2|
<p>If you cannot step inside that function, youโ€™re probably missing debug symbols for the library (check with <code>info shared</code>). You can try to either install symbols (usually in a package named <code>libc-dbg</code> or similar), or debug on assembly level by using <code>si</code> (step instruction) command. </p>
25172
2020-05-31T09:14:53.497
<p>I'm new with gdb and I have spent hours looking for direction but I can't find any. I need to analyze an executable to find how this program process the arguments and where the output came from. I have it running on my system, got it working correctly to print some encoded string. After some days trying gdb, I figure that I need to trace the data inside every function, but I can't pass this function __libc_init where the program alwas exited with code 0235. The last process says <code>__libc_init () from /system/lib/libc.so</code> so i think it's doing something with this external library libc.so. How could I continue the debug process when I hit this type of process? I can't find any reference to understand this.</p>
GDB exited when running library
|gdb|elf|libc|
<p>Technically, </p> <pre><code>PUSH A RET </code></pre> <p>is equivalent to </p> <pre><code>JMP A </code></pre> <p>and</p> <pre><code>PUSH A PUSH B RET </code></pre> <p>is equivalent to </p> <pre><code>CALL B JMP A </code></pre> <p>You can write a x64dbg script which <a href="https://help.x64dbg.com/en/latest/commands/searching/find.html" rel="nofollow noreferrer">searches</a> for the above pattern and replaces it with the simplified assembly.</p> <hr> <h2>Example</h2> <p><code>PUSH + RET</code> has the byte pattern</p> <pre><code>0: 68 44 33 22 11 push 0x11223344 5: c3 ret </code></pre> <p>The following script replaces it with <code>JMP</code> and the remainder (if any) with <code>NOP</code>.</p> <pre><code>$base = 0x91e000 $search_size = 0x100 findall $base, "68 ?? ?? ?? ?? c3", $search_size $count = $result next: dec $count $addr = ref.addr($count) $jmp_addr = dis.imm($addr) asm $addr, "jmp 0x{$jmp_addr}" $asm_size = $result $remainder = 6 - $asm_size fill_nop: dec $remainder asm $addr+$asm_size+$remainder, "nop" test $remainder, $remainder jnz fill_nop test $count, $count jnz next msg "Done" </code></pre> <p>Similarly for <code>PUSH + PUSH + RET</code>,</p> <pre><code>0: 68 44 33 22 11 push 0x11223344 5: 68 dd cc bb aa push 0xaabbccdd a: c3 ret </code></pre> <p>The following script replaces it with <code>CALL + JMP</code>.</p> <pre><code>$base = 0x91e000 $search_size = 0x100 findall $base, "68 ?? ?? ?? ?? 68 ?? ?? ?? ?? c3", $search_size $count = $result next: dec $count $addr = ref.addr($count) $ret_addr = dis.imm($addr) $call_addr = dis.imm($addr+5) asm $addr, "call 0x{$call_addr}" $asm_size = $result asm $addr+$asm_size, "jmp 0x{$ret_addr}" add $asm_size, $result $remainder = 0xb - $asm_size fill_nop: dec $remainder asm $addr+$asm_size+$remainder, "nop" test $remainder, $remainder jnz fill_nop test $count, $count jnz next msg "Done" </code></pre> <hr> <p>However there are some caveats with the above approach:</p> <ol> <li><p><code>PUSH + PUSH + RET</code> can be converted to <code>CALL + JMP</code> only if the callee uses <code>RET</code> instruction to return back to the caller (which is normal in cdecl). It won't work if it obfuscates the return using a <code>JMP</code> instruction. That is instead of <code>RET</code> there is </p> <pre><code>ADD ESP, 4 JMP DWORD PTR [ESP-4] </code></pre></li> <li><p>Pattern search will work in most cases. However if parts of the code are encrypted it can return false positives and you may be inadvertently overwriting wrong data.</p></li> </ol>
25181
2020-06-01T09:19:51.083
<p>I wanted to run an app on a VM but there are PUSH PUSH RETs stopping me from looking at their anti VM code. There is a messagebox when I run it on a VM. I set a breakpoint at <code>MessageBoxA</code> and it gets triggered as well as EAX is showing the message for the VM. It's all good until now.</p> <p><a href="https://i.stack.imgur.com/QO1IB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QO1IB.png" alt="enter image description here"></a></p> <p>I'm using x64dbg and I opened <code>Call Stack</code> tab and double-clicked on the address after user32.MessageBoxA (basically 2nd record), so I could trace back the calls before the actual MessageBoxA. It landed me here:</p> <p><a href="https://i.stack.imgur.com/JGI1a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JGI1a.png" alt="enter image description here"></a></p> <p>I heard that <code>PUSH RET</code> is like a <code>jmp</code>, <code>PUSH PUSH RET</code> is like a <code>call</code>. How do they work? Can they be deobfuscated with a tool/plugin or something?</p> <p>PUSH 0xC9DFBF leads me here:</p> <p><a href="https://i.stack.imgur.com/IdSFw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IdSFw.png" alt="enter image description here"></a></p> <p>PUSH 0xA4DB49 leads me here:</p> <p><a href="https://i.stack.imgur.com/cnZq1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cnZq1.png" alt="enter image description here"></a></p> <p>When I follow that jmp, it leads to similar code to <code>PUSH 0xC9DFBF</code>'s image which ends with a jmp to MessageBoxA.</p> <p>What could you recommend me to step into the code before the actual MessageBoxA call, so I can find their anti VM code and patch it? Do I need to step the instructions from the beginning one by one?</p> <p>Dumps: <a href="http://ufile.io/56c5b2z6" rel="nofollow noreferrer">http://ufile.io/56c5b2z6</a>. Rebase to 0x1270000 and find 0181E65C address. This address is in the executable file. I attached two dumped DLLs as well, because they were referenced.</p>
Dealing with obfuscated PUSH PUSH RET instructions
|assembly|x64dbg|deobfuscation|
<p>I was misinterpreting the context of the comment in the original link, it seems. I was under the impression that <code>Module.load</code> was a v8-ism, while it in fact appears to be a Frida-API.</p> <p><a href="https://frida.re/docs/javascript-api/#module" rel="nofollow noreferrer">https://frida.re/docs/javascript-api/#module</a></p>
25184
2020-06-01T13:22:20.240
<p>I was reading <a href="https://frida.re/news/2019/09/18/frida-12-7-released/" rel="nofollow noreferrer">this</a> Frida release page and noticed it made the following reference:</p> <blockquote> <p>Short of writing the whole agent in C, one could go ahead and build a native library, and load it using Module.load(). This works but means it has to be compiled for every single architecture, deployed to the target, etc.</p> </blockquote> <p>The CModule feature is fantastic for Frida-centric actions, but it would be nice to load generic shared-objects into the target process. CModule appears to be written for performance optimization within Stalker and related code. Any attempt to do something "extra" results in something like this will result in compile-time (at runtime, by the embedded TinyCC) errors such as:</p> <pre><code>Compilation failed: In file included from module.c:3:\nmodule.c:3: error: include file 'dlfcn.h' not found" </code></pre> <p>^ Attempt at writing a CModule stub that dlopen'd a shared object from disk. </p> <p>But the comment by Ole in the link above alludes to this being possible, though I can't find any references other than the <a href="https://nodejs.org/api/addons.html#addons_hello_world" rel="nofollow noreferrer">NodeJS C++ Addons</a> features that are, of course, specific to NodeJS.</p> <hr> <p><strong>tl;dr</strong> How does one load a generic object such that all of its exported functions are callable from Javascript? Is this possible?</p>
Load a *.dylib or *.so object into the Javascript V8 runtime?
|javascript|shared-object|frida|
<p>First: the code is only checking bit 2 (bit 0,1,2) if 25 or 28Mhz clock is set</p> <p>Second: maybe its redundant but can't say without original code - could be still a problem with your disassembler</p> <pre><code>retf 0004 ; instance pointer? </code></pre> <p>is a far return with pop of 4 bytes from stack</p>
25190
2020-06-02T02:05:46.907
<p>I'm reverse-engineering some code I wrote in the middle-90s for which the source is long-lost and I'm a bit baffled by some VGA code I've encountered. I think it's <em>probably</em> from library or 3rd party code as I was just learning computers then and, while I did include some assembly to interact with VGA, it wasn't this informed.</p> <p>If it's helpful, the app is a 16-bit DOS real-mode exe and the original source was compiled by the Turbo Pascal compiler (either version 6 or 7).</p> <pre><code> ; function boilerplate push bp mov bp,sp call 0EE2:0530 ; stack bounds check function ; probe vga port 03CCh sub sp,0002 ; why? mov dx,03CC in al,dx and al,0C ; mask bits 3 &amp; 2 cmp al,04 ; al == 00000100b mov al,00 ; pre return value jne jump_label ; return 0 inc ax ; return 1 jump_label: ; store return value in [bp-01] as well, for.. reasons. mov [bp-01],al mov al,[bp-01] ; function boilerplate mov sp,bp pop bp retf 0004 ; instance pointer? </code></pre> <p>So the question is, what is the intent here? Two parts are confusing to me:</p> <p><strong>First</strong>, bits 2 and 3 denote <em>clock select</em> according to the VGA docs I've read, but those docs are light on information about what that means when bit 3 is involved. For example, <a href="http://www.osdever.net/FreeVGA/vga/extreg.htm#3CCR3C2W" rel="nofollow noreferrer">http://www.osdever.net/FreeVGA/vga/extreg.htm#3CCR3C2W</a> declares the two values with the bit 3 set as <em>undefined</em>.</p> <p>This function seems to return 0 when bit 3 is set and bit 2 isn't. But, why? What is it trying to determine about the hardware?</p> <p><strong>Second</strong>, and this is an aside, but what is the intent of <code>mov [bp-01],al</code> followed by <code>mov al,[bp-01]</code>? This seems redundant!</p>
Why would VGA port 03CC respond with bit 3 set and bit 2 not?
|x86|dos|
<p>I would like to answer my own question. Firstly, we need to understand that funcap annotates disassembly with anterior comments which are helpful most of the time. But, sometimes it can provide redundant information which can hinder the normal workflow. Unlike normal comments and repeatable comments which usually appear at the end of the line, anterior comments appear above any instruction or data. While posterior comments appear below any given data or instruction in disassembly.</p> <p>Therefore, the above problem of clearing comments can be broken down into 2 steps:</p> <ol> <li>Delete anterior comments while retainingย other comments at the end of line(comments, repeatable comments).</li> <li>Set the color of the disassembly view to default.</li> </ol> <p>Opening and deleting every individual comment manually using <kbd>Insert</kbd> is a tedious task. We can automate this (boring) task using IDC script or IDAPython script.</p> <p><strong>clear_comments.idc</strong> - idc script</p> <pre><code>// clear_comments.idc - clear all (anterior)comments by funcap using IDC #include &lt;idc.idc&gt; static main(void) { auto ea; for (ea=MinEA(); ea != BADADDR; ea=NextHead(ea, BADADDR)) { DelExtLnA(ea, 0); // delete anterior comments SetColor(ea, CIC_FUNC, DEFCOLOR); // set default color of functions and data SetColor(ea, CIC_ITEM, DEFCOLOR); } Message(&quot;[*] refreshing disassembly.&quot;); Refresh(); Message(&quot;.ok\n&quot;); Message(&quot;[*] refreshing lists.&quot;); RefreshLists(); Message(&quot;.ok\n&quot;); } </code></pre> <p><strong>clear_comments.py</strong> - idapython script</p> <pre><code># clear_comments.py - clear all (anterior)comments by funcap using IDAPython (python 2.7.10) from idaapi import * from idc import DelExtLnA, SetColor, Refresh, RefreshLists def refresh_disassembly(): Refresh() return &quot;disassembly&quot; def refresh_lists(): RefreshLists() return &quot;lists&quot; def clear_comments(): ea = idaapi.cvar.inf.minEA while ea != BADADDR: DelExtLnA(ea, 0) # delete anterior comments SetColor(ea, CIC_FUNC, DEFCOLOR) # set default color of functions and data SetColor(ea, CIC_ITEM, DEFCOLOR) ea = idaapi.next_head(ea, idaapi.cvar.inf.maxEA) print &quot;[*] refreshing&quot;, refresh_disassembly(), &quot;..ok&quot; print &quot;[*] refreshing&quot;, refresh_lists(), &quot;..ok&quot; return None clear_comments() </code></pre> <p><em>Note 1: I have tested the idapython script in IDA 6.6 with python 2.7.10. For using this script with python 3.x.x we just need some minor adjustments to <code>print(...)</code> statements at <code>line:22</code> <code>line:23</code> only.</em></p> <p><em>Note 2: These scripts can be used to delete pseudo comments or to reset the color of the disassembly view to default.</em></p>
25194
2020-06-02T11:26:38.267
<p>How to clear the comments created by funcap and restore database to it's previous state?</p> <p>I tried reanalyzing the program but comments do not seems to go away from database.</p> <p>Though, checking-off Comments in IDA Options seems to work, but it also remove comments that I have made.</p> <p><a href="https://i.stack.imgur.com/bQ83R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bQ83R.png" alt="enter image description here"></a></p>
How to clear all comments created in ida using funcap?
|ida|ida-plugin|
<p>The offsets you are quoting are not the offsets of the structure members, but they are offsets of the debug information statements inside the dwarf section. The members itself are all 8 bytes in size. <code>_IO_write_ptr</code> is at offset 40, <code>_IO_write_end</code> is at offset 48 and and <code>_IO_buf_base</code> is at offset 56.</p> <p>The debug information for <code>_IO_write_end</code> is bigger than the previous debug information records, because the member <code>_IO_write_end</code> is declared in line 256 of the source file, and encoding line numbers of 256 or bigger takes more bytes than encoding line numbers zero to 255.</p>
25217
2020-06-05T09:26:28.057
<p>Looking at DWARFs of bzip2_base I see different offsets between members of a structure type although they are of the same type. Check _IO_FILE structure at the offset 0x9c <a href="https://github.com/ryantanwk/VaTy/blob/master/benchmark/sample_binaries/bzip2_base.gcc54-64bit.DIE" rel="nofollow noreferrer">here</a>. All the way until the 7th member at 0xF0 (_IO_write_end) all members have 12 Byte offset from the previous member, but the 8th member (@ 0xFD) onward the difference in the DIE offset gets 13 Bytes. Can anyone help me understand why? any good text that explains?</p>
How is padding size calculated for members of structure types?
|elf|struct|debugging-symbols|offset|
<p>Try to find the string of the error message in the binary (Hotkey: <kbd>Alt</kbd>+<kbd>B</kbd>, Search for binary). If the auto analysis worked well, the string should be annotated with all functions that reference the string, and you should be able to jump to the instructions that refer to the message using the cross references popup (Hotkey: <kbd>Ctrl</kbd>+<kbd>X</kbd>)</p>
25222
2020-06-06T10:14:35.400
<p>Let's suppose I want to use IDA Pro to debug a Windows PE64 application that always throws an error message at a specific point when being run. What steps would I have to take to find the specific function in the code of the application that throws the error message? </p>
How can I find the function that throws an error message in IDA Pro?
|ida|disassembly|debugging|
<p>If you can't modify the binary but through the static analysis you get the number of bytes you need to provide as a flag, you can construct bit vector</p> <pre><code>flag_chars = [claripy.BVS('flag_%d' % i, 8) for i in range(6)] flag = claripy.Concat(*flag_chars + [claripy.BVV(b'\n')]) </code></pre> <p>and pass that to the <code>entry_state</code> since the flag is provided as an input through <code>stdin</code> to this binary.</p> <pre><code>p = angr.Project('test') state = p.factory.entry_state(args=['./test'], stdin=flag) </code></pre> <p>With such setup, <code>angr</code> will successfully find the solution.</p> <p>Additionally, if you would like to extract the flag</p> <pre><code>found = sm.found[0] flag_str = found.solver.eval_upto(flag, 7, cast_to = bytes) print(flag_str) </code></pre>
25237
2020-06-08T08:10:46.790
<p>I am trying to learn angr from beginning. Due to lack of simple tutorials I programmed my own little executable which angr should solve.</p> <p>The C code looks as follows:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;stdlib.h&gt; int main(int argc, char *argv[]) { char buffer[20]; printf("Password\n"); fgets(buffer,20,stdin); if (strcmp(buffer,"super!\n")==0) { printf("SUCCESS!\n"); } else { printf("FAIL!\n"); } return 0; } </code></pre> <p>When compiled and opened in binary ninja I see the printfs at following addresses: <a href="https://i.stack.imgur.com/nMLiL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nMLiL.png" alt="BN"></a> So I created following angr python3 code:</p> <pre><code>import angr from angr.state_plugins import SimSystemPosix p = angr.Project('./test') state = p.factory.entry_state() sm = p.factory.simulation_manager(state) sm.explore(find=0x40118c, avoid=0x40119a) print(sm.found) </code></pre> <p>Running the python code shows following output:</p> <blockquote> <p>python3 solve_angr.py WARNING | 2020-06-08 10:02:29,497 | angr.state_plugins.symbolic_memory | The program is accessing memory or registers with an unspecified value. This could indicate unwanted behavior.<br> WARNING | 2020-06-08 10:02:29,497 | angr.state_plugins.symbolic_memory | angr will cope with this by generating an unconstrained symbolic variable and continuing. You can resolve this by:<br> WARNING | 2020-06-08 10:02:29,497 | angr.state_plugins.symbolic_memory | 1) setting a value to the initial state<br> WARNING | 2020-06-08 10:02:29,497 | angr.state_plugins.symbolic_memory | 2) adding the state option ZERO_FILL_UNCONSTRAINED_{MEMORY,REGISTERS}, to make unknown regions hold null<br> WARNING | 2020-06-08 10:02:29,497 | angr.state_plugins.symbolic_memory | 3) adding the state option SYMBOL_FILL_UNCONSTRAINED_{MEMORY_REGISTERS}, to suppress these messages.<br> WARNING | 2020-06-08 10:02:29,498 | angr.state_plugins.symbolic_memory | Filling memory at 0x7fffffffffefff8 with 72 unconstrained bytes referenced from 0x58d4e0 (strcmp+0x0 in libc.so.6 (0x8d4e0))<br> WARNING | 2020-06-08 10:02:29,499 | angr.state_plugins.symbolic_memory | Filling memory at 0x7fffffffffeff70 with 8 unconstrained bytes referenced from 0x58d4e0 (strcmp+0x0 in libc.so.6 (0x8d4e0))<br> []</p> </blockquote> <p>The [] indicates that it did not find any solution.</p> <p>Can anybody tell me what I did wrong?</p>
Simple angr example not working
|c|angr|
<p>This is function <code>dflt</code> (or <code>__aeabi_i2d</code>) from the ARM compiler libraries. It performs a conversion of a 32-bit signed integer in <code>R0</code> into a a soft-float <strong>double</strong> (64-bit floating point value) in <code>R0:R1</code>. </p> <p>An <a href="https://en.wikipedia.org/wiki/Double-precision_floating-point_format" rel="nofollow noreferrer">IEEE 754 double</a> consists of a sign bit, 11-bit exponent and 52-bit fraction:</p> <pre><code> 63 62 52 51 0 +------------------------------------------------------------------+ | s | exponent(11) | fraction(52) | +------------------------------------------------------------------+ +------------------------------------------------------------------+ | R1 | R0 | +------------------------------------------------------------------+ 31 0 31 0 </code></pre> <p>The value of the number is 2^(e-1023)*1.fraction</p> <p>The code calculates the exponent and fraction that would approximate the original value and puts it into R0:R1. The magic numbers in shifts are necessary to line up the fraction across the two registers and 1024 is the bias for the exponent.</p>
25245
2020-06-09T02:46:05.857
<p>I'm a little stuck trying to understand this simple piece of code. It get's a number in R0. The first part seems to be a R0 = abs(R0), but then it get's more difficult. The number of leading zeros is determined, then it's left shifted by that many bits and then it's checked if that is > 0, otherwise 0 is returned. I don't get what the purpose of the entire shifting there is supposed to be and what the Add and additional shift operations are supposed to do there. </p> <pre><code>ROM:0005B7BE ; =============== S U B R O U T I N E ======================================= ROM:0005B7BE ROM:0005B7BE ROM:0005B7BE sub_5B7BE ROM:0005B7BE ANDS.W R2, R0, #0x80000000 ROM:0005B7C2 IT MI ROM:0005B7C4 NEGMI R0, R0 ROM:0005B7C6 CLZ.W R3, R0 ROM:0005B7CA LSLS.W R1, R0, R3 ROM:0005B7CE BEQ retZero ROM:0005B7D0 RSB.W R3, R3, #29 ROM:0005B7D4 ADD.W R3, R3, #1024 ROM:0005B7D8 MOV.W R0, R1,LSL#21 ROM:0005B7DC ADD.W R2, R2, R3,LSL#20 ROM:0005B7E0 ADD.W R1, R2, R1,LSR#11 ROM:0005B7E4 BX LR ROM:0005B7E6 ; --------------------------------------------------------------------------- ROM:0005B7E6 ROM:0005B7E6 retZero ROM:0005B7E6 MOV.W R0, #0 ROM:0005B7EA BX LR ROM:0005B7EA ; End of function sub_5B7BE </code></pre>
Issue understanding simple ARM ASM function
|disassembly|decompilation|arm|assembly|
<p>Values around <code>FFFFFFFF</code> are used in Cortex-M for <em><a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0552a/Babefdjc.html" rel="nofollow noreferrer">exception returns</a></em> (ECX_RETURN). Currently defined values:</p> <ol> <li><p>0xFFFFFFF1 - return to Handler mode, restore state from main stack</p></li> <li><p>0xFFFFFFF9 - return to Thread mode, restore state from main stack</p></li> <li><p>0xFFFFFFFD - return to Thread mode, restore state from process stack</p></li> </ol> <p>So the actual branch address is taken from the stack (MSP or PSP, depending on the low bits of the value). See the linked document for more details. </p> <p>Since GDB is mostly used for user-mode debugging, it does not expect such shenanigans and probably tries to set a breakpoint at the value of <code>LR</code> which naturally fails. OpenOCD knows about exceptions and is able to step properly. </p>
25246
2020-06-09T05:10:22.140
<p>I'm debugging an ARM cortex M4 (STM32F4) running FreeRTOS. Inside the assembly FreeRTOS function <code>vPortSVCHandler</code>, there's a branch instruction</p> <pre><code>bx r14 </code></pre> <p>using GDB, I step through instruction by instruction and find that r14 (lr) contains the value <code>0xfffffffd</code> (not a valid address) immediately before the bx instruction is executed.</p> <p>For some reason, GDB doesn't follow the <code>bx</code> instruction with <code>si</code> (hangs), but I'm still able to <code>step</code> via openOCD. I find that the function that's branched to is in fact a valid function at address <code>0x08012abc</code>.</p> <p>From the ARM docs on <code>bx</code>, its argument should be a register containing an address to branch to. </p> <p>Clearly, I'm misunderstanding or looking at the wrong docs.</p> <p>I tried tweaking <code>lr</code> with GDB just before the branch instruction. Changing it to <code>0x0</code> or <code>0xfffffff7</code> results in a hard fault shortly after the branch.</p> <p>How does this branch instruction, when called with a value of <code>0xfffffffd</code>, result in branching to a valid function at <code>0x08102abc</code>?</p>
ARM bx instruction branches to address not specified as argument
|arm|
<p>In some games I have found the encryption on, it has been before the send call e.g. a function that calls send sometimes 2-3 calls up.</p> <p>For recv it is decrypting after but some first decrypted part of it for a header to look up the size/id.</p> <p>Others had compressed packets (zlib) which took a little bit of figuring.</p> <p>A trick to see if is possibly compressed or encrypted well is try to compress the data (if large enough) if it does not get any meaningful compression then it is already compressed or encrypted enough to look random.</p> <p>So the application might call recv or some other func to get data in. Then it may, decrypt some identifier or length e.g. Packet ID lookup size or size in header.</p> <p>Try sending 20 A characters the first time Restarting the app and sending 23 A characters</p> <p>Do a byte by byte difference and see what stands out as different.</p> <p>Sometimes encryption key could be sent by the server first, in which case look for a single byte, block of bytes etc, that is copied somewhere on first recv, find references to that or memory (add a read breakpoint on it) and you might find your encrypt and/or decrypt routine.</p> <p>Do multiple connections with same input data have the same data sent on the wire?</p> <p>Can you send some reliable information and packet sniff it to see what it looks like?</p> <p>For example if it has a login as the first packet and it is sent first straight after connection.</p> <p>Send a long string of AAAAAAAAAAAAAAAAAAAAAAA And observe the data.</p> <p>Does it look like</p> <p>10 00 01 00 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9 C9</p> <p>For example that would indicate something like xor. If xor observe many packets and look for bytes that you see often, e.g. 00 xor by something is the value.</p> <p>Could also look more jumbled up or blocks of 4 bytes or some length. If you see repeating sequence e.g. C9 EF AD CC C9 EF AD CC and you know the input data was a long string of "A" for example, then its doing a pattern.</p> <p>I have seen some implementations where something like blowfish was used, initially seeded but they did not handle padding the packet out fully to a multiple of the block length, so odd number of bytes showed up as plain text.</p> <p>If the data is different each time from the very first send with no other recv, it could be a time based encryption based on when you connected, or that the client just picks random key and tells the server it.</p> <p>For example if the first packet sent from client to server is 32 bytes of gibberish, its probably a key or an initialization vector to seed a block cipher or something...</p> <p>One software was like this. CustomSend(data, length)</p> <p>Which copied the bytes to a buffer, offset by packet header. Filled in the header with the length. Encrypted the entire content using another function (Look for loops before send or a function called before send containing loops could be a few levels up or deep, but you should follow what happens to the buffer of data, you need to do this backwards.</p> <p>Following the code backwards can be tricky sometimes I find it easier to go forward if you can find something you know will submit some known data to send to this socket action/packet. Sometimes this is after a connect or after a first recv. Or after hitting enter in a chat box.</p> <p>It is also not guaranteed that the same encryption or key is used for both encryption and decryption.</p> <p>It could also be some kind of Asymmetric encryption, e.g. one key to encrypt but another to decrypt with each end only knowing the key needed to send or recv data with the other.</p> <p>Or they could get crafty and encrypt the data one way for the first few packets and switch it up after negotiating keys to use.</p> <p>If you happen to use IDA or maybe there is an alternative on Ghidra <a href="https://github.com/d3v1l401/FindCrypt-Ghidra" rel="nofollow noreferrer">https://github.com/d3v1l401/FindCrypt-Ghidra</a> or other tools? You can use something like FindCrypt to find known crypto algorithms <a href="https://www.hex-rays.com/blog/findcrypt/" rel="nofollow noreferrer">https://www.hex-rays.com/blog/findcrypt/</a> which by looking at what uses/references them you might find the encrypt/decrypt that way.</p> <p>Sounds fun hope you can make some progress on it.</p>
25252
2020-06-09T14:08:37.297
<p>I have several applications that interact with the network, but the data is encrypted. I set breakpoints on send ws2_32.dll and found the correct buffer in which the encrypted data was located (then I checked the call stack to find the encryption function used), but this did not lead to anything good, for example, breakpoints for reading and entries in. If you have information describing the process of searching for packages in programs or in examples / books. I'll be happy</p>
Decrypt application protocol packet
|unpacking|decryption|patch-reversing|
<p>Not sure if you ask about one line or the whole program.</p> <p>One assembly line can be obtain for example by such script:</p> <pre><code>addr = toAddr(&lt;address&gt;) print(currentProgram.getListing().getInstructionAt(addr)) </code></pre> <p>if we are talking about the whole program</p> <pre><code>for instr in currentProgram.getListing().getInstructions(True): print(instr) </code></pre> <p>but I guess the last one can take a while. More information can be found in the docs about <a href="https://ghidra.re/ghidra_docs/api/ghidra/program/model/listing/Listing.html" rel="noreferrer">Listing</a> object.</p>
25261
2020-06-10T08:50:39.840
<p>I'm using Ghidra to reverse engineer an EXE file and save its assembly line code only. Does Ghidra have any function or scripts which exports the assembly line code? I don't want to manually copy the code from the Listing window.</p>
Extracting Assembly line code from an executable in Ghidra
|assembly|ghidra|