I am trying to create a bash script to simulate a mail attack to our mailserver. For this reason i want to create a bash script to send hundred of mails to our server, but when i launch the command:
$telnet 192.168.12.1 25
<-- where 192.168.12.1 is the ip of our server
The telnet session start and all the commands that i write later aren't executed. I also tried to create a second script to launch command on the telnet session after that this one are been created, but when i write from the second script:
$echo -ne "EHLO domain.com\\r\\f"
It print the command but doesn't do the ENTER so the command is not taken. Any idea?
you should pipe the stdin script
telnet 192.168.12.1 25 < filenamewithcommands.txt
this will open the telnet command and pipe in all the character from the file, including returns
Try out
echo -ne "EHLO domain.com\\r\\n"
or
echo -e "EHLO domain.com\\r"
or simply try out something from here: http://mailtestingtools.blogspot.hu/ (it's in english)
End of line for SMTP is \\r\\n
, not \\r\\f
, but I don't think that is your problem. When you do something like this:
telnet mailhost 25 < commands.txt
The data in the text file will be sent immediately to the mailserver, and then the connection will be closed, which will prevent the mailserver's response from being seen. You'll probably find that:
{ cat commands.txt; sleep 1; } | telnet mailhost.25
lets you see the responses. (I agree with the comment that nc
(netcat) is a better tool for this type of work than telnet
).
That's probably not the best way to test a mailbomb, but it might get you started.
Note: ESMTP (that is, a session started with EHLO
rather than HELO
) may use "pipelining" if the server indicates that it will accept that by responding 250-PIPELINING
to the EHLO
, but you are still expected to wait for the server to respond 250 OK
to the DATA
. See RFC 2920 for details.
None of the above worked. I found a solution. I used the expect command. This is what i write on my terminal to send 4 mails:
for i in {1..4} do expect ./telnet.exp 192.168.12.1 abc@hotmail.com vmail@ho.tld done
the command "expect" read the commands in the file telnet.exp, contact the server with the ip 192.168.12.1 and send an email from abc@hotmail.com to vmail@gmail.com
Content of the file telnet.exp:
#! /usr/bin/expect
set timeout 20
set server [lindex $argv 0]
set sndr_mail [lindex $argv 1]
set rcpt_mail [lindex $argv 2]
set ts [timestamp -format "%Y-%m-%d %H:%M:%S"]
spawn telnet $server 25
expect "Connected to "
expect "220 "
send "HELO galaxy\n"
expect "250 "
send "MAIL FROM:<$sndr_mail>\n"
expect "250 "
send "RCPT TO:<$rcpt_mail>\n"
expect "250 "
send "DATA\n"
expect "354 "
send "From:$sndr_mail\n"
send "To:$rcpt_mail\n"
send "Subject:Testing $server\n\n"
send "Testing: $server\n"
send "Timestamp: $ts\n"
send ".\n"
expect "250 "
send "quit\n"
expect "221 "
# TIAF!
Thanks to everyone
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.