int __cdecl main(int argc, constchar **argv, constchar **envp) { int result; // eax int stat_loc; // [rsp+4h] [rbp-3Ch] int i; // [rsp+8h] [rbp-38h] __pid_t pid; // [rsp+Ch] [rbp-34h] char s2; // [rsp+10h] [rbp-30h] unsigned __int64 v8; // [rsp+28h] [rbp-18h]
v8 = __readfsqword(0x28u); pid = fork(); if ( pid ) { argv = (constchar **)&stat_loc; waitpid(pid, &stat_loc, 0); } else { for ( i = 0; i <= strlen(&flag); ++i ) { if ( *(&flag + i) == 105 || *(&flag + i) == 114 ) *(&flag + i) = 49; } } printf("input the flag:", argv); __isoc99_scanf("%20s", &s2); if ( !strcmp(&flag, &s2) ) result = puts("this is the right flag!"); else result = puts("wrong flag!"); return result; }
The fork creates another process, but the loop in the main thread is the quickest place to start:
1 2 3 4 5
for ( i = 0; i <= strlen(flag); ++i ) { if ( flag[i] == 'i' || flag[i] == 'r' ) flag[i] = '1'; }
The loop replaces both i and r with 1.
Tracing shows the flag is {hacking_for_fun}, giving flag{hack1ng_fo1_fun} after the transformation.
That submission works. I expected the fork to hide a trap, but apparently not!
Happy New Year
PEiD reports UPX packing, but my usual unpacker cannot handle it. The latest official UPX does the job; PEiD then mentions yoda's Protector. I opened the result in IDA and went straight to main.
It is essentially a number-guessing game with no reward for a correct guess. In the strings window, the first string is the flag, BJD{S1mple_ReV3r5e_W1th_0D_0r_IDA}, which submits successfully.
Reversing it shows the string hidden in a menu variable, probably using inline assembly. It is not visible in the pseudocode but appears immediately in the assembly.
helloworld
The download is an Android APK, and I had never reversed one before. Time to find a tutorial.
The tutorials point to dex2jar for converting the APK’s DEX into a JAR. Opening that JAR in jar-decompiler brings the flag into view almost immediately.
for ( i = 0; i < 100; ++i ) { if ( (unsignedint)i >= 0x64 ) j____report_rangecheckfailure(); Dest[i] = 0; } print("please enter the flag:"); scanf("%20s", &flag); flagLength = j_strlen(&flag); v1 = (constchar *)sub_4110BE((int)&flag, flagLength, (int)&v11); strncpy(Dest, v1, 40u); v8 = j_strlen(Dest); for ( j = 0; j < v8; ++j ) Dest[j] += j; v2 = j_strlen(Dest); if ( !strncmp(Dest, Str2, v2) ) print("rigth flag!\n"); else print("wrong flag!\n"); HIDWORD(v4) = v3; LODWORD(v4) = 0; return v4; }
Unlike the previous check, this one first calls a transformation function, then adds each character’s index before comparing the result with the target.
The transformation function is the next place to look:
The alphabet and substitution table both look like Base64. I tried that hypothesis in a script, undoing the index adjustment first.
1 2 3 4 5 6
import base64 s1 = 'e3nifIH9b_C@n@dH' s1 = list(s1) for i in range(len(s1)): s1[i] = chr(ord(s1[i]) - i) print(base64.b64decode(''.join(s1)))
The flag is {i_l0ve_you}. It really was Base64.
A Different Flag
This x86 Windows program asks for directions numbered 1–4. The code updates coordinates, rejects walls and out-of-bounds moves, and succeeds on #: it is a maze.
The modulo operation makes this awkward, but the following identity helps: $$ (a + b) % c=(a % c + b % c)%c $$ All key characters are lowercase, so their values cannot exceed 26; inputChar - '\' is roughly between 25 and 100.
I enumerated possible input characters for each position:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
text = list('killshadow') text = [ord(x) for x in text] key = list('adsfkndcls') key = [ord(x) for x in key] flag = [0] * len(text) for i in range(len(text)): flag[i] = text[i] - ord('a') flag[i] += 26 * 2 flag[i] += key[i] - ord('a') flag[i] += ord('\'')
#print(flag) print(''.join([chr(x) for x in flag]))
KL^Q]UDFZi and efxkwo^t are strange flags, and neither submission is accepted.
An online writeup tests candidates directly because each character is encrypted independently:
text = list('killshadow') text = [ord(x) for x in text] key = list('adsfkndcls') key = [ord(x) for x in key] flag = [0] * len(text) #charset = list(range(ord('a'), ord('z')+1)) charset = list(range(ord('A'), ord('Z')+1)) for cnt in range(len(text)): for i in charset: res = change(i, cnt) if res == text[cnt]: flag[cnt] = i print(''.join([chr(x) for x in flag]))
There are multiple solutions: uppercase KLDQCUDFZO and lowercase efxkwoxzti. In principle, mixing their characters should also satisfy the conditions.
Scratch to Win
IDA shows a Win32 windowed program. I can only see a scratch-card interface, so inspect the dialog logic in diagFunc.
The two functions are visible here. The first, sub_4010F0, encrypts the key and appears to use recursion. Dynamic debugging in OllyDbg, with a few jumps changed, shows the key changing from ZJSECaNH3ng to 3CEHJNSZagn: a simple permutation.
Next inspect sub_401000. Its alphabet looks like Base64. The checks suggest values for input[0] and input[1], and checks on input[3] and input[4] can verify the guess. A modified Base64 alphabet also appears among the strings.
The result is UJWP1jMp.
Java Reverse Decryption
The archive contains a Java class. Its Encrypt method adds 64 to each character, XORs the result with 0x20, and compares the list with a hard-coded KEY:
seg001:0000 sub_10030 proc near ; CODE XREF: sub_10030↓j seg001:0000 ; start+5↓p seg001:0000 jmp short sub_10030 seg001:0000 sub_10030 endp seg001:0000 seg001:0002 ; --------------------------------------------------------------------------- seg001:0002 mov cx, 22h ; '"' seg001:0005 lea bx, aUDuTZWjQGjzZWz ; "]U[du~|t@{z@wj.}.~q@gjz{z@wzqW~/b;" seg001:0009 seg001:0009 loc_10039: ; CODE XREF: seg001:000F↓j seg001:0009 mov di, cx seg001:000B dec di seg001:000C xor byte ptr [bx+di], 1Fh seg001:000F loop loc_10039 seg001:0011 lea dx, aUDuTZWjQGjzZWz ; "]U[du~|t@{z@wj.}.~q@gjz{z@wzqW~/b;" seg001:0015 mov ah, 9 seg001:0017 int 21h ; DOS - PRINT STRING seg001:0017 ; DS:DX -> string terminated by "$" seg001:0019 retn seg001:001A assume ss:dseg, ds:nothing seg001:001A seg001:001A ; =============== S U B R O U T I N E ======================================= seg001:001A seg001:001A ; Attributes: noreturn seg001:001A seg001:001A public start seg001:001A start proc near seg001:001A mov ax, seg dseg seg001:001D mov ds, ax seg001:001F assume ds:dseg seg001:001F call sub_10030 seg001:001F start endp seg001:001F seg001:0022 ; --------------------------------------------------------------------------- seg001:0022 mov ah, 4Ch seg001:0024 int 21h ; DOS - 2+ - QUIT WITH EXIT CODE (EXIT) seg001:0024 seg001 ends ; AL = exit code seg001:0024 seg001:0024 seg001:0024 end start
The loop XORs each stored character with 0x1F. Applying the same operation again should recover the text.
I used a short script:
1 2 3 4 5 6 7
a = ']U[du~|t@{z@wj.}.~q@gjz{z@wzqW~/b;' a = list(a) a = [ord(x) for x in a] flag = [] for i in a: flag.append(i ^ 0x1f) print(''.join([chr(x) for x in flag]))
The result is BJD{jack_de_hu1b1an_xuede_henHa0}.
check_1n
The program opens with an ASCII-art laptop. IDA lists many functions and main is not obvious, so I searched for the function that prints the laptop and followed its references.
There are too many strings for easy static analysis, so use OllyDbg.
OllyDbg does not reveal much either, but there is a strange string: 2i9Q8AtFJTfL3ahU2XGuemEqZJ2ensozjg1EjPJwCHy4RY1Nyvn1ZE1bZe.
There appears to be a decryption function, but the encryption routine is hard to read. Jumping from main in OllyDbg gets stuck at malloc, and there are anti-debugging checks along the way.
Finally, Shift+F12 reveals the startup password HelloWorld.
A flag file contains a fake flag. Base64 decoding gives Why don't you try the magic brick game.
That sounds like an invitation to try the brick-breaking game.
I lost the game—and the real flag appeared anyway!