Skip to content

Instantly share code, notes, and snippets.

@msaladna
Created January 18, 2020 19:33
Show Gist options
  • Save msaladna/7fc0229b007422b3c96fa8b638f12b2f to your computer and use it in GitHub Desktop.
Save msaladna/7fc0229b007422b3c96fa8b638f12b2f to your computer and use it in GitHub Desktop.
Simple SMTP auth test
<?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