";
33 | $h->endpage();
34 |
--------------------------------------------------------------------------------
/challenges/challenge_5.md:
--------------------------------------------------------------------------------
1 | # file-upload Challenge 5
2 |
3 | ----------------------
4 |
5 | ...
6 |
7 | Ok, I will cease listening to users - can't trust them. I dropped support for the "1337" extension - and to be safe, I quarantined the preferences in an iframe (I heard iframes can help contain hackers). You'll have to be more creative if you want to get past my code now!
8 |
9 | The new code is available in game, you'll see it in the menu on the left with the title "Preferences: Challenge 5".
10 |
11 | -Breakthenet Game Owner
12 |
13 | ----------------------
14 |
15 | Stuck?
16 | ----------------------
17 |
18 | Click for hint 1
19 | His iframe idea was both a bad idea and poorly coded, and merits investigation.
20 |
21 |
22 |
23 | Click for hint 2
24 | Does the include() php function care what the extension of the file is?
25 |
26 |
27 |
28 | Click for hint 3
29 | This challenge is two-part. Part 1 is getting your code to a local file on his server (with an image extension). Part 2 is using the local file inclusion vulnerability to load in your 'image' as though it was code.
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/challenges/challenge_4.md:
--------------------------------------------------------------------------------
1 | # file-upload Challenge 4
2 |
3 | ----------------------
4 |
5 | This is driving me nuts - the arcane knowledge required for your last trick is ridiculous.
6 |
7 | I noticed a trend in all your exploits though. You required the file to end with .php to get your code to run. I'm going to go back to my file extension checker and just fix that up to ONLY check the last extension on a file. I also got a request in my forums to support an obscure image format called "1337", so I'm adding that to the whitelist.
8 |
9 | The new code is available in game, you'll see it in the menu on the left with the title "Preferences: Challenge 4".
10 |
11 | Thanks again for your help!
12 |
13 | -Breakthenet Game Owner
14 |
15 | ----------------------
16 |
17 | Stuck?
18 | ----------------------
19 |
20 | Click for hint 1
21 | 1337...? Wth? What is that an extension for?
22 |
23 |
24 |
25 | Click for hint 2
26 | How does apache handle files with multiple file extensions?
27 |
28 |
29 |
30 | Click for major hint 3
31 | Apache uses last known extension if multiple extensions present
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/votetrpg.php:
--------------------------------------------------------------------------------
1 | startheaders();
14 | include "mysql.php";
15 | global $c;
16 | $is =
17 | mysql_query(
18 | "SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",
19 | $c) or die(mysql_error());
20 | $ir = mysql_fetch_array($is);
21 | check_level();
22 | $fm = money_formatter($ir['money']);
23 | $cm = money_formatter($ir['crystals'], '');
24 | $lv = date('F j, Y, g:i a', $ir['laston']);
25 | $q =
26 | mysql_query(
27 | "SELECT * FROM votes WHERE userid=$userid AND list='trpg'",
28 | $c);
29 | if (mysql_num_rows($q))
30 | {
31 | $h->startheaders();
32 | $h->userdata($ir, $lv, $fm, $cm);
33 | $h->menuarea();
34 | print "You have already voted at TOPRPG today!";
35 | $h->endpage();
36 | }
37 | else
38 | {
39 | mysql_query("INSERT INTO votes values ($userid,'trpg')", $c);
40 | mysql_query("UPDATE users SET money=money+300 WHERE userid=$userid", $c);
41 | header("Location:http://www.toprpgames.com/vote.php?idno=757");
42 | exit;
43 | }
44 |
--------------------------------------------------------------------------------
/donatordone.php:
--------------------------------------------------------------------------------
1 | startheaders();
14 | include "mysql.php";
15 | global $c;
16 | $is =
17 | mysql_query(
18 | "SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",
19 | $c) or die(mysql_error());
20 | $ir = mysql_fetch_array($is);
21 | check_level();
22 | $fm = money_formatter($ir['money']);
23 | $cm = money_formatter($ir['crystals'], '');
24 | $lv = date('F j, Y, g:i a', $ir['laston']);
25 | $h->userdata($ir, $lv, $fm, $cm);
26 | $h->menuarea();
27 | if ($_GET['action'] == "cancel")
28 | {
29 | print "You have cancelled your donation. Please donate later...";
30 | }
31 | else if ($_GET['action'] == "done")
32 | {
33 | if (!$_GET['tx'])
34 | {
35 | die("Get a life.");
36 | }
37 | mysql_query(
38 | "INSERT INTO dps_process VALUES(NULL,$userid," . time()
39 | . ",'{$_GET['type']}');", $c);
40 | print
41 | "Your donation has been processed. An admin will check it and you should be credited in about 24-48 hours.";
42 | }
43 | $h->endpage();
44 |
--------------------------------------------------------------------------------
/oclog.php:
--------------------------------------------------------------------------------
1 | startheaders();
14 | include "mysql.php";
15 | global $c;
16 | $is =
17 | mysql_query(
18 | "SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",
19 | $c) or die(mysql_error());
20 | $ir = mysql_fetch_array($is);
21 | check_level();
22 | $fm = money_formatter($ir['money']);
23 | $cm = money_formatter($ir['crystals'], '');
24 | $lv = date('F j, Y, g:i a', $ir['laston']);
25 | $h->userdata($ir, $lv, $fm, $cm);
26 | $h->menuarea();
27 | $_GET['ID'] = abs((int) $_GET['ID']);
28 | if (!$_GET['ID'])
29 | {
30 | die("Incorrect usage of file.");
31 | }
32 | $q = mysql_query("SELECT * FROM oclogs WHERE oclID={$_GET['ID']}", $c);
33 | $r = mysql_fetch_array($q);
34 | print
35 | "Here is the detailed view on this crime.
36 | Crime: {$r['ocCRIMEN']}
37 | Time Executed: " . date('F j, Y, g:i:s a', $r['ocTIME'])
38 | . "
39 | {$r['oclLOG']}
40 | Result: {$r['oclRESULT']}
41 | Money Made: \${$r['oclMONEY']}";
42 | $h->endpage();
43 |
--------------------------------------------------------------------------------
/challenges/challenge_3.md:
--------------------------------------------------------------------------------
1 | # file-upload Challenge 3
2 |
3 | ----------------------
4 |
5 | Geez. This is harder than I thought. Ok, based on your advice I dropped the client-side mime type validation and am trying something new.
6 |
7 | The code should now actually validate that what is being uploaded is a real image, with real dimensions and real mime-types.
8 |
9 | There's no way you should be able to bust past this one.
10 |
11 | It's available in game, you'll see it in the menu on the left with the title "Preferences: Challenge 3".
12 |
13 | Thanks again for your help!
14 |
15 | -Breakthenet Game Owner
16 |
17 | ----------------------
18 |
19 | Stuck?
20 | ----------------------
21 |
22 | Click for hint 1
23 | You must upload a valid image on this one (no way to get around that).
24 |
25 |
26 |
27 | Click for hint 2
28 | PHP ignores anything outside of the and ?> tags.
29 |
30 |
31 |
32 | Click for hint 3
33 | You can actually insert a comment inside a GIF, which anything processing that GIF ignores. That comment could be anything... it could even have characters like < and ? in it. [GIMP, a free software for manipulating images, will allow you to insert comments in gifs.](http://s116.photobucket.com/user/bayououtdoor/media/gifcomment.gif.html)
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/votetwg.php:
--------------------------------------------------------------------------------
1 | startheaders();
14 | include "mysql.php";
15 | global $c;
16 | $is =
17 | mysql_query(
18 | "SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",
19 | $c) or die(mysql_error());
20 | $ir = mysql_fetch_array($is);
21 | check_level();
22 | $fm = money_formatter($ir['money']);
23 | $cm = money_formatter($ir['crystals'], '');
24 | $lv = date('F j, Y, g:i a', $ir['laston']);
25 | $q =
26 | mysql_query(
27 | "SELECT * FROM votes WHERE userid=$userid AND list='twg'", $c);
28 | if (mysql_num_rows($q))
29 | {
30 | $h->startheaders();
31 | $h->userdata($ir, $lv, $fm, $cm);
32 | $h->menuarea();
33 | print "You have already voted at TWG today!";
34 | $h->endpage();
35 | }
36 | else
37 | {
38 | mysql_query("INSERT INTO votes values ($userid,'twg')", $c);
39 | mysql_query(
40 | "UPDATE users SET energy=energy+maxenergy/5 WHERE userid=$userid",
41 | $c);
42 | mysql_query("UPDATE users SET energy=maxenergy WHERE energy>maxenergy", $c);
43 | header("Location:http://www.topwebgames.com/in.asp?id=3341");
44 | exit;
45 | }
46 |
--------------------------------------------------------------------------------
/hospital.php:
--------------------------------------------------------------------------------
1 | startheaders();
14 | include "mysql.php";
15 | global $c;
16 | $is =
17 | mysql_query(
18 | "SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",
19 | $c) or die(mysql_error());
20 | $ir = mysql_fetch_array($is);
21 | check_level();
22 | $fm = money_formatter($ir['money']);
23 | $cm = money_formatter($ir['crystals'], '');
24 | $lv = date('F j, Y, g:i a', $ir['laston']);
25 | $h->userdata($ir, $lv, $fm, $cm);
26 | $h->menuarea();
27 | print
28 | "
Hospital
29 |
ID
Name
Level
Time
Reason
";
30 | $q =
31 | mysql_query(
32 | "SELECT u.*,c.* FROM users u WHERE u.hospital > 0 ORDER BY u.hospital DESC",
33 | $c);
34 | while ($r = mysql_fetch_array($q))
35 | {
36 | print
37 | "\n
";
42 | }
43 | }
44 | $h->endpage();
45 |
--------------------------------------------------------------------------------
/challenges/challenge_1.md:
--------------------------------------------------------------------------------
1 | # file-upload Challenge 1
2 |
3 | ----------------------
4 |
5 | All players in my game have a profile pic. Currently, they have to stick in a url to some outside image hosting source for that pic - which I've gotten many complaints about. My players want to know why they can't just upload the images straight in my game.
6 |
7 | I've been experimenting with a feature to allow this, but before launching it, was hoping you could help me out by testing to see if it is secure. Could you see if you can do anything malicious with it?
8 |
9 | It's available in game, you'll see it in the menu on the left with the title "Preferences: Challenge 1".
10 |
11 | After uploading an image, you can click "My Profile" in the menu on the left to see it (perhaps right click it if it's a broken image, and click open image in new tab).
12 |
13 | -Breakthenet Game Owner
14 |
15 | ----------------------
16 |
17 | Stuck?
18 | ----------------------
19 |
20 | Click for hint 1
21 | This is not a black box challenge, you can look in the source code for clues if you get stuck! The particular code you are looking for is [here](https://github.com/breakthenet/file-upload-exercises/blob/master/preferences_c1.php#L213-L245).
22 |
23 |
24 |
25 | Click for hint 2
26 | What does the strpos function in php actually search for?
27 |
28 |
29 |
30 | Click for hint 3
31 | Is it possible to have multiple extensions on a file (chained together?)
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/searchname.php:
--------------------------------------------------------------------------------
1 | startheaders();
14 | include "mysql.php";
15 | global $c;
16 | $is =
17 | mysql_query(
18 | "SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",
19 | $c) or die(mysql_error());
20 | $ir = mysql_fetch_array($is);
21 | check_level();
22 | $fm = money_formatter($ir['money']);
23 | $cm = money_formatter($ir['crystals'], '');
24 | $lv = date('F j, Y, g:i a', $ir['laston']);
25 | $h->userdata($ir, $lv, $fm, $cm);
26 | $h->menuarea();
27 | //search name
28 | if (!$_GET['name'])
29 | {
30 | print "Invalid use of file";
31 | }
32 | else
33 | {
34 | $namebit = mysql_real_escape_string(stripslashes($_GET['name']), $c);
35 | $q =
36 | mysql_query(
37 | "SELECT * FROM users WHERE username LIKE ('%{$namebit}%')",
38 | $c);
39 | print
40 | mysql_num_rows($q)
41 | . " players found.
42 |