Ultimate Birthday Email(s)

Once upon a time my evil side decided to email someone Happy Birthday… From the whole company.

We have an LDAP directory containing everyone’s name and email but it can easily be retro fitted for Windows AD or a CSV file.

I used the mutt progam to spoof the headers but there is another way using netcat (nc) I have outlines here.

Let’s begin with email.sh:

#!/bin/sh
# email.sh - Reads email addresses and names from ldap and and generates fake emails to people
# http://www.hax.nu

ldapsearch -xLLL cn mail | while read line
do
# find the name of the user:
        if echo ${line:0:2} | grep cn > /dev/null; then
                name=`echo $line | sed 's/cn: //'`
#               echo name = $name
        fi
# find the mail:
        if echo ${line:0:4} | grep mail > /dev/null; then
                mail=`echo $line | sed 's/mail: //'`
#               echo mail = $mail
        fi
# if we have both of those, let's send the email 
        if echo ${line:0:2} | grep dn >/dev/null; then
                if [ "x" == "x$name" ] ; then
                        mail=''
                        name=''
                fi
                if [ "x" == "x$mail" ] ; then
                        mail=''
                        name=''
                fi
                if [ "x" != "x$mail" ] ; then
                        subj=`~/randline.sh ~/bday.txt`
                        echo done $name $mail
                        cat ~/email_template.txt | sed "s/_SUBJECT_/$subj/g" | sed "s/_NAME_/$name/g" | sed "s/_EMAIL_/$mail/g" > /tmp/x_email.txt
                        echo | mutt -H /tmp/x_email.txt
                fi
        fi

done
rm /tmp/x_email.txt

This assumes your LDAP is either public or you have a secret file in place for your credentials.

Contents of ~/randline.sh:

#!/bin/sh
# randline - Reads random line from a file
# http://www.hax.nu

if [ $# -lt 1 ]; then
        echo "usage: $0 <file>"
        exit
fi

# Get Line count
LINES=`wc -l $1 | awk '{ print ($1 + 1) }'`

# Get offset
RN=$[ ($RANDOM + $RANDOM) % $LINES + 1 ]

# Fetch single random line. 
head -n $RN $1 | tail -n 1 

Then you need your list of subject lines stored in ~/bday.txt:

Happy bday!
Yo happy birthday old man.
HB!
old old old....
happy birthday.
There is a 'pp' in happy birthday. But there is no 'pp' in OLD.
Happy Birthday!
H... app... y... Happy Birthday!
H.a.p.p.y Birthday!
Happy Birthday!!
Happy Birthday!!!
Happy Birthday.
HAPPY BIRTHDAY!
OMG HAPPY BIRTHDAY!
WTF WHO IS OLD?!?!
Peace, old geezer :)

Then you’re going to want to customize your template ~/email_template.txt:

To: John Doe <john@doe.com>
From: _NAME_ 
Subject: _SUBJECT_

Happy birthday!

_NAME_

The last part is just run the script:

./email.sh

That’s all there is to it. You’re office is going to hate you forever now.

Goodluck! Feel free to leave a comment below with feedback and corrections. Also if you found this helpful and would like occasional updates of things happening in this arena subscribe to the newsletter. Thanks!

No Comments Yet

Leave a Reply

Your email address will not be published. Required fields are marked *