[ALUG] Inserting a file into a telnet session

Brett Parker iDunno at sommitrealweird.co.uk
Tue Oct 9 16:48:25 BST 2007


On Tue, Oct 09, 2007 at 04:04:49PM +0100, Ted Harding wrote:
> So all I would need to do is copy that file, edit out unwanted
> headers and modify others, and then 'cat' the edited copy down
> the line after the 'data' command in SMTP.
> 
> Or that would be the case, if only I could find out how to 'cat
> it down the line' while still on that telnet connection!
> 
> (Perhaps one can see why ssh wouldn't work iin this case ... :))

Why not open the socket in your favourite programming language and parse
the responses etc... it should be relatively easy to knock up something
that does this in either python or perl...

Heck, this being pure telnet, you might even be able to just use expect
to do it...

Something like the attached script should give you an idea (OK - so
there's a bug in the attached script... but hey ;)

Cheers,
-- 
Brett Parker
-------------- next part --------------
#!/usr/bin/expect -f

spawn telnet amnesiac.heapspace.net 25

expect {
    220 {
        send "HELO test.host\n"
    } timeout {
        send_user "Timed out connecting to host"
        abort
    }
}

expect {
    250 {
        send "MAIL FROM: <brettp at sommitrealweird.co.uk>\n"
    } timeout {
        send_user "Timed out at MAIL FROM"
        abort
    } default {
        send_user "Something bad happened - aborting"
        abort
    }
}

expect {
    250 {
        send "RCPT TO: <brettp at sommitrealweird.co.uk>\n"
    } default {
        send_user "Something bad happened - aborting"
        abort
    }
}

expect {
    250 {
        send "DATA\n"
    } default {
        send_user "Something bad happened - aborting"
        abort
    }
}

expect {
    354 {
        send "From: Brett Parker <brettp at sommitrealweird.co.uk>\n"
        send "To: Brett Parker <brettp at sommitrealweird.co.uk>\n"
        send "Subject: Test Mail\n"
        send "\n\n"
    } default {
        send_user "Didn't get a 354 - giving up"
        abort
    }
}

send [exec cat test.txt]
send "\r\n.\r\n"

expect {
    250 {
        send_user "All done."
        exit
    } default {
        send_user "It broke, bah."
        abort
    }
}



More information about the main mailing list