Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- Copyright (c) 2012, HackThisSite.org
- All rights reserved.
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the HackThisSite.org nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- /**
- * Authors:
- * Bren2010 ( Brendan Mc. )
- **/
- class HTSMission {
- // Edit these -- they will be assigned to you.
- var $serverId = 0;
- var $missionId = 0;
- // Do not edit these
- var $remoteUrl = 'hackthissite.org';
- var $remotePort = '51064';
- var $userId;
- // Initiates class. You should call this on every page load, but
- // it is fine if you only call it on the index page and the
- // winning page of the mission.
- public function __construct() {
- if (!isset($_SESSION)) session_start();
- if (!empty($_SESSION['userId'])) $this->userId = $_SESSION['userId'];
- if (!empty($_GET['userId'])) {
- $_SESSION['userId'] = (int) $_GET['userId'];
- header('Location: ' . $_SERVER['PHP_SELF']);
- die;
- } else if (empty($_SESSION['userId']) && empty($_GET['userId'])) {
- die('Access denied.');
- }
- }
- // Call to mark mission as completed.
- public function finish() {
- $socket = @fsockopen($this->remoteUrl, $this->remotePort, $errno, $errstr, 1);
- if (!$socket) die('Unable to connect to HackThisSite\'s servers!
- Please contact a HackThisSite developer.');
- $info = stream_get_meta_data($socket);
- if ($info['timed_out']) die('Coult not contact HTS.');
- $serverId = $this->uncompliment($this->serverId);
- $userId = $this->uncompliment($this->userId);
- $missionId = $this->uncompliment($this->missionId);
- $toWrite = '';
- foreach($serverId as $byte) { $toWrite .= chr($byte); }
- foreach ($userId as $byte) { $toWrite .= chr($byte); }
- foreach ($missionId as $byte) { $toWrite .= chr($byte); }
- fwrite($socket, $toWrite);
- fclose($socket);
- }
- private function uncompliment($integer) {
- $toReturn = array();
- while (true) {
- array_push($toReturn, $integer % 256);
- $integer = floor($integer / 256);
- if ($integer == 0) break;
- }
- return array_reverse(array_pad($toReturn, 4, 0));
- }
- }
Add Comment
Please, Sign In to add comment