function warscore_function($socket, $pid) { # Init GWF $gwf = new GWF3(getcwd(), array('website_init' => false, 'autoload_modules' => false, 'load_module' => false, 'start_debug' => true, 'get_user' => false, 'log_request' => false, 'no_session' => true, 'store_last_url' => false, 'ignore_user_abort' => false)); gdo_db(); GWF_Debug::setDieOnError(false); GWF_HTML::init(); if (false === ($wechall = GWF_Module::loadModuleDB('WeChall', true, true, true))) { warscore_error($socket, 'Cannot load WeChall!'); } $wechall->includeClass('WC_Warbox'); $wechall->includeClass('WC_WarToken'); $wechall->includeClass('WC_Warflag'); $wechall->includeClass('WC_Warflags'); $wechall->includeClass('sites/warbox/WCSite_WARBOX'); if (false === ($input = socket_read($socket, 2048))) { warscore_error($socket, 'Read Error 1!'); } warscore_debug("GOT INPUT: {$input}"); if (false === ($username = Common::substrUntil($input, "\n", false))) { warscore_error($socket, 'No username sent!'); } if (false === ($user = GWF_User::getByName($username))) { warscore_error($socket, 'Unknown user!'); } warscore_debug("GOT USER: {$username}"); if ('' === ($token = Common::substrFrom($input, "\n", ''))) { warscore_error($socket, 'No token sent!'); } $token = trim(Common::substrUntil($token, "\n", $token)); if (!WC_WarToken::isValidWarToken($user, $token)) { warscore_error($socket, 'Invalid Token!'); } if (!socket_getpeername($socket, $client_ip, $client_port)) { warscore_error($socket, 'Socket Error 2!'); } echo "{$client_ip}\n"; $boxes = WC_Warbox::getByIP($client_ip); if (count($boxes) === 0) { warscore_error($socket, 'Unknown Warbox!'); } warscore_debug("GOT N BOXES: " . count($boxes)); $curr_port = 0; foreach ($boxes as $box) { $box instanceof WC_Warbox; if ($curr_port !== $box->getVar('wb_port')) { $curr_port = $box->getVar('wb_port'); warscore_identd($socket, $box, $user, $client_ip, $client_port); } } socket_write($socket, 'Bailing out! You should not see me.'); socket_close($socket); die(0); }
function math_pyramid_check(WC_Challenge $chall, $formula, $maxlen, $precision = 4) { error_reporting(E_ERROR); GWF_Debug::setDieOnError(false); GWF_Debug::setMailOnError(false); $len = strlen($formula); $tests = array('0' => 0, '1' => 0.2357, '3.14' => 7.2971, '10' => 235.7023, '100' => 235702.2604); $eval = new EvalMath(); $fa = "f(a) = {$formula}"; if (false === $eval->evaluate($fa)) { echo GWF_HTML::error('Math Pyramid', $chall->lang('err_formula', array(htmlspecialchars($fa)))); return false; } GWF_Debug::setDieOnError(true); GWF_Debug::setMailOnError(true); $back = GWF_HTML::message('Math Pyramid', $chall->lang('msg_formula', array(htmlspecialchars($fa))), false); $correct = 0; foreach ($tests as $a => $result) { $result2 = $eval->evaluate("f({$a})"); $result = sprintf('%.0' . $precision . 'f', $result); $result2 = sprintf('%.0' . $precision . 'f', $result2); if ($result === $result2) { $back .= GWF_HTML::message('Math Pyramid', $chall->lang('msg_correct', array($a, $result2, $result)), false); $correct++; } else { $back .= GWF_HTML::error('Math Pyramid', $chall->lang('err_wrong', array($a, $result2, $result)), false); } } require_once GWF_CORE_PATH . 'module/WeChall/WC_MathChall.php'; if ($chall->getID() > 0 && $correct === count($tests)) { if (false === WC_MathChall::insertSolution($chall->getID(), GWF_Session::getUserID(), $formula)) { $back .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } else { $back .= GWF_HTML::message('Math Pyramid', WC_HTML::lang('msg_wmc_sol_inserted', array($len, WC_MathChall::getLimitedHREF($chall, $len))), false); } } # Check Len if ($len > $maxlen) { $back .= GWF_HTML::error('Math Pyramid', $chall->lang('err_too_long', array($len, $maxlen)), false); } echo $back; if ($correct === count($tests) && $len <= $maxlen) { if ($len < $maxlen) { echo GWF_HTML::message('Math Pyramid', $chall->lang('msg_new_record', array($len, $maxlen)), false); GWF_Settings::setSetting('WC_MATH_PYRAMID', $len); } $chall->onChallengeSolved(GWF_Session::getUserID()); } }
<?php # WeChall things chdir('../../../'); define('GWF_PAGE_TITLE', 'PHP 0819'); require_once 'challenge/html_head.php'; if (false === ($chall = WC_Challenge::getByTitle(GWF_PAGE_TITLE))) { $chall = WC_Challenge::dummyChallenge(GWF_PAGE_TITLE, 2, 'challenge/space/php0819/index.php', false); } $chall->showHeader(); ############### ## Challenge ## ############### GWF_Debug::setDieOnError(false); GWF_Debug::setMailOnError(false); require_once 'challenge/space/php0819/php0819.php'; echo GWF_Box::box($chall->lang('info', array(GWF_WEB_ROOT . 'profile/space')), $chall->lang('title')); if (isset($_GET['eval'])) { if (true === $challenge()) { $chall->onChallengeSolved(GWF_Session::getUserID()); } } GWF_Debug::setDieOnError(true); GWF_Debug::setMailOnError(true); $filename = 'challenge/space/php0819/php0819.php'; $message = '[PHP]' . file_get_contents($filename) . '[/PHP]'; echo GWF_Message::display($message); # TODO: GET form input box? (gizmore) echo $chall->copyrightFooter(); require_once 'challenge/html_foot.php';
/** * The GWF-Installation-Wizard * @author spaceone * @author gizmore */ header('Content-Type: text/html; charset=UTF-8'); # Load Install-Core require_once GWF_CORE_PATH . 'inc/install/GWF_InstallWizard.php'; require_once GWF_CORE_PATH . 'inc/install/GWF_InstallConfig.php'; require_once GWF_CORE_PATH . 'inc/install/GWF_InstallFunctions.php'; require_once GWF_CORE_PATH . 'inc/install/GWF_InstallWizardLanguage.php'; // define('GWF_INSTALLATION', true); define('GWF_STEP', Common::getGetString('step', '0')); define('GWF_LOGGING_PATH', getcwd() . '/protected/installog'); $gwf = new GWF3(getcwd(), array('website_init' => false, 'autoload_modules' => false, 'load_module' => false, 'load_config' => false, 'start_debug' => true, 'get_user' => false, 'do_logging' => true, 'log_request' => true, 'blocking' => false, 'no_session' => true, 'store_last_url' => false, 'ignore_user_abort' => true)); GWF_Debug::setDieOnError(false); # Website init GWF_InstallWizardLanguage::init(); GWF_HTML::init(); # Set install language $il = new GWF_LangTrans(GWF_CORE_PATH . 'lang/install/install'); GWF_InstallWizard::setGWFIL($il); # Design init GWF3::setDesign('install'); GWF_Website::addCSS(GWF_WEB_ROOT . 'tpl/install/css/install.css'); GWF_Website::addCSS(GWF_WEB_ROOT . 'tpl/install/css/design.css'); GWF_Website::setPageTitle('GWF Install Wizard'); $tVars = array('gwfpath' => GWF_PATH, 'gwfwebpath' => GWF_WWW_PATH, 'step' => GWF_STEP, 'il' => $il, 'steps' => 11, 'timings' => GWF_DebugInfo::getTimings()); GWF_Template::addMainTvars($tVars); if (false !== Common::getPost('create_admin')) { $page = GWF_InstallWizard::wizard_9_1();
function Upgrade_WeChall_5_06(Module_WeChall $module) { GWF_Website::addDefaultOutput(GWF_HTML::message('WC5', "Database additions for speedy warboxes.")); gdo_db()->setDieOnError(false); GWF_Debug::setDieOnError(false); $back = ''; # Copy warchalls to warflags table $module->includeClass('WC_Warchall'); $module->includeClass('WC_Warchalls'); $module->includeClass('WC_Warflag'); $module->includeClass('WC_Warflags'); $flag = GDO::table('WC_Warflag'); $flags = GDO::table('WC_Warflags'); # if (!$flag->createColumn('wf_solvers')) { $back .= GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__)); } if (!$flag->createColumn('wf_options')) { $back .= GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__)); } if (!$flag->dropColumn('wf_flag')) { $back .= GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__)); } $flag->update("wf_options=1"); $now = GWF_Time::getDate(); $chall = GDO::table('WC_Warchall'); $challs = GDO::table('WC_Warchalls'); foreach ($chall->selectAll('*', '', '', NULL, -1, -1, GDO::ARRAY_O) as $c) { $c instanceof WC_Warchall; $boxid = $c->getVar('wc_boxid'); $newflag = new WC_Warflag(array('wf_id' => '0', 'wf_wbid' => $boxid, 'wf_order' => '0', 'wf_cat' => 'exploit', 'wf_score' => '1', 'wf_solvers' => '0', 'wf_title' => $c->getVar('wc_level'), 'wf_url' => '', 'wf_authors' => 'Steven', 'wf_status' => 'up', 'wf_login' => '', 'wf_flag_enc' => NULL, 'wf_created_at' => $now, 'wf_last_solved_at' => NULL, 'wf_last_solved_by' => NULL, 'wf_options' => WC_Warflag::WARCHALL)); $newflag->replace(); $nfid = $newflag->getID(); foreach ($challs->selectAll('*', "wc_wcid={$c->getID()}", '', NULL, -1, -1, GDO::ARRAY_O) as $entry) { $entry instanceof WC_Warchalls; $flags->insertAssoc(array('wf_wfid' => $nfid, 'wf_uid' => $entry->getVar('wc_uid'), 'wf_solved_at' => $entry->getVar('wc_solved_at'), 'wf_attempts' => '1', 'wf_last_attempt' => NULL)); } } $flag->update("wf_solvers = (SELECT COUNT(*) FROM wc4_wc_warflags WHERE wf_wfid=wf_id)"); $flag->update("wf_last_solved_at = (SELECT MAX(wf_solved_at) FROM wc4_wc_warflags WHERE wf_wfid=wf_id)"); $flag->update("wf_last_solved_by = (SELECT wf_uid FROM wc4_wc_warflags WHERE wf_wfid=wf_id ORDER BY wf_solved_at DESC LIMIT 1)"); $module->includeClass('WC_Warbox'); $boxes = GDO::table('WC_Warbox'); if (!$boxes->createColumn('wb_players')) { $back .= GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__)); } if (!$boxes->createColumn('wb_flags')) { $back .= GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__)); } if (!$boxes->createColumn('wb_challs')) { $back .= GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__)); } if (!$boxes->createColumn('wb_totalscore')) { $back .= GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__)); } foreach ($boxes->selectAll('*', "", "", NULL, -1, -1, GDO::ARRAY_O) as $box) { $box instanceof WC_Warbox; $box->recalcPlayersAndScore(); } $box->update("wb_challs=(SELECT COUNT(*) FROM wc4_wc_warflag WHERE wf_wbid=wb_id)"); $box->update("wb_levels=(SELECT COUNT(*) FROM wc4_wc_warflag WHERE wf_wbid=wb_id AND wf_options&2)"); $box->update("wb_flags=(SELECT COUNT(*) FROM wc4_wc_warflag WHERE wf_wbid=wb_id AND wf_options&1)"); $chall->dropTable(); $challs->dropTable(); return $back; }