Advertisement
lollhosh

fucking_coffee

May 25th, 2017
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.59 KB | None | 0 0
  1. First create a folder and name it "HackerScripts"
  2.  
  3. Next create a file called "fucking_coffee.php"
  4.  
  5. and put it inside folder "HackerScripts"
  6.  
  7.  
  8. Example -
  9.  
  10. -Folder - HackerScripts
  11. - fucking_coffee.php
  12. - Folder - Telnet
  13. - Telnet.php
  14.  
  15.  
  16.  
  17. Code:
  18. <?php
  19. namespace HackerScripts;
  20.  
  21. /**
  22. * Class fucking_coffee
  23. *
  24. * @package HackerSripts
  25. *
  26. */
  27.  
  28. use HackerScripts\Lib\Telnet;
  29.  
  30. class fucking_coffee
  31. {
  32.  
  33. /**
  34. * The telnet class
  35. *
  36. * @var HackerScripts\Lib\Telnet
  37. */
  38.  
  39. protected $telnet;
  40.  
  41. /**
  42. * The password for this coffee machine
  43. *
  44. * @var string
  45. */
  46.  
  47. protected $password = "";
  48.  
  49. /**
  50. * The host of this coffee machine
  51. *
  52. * @var string
  53. */
  54.  
  55. protected $host = "";
  56.  
  57. /**
  58. * The port of this coffee machine
  59. *
  60. * @var string
  61. */
  62.  
  63. protected $port = "";
  64.  
  65. /**
  66. * Delay for 24 seconds.
  67. *
  68. * @var int
  69. */
  70.  
  71. protected $delay = 24;
  72.  
  73. /**
  74. * What we do when we construct this class
  75. */
  76.  
  77. public function __construct()
  78. {
  79.  
  80. /**
  81. * Lets not run this on the weekends
  82. */
  83.  
  84. if( $this->IsWeekend( date('m.d.y') ) == false )
  85. {
  86.  
  87. return false;
  88. }
  89.  
  90. /**
  91. * Create a new telnet class
  92. */
  93.  
  94. $this->telnet = new Telnet( $this->host, $this->port );
  95.  
  96. /**
  97. * Once we have completed this, we can brew our coffee!
  98. */
  99.  
  100. $this->BrewCoffee( function(){
  101.  
  102. /**
  103. * Echo out a message
  104. */
  105.  
  106. echo "coffee has been poured";
  107.  
  108. /**
  109. * Unset
  110. */
  111.  
  112. unset( $this->telnet );
  113. });
  114.  
  115. /**
  116. * Return tue
  117. */
  118.  
  119. return true;
  120. }
  121.  
  122. /**
  123. * Brews our coffee
  124. *
  125. * @param $callback
  126. */
  127.  
  128. public function BrewCoffee( $callback )
  129. {
  130.  
  131. if( $this->telnet != null )
  132. {
  133.  
  134. /**
  135. * Execute and enter the password
  136. */
  137.  
  138. $this->telnet->exec('Password: ' . $this->password);
  139.  
  140. /**
  141. * Brew the coffee
  142. */
  143.  
  144. $this->telnet->exec('sys brew');
  145.  
  146. /**
  147. * Wait
  148. */
  149.  
  150. sleep( $this->delay );
  151.  
  152. /**
  153. * Pour the coffee
  154. */
  155.  
  156. $this->telnet->exec('sys pour');
  157.  
  158. /**
  159. * Execute our callback
  160. */
  161.  
  162. call_user_func( $callback );
  163. }
  164. }
  165.  
  166. /**
  167. * Is this currently the weekend?
  168. *
  169. * @param $date
  170. *
  171. * @return bool
  172. */
  173.  
  174. public function IsWeekend( $date )
  175. {
  176.  
  177. if( date('N', strtotime( $date ) ) >= 6 )
  178. {
  179.  
  180. return true;
  181. }
  182.  
  183. return false;
  184. }
  185.  
  186. }
  187.  
  188. Create folder and name it "Lib" then create new php called "Telnet.php"
  189.  
  190. Code:
  191. <?php
  192. namespace HackerScripts\Lib;
  193.  
  194. /**
  195. * Telnet class
  196. *
  197. * Used to execute remote commands via telnet connection
  198. * Usess sockets functions and fgetc() to process result
  199. *
  200. * All methods throw Exceptions on error
  201. *
  202. * Written by Dalibor Andzakovic <dali@swerve.co.nz>
  203. * Based on the code originally written by Marc Ennaji and extended by
  204. * Matthias Blaser <mb@adfinis.ch>
  205. *
  206. * Extended by Christian Hammers <chammers@netcologne.de>
  207. * Modified by Frederik Sauer <fsa@dwarf.dk>
  208. *
  209. */
  210.  
  211. class Telnet {
  212.  
  213. private $host;
  214. private $port;
  215. private $timeout;
  216. private $stream_timeout_sec;
  217. private $stream_timeout_usec;
  218.  
  219. private $socket = NULL;
  220. private $buffer = NULL;
  221. private $prompt;
  222. private $errno;
  223. private $errstr;
  224. private $strip_prompt = TRUE;
  225.  
  226. private $NULL;
  227. private $DC1;
  228. private $WILL;
  229. private $WONT;
  230. private $DO;
  231. private $DONT;
  232. private $IAC;
  233.  
  234. private $global_buffer = '';
  235.  
  236. const TELNET_ERROR = FALSE;
  237. const TELNET_OK = TRUE;
  238.  
  239. public function __construct($host = '127.0.0.1', $port = '23', $timeout = 10, $prompt = '$', $stream_timeout = 1) {
  240. $this->host = $host;
  241. $this->port = $port;
  242. $this->timeout = $timeout;
  243. $this->setPrompt($prompt);
  244. $this->setStreamTimeout($stream_timeout);
  245.  
  246. // set some telnet special characters
  247. $this->NULL = chr(0);
  248. $this->DC1 = chr(17);
  249. $this->WILL = chr(251);
  250. $this->WONT = chr(252);
  251. $this->DO = chr(253);
  252. $this->DONT = chr(254);
  253. $this->IAC = chr(255);
  254.  
  255. $this->connect();
  256. }
  257.  
  258. public function __destruct() {
  259. // clean up resources
  260. $this->disconnect();
  261. $this->buffer = NULL;
  262. $this->global_buffer = NULL;
  263. }
  264.  
  265. public function connect() {
  266. // check if we need to convert host to IP
  267. if (!preg_match('/([0-9]{1,3}\\.){3,3}[0-9]{1,3}/', $this->host)) {
  268. $ip = gethostbyname($this->host);
  269.  
  270. if ($this->host == $ip) {
  271. throw new Exception("Cannot resolve $this->host");
  272. } else {
  273. $this->host = $ip;
  274. }
  275. }
  276.  
  277. // attempt connection - suppress warnings
  278. $this->socket = @fsockopen($this->host, $this->port, $this->errno, $this->errstr, $this->timeout);
  279.  
  280. if (!$this->socket) {
  281. throw new Exception("Cannot connect to $this->host on port $this->port");
  282. }
  283.  
  284. if (!empty($this->prompt)) {
  285. $this->waitPrompt();
  286. }
  287.  
  288. return self::TELNET_OK;
  289. }
  290.  
  291. public function disconnect() {
  292. if ($this->socket) {
  293. if (! fclose($this->socket)) {
  294. throw new Exception("Error while closing telnet socket");
  295. }
  296. $this->socket = NULL;
  297. }
  298. return self::TELNET_OK;
  299. }
  300.  
  301. public function exec($command, $add_newline = TRUE) {
  302. $this->write($command, $add_newline);
  303. $this->waitPrompt();
  304. return $this->getBuffer();
  305. }
  306.  
  307. public function login($username, $password) {
  308. try {
  309. $this->setPrompt('login:');
  310. $this->waitPrompt();
  311. $this->write($username);
  312. $this->setPrompt('Password:');
  313. $this->waitPrompt();
  314. $this->write($password);
  315. $this->setPrompt();
  316. $this->waitPrompt();
  317. } catch (Exception $e) {
  318. throw new Exception("Login failed.");
  319. }
  320.  
  321. return self::TELNET_OK;
  322. }
  323.  
  324. public function setPrompt($str = '$') {
  325. return $this->setRegexPrompt(preg_quote($str, '/'));
  326. }
  327.  
  328. public function setRegexPrompt($str = '\$') {
  329. $this->prompt = $str;
  330. return self::TELNET_OK;
  331. }
  332.  
  333. public function setStreamTimeout($timeout) {
  334. $this->stream_timeout_usec = (int)(fmod($timeout, 1) * 1000000);
  335. $this->stream_timeout_sec = (int)$timeout;
  336. }
  337.  
  338. public function stripPromptFromBuffer($strip) {
  339. $this->strip_prompt = $strip;
  340. } // function stripPromptFromBuffer
  341.  
  342. protected function getc() {
  343. stream_set_timeout($this->socket, $this->stream_timeout_sec, $this->stream_timeout_usec);
  344. $c = fgetc($this->socket);
  345. $this->global_buffer .= $c;
  346. return $c;
  347. }
  348.  
  349. public function clearBuffer() {
  350. $this->buffer = '';
  351. }
  352.  
  353. public function readTo($prompt) {
  354. if (!$this->socket) {
  355. throw new Exception("Telnet connection closed");
  356. }
  357.  
  358. // clear the buffer
  359. $this->clearBuffer();
  360.  
  361. $until_t = time() + $this->timeout;
  362. do {
  363. // time's up (loop can be exited at end or through continue!)
  364. if (time() > $until_t) {
  365. throw new Exception("Couldn't find the requested : '$prompt' within {$this->timeout} seconds");
  366. }
  367.  
  368. $c = $this->getc();
  369.  
  370. if ($c === FALSE) {
  371. if (empty($prompt)) {
  372. return self::TELNET_OK;
  373. }
  374. throw new Exception("Couldn't find the requested : '" . $prompt . "', it was not in the data returned from server: " . $this->buffer);
  375. }
  376.  
  377. // Interpreted As Command
  378. if ($c == $this->IAC) {
  379. if ($this->negotiateTelnetOptions()) {
  380. continue;
  381. }
  382. }
  383.  
  384. // append current char to global buffer
  385. $this->buffer .= $c;
  386.  
  387. // we've encountered the prompt. Break out of the loop
  388. if (!empty($prompt) && preg_match("/{$prompt}$/", $this->buffer)) {
  389. return self::TELNET_OK;
  390. }
  391.  
  392. } while ($c != $this->NULL || $c != $this->DC1);
  393. }
  394.  
  395. public function write($buffer, $add_newline = TRUE) {
  396. if (!$this->socket) {
  397. throw new Exception("Telnet connection closed");
  398. }
  399.  
  400. // clear buffer from last command
  401. $this->clearBuffer();
  402.  
  403. if ($add_newline == TRUE) {
  404. $buffer .= "\n";
  405. }
  406.  
  407. $this->global_buffer .= $buffer;
  408. if (!fwrite($this->socket, $buffer) < 0) {
  409. throw new Exception("Error writing to socket");
  410. }
  411.  
  412. return self::TELNET_OK;
  413. }
  414.  
  415. protected function getBuffer() {
  416. // Remove all carriage returns from line breaks
  417. $buf = preg_replace('/\r\n|\r/', "\n", $this->buffer);
  418. // Cut last line from buffer (almost always prompt)
  419. if ($this->strip_prompt) {
  420. $buf = explode("\n", $buf);
  421. unset($buf[count($buf) - 1]);
  422. $buf = implode("\n", $buf);
  423. }
  424. return trim($buf);
  425. }
  426.  
  427. public function getGlobalBuffer() {
  428. return $this->global_buffer;
  429. }
  430.  
  431. protected function negotiateTelnetOptions() {
  432. $c = $this->getc();
  433.  
  434. if ($c != $this->IAC) {
  435. if (($c == $this->DO) || ($c == $this->DONT)) {
  436. $opt = $this->getc();
  437. fwrite($this->socket, $this->IAC . $this->WONT . $opt);
  438. } else if (($c == $this->WILL) || ($c == $this->WONT)) {
  439. $opt = $this->getc();
  440. fwrite($this->socket, $this->IAC . $this->DONT . $opt);
  441. } else {
  442. throw new Exception('Error: unknown control character ' . ord($c));
  443. }
  444. } else {
  445. throw new Exception('Error: Something Wicked Happened');
  446. }
  447.  
  448. return self::TELNET_OK;
  449. }
  450.  
  451. protected function waitPrompt() {
  452. return $this->readTo($this->prompt);
  453. }
  454. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement