{"id":213,"date":"2011-12-02T17:23:00","date_gmt":"2011-12-02T16:23:00","guid":{"rendered":"http:\/\/blog.pi3.com.pl\/?p=213"},"modified":"2012-02-26T02:19:34","modified_gmt":"2012-02-26T01:19:34","slug":"can-you-crack-it-interesting-challenge","status":"publish","type":"post","link":"https:\/\/blog.pi3.com.pl\/?p=213","title":{"rendered":"Can you crack it &#8211; interesting challenge :)"},"content":{"rendered":"<p style=\"text-align: center;\"><a href=\"http:\/\/blog.pi3.com.pl\/?attachment_id=235\" rel=\"attachment wp-att-235\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-235\" title=\"Main page\" src=\"http:\/\/blog.pi3.com.pl\/wp-content\/uploads\/2011\/12\/codecrack_616-300x178.jpg\" alt=\"\" width=\"400\" height=\"278\" \/><\/a><\/p>\n<p>Yesterday I read in one of the polish portal (with news) an\u00a0 information about interesting challenge organized by the <a href=\"http:\/\/www.gchq.gov.uk\/\" target=\"_blank\"><strong>Government Communications Headquarters<\/strong> (<strong>GCHQ<\/strong>)<\/a>. This\u00a0is a British intelligence agency responsible for providing signals intelligence (SIGINT) and information assurance to the UK government and armed forces. Based in Cheltenham, it operates under the guidance of the Joint Intelligence Committee. CESG (originally Communications-Electronics Security Group) is the branch of GCHQ which works to secure the communications and information systems of the government and critical parts of UK national infrastructure.<\/p>\n<p>GCHQ, is aiming to attract the next generation of web-savvy spies by running an ad campaign that challenges computer hackers to crack a code to get an interview.<\/p>\n<p>Ok so let&#8217;s look at it closer \ud83d\ude42<\/p>\n<p>&nbsp;<\/p>\n<h2>First level<\/h2>\n<p>I will not analyze the security of webpage and server. I will try to discuss about pure challenge. OK so first question is what does this hexcode means? Let&#8217;s look it closer:<\/p>\n<pre><span style=\"color: #ff0000;\">0xeb 0x04<\/span> 0xaf 0xc2 0xbf 0xa3 0x81 0xec\u00a0\u00a0 0x00 0x01 0x00 0x00 0x31 0xc9 0x88 0x0c\r\n0x0c 0xfe <span style=\"color: #ff0000;\">0xc1 0x75<\/span> 0xf9 0x31 0xc0 0xba\u00a0\u00a0 <span style=\"color: #00ffff;\">0xef 0xbe 0xad 0xde<\/span> 0x02 0x04 0x0c 0x00\r\n0xd0 0xc1 0xca 0x08 0x8a 0x1c 0x0c 0x8a\u00a0\u00a0 0x3c 0x04 0x88 0x1c 0x04 0x88 0x3c 0x0c\r\n0xfe <span style=\"color: #ff0000;\">0xc1 0x75<\/span> 0xe8 0xe9 0x5c 0x00 0x00\u00a0\u00a0 0x00 0x89 0xe3 0x81 0xc3 0x04 0x00 0x00\r\n0x00 0x5c 0x58 0x3d <span style=\"color: #00ffff;\">0x41 0x41 0x41 0x41<\/span>\u00a0\u00a0 0x75 0x43 0x58 0x3d <span style=\"color: #00ffff;\">0x42 0x42 0x42 0x42<\/span>\r\n0x75 0x3b 0x5a 0x89 0xd1 0x89 0xe6 0x89\u00a0\u00a0 0xdf 0x29 0xcf 0xf3 0xa4 0x89 0xde 0x89\r\n0xd1 0x89 0xdf 0x29 0xcf 0x31 0xc0 0x31\u00a0\u00a0 0xdb 0x31 0xd2 0xfe 0xc0 0x02 0x1c 0x06\r\n0x8a 0x14 0x06 0x8a 0x34 0x1e 0x88 0x34\u00a0\u00a0 0x06 0x88 0x14 0x1e 0x00 0xf2 0x30 0xf6\r\n0x8a 0x1c 0x16 0x8a 0x17 0x30 0xda 0x88\u00a0\u00a0 0x17 0x47 0x49 0x75 0xde 0x31 0xdb 0x89\r\n0xd8 0xfe 0xc0 <span style=\"color: #ff0000;\">0xcd 0x80<\/span> <span style=\"color: #ff0000;\">0x90 0x90<\/span> 0xe8\u00a0\u00a0 0x9d 0xff 0xff 0xff <span style=\"color: #00ffff;\">0x41 0x41 0x41 0x41<\/span><\/pre>\n<p>For the first quick view we can say there is some interesting bytes. With red color I sign this bytes which can be a dump of x86 assembler instructions (of course there is more but this can be typical for shellcodes) and with the blue color I sign interesting bytes for me \ud83d\ude42 &#8211; 0x41414141 and 0x424242 for me always will be connected with exploiting \ud83d\ude09<\/p>\n<p>OK so let&#8217;s try to analyze this bytes as x86 instructions:<\/p>\n<pre>\u00a0\u00a0 0x0804a040 &lt;+0&gt;:\u00a0\u00a0 \u00a0jmp\u00a0\u00a0\u00a0 0x804a046 &lt;shellcode+6&gt;\r\n\u00a0\u00a0 0x0804a042 &lt;+2&gt;:\u00a0\u00a0 \u00a0scas\u00a0\u00a0 %es:(%edi),%eax\r\n\u00a0\u00a0 0x0804a043 &lt;+3&gt;:\u00a0\u00a0 \u00a0ret\u00a0\u00a0\u00a0 $0xa3bf\r\n\u00a0\u00a0 0x0804a046 &lt;+6&gt;:\u00a0\u00a0 \u00a0sub\u00a0\u00a0\u00a0 $0x100,%esp\r\n\u00a0\u00a0 0x0804a04c &lt;+12&gt;:\u00a0\u00a0 \u00a0xor\u00a0\u00a0\u00a0 %ecx,%ecx\r\n\u00a0\u00a0 0x0804a04e &lt;+14&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 %cl,(%esp,%ecx,1)\r\n\u00a0\u00a0 0x0804a051 &lt;+17&gt;:\u00a0\u00a0 \u00a0inc\u00a0\u00a0\u00a0 %cl\r\n\u00a0\u00a0 0x0804a053 &lt;+19&gt;:\u00a0\u00a0 \u00a0jne\u00a0\u00a0\u00a0 0x804a04e &lt;shellcode+14&gt;\r\n\u00a0\u00a0 0x0804a055 &lt;+21&gt;:\u00a0\u00a0 \u00a0xor\u00a0\u00a0\u00a0 %eax,%eax\r\n\u00a0\u00a0 0x0804a057 &lt;+23&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 $0xdeadbeef,%edx\r\n\u00a0\u00a0 0x0804a05c &lt;+28&gt;:\u00a0\u00a0 \u00a0add\u00a0\u00a0\u00a0 (%esp,%ecx,1),%al\r\n\u00a0\u00a0 0x0804a05f &lt;+31&gt;:\u00a0\u00a0 \u00a0add\u00a0\u00a0\u00a0 %dl,%al\r\n\u00a0\u00a0 0x0804a061 &lt;+33&gt;:\u00a0\u00a0 \u00a0ror\u00a0\u00a0\u00a0 $0x8,%edx\r\n\u00a0\u00a0 0x0804a064 &lt;+36&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 (%esp,%ecx,1),%bl\r\n\u00a0\u00a0 0x0804a067 &lt;+39&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 (%esp,%eax,1),%bh\r\n\u00a0\u00a0 0x0804a06a &lt;+42&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 %bl,(%esp,%eax,1)\r\n\u00a0\u00a0 0x0804a06d &lt;+45&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 %bh,(%esp,%ecx,1)\r\n\u00a0\u00a0 0x0804a070 &lt;+48&gt;:\u00a0\u00a0 \u00a0inc\u00a0\u00a0\u00a0 %cl\r\n\u00a0\u00a0 0x0804a072 &lt;+50&gt;:\u00a0\u00a0 \u00a0jne\u00a0\u00a0\u00a0 0x804a05c &lt;shellcode+28&gt;\r\n<span style=\"color: #ff0000;\">\u00a0\u00a0 0x0804a074 &lt;+52&gt;:\u00a0\u00a0 \u00a0jmp\u00a0\u00a0\u00a0 0x804a0d5 &lt;shellcode+149&gt;<\/span>\r\n\u00a0\u00a0 0x0804a079 &lt;+57&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 %esp,%ebx\r\n\u00a0\u00a0 0x0804a07b &lt;+59&gt;:\u00a0\u00a0 \u00a0add\u00a0\u00a0\u00a0 $0x4,%ebx\r\n\u00a0\u00a0 0x0804a081 &lt;+65&gt;:\u00a0\u00a0 \u00a0pop\u00a0\u00a0\u00a0 %esp\r\n\u00a0\u00a0 0x0804a082 &lt;+66&gt;:\u00a0\u00a0 \u00a0pop\u00a0\u00a0\u00a0 %eax\r\n<span style=\"color: #00ffff;\">\u00a0\u00a0 0x0804a083 &lt;+67&gt;:\u00a0\u00a0 \u00a0cmp\u00a0\u00a0\u00a0 $0x41414141,%eax<\/span>\r\n<span style=\"color: #00ffff;\">\u00a0\u00a0 0x0804a088 &lt;+72&gt;:\u00a0\u00a0 \u00a0jne\u00a0\u00a0\u00a0 0x804a0cd &lt;shellcode+141&gt;<\/span>\r\n<span style=\"color: #00ffff;\">\u00a0\u00a0 0x0804a08a &lt;+74&gt;:\u00a0\u00a0 \u00a0dec\u00a0\u00a0\u00a0 %eax<\/span>\r\n<span style=\"color: #00ffff;\">\u00a0\u00a0 0x0804a08b &lt;+75&gt;:\u00a0\u00a0 \u00a0cmp\u00a0\u00a0\u00a0 $0x42424242,%eax<\/span>\r\n<span style=\"color: #00ffff;\">\u00a0\u00a0 0x0804a090 &lt;+80&gt;:\u00a0\u00a0 \u00a0jne\u00a0\u00a0\u00a0 0x804a0cd &lt;shellcode+141&gt;<\/span>\r\n\u00a0\u00a0 0x0804a092 &lt;+82&gt;:\u00a0\u00a0 \u00a0pop\u00a0\u00a0\u00a0 %edx\r\n\u00a0\u00a0 0x0804a093 &lt;+83&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 %edx,%ecx\r\n\u00a0\u00a0 0x0804a095 &lt;+85&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 %esp,%esi\r\n\u00a0\u00a0 0x0804a097 &lt;+87&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 %ebx,%edi\r\n\u00a0\u00a0 0x0804a099 &lt;+89&gt;:\u00a0\u00a0 \u00a0sub\u00a0\u00a0\u00a0 %ecx,%edi\r\n\u00a0\u00a0 0x0804a09b &lt;+91&gt;:\u00a0\u00a0 \u00a0rep movsb %ds:(%esi),%es:(%edi)\r\n\u00a0\u00a0 0x0804a09d &lt;+93&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 %ebx,%esi\r\n\u00a0\u00a0 0x0804a09f &lt;+95&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 %edx,%ecx\r\n\u00a0\u00a0 0x0804a0a1 &lt;+97&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 %ebx,%edi\r\n\u00a0\u00a0 0x0804a0a3 &lt;+99&gt;:\u00a0\u00a0 \u00a0sub\u00a0\u00a0\u00a0 %ecx,%edi\r\n\u00a0\u00a0 0x0804a0a5 &lt;+101&gt;:\u00a0\u00a0 \u00a0xor\u00a0\u00a0\u00a0 %eax,%eax\r\n\u00a0\u00a0 0x0804a0a7 &lt;+103&gt;:\u00a0\u00a0 \u00a0xor\u00a0\u00a0\u00a0 %ebx,%ebx\r\n\u00a0\u00a0 0x0804a0a9 &lt;+105&gt;:\u00a0\u00a0 \u00a0xor\u00a0\u00a0\u00a0 %edx,%edx\r\n\u00a0\u00a0 0x0804a0ab &lt;+107&gt;:\u00a0\u00a0 \u00a0inc\u00a0\u00a0\u00a0 %al\r\n\u00a0\u00a0 0x0804a0ad &lt;+109&gt;:\u00a0\u00a0 \u00a0add\u00a0\u00a0\u00a0 (%esi,%eax,1),%bl\r\n\u00a0\u00a0 0x0804a0b0 &lt;+112&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 (%esi,%eax,1),%dl\r\n\u00a0\u00a0 0x0804a0b3 &lt;+115&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 (%esi,%ebx,1),%dh\r\n\u00a0\u00a0 0x0804a0b6 &lt;+118&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 %dh,(%esi,%eax,1)\r\n\u00a0\u00a0 0x0804a0b9 &lt;+121&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 %dl,(%esi,%ebx,1)\r\n\u00a0\u00a0 0x0804a0bc &lt;+124&gt;:\u00a0\u00a0 \u00a0add\u00a0\u00a0\u00a0 %dh,%dl\r\n\u00a0\u00a0 0x0804a0be &lt;+126&gt;:\u00a0\u00a0 \u00a0xor\u00a0\u00a0\u00a0 %dh,%dh\r\n\u00a0\u00a0 0x0804a0c0 &lt;+128&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 (%esi,%edx,1),%bl\r\n\u00a0\u00a0 0x0804a0c3 &lt;+131&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 (%edi),%dl\r\n\u00a0\u00a0 0x0804a0c5 &lt;+133&gt;:\u00a0\u00a0 \u00a0xor\u00a0\u00a0\u00a0 %bl,%dl\r\n\u00a0\u00a0 0x0804a0c7 &lt;+135&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 %dl,(%edi)\r\n\u00a0\u00a0 0x0804a0c9 &lt;+137&gt;:\u00a0\u00a0 \u00a0inc\u00a0\u00a0\u00a0 %edi\r\n\u00a0\u00a0 0x0804a0ca &lt;+138&gt;:\u00a0\u00a0 \u00a0dec\u00a0\u00a0\u00a0 %ecx\r\n\u00a0\u00a0 0x0804a0cb &lt;+139&gt;:\u00a0\u00a0 \u00a0jne\u00a0\u00a0\u00a0 0x804a0ab &lt;shellcode+107&gt;\r\n\u00a0\u00a0 0x0804a0cd &lt;+141&gt;:\u00a0\u00a0 \u00a0xor\u00a0\u00a0\u00a0 %ebx,%ebx\r\n\u00a0\u00a0 0x0804a0cf &lt;+143&gt;:\u00a0\u00a0 \u00a0mov\u00a0\u00a0\u00a0 %ebx,%eax\r\n\u00a0\u00a0 0x0804a0d1 &lt;+145&gt;:\u00a0\u00a0 \u00a0inc\u00a0\u00a0\u00a0 %al\r\n\u00a0\u00a0 0x0804a0d3 &lt;+147&gt;:\u00a0\u00a0 \u00a0int\u00a0\u00a0\u00a0 $0x80\r\n<span style=\"color: #ff0000;\">\u00a0\u00a0 0x0804a0d5 &lt;+149&gt;:\u00a0\u00a0 \u00a0nop<\/span>\r\n<span style=\"color: #ff0000;\">\u00a0\u00a0 0x0804a0d6 &lt;+150&gt;:\u00a0\u00a0 \u00a0nop<\/span>\r\n<span style=\"color: #ff0000;\">\u00a0\u00a0 0x0804a0d7 &lt;+151&gt;:\u00a0\u00a0 \u00a0call\u00a0\u00a0 0x804a079 &lt;shellcode+57&gt;<\/span>\r\n\u00a0\u00a0 0x0804a0dc &lt;+156&gt;:\u00a0\u00a0 \u00a0inc\u00a0\u00a0\u00a0 %ecx\r\n\u00a0\u00a0 0x0804a0dd &lt;+157&gt;:\u00a0\u00a0 \u00a0inc\u00a0\u00a0\u00a0 %ecx\r\n\u00a0\u00a0 0x0804a0de &lt;+158&gt;:\u00a0\u00a0 \u00a0inc\u00a0\u00a0\u00a0 %ecx\r\n\u00a0\u00a0 0x0804a0df &lt;+159&gt;:\u00a0\u00a0 \u00a0inc\u00a0\u00a0\u00a0 %ecx\r\n\u00a0\u00a0 0x0804a0e0 &lt;+160&gt;:\u00a0\u00a0 \u00a0add\u00a0\u00a0\u00a0 %al,(%eax)<\/pre>\n<p>So this is it. This code make sense and this was good way of analyzing. I sign by read color this instruction which always cause exit() syscall and half of the code won&#8217;t be executed (as we will see further even more). But first, at the beginning this code jump over 2 next instruction (so they are never executed) and than allocate memory which is filled by natural numbers. Next they are converted to some more interested values and finally there is static jump to the code which cause syscall exit() &#8211; red colour. That&#8217;s all, so what next? As we can see directly after jump instruction, the program tries to get the new value for the stack pointer exactly from the stack. It gaves us an information that smth should be changed there \ud83d\ude09 Also as we can see further (blue colour) from the stack is popped also value for %%eax register and compared with the 0x41414141 value. Next this value is decremented by one and again compared but now with the 0x42424242 value. Logically it makes no sense. If first compare will be true than next will be bad &#8211; 0x41414141 &#8211; 1 = 0x41414140 so it will never be 0x42424242. If we want to pass all this checks and executed further code we must change a lot \ud83d\ude09<\/p>\n<h3>First change<\/h3>\n<p>Ok let&#8217;s come back to the syscall exit(). We don&#8217;t want to stop the execution flow but continue, and we know that further code expect the new stack pointer in the stack. Also we know that after this operation program tries to get new value for %%eax register from the new stack and compare with the value 0x414141. As we can see in the end of the shellcode we have instructions:<\/p>\n<pre>\u00a0\u00a0 0x0804a0dc &lt;+156&gt;:\u00a0\u00a0 \u00a0inc\u00a0\u00a0\u00a0 %ecx\r\n\u00a0\u00a0 0x0804a0dd &lt;+157&gt;:\u00a0\u00a0 \u00a0inc\u00a0\u00a0\u00a0 %ecx\r\n\u00a0\u00a0 0x0804a0de &lt;+158&gt;:\u00a0\u00a0 \u00a0inc\u00a0\u00a0\u00a0 %ecx\r\n\u00a0\u00a0 0x0804a0df &lt;+159&gt;:\u00a0\u00a0 \u00a0inc\u00a0\u00a0\u00a0 %ecx<\/pre>\n<p>this is exactly the value 0x414141:<\/p>\n<pre>(gdb) x\/x 0x0804a0dc\r\n0x804a0dc &lt;shellcode+156&gt;:\u00a0\u00a0 \u00a00x41414141\r\n(gdb)<\/pre>\n<p>so here we go with answer \ud83d\ude09 Like in the oldschool technique of getting current stack pointer used in viruses &#8211; let&#8217;s change syscall exit() to the call which gave us back the flow to the shellcode. Old code:<\/p>\n<pre>\u00a0\u00a0 0x0804a0d5 &lt;+149&gt;:\u00a0\u00a0 \u00a0nop\r\n\u00a0\u00a0 0x0804a0d6 &lt;+150&gt;:\u00a0\u00a0 \u00a0nop\r\n\u00a0\u00a0 0x0804a0d7 &lt;+151&gt;:\u00a0\u00a0 \u00a0call\u00a0\u00a0 0x804a079 &lt;shellcode+57&gt; # value: 0x80cd<\/pre>\n<p>New code:<\/p>\n<pre>\u00a0\u00a0 0x804c095:\u00a0\u00a0 \u00a0nop\r\n\u00a0\u00a0 0x804c096:\u00a0\u00a0 \u00a0nop\r\n\u00a0\u00a0 0x804c097:\u00a0\u00a0 \u00a0call\u00a0\u00a0 0x804c039 # value: 0x45eb<\/pre>\n<p>OK &#8211; works. First compare is passed but of course second is not and again game over. But If we think again about it, decrementing instruction can be also overwrite to ours and as we know the new stack pointer is now _after_ the shellcode. We are able to add new bytes after this shellcode and change the assembler instruction which decrements value in register %%eax to pop new value from the stack \ud83d\ude42 This is in fact the answer \ud83d\ude09<\/p>\n<h3>Second change<\/h3>\n<p>Old instruction:<\/p>\n<pre>\u00a0\u00a0 0x0804a08a &lt;+74&gt;:\u00a0\u00a0 \u00a0dec\u00a0\u00a0\u00a0 %eax\u00a0 # byte: 0x48<\/pre>\n<p>New instruction:<\/p>\n<pre>\u00a0\u00a0 0x804c04a:\u00a0\u00a0 \u00a0pop\u00a0\u00a0\u00a0 %eax\u00a0 # byte: 0x58<\/pre>\n<p>Perfect. Now we have another problem &#8211; which data should be added in the end of shellcode? We can manually add 0x42424242 value to pass the compare check but what about further code? Maybe this 0x42424242\u00a0 is a tip? In further code the value for %%edx register is also popped from the stack. And next bytes are used to copy in temporary place and manipulate them. So of course all of this is a tip. Lets come back again to the main page of the crack site. Bytes which we used to create shellcode are not in the site as text but as image. We were frustrating to rewrite them manually not just simply copying. But wait a minute why this is an image?<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/blog.pi3.com.pl\/?attachment_id=240\" rel=\"attachment wp-att-240\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-240\" title=\"Main Image\" src=\"http:\/\/blog.pi3.com.pl\/wp-content\/uploads\/2011\/12\/cyber.png\" alt=\"\" width=\"666\" height=\"234\" srcset=\"https:\/\/blog.pi3.com.pl\/wp-content\/uploads\/2011\/12\/cyber.png 740w, https:\/\/blog.pi3.com.pl\/wp-content\/uploads\/2011\/12\/cyber-300x105.png 300w\" sizes=\"auto, (max-width: 666px) 100vw, 666px\" \/><\/a><\/p>\n<h3>Steganography<\/h3>\n<p>Analyzing image can be hard \ud83d\ude09 But I&#8217;m lazy buster and usually before I move to real hard job like analyze or full RE I try to get as much information as I can in as simple way as it can be. So let&#8217;s run strings command \ud83d\ude09 There is 983 lines (not small image) but one line from the top is very interesting:<\/p>\n<pre>$ strings cyber.png |head\r\nIHDR\r\nsRGB\r\n\u00a0\u00a0 \u00a0pHYs\r\ntIME\r\n]iTXtComment\r\n<span style=\"color: #ff0000;\">QkJCQjIAAACR2PFtcCA6q2eaC8SR+8dmD\/zNzLQC+td3tFQ4qx8O447TDeuZw5P+0SsbEcYR<\/span>\r\n<span style=\"color: #ff0000;\">78jKLw==2<\/span>\r\nIDATx\r\n.^cwuW\r\n$<\/pre>\n<p>Here you go \ud83d\ude09 First impression is &#8211; this is base64. Let&#8217;s check in one of the online sites if there is logic in this string. After decoding to the ASCII we see that hexdump should be done _but_ look for the first 4 bytes in this string:<\/p>\n<pre><span style=\"color: #ff0000;\">BBBB<\/span>2\u2205\u2205\u2205\u00d8\u00f1mp :\u00abg\u00c4\u00fb\u00c7f\u00fc\u00cd\u00cc\u00b4\u00fa\u00d7w\u00b4T8\r\n\u00eb\u00c3\u00fe\u00d1+\u00c6\u00ef\u00c8\u00ca\/?\u00ff\u00d8\u2205\u2205<\/pre>\n<p>Yes, this is exactly 0x42424242 value.\u00a0 So probably this is what we need \ud83d\ude09 After adding this hex in the end of the shellcode and all of our changes and adding the code for dumping the memory after whole process of executing shellcode (this dump function write by yourself) we will see this beautiful message from the memory:<\/p>\n<pre>GET \/15b436de1f9107f3778aad525e5d0b20.js HTTP\/1.1<\/pre>\n<p>Interesting, isn&#8217;t it? \ud83d\ude42 Yep the first level is done.<\/p>\n<p>&nbsp;<\/p>\n<h2>Second level<\/h2>\n<p>What does this link have?<\/p>\n<pre>\/\/--------------------------------------------------------------------------------------------------\r\n\/\/\r\n\/\/ stage 2 of 3\r\n\/\/\r\n\/\/ challenge:\r\n\/\/   reveal the solution within VM.mem\r\n\/\/\r\n\/\/ disclaimer:\r\n\/\/   tested in ie 9, firefox 6, chrome 14 and v8 shell (http:\/\/code.google.com\/apis\/v8\/build.html),\r\n\/\/   other javascript implementations may or may not work.\r\n\/\/\r\n\/\/--------------------------------------------------------------------------------------------------\r\n\r\nvar VM = {\r\n\r\n  cpu: {\r\n    ip: 0x00,\r\n\r\n    r0: 0x00,\r\n    r1: 0x00,\r\n    r2: 0x00,\r\n    r3: 0x00,\r\n\r\n    cs: 0x00,\r\n    ds: 0x10,\r\n\r\n    fl: 0x00,\r\n\r\n    firmware: [0xd2ab1f05, 0xda13f110]\r\n  },\r\n\r\n  mem: [\r\n    0x31, 0x04, 0x33, 0xaa, 0x40, 0x02, 0x80, 0x03, 0x52, 0x00, 0x72, 0x01, 0x73, 0x01, 0xb2, 0x50,\r\n    0x30, 0x14, 0xc0, 0x01, 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n\r\n    0x98, 0xab, 0xd9, 0xa1, 0x9f, 0xa7, 0x83, 0x83, 0xf2, 0xb1, 0x34, 0xb6, 0xe4, 0xb7, 0xca, 0xb8,\r\n    0xc9, 0xb8, 0x0e, 0xbd, 0x7d, 0x0f, 0xc0, 0xf1, 0xd9, 0x03, 0xc5, 0x3a, 0xc6, 0xc7, 0xc8, 0xc9,\r\n    0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,\r\n    0xda, 0xdb, 0xa9, 0xcd, 0xdf, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,\r\n    0x26, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9,\r\n    0x7d, 0x1f, 0x15, 0x60, 0x4d, 0x4d, 0x52, 0x7d, 0x0e, 0x27, 0x6d, 0x10, 0x6d, 0x5a, 0x06, 0x56,\r\n    0x47, 0x14, 0x42, 0x0e, 0xb6, 0xb2, 0xb2, 0xe6, 0xeb, 0xb4, 0x83, 0x8e, 0xd7, 0xe5, 0xd4, 0xd9,\r\n    0xc3, 0xf0, 0x80, 0x95, 0xf1, 0x82, 0x82, 0x9a, 0xbd, 0x95, 0xa4, 0x8d, 0x9a, 0x2b, 0x30, 0x69,\r\n    0x4a, 0x69, 0x65, 0x55, 0x1c, 0x7b, 0x69, 0x1c, 0x6e, 0x04, 0x74, 0x35, 0x21, 0x26, 0x2f, 0x60,\r\n    0x03, 0x4e, 0x37, 0x1e, 0x33, 0x54, 0x39, 0xe6, 0xba, 0xb4, 0xa2, 0xad, 0xa4, 0xc5, 0x95, 0xc8,\r\n    0xc1, 0xe4, 0x8a, 0xec, 0xe7, 0x92, 0x8b, 0xe8, 0x81, 0xf0, 0xad, 0x98, 0xa4, 0xd0, 0xc0, 0x8d,\r\n    0xac, 0x22, 0x52, 0x65, 0x7e, 0x27, 0x2b, 0x5a, 0x12, 0x61, 0x0a, 0x01, 0x7a, 0x6b, 0x1d, 0x67,\r\n    0x75, 0x70, 0x6c, 0x1b, 0x11, 0x25, 0x25, 0x70, 0x7f, 0x7e, 0x67, 0x63, 0x30, 0x3c, 0x6d, 0x6a,\r\n    0x01, 0x51, 0x59, 0x5f, 0x56, 0x13, 0x10, 0x43, 0x19, 0x18, 0xe5, 0xe0, 0xbe, 0xbf, 0xbd, 0xe9,\r\n    0xf0, 0xf1, 0xf9, 0xfa, 0xab, 0x8f, 0xc1, 0xdf, 0xcf, 0x8d, 0xf8, 0xe7, 0xe2, 0xe9, 0x93, 0x8e,\r\n    0xec, 0xf5, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n\r\n    0x37, 0x7a, 0x07, 0x11, 0x1f, 0x1d, 0x68, 0x25, 0x32, 0x77, 0x1e, 0x62, 0x23, 0x5b, 0x47, 0x55,\r\n    0x53, 0x30, 0x11, 0x42, 0xf6, 0xf1, 0xb1, 0xe6, 0xc3, 0xcc, 0xf8, 0xc5, 0xe4, 0xcc, 0xc0, 0xd3,\r\n    0x85, 0xfd, 0x9a, 0xe3, 0xe6, 0x81, 0xb5, 0xbb, 0xd7, 0xcd, 0x87, 0xa3, 0xd3, 0x6b, 0x36, 0x6f,\r\n    0x6f, 0x66, 0x55, 0x30, 0x16, 0x45, 0x5e, 0x09, 0x74, 0x5c, 0x3f, 0x29, 0x2b, 0x66, 0x3d, 0x0d,\r\n    0x02, 0x30, 0x28, 0x35, 0x15, 0x09, 0x15, 0xdd, 0xec, 0xb8, 0xe2, 0xfb, 0xd8, 0xcb, 0xd8, 0xd1,\r\n    0x8b, 0xd5, 0x82, 0xd9, 0x9a, 0xf1, 0x92, 0xab, 0xe8, 0xa6, 0xd6, 0xd0, 0x8c, 0xaa, 0xd2, 0x94,\r\n    0xcf, 0x45, 0x46, 0x67, 0x20, 0x7d, 0x44, 0x14, 0x6b, 0x45, 0x6d, 0x54, 0x03, 0x17, 0x60, 0x62,\r\n    0x55, 0x5a, 0x4a, 0x66, 0x61, 0x11, 0x57, 0x68, 0x75, 0x05, 0x62, 0x36, 0x7d, 0x02, 0x10, 0x4b,\r\n    0x08, 0x22, 0x42, 0x32, 0xba, 0xe2, 0xb9, 0xe2, 0xd6, 0xb9, 0xff, 0xc3, 0xe9, 0x8a, 0x8f, 0xc1,\r\n    0x8f, 0xe1, 0xb8, 0xa4, 0x96, 0xf1, 0x8f, 0x81, 0xb1, 0x8d, 0x89, 0xcc, 0xd4, 0x78, 0x76, 0x61,\r\n    0x72, 0x3e, 0x37, 0x23, 0x56, 0x73, 0x71, 0x79, 0x63, 0x7c, 0x08, 0x11, 0x20, 0x69, 0x7a, 0x14,\r\n    0x68, 0x05, 0x21, 0x1e, 0x32, 0x27, 0x59, 0xb7, 0xcf, 0xab, 0xdd, 0xd5, 0xcc, 0x97, 0x93, 0xf2,\r\n    0xe7, 0xc0, 0xeb, 0xff, 0xe9, 0xa3, 0xbf, 0xa1, 0xab, 0x8b, 0xbb, 0x9e, 0x9e, 0x8c, 0xa0, 0xc1,\r\n    0x9b, 0x5a, 0x2f, 0x2f, 0x4e, 0x4e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r\n    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r\n  ],\r\n\r\n  exec: function()\r\n  {\r\n    \/\/ virtual machine architecture\r\n    \/\/ ++++++++++++++++++++++++++++\r\n    \/\/\r\n    \/\/ segmented memory model with 16-byte segment size (notation seg:offset)\r\n    \/\/\r\n    \/\/ 4 general-purpose registers (r0-r3)\r\n    \/\/ 2 segment registers (cs, ds equiv. to r4, r5)\r\n    \/\/ 1 flags register (fl)\r\n    \/\/\r\n    \/\/ instruction encoding\r\n    \/\/ ++++++++++++++++++++\r\n    \/\/\r\n    \/\/           byte 1               byte 2 (optional)\r\n    \/\/ bits      [ 7 6 5 4 3 2 1 0 ]  [ 7 6 5 4 3 2 1 0 ]\r\n    \/\/ opcode      - - -\r\n    \/\/ mod               -\r\n    \/\/ operand1            - - - -\r\n    \/\/ operand2                         - - - - - - - -\r\n    \/\/\r\n    \/\/ operand1 is always a register index\r\n    \/\/ operand2 is optional, depending upon the instruction set specified below\r\n    \/\/ the value of mod alters the meaning of any operand2\r\n    \/\/   0: operand2 = reg ix\r\n    \/\/   1: operand2 = fixed immediate value or target segment (depending on instruction)\r\n    \/\/\r\n    \/\/ instruction set\r\n    \/\/ +++++++++++++++\r\n    \/\/\r\n    \/\/ Notes:\r\n    \/\/   * r1, r2 =&gt; operand 1 is register 1, operand 2 is register 2\r\n    \/\/   * movr r1, r2 =&gt; move contents of register r2 into register r1\r\n    \/\/\r\n    \/\/ opcode | instruction | operands (mod 0) | operands (mod 1)\r\n    \/\/ -------+-------------+------------------+-----------------\r\n    \/\/ 0x00   | jmp         | r1               | r2:r1\r\n    \/\/ 0x01   | movr        | r1, r2           | rx,   imm\r\n    \/\/ 0x02   | movm        | r1, [ds:r2]      | [ds:r1], r2\r\n    \/\/ 0x03   | add         | r1, r2           | r1,   imm\r\n    \/\/ 0x04   | xor         | r1, r2           | r1,   imm\r\n    \/\/ 0x05   | cmp         | r1, r2           | r1,   imm\r\n    \/\/ 0x06   | jmpe        | r1               | r2:r1\r\n    \/\/ 0x07   | hlt         | N\/A              | N\/A\r\n    \/\/\r\n    \/\/ flags\r\n    \/\/ +++++\r\n    \/\/\r\n    \/\/ cmp r1, r2 instruction results in:\r\n    \/\/   r1 == r2 =&gt; fl = 0\r\n    \/\/   r1 &lt; r2  =&gt; fl = 0xff\r\n    \/\/   r1 &gt; r2  =&gt; fl = 1\r\n    \/\/\r\n    \/\/ jmpe r1\r\n    \/\/   =&gt; if (fl == 0) jmp r1\r\n    \/\/      else nop\r\n\r\n    throw \"VM.exec not yet implemented\";\r\n  }\r\n\r\n};\r\n\r\n\/\/--------------------------------------------------------------------------------------------------\r\n\r\ntry\r\n{\r\n  VM.exec();\r\n}\r\ncatch(e)\r\n{\r\n  alert('\\nError: ' + e + '\\n');\r\n}\r\n\r\n\/\/--------------------------------------------------------------------------------------------------<\/pre>\n<p>As we can read this level is completely different from the previous \ud83d\ude42 Short overview:<\/p>\n<ul>\n<li>We must implement own Virtual Machine(!)<\/li>\n<li>VM must emulate segmented memory model with 16-byte segment size (notation seg:offset)<\/li>\n<li>There is defined own assembler with own simple architecture<\/li>\n<li>CPU have 8 registers: 4 general-purpose registers (r0-r3), 2 segment registers (cs, ds equiv. to r4, r5), 1 flags register (fl), and of course IP register (Instruction Pointer)<\/li>\n<li>We know how instruction encoding looks like.<\/li>\n<li>We know how to manipulate flags register.<\/li>\n<li>8 instructions are defined<\/li>\n<li>Memory dump is available which must be used to execute our emulator<\/li>\n<\/ul>\n<p>To solve this level we must know that segment-offset architecture has always shifted memory etc. If we look closer we can find that emulated %%ds register has value 0x10 (because its 16 bits architecture).<\/p>\n<p>I won&#8217;t post here my implementation of this VM, but after all again we must dump the memory how it is changed. Here it is:<\/p>\n<pre>1^D3&lt;AA&gt;@^B&lt;80&gt;^CR^@r^As^A&lt;B2&gt;P0^T&lt;C0&gt;^A&lt;80&gt;^@^P^P^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@2^@u^L32@^B&lt;80&gt;^CR^@r^As^C&lt;B2&gt;^@\u00f0^@0C0&gt;^A&lt;FF&gt;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@u^P^A^@^@^@^@^@^@^@^@^@^@^@&lt;CC&gt;^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@}^_^U`MMR}^N'm^PmZ^FVG^TB^N&lt;B6&gt;&lt;B2&gt;&lt;B2&gt;&lt;E6&gt;\ubd03&lt;8E&gt;&lt;D7&gt;&lt;E5&gt;&lt;D4&gt;&lt;D9&gt;&lt;C3&gt;&lt;F0&gt;&lt;80&gt;&lt;95&gt;&lt;U+4209A&gt;&lt;BD&gt;&lt;95&gt;&lt;A4&gt;&lt;8D&gt;&lt;9A&gt;+0iJieU^\\{i^\\n^Dt5!&amp;\/`^CN7^^3T9\u6eb4&lt;A2&gt;&lt;AD&gt;&lt;A4&gt;\u0155&lt;C8&gt;&lt;C1&gt;&lt;E4&gt;&lt;8A&gt;&lt;EC&gt;\u748b&lt;E8&gt;&lt;81&gt;&lt;U+2D624&gt;&lt;D0&gt;&lt;C0&gt;&lt;8D&gt;&lt;AC&gt;\"Re~'+Z^Ra\r\n^Azk^]g<span style=\"color: #ff0000;\">GET \/da75370fe15c4148bd4ceec861fbdaa5.exe HTTP\/1.0<\/span>^@^@^@^@^@^@^@^@^@^@^@^@^@^@7z^G^Q^_^]h%2w^^b#[GUS0^QB&lt;F6&gt;&lt;F1&gt;&lt;B1&gt;&lt;E6&gt;&lt;C3&gt;&lt;CC&gt;&lt;F8&gt;&lt;C5&gt;&lt;E4&gt;&lt;CC&gt;&lt;C0&gt;\u04c5&lt;FD&gt;&lt;9A&gt;&lt;E3&gt;\u6075&lt;BB&gt;&lt;D7&gt;\u0347&lt;A3&gt;&lt;D3&gt;k6oofU0^VE^\u00a0\u00a0 t\\?)+f=^M\r\n^M^B0(5^U\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ^U&lt;DD&gt;&lt;EC&gt;&lt;B8&gt;&lt;E2&gt;&lt;FB&gt;&lt;D8&gt;&lt;CB&gt;&lt;D8&gt;\u044b\u0542\u065a&lt;F1&gt;&lt;92&gt;&lt;AB&gt;&lt;E8&gt;&lt;A6&gt;&lt;D6&gt;\u040c&lt;AA&gt;\u0494&lt;CF&gt;EFg }D^TkEmT^C^W`bUZJfa^QWhu^Eb6}^B^P\"B2&lt;BA&gt;&lt;E2&gt;&lt;B9&gt;&lt;E2&gt;\u05b9&lt;FF&gt;&lt;C3&gt;\u928f&lt;C1&gt;&lt;8F&gt;\u1e24&lt;96&gt;&lt;U+4F071&gt;&lt;8D&gt;&lt;89&gt;&lt;CC&gt;&lt;D4&gt;xvar&gt;7#Vsqyc^Q iz^Th^E!^^2'Y&lt;B7&gt;\u03eb&lt;DD&gt;&lt;D5&gt;\u0317&lt;93&gt;&lt;F2&gt;&lt;E7&gt;&lt;C0&gt;&lt;EB&gt;&lt;FF&gt;\u98ff&lt;A1&gt;&lt;AB&gt;&lt;8B&gt;&lt;BB&gt;&lt;9E&gt;&lt;9E&gt;&lt;8C&gt;&lt;A0&gt;&lt;C1&gt;&lt;9B&gt;Z\/\/NN^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@<\/pre>\n<p>As we can see there is hidden link for the next level \ud83d\ude09 Now we must probably play with binary \ud83d\ude09<\/p>\n<p>Btw. to be sure that our emulator is correct, last instruction must be &#8216;hlt&#8217; &#8211; halt.<\/p>\n<p>&nbsp;<\/p>\n<h2>Third level (last)<\/h2>\n<p>First of all, this is Windows binary so I will use VM to play with it (I use VirtualBox with Win XP SP3 + IDA of course ;p). We need to install cygwin to run the binary because of the libcrypt which was used to compile the binary. After all when we run the binary we will be asked to give an argument<\/p>\n<pre>usage: keygen.exe hostname<\/pre>\n<p>Let&#8217;s look inside of the binary&#8230;<\/p>\n<pre>\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0 mov\u00a0\u00a0 \u00a0[esp+78h+var_74], offset aR ; \"r\"\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0mov\u00a0\u00a0 \u00a0[esp+78h+var_78], offset aLicense_txt ;\u00a0\u00a0 \u00a0\"license.txt\"\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0call\u00a0\u00a0 \u00a0_fopen64\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0mov\u00a0\u00a0 \u00a0[ebp+var_4C], eax\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0cmp\u00a0\u00a0 \u00a0[ebp+var_4C], 0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0jnz\u00a0\u00a0 \u00a0short loc_401120\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0mov\u00a0\u00a0 \u00a0[esp+78h+var_78], offset aErrorLicense_t ; \"error: license.txt not found\\n\"\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0call\u00a0\u00a0 \u00a0printf\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0mov\u00a0\u00a0 \u00a0[ebp+var_50], 0FFFFFFFFh\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0jmp\u00a0\u00a0 \u00a0loc_401204<\/pre>\n<p>So program is looking for the license.txt file<\/p>\n<pre>\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0 lea\u00a0\u00a0 \u00a0eax, [ebp+var_38]\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0mov\u00a0\u00a0 \u00a0[esp+78h+var_70], eax\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0mov\u00a0\u00a0 \u00a0[esp+78h+var_74], offset aS ; \"%s\"\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0mov\u00a0\u00a0 \u00a0eax, [ebp+var_4C]\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0mov\u00a0\u00a0 \u00a0[esp+78h+var_78], eax\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0call\u00a0\u00a0 \u00a0fscanf<\/pre>\n<p>Get the string from this file (here is by the way <strong>stack overflow bug<\/strong> :D). Next:<\/p>\n<pre>\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0 cmp\u00a0\u00a0 \u00a0[ebp+var_38], 71686367h\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0jnz\u00a0\u00a0 \u00a0short loc_4011CF<\/pre>\n<p>program checks the first 4 bytes if they are equal to 0x71686367 which in fact is equal to the string &#8220;gchq&#8221; &#8211; so the pattern of The Government Communications Headquarters \ud83d\ude42 Next:<\/p>\n<pre>\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0 mov\u00a0\u00a0 \u00a0eax, dword_402000\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0mov\u00a0\u00a0 \u00a0[esp+78h+var_74], eax\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0lea\u00a0\u00a0 \u00a0eax, [ebp+var_38]\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0add\u00a0\u00a0 \u00a0eax, 4\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0mov\u00a0\u00a0 \u00a0[esp+78h+var_78], eax\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0call\u00a0\u00a0 \u00a0crypt\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0 mov\u00a0\u00a0 \u00a0edx, eax\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0mov\u00a0\u00a0 \u00a0eax, dword_402000\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0mov\u00a0\u00a0 \u00a0[esp+78h+var_74], eax\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0mov\u00a0\u00a0 \u00a0[esp+78h+var_78], edx\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0call\u00a0\u00a0 \u00a0strcmp\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0test\u00a0\u00a0 \u00a0eax, eax\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0jnz\u00a0\u00a0 \u00a0short loc_4011A5<\/pre>\n<p>Here is small trick \ud83d\ude42 For me very clever, so we can see call for the crypt() function and next compare and jump. If we analyze it closer we can see that argument for the crypt() is the same like one argument for the strcmp() function. So crypt() must return exactly the same value like one which was passed as argument. Pseudocode can look like:<\/p>\n<pre>char *tmp=\"hqDTK7b8K2rvw\";\r\nif (strcmp(crypt(bufor+4, tmp), tmp)) {\r\n\u00a0\u00a0 ...<\/pre>\n<p>This is very interesting situation because we must find string which after pass it to the crypt() function with the salt &#8220;hqDTK7b8K2rvw&#8221; will be encrypted to exactly the same value as salt (&#8220;hqDTK7b8K2rvw&#8221;) \ud83d\ude42<\/p>\n<p>Two ways can be used to find this string &#8211; bruteforce and rainbow tables. I&#8217;ve done both \ud83d\ude00 In fact bruteforcing won&#8217;t take as much time. Anyway the answer is&#8230;.<\/p>\n<p style=\"text-align: center;\"><strong>cyberwin<\/strong><\/p>\n<p>\ud83d\ude42 Yes, we have it \ud83d\ude42 Now we know that license key should looks like:<\/p>\n<pre>gchqcyberwin<\/pre>\n<p>Whatever we add after this string it won&#8217;t change the value of encrypted string (because of the salt). So let&#8217;s try to run the code with exactly this license.txt file:<\/p>\n<pre>_&gt; da75370fe15c4148bd4ceec861fbdaa5.exe www.canyoucrackit.co.uk\r\n\r\nkeygen.exe\r\n\r\nloading stage1 license key(s)...\r\nloading stage2 license key(s)...\r\n\r\nrequest:\r\n\r\nGET \/hqDTK7b8K2rvw\/0\/0\/0\/key.txt HTTP\/1.0\r\n\r\nresponse:\r\n\r\nHTTP\/1.1 404 Not Found\r\nContent-Type: text\/html; charset=us-ascii\r\nServer: Microsoft-HTTPAPI\/2.0\r\nDate: Thu, 01 Dec 2011 23:55:05 GMT\r\nConnection: close\r\nContent-Length: 315\r\n\r\n&lt;HTML body&gt;<\/pre>\n<p>So what we know now&#8230; File tries to connect to the server given as the argument in command line and tries to GET a key.txt file from the URL:<\/p>\n<pre>\/hqDTK7b8K2rvw\/0\/0\/0\/key.txt<\/pre>\n<p>So again we have some question. Why there is three values of 0 (zero) number? Is the server given in command line is correct? When the program is running it prints:<\/p>\n<pre>loading stage1 license key(s)...\r\nloading stage2 license key(s)...<\/pre>\n<p>Why he do that? If we look again to the java script code from the previous level we can read:<\/p>\n<pre>\/\/ stage 2 of 3<\/pre>\n<p>Is it somehow connected to this string? OK so&#8230; if we add anything after the magic string in license.txt file program tries to dump it as hex value and put in the URL, so:<\/p>\n<pre>_&gt; da75370fe15c4148bd4ceec861fbdaa5.exe www.canyoucrackit.co.uk\r\n\r\nkeygen.exe\r\n\r\nloading stage1 license key(s)...\r\nloading stage2 license key(s)...\r\n\r\nrequest:\r\n\r\nGET \/hqDTK7b8K2rvw\/41414141\/42424242\/43434343\/key.txt HTTP\/1.0\r\n\r\nresponse:\r\n\r\nHTTP\/1.1 404 Not Found\r\nContent-Type: text\/html; charset=us-ascii\r\nServer: Microsoft-HTTPAPI\/2.0\r\nDate: Thu, 01 Dec 2011 23:58:05 GMT\r\nConnection: close\r\nContent-Length: 315\r\n\r\n&lt;HTML body&gt;<\/pre>\n<p>Again we cannot put too long string because we can make stack overflow bug \ud83d\ude09 Of course we do not need to do that \ud83d\ude09 What is interesting we must find correct three 4bytes values and this is the main goal &#8211; find a correct path for the key.txt file &#8211; as I said in first level there is unused 4 bytes &#8211; use it + in 2 stage there was also 2 unused bytes but written directly in the .js file \ud83d\ude09<\/p>\n<p><strong>UPDATE:<\/strong> Some ppl didn&#8217;t believe I know what bytes should be used. But<strong> as I said in previous sentence<\/strong> &#8211; all bytes are in previous stages. Here is the correct link:<\/p>\n<pre>http:\/\/www.canyoucrackit.co.uk\/hqDTK7b8K2rvw\/a3bfc2af\/d2ab1f05\/da13f110\/key.txt<\/pre>\n<p>So first value <strong>as I pointed in all previous sentence<\/strong> (when I described first level<strong> also I point it specially<\/strong>) is from the unused code from the shellcode. Two next bytes are the firmware from the second stage.<\/p>\n<h2>Ending<\/h2>\n<p>When we solve all problems and enter correct string in the main page which is:<\/p>\n<dl id=\"comments-block\">\n<dd id=\"Blog1_cmt-1337870359939349660\">\n<pre><strong>Pr0t3ct!on#cyber_security@12*12.2011+<\/strong><\/pre>\n<\/dd>\n<\/dl>\n<p>you will be redirect to this page:<\/p>\n<pre>http:\/\/www.canyoucrackit.co.uk\/soyoudidit.asp<\/pre>\n<p>Here is screenshot:<\/p>\n<p><a href=\"http:\/\/blog.pi3.com.pl\/?attachment_id=245\" rel=\"attachment wp-att-245\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-245\" title=\"soyoudidit\" src=\"http:\/\/blog.pi3.com.pl\/wp-content\/uploads\/2011\/12\/soyoudidit-300x208.png\" alt=\"\" width=\"300\" height=\"208\" srcset=\"https:\/\/blog.pi3.com.pl\/wp-content\/uploads\/2011\/12\/soyoudidit-300x208.png 300w, https:\/\/blog.pi3.com.pl\/wp-content\/uploads\/2011\/12\/soyoudidit.png 1005w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>After you click the button you are going to be redirected here:<\/p>\n<pre>http:\/\/www.gchq-careers.co.uk\/cyber-jobs\/<\/pre>\n<p>Here is screenshot:<\/p>\n<p><a href=\"http:\/\/blog.pi3.com.pl\/?attachment_id=250\" rel=\"attachment wp-att-250\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-250\" title=\"final\" src=\"http:\/\/blog.pi3.com.pl\/wp-content\/uploads\/2011\/12\/final-300x268.png\" alt=\"\" width=\"300\" height=\"268\" srcset=\"https:\/\/blog.pi3.com.pl\/wp-content\/uploads\/2011\/12\/final-300x268.png 300w, https:\/\/blog.pi3.com.pl\/wp-content\/uploads\/2011\/12\/final.png 644w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>and final redirection is here:<\/p>\n<pre>https:\/\/apply.gchq-careers.co.uk\/fe\/tpl_gchq01ssl.asp?newms=jj&amp;id=35874<\/pre>\n<p>Here is some screenshot with salary:<\/p>\n<p><a href=\"http:\/\/blog.pi3.com.pl\/?attachment_id=253\" rel=\"attachment wp-att-253\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-253\" title=\"salary\" src=\"http:\/\/blog.pi3.com.pl\/wp-content\/uploads\/2011\/12\/salary-300x206.png\" alt=\"\" width=\"300\" height=\"206\" srcset=\"https:\/\/blog.pi3.com.pl\/wp-content\/uploads\/2011\/12\/salary-300x206.png 300w, https:\/\/blog.pi3.com.pl\/wp-content\/uploads\/2011\/12\/salary.png 516w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h2>Conclusion<\/h2>\n<p>This is very nice challenge and requires in fact huge skills. Very nice training for our brains \ud83d\ude09 Anyway few points which I must write now:<\/p>\n<ul>\n<li>To apply for this job you must have English citizen &#8211; I don&#8217;t have so automagically I can&#8217;t apply even when I finished this challenge \ud83d\ude09<\/li>\n<li>This challenge requires a lot of skills and the salary(!) is very low for the ppl with this skills so I understand why they cannot find good ppl \ud83d\ude09<\/li>\n<li>I&#8217;m living and working now in London and I can say its quite nice place \ud83d\ude09<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>UPDATE 2<\/strong>: More information about second level + my implementation of VM can be found here:<\/p>\n<pre><a href=\"http:\/\/blog.pi3.com.pl\/?p=268\">http:\/\/blog.pi3.com.pl\/?p=268<\/a><\/pre>\n<p>&nbsp;<\/p>\n<p>Best regards,<\/p>\n<p>Adam Zabrocki<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday I read in one of the polish portal (with news) an\u00a0 information about interesting challenge organized by the Government Communications Headquarters (GCHQ). This\u00a0is a British intelligence agency responsible for providing signals intelligence (SIGINT) and information assurance to the UK government and armed forces. Based in Cheltenham, it operates under the guidance of the Joint [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,5,6],"tags":[],"class_list":["post-213","post","type-post","status-publish","format-standard","hentry","category-bughunt","category-exploiting","category-ideas"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=\/wp\/v2\/posts\/213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=213"}],"version-history":[{"count":65,"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=\/wp\/v2\/posts\/213\/revisions"}],"predecessor-version":[{"id":259,"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=\/wp\/v2\/posts\/213\/revisions\/259"}],"wp:attachment":[{"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.pi3.com.pl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}