?

Log in

Tracking down compromised email accounts - I'm on the downeaster alexa

> Recent Entries
> Archive
> Friends
> Profile
> Gushi Land!

August 26th, 2014


Previous Entry Share Next Entry
11:42 pm - Tracking down compromised email accounts

Mitigating a Mail Server Attack

Analysis

A few days ago, I noticed an unusual number of bounceback messages from one specific user directed at yahoo.com email addresses. When I looked inside the mail queue, I noticed that each message had dozens of recipients.

The troubling thing is, looking at the mail logs, I saw the dreaded line

maillog.7.bz2:Aug 18 21:33:08 <mail.info> prime sm-mta[80096]: 
AUTH=server, relay=[84.32.158.42], authid=vivian@littlestdomain.com, 
mech=PLAIN, bits=0

The AUTH=server bit tells me that rather than a rogue script running here (a not-uncommon thing that happens when you let users run PHP scripts), this was an actual password that got leaked, and was being used to send mail just as a regular user would.

I quickly concluded "compromised account", changed the user's password, and contacted them out-of-band with a new password. Life seemed good.

...then I noticed a second account doing the same thing. Okay, that's weird. Maybe my users have started falling for a really effective phishing scam?

When it happened a third time, a few days later, I recalled the old Ian Fleming quote:

"Once is happenstance. Twice is coincidence. Three times, it's enemy action."

Combat Perl

So, faced with the task of seeing if there were any other users who were affected, I wrote a short little bit of perl code to analyze my mail logs, and spit out each login, as well as the number of times each IP had logged in.

The code looks like this. No, there's no fancy "use Strict" or anything like that. I used YAML as an output format because writing "Dump" is easier than writing a foreach loop to iterate over the hashes.

#!/usr/bin/perl

use YAML;
open FOO, "/usr/bin/bzgrep -i \"auth=server\" /var/log/maillog.0.bz2|";
my @lines = <FOO>;
my %thing;
foreach my $line (@lines) {
  chomp $line;
  if ($line =~ /\[(\d+\.\d+\.\d+\.\d+)\].*authid=(\S+),/) {
        print "ip address $1 authid $2 found in $line\n";
        $thing{$2}{$1}++;
  }
}

print Dump %thing;

Combat perl output

The code above produced output like what I have here. Note that I've altered all the logins and none of the below actually exist on my system. The IP addresses and counts, however, are real.

--- jim
---
209.85.219.47: 1
216.15.173.10: 4
--- bob
---
107.144.99.110: 1
--- moe
---
107.144.99.110: 10
--- curly@curly.net
---
163.23.34.45: 9
177.19.195.242: 10
177.55.38.11: 3
177.6.83.93: 1
179.182.193.136: 2
179.182.198.161: 3
186.222.71.36: 2
187.110.215.243: 6
187.35.157.21: 1
188.11.56.33: 4
189.75.25.147: 9
190.220.7.227: 2
193.152.213.171: 7
193.32.77.45: 4
200.63.165.85: 2
201.15.121.108: 3
201.216.221.245: 3
201.231.237.7: 4
201.41.166.52: 5
201.7.227.106: 1
201.77.115.15: 2
212.174.233.143: 4
212.40.242.27: 6
213.98.140.39: 4
213.98.78.213: 2
217.149.97.78: 5
217.216.67.202: 2
217.7.241.62: 1
219.92.29.90: 10
31.145.8.126: 3
37.159.194.66: 8
46.25.232.183: 1
50.79.128.153: 4
62.42.1.181: 1
66.17.46.53: 4
72.67.57.38: 3
77.229.13.35: 7
77.231.97.130: 7
78.186.71.8: 7
78.188.184.173: 5
78.188.19.231: 6
78.189.53.17: 2
80.35.0.235: 3
81.133.208.133: 4
81.142.195.149: 3
81.149.106.151: 2
81.214.85.206: 7
81.215.226.231: 13
81.218.104.229: 4
81.45.181.255: 4
82.108.126.242: 1
82.127.51.45: 2
82.153.165.168: 8
82.85.115.185: 5
82.91.75.35: 12
83.19.111.210: 3
83.56.26.36: 8
85.105.139.205: 7
85.105.85.72: 8
85.152.27.1: 2
85.251.7.78: 1
85.71.229.247: 3
87.139.118.153: 3
87.22.242.43: 2
87.23.197.245: 4
88.103.141.154: 6
88.12.31.52: 1
88.2.171.129: 4
88.247.171.72: 5
88.247.78.60: 5
88.248.23.202: 4
88.249.248.163: 4
88.250.240.101: 3
88.87.205.230: 3
88.9.119.148: 5
89.119.131.171: 4
92.56.76.179: 7
93.207.41.7: 1
95.236.181.166: 7
95.243.214.226: 1
95.60.124.88: 8
--- thing
---
67.68.160.180: 1
--- stuff
---
207.161.109.87: 2
--- steve
---
209.85.215.49: 1
209.85.217.180: 1
--- joe
---
70.117.105.120: 1

So, one of these things is not like the others. It's understandable that a person may have two or three ips in a given period. Their ips change, they're logging on from multiple computers.

Remember that these are ONLY the ip addresses pulled from the sendmail logs. Only on connections where a piece of mail is sent, using SMTP auth.

So, that curly@curly.net entry? Yeah, that is that what security researchers call a "snowshoe" attack -- not one server sending hundreds of mails (which would be easy to block), but instead, it's spread out, and even though I now have a list of ips I could block, what we're looking at here is a botnet of otherwise compromised machines on a dozen or more ISPs.

The other thing to note about the curly@curly.net entry is that it's a full user@domain entry. Put another way, it's an email address -- one where the LHS (left hand side) just so happens to match the user's actual login.

What was going on here is that the way I (and most people) do SMTP auth in sendmai, there can be a concept of multiple "realms" defined -- for example, to log in against different authentication databases. As I'm not using this feature, the realm and everything after is ignored (but still logged).

As I normally instruct my users to only use the barename to log in, any login using a full realm must be a compromised account.

Notifying the User

So, there's a problem here. While I can easily change the user's password and send them mail, this effectively locks them out of their account and keeps them from getting anything done until we touch base.

What I wanted to do was find a way to block the users who were using the "bad" format, while letting good users go on. I wanted a quick, guilt-free way to block the sending of mail, without breaking the communication link.

What I discovered was a ten year old post in the old usenet group comp.mail.sendmail, here.

With a little bit of tweaking, I had applied that same config to my own sendmail, and had configured a line in the access database to block a test user. The account still worked, but it wouldn't let them send mail. Perfect. I could block "curly@curly.com" without blocking "curly". (And yes, this relies on a little bit of obscurity -- but it's a botnet, not monkeys at typewriters, it's only going to try what it knows).

Identifying the source

So, three accounts with relatively secure passwords compromised in a week. What was the common thread? Could these people have all used the same insecure passwordless wifi networks? Is there some newfangled router exploit that mails your traffic all off to the highest bidder?

I spoke to all the users. None of them had fallen for any phishing emails. They were running different OSes, so a password-stealing virus was out. And then it hit me. Like a ton of bricks.

I've recently seen a surge of spam to addresses like macromedia-at-gushi.org, adobe-at-gushi.org, adobe2012-at-gushi.org.
The reason?

Well, it's all because adobe sucks at securing your data.
Sometime last year, people were able to download 150 million usernames and passwords from adobe's backend servers. And, as the article I just linked will tell you, those passwords were encrypted weakly, and in a way that all the users had the same encrypted password string, for a given password.

While I'm not 100 percent sure this was the attack vector -- there's been several other leaks that happened (last.fm, Linkedin, E-harmony), and about 90 percent sure that this is the likely cause, even if I don't know which site it was that ultimately spilled my users' beans.


(4 comments | Leave a comment)

Comments:


[User Picture]
From:gushi
Date:August 27th, 2014 07:28 pm (UTC)
(Link)
Short version: People's passwords were being used to send mail from their domains, through my server. With all the "trust" that my server provides (i.e. it looked to other people's spam filters as not-spoofed). I found some patterns in there that let me identify it easily.

What you need to do: If I haven't bugged you, nothing, but like everyone says, don't use the same password everywhere and change your passwords regularly.


> Go to Top
LiveJournal.com