{"id":32,"date":"2022-07-17T22:00:07","date_gmt":"2022-07-17T22:00:07","guid":{"rendered":"http:\/\/moveax.me\/?p=32"},"modified":"2022-08-31T19:02:36","modified_gmt":"2022-08-31T19:02:36","slug":"crackme0x06-dissected-with-radare2","status":"publish","type":"post","link":"https:\/\/giga-rapid.com\/esites\/moveaxme\/crackme0x06-dissected-with-radare2\/","title":{"rendered":"Crackme0x06 Dissected with Radare2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Crackme0x06! A new exercise, a new function. Also, some new tricks are used to obtain the so wanted \u201cPassword OK\u201d.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This exercise is very alike the&nbsp;<a href=\"crackme0x05\/\">previous<\/a>&nbsp;one, so I won\u2019t go through the functions already explained.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Getting the&nbsp;Crackme0x06&nbsp;password through analysis<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">As usual, let\u2019s check the functions available.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We\u2019ve got a new function: dummy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One of the conditions that we saw before, must be met if we want to jump to this function, we need to sum from left to right until we get 0x10 (16 in decimal). If this condition is met, we are on the right path, and will go to dummy function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s take a peek into this function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There\u2019s a lot going on here. This (not so) dummy function messed up my brain with all those \u201ceax*4\u201d.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before we continue, let me show you something that I saw when I started debugging this function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>LS_COLORS?! Are we painting now???<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">I didn\u2019t know what to expect at this point, so I googled for this, and ended up finding that this is an environment variable\u2026<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So you can follow my explanation, let me go ahead and tell you that this function looks for something in your environment variables, looping through all of them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Moving on, at the beginning of this function, we see a reset to the local_4h, which is an index.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The next few instructions until the compare, ensures that you get an \u201cInvalid password\u201d if all the environment variables are compared and the desired on is not found. arg_ch as you\u2019ve seen, holds a pointer to the first environment variable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pay attention to the manipulation of&nbsp;<em>ecx<\/em>&nbsp;and&nbsp;<em>edx<\/em>&nbsp;registers, at 0x080484d7 address and the next one.&nbsp;<em>ecx<\/em>&nbsp;will hold the step that will be used to jump to the next environment variable.&nbsp;<em>edx<\/em>&nbsp;has a copy of the address where the first environment variable is located.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The way used to iterate over all the environment variables is a sum between these two registers as you can see at 0x080484f6 address.<\/p>\n\n\n\n\n\n<p class=\"wp-block-paragraph\">This is what happens. edx is \u201cthe same\u201d as arg_ch and ecx represents each box of the middle column, where each box has a size of 4 bytes (that eax*<strong>4<\/strong>) and holds the address of each environment variable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, we see a 3 being moved to local_8h and the string \u201cLOLO\u201d being loaded to local_4h_2 and after that, we see a strncmp. This&nbsp;<a href=\"https:\/\/linux.die.net\/man\/3\/strncmp\">strncmp<\/a>&nbsp;function takes three arguments: two strings and the size. Obviously, the 3 is the size and the \u201cLOLO\u201d is one of the two string. The last string is the environment variable. Notice that only three characters will be compared, so you\u2019ll be actually comparing \u201cLOL\u201d with something. The following test instruction is easy, because strncmp returns 0 if (in this case) the first 3 bytes of both strings match.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In that case, we\u2019ll leave the function with 1 loaded into the eax register.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Returning to parell function, and as crackme0x05, we will check if the number provided is even.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Solution<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To solve crackme0x06 exercise the following conditions must be met:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>We must sum the digits of the number provided, from the left to right, until we get 0x10<\/li><li>We must set the environment variable LOL<\/li><li>The number must be even<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">To set an environment variable, use the command \u201cexport LOL=<em>something<\/em>\u201c. You can also execute the exercise as \u201cLOL=<em>something<\/em>&nbsp;.\/crackme0x06\u2033<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Modifying&nbsp;<\/strong><strong>Crackme0x06&nbsp;to accept any password<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To make this crackme accept any password we can simply make the following modifications.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the check function, replace the&nbsp;<em>jae<\/em>&nbsp;for an unconditional jump to the sym.parell\u2019s call.<\/p>\n\n\n\n\n\n<p class=\"wp-block-paragraph\">Next, we go to dummy function and again, replace the&nbsp;<em>je<\/em>&nbsp;for an unconditional jump to 0x08048505 address making the program exit this function.<\/p>\n\n\n\n\n\n<p class=\"wp-block-paragraph\">After this, the program still checks if we inserted an even number. We don\u2019t want that. So let\u2019s clear the eax register in the&nbsp;<em>and<\/em>&nbsp;instruction.<\/p>\n\n\n\n\n<p class=\"wp-block-paragraph\">I think this is enough. Let\u2019s confirm.<\/p>\n\n\n\n\n\n<p class=\"wp-block-paragraph\">Yep. Seems cracked \ud83d\ude09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Notice that you no longer need the environment variable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do you have a more clever way to crack this one?<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Walkthrough video<\/strong><\/h4>\n\n\n<!-- \/wp:post-content -->","protected":false},"excerpt":{"rendered":"<p>Crackme0x06! A new exercise, a new function. Also, some new tricks are used to obtain the so wanted \u201cPassword OK\u201d. This exercise is very alike&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/giga-rapid.com\/esites\/moveaxme\/crackme0x06-dissected-with-radare2\/\">Continue reading<span class=\"screen-reader-text\">Crackme0x06 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-32","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\/32","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=32"}],"version-history":[{"count":2,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/posts\/32\/revisions"}],"predecessor-version":[{"id":124,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/posts\/32\/revisions\/124"}],"wp:attachment":[{"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/media?parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/categories?post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/giga-rapid.com\/esites\/moveaxme\/wp-json\/wp\/v2\/tags?post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}