Created
January 16, 2021 05:39
-
-
Save jakebathman/5c48af8380d1f9930c47993b6d6f5be9 to your computer and use it in GitHub Desktop.
Revisions
-
jakebathman created this gist
Jan 16, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ <?php $host = 'palindromer-bd7e0fc867d57915.elb.us-east-1.amazonaws.com'; $port = 7777; $socket = fsockopen($host, $port); if (! $socket) { die('Error: connection not successful'); } echo 'Processing lines '; while ($line = fgets($socket)) { echo '.'; // Divide the string into word chunks along spaces $words = explode(' ', $line); // Check for special line, denoting flag if (stripos($line, '!!!') === 0) { if (preg_match('/!!! flag\[(.*?)\]/i', $line, $matches)) { $response = $matches[1] . "\n"; echo "\n\nFlag received: {$response}"; fputs($socket, $response); return fclose($socket); } } // Get the palindromes $return = []; foreach ($words as $word) { if (isPalindromic($word)) { $return[] = $word; } } // Must respond with newline at the end $response = trim(implode(' ', $return)) . "\n"; // Send response string fputs($socket, $response); } function isPalindromic($word) { $word = trim($word); return $word == strrev($word); }