start	end	text
0	7040	Well, so it's going to be 2.9 right now.
7140	12460	And originally we were going to have another person introduce Sam,
12460	16120	but he's a little bit camera shy, so I guess I've got to do it.
16480	26220	So I guess the best way I can introduce our next speaker is Council 9 Black Badge winner, Sam Earp.
26240	26980	Thank you.
26980	31540	Thank you. Hi, my name is Sam.
31820	34480	Today I'll be presenting on hunting certificates and servers.
35000	36620	And so let's get started.
37340	43020	Our team, Council 9, has won two black badges through the badge challenge.
44520	48120	As Meg mentioned, I'm also a software engineer at Akamai.
50400	54940	So one thing I have to be very clear here, the opinion is expressed here on my own, no one else's.
54940	58740	And be careful when you connect to any host online.
58740	64020	And always seek explicit permission before attempting to exploit, etc.
66020	68160	So there's three parts to this.
68160	69980	So part one is getting the internet.
70200	73380	So this is actually a DEF CON story.
73860	79640	As part of the badge challenge, we noticed the person who would run the badge challenge every year,
79640	82540	1057, would use the same TLDs over and over again.
82540	85240	In particular, he was very fond of the .codes TLD.
85520	89520	Unfortunately, there are not a lot of .codes domain names.
89720	94860	So he picked up on this and started monitoring for any new .codes registration online,
95400	103000	as well as scanning the internet for domains hosted that contained a .code domain.
103120	105480	We'd also then search for relevant Whois records as well.
106520	108940	And this was a pretty closely held secret by our team.
108940	111660	There were about 10 people or so that knew this at the time.
111660	114660	And I'm really only sharing it now simply because it's...
115180	118380	the contest is largely over in its current form anyways.
120200	122360	And so our scanners actually worked.
122360	123800	They picked up one domain.
123920	126560	We got a Slack notification that grey.codes was registered,
126560	129100	and it contained lost handle.
129160	131120	Therefore, it must be him, obviously.
132260	134260	So it contained a series of puzzles.
134260	135480	So we visited the website.
135480	139040	We spent about 72 hours not really sleeping, solving the puzzles,
139040	142140	thinking it was a registration for a contest or something similar.
143020	147180	And we sent through the solution on the final step.
147360	150200	This was November 2nd, 2016.
150760	152880	And lost replied back,
152880	154580	I don't know what you're talking about, essentially.
154580	156080	And it appears you've been trolled.
157600	163840	So I sent grey.codes a message on Twitter asking who he was and what he's doing.
164080	167460	And it turns out we weren't the only ones who got trolled.
167460	173660	All of the other teams who were competing against us at DEF CON that year also got trolled.
173780	178440	And, yeah, it actually turned out it was one of the ten people that we had told about this
178440	181600	trolled the rest of us using our own scanner.
184200	187180	So that was kind of my first introduction to scanning the Internet
187180	192020	and doing large-scale reconnaissance in the IPv4 space.
192100	197300	And that really got me thinking of what else I could find and search for on public Internet.
197900	202200	And one thing I'm very familiar with is TLS certificates.
202420	206100	And as you might know, TLS certificates contain host names.
206620	210960	And so before I talk about scanning the Internet for TLS certificates,
210960	212980	I have to talk about TLS.
212980	217280	And this is going to be really basic. I'm sorry if you're a TLS expert.
218160	223160	TLS handshake, you send over in the client hello,
223160	226120	you send over what you're connecting to in the server name indicator,
226120	227580	or who you're asking for.
227720	230920	Then the server will return back a certificate to you.
231500	236880	And then there's a handshake that occurs that drives the secret that's used to communicate.
238220	242240	And, yeah, so that's kind of like a high level of how TLS works.
242240	246720	So if you go to HTTPS, any website today, this is what your browser will be doing.
248220	251780	So I want the host names that are found in that second step there.
252600	259740	And so I wanted an efficient way to get these host names at scale,
259740	262480	ideally from as small a server as possible.
262480	267940	I'm not operating with any budget here. I'm running VPS with a single CPU core.
268680	271120	So I cut off the rest of the connection.
272060	278540	And so when I get a certificate back from the server,
278540	280280	I would just immediately kill the connection
280280	285120	and not continue along with the heavy crypto that's involved in doing the rest of the handshake.
285960	290480	This isn't really anything crazy.
290480	291880	It's entirely by the spec.
291880	295840	You're allowed to exit out of the handshake at any point if something goes wrong.
299020	303600	So, yeah, so by doing this, I'm able to save CPU costs on my server
303600	307100	and connect to many more servers for as cheap as possible.
308380	310340	So what's in an X.509 certificate?
310340	313420	Just to give you an example, this is one for google.com.
313420	315780	And as you can see, it contains many, many host names.
315780	317340	And this is fairly common.
317340	321120	You'll see either wildcard or just a list of domain names.
324240	329100	So as I kind of mentioned previously, I scanned the Internet for these.
329100	331000	So I set up a scanner.
331000	333520	So for every IPv4 host, I did two things.
333520	338260	I ran mass scan over it, which just checks whether or not port 443 is open.
338520	342160	I do that because nothing I write will be faster than mass scan.
342160	346100	So this is a good first filter to prove that 443 is open.
346320	352220	I then wrote a Golang program that sends a TLS client hello
352220	356080	and then gets the server certificate back and then just immediately disconnects.
356120	358780	And so the pseudocode roughly looks like this.
358780	362360	There's a few parsing steps in between, but this is essentially all that I run.
362360	366960	And I had to modify the Golang TLS stack to get this early return
366960	369080	because it's not really a standard thing to do.
369080	371980	It was actually surprisingly easy.
371980	374060	I really love working with the Golang TLS stack.
374060	379040	It's much, much easier than working with OpenSSL, if you're familiar with OpenSSL.
380580	385940	So this is what I set up and ran, and it took about 72 hours or so.
385940	392300	So I got about 12 gigabytes of data back, which was host name, IP address combinations.
393120	397060	And I then asked myself some really basic questions, like, am I finding every host?
397060	401520	And this scanner identified 51 million hosts online in the IPv4 space.
401600	405000	A 2015 paper that I found identified 42 million.
405000	408500	One really interesting thing, Shodan only finds 42 million today.
408500	411760	I don't understand the discrepancy between MyScanner and Shodan.
411760	414320	I suspect that Shodan's been blocked from parts of the Internet,
414320	416380	but I don't have any data to back that up.
418180	421220	And I have to ask myself, am I finding every certificate online?
421220	422620	And the answer really is no.
422840	427280	It's common server configuration in that client hello.
427280	429560	I could specify an SNI. It's a client server configuration
430040	433500	that the TLS client hello is used to differentiate clients.
433780	438120	And based on what you pass in there, that will turn a different certificate back to you.
438120	440420	And so this scanner will miss all of those.
440840	444520	Another thing I have to point out is that the Golang X.509 parser is very strict.
444740	446860	So if your server was doing something weird with certificates
447260	452040	or really just had any sort of non-standard X.509 cert,
452040	455440	it likely will not pass through Golang's X.509 parser.
455560	460360	And there's actually a blog post on how to parse malformed certificates there,
460360	461300	if you're interested.
462780	464720	So I also have to ask, who else is doing this?
464720	469400	Because none of this is really new or revolutionary, in my opinion.
469400	473360	So I set up a TLS server, and I just captured traffic.
473360	477380	And I just got the PCAP back.
477380	481820	And I actually found three servers that did the exact same thing that I'm doing.
481840	484880	Two of them were from universities,
484880	487360	which were scanning the internet for their own research purposes.
487360	491100	And one of them was from a hosting provider in Germany as well.
491100	493840	So clearly there's somebody in Germany who's doing the exact same thing
493840	497500	and simply not publishing it in any paper that I found.
499600	501900	I believe that they're doing the same thing as I am
501900	504860	because of the way that they closed the connections,
504860	507580	as well as there was no SNI sent in the connection they made to me.
507580	509480	So clearly they weren't trying to connect me to a host.
509480	513260	They were just simply trying to connect to my IP address
513260	515940	to just get back the certificate that I would return.
519410	526370	So I now have 12 gigabytes of host name, IP address combinations,
526370	529790	which is a lot of data and it's not the most friendly form to work with,
529790	531290	12 gigabytes of text.
531710	537510	So this is part two, which is how to search large parts of large DNS datasets.
537790	541790	And so this actually came about because I wanted to use the Rapid7 datasets.
542150	548570	So in the Rapid7 DNS, they have DNS listeners online
548570	555230	for FDNS and RDNS requests and forward and reverse DNS requests.
555910	558630	And you can just go to their website and download this.
558630	560230	It's a great resource. I love it.
560230	564030	It's just really hard to work with because it's 10 gigabytes of compressed text,
564030	567130	which expands out to about 100 gigabytes of uncompressed text.
567530	570470	And so this always took a long time to search.
570470	573210	Every time I wanted to search through this, it took about 20 minutes,
573210	574810	which is a little bit insane.
575010	579670	So I found myself trying to write better or trying to script, I should say,
579670	583770	better or more fast ways to decompress and grep
584450	588990	or use more disk space to grep faster.
589310	591050	And this obviously took a long time.
591050	594530	And I actually wrote a blog post about this,
595390	598690	which is linked to there, back in February.
598890	604490	And so in order to sort the data, I took advantage of the DNS structure.
604490	608670	So DNS is structured such that when you make a DNS request for,
608670	612850	in this case, blog.erbysam.com, you actually first go to the root,
612850	615890	which is dot, roughly com, and then you go to com,
615890	619750	and then you go to com.erbysam, and then you go to com.erbysam.blog.
620010	626030	And so you can take advantage of this in order to sort the data.
626170	632170	So I reversed every string, roughly, and sorted it.
632170	635070	At this point, because the data is sorted,
635070	639810	in order to find a host name that I'm looking for in this dataset,
639810	641290	I just simply have to binary search it,
641290	647030	which is an order of magnitude faster than grepping through the files,
648010	651250	if you're familiar with how binary searches work.
652590	654990	I talked about this in much more detail in my blog,
654990	656450	if you're interested in the technical details.
656450	658650	I also have code online on how to do this.
658830	661950	And this is actually something that's hosted online as well.
662710	665430	So I put this online using a Golang web server.
665570	670350	It's available today on dns.bufferover.run, bufferover.run.dns,
670350	674170	and you get back data from the Rapid7 datasets.
675710	677170	I use this myself.
677170	679370	It's a great way to just quickly grep through them
679370	680710	if you're searching for something.
680910	683170	And I also posted the runtime on there.
683290	685190	The runtime is usually a fraction of a second
685190	687030	to binary search through this data.
688730	691230	And I also linked to my GitHub account here,
691230	701890	which has the code to convert the data into a searchable format
701890	703450	that's usable by the server.
704990	708470	So one day I woke up and I checked the traffic for this website.
708470	709890	And I saw this.
709890	712810	And I thought, man, I'm a really good blogger.
712810	718490	But what had actually happened was I got pulled into something called Amass,
718490	723430	which is a utility for hostname reconnaissance
723430	725450	that's published by OWASP.
725590	727450	And this was completely unknown to me.
727450	729050	Luckily, the server held up.
729270	731310	I'm a little bit proud of that, personally.
731510	736230	But that was the source of all this data.
736390	738730	And the fact that it's so heavily cached
738730	740970	means that everyone's searching for the same hostnames,
740970	743550	or they're repeatedly searching for the same hostnames over and over again,
743550	745330	which I found really interesting.
747390	749670	So I actually don't collect data on this.
749670	751190	I don't actually know what everyone's searching for.
751190	753050	And I, frankly, don't really want to.
753850	757450	So now that I have a good data set and I have a good way to search it,
757450	758590	I want to put it all together.
759490	763710	And so similar to the DNS records with Rapid7,
763710	768490	I hosted this online at tls.bufferoverrun over .run.dns.
768670	770310	And this is actually online today.
770310	771930	And you're welcome to try it out.
773210	776730	It's literally just a combination of the data set
776730	780330	that the MySQL scanner picked up,
780330	785190	as well as the server behind the Rapid7 data set.
785590	787550	And this is actually fully automated at this point,
787550	789730	so this will refresh once a week.
791930	795770	So I then have to compare myself to what else is out there.
795770	799650	I'm mostly just curious to see if this is even necessary.
799650	804050	And so Shodan.io should contain similar results.
804150	805110	It's not free.
805730	810210	I found that my TLS scanner tends to pick up some more results than Shodan,
810210	811350	which I found interesting.
811390	812830	And that kind of goes back to my previous point
812830	815290	that I think Shodan is being blocked by large parts of the internet,
815290	817150	but I don't have any data to really prove that.
817690	819770	Certificate transparency monitors are awesome,
820210	821910	but they only contain publicly trusted certs
821910	824130	and they don't link back to where the cert came from.
824330	826390	And Rapid7 actually has a TLS data set,
826390	830430	but it's only the new certificates they encounter in their scans every week.
830430	834050	They don't have historical data unless you have an account with them.
834550	835590	And there are many others.
835590	840650	The OAuth AMS tool has a great list of existing resources online.
843070	846230	So just to give a demo here, obviously hack yourself first,
846230	848550	plug in your company's name, see what you find.
848610	850150	I find that really interesting.
850510	853510	There's also, when I build these tools,
853510	856530	one of the first things I do is I run them against .mil.
856530	861350	And I report whatever I find back to the DoD Vulnerability Disclosure Program.
861430	864970	So if you're interested in finding vulnerabilities,
864970	870870	go look at the 473,000 results here, find a host name,
870870	873430	try and exploit it, report what you find.
873710	875190	So I did that.
875190	879770	And I found a WebLogic remote code execution
879770	884510	that was still online from the 2017 exploit.
884590	888310	And I was able to exploit it and report it in.
888570	891110	And I just do this simply to test my tools.
891110	900190	But at the same time, because the military has such a variation of technology online,
900190	903770	because it's all subcontracted out, it's not all PHP, it's not all Java,
904330	907530	your tools will likely pick up something interesting.
908290	911150	And so actually, one interesting thing about this is that
911150	913710	they actually blocked outbound traffic,
913710	917030	which would likely make automated skinners fail here.
917030	921190	So I was able to demonstrate this by injecting a sleep of 12 seconds,
921190	925250	and then the result took 12 seconds to return back to me, demonstrating RCE.
928590	931650	So yeah, hack yourself first, hack your military first.
932530	933790	Thank you.
940070	941110	Questions?
944740	947220	I use Linode.
947340	951820	With Linode, if you are a security researcher,
951820	955160	or sorry, if you are doing something for security research,
955160	958480	you can get a security researcher designation on your account,
958480	960800	which means that as long as you follow the rules
960800	965620	and you have a page that links to what your tool is doing,
965620	966580	connecting to other hosts,
966580	970360	they will have an automated reply
970360	972900	to anybody filing abuse complaints against you.
980150	988470	No, it matches based on a reverse of the DNS name.
988750	991330	So you could do .mil, army.mil,
991330	993830	and it would return you everything underneath that zone.
999070	1000670	Any other questions?
1003900	1006080	Thank you. I hope this was interesting.
