MIME Injection Attacks

Posted by robbiebow on 28 December, 2006 under perl | Be the First to Comment

Ever since the dawn of Matt’s formmail.cgi, there has been people wanting to use your CGIs to send emails to people you didn’t intend them to. MIME Injection attacks continue this tradition. They work by sending MIME headers in one of the form fields and following these by two new line characters. Providing the form field input is used by your script in the email headers (e.g. an email address supplied by the form used as the from: value) then this can result in your MTA thinking it has all the headers and everything after the two new lines is the body of the email.

An easy and effective way to make sure your script are safe from this sort of attack is to check the form data for MIME headers. I use a simple regex to do this and check any the form field that will be used in the email header with something like this in my scripts:

my $regexp = '(bcc|cc|content-type|to|from)\s*:';
foreach (qw(last_name first_name email)) {
if ($input->{$_} =~ /$regexp/is) {
warn Dumper($input);
die;
}
}

Why would anyone put "to:" or "bcc:" or "content-type:" in a name or email address field on a web form? I can think of no legitimate reason, so I just log the form submission for bedtime reading and crash out. If I’m running under FastCGI, I don’t die, I just return the thank you page and do nothing else seeing as killing off a script under FastCGI is a costly exercise in terms of resources to start it back up again.

Successfully reclaimed bank charges

Posted by robbiebow on 7 December, 2006 under stuff | Be the First to Comment

Hurrah! I’ve just learnt that my bank have repaid me £2004.25 worth of penalty charges from the last six years banking with them. I heard that bank penalty charges were unlawful a while ago. I looked around for more information and found Money Saving Expert had the info I needed. That led me to the excellent Consumer Action Group which is basically a consumer support group with advice on how the law stands, how to go about reclaiming your money, and even has templates for letters and spreadsheets to get you through to success.

Read more of this article »

Optimizing MySQL

Posted by robbiebow on 6 December, 2006 under geek | Be the First to Comment

One of the best ways to speed up any system that relies on a database is to optimize the database. So that’s what I did the other night for MySQL 5.0.24 running on a Windows box with a 3.2GHz processor and 2GB of RAM. The server uses a mixture of table types (InnoDB and MyISAM) and gets hit a lot with queries against tables that don’t change an awful lot. The resultant my.ini config should give you some ideas on how to optimize MySQL in a similar situation