$ r2 -c "=H" file
) and Bokken . /*************************************************************************** * Dr. Evil's Insidious Bomb, Version 1.1 * Copyright 2011, Dr. Evil Incorporated. All rights reserved. * * LICENSE: * * Dr. Evil Incorporated (the PERPETRATOR) hereby grants you (the * VICTIM) explicit permission to use this bomb (the BOMB). This is a * time limited license, which expires on the death of the VICTIM. * The PERPETRATOR takes no responsibility for damage, frustration, * insanity, bug-eyes, carpal-tunnel syndrome, loss of sleep, or other * harm to the VICTIM. Unless the PERPETRATOR wants to take credit, * that is. The VICTIM may not distribute this bomb source code to * any enemies of the PERPETRATOR. No VICTIM may debug, * reverse-engineer, run "strings" on, decompile, decrypt, or use any * other technique to gain knowledge of and defuse the BOMB. BOMB * proof clothing may not be worn when handling this program. The * PERPETRATOR will not apologize for the PERPETRATOR's poor sense of * humor. This license is null and void where the BOMB is prohibited * by law. ***************************************************************************/ #include <stdio.h> #include <stdlib.h> #include "support.h" #include "phases.h" /* * Note to self: Remember to erase this file so my victims will have no * idea what is going on, and so they will all blow up in a * spectaculary fiendish explosion. -- Dr. Evil */ FILE *infile; int main(int argc, char *argv[]) { char *input; /* Note to self: remember to port this bomb to Windows and put a * fantastic GUI on it. */ /* When run with no arguments, the bomb reads its input lines * from standard input. */ if (argc == 1) { infile = stdin; } /* When run with one argument <file>, the bomb reads from <file> * until EOF, and then switches to standard input. Thus, as you * defuse each phase, you can add its defusing string to <file> and * avoid having to retype it. */ else if (argc == 2) { if (!(infile = fopen(argv[1], "r"))) { printf("%s: Error: Couldn't open %s\n", argv[0], argv[1]); exit(8); } } /* You can't call the bomb with more than 1 command line argument. */ else { printf("Usage: %s [<input_file>]\n", argv[0]); exit(8); } /* Do all sorts of secret stuff that makes the bomb harder to defuse. */ initialize_bomb(); printf("Welcome to my fiendish little bomb. You have 6 phases with\n"); printf("which to blow yourself up. Have a nice day!\n"); /* Hmm... Six phases must be more secure than one phase! */ input = read_line(); /* Get input */ phase_1(input); /* Run the phase */ phase_defused(); /* Drat! They figured it out! * Let me know how they did it. */ printf("Phase 1 defused. How about the next one?\n"); /* The second phase is harder. No one will ever figure out * how to defuse this... */ input = read_line(); phase_2(input); phase_defused(); printf("That's number 2. Keep going!\n"); /* I guess this is too easy so far. Some more complex code will * confuse people. */ input = read_line(); phase_3(input); phase_defused(); printf("Halfway there!\n"); /* Oh yeah? Well, how good is your math? Try on this saucy problem! */ input = read_line(); phase_4(input); phase_defused(); printf("So you got that one. Try this one.\n"); /* Round and 'round in memory we go, where we stop, the bomb blows! */ input = read_line(); phase_5(input); phase_defused(); printf("Good work! On to the next...\n"); /* This phase will never be used, since no one will get past the * earlier ones. But just in case, make this one extra hard. */ input = read_line(); phase_6(input); phase_defused(); /* Wow, they got it! But isn't something... missing? Perhaps * something they overlooked? Mua ha ha ha ha! */ return 0; }
$ r2 -A bomb -- In soviet Afghanistan, you debug radare2! [0x00400c90]> afl~phase 0x00400ee0 28 3 sym.phase_1 0x004015c4 149 8 sym.phase_defused 0x00400efc 71 8 sym.phase_2 0x00400f43 139 8 sym.phase_3 0x0040100c 86 7 sym.phase_4 0x00401062 146 9 sym.phase_5 0x004010f4 272 26 sym.phase_6 0x00401242 81 5 sym.secret_phase
[0x00400c90]> s 0x00400ee0 # 's' - [0x00400ee0]> pd 8 # 8
0000000000400ee0 <phase_1>: 400ee0: 48 83 ec 08 sub rsp,0x8 400ee4: be 00 24 40 00 mov esi,0x402400 400ee9: e8 4a 04 00 00 call 401338 <strings_not_equal> 400eee: 85 c0 test eax,eax 400ef0: 74 05 je 400ef7 <phase_1+0x17> 400ef2: e8 43 05 00 00 call 40143a <explode_bomb> 400ef7: 48 83 c4 08 add rsp,0x8 400efb: c3 ret retq
$ ./bomb Welcome to my fiendish little bomb. You have 6 phases with which to blow yourself up. Have a nice day! Border relations with Canada have never been better. Phase 1 defused. How about the next one?
[0x00400ee0]> pdf @ 0x00400efc
[0x00400ee0]> pdf @ sym.phase_2
[0x00400ee0]> s 0x0040149e # [0x0040149e]> af+ sym.read_six_numbers `?vi $$-sym.read_six_numbers` rsn # rsn, sym.read_six_numbers .
void read_six_numbers(char *str, long long *p) { if (sscanf(str, "%d %d %d %d %d %d", p, p+1, p+2, p+3, p+4, p+5) <= 5) explode_bomb(); }
mov eax, dword [rbx - 4] ; eax add eax, eax ; cmp dword [rbx], eax ; je 0x400f25 ; , call sym.explode_bomb ; , add rbx, 4 ; cmp rbx, rbp ; , jne 0x400f17 ; , jmp 0x400f3c ;
$ ./bomb ... Phase 1 defused. How about the next one? 1 2 4 8 16 32 That's number 2. Keep going!
[0x0040149e]> pxQ 72 @ 0x402470 0x00402470 0x0000000000400f7c sym.phase_3+57 0x00402478 0x0000000000400fb9 sym.phase_3+118 0x00402480 0x0000000000400f83 sym.phase_3+64 0x00402488 0x0000000000400f8a sym.phase_3+71 0x00402490 0x0000000000400f91 sym.phase_3+78 0x00402498 0x0000000000400f98 sym.phase_3+85 0x004024a0 0x0000000000400f9f sym.phase_3+92 0x004024a8 0x0000000000400fa6 sym.phase_3+99
[0x0040149e]> !rax2 0xcf 207 [0x0040149e]> ?vi 0x2c3; ?vi 0x100; ?vi 0x185; ?vi 0xce; ?vi 0x2aa; ?vi 0x147; ?vi 0x137 707 256 389 206 682 327 311
$ ./bomb ... That's number 2. Keep going! 4 389 Halfway there!
[0x0040149e]> ag sym.func4 > func4.dot [0x0040149e]> dot -Tpng -o func4.png func4.dot
void phase_4(char *str) { int x, y; if (sscanf(str, "%d %d", &x, &y) != 2 || x > 14 || func4(x, 0, 14) || y != 0) explode_bomb(); } int func4(int x, int y, int z) { unsigned diff = (z - y)/2; int p = y + diff; if (p > x) { func4(x, y, p-1); return diff * 2; } else if (p < x) { func4(x, p + 1, z); return diff * 2 + 1; } return 0; }
$ ./bomb in.tmp ... Halfway there! 7 0 So you got that one. Try this one.
$ r2 -Ad bomb
[0x0040149e]> ood
[0x7f2960b99d80]> db sym.phase_5 # s sym.phase_5; db $$ [0x7f2960b99d80]> dc # 1
char *s = "maduiersnfotvbyl"
and the resulting string is compared to "flyers". $ rax2 -s 49 4e 4f 45 46 47 INOEFG
$ ./bomb ... So you got that one. Try this one. INOEFG Good work! On to the next...
$ r2 -Aw bomb -- Did you ever ordered a pizza using radare2? [0x00400c90]> s 0x00400ec6 # call sym.phase_6 [0x00400ec6]> wa call sym.secret_phase # [0x00400ec6]> pdf @ sym.secret_phase; pdf @ sym.fun7
void secret_phase() { long num = strtol(read_line()) - 1; if (num > 0x3e8 || fun7((long*)(0x6030f0), num) != 2) explode_bomb(); puts("Wow! You've defused the secret stage!"); phase_defused(); } int fun7(long *array, int num) { if (array == 0) return -1; if (*array <= num) { if (*array == num) return 0; // 1 else { return 2 * fun7(array + 1, num); // 2 } } else { return 2 * fun7(array + 2, num) + 1; // 3 } }
[0x00401204]> px 480 @ 0x6030f0 - offset - 0 1 2 3 4 5 6 7 8 9 ABCDEF 0123456789ABCDEF 0x006030f0 2400 0000 0000 0000 1031 6000 0000 0000 $........1`..... 0x00603100 3031 6000 0000 0000 0000 0000 0000 0000 01`............. 0x00603110 0800 0000 0000 0000 9031 6000 0000 0000 .........1`..... 0x00603120 5031 6000 0000 0000 0000 0000 0000 0000 P1`............. 0x00603130 3200 0000 0000 0000 7031 6000 0000 0000 2.......p1`..... 0x00603140 b031 6000 0000 0000 0000 0000 0000 0000 .1`............. 0x00603150 1600 0000 0000 0000 7032 6000 0000 0000 ........p2`..... 0x00603160 3032 6000 0000 0000 0000 0000 0000 0000 02`............. 0x00603170 2d00 0000 0000 0000 d031 6000 0000 0000 -........1`..... 0x00603180 9032 6000 0000 0000 0000 0000 0000 0000 .2`............. 0x00603190 0600 0000 0000 0000 f031 6000 0000 0000 .........1`..... 0x006031a0 5032 6000 0000 0000 0000 0000 0000 0000 P2`............. 0x006031b0 6b00 0000 0000 0000 1032 6000 0000 0000 k........2`..... 0x006031c0 b032 6000 0000 0000 0000 0000 0000 0000 .2`............. 0x006031d0 2800 0000 0000 0000 0000 0000 0000 0000 (............... 0x006031e0 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x006031f0 0100 0000 0000 0000 0000 0000 0000 0000 ................ 0x00603200 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00603210 6300 0000 0000 0000 0000 0000 0000 0000 c............... 0x00603220 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00603230 2300 0000 0000 0000 0000 0000 0000 0000 #............... 0x00603240 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00603250 0700 0000 0000 0000 0000 0000 0000 0000 ................ 0x00603260 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00603270 1400 0000 0000 0000 0000 0000 0000 0000 ................ 0x00603280 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x00603290 2f00 0000 0000 0000 0000 0000 0000 0000 /............... 0x006032a0 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x006032b0 e903 0000 0000 0000 0000 0000 0000 0000 ................ 0x006032c0 0000 0000 0000 0000 0000 0000 0000 0000 ................
$ ./bombSec in.tmp ... Good work! On to the next... 22 Wow! You've defused the secret stage! Congratulations! You've defused the bomb!
Source: https://habr.com/ru/post/274617/
All Articles