Alright, so this is the Digital Cockroach Bait Station. Uh, we're gonna talk about how to build spam honeypots and who am I? Uh, I'm senior threat intelligence researcher with, uh, ThreatConnect and I'm on the TCERT team and I can't see a thing because of that light but I hope some of the team members are out there somewhere. But, uh, that's my Twitter handle Maur Utkonos. Uh, Utkonos is the, uh, Russian word for duckbill platypus, in case you were wondering. And also a few days ago I met the other, uh, person who happens to use the same, uh, handle at, at, uh, Black Hat. So, so why, why are we doing this? What is the, what are the, what are the problems that we're trying to solve and what requirements do we have? So, I, my requirements are that I need, uh, I need to, uh, I need to, uh, I need to, uh, I need to fresh malware samples and I need fresh malicious links. Uh, I also need fresh, uh, advanced fee fraud scams. So, um, you know, just to go over technical terms, advanced fee fraud is like the, um, the Nigerian prince that wants, uh, to send you a million dollars but he needs you to send him fifty dollars or a hundred dollars before you can get your million dollars from him. So, those are advanced fee fraud scams, uh, aka 419. And the, the goal of course in all of this is to get actionable threat intelligence. So, IOCs, um, IP addresses, um, spamming nodes, whatever, whatever it is that you're looking for but you need to know, uh, the intelligence. So, there's a, uh, sort of a, uh, difference in terminology. Um, I'm just gonna use them interchangeably because the idea of a spam trap and spam honeypot I think are almost exactly the same. Um, and to go to something that's an internet addiction can be quite complex. So spam traps are also email addresses. Those are created not for communication but to relies on, um, spam, so the point here is to get more spam and to get it from as many different sources as possible. And also to be able to track, uh, which address you sent over here, which address you put on this website, and then you can have metrics as to which, you know, which location for an email address is better at generating certain types of spam. Uh, neurotransmitters, uh, you know, and then therefore, you know, gathering certain types of botnets, certain types of binaries, and then you can figure out, alright, I should focus on seeding the email addresses in this area to get more of Y. I need to seed over here to get more of X. So, my background is biology and so I found it fascinating to, you know, kind of do a little bit of correlation or at least connection between biology and what I do now. And so I'm, I don't know if you recognize all of these bait traps, but this one is for cockroaches. I'm sure you all have seen those. The one in the center, the, so the subtitle there, the URL where I got it, that's actually, they actually named it wrong. It's not for cockroaches, that's actually for flies. Typically used for catching drosophila and that kind of stuff. But, or house flies, whatever type of flies you want to catch. That one's more of a general, you know, insect trap, where insects are going to slide down and they can't get up the sides and get out. This one's disgusting. That's, the brown slime that's on there is roach butter, I think it's called. And then the one on the left, or on my right, your left, I don't know. That one is driven by CO2. And this is probably the most disgusting of all of them. That's a bed bug trap. And I don't know if you know the way, the way the bed bugs operate is they follow CO2. So they're looking for your breath at night. So, moving on from the, the biology. So this is the diagram of, of a spam honeypot. And this is the whole idea here is to keep everything as simple as possible. Absolutely simple as possible. Because I don't want to spend time working on the spam honeypot. I want to spend time working, analyzing the data that I get from it. So, spam goes in. It's your choice as to what mail server you want to use. I use post fix now. I had started out using sendmail, but then I realized I didn't want to have two honeypots in the same thing. I didn't want to have just a, a sendmail honeypot in the same thing. I wanted to have two honeypots in the same thing. Inside of a spam honeypot. And so, uh, inside the mail server I have all of the incoming email processed by a Python script. And if any of you were at my workshop on Friday afternoon, uh, you have a copy of a simpler, a much simpler version of that, uh, Python script. And the goal there is to, uh, change the email headers and the rest of the email into, uh, JSON format. And then from there to insert that as, uh, uh, an indexable, uh, JSON document into Elasticsearch. So, I just wanted to cover a few definitions if you're not familiar with some of the things that I've been talking about. So, post fix is a general purpose mail server. Uh, I prefer using it on FreeBSD because I have a lot of experience with FreeBSD and hardening it. So, uh, that's my preferred operating system. Uh, JSON is JavaScript object notation, uh, it's a machine and human readable data interchange format. Uh, that's the website if you want to know more about it. If you haven't heard of JSON, uh, you must have heard of it. So, uh, Elasticsearch is a full text search engine. It's accessible via rest API. It stores documents. I'm going to try to raise my voice over So it stores documents in JSON, so it's perfect for my purpose of taking JSON and making something that I can search through and find commonalities among, you know, spam campaigns and so on. So the mail server configuration is the goal, it's very simple again. So you want to accept e-mail that's sent to any user name and sent to any domain. So you want it to be completely open, but you don't want it to reply to anything. You don't want it to send back bounce messages. You don't want to have any sort of outbound e-mail coming from it at all. Typically, you know, I change the host firewall so that it can't do anything outbound. And so, you know, obviously, anything at anything, so star, at star, at star, whatever you want to accept, you want to accept all of it. So the idea here is to make sure that when you're sending something to the server, you want it to process all inbound e-mail with a custom Python script and also naturally because it's a mail server, you get to, you get a copy of all the messages in the different, if you set it up for mbox or if you set it up for mail dir, you get a copy of all the messages nicely divided up by e-mail address that it was sent to. And so, the Python script and I see at least one person from class. So we went over this Python script in class and so I built it using e-mail.parser core module in Python. And I prefer Python 3, but the, for all intents and purposes, this particular library is almost the same in both 2 and 3, or 2.7 and 3 and above. And what I use it for is to translate all of the e-mail into JSON format, specifically the headers, so that the headers are divided up into key value pairs, which they already are in, you know, in an e-mail. And so, you know, it's, it's, it's, it's, it's, it's, it's, it's not really a real e-mail format, but it's just a flat text file, ah, and this way I've translated it into JSON and it's a little bit more usable, especially with Elasticsearch. So, ah, this is the slide where I could probably spend the next 10 hours, ah, talking about it. So, ah, so I've done, I've done a lot, a lot, a lot of thinking about, ah, e-mail headers and what data you can get from e-mail headers. Ah, how to use it and, and what it means. So, so divided this mind map into two components. So there's the header and the body. And the header, the first thing at the top, so that's the date time zone. And this is actually more important than would be obvious. So the date and time zone shows you either where the spammer, so this is a forgeable header field. But the time zone will show you the geographical approximate location of the origin IP address. So, you know, if you see some date time zones, the time zones that are in Eastern Europe, China, you know, these things are not a strong indicator, but they're still an indicator. So received SPF, this is actually an anti-spam header field. And so looking for things like SPF fail are, you know, a good way to find stuff that's nasty. DKIM, domain keys. So this is another anti-spam header. But this one is driven cryptographically. And one thing that was interesting was, so a couple years ago, LinkedIn had a fantastic idea of injecting their own spam in a man-in-the-middle system called intro. And intro basically broke DKIM very badly. And it was a very, very bad idea. So the next part is the hello string. This is the component of an SMTP handshake. And I don't know if anyone has done like a manual SMTP handshake by telnetting to port 25 on a mail server. So So the first thing that you do is you type ELHO or H-E-L-O and then you type in the, you give the mail server the domain that you theoretically are coming from. You can totally lie to many mail servers. Some mail servers will check whether that is related to the reverse DNS of the IP that you're coming from or not. This one is important. I think this one is very, very important for two reasons. First of all, if you're dealing with a piece of malware which sends out spam, it's obviously going to be connecting to a mail server to deliver the spam. And so it needs to be configured in advance with some sort of fake H-E-L-O string. It's not, if it's coming from a compromised workstation, obviously that, it doesn't, it might know, but it doesn't care what the, what the IP address is. So it's not going to be able to tell what the real domain name is if there even is one for that, you know, maybe it's someone's home, uh, home workstation and there's no domain that it can possibly figure out. So it can't tell the truth to a mail server. So it will be, uh, configured to either say the same thing over and over, so that's an indicator, or it'll have something similar to, uh, you know, a domain generation algorithm where it comes up with something that's different each time. However, because it's, because it's created algorithmically, uh, you can then use that as an indicator as well. If you can figure out what the algorithm is that it uses to generate that set, uh, or that type of, that, uh, that set of, um, domain names, you can then identify, uh, the particular, uh, botnet or, uh, piece of, uh, malware which is generating that particular piece of spam. The next part is the originating IP. So, you, your IP address is generated by the spam server. So, it's, you, obviously this is the IP address of the thing or the entity, whatever it is that's sending the spam out to your mail server, to your spam honeypot I should say. And there's a few ways, few things that you can do to analyze this particular piece of information. So these are the basics. Network who is, basically getting what the identity of the ISP or at least maybe lower ISP, the hosting company or maybe the local reseller of the IP address. And then GOIP, so the location of the IP address. Some of this, if you get the GOIP from network who is, it might not actually correlate with the real geographic location of that IP address, but at least it will give you a hint. And then ASN who is. ASN who is typically is a little bit cleanlier, cleaner than network who is. It, it's a little bit cleaner than network who is. Typically has better, better data in it than network who is. It's maintained a little bit better. R who is, this is, this is where if a particular IP address has been reassigned to maybe a, a hosting reseller or something like that, the R who is, the R who is data will contain the address and, and identity information of that reseller. Reply to, this is an important one. When we, when I was working with, when I was working with, when I was working with R, I was doing anti-phishing. This is basically the, if, if you're talking about a 419 scam or advanced fee fraud, the adversary needs to collect the replies to, to their, to their fraud scam. So typically the reply to address is not forged. Typically the reply to address, as long as it still exists and hasn't been taken down, has, you know, some slime ball actually reading the email that comes into that. So that's another important indicator there. Um, subject, obviously, uh, this is an indicator, very valuable. Uh, you, you have a new fax, please click here. Uh, or some such thing like that. And then the from address, this is typically forged. This is very easily forged. Um, and it could say almost anything. Uh, it might even be different than the reply to. So what's that? Uh, sure. Alright, now hard to concentrate. Um, alright, so envelope sender. This one is, uh, another component that comes from the SMTP handshake. So if you've, uh, again if we go back to the manual SMTP handshake, where we've got the H-E-L-O string, the next two things that you do is, uh, mail from and receipt to. So, uh, that one is, uh, typically, um, also an indicator. So this one, this one, uh, some mail servers will check whether this is, uh, um, has it. I'll try. Hold on. Uh, this one, this one, uh, some mail servers will check whether this is, uh, an indicator. Uh, so envelope sender, uh, also an indicator, obviously. Uh, return path, again, this is an indicator. X mailer, this is one that. So, uh, X mailer, this is one that I find important, uh, especially when, uh, talking about compromised websites. So the X mailer is, uh, a header field that shows, uh, either the name of the file or the full URL of the mailer, uh, in the uh, that sent the, the, the piece of spam. So if it was coming from, like, a PHP mailer that was installed, uh, via back door on a compromised website, uh, often, thank you very much. Um. Okay. Where was I? Alright, so X mailer. Uh, X mailer is a, is an important indicator, I think, uh, for two reasons. Um, often the, uh, the PHP script that sends the spam, and we'll see this in a moment, um, actually this is in a slide from the, from the workshop, I apologize, so we won't actually see the emails, uh, the, the X mailer, uh, string. Uh, but, X mailer, if you have a compromised website and there's been a back door installed, and you'll often see, you know, mailer1.php, and if you go to that URL, you'll have, like, uh, text entry boxes, and you'd basically end up, uh, you enter your spam, uh, headers, you enter your spam body, and all that stuff, and then hit send, and then it sends it, uh, via the, the web server, and so often the URL for that particular, uh, X mailer, that, that PHP mailer will, will appear in the X mailer, uh, header field. And so that becomes a URL indicator. Um, indicator that the website has been compromised. It's also, uh, sometimes it can be forged. So I've seen botnets which will just generate fake xmailer header fields in a set. So they'll say, they'll just have a canned set of fake xmailer headers. But again, that's another indicator. So I can see, I can actually determine that this is a specific, this specific botnet because I see this fake xmailer header and if I go and look for that particular URL there's nothing there because it, you know, that's not, you know, that's not how that botnet sent that particular piece of spam. And then obviously mailer URL that's related just like what I was saying to the xmailer. So that's, that is the indicator that I'm talking about. So the next component here is the MIME boundary string. So if you're not familiar with MIME or what I'm talking about here, it's the, there's one, one in, one of these in the header and it, it tells your mail client where the boundary of any attachment or where the change from either HTML to text or, and each one has this MIME boundary string in the beginning and the end of that attachment. And then it's also in the, in the header. So I have a theory and I, I, you know, I'm working on this at the moment that the MIME boundary string is also an indicator. And the reason why I'm working on this at the moment is that the MIME boundary string is also an indicator and the reason for this is possibly the, the, you know, some bop nets might just use a, a pre-generated specific MIME boundary string. And then you'll be able to, to use that obviously as a, as an indicator. SimHash. So this is not actually a header field, obviously. So SimHash is a type of piece wise fuzzy hashing. There's a, I, there's probably more than this, but the two main ones that I use are SSDeep and SimHash. And so one of the And ssdeep is more specifically tailored towards binaries. So if you have a malware binary, you run it through ssdeep and then you get a signature where you can compare two different binaries and see maybe how similar or how different they are from each other. And so simhash, the concept is the same but the target is slightly different. So the simhash is an algorithm that is meant to look at text. So and my concept here is to take the simhash algorithm and then run the simhash algorithm on each header field so that you can, you know, show the similarity or difference between any single header field that you've run through the simhash algorithm. Okay and also, by the way, there's one header field here on the ssdeep that's just received which is missing from my mind map, it was one of those so extremely obvious that I didn't even put it on the mind map but someone in the workshop mentioned, you know, hey, you don't have received on there, but yeah. So received is another important header. And also I want to point out that the Python script that I use, uh basically catches all header fields. So it converts the entire header, even the x, you know, the x on the left hand side, you can X, by the way, you can have X and then an arbitrary string after that as a key. So you can have as many X blah, blah, blahs as you want in a header. So the script that I use catches all of them and just converts the whole thing into a key value pair set in JSON. So moving on to the body, these are some of the indicators that you can pull out of a body. Phone number. Obviously this is for, again, if we're going back to like the 419 scams, a lot of them use a VoIP line or, you know, a mobile phone number and they'll be sitting there and it'll basically, they'll have one number that they're routing calls to and then the sort of like crumple zone of numbers that they expect to have taken down constantly are the ones that you're going to find in the e-mail. Yeah. In the spam. Obviously, attachments. This is one thing that is, you know, a method that they deliver malware to you with. So obviously, you know, it's the old don't click on and don't run anything that's executable or a document that you get in e-mail from anyone that you don't know. And even if you know them, let's not run it anyway. And then URLs. So often you'll find a drive-by. You'll see a lot of them. You'll see a lot of them in the spam email. So you'll find a place where they're just, like, a tag URL contained in an e-mail. You'll also find phishing pages. We covered some pretty interesting phishing techniques and pages in our, in my workshop. Again, take a SEM hash. So all the text, all the body of, all spam body emails is text. So obviously, you just take a SEM hash of this. You can do comparisons. Also, do SEM hashes of the body components. So take a SEM hash of maybe the HTML and the text. Some stupid email clients only generate HTML emails with no text. So this is where what I mean by rendered sim hash, use something like beautiful soup or another HTML parser and just remove all of the HTML tags so that you're left behind with just the text and then take a sim hash of that text. And obviously an email address, you can get email addresses and keep the text itself. So that's the, those are the things that you can collect from the body of the email and that's the header. Alright and then after you've generated, after you've generated this blob of JSON for the header, put it into elastic search. Create an index, set the type, you know you have like type, type, type, type, type, type, and index. You know I just call it email as the type and then emails as the index. And then you can use Kibana to do visualizations on the data that you have jammed into elastic search. Alright so now the fun begins. You've done the boring stuff, you've stood up a server, that part is done. Now we get to have some fun baiting the trap. So, I'm going to show you a little bit of this. Register a domain. Don't bother paying for a domain the first time you go through this. Just go and get a, go get one of the free, free domains. If you do buy a domain, make sure you turn on privacy. You don't want your home address or your work address or anything related to you in the, in the whois information for a spam trap, spam honeypot domain. Obviously that is a bad idea. And then you want to configure DNS. So you want to configure DNS. You want to configure DNS. There's a couple of sort of very specific components here. You want to assign three IP addresses. The point here is you are mimicking, you're making this look believable as an actual set of mail servers. So you want to behave exactly like a, you know, an email admin at a normal company. So you want it to look legitimate. So assign three email addresses, I'm sorry, email addresses, sorry, three IP addresses. Assign three IP addresses. Assign three IP addresses. Assign three IP addresses. Even if you're only running one, ah, virtual server, assign three, assign three IP addresses to that, ah, in, you know, virtual NICs and you'll be able to have, you're basically increasing your, your attack surface that the spammers are going to be able to send to. Um, also, create primary and backup host names. Again, you want it to look like a real set of mail servers. So mail one dot blah, blah, blah dot com. Mail two dot mail two dot mail three dot dot blah blah dot com, mail three dot blah blah dot com. Also, create three DNSMX records, not just one, and assign them different priorities. I found this is very important because often the way companies have set up their backup and primary mail servers, they've done it incorrectly in that they trust the email that comes from their backup server, but their backup server may not have the same level of spam filtration as their primary, and so spammers will avoid even sending to the organization's primary server. They will send the spam to the backup, you know, the secondary and tertiary MX records, specifically the because they know that sometimes that will avoid the spam protections that the organization has. And, if you're a mail admin, sysadmin, go and check. Go and check and make sure that your secondary and tertiary mail servers have the same spam protection that your primary does, because that's a huge hole. But, the point here is have those tertiary and secondary MX records so that you catch that additional, you know, that additional fractional larger amount of spam. And then you want to generate email addresses. So, you want to see them across the internet. You want to spread them everywhere. Put them in forum posts. Jam them into your, jam them on your website. Put them in comments. You know, be as crazy about them as you want. See them in your website. Give them to your friends. You know, make it as easy as you can to get them into your game. See who can generate the most spam. See who can, like, get the most stuff coming from the particular email address that they have seeded for you. But, for all of this, keep track of where and when and who you gave them to and where they went. And this is super important so that you know, when I seeded this email address to here, compared to seeding an email address here, I can then track the metrics for how much spam they have. So, you know, how much spam each one generated. So, maintain a database or keep a spreadsheet or, I don't know, write them down on a piece of paper. But make sure that you keep track of where the addresses went and when you, when you seeded them. So that you can do some metrics on that afterwards. So, registering a domain. There's many, many, many free services for getting domain names out there. The adversary uses them. Why can't we? So, you know, you want to make sure you don't have to spend money on this. So, just go, don't, don't need to spend money on this. Also, protect your identity by using, basically, burner emails, domain registration, free DNS services. All of these, there are free services out there for each one. And when you're setting things up, if it's possible, if it's possible that you can set it up this way, when you contact all of these things to set them up, use Tor, you know. Be as protective as possible of your own identity. And then before you begin seeding, make sure that you verify your DNS records and verify your who is. Look at it, look at it carefully and make sure that you haven't missed something and left maybe your name in there, or something that someone could, something that could lead an adversary back to you. So, take a look at it. If you want to look at your DNS records, maybe look at your DNS records on a, another machine, use a VPN, maybe, you know, you can find a way to do it. to look at it from somewhere else so you can see whether the TTL has updated and you can see the fresh DNS record. Also make the user name on the server generic. Don't log into your server with a user name that's your name. Because if the server gets popped, they now know your name. So make it generic, doesn't matter. Whatever you want to just make your user name, user name or your admin user, admin, doesn't matter. Just make sure it's not your name. So check your DNS records. This is just a dump from example.com, set up how I would want a spam honeypot set up correctly. So as you can see I've set up five name servers and then three MX records and I've called them mail one, mail two, and mail three. And I've called them the, they all have a different priority as you can see. The 10, 20 and 30 priority. And then the A records for each one. That's just fake. Those are fake numbers. But I've set three different IP addresses for each one of the mail servers. And again back to the really fun stuff. So this is when you generate email addresses. So you want to generate email addresses that look believable. So have fun with it. Have a lot of fun with it. So this is a These are a few of my favorite random name generators. So you can go in there. Behind the name you get to learn a little bit about what the meaning of the names are that you're seeding into email addresses. Random name generator.info. Name mesh. These are funny actually. And these are for generating believable domain names that sound like a real business. These are hilarious. They will generate just, you know, ridiculous business names. And business name generator. I love Scrabble, by the way. I love playing Scrabble. Scrabble is fantastic. So why not increase your Scrabble knowledge while you're seeding your spam honeypot. So go look through Scrabble word finder. Start memorizing some of the smaller, you know, the two-letter words or three-letter words and whatever. Go through word find, word finder, your dictionary. Increase your Scrabble knowledge while you're, while you're working on spam. Also anagram solvers. These are great. You put in, basically you put in a word and then it shows you all of the other, you know, words that are made up of the same letters, but rearranged. So just, the point here is have fun with this process. It doesn't, it doesn't need to be boring. And hopefully after you've done all of this and you've got your, your mail service set addresses and now you have spam rolling in. And this one is great. This is probably the best piece of spam that I've ever seen in my entire life. So it has ASCII art in it and it's basically a hand telling you click on this link. And if you look at the link, I would never click on that. If you see a link that ends in main.php or document.php or something like that, never good. Never, never, never good. Okay. So, thank you. This is my Twitter handle. That's my company's Twitter handle. This is the blog. Next week after we're all back home, there will be slides and everything. So if you have any questions, feel free to ask anything from my workshop and from the presentation up on our blog. And do we have any questions out there? Anybody? In the back. You'll have to yell because. Very good point. So, if I'm getting your gist, make your entire DNS, set of DNS records blank. And if you don't, have a DNS record that is believable. So, have a and actually you're right. Maybe even have a web server with a believable website on there. So, he's saying have an A record for www.blahblahblah.com so that you have a fully believable DNS record. That's a very good point. Just blahblahblah.com Get email. Another good point. So yes, you will get, you will get spam to those records. Right. Alright. Any other questions? Yes. You're going to have to yell. Yes. Actually the, so the, the Python script code that if you, the people that came to my workshop, they already have a copy of it and we've worked with it, but I'll make sure to put this up on, when I get back to, to, to home. More questions? Yes. Oh, yeah, they're, they're not, they're not necessary, but I'm, I'm not concerning myself with the necessity of a particular email header. I'm using these as indicators to determine possibly the origin of that particular piece of spam. Uh, use it to correlate, um, across like maybe this particular botnet compared to this particular botnet produces a, a slightly different set of X, X, you know, X headers. So whether they're, whether they are, uh, required to, uh, use the code or not, they're, they're not necessarily, they're required or not is not important to me. It's using them, uh, as an indicator. If that makes sense. Question? More questions? Okay. Um, so the question was is there any insight on, um, you know, taking the knowledge, like taking the knowledge that you're gathering from this and then using it, uh, in the, your example with SpamAssassin. So I would say, uh, yes. And that's, that's actually the, the ultimate goal of all of this. So what you're going to do is you've got, uh, basically a library of spam that you've already collected. You have spam coming in. You're analyzing the spam. You're pulling out indicators like the origin IP. Um, and these are all things that you can use to block, you know, future spam. In addition to knowing about, you know, to, in addition to the, the, the threat intelligence component of it, you can also take these indicators and you can push them out to a defensive device or defensive system such as, uh, SpamAssassin. More questions? Okay. Thank you everybody. Thanks for coming out. Appreciate it.