Pretending to be an IMAP server using netcat

So, say you want to pretend to be an imap server using nc (can’t think of any good reason why you’d want to do this, we were trying to seriously confuse an iphone). So, you do something like:

cat - | nc -l -p 143 -v

And when the line

connect to [127.0.0.1] from localhost [127.0.0.1] 39656

appears you type

* OK myIMAPserver

If the client is you pretending to be an imap client or even mutt, you’ll find that you get a response. If, on the other hand, the client is an iPhone, you’ll get absolutely nothing. Why? Because the RFC for IMAP states:

All interactions transmitted by client and server are in the form of
lines; that is, strings that end with a CRLF.

CR is a carriage return (ascii code 0d), LF is a line feed (ascii code 0a)

But netcat doesn’t believe in sending CRs (fair enough I suppose, unix uses LF as the new line character, with windows using the CRLF pair). On OSX you can coax nc into sending a CRLF by typing CTRL+V and then pressing return twice. Once you do that, the iPhone starts talking to you (in a REALLY insecure manner, but that’s another story

Fun.

One Response to “Pretending to be an IMAP server using netcat”

  1. sed -e ’s/$/\r/’ | nc -l -p 143 -v

Leave a Reply