[00:00.000 --> 00:07.040] Well, so it's going to be 2.9 right now. [00:07.140 --> 00:12.460] And originally we were going to have another person introduce Sam, [00:12.460 --> 00:16.120] but he's a little bit camera shy, so I guess I've got to do it. [00:16.480 --> 00:26.220] So I guess the best way I can introduce our next speaker is Council 9 Black Badge winner, Sam Earp. [00:26.240 --> 00:26.980] Thank you. [00:26.980 --> 00:31.540] Thank you. Hi, my name is Sam. [00:31.820 --> 00:34.480] Today I'll be presenting on hunting certificates and servers. [00:35.000 --> 00:36.620] And so let's get started. [00:37.340 --> 00:43.020] Our team, Council 9, has won two black badges through the badge challenge. [00:44.520 --> 00:48.120] As Meg mentioned, I'm also a software engineer at Akamai. [00:50.400 --> 00:54.940] So one thing I have to be very clear here, the opinion is expressed here on my own, no one else's. [00:54.940 --> 00:58.740] And be careful when you connect to any host online. [00:58.740 --> 01:04.020] And always seek explicit permission before attempting to exploit, etc. [01:06.020 --> 01:08.160] So there's three parts to this. [01:08.160 --> 01:09.980] So part one is getting the internet. [01:10.200 --> 01:13.380] So this is actually a DEF CON story. [01:13.860 --> 01:19.640] As part of the badge challenge, we noticed the person who would run the badge challenge every year, [01:19.640 --> 01:22.540] 1057, would use the same TLDs over and over again. [01:22.540 --> 01:25.240] In particular, he was very fond of the .codes TLD. [01:25.520 --> 01:29.520] Unfortunately, there are not a lot of .codes domain names. [01:29.720 --> 01:34.860] So he picked up on this and started monitoring for any new .codes registration online, [01:35.400 --> 01:43.000] as well as scanning the internet for domains hosted that contained a .code domain. [01:43.120 --> 01:45.480] We'd also then search for relevant Whois records as well. [01:46.520 --> 01:48.940] And this was a pretty closely held secret by our team. [01:48.940 --> 01:51.660] There were about 10 people or so that knew this at the time. [01:51.660 --> 01:54.660] And I'm really only sharing it now simply because it's... [01:55.180 --> 01:58.380] the contest is largely over in its current form anyways. [02:00.200 --> 02:02.360] And so our scanners actually worked. [02:02.360 --> 02:03.800] They picked up one domain. [02:03.920 --> 02:06.560] We got a Slack notification that grey.codes was registered, [02:06.560 --> 02:09.100] and it contained lost handle. [02:09.160 --> 02:11.120] Therefore, it must be him, obviously. [02:12.260 --> 02:14.260] So it contained a series of puzzles. [02:14.260 --> 02:15.480] So we visited the website. [02:15.480 --> 02:19.040] We spent about 72 hours not really sleeping, solving the puzzles, [02:19.040 --> 02:22.140] thinking it was a registration for a contest or something similar. [02:23.020 --> 02:27.180] And we sent through the solution on the final step. [02:27.360 --> 02:30.200] This was November 2nd, 2016. [02:30.760 --> 02:32.880] And lost replied back, [02:32.880 --> 02:34.580] I don't know what you're talking about, essentially. [02:34.580 --> 02:36.080] And it appears you've been trolled. [02:37.600 --> 02:43.840] So I sent grey.codes a message on Twitter asking who he was and what he's doing. [02:44.080 --> 02:47.460] And it turns out we weren't the only ones who got trolled. [02:47.460 --> 02:53.660] All of the other teams who were competing against us at DEF CON that year also got trolled. [02:53.780 --> 02:58.440] And, yeah, it actually turned out it was one of the ten people that we had told about this [02:58.440 --> 03:01.600] trolled the rest of us using our own scanner. [03:04.200 --> 03:07.180] So that was kind of my first introduction to scanning the Internet [03:07.180 --> 03:12.020] and doing large-scale reconnaissance in the IPv4 space. [03:12.100 --> 03:17.300] And that really got me thinking of what else I could find and search for on public Internet. [03:17.900 --> 03:22.200] And one thing I'm very familiar with is TLS certificates. [03:22.420 --> 03:26.100] And as you might know, TLS certificates contain host names. [03:26.620 --> 03:30.960] And so before I talk about scanning the Internet for TLS certificates, [03:30.960 --> 03:32.980] I have to talk about TLS. [03:32.980 --> 03:37.280] And this is going to be really basic. I'm sorry if you're a TLS expert. [03:38.160 --> 03:43.160] TLS handshake, you send over in the client hello, [03:43.160 --> 03:46.120] you send over what you're connecting to in the server name indicator, [03:46.120 --> 03:47.580] or who you're asking for. [03:47.720 --> 03:50.920] Then the server will return back a certificate to you. [03:51.500 --> 03:56.880] And then there's a handshake that occurs that drives the secret that's used to communicate. [03:58.220 --> 04:02.240] And, yeah, so that's kind of like a high level of how TLS works. [04:02.240 --> 04:06.720] So if you go to HTTPS, any website today, this is what your browser will be doing. [04:08.220 --> 04:11.780] So I want the host names that are found in that second step there. [04:12.600 --> 04:19.740] And so I wanted an efficient way to get these host names at scale, [04:19.740 --> 04:22.480] ideally from as small a server as possible. [04:22.480 --> 04:27.940] I'm not operating with any budget here. I'm running VPS with a single CPU core. [04:28.680 --> 04:31.120] So I cut off the rest of the connection. [04:32.060 --> 04:38.540] And so when I get a certificate back from the server, [04:38.540 --> 04:40.280] I would just immediately kill the connection [04:40.280 --> 04:45.120] and not continue along with the heavy crypto that's involved in doing the rest of the handshake. [04:45.960 --> 04:50.480] This isn't really anything crazy. [04:50.480 --> 04:51.880] It's entirely by the spec. [04:51.880 --> 04:55.840] You're allowed to exit out of the handshake at any point if something goes wrong. [04:59.020 --> 05:03.600] So, yeah, so by doing this, I'm able to save CPU costs on my server [05:03.600 --> 05:07.100] and connect to many more servers for as cheap as possible. [05:08.380 --> 05:10.340] So what's in an X.509 certificate? [05:10.340 --> 05:13.420] Just to give you an example, this is one for google.com. [05:13.420 --> 05:15.780] And as you can see, it contains many, many host names. [05:15.780 --> 05:17.340] And this is fairly common. [05:17.340 --> 05:21.120] You'll see either wildcard or just a list of domain names. [05:24.240 --> 05:29.100] So as I kind of mentioned previously, I scanned the Internet for these. [05:29.100 --> 05:31.000] So I set up a scanner. [05:31.000 --> 05:33.520] So for every IPv4 host, I did two things. [05:33.520 --> 05:38.260] I ran mass scan over it, which just checks whether or not port 443 is open. [05:38.520 --> 05:42.160] I do that because nothing I write will be faster than mass scan. [05:42.160 --> 05:46.100] So this is a good first filter to prove that 443 is open. [05:46.320 --> 05:52.220] I then wrote a Golang program that sends a TLS client hello [05:52.220 --> 05:56.080] and then gets the server certificate back and then just immediately disconnects. [05:56.120 --> 05:58.780] And so the pseudocode roughly looks like this. [05:58.780 --> 06:02.360] There's a few parsing steps in between, but this is essentially all that I run. [06:02.360 --> 06:06.960] And I had to modify the Golang TLS stack to get this early return [06:06.960 --> 06:09.080] because it's not really a standard thing to do. [06:09.080 --> 06:11.980] It was actually surprisingly easy. [06:11.980 --> 06:14.060] I really love working with the Golang TLS stack. [06:14.060 --> 06:19.040] It's much, much easier than working with OpenSSL, if you're familiar with OpenSSL. [06:20.580 --> 06:25.940] So this is what I set up and ran, and it took about 72 hours or so. [06:25.940 --> 06:32.300] So I got about 12 gigabytes of data back, which was host name, IP address combinations. [06:33.120 --> 06:37.060] And I then asked myself some really basic questions, like, am I finding every host? [06:37.060 --> 06:41.520] And this scanner identified 51 million hosts online in the IPv4 space. [06:41.600 --> 06:45.000] A 2015 paper that I found identified 42 million. [06:45.000 --> 06:48.500] One really interesting thing, Shodan only finds 42 million today. [06:48.500 --> 06:51.760] I don't understand the discrepancy between MyScanner and Shodan. [06:51.760 --> 06:54.320] I suspect that Shodan's been blocked from parts of the Internet, [06:54.320 --> 06:56.380] but I don't have any data to back that up. [06:58.180 --> 07:01.220] And I have to ask myself, am I finding every certificate online? [07:01.220 --> 07:02.620] And the answer really is no. [07:02.840 --> 07:07.280] It's common server configuration in that client hello. [07:07.280 --> 07:09.560] I could specify an SNI. It's a client server configuration [07:10.040 --> 07:13.500] that the TLS client hello is used to differentiate clients. [07:13.780 --> 07:18.120] And based on what you pass in there, that will turn a different certificate back to you. [07:18.120 --> 07:20.420] And so this scanner will miss all of those. [07:20.840 --> 07:24.520] Another thing I have to point out is that the Golang X.509 parser is very strict. [07:24.740 --> 07:26.860] So if your server was doing something weird with certificates [07:27.260 --> 07:32.040] or really just had any sort of non-standard X.509 cert, [07:32.040 --> 07:35.440] it likely will not pass through Golang's X.509 parser. [07:35.560 --> 07:40.360] And there's actually a blog post on how to parse malformed certificates there, [07:40.360 --> 07:41.300] if you're interested. [07:42.780 --> 07:44.720] So I also have to ask, who else is doing this? [07:44.720 --> 07:49.400] Because none of this is really new or revolutionary, in my opinion. [07:49.400 --> 07:53.360] So I set up a TLS server, and I just captured traffic. [07:53.360 --> 07:57.380] And I just got the PCAP back. [07:57.380 --> 08:01.820] And I actually found three servers that did the exact same thing that I'm doing. [08:01.840 --> 08:04.880] Two of them were from universities, [08:04.880 --> 08:07.360] which were scanning the internet for their own research purposes. [08:07.360 --> 08:11.100] And one of them was from a hosting provider in Germany as well. [08:11.100 --> 08:13.840] So clearly there's somebody in Germany who's doing the exact same thing [08:13.840 --> 08:17.500] and simply not publishing it in any paper that I found. [08:19.600 --> 08:21.900] I believe that they're doing the same thing as I am [08:21.900 --> 08:24.860] because of the way that they closed the connections, [08:24.860 --> 08:27.580] as well as there was no SNI sent in the connection they made to me. [08:27.580 --> 08:29.480] So clearly they weren't trying to connect me to a host. [08:29.480 --> 08:33.260] They were just simply trying to connect to my IP address [08:33.260 --> 08:35.940] to just get back the certificate that I would return. [08:39.410 --> 08:46.370] So I now have 12 gigabytes of host name, IP address combinations, [08:46.370 --> 08:49.790] which is a lot of data and it's not the most friendly form to work with, [08:49.790 --> 08:51.290] 12 gigabytes of text. [08:51.710 --> 08:57.510] So this is part two, which is how to search large parts of large DNS datasets. [08:57.790 --> 09:01.790] And so this actually came about because I wanted to use the Rapid7 datasets. [09:02.150 --> 09:08.570] So in the Rapid7 DNS, they have DNS listeners online [09:08.570 --> 09:15.230] for FDNS and RDNS requests and forward and reverse DNS requests. [09:15.910 --> 09:18.630] And you can just go to their website and download this. [09:18.630 --> 09:20.230] It's a great resource. I love it. [09:20.230 --> 09:24.030] It's just really hard to work with because it's 10 gigabytes of compressed text, [09:24.030 --> 09:27.130] which expands out to about 100 gigabytes of uncompressed text. [09:27.530 --> 09:30.470] And so this always took a long time to search. [09:30.470 --> 09:33.210] Every time I wanted to search through this, it took about 20 minutes, [09:33.210 --> 09:34.810] which is a little bit insane. [09:35.010 --> 09:39.670] So I found myself trying to write better or trying to script, I should say, [09:39.670 --> 09:43.770] better or more fast ways to decompress and grep [09:44.450 --> 09:48.990] or use more disk space to grep faster. [09:49.310 --> 09:51.050] And this obviously took a long time. [09:51.050 --> 09:54.530] And I actually wrote a blog post about this, [09:55.390 --> 09:58.690] which is linked to there, back in February. [09:58.890 --> 10:04.490] And so in order to sort the data, I took advantage of the DNS structure. [10:04.490 --> 10:08.670] So DNS is structured such that when you make a DNS request for, [10:08.670 --> 10:12.850] in this case, blog.erbysam.com, you actually first go to the root, [10:12.850 --> 10:15.890] which is dot, roughly com, and then you go to com, [10:15.890 --> 10:19.750] and then you go to com.erbysam, and then you go to com.erbysam.blog. [10:20.010 --> 10:26.030] And so you can take advantage of this in order to sort the data. [10:26.170 --> 10:32.170] So I reversed every string, roughly, and sorted it. [10:32.170 --> 10:35.070] At this point, because the data is sorted, [10:35.070 --> 10:39.810] in order to find a host name that I'm looking for in this dataset, [10:39.810 --> 10:41.290] I just simply have to binary search it, [10:41.290 --> 10:47.030] which is an order of magnitude faster than grepping through the files, [10:48.010 --> 10:51.250] if you're familiar with how binary searches work. [10:52.590 --> 10:54.990] I talked about this in much more detail in my blog, [10:54.990 --> 10:56.450] if you're interested in the technical details. [10:56.450 --> 10:58.650] I also have code online on how to do this. [10:58.830 --> 11:01.950] And this is actually something that's hosted online as well. [11:02.710 --> 11:05.430] So I put this online using a Golang web server. [11:05.570 --> 11:10.350] It's available today on dns.bufferover.run, bufferover.run.dns, [11:10.350 --> 11:14.170] and you get back data from the Rapid7 datasets. [11:15.710 --> 11:17.170] I use this myself. [11:17.170 --> 11:19.370] It's a great way to just quickly grep through them [11:19.370 --> 11:20.710] if you're searching for something. [11:20.910 --> 11:23.170] And I also posted the runtime on there. [11:23.290 --> 11:25.190] The runtime is usually a fraction of a second [11:25.190 --> 11:27.030] to binary search through this data. [11:28.730 --> 11:31.230] And I also linked to my GitHub account here, [11:31.230 --> 11:41.890] which has the code to convert the data into a searchable format [11:41.890 --> 11:43.450] that's usable by the server. [11:44.990 --> 11:48.470] So one day I woke up and I checked the traffic for this website. [11:48.470 --> 11:49.890] And I saw this. [11:49.890 --> 11:52.810] And I thought, man, I'm a really good blogger. [11:52.810 --> 11:58.490] But what had actually happened was I got pulled into something called Amass, [11:58.490 --> 12:03.430] which is a utility for hostname reconnaissance [12:03.430 --> 12:05.450] that's published by OWASP. [12:05.590 --> 12:07.450] And this was completely unknown to me. [12:07.450 --> 12:09.050] Luckily, the server held up. [12:09.270 --> 12:11.310] I'm a little bit proud of that, personally. [12:11.510 --> 12:16.230] But that was the source of all this data. [12:16.390 --> 12:18.730] And the fact that it's so heavily cached [12:18.730 --> 12:20.970] means that everyone's searching for the same hostnames, [12:20.970 --> 12:23.550] or they're repeatedly searching for the same hostnames over and over again, [12:23.550 --> 12:25.330] which I found really interesting. [12:27.390 --> 12:29.670] So I actually don't collect data on this. [12:29.670 --> 12:31.190] I don't actually know what everyone's searching for. [12:31.190 --> 12:33.050] And I, frankly, don't really want to. [12:33.850 --> 12:37.450] So now that I have a good data set and I have a good way to search it, [12:37.450 --> 12:38.590] I want to put it all together. [12:39.490 --> 12:43.710] And so similar to the DNS records with Rapid7, [12:43.710 --> 12:48.490] I hosted this online at tls.bufferoverrun over .run.dns. [12:48.670 --> 12:50.310] And this is actually online today. [12:50.310 --> 12:51.930] And you're welcome to try it out. [12:53.210 --> 12:56.730] It's literally just a combination of the data set [12:56.730 --> 13:00.330] that the MySQL scanner picked up, [13:00.330 --> 13:05.190] as well as the server behind the Rapid7 data set. [13:05.590 --> 13:07.550] And this is actually fully automated at this point, [13:07.550 --> 13:09.730] so this will refresh once a week. [13:11.930 --> 13:15.770] So I then have to compare myself to what else is out there. [13:15.770 --> 13:19.650] I'm mostly just curious to see if this is even necessary. [13:19.650 --> 13:24.050] And so Shodan.io should contain similar results. [13:24.150 --> 13:25.110] It's not free. [13:25.730 --> 13:30.210] I found that my TLS scanner tends to pick up some more results than Shodan, [13:30.210 --> 13:31.350] which I found interesting. [13:31.390 --> 13:32.830] And that kind of goes back to my previous point [13:32.830 --> 13:35.290] that I think Shodan is being blocked by large parts of the internet, [13:35.290 --> 13:37.150] but I don't have any data to really prove that. [13:37.690 --> 13:39.770] Certificate transparency monitors are awesome, [13:40.210 --> 13:41.910] but they only contain publicly trusted certs [13:41.910 --> 13:44.130] and they don't link back to where the cert came from. [13:44.330 --> 13:46.390] And Rapid7 actually has a TLS data set, [13:46.390 --> 13:50.430] but it's only the new certificates they encounter in their scans every week. [13:50.430 --> 13:54.050] They don't have historical data unless you have an account with them. [13:54.550 --> 13:55.590] And there are many others. [13:55.590 --> 14:00.650] The OAuth AMS tool has a great list of existing resources online. [14:03.070 --> 14:06.230] So just to give a demo here, obviously hack yourself first, [14:06.230 --> 14:08.550] plug in your company's name, see what you find. [14:08.610 --> 14:10.150] I find that really interesting. [14:10.510 --> 14:13.510] There's also, when I build these tools, [14:13.510 --> 14:16.530] one of the first things I do is I run them against .mil. [14:16.530 --> 14:21.350] And I report whatever I find back to the DoD Vulnerability Disclosure Program. [14:21.430 --> 14:24.970] So if you're interested in finding vulnerabilities, [14:24.970 --> 14:30.870] go look at the 473,000 results here, find a host name, [14:30.870 --> 14:33.430] try and exploit it, report what you find. [14:33.710 --> 14:35.190] So I did that. [14:35.190 --> 14:39.770] And I found a WebLogic remote code execution [14:39.770 --> 14:44.510] that was still online from the 2017 exploit. [14:44.590 --> 14:48.310] And I was able to exploit it and report it in. [14:48.570 --> 14:51.110] And I just do this simply to test my tools. [14:51.110 --> 15:00.190] But at the same time, because the military has such a variation of technology online, [15:00.190 --> 15:03.770] because it's all subcontracted out, it's not all PHP, it's not all Java, [15:04.330 --> 15:07.530] your tools will likely pick up something interesting. [15:08.290 --> 15:11.150] And so actually, one interesting thing about this is that [15:11.150 --> 15:13.710] they actually blocked outbound traffic, [15:13.710 --> 15:17.030] which would likely make automated skinners fail here. [15:17.030 --> 15:21.190] So I was able to demonstrate this by injecting a sleep of 12 seconds, [15:21.190 --> 15:25.250] and then the result took 12 seconds to return back to me, demonstrating RCE. [15:28.590 --> 15:31.650] So yeah, hack yourself first, hack your military first. [15:32.530 --> 15:33.790] Thank you. [15:40.070 --> 15:41.110] Questions? [15:44.740 --> 15:47.220] I use Linode. [15:47.340 --> 15:51.820] With Linode, if you are a security researcher, [15:51.820 --> 15:55.160] or sorry, if you are doing something for security research, [15:55.160 --> 15:58.480] you can get a security researcher designation on your account, [15:58.480 --> 16:00.800] which means that as long as you follow the rules [16:00.800 --> 16:05.620] and you have a page that links to what your tool is doing, [16:05.620 --> 16:06.580] connecting to other hosts, [16:06.580 --> 16:10.360] they will have an automated reply [16:10.360 --> 16:12.900] to anybody filing abuse complaints against you. [16:20.150 --> 16:28.470] No, it matches based on a reverse of the DNS name. [16:28.750 --> 16:31.330] So you could do .mil, army.mil, [16:31.330 --> 16:33.830] and it would return you everything underneath that zone. [16:39.070 --> 16:40.670] Any other questions? [16:43.900 --> 16:46.080] Thank you. I hope this was interesting.