WEBVTT

00:00.000 --> 00:07.040
Well, so it's going to be 2.9 right now.

00:07.140 --> 00:16.120
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.

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:29.260
Thank you.

00:30.040 --> 00:31.540
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:22.540
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.

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:43.000
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.

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:09.100
We got a Slack notification that grey.codes was registered, 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:22.140
We spent about 72 hours not really sleeping, solving the puzzles, 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:34.580
And lost replied back, 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 --> 03:01.600
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.

03:04.200 --> 03:12.020
So that was kind of my first introduction to scanning the Internet 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:32.980
And so before I talk about scanning the Internet for TLS certificates, I have to talk about TLS.

03:32.980 --> 03:34.400
And this is going to be really basic.

03:34.400 --> 03:37.280
I'm sorry if you're a TLS expert.

03:38.160 --> 03:47.580
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.

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:22.480
And so I wanted an efficient way to get these host names at scale, ideally from as small a server as possible.

04:22.480 --> 04:24.060
I'm not operating with any budget here.

04:24.060 --> 04:27.940
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:45.120
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.

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:07.100
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.

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:56.080
I then wrote a Golang program that sends a TLS client hello 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:09.080
And I had to modify the Golang TLS stack to get this early return 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:56.380
I suspect that Shodan's been blocked from parts of the Internet, 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:08.320
I could specify an SNI.

07:08.320 --> 07:13.500
It's a client server configuration 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:35.440
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.

07:35.560 --> 07:41.300
And there's actually a blog post on how to parse malformed certificates there, 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:07.360
Two of them were from universities, 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:17.500
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.

08:19.600 --> 08:27.580
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.

08:27.580 --> 08:29.480
So clearly they weren't trying to connect me to a host.

08:29.480 --> 08:35.940
They were just simply trying to connect to my IP address to just get back the certificate that I would return.

08:39.410 --> 08:51.290
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.

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:15.230
So in the Rapid7 DNS, they have DNS listeners online 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:19.570
It's a great resource.

09:19.570 --> 09:20.230
I love it.

09:20.230 --> 09:27.130
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.

09:27.530 --> 09:30.470
And so this always took a long time to search.

09:30.470 --> 09:34.810
Every time I wanted to search through this, it took about 20 minutes, which is a little bit insane.

09:35.010 --> 09:48.990
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.

09:49.310 --> 09:51.050
And this obviously took a long time.

09:51.050 --> 09:58.690
And I actually wrote a blog post about this, 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:19.750
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.

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:51.250
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.

10:52.590 --> 10:56.450
I talked about this in much more detail in my blog, 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:14.170
It's available today on dns.bufferover.run, bufferover.run.dns, and you get back data from the Rapid7 datasets.

11:15.710 --> 11:17.170
I use this myself.

11:17.170 --> 11:20.710
It's a great way to just quickly grep through them if you're searching for something.

11:20.910 --> 11:23.170
And I also posted the runtime on there.

11:23.290 --> 11:27.030
The runtime is usually a fraction of a second to binary search through this data.

11:28.730 --> 11:43.450
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.

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 --> 12:05.450
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.

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:25.330
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.

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:38.590
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.

12:39.490 --> 12:48.490
And so similar to the DNS records with Rapid7, 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 --> 13:05.190
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.

13:05.590 --> 13:09.730
And this is actually fully automated at this point, 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:31.350
I found that my TLS scanner tends to pick up some more results than Shodan, which I found interesting.

13:31.390 --> 13:37.150
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.

13:37.690 --> 13:44.130
Certificate transparency monitors are awesome, but they only contain publicly trusted certs and they don't link back to where the cert came from.

13:44.330 --> 13:50.430
And Rapid7 actually has a TLS data set, 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:08.550
So just to give a demo here, obviously hack yourself first, 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:16.530
There's also, when I build these tools, 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:33.430
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.

14:33.710 --> 14:35.190
So I did that.

14:35.190 --> 14:44.510
And I found a WebLogic remote code execution 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:07.530
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.

15:08.290 --> 15:17.030
And so actually, one interesting thing about this is that they actually blocked outbound traffic, which would likely make automated skinners fail here.

15:17.030 --> 15:25.250
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.

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 --> 16:05.620
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,

16:05.620 --> 16:12.900
connecting to other hosts, they will have an automated reply 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:33.830
So you could do .mil, army.mil, and it would return you everything underneath that zone.

16:39.070 --> 16:40.670
Any other questions?

16:43.900 --> 16:44.800
Thank you.

16:44.800 --> 16:46.080
I hope this was interesting.

