From fa10962295ff27fae257175a189bd4cf2adccd65 Mon Sep 17 00:00:00 2001 From: thomashaw Date: Thu, 30 Mar 2017 11:21:33 +0100 Subject: [PATCH] adding breakthenet xss web vulnerability -- Now registers the mysql db + allows www-data to connect with password 'example', change this! register.php claims that registration was successful but logging in does not work... investigate further. --- .../btn_xss_challenge/btn_xss_challenge.pp | 1 + .../webapp/btn_xss_challenge/files/README.md | 13 +++ .../webapp/btn_xss_challenge/files/app.json | 21 +++++ .../btn_xss_challenge/files/authenticate.php | 19 +++++ .../btn_xss_challenge/files/composer.json | 6 ++ .../btn_xss_challenge/files/composer.lock | 21 +++++ .../webapp/btn_xss_challenge/files/dbdata.sql | 8 ++ .../files/fake_admin_browser.js | 41 ++++++++++ .../webapp/btn_xss_challenge/files/index.php | 82 +++++++++++++++++++ .../webapp/btn_xss_challenge/files/login.php | 38 +++++++++ .../webapp/btn_xss_challenge/files/logout.php | 5 ++ .../webapp/btn_xss_challenge/files/mysql.php | 7 ++ .../btn_xss_challenge/files/register.php | 46 +++++++++++ .../btn_xss_challenge/files/setup_mysql.php | 34 ++++++++ .../files/trigger_fake_admin.php | 6 ++ .../files/trigger_fake_admin_2.php | 10 +++ .../btn_xss_challenge/manifests/configure.pp | 13 +++ .../btn_xss_challenge/manifests/init.pp | 4 + .../btn_xss_challenge/manifests/install.pp | 14 ++++ .../btn_xss_challenge/secgen_metadata.xml | 39 +++++++++ 20 files changed, 428 insertions(+) create mode 100644 modules/vulnerabilities/unix/webapp/btn_xss_challenge/btn_xss_challenge.pp create mode 100755 modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/README.md create mode 100755 modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/app.json create mode 100755 modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/authenticate.php create mode 100755 modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/composer.json create mode 100755 modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/composer.lock create mode 100755 modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/dbdata.sql create mode 100644 modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/fake_admin_browser.js create mode 100755 modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/index.php create mode 100755 modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/login.php create mode 100755 modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/logout.php create mode 100755 modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/mysql.php create mode 100755 modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/register.php create mode 100755 modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/setup_mysql.php create mode 100644 modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/trigger_fake_admin.php create mode 100644 modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/trigger_fake_admin_2.php create mode 100644 modules/vulnerabilities/unix/webapp/btn_xss_challenge/manifests/configure.pp create mode 100644 modules/vulnerabilities/unix/webapp/btn_xss_challenge/manifests/init.pp create mode 100644 modules/vulnerabilities/unix/webapp/btn_xss_challenge/manifests/install.pp create mode 100644 modules/vulnerabilities/unix/webapp/btn_xss_challenge/secgen_metadata.xml diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/btn_xss_challenge.pp b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/btn_xss_challenge.pp new file mode 100644 index 000000000..620986a04 --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/btn_xss_challenge.pp @@ -0,0 +1 @@ +require btn_xss_challenge \ No newline at end of file diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/README.md b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/README.md new file mode 100755 index 000000000..540efe0ac --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/README.md @@ -0,0 +1,13 @@ +# XSS Cookie Stealing Challenge + +Challenge: See if you can become logged in as the "admin" user. + +Note that to do so, you'll need to create your own account and create an XSS attack on your user profile. + +For purposes of this challenge, anything you successfully "alert()" in the admin's browser will be passed along to you. (Admin browser is simulated using phantomjs) + +Deploy to your own Heroku instance with this button below, or try out our live demo [HERE](https://ctf-xss-challenge.herokuapp.com/) (not guaranteed to be up). + +[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy) + +Note that useful information for testing and debugging will be logged to the Papertrail app in your heroku instance. Open papertrail to view those streaming logs. diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/app.json b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/app.json new file mode 100755 index 000000000..ed3f15b6c --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/app.json @@ -0,0 +1,21 @@ +{ + "env": { + "CTF_FLAG": "PUT-FLAG-HERE" + }, + "addons": [ + "papertrail", + "cleardb" + ], + "success_url": "/index.php", + "scripts": { + "postdeploy": "php setup_mysql.php" + }, + "buildpacks": [ + { + "url": "https://github.com/heroku/heroku-buildpack-php" + }, + { + "url": "https://github.com/stomita/heroku-buildpack-phantomjs" + } + ] +} diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/authenticate.php b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/authenticate.php new file mode 100755 index 000000000..74e5f8a21 --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/authenticate.php @@ -0,0 +1,19 @@ +> Back"); +} +else +{ + $mem = mysql_fetch_assoc($uq); + $_SESSION['id'] = $mem['id']; + setcookie("hint", 'use-these-cookies-to-login-as-admin', time()+36000); + header("Location: /index.php"); + exit; +} diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/composer.json b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/composer.json new file mode 100755 index 000000000..e09c14372 --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/composer.json @@ -0,0 +1,6 @@ +{ + "require": { + "ext-mysql": "*", + "ext-mbstring":"*" + } +} \ No newline at end of file diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/composer.lock b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/composer.lock new file mode 100755 index 000000000..19e8d772f --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/composer.lock @@ -0,0 +1,21 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "4032f9a7678ad10ae1a13e7369f85d34", + "content-hash": "a243a4e7654fee2a753e9fd9e0f4aec1", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "ext-mysql": "*", + "ext-mbstring": "*" + }, + "platform-dev": [] +} diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/dbdata.sql b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/dbdata.sql new file mode 100755 index 000000000..bc8e43a6c --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/dbdata.sql @@ -0,0 +1,8 @@ +DROP TABLE IF EXISTS `users`; +CREATE TABLE `users` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `username` varchar(20) NOT NULL DEFAULT '', + `password` varchar(255) NOT NULL DEFAULT '', + `profile_desc` longtext NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; \ No newline at end of file diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/fake_admin_browser.js b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/fake_admin_browser.js new file mode 100644 index 000000000..db87452bd --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/fake_admin_browser.js @@ -0,0 +1,41 @@ +// Locally: phantomjs fake_admin_browser.js --url test.com +// Heroku: /app/vendor/phantomjs/bin/phantomjs fake_admin_browser.js --url test.com + +var system = require('system'); +var base_url = "http://localhost:8888/"; +var password = ""; +var profileid = 0; + +if (system.args.length === 1) { + console.log('Try to pass some args when invoking this script!'); +} else { + system.args.forEach(function (arg, i) { + if (i == 2) { + base_url = arg; + } + if (i == 4) { + password = arg; + } + if (i == 6) { + profileid = arg; + } + }); +} + +function open_target_profile(profileid) { + var userprofilepage = require('webpage').create(); + userprofilepage.onAlert = function(alertmsg) { + console.log(alertmsg); + } + userprofilepage.open(base_url+"index.php?id="+profileid, function (status) { + setTimeout(function(){ + phantom.exit(0); + }, 3000); + }); +} + +var loginpage = require('webpage').create(); +loginpage.open(base_url+'authenticate.php', 'post', 'username=admin&password='+password+'&save=OFF', function (status) { + + open_target_profile(profileid); +}); diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/index.php b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/index.php new file mode 100755 index 000000000..faaea2dea --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/index.php @@ -0,0 +1,82 @@ + + + + +
+
+ 's Profile + +

+

+

+

+

+

+

+

+

+

+
+ CTF Flag: ".$ctf_flag.""; + } + else { + print "CTF Flag: [disabled] - Must be logged in as admin to access."; + } + ?> +
+ +
+ +
+ Update your Profile Description +
+ Current Value:
+
+ +
+
+ +


+ + + +


+ > LOGOUT +
diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/login.php b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/login.php new file mode 100755 index 000000000..de7d3983b --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/login.php @@ -0,0 +1,38 @@ + + + + +BreakTheNet + + +

+ > BreakTheNet Log-In +

+ + + + + +
+
+ About BreakTheNet + An XSS challenge - see if you can become logged in as the "admin" user.

+ Note that to do so, you'll need to create your own account and create an XSS attack on your user profile.

+ For purposes of this challenge, anything you successfully "alert()" in the admin's browser will be passed along to you.

+ Feel free to review the source code as part of the challenge here. +
+
+
+ Login +
+ Username:
+ Password:
+ +
+
+

+

+ REGISTER NOW! +


+ + diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/logout.php b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/logout.php new file mode 100755 index 000000000..40561b28a --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/logout.php @@ -0,0 +1,5 @@ + + + + + + +breakthenet + + + +> Login"; + } +} +else +{ + ?> +

+ Register +

+
+ Username:
+ + Password:
+ +

+ > Go Back + + + diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/setup_mysql.php b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/setup_mysql.php new file mode 100755 index 000000000..e99ffcdb9 --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/setup_mysql.php @@ -0,0 +1,34 @@ +
+ + diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/trigger_fake_admin_2.php b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/trigger_fake_admin_2.php new file mode 100644 index 000000000..761dcb986 --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/files/trigger_fake_admin_2.php @@ -0,0 +1,10 @@ +
"; +print "We caught an admin! Our XSS caught this information via alert():"; +print "
"; +print nl2br($results); +print "
"; \ No newline at end of file diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/manifests/configure.pp b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/manifests/configure.pp new file mode 100644 index 000000000..e1dd8960e --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/manifests/configure.pp @@ -0,0 +1,13 @@ +class btn_xss_challenge::configure { + $json_inputs = base64('decode', $::base64_inputs) + $secgen_parameters = parsejson($json_inputs) + + + # Create www-data user in mysql + ::mysql::db { 'mydb': + user => 'www-data', + password => 'example', + host => 'localhost', + grant => ['SELECT', 'UPDATE'], + } +} \ No newline at end of file diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/manifests/init.pp b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/manifests/init.pp new file mode 100644 index 000000000..356cc92c9 --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/manifests/init.pp @@ -0,0 +1,4 @@ +class btn_xss_challenge{ + require btn_xss_challenge::install + require btn_xss_challenge::configure +} \ No newline at end of file diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/manifests/install.pp b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/manifests/install.pp new file mode 100644 index 000000000..3324747eb --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/manifests/install.pp @@ -0,0 +1,14 @@ +class btn_xss_challenge::install { + + Exec { path => ['/bin', '/usr/bin', '/usr/local/bin', '/sbin', '/usr/sbin'] } + + package { ['php5','php5-mysql']: + ensure => installed, + } + + file { 'btn_xss-copy_files': + path => '/var/www/challenge_dir', + source => "puppet:///modules/btn_xss_challenge", + recurse => true, + } +} \ No newline at end of file diff --git a/modules/vulnerabilities/unix/webapp/btn_xss_challenge/secgen_metadata.xml b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/secgen_metadata.xml new file mode 100644 index 000000000..3a3d2990b --- /dev/null +++ b/modules/vulnerabilities/unix/webapp/btn_xss_challenge/secgen_metadata.xml @@ -0,0 +1,39 @@ + + + + XSS Cookie Stealing Challenge + emeth- + Thomas Shaw + MIT + BreakTheNet - XSS Cookie Stealing Challenge. Try become the 'admin' user.For purposes of this challenge, + anything you successfully "alert()" in the admin's browser will be passed along to you. (Admin browser is simulated + using phantomjs). + + + webapp + xss_challenge + none + remote + linux + + strings_to_leak + + + + + + + + Create your own account and perform an XSS attack on your own user profile. + + + webapp + + + + modules/services/unix/http/lamp + + + \ No newline at end of file