{"id":415,"date":"2020-11-01T15:47:00","date_gmt":"2020-11-01T15:47:00","guid":{"rendered":"https:\/\/badbit.vc\/?p=415"},"modified":"2020-11-30T19:23:16","modified_gmt":"2020-11-30T19:23:16","slug":"flare-on-7","status":"publish","type":"post","link":"https:\/\/badbit.vc\/index.php\/2020\/11\/01\/flare-on-7\/","title":{"rendered":"Flare-On 7 | Challenge 1"},"content":{"rendered":"\n<p>This is my first entry for the <a rel=\"noreferrer noopener\" href=\"https:\/\/flare-on.com\/\" target=\"_blank\">Flare-On<\/a> challenge. For those who don&#8217;t know, Flare-On is a yearly binary based challenge series which is heavily focused on reverse engineering. It usually comprises of  ~15 challenges with increasing difficulty level.<\/p>\n\n\n\n<p>This year, the event had 11 challenges. Due to the nicheness and the difficulty level of the topic, the competition sees comparatively lower participation than other traditional CTF-like events. This year, the total number of participants was 5648 and only <strong>260<\/strong> could complete all the 11 challenges [<a rel=\"noreferrer noopener\" href=\"https:\/\/vulners.com\/fireeye\/FIREEYE:3C97C63F1725390B2FB7FD0C2983FDE3\" target=\"_blank\">source<\/a>].  <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"912\" height=\"565\" src=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/0.5stats.jpg\" alt=\"\" class=\"wp-image-455\" srcset=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/0.5stats.jpg 912w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/0.5stats-300x186.jpg 300w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/0.5stats-768x476.jpg 768w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/0.5stats-850x527.jpg 850w\" sizes=\"auto, (max-width: 912px) 100vw, 912px\" \/><\/figure>\n\n\n\n<p>Due to time constraints, I was able to solve two challenges. Late to the game but following are the writeups for the same.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Challenge 1 &#8211; Fidler<\/h2>\n\n\n\n<p><strong><em>Challenge description TLDR<\/em><\/strong> &#8211; Pygame based runnable exe. Win the game by any means to reveal the flag.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"148\" src=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/kittyelaine.png\" alt=\"\" class=\"wp-image-420\"\/><\/figure><\/div>\n\n\n\n<p>After downloading and unzipping the 7z file from the challenge screen, we are presented with an executable file named fidler.exe, two .py files, a message.txt and two folders named fonts and img. The message.txt gave a brief description about the challenge.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"689\" height=\"251\" src=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/0.jpg\" alt=\"\" class=\"wp-image-426\" srcset=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/0.jpg 689w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/0-300x109.jpg 300w\" sizes=\"auto, (max-width: 689px) 100vw, 689px\" \/><\/figure>\n\n\n\n<p>Alright, we are supposed to win the game by any means. After taking a quick look in CFF explorer it was evident that it was a x64 PE file.<\/p>\n\n\n\n<p><strong>Let us execute!<\/strong><\/p>\n\n\n\n<p>After executing the file &#8211; fidler.exe, we are presented with a window which asks us for a password. Trying to put a random string in the text bar doesn&#8217;t allow us to proceed further and throws an error screen.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"563\" src=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/1.jpg\" alt=\"\" class=\"wp-image-427\" srcset=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/1.jpg 960w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/1-300x176.jpg 300w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/1-768x450.jpg 768w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/1-850x498.jpg 850w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"992\" height=\"631\" src=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/2.jpg\" alt=\"\" class=\"wp-image-428\" srcset=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/2.jpg 992w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/2-300x191.jpg 300w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/2-768x489.jpg 768w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/2-850x541.jpg 850w\" sizes=\"auto, (max-width: 992px) 100vw, 992px\" \/><\/figure>\n\n\n\n<p><strong>Solution:<\/strong><\/p>\n\n\n\n<p>Taking a look at the source code under the file fidler.py to understand the program flow, it reveals that in the main function, password_screen() is called and if it returns true then the control is passed to game_screen() or else the control is passed to password_fail_screen().<\/p>\n\n\n\n<p>Alright, so we are supposed to somehow circumvent the password check here to pass the control to game_screen(). <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"680\" height=\"718\" src=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/3.jpg\" alt=\"\" class=\"wp-image-429\" srcset=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/3.jpg 680w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/3-284x300.jpg 284w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/3-300x317.jpg 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/figure>\n\n\n\n<p>I could think of two options here:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Manipulate the else statement to pass the control to game_screen which means that even if password_screen() function returns false, the game_screen() function would execute which basically is equivalent to passing the control to normal execution even if an incorrect password is entered<\/li><li>Try finding out the password from within the program<\/li><\/ol>\n\n\n\n<p>Even though the first option seemed easier, I didn&#8217;t want to download any dependencies to recompile the python code to convert it to a runnable exe and so I went with the second option.<\/p>\n\n\n\n<p>Taking a closer look at password_screen() function, it was clear that the password_check() function was being called which simply returns true if the given user input is same as the key. To find out the key it was just a matter of printing the key.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"890\" src=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/4.jpg\" alt=\"\" class=\"wp-image-430\" srcset=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/4.jpg 872w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/4-294x300.jpg 294w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/4-768x784.jpg 768w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/4-300x306.jpg 300w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/4-850x868.jpg 850w\" sizes=\"auto, (max-width: 872px) 100vw, 872px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"675\" height=\"298\" src=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/5.jpg\" alt=\"\" class=\"wp-image-431\" srcset=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/5.jpg 675w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/5-300x132.jpg 300w\" sizes=\"auto, (max-width: 675px) 100vw, 675px\" \/><\/figure>\n\n\n\n<p>As seen above, the key was &#8211; <strong>ghost<\/strong>. Now that we have the password for entering the game screen, let&#8217;s try to enter the obtained key and check out the game. Following is the game screen after entering the key.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"985\" height=\"637\" src=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/6.jpg\" alt=\"\" class=\"wp-image-432\" srcset=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/6.jpg 985w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/6-300x194.jpg 300w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/6-768x497.jpg 768w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/6-850x550.jpg 850w\" sizes=\"auto, (max-width: 985px) 100vw, 985px\" \/><\/figure><\/div>\n\n\n\n<p>Remember, the goal is to win by any way possible to reveal the flag. Let&#8217;s win!<\/p>\n\n\n\n<p>As per the game&#8217;s rules presented in the game window, we are supposed to earn 100 Billion coins to win which will reveal the flag.<br>Clicking the kitty once raises the coin count by one. Obviously, it&#8217;s not feasible to click the kitty a 100 Billion times. There was another way &#8211; &#8220;Buy autoclickers&#8221; which would subtract 10 coins from your earned coins and increase the counter at a rate of one coin per second.<\/p>\n\n\n\n<p>Okay so we now know the game&#8217;s flow.<\/p>\n\n\n\n<p><strong>Solution:<\/strong><br>I could think of two possible ways to find the flag.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>We manipulate the autoclicker logic and somehow increase the count of the coin count<\/li><li>Figure out how the flag is stored and displayed<\/li><\/ol>\n\n\n\n<p>I chose the second way.<\/p>\n\n\n\n<p>The goal is to make the game display the victory screen. Taking a look at the source given in the fidler.py file, we can see that the victory_screen() function is called if current_coins &gt; (target_amount &#8211; 2^20). Also, the target amount is hardcoded to (2^36) + (2^35) which is equal to 103079215104.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"227\" src=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/6.5.jpg\" alt=\"\" class=\"wp-image-435\" srcset=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/6.5.jpg 710w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/6.5-300x96.jpg 300w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<p>So our current coin value should be more than 103079215104 &#8211; (2^20) in order to pass the control to victory_screen().<br>Further, the code reduces 2^20 from current coins until they are &gt;= (target_amount + 2^20) which ultimately boils down to a constant value irrespective of the variable current_coins as far as it satisifies the previous condition and that really doesn&#8217;t matter us.<\/p>\n\n\n\n<p>Hence, the only mandatory requirement to pass the control to victory_screen() is to have the <strong>current_coins amount &gt; (target_amount &#8211; 2^20) i.e. &gt; 103078166528<\/strong><\/p>\n\n\n\n<p>Therefore, our current_coin value should be any value greater than 103078166528 in order to pass the control to victory_screen() function.<\/p>\n\n\n\n<p>Below is the re-written function that passed 103078166529 as our current_value and passed the control as it is to the existing flow of decode_flag() from the fidler.py file.<br>On the window at right hand side, we can see two outputs just to confirm the flow.<br>1. Where the current_coin value is greater than 103078166528<br>2. Where the current_coin value is less than 103078166528<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"451\" src=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/7-1-1024x451.jpg\" alt=\"\" class=\"wp-image-436\" srcset=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/7-1-1024x451.jpg 1024w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/7-1-300x132.jpg 300w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/7-1-768x338.jpg 768w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/7-1-850x374.jpg 850w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/7-1.jpg 1340w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>And there we have our flag! \ud83d\ude00<br>With this one down, I was <em>1338th<\/em> in the participant pool to complete the challenge.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"783\" src=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/1338-1024x783.jpg\" alt=\"\" class=\"wp-image-437\" srcset=\"https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/1338-1024x783.jpg 1024w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/1338-300x229.jpg 300w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/1338-768x587.jpg 768w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/1338-850x650.jpg 850w, https:\/\/badbit.vc\/wp-content\/uploads\/2020\/11\/1338.jpg 1028w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Since this was level one, it was a simple challenge just to get us going. Flare-On is notoriously known to tremendously increase the difficulty bar with every challenge which will be evident when we will dive into challenge two!<\/p>\n\n\n\n<p>Write-Up for challenge two will be up soon. Stay tuned!<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is my first entry for the Flare-On challenge. For those who don&#8217;t know, Flare-On is a yearly binary based challenge series which is heavily focused on reverse engineering. It usually comprises of ~15 challenges with increasing difficulty level. This year, the event had 11 challenges. Due to the nicheness and the difficulty level of&#8230;<\/p>\n","protected":false},"author":1,"featured_media":418,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[15,13,16,14],"class_list":["post-415","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ctf-write-ups","tag-fireeye","tag-flareon7","tag-malwareanalysis","tag-reverseengineering"],"_links":{"self":[{"href":"https:\/\/badbit.vc\/index.php\/wp-json\/wp\/v2\/posts\/415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badbit.vc\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badbit.vc\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badbit.vc\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badbit.vc\/index.php\/wp-json\/wp\/v2\/comments?post=415"}],"version-history":[{"count":26,"href":"https:\/\/badbit.vc\/index.php\/wp-json\/wp\/v2\/posts\/415\/revisions"}],"predecessor-version":[{"id":460,"href":"https:\/\/badbit.vc\/index.php\/wp-json\/wp\/v2\/posts\/415\/revisions\/460"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badbit.vc\/index.php\/wp-json\/wp\/v2\/media\/418"}],"wp:attachment":[{"href":"https:\/\/badbit.vc\/index.php\/wp-json\/wp\/v2\/media?parent=415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badbit.vc\/index.php\/wp-json\/wp\/v2\/categories?post=415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badbit.vc\/index.php\/wp-json\/wp\/v2\/tags?post=415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}