Wednesday, January 9, 2008

send emails using JScript + Netcat

Automated Email Sending From The Command Line Using JScript (CodeProject)
Send emails using JScript and Netcat. This technique can used for mailouts or load testing.
Download nc111nt.zip - 104.4 KB (NetCat for Windows)
Netcat for Windows is phenomenally powerful when driven from Windows Scripting Host!

Netcat On Windows Background
Netcat is a very powerful, open source (GPL 2) network tool that come originally from Unix. It is so powerful and easy to use that it has gained a bad reputation as a hacker tool. This is not what it was designed for, and indeed, many security professionals use it in the war against hackers.
var strExe = "nc -v smtp.myserver.co.uk 25";

var objShell = WScript.CreateObject("WScript.Shell");
var total = 512;
var delay = 0;
var victim = "oops@example.com";

for(var i=0;i<total;++i)
{
var strExeIn ="HELO nerds-central.com\r\n";
strExeIn+="MAIL FROM: <test@example.com>\r\n";
strExeIn+="RCPT TO: <"+victim+">\r\n";
strExeIn+="DATA\r\n";
strExeIn+="Body of email: this is an auto generated test email.\r\n";
strExeIn+="This is "+(i+1)+" of "+total+"\r\n";
strExeIn+=".\r\n";
strExeIn+="QUIT\r\n";

var objScriptExec = objShell.Exec(strExe);
objScriptExec.StdIn.write(strExeIn);
objScriptExec.StdIn.close();
WScript.echo("Sending "+(i+1)+" of "+total+" to "+victim);
WScript.echo(objScriptExec.StdOut.ReadAll());
WScript.sleep(delay);
}