1 00:00:00,000 --> 00:00:06,240 So welcome to pillaging DBCS repositories for fun and profit. A little bit about me, I'm 2 00:00:06,240 --> 00:00:14,340 Adam Baldwin, not to be confused with this Adam Baldwin. I co-founded Ingenuity, a pen 3 00:00:14,340 --> 00:00:23,760 testing firm, a pen tester of webs and I curate evilpacket.net. That's about it. So what the 4 00:00:23,760 --> 00:00:31,420 fuck is DBCS for those of you that might not be familiar with what Git, Mercurial or Bazaar are. 5 00:00:32,380 --> 00:00:37,880 They're distributed version control systems. They're source code management tools to keep 6 00:00:37,880 --> 00:00:46,480 track of revisions to files and crap like that. Sounds great. They're basically made up of a 7 00:00:46,480 --> 00:00:51,520 meta directory and a working tree at a high level. The meta directory is what we're going to 8 00:00:51,520 --> 00:00:53,740 be talking about today. The meta directory is the source code that's going to be working 9 00:00:53,740 --> 00:00:59,620 with us. It contains a bunch of really juicy information and great. That's the high level 10 00:00:59,620 --> 00:01:04,200 overview. So what's the problem with this? It sounds like a great tool for developers and for 11 00:01:04,200 --> 00:01:12,520 managing revisions and things like that. The problem is that this is being used by developers and 12 00:01:12,520 --> 00:01:22,380 by operations to push web apps out to production. They're starting to, it's a really popular tool 13 00:01:22,380 --> 00:01:28,300 right? Like Git push and now your shit's in production. The problem is that they're leaving 14 00:01:28,300 --> 00:01:33,960 these dot meta directories public. We're supposed to be blocking these. It's pretty standard 15 00:01:33,960 --> 00:01:41,600 practice to block dot directories. However, these are getting, these are getting left in web 16 00:01:41,600 --> 00:01:51,200 routes. And as an attacker, we want to have access to all of this, the information that's in this 17 00:01:51,200 --> 00:01:59,520 repository. The situation might be we're doing a pen test or we're an attacker and we want to get 18 00:02:00,960 --> 00:02:12,360 some foothold on this site. This might be that foothold. And no, that doesn't say dot gov. So in 19 00:02:13,050 --> 00:02:19,200 the situation that I ran into, we were deploying a site. They left the dot git meta directory in 20 00:02:20,500 --> 00:02:21,180 there. So we're going to have to do something about that. We're going to have to do something about 21 00:02:21,200 --> 00:02:28,540 theуй to. I wanted to see what type of exposure does this create? And as you'll see later on, we 22 00:02:28,540 --> 00:02:34,000 can't just simply clone the repository out of the web route. It just, it doesn't work that way. 23 00:02:34,860 --> 00:02:40,300 So once we, first step is identifying repositories. Then we need to figure out how to 24 00:02:40,300 --> 00:02:46,200 extract information from those repositories. And then of course some random process and then 25 00:02:46,200 --> 00:02:51,180 we'll profit as you will see. So here's how we identify repositories. Step number one is we're 26 00:02:51,200 --> 00:02:55,900 repositories. It's pretty damn simple. All three of them, Git, HG Bazaar, and there's others. I 27 00:02:55,900 --> 00:03:00,200 focused on these three. They all have predictable file names. They all have something in the 28 00:03:00,200 --> 00:03:08,780 repository that is, that you can access and then pull a regex match against. These are very 29 00:03:08,780 --> 00:03:13,400 lightweight files is why I picked these. They have great patterns, they're lightweight, and 30 00:03:13,400 --> 00:03:20,020 there's other files that are, that you could use, but they're a variable size and it's a real 31 00:03:20,020 --> 00:03:25,040 pain when you have to download, you know, a couple meg file to pattern match against. As an 32 00:03:25,040 --> 00:03:30,500 example, you can example.com slash .git slash head and it could be any directory. It doesn't 33 00:03:30,500 --> 00:03:36,120 have to be just the root. If you want to see the patterns that we're using, there's a plug-in 34 00:03:36,120 --> 00:03:43,760 for W3AF, for the web attack and audit framework scanner. Just go look at the code and 35 00:03:43,760 --> 00:03:50,000 there's the patterns that we're using in there. Very useful for identifying these. And then 36 00:03:50,020 --> 00:03:53,640 as far as I know, there's no other scanners that are looking for these other source code. 37 00:03:54,340 --> 00:04:01,300 Please, if somebody knows of them, correct me and let me know afterwards. So we wanted to 38 00:04:01,300 --> 00:04:08,280 understand just how large a scope this problem was, right? If we, you know, who is doing this? 39 00:04:08,520 --> 00:04:16,440 And so we scanned the top million Alexa sites and we found roughly 2000 repositories out of 40 00:04:16,440 --> 00:04:20,000 those a million sites. So it's not real common. But we have a lot of data. We have a lot of data. 41 00:04:20,020 --> 00:04:24,140 But as you will see, the impact and the information that we can extract from these 42 00:04:24,140 --> 00:04:31,280 repositories is pretty significant. Extremely useful to an attacker. And gives you that 43 00:04:31,280 --> 00:04:37,200 foothold that you might need. Obviously the most popular was Git out of all those. So that's 44 00:04:37,200 --> 00:04:44,780 what we'll demo in a bit. So once you've identified the repo that you have a Git repository or an 45 00:04:44,780 --> 00:04:50,000 HTML repository or bazaar, you need to clone that repository. So you need to clone that repository. 46 00:04:50,020 --> 00:04:58,620 And you can't simply run, say, Git clone and clone that URL. So here's the process that we came up 47 00:04:58,620 --> 00:05:05,520 with to actually extract data from the repositories. First thing you need to do is check for 48 00:05:05,520 --> 00:05:09,260 directory browsing. If directory browsing is enabled on the site, it's game over. You can 49 00:05:09,260 --> 00:05:18,020 simply wget the .git directory and then restore the repository. Git reset hard and then you've got 50 00:05:18,020 --> 00:05:20,000 your contents. You've got the source code. You've got the source code. You've got the 51 00:05:20,000 --> 00:05:28,100 entire tree. If that doesn't work, barring that, we need to get the predictable files. There's an 52 00:05:28,100 --> 00:05:33,020 index file in every single one of them, an index or a DIR state. That index file, that DIR state 53 00:05:33,020 --> 00:05:40,460 contains a listing of all of the stuff that's in that repository. And for a web application, 54 00:05:40,660 --> 00:05:44,500 that's the web root. That's all the crap that they're sticking in that web root. Source code 55 00:05:44,500 --> 00:05:49,380 files and anything else that might be included. So even if you're not able to extract any 56 00:05:49,380 --> 00:05:49,980 additional data from that repository, you're not going to be able to get the entire tree. If that's 57 00:05:49,980 --> 00:05:54,420 all data, you can glean a lot of information from just that single index file that's a 58 00:05:54,420 --> 00:06:01,520 predictable file in all instances. After we get that index and we parse that index, we need to 59 00:06:01,520 --> 00:06:05,860 download references that that index points to and then we can try to restore the repository after 60 00:06:05,860 --> 00:06:11,960 that. In some instances, that's not 100% possible because of how the repositories store data, but 61 00:06:11,960 --> 00:06:18,920 you're going to get enough information. So pillaging. Once we have our information, what kinds 62 00:06:18,920 --> 00:06:23,120 of things are we looking for? What are we going to find? Well, easy enough, we're going to find 63 00:06:23,120 --> 00:06:28,480 platform details. We're going to find if there's backup files, if there's SQL dumps in there, if 64 00:06:28,480 --> 00:06:33,560 there's source code. It's a web app, right? That's what it's going to be. Credentials, certs, API 65 00:06:33,560 --> 00:06:40,180 keys just to get you started thinking. Out of those top million sites, here's the kind of stuff 66 00:06:40,180 --> 00:06:43,740 that we found. And I'm not going to go through all of them, but some of the more interesting ones, 67 00:06:43,920 --> 00:06:48,900 SQL dumps of entire databases. Http, Http, Http, Http, Http, Http, Http, Http, Http, Http, Http, Http, Http. 68 00:06:48,900 --> 00:06:55,140 Passwords, Excel documents, mail spools. You're kind of getting the picture of stuff that we're 69 00:06:55,140 --> 00:07:02,620 going to find. And basically, these repositories shouldn't have this stuff checked into them. 70 00:07:02,720 --> 00:07:08,860 That's one of the core problems. Not that they just left that the meta directory is hanging out 71 00:07:08,860 --> 00:07:14,080 in the web route, but that the developers are checking this crap in. Right? They're not being 72 00:07:14,080 --> 00:07:18,880 audited. No one's giving a flying fuck what they put into the repository. So, you're going to get 73 00:07:18,900 --> 00:07:22,000 this crap in there. And even if they did and they go, oh, I shouldn't have put that in there, 74 00:07:22,480 --> 00:07:27,400 they just remove it. And they forget about this old revision that's hanging out in the tree. 75 00:07:27,580 --> 00:07:34,260 And so, if you're, you can find stuff that's not just in the current revision. If you look a few 76 00:07:34,260 --> 00:07:41,600 back, you're going to find some really juicy stuff potentially just by looking at the logs. So, 77 00:07:41,660 --> 00:07:48,880 here's, here's the epic fail montage, the remember pillage, then, then, then, then, then, then, 78 00:07:48,900 --> 00:07:57,300 burn. Just some of the really, really fun stuff that we found. Database passwords. In shell 79 00:07:57,300 --> 00:08:14,600 scripts. Database dumps. That does not say dot gov. As well as user tables. Absolute piles and 80 00:08:14,600 --> 00:08:18,820 piles and piles of sequel dumps that people had done and just said, oh, we'll check them into the 81 00:08:18,900 --> 00:08:24,060 repository and push them to our git server. Because that's cheap backup and it's a really good 82 00:08:24,060 --> 00:08:29,820 idea. Git ignore. The git ignore file or the htignore file. Every one of these has a different 83 00:08:29,820 --> 00:08:38,300 ignore file but they're really useful. It's the, it's the developer's way of saying we don't 84 00:08:38,300 --> 00:08:42,320 want to be bothered by this stuff in our repository. So, so we're going to ignore it. We 85 00:08:42,320 --> 00:08:44,860 don't want to be bothered. And we're not going to check it into our repository but we're going 86 00:08:44,860 --> 00:08:48,880 to put a pattern into the, the, the ignore file. What's the problem? You're going to get a lot of 87 00:08:48,900 --> 00:08:52,580 really good place to look because you're like oh these are the juicy things that you don't want 88 00:08:52,580 --> 00:08:59,120 us to know about but now we know about it. It's kind of like the robots.txt thing. How about 89 00:08:59,120 --> 00:09:03,840 customer invoices? This particular site had I'm pretty sure every customer invoice it ever 90 00:09:03,840 --> 00:09:09,520 generated hanging out in their repository. They weren't predictable file names in the web 91 00:09:09,520 --> 00:09:12,900 route. You wouldn't have been able to easily brute force them with something like Dirt Buster 92 00:09:12,900 --> 00:09:19,860 or anything like that. But you could extract them from the repository. How about some API keys? 93 00:09:20,000 --> 00:09:29,020 Apparently they still use MySpace. Google API, Facebook. SSH key for the EC2 instance. Those 94 00:09:29,020 --> 00:09:39,000 aren't useful at all are they? I don't know. HD passwords. This is a really interesting one as 95 00:09:39,000 --> 00:09:42,880 well. It's a German site. It's a German site. It's a German site. It's a German site. It's a 96 00:09:42,900 --> 00:09:44,260 German site. It's a German site. It's a German site. It's a German site. When you went to the 97 00:09:44,260 --> 00:09:52,880 actual file in the web route it was HD password protected. If you pull it out of the repository 98 00:09:52,880 --> 00:09:58,760 you can obviously get that particular file. I'd really be curious on the discussion I'd love 99 00:09:58,760 --> 00:10:04,600 to have this discussion with the EFF on is this actually bypassing access control? These files 100 00:10:04,600 --> 00:10:09,300 are public because they're in the dot git directory. They're just sitting there. You don't 101 00:10:09,300 --> 00:10:12,880 actually have to bypass access control to access them. So yeah. That's a good question. If you 102 00:10:12,900 --> 00:10:18,200 So what type of line are you crossing if you're accessing this stuff in the git directory? 103 00:10:18,420 --> 00:10:24,160 In the meta directory? Coincidentally enough, these are account numbers and routing numbers 104 00:10:24,900 --> 00:10:34,880 for a very large pile of their customers. So yeah, no authorization required. How about 105 00:10:34,880 --> 00:10:40,140 credit card numbers and doc files? Seriously? What the fuck? 106 00:10:42,960 --> 00:10:54,720 Yeah, this is actually a non-U.S. company. So I don't know if PCI. Wow, that went fast. 107 00:10:55,000 --> 00:11:03,480 So we have a demo. And then a tool release to automate all of this. Because I really didn't 108 00:11:03,480 --> 00:11:11,260 give you any technical details. Because I don't know. So demo time. Hey, look, demo. 109 00:11:12,900 --> 00:11:21,540 So what I did was I pulled down the DVCS toolkit. Once I push that up on the github, you'll get 110 00:11:21,540 --> 00:11:34,760 the URL in a bit. What I included was a tool for BZR, BZGIT and. And I included the 111 00:11:34,760 --> 00:11:41,440 PyCloud scripts that we use to scan the top million sites. So you can just use them. PyCloud is 112 00:11:41,440 --> 00:11:42,880 very handy for and I have a lot of quick access it and I can really help you out. And I 113 00:11:43,500 --> 00:11:52,400 a lot of stuff simultaneously. And some rejects and that's about it. So to start out I'm 114 00:11:52,400 --> 00:11:59,860 going to show you, here's the git directory of our target site. As you see there's a lot of 115 00:12:01,100 --> 00:12:05,860 different predictable file names. We've got configs, we've got the index file, the object 116 00:12:05,860 --> 00:12:12,280 store. This is how git stores all their crap, right? It's the shaw value of a particular 117 00:12:12,280 --> 00:12:20,780 file. And those are the files that we're going to go after. And so let's show that git clone. 118 00:12:22,320 --> 00:12:37,320 Git clone. Yeah, it doesn't work. Same thing with BZ and HG. It's not going to work. If we run 119 00:12:37,320 --> 00:12:42,260 the particular git pillage, it's not going to work. It's not going to work. It's not going to 120 00:12:42,280 --> 00:12:47,180 work. What it does is it pulls down the index file, parses it and lets you know, hey, you're 121 00:12:47,180 --> 00:12:52,360 about to make 1,900 requests. Depending on the site and depending on what they check in, this 122 00:12:52,360 --> 00:12:59,600 could take a really, really, really long time. Some sites had 20, 30,000 objects in their data 123 00:12:59,600 --> 00:13:06,520 store. For those situations, don't download it. Figure out what you might want to go after. Just 124 00:13:06,520 --> 00:13:12,260 hit no, look in the index file yourself, and then you're good to go. And then you're good to go. 125 00:13:12,260 --> 00:13:16,300 Look to see what juicy information you might want. They might not have anything you actually want 126 00:13:16,300 --> 00:13:23,360 to download. So in our case, we're going to hit yes. It's just a lot of annoying scrolling text. 127 00:13:24,220 --> 00:13:28,460 It's basically telling you all the objects it's going to get, and it's pulling down those 128 00:13:28,460 --> 00:13:36,100 references. Anybody uses the tool. If you get 404s, that's normal. Git doesn't let you get some 129 00:13:36,100 --> 00:13:40,940 of them, just based on how it works. After it downloads those references, it tries to check out 130 00:13:40,940 --> 00:13:42,240 each file to restore it. And then it doesn't let you get any of those references. And then it tries to 131 00:13:42,260 --> 00:13:54,900 into your working directory. It works on git, bizarre and 132 00:13:54,900 --> 00:14:10,420 Mercurial. All right. So it's kind of hard to see because the 133 00:14:10,420 --> 00:14:17,860 large font. Once it checks out all the files, it's just going to run those file names against a 134 00:14:20,420 --> 00:14:25,240 regex file that we included in the tool kit and I'd love some contributions to that and it 135 00:14:25,240 --> 00:14:28,300 kind of shows you, oh, these might be files of interest that you might want to go look at 136 00:14:28,300 --> 00:14:32,800 right away. Pretty cheesy, pretty error prone as you can see. There's crap we just don't care 137 00:14:32,800 --> 00:14:40,400 about. I'm going to sanitize this file so you guys don't know who this is from. I'm going to 138 00:14:40,420 --> 00:14:47,000 go ahead and do that. Well, first of all, there's all the source code for the site. Yay. So 139 00:14:47,000 --> 00:14:51,100 you've got all the, everything in the web root that we're able to check out. So now you went 140 00:14:51,100 --> 00:14:56,340 from having no knowledge, you know, of the site to actually having the entire source code tree 141 00:14:56,340 --> 00:15:00,440 for that web application, which is really, really, really powerful from an attacker's 142 00:15:00,440 --> 00:15:08,340 perspective. Let's sanitize the WP config. Great. This is a WordPress site, right? Let's 143 00:15:08,340 --> 00:15:08,960 hope that worked. 144 00:15:11,460 --> 00:15:18,720 There's some cookie ashes. Database, password, you know, again, all the crap that you'd find in a 145 00:15:18,720 --> 00:15:30,420 WordPress config. Auth keys, all that stuff. I've sanitized them in there, but that's, that's 146 00:15:30,420 --> 00:15:34,400 something just so I can sanitize this file so you don't know who this particular site came from. 147 00:15:34,980 --> 00:15:40,400 It's just a random WordPress site. I'm going to go ahead and do that. I'm going to go ahead and 148 00:15:40,420 --> 00:15:55,840 see. So that's pretty much it. That's the tool. You can get the tool at the GitHub repository 149 00:15:55,840 --> 00:16:02,580 there. And I will be putting that up after the talk. I forgot to set it public before I got up 150 00:16:02,580 --> 00:16:07,940 here. Please fork and contribute. There's lots of bugs. There's stuff that it could use feature-wise. 151 00:16:08,540 --> 00:16:16,680 It could use some love. Please contribute. Questions and answers in the QA room. That's it.