{"id":15,"date":"2022-07-17T21:55:47","date_gmt":"2022-07-17T21:55:47","guid":{"rendered":"http:\/\/moveax.me\/?p=15"},"modified":"2022-07-18T00:20:49","modified_gmt":"2022-07-18T00:20:49","slug":"crackme0x02","status":"publish","type":"post","link":"https:\/\/giga-rapid.com\/esites\/moveaxme\/crackme0x02\/","title":{"rendered":"Crackme0x02 Dissected with Radare2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">For the Crackme0x02, I\u2019ll follow two approaches. First, I\u2019m going to find out the password through analysis. Then, I\u2019ll modify the program in order to accept any password.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you\u2019re not acquainted with any of the commands used in this post, you can always take a look at&nbsp;<a href=\"%3Cspan%20class='hiddenSpellError%20wpgc-spelling'%20style='background:%20#FFC0C0;'%3ERadare%3C\/span%3E-basics\/\">Radare Basics<\/a>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"wp-content\/uploads\/2018\/01\/crackme0x02.png\" alt=\"crackme0x02\" class=\"wp-image-163\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s start and first of all, we need to run the program.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Like the&nbsp;<a href=\"crackme0x01\">previous exercise<\/a>, this one is a password challenge.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Getting the&nbsp;Crackme0x02&nbsp;password through analysis<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To start debugging this program we need to start Radare with the flags&nbsp;<em>A<\/em>&nbsp;and&nbsp;<em>d<\/em>. Then, we can check the strings present in data section.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"wp-content\/uploads\/2018\/01\/iz.png\" alt=\"iz\" class=\"wp-image-141\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">None of this strings seems to be useful, so if we check the functions present in this binary we can see the main function that we can seek to. Let\u2019s print the main.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"wp-content\/uploads\/2018\/01\/pdf.png\" alt=\"pdf\" class=\"wp-image-146\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Similarly to the previous exercise, the string printed is determine by a compare intruction. Between the scanf instruction and this compare instruction we can see some operations taking place, including one sum and one multiplication. Now, it\u2019s time to dissect that part of the code using breakpoints.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We can see the local variable local_8h holding 0x5a value and local_ch holding 0x1ec, but let\u2019s use afvd to confirm. For that, we need to set a breakpoint right after this last instruction, at 0x08048439 address.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After set a breakpoint we can see it in front of that address, using pdf. Then, use dc to run the program until it hits the breakpoint.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"wp-content\/uploads\/2018\/01\/afvd-Copy.png\" alt=\"afvd\" class=\"wp-image-155\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Yes, local_8h and local_ch hold those values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The next instruction puts the value of local_ch in the edx register. Notice that this doesn\u2019t happen for local_8h. Instead, eax loads the address of this variable using lea operator which means that eax will \u201cpoint\u201d to local_8h memory address.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Solution<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">From this point forward, the operations to calculate the solution are taking place.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The next instruction adds the value of edx to the value of the memory cell to where eax points to, and stores it in that same address. The value of local_ch (0x1ec) was added to local_8h (0x5a) and stored in local_8h.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s check the contents of all variables again.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"wp-content\/uploads\/2018\/01\/afvd2.png\" alt=\"afvd2\" class=\"wp-image-157\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">So far, so good. Next, the value stored in local_8h is moved to eax register. At this point, both local_8h and register eax holds the value 0x246, so the next imul instruction will raise this value to the power 2. eax register should now have the value 0x52b24. Let\u2019s confirm using dr command.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"wp-content\/uploads\/2018\/01\/dr.png\" alt=\"\" class=\"wp-image-158\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">There it is! The next two instructions will prepare the registers and variables for the cmp instruction. So, local_ch now have the solution to this challenge and eax holds the value inserted by the user (which was stored in local_4h).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We now know that the solution for this crackme must be 0x52b24 (or 338724 in decimal). Let\u2019s check.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"wp-content\/uploads\/2018\/01\/solution.png\" alt=\"Solution\" class=\"wp-image-159\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">We\u2019ve got it right!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Getting the&nbsp;Crackme0x02&nbsp;password through program modification<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Time for the hard part. Before I continue, let me just state that I could manipulate the code in many ways and obtain an identical result. For instance, I could replace the compare instruction by&nbsp;<em>cmp<\/em>&nbsp;eax, eax for example or I could edit the opcode before the compare instruction and save some value in eax register.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Instead, I going to overwrite the jump instruction right after the compare instruction and replace it with a nop by changing the opcodes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For more information about the opcodes, I advise you to take a look in&nbsp;<a href=\"https:\/\/www.mathemainzel.info\/files\/x86asmref.html\">this website<\/a>&nbsp;and&nbsp;<a href=\"https:\/\/ref.x86asm.net\/coder32.html\">this one<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, if we going to modify the program we need to open it in write mode (with the w flag). Don\u2019t forget A flag as well. After that, you still need seek to the main function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So, the target operation is at 0x08048451 address. To replace it let\u2019s use wx command. By the way, the 90 that you see in the image below is the opcode for the nop operation<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"wp-content\/uploads\/2018\/01\/write.png\" alt=\"<span class='hiddenSpellError wpgc-spelling' style='background: #FFC0C0;'&gt;wx<\/span&gt;\" class=\"wp-image-172\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">If the second operation is difficult to understand, check the walkthrough video at the end of this post.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The next image is just a portion of pdf command. It\u2019s possible to see that the jump operation has been replaced.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"wp-content\/uploads\/2018\/01\/pdf-1.png\" alt=\"pdf\" class=\"wp-image-173\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Just to be crystal clear, it doesn\u2019t matter the value of eax nor local_ch because no action will take place after the compare instruction.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, let\u2019s run crackme0x02 and check if we\u2019re good.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"wp-content\/uploads\/2018\/01\/result.png\" alt=\"result\" class=\"wp-image-174\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Mission Accomplished&nbsp;<img decoding=\"async\" alt=\"\ud83d\ude4c\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/13.0.0\/svg\/1f64c.svg\"><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Walkthrough video<\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>For the Crackme0x02, I\u2019ll follow two approaches. First, I\u2019m going to find out the password through analysis. Then, I\u2019ll modify the program in order to&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/giga-rapid.com\/esites\/moveaxme\/crackme0x02\/\">Continue reading<span class=\"screen-reader-text\">Crackme0x02 Dissected with Radare2<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,1],"tags":[],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-radare2","category-uncategorized","entry"],"_links":{"self":[{"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":2,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"predecessor-version":[{"id":23,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/posts\/15\/revisions\/23"}],"wp:attachment":[{"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}