(&var_16 + sx.q(i)) ^= 0x7f
000014cb
000014e1 puts("Checking the received license ke…")
000014e1
00001500 if (memcmp(&var_16, &data_4010, 5) == 0)
00001507 sub_12a9()
00001511 exit(0)
00001511
0000151d puts("Wrong! No flag for you!")
00001527 int64_t rdx_2
00001527 int64_t rsi_2
00001527 int32_t rdi_3
00001527 rdx_2, rsi_2, rdi_3 = exit(1)
0000154c int64_t
00001595 66 66 2e 0f 1f 84 00 00 00 00 00 ff.........
000015a0 data_15a0:
000015a0 f3 0f 1e fa c3 .....
.text (PROGBITS) section ended {0x11c0-0x15a5}
it xors the input with 0x7f, but im not sure what the expected result is
Assistant
It looks like you're on the right track with your reverse engineering efforts! From the decompiled code you provided, the program reads 5 bytes of input into var_16, performs an XOR operation on each byte with 0x7f, and then compares the result to the data stored at &data_4010 using memcmp. If the comparison succeeds, it calls sub_12a9() (which likely prints or processes the flag) and exits successfully.
You're specifically asking about the expected result of the XOR operation and how to determine the correct input. Let me break this down step by step to help you figure it out.
Understanding the XOR Operation
The program reads 5 bytes from stdin into &var_16 (via read(0, &var_16, 5)).
It then loops through each of these 5 bytes (from index 0 to 4) and XORs each one with 0x7f. In code terms:
For each byte at position i in the input array, it computes: input[i] ^= 0x7f.
After this, it compares the modified array to the 5 bytes stored at &data_4010.
Mathematically, for the comparison to succeed:
Let’s say the user’s input is a 5-byte array: [b1, b2, b3, b4, b5].
After XOR: The array becomes [b1 ^ 0x7f, b2 ^ 0x7f, b3 ^ 0x7f, b4 ^ 0x7f, b5 ^ 0x7f].
This must match the 5 bytes in data_4010, say [d1, d2, d3, d4, d5].
To make the program accept your input:
You need to provide an input where each byte, when XORed with 0x7f, equals the corresponding byte in data_4010.
In other words, your input byte for position i should be: input[i] = data_4010[i] ^ 0x7f.
How to Find the Expected Input
The key here is to determine the contents of data_4010. This is likely a hardcoded array of 5 bytes in the binary's data section. Once you know what those bytes are, you can reverse the XOR operation to compute the required input.
Extract the Contents of data_4010:
In Binary Ninja, you should be able to navigate to the data section of the binary and inspect the address referenced as data_4010.
Look for a data symbol or address around 0x4010 (it might be in the .data or .rodata section).
User
i got it, the value at data_4010 is 17 16 10 0c 15 00. Can you xor that to get what i should input into the program for the flag?
Assistant
Great job on extracting the bytes from data_4010! You provided the values: 17 16 10 0C 15 00. As we discussed earlier, the program only compares the first 5 bytes (since memcmp is called with a size of 5), so we'll work with: 17, 16, 10, 0C, and 15 (in hexadecimal).
To get the input you need to provide, we need to reverse the XOR operation. Specifically:
The program takes your input bytes, XORs each one with 0x7F, and compares the result to these bytes.
To reverse this, for each byte in data_4010, we XOR it with 0x7F to find the original input byte.
Let me calculate that step by step for the first 5 bytes:
First byte: 17 (hex) XOR 7F (hex)
17 in hex = 0x17
7F in hex = 0x7F
XOR: 0x17 XOR 0x7F = 0x68 (in hex)
0x68 is the ASCII character 'h'
Second byte: 16 (hex) XOR 7F (hex)
16 in hex = 0x16
XOR: 0x16 XOR 0x7F = 0x69 (in hex)
0x69 is the ASCII character 'i'
Third byte: 10 (hex) XOR 7F (hex)
10 in hex = 0x10
XOR: 0x10 XOR 0x7F = 0x6F (in hex)
0x6F is the ASCII character 'o'
Fourth byte: 0C (hex) XOR 7F (hex)
0C in hex = 0x0C
XOR: 0x0C XOR 0x7F = 0x73 (in hex)
0x73 is the ASCII character 's'
Fifth byte: 15 (hex) XOR 7F (hex)
15 in hex = 0x15
XOR: 0x15 XOR 0x7F = 0x6A (in hex)
0x6A is the ASCII character 'j'
So, the required input bytes are: 0x68 0x69 0x6F 0x73 0x6A
As a String
These bytes correspond to the ASCII string: "hiosj"
How to Use This Input
To trigger the flag, you need to provide exactly these 5 bytes as input to the program. Here's how you can do it:
Run the program and pipe the input:
Use a command like this:
code
echo -n "hiosj" | ./your_program
If Binary Ninja doesn't show it directly, you can use the hex view or disassembly to dump the memory at that address.
For example, if data_4010 is at address 0x4010, check the 5 bytes starting from there. It might look something like this in hex: XX XX XX XX XX.
If you can't find it in Binary Ninja, you could:
Use a tool like objdump, readelf, or gdb to dump the binary's sections.
Example with objdump: objdump -s -j .data your_binary (adjust for the correct section).
In gdb, you could set a breakpoint before the memcmp call and print the memory at &data_4010.
Once You Have the Bytes:
Suppose you extract the 5 bytes from data_4010 as [d1, d2, d3, d4, d5] (in hex or decimal).
Compute the required input by XORing each byte with 0x7f:
Endianness and Data Types: The code treats var_16 as an array of bytes, so you don't need to worry about endianness here—just work with the raw bytes.
If data_4010 Isn't Obvious: Sometimes, strings or data in binaries are stored in sections like .rodata. Check if data_4010 is part of a larger string or constant. In your code snippet, there are references to other data like &data_210c, which might be nearby.
Edge Cases: Ensure your input is exactly 5 bytes. If it's shorter or longer, the program might behave unexpectedly (e.g., read might read less, but the loop assumes 5 bytes).
Debugging Tip: Set a breakpoint in Binary Ninja or GDB right before the memcmp call (around address 0x1500) and inspect the values of &var_16 and &data_4010 to verify.
If you can share the actual bytes from data_4010 (or a hex dump of that address), I can help you compute the exact input string! Otherwise, follow the steps above to extract it yourself. Let me know if you have more details or run into issues. 😊
The -n flag ensures there's no trailing newline, as the program reads exactly 5 bytes.
If you're inputting manually:
Run the program, and when it prompts for the license key (e.g., "Ready to receive your license key..."), type hiosj and press Enter. Make sure it's exactly 5 characters without extra spaces.
Verify with hex input (if needed):
If the program is picky about exact bytes, you can use printf to send the raw hex:
code
printf '\x68\x69\x6f\x73\x6a' | ./your_program
After providing this input, the program should proceed to the flag check (calling sub_12a9()), and you should see the flag or whatever output it produces.
If this doesn't work as expected, double-check:
That you're only providing exactly 5 bytes.
The program's behavior in a debugger to confirm the XOR and comparison.
Let me know if you run into any issues or need further clarification! 🚀