Created
January 18, 2020 19:33
-
-
Save msaladna/7fc0229b007422b3c96fa8b638f12b2f to your computer and use it in GitHub Desktop.
Simple SMTP auth test
This file contains 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 characters
<?php declare(strict_types=1); | |
function connect(string $user, string $pass) | |
{ | |
$host = '192.168.0.147'; | |
$errno = $errstr = null; | |
if (!($socket = fsockopen($host, 587, $errno, $errstr, 15))) { | |
die("Failed to connect to $host"); | |
} | |
server_parse($socket, '220'); | |
fwrite($socket, "EHLO randohost\r\n"); | |
server_parse($socket, '250'); | |
fwrite($socket, 'AUTH LOGIN' . "\r\n"); | |
server_parse($socket, '334'); | |
fwrite($socket, base64_encode($user) . "\r\n"); | |
server_parse($socket, '334'); | |
fwrite($socket, base64_encode($pass) . "\r\n"); | |
if (server_parse($socket, '235')) { | |
echo "Found a match! $user:$pass\n"; | |
} | |
fwrite($socket, 'QUIT' . "\r\n"); | |
fclose($socket); | |
return true; | |
} | |
//Functin to Processes Server Response Codes | |
function server_parse($socket, $expected) | |
{ | |
$server_response = ''; | |
do { | |
if (!($server_response = fgets($socket, 256))) { | |
die('Error while fetching server response codes. Expected: ' . $expected); | |
} | |
} while ($server_response[3] !== ' '); | |
return strpos($server_response, $expected) === 0; | |
} | |
$usage = getrusage(); | |
connect("foo", "bar"); | |
$finusage = getrusage(); | |
foreach ($usage as $k => $v) { | |
echo "$k: ", ($finusage[$k] - $v), "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment