Well, so it's going to be 2.9 right now. And originally we were going to have another person introduce Sam, but he's a little bit camera shy, so I guess I've got to do it. So I guess the best way I can introduce our next speaker is Council 9 Black Badge winner, Sam Earp. Thank you. Thank you. Hi, my name is Sam. Today I'll be presenting on hunting certificates and servers. And so let's get started. Our team, Council 9, has won two black badges through the badge challenge. As Meg mentioned, I'm also a software engineer at Akamai. So one thing I have to be very clear here, the opinion is expressed here on my own, no one else's. And be careful when you connect to any host online. And always seek explicit permission before attempting to exploit, etc. So there's three parts to this. So part one is getting the internet. So this is actually a DEF CON story. As part of the badge challenge, we noticed the person who would run the badge challenge every year, 1057, would use the same TLDs over and over again. In particular, he was very fond of the .codes TLD. Unfortunately, there are not a lot of .codes domain names. So he picked up on this and started monitoring for any new .codes registration online, as well as scanning the internet for domains hosted that contained a .code domain. We'd also then search for relevant Whois records as well. And this was a pretty closely held secret by our team. There were about 10 people or so that knew this at the time. And I'm really only sharing it now simply because it's... the contest is largely over in its current form anyways. And so our scanners actually worked. They picked up one domain. We got a Slack notification that grey.codes was registered, and it contained lost handle. Therefore, it must be him, obviously. So it contained a series of puzzles. So we visited the website. We spent about 72 hours not really sleeping, solving the puzzles, thinking it was a registration for a contest or something similar. And we sent through the solution on the final step. This was November 2nd, 2016. And lost replied back, I don't know what you're talking about, essentially. And it appears you've been trolled. So I sent grey.codes a message on Twitter asking who he was and what he's doing. And it turns out we weren't the only ones who got trolled. All of the other teams who were competing against us at DEF CON that year also got trolled. And, yeah, it actually turned out it was one of the ten people that we had told about this trolled the rest of us using our own scanner. So that was kind of my first introduction to scanning the Internet and doing large-scale reconnaissance in the IPv4 space. And that really got me thinking of what else I could find and search for on public Internet. And one thing I'm very familiar with is TLS certificates. And as you might know, TLS certificates contain host names. And so before I talk about scanning the Internet for TLS certificates, I have to talk about TLS. And this is going to be really basic. I'm sorry if you're a TLS expert. TLS handshake, you send over in the client hello, you send over what you're connecting to in the server name indicator, or who you're asking for. Then the server will return back a certificate to you. And then there's a handshake that occurs that drives the secret that's used to communicate. And, yeah, so that's kind of like a high level of how TLS works. So if you go to HTTPS, any website today, this is what your browser will be doing. So I want the host names that are found in that second step there. And so I wanted an efficient way to get these host names at scale, ideally from as small a server as possible. I'm not operating with any budget here. I'm running VPS with a single CPU core. So I cut off the rest of the connection. And so when I get a certificate back from the server, I would just immediately kill the connection and not continue along with the heavy crypto that's involved in doing the rest of the handshake. This isn't really anything crazy. It's entirely by the spec. You're allowed to exit out of the handshake at any point if something goes wrong. So, yeah, so by doing this, I'm able to save CPU costs on my server and connect to many more servers for as cheap as possible. So what's in an X.509 certificate? Just to give you an example, this is one for google.com. And as you can see, it contains many, many host names. And this is fairly common. You'll see either wildcard or just a list of domain names. So as I kind of mentioned previously, I scanned the Internet for these. So I set up a scanner. So for every IPv4 host, I did two things. I ran mass scan over it, which just checks whether or not port 443 is open. I do that because nothing I write will be faster than mass scan. So this is a good first filter to prove that 443 is open. I then wrote a Golang program that sends a TLS client hello and then gets the server certificate back and then just immediately disconnects. And so the pseudocode roughly looks like this. There's a few parsing steps in between, but this is essentially all that I run. And I had to modify the Golang TLS stack to get this early return because it's not really a standard thing to do. It was actually surprisingly easy. I really love working with the Golang TLS stack. It's much, much easier than working with OpenSSL, if you're familiar with OpenSSL. So this is what I set up and ran, and it took about 72 hours or so. So I got about 12 gigabytes of data back, which was host name, IP address combinations. And I then asked myself some really basic questions, like, am I finding every host? And this scanner identified 51 million hosts online in the IPv4 space. A 2015 paper that I found identified 42 million. One really interesting thing, Shodan only finds 42 million today. I don't understand the discrepancy between MyScanner and Shodan. I suspect that Shodan's been blocked from parts of the Internet, but I don't have any data to back that up. And I have to ask myself, am I finding every certificate online? And the answer really is no. It's common server configuration in that client hello. I could specify an SNI. It's a client server configuration that the TLS client hello is used to differentiate clients. And based on what you pass in there, that will turn a different certificate back to you. And so this scanner will miss all of those. Another thing I have to point out is that the Golang X.509 parser is very strict. So if your server was doing something weird with certificates or really just had any sort of non-standard X.509 cert, it likely will not pass through Golang's X.509 parser. And there's actually a blog post on how to parse malformed certificates there, if you're interested. So I also have to ask, who else is doing this? Because none of this is really new or revolutionary, in my opinion. So I set up a TLS server, and I just captured traffic. And I just got the PCAP back. And I actually found three servers that did the exact same thing that I'm doing. Two of them were from universities, which were scanning the internet for their own research purposes. And one of them was from a hosting provider in Germany as well. So clearly there's somebody in Germany who's doing the exact same thing and simply not publishing it in any paper that I found. I believe that they're doing the same thing as I am because of the way that they closed the connections, as well as there was no SNI sent in the connection they made to me. So clearly they weren't trying to connect me to a host. They were just simply trying to connect to my IP address to just get back the certificate that I would return. So I now have 12 gigabytes of host name, IP address combinations, which is a lot of data and it's not the most friendly form to work with, 12 gigabytes of text. So this is part two, which is how to search large parts of large DNS datasets. And so this actually came about because I wanted to use the Rapid7 datasets. So in the Rapid7 DNS, they have DNS listeners online for FDNS and RDNS requests and forward and reverse DNS requests. And you can just go to their website and download this. It's a great resource. I love it. It's just really hard to work with because it's 10 gigabytes of compressed text, which expands out to about 100 gigabytes of uncompressed text. And so this always took a long time to search. Every time I wanted to search through this, it took about 20 minutes, which is a little bit insane. So I found myself trying to write better or trying to script, I should say, better or more fast ways to decompress and grep or use more disk space to grep faster. And this obviously took a long time. And I actually wrote a blog post about this, which is linked to there, back in February. And so in order to sort the data, I took advantage of the DNS structure. So DNS is structured such that when you make a DNS request for, in this case, blog.erbysam.com, you actually first go to the root, which is dot, roughly com, and then you go to com, and then you go to com.erbysam, and then you go to com.erbysam.blog. And so you can take advantage of this in order to sort the data. So I reversed every string, roughly, and sorted it. At this point, because the data is sorted, in order to find a host name that I'm looking for in this dataset, I just simply have to binary search it, which is an order of magnitude faster than grepping through the files, if you're familiar with how binary searches work. I talked about this in much more detail in my blog, if you're interested in the technical details. I also have code online on how to do this. And this is actually something that's hosted online as well. So I put this online using a Golang web server. It's available today on dns.bufferover.run, bufferover.run.dns, and you get back data from the Rapid7 datasets. I use this myself. It's a great way to just quickly grep through them if you're searching for something. And I also posted the runtime on there. The runtime is usually a fraction of a second to binary search through this data. And I also linked to my GitHub account here, which has the code to convert the data into a searchable format that's usable by the server. So one day I woke up and I checked the traffic for this website. And I saw this. And I thought, man, I'm a really good blogger. But what had actually happened was I got pulled into something called Amass, which is a utility for hostname reconnaissance that's published by OWASP. And this was completely unknown to me. Luckily, the server held up. I'm a little bit proud of that, personally. But that was the source of all this data. And the fact that it's so heavily cached means that everyone's searching for the same hostnames, or they're repeatedly searching for the same hostnames over and over again, which I found really interesting. So I actually don't collect data on this. I don't actually know what everyone's searching for. And I, frankly, don't really want to. So now that I have a good data set and I have a good way to search it, I want to put it all together. And so similar to the DNS records with Rapid7, I hosted this online at tls.bufferoverrun over .run.dns. And this is actually online today. And you're welcome to try it out. It's literally just a combination of the data set that the MySQL scanner picked up, as well as the server behind the Rapid7 data set. And this is actually fully automated at this point, so this will refresh once a week. So I then have to compare myself to what else is out there. I'm mostly just curious to see if this is even necessary. And so Shodan.io should contain similar results. It's not free. I found that my TLS scanner tends to pick up some more results than Shodan, which I found interesting. And that kind of goes back to my previous point that I think Shodan is being blocked by large parts of the internet, but I don't have any data to really prove that. Certificate transparency monitors are awesome, but they only contain publicly trusted certs and they don't link back to where the cert came from. And Rapid7 actually has a TLS data set, but it's only the new certificates they encounter in their scans every week. They don't have historical data unless you have an account with them. And there are many others. The OAuth AMS tool has a great list of existing resources online. So just to give a demo here, obviously hack yourself first, plug in your company's name, see what you find. I find that really interesting. There's also, when I build these tools, one of the first things I do is I run them against .mil. And I report whatever I find back to the DoD Vulnerability Disclosure Program. So if you're interested in finding vulnerabilities, go look at the 473,000 results here, find a host name, try and exploit it, report what you find. So I did that. And I found a WebLogic remote code execution that was still online from the 2017 exploit. And I was able to exploit it and report it in. And I just do this simply to test my tools. But at the same time, because the military has such a variation of technology online, because it's all subcontracted out, it's not all PHP, it's not all Java, your tools will likely pick up something interesting. And so actually, one interesting thing about this is that they actually blocked outbound traffic, which would likely make automated skinners fail here. So I was able to demonstrate this by injecting a sleep of 12 seconds, and then the result took 12 seconds to return back to me, demonstrating RCE. So yeah, hack yourself first, hack your military first. Thank you. Questions? I use Linode. With Linode, if you are a security researcher, or sorry, if you are doing something for security research, you can get a security researcher designation on your account, which means that as long as you follow the rules and you have a page that links to what your tool is doing, connecting to other hosts, they will have an automated reply to anybody filing abuse complaints against you. No, it matches based on a reverse of the DNS name. So you could do .mil, army.mil, and it would return you everything underneath that zone. Any other questions? Thank you. I hope this was interesting.