1 00:00:00,000 --> 00:00:11,380 Hello, everyone. Can you hear me in back? Yep. Good, good. My name is Fyodor from Insecure.org and the 2 00:00:11,380 --> 00:00:18,260 MMAP project. I'm here with NMAP's co-maintainer, David Fifield. I'd like to thank you all for 3 00:00:18,260 --> 00:00:24,260 coming and, of course, DEF CON for having me. I've been going to DEF CON for 12 years and it's one of 4 00:00:24,260 --> 00:00:29,680 my favorite conferences. Basically, I don't think there's really anywhere else in the world that 5 00:00:29,680 --> 00:00:37,280 you get such a concentration of smart people, passion for technology and energy as you do at DEF 6 00:00:37,280 --> 00:00:46,380 CON. There's also the parties as well. So I think I'm going to start out this presentation with a 7 00:00:46,380 --> 00:00:50,540 couple questions for the audience that will help us give us an idea of how much introductory 8 00:00:50,540 --> 00:00:56,520 material we need to cover. Could I get a show of hands for anyone here who has heard of and used 9 00:00:56,520 --> 00:00:58,080 the NMAP security scanner? 10 00:01:01,780 --> 00:01:07,520 Awesome. All right. Well, we'll definitely skip NMAP for dummies then. What about a little harder 11 00:01:07,520 --> 00:01:15,200 question? Who has used a newer feature on NMAP, the NMAP scripting engine? Okay. Well, we've got at 12 00:01:15,200 --> 00:01:20,440 least a third of you, maybe a half. That's great. And for those who haven't, we're going to really 13 00:01:20,440 --> 00:01:26,520 show the highlights and features of the NMAP scripting engine and maybe we'll be able to inspire 14 00:01:26,520 --> 00:01:28,160 you to give it a try. 15 00:01:29,680 --> 00:01:46,560 I want to mention that all of the... Oops. Cancel, cancel, cancel. Evil hackers in this room. I 16 00:01:46,560 --> 00:01:57,500 think we'll take wired, please. All right. So these features that we're going to show are all 17 00:01:57,500 --> 00:01:59,660 available in NMAP version 5.0. 18 00:01:59,680 --> 00:02:02,860 This is our new version of the NMAP code. It's called 5.3.5DC1, the DEFCON release we made 19 00:02:02,860 --> 00:02:10,260 earlier this month. And also in 5.3.5DC18 for some of the newer ones, which is our latest 20 00:02:10,260 --> 00:02:19,140 subversion repository code. So let's get started. The slides are kind of cut off on the left a bit. 21 00:02:19,360 --> 00:02:26,920 But I'm hoping that none of that will be so critical and we'll be able to work around it. So I'm going 22 00:02:26,920 --> 00:02:29,660 to start with just a little outline so you know what we're going to cover next. All right. We're going to 23 00:02:29,680 --> 00:02:32,440 cover in this talk. First we're going to give a quick 24 00:02:32,440 --> 00:02:35,660 introduction to the Nmap scripting engine, what it is, 25 00:02:35,760 --> 00:02:39,340 how to use it, why we built it. And then we're going to actually 26 00:02:39,340 --> 00:02:43,340 give you a demo to show you the power of the Nmap scripting 27 00:02:43,340 --> 00:02:47,520 engine. And we're going to do that by a large scale scan of 28 00:02:47,520 --> 00:02:55,520 more than a million IPs of a major corporation. All right. 29 00:02:55,520 --> 00:03:04,700 We're going to hide this panel. Okay. So after we show you the 30 00:03:04,700 --> 00:03:07,960 large scale demo, we're going to then go into taking the next 31 00:03:07,960 --> 00:03:11,780 step and actually writing your own NSE scripts and how to do 32 00:03:11,780 --> 00:03:15,600 that. And then David has a really great demo to really 33 00:03:15,600 --> 00:03:19,640 demonstrate the ease of writing an NSE script by writing one 34 00:03:19,640 --> 00:03:23,880 from scratch right in front of you in front of 500 people. And 35 00:03:24,660 --> 00:03:25,500 hopefully he does it. 36 00:03:25,500 --> 00:03:30,480 He doesn't have any syntax errors. So then after that we'll 37 00:03:30,480 --> 00:03:33,280 do the final notes and then we'll move to the Q&A room for 38 00:03:33,280 --> 00:03:37,840 the questions and answers. So the Nmap scripting engine is 39 00:03:37,840 --> 00:03:41,380 one of Nmap's most powerful and flexible features. It allows 40 00:03:41,380 --> 00:03:45,840 users to write and share simple scripts that they can use to 41 00:03:45,840 --> 00:03:50,020 automate networking tasks from enhanced network discovery to 42 00:03:50,020 --> 00:03:55,040 vulnerability detection or even exploitation. And the good news 43 00:03:55,040 --> 00:03:55,480 is, we're going to be able to use it for a number of different 44 00:03:55,500 --> 00:03:57,900 purposes. You don't have to write all these scripts yourself. 45 00:03:58,400 --> 00:04:03,660 Nmap ships with a library of 131 NSE scripts which already can 46 00:04:03,660 --> 00:04:09,280 handle a wide variety of tasks. I feel that NSE really completes 47 00:04:09,280 --> 00:04:13,740 Nmap scanning mission. We already had host discovery where 48 00:04:13,740 --> 00:04:16,560 Nmap scans the networks and tries to find the machines that 49 00:04:16,560 --> 00:04:21,000 are up and available. We had OS detection where Nmap would figure 50 00:04:21,000 --> 00:04:25,140 out what operating system those machines are running. We had port 51 00:04:25,140 --> 00:04:28,560 scanning followed by version detection in order to find all 52 00:04:28,560 --> 00:04:31,380 the services there, what application and version numbers 53 00:04:31,380 --> 00:04:36,200 they're running. And then NSE is basically the glue that binds 54 00:04:36,200 --> 00:04:40,320 all of this knowledge together about the network. You can use 55 00:04:40,320 --> 00:04:44,020 it to interrogate the host in pretty much any way you desire. 56 00:04:44,500 --> 00:04:47,320 We're going to look at an example on this slide. I don't 57 00:04:47,320 --> 00:04:49,820 know if you can read it in the back, but we're going to go over 58 00:04:49,820 --> 00:04:53,700 what it says anyhow. Basically here we're doing a scan of a 59 00:04:53,700 --> 00:04:55,120 machine, scanme.nse. We're going to look at an example on 60 00:04:55,120 --> 00:04:58,860 Nmap.org. That's when I run for the purpose of people testing 61 00:04:58,860 --> 00:05:04,560 their Nmap, make sure it's working well. And basically you'll 62 00:05:04,560 --> 00:05:08,060 find out in this talk that I'm not really shy about scanning 63 00:05:08,060 --> 00:05:11,760 other people's machines. And so I feel it's only fair to provide 64 00:05:11,760 --> 00:05:16,320 one of my own that people can use to scan me back. We're also 65 00:05:16,320 --> 00:05:19,540 giving the capital A option which tells Nmap to use its 66 00:05:19,540 --> 00:05:23,460 advanced features such as OS detection, version detection, 67 00:05:23,700 --> 00:05:25,100 and the Nmap scripting app. We're also giving the capital A 68 00:05:25,120 --> 00:05:27,540 option to use the Nmap engine. And then we get these results. 69 00:05:27,940 --> 00:05:31,420 Now most of it is going to be familiar to typical Nmap users, 70 00:05:31,700 --> 00:05:35,500 regular Nmap users. But I want to highlight the Nmap scripting 71 00:05:35,500 --> 00:05:41,200 engine results from this. First we have the under SSH, the SSH 72 00:05:41,200 --> 00:05:46,220 host key script which just grabs the cryptographic key hash that 73 00:05:46,220 --> 00:05:49,740 the server uses to identify itself. And while that might be 74 00:05:49,740 --> 00:05:53,020 useful for say a script that you would use to scan the network 75 00:05:53,020 --> 00:05:55,100 and find bogus keys that could be used to scan the network, we 76 00:05:55,120 --> 00:05:58,020 have the SSH host key indicative of an attack or Trojan SSH. 77 00:05:58,260 --> 00:06:02,860 What I like to use it for is machines, a form of unique 78 00:06:02,860 --> 00:06:08,120 identification that is independent of IP address. So 79 00:06:08,120 --> 00:06:11,520 say I'm scanning a machine. I find one. I'm really interested 80 00:06:11,520 --> 00:06:15,260 into it. Maybe I manage to brute force some passwords. The next 81 00:06:15,260 --> 00:06:19,020 day I try to get into it further. But it's gone. Maybe 82 00:06:19,020 --> 00:06:22,460 it's a DHCP client. It could have changed address to 83 00:06:22,460 --> 00:06:25,100 anything else. Well, with SSH host key, it's not going to be 84 00:06:25,120 --> 00:06:27,880 easy. What I do is scan the network again and try and find 85 00:06:27,880 --> 00:06:32,180 that key. Similarly, if I'm doing a big scan and I see a 86 00:06:32,180 --> 00:06:35,700 bunch of machines that seem to be configured similarly, are 87 00:06:35,700 --> 00:06:39,020 those really different machines or is it just one machine with a 88 00:06:39,020 --> 00:06:43,720 bunch of IP aliases? Well, with host key script, that's a good 89 00:06:43,720 --> 00:06:47,660 way to figure it out. You'll also see some scripts below the 90 00:06:47,660 --> 00:06:53,860 HTTP port. We've got HTML title which is a super simple script 91 00:06:53,860 --> 00:06:55,100 which just grabs the code. It's not going to be easy to get 92 00:06:55,120 --> 00:06:58,620 the root web page from a web server and tells you the title. 93 00:06:58,820 --> 00:07:02,540 Very easy to do but useful information in the context of a 94 00:07:02,540 --> 00:07:07,280 scan. We also have HTTP methods which basically says what 95 00:07:07,280 --> 00:07:09,960 methods does this server support? Get, post, whatever. 96 00:07:10,280 --> 00:07:14,060 In this case, it says the trace method is potentially a little 97 00:07:14,060 --> 00:07:18,060 bit risky. Here's a URL you can use to find out more. If it had 98 00:07:18,060 --> 00:07:21,720 like the delete method or the put method, then it would be 99 00:07:21,720 --> 00:07:25,100 sounding even bigger alarm bells. So the nice thing about 100 00:07:25,120 --> 00:07:29,660 this is that with NSE, it puts the results down here by the port 101 00:07:29,660 --> 00:07:33,440 or host that they related to so you can see them all in one 102 00:07:33,440 --> 00:07:41,040 place. Now I mentioned that we already have a library of scripts 103 00:07:41,040 --> 00:07:45,660 here. Is this zoomed enough that you guys can read it in the 104 00:07:45,660 --> 00:07:52,840 back? Yes? Good deal. So this script, we have 131 of them and 105 00:07:52,840 --> 00:07:54,840 I'm certainly not going to go through them all right now. 106 00:07:55,120 --> 00:07:58,820 But I want to mention on the left side, these categories that 107 00:07:58,820 --> 00:08:03,460 we have. So you can get an idea of the breadth of tasks that NSE 108 00:08:03,460 --> 00:08:07,700 can be useful for. The auth category is for authorization 109 00:08:07,700 --> 00:08:11,960 related scripts like we see up here the AFP brute force script 110 00:08:12,500 --> 00:08:15,580 which does brute force authentication cracking for the 111 00:08:15,580 --> 00:08:20,100 Apple filing protocol. We have default scripts which is a hand 112 00:08:20,100 --> 00:08:23,720 curated set we select to find the ones that are most useful to 113 00:08:23,720 --> 00:08:25,100 people. And these are the ones that are most useful to people. 114 00:08:25,100 --> 00:08:26,580 These are the ones that are most likely to cause network 115 00:08:26,580 --> 00:08:29,820 disruption or to be perceived as attack or otherwise 116 00:08:29,820 --> 00:08:33,780 undesirable. We have discovery tests. I mean that's kind of 117 00:08:33,780 --> 00:08:37,840 NMAP's bread and butter. So if you click on a category, you can 118 00:08:37,840 --> 00:08:41,820 see all of the scripts that are in that category. And so for 119 00:08:41,820 --> 00:08:45,220 discovery, we have a bunch of information. If a DB2 database 120 00:08:45,220 --> 00:08:48,400 is found, tell us what's up there. Grab information from 121 00:08:48,400 --> 00:08:55,080 DHCP, DNS, HTTP, and it goes on and on. So we have a bunch of 122 00:08:58,120 --> 00:09:00,880 things. We have the DOS category for denial of service 123 00:09:00,880 --> 00:09:04,060 attacks. There's only one of those. I think we only have one 124 00:09:04,060 --> 00:09:08,520 in the exploit category for exploits now. External, that's 125 00:09:08,520 --> 00:09:12,500 kind of a policy related category. Fuzzers. We have 126 00:09:12,500 --> 00:09:15,720 intrusive and safe categories are two important ones to know. 127 00:09:16,160 --> 00:09:19,340 Basically, the safe ones, we feel those are the ones you can 128 00:09:19,340 --> 00:09:22,480 run with little risk. They're not usually going to use a lot 129 00:09:22,480 --> 00:09:24,720 of network resources. They're not likely to crash 130 00:09:25,100 --> 00:09:28,200 servers. They're not likely to be perceived as really hostile 131 00:09:28,200 --> 00:09:32,360 by a network admin. Whereas the ones that aren't safe that we 132 00:09:32,360 --> 00:09:34,560 think do have some of those problems, we put in the 133 00:09:34,560 --> 00:09:37,840 intrusive category so that you can consider more carefully why 134 00:09:37,840 --> 00:09:41,520 is it intrusive and does that matter to me before you decide 135 00:09:41,520 --> 00:09:45,920 on your scan. We have a malware category. For example, NMAP was 136 00:09:45,920 --> 00:09:48,640 one of the first scanners to remotely detect the config or 137 00:09:48,640 --> 00:09:52,320 worm last year. And the malware category is where that would 138 00:09:52,320 --> 00:09:55,080 belong. Version detection. NMAP is one of the first scanners to 139 00:09:55,100 --> 00:09:58,120 do that. NMAP's version detection engine now has more 140 00:09:58,120 --> 00:10:02,100 than 6,000 version detection signatures in it. So we can 141 00:10:02,100 --> 00:10:05,600 detect a huge number of applications. But there are some 142 00:10:05,600 --> 00:10:10,560 protocols that they're basically designed to hide from people 143 00:10:10,560 --> 00:10:13,120 trying to detect them on the network. Skype is an example. 144 00:10:13,400 --> 00:10:16,200 And for those where our version detection isn't strong enough, 145 00:10:16,560 --> 00:10:20,620 well, we found methods with NSE with its ability to interrogate 146 00:10:20,620 --> 00:10:24,600 multiple probes and analyze the responses more carefully is able 147 00:10:24,600 --> 00:10:25,080 to do that. So we've found methods with NSE with its ability 148 00:10:25,080 --> 00:10:27,960 to do those. And then we have vulnerability detection related 149 00:10:27,960 --> 00:10:32,500 scripts. So this NSE doc page, which you can visit at any time 150 00:10:32,500 --> 00:10:36,680 at NMAP.org.NSE doc, is really an easy way to find the scripts 151 00:10:36,680 --> 00:10:40,060 that you think are going to be useful. And when you find the 152 00:10:40,060 --> 00:10:42,900 script you want, you can actually take it a little bit 153 00:10:42,900 --> 00:10:46,860 further. We're going to look at a script real quickly called 154 00:10:46,860 --> 00:10:53,000 NFS-LS. That basically says if NMAP detects an NFS server on 155 00:10:53,000 --> 00:10:55,060 the network, you can use NFS-LS to detect the script that you 156 00:10:55,060 --> 00:10:56,420 think is going to be useful. You can also use NFS-LS to say what 157 00:10:56,420 --> 00:11:01,380 shares are available, what list the file names in those shares, 158 00:11:01,540 --> 00:11:04,320 as well as the permission information. And yes, this is 159 00:11:04,320 --> 00:11:06,960 stuff you could already get from running other tools separately. 160 00:11:07,280 --> 00:11:10,480 But the nice thing is to have it all in your scan results all run 161 00:11:10,480 --> 00:11:15,380 automatically together. And so you find that through NSE doc, 162 00:11:15,620 --> 00:11:18,860 and then you can actually click on it to get information about 163 00:11:18,860 --> 00:11:23,600 that script itself. So the very first link is to get the source 164 00:11:23,600 --> 00:11:25,040 code of the script. And then you can actually click on it to get 165 00:11:25,060 --> 00:11:26,220 information about that script. If you really want to figure out 166 00:11:26,220 --> 00:11:30,640 what it's doing, that's where you're going to go. The next is 167 00:11:30,640 --> 00:11:33,880 the description of the script. Basically tells you what the 168 00:11:33,880 --> 00:11:37,720 script does. You get all the arguments for the script. We 169 00:11:37,720 --> 00:11:40,380 have the wrong script here, obviously. This is the show 170 00:11:40,380 --> 00:11:47,740 amount script instead of the LS script. This one has a bigger 171 00:11:47,740 --> 00:11:52,780 summary because it's more useful of a script. You can see the 172 00:11:52,780 --> 00:11:55,040 arguments. It takes like maximum number of files. It's 173 00:11:55,060 --> 00:11:57,880 a lot of files. You want it to show whether you want the 174 00:11:57,880 --> 00:12:02,220 modification time or access time or what. You get example usage so 175 00:12:02,220 --> 00:12:06,160 you know how to use it. We see some of the arguments are from a 176 00:12:06,160 --> 00:12:11,200 helper library we have for RPC and NFS. So you can see these 177 00:12:11,200 --> 00:12:13,940 arguments aren't specific to this script, but they're specific 178 00:12:13,940 --> 00:12:16,960 to a library that the script uses and so they might be useful. 179 00:12:17,600 --> 00:12:21,160 You get an output. And as you can see, the author of this 180 00:12:21,160 --> 00:12:24,980 tried hard to make it look basically like a directory list 181 00:12:25,060 --> 00:12:28,240 thing you get from LS. And then you get things like what 182 00:12:28,240 --> 00:12:32,720 categories it's in. In this case for listing NFS directories, it's 183 00:12:32,720 --> 00:12:35,020 in discovery because you're figuring out information about 184 00:12:35,020 --> 00:12:37,900 the network. And it's in safe because you're not really doing 185 00:12:37,900 --> 00:12:41,340 anything intrusive. You're basically using this service as 186 00:12:41,340 --> 00:12:46,120 it was intended. So we have a lot of scripts now. 131 I 187 00:12:46,120 --> 00:12:50,140 mentioned. And it's always growing. Here's an example of 188 00:12:50,140 --> 00:12:54,820 the data behind that growth. We started out with about 20 189 00:12:54,820 --> 00:12:55,040 scripts. We started out with about 20 scripts. We started out 190 00:12:55,060 --> 00:12:58,100 with about 20 scripts. It took us some time to get our review 191 00:12:58,100 --> 00:13:01,400 process in place, to get all the infrastructure there to easily 192 00:13:02,040 --> 00:13:05,540 write and process scripts. But then lately it's just been 193 00:13:05,540 --> 00:13:08,220 growing like we can't hardly believe. I mean, we've been 194 00:13:08,220 --> 00:13:11,480 working four years on this system and had it in NMAP for 195 00:13:11,480 --> 00:13:14,560 three and a half. But more than half of our scripts have been 196 00:13:14,560 --> 00:13:17,540 written in the last year. And I won't be surprised if when 197 00:13:17,540 --> 00:13:25,040 DEF CON rolls around next year, it's doubled again. So we've 198 00:13:31,200 --> 00:13:35,120 basically shown you the raw basics of NSE. Basically what it 199 00:13:35,120 --> 00:13:39,460 is, what it can do. Now let's actually show you an example of 200 00:13:39,460 --> 00:13:43,060 what it can do. And to do this, I want to introduce you to a 201 00:13:43,060 --> 00:13:46,620 set of scripts written by a fellow named Ron Bose who spent 202 00:13:46,620 --> 00:13:51,940 months researching the SMB and MSRPC protocols. Which is not 203 00:13:51,940 --> 00:13:55,020 something I would really wish on anyone. But it's something that 204 00:13:55,020 --> 00:13:58,760 I'm glad he did it. And these 13 scripts are a great gift to the 205 00:13:58,760 --> 00:14:03,040 NMAP community. Basically there's informational scripts to just 206 00:14:03,040 --> 00:14:07,080 query the SMB server and say give us the detailed OS 207 00:14:07,080 --> 00:14:10,220 information, including service pack and such, the server stats, 208 00:14:10,560 --> 00:14:14,280 the system info, the security mode. We have enumeration scripts 209 00:14:14,590 --> 00:14:17,840 to say contact the server and give us a list of users or 210 00:14:17,840 --> 00:14:21,720 domains or groups or processes, sessions or shares. And then we 211 00:14:21,720 --> 00:14:24,920 have three more intrusive scripts. We have SMB brute, 212 00:14:25,020 --> 00:14:28,160 which does brute force authentication cracking against 213 00:14:28,160 --> 00:14:31,820 the server to try and figure out passwords. And it can work in 214 00:14:31,820 --> 00:14:37,180 conjunction with the SMB enum users so that you already have a 215 00:14:37,180 --> 00:14:41,440 user list. We have SMB check vulns, which checks for a number 216 00:14:41,440 --> 00:14:45,880 of remotely exploitable MSRPC bugs. And then we have SMB PS 217 00:14:45,880 --> 00:14:49,920 exec, which allows you to execute arbitrary commands on 218 00:14:49,920 --> 00:14:53,200 the server with some canned ones available for you for things 219 00:14:53,200 --> 00:14:54,820 like dumping hash word passes. 220 00:14:55,540 --> 00:15:00,080 Dumping password hashes. You can look at the different, you 221 00:15:00,080 --> 00:15:03,640 might want to start a remote display server, that sort of 222 00:15:03,640 --> 00:15:07,760 thing. So Ron sent me all these scripts and I'm like, 223 00:15:07,900 --> 00:15:11,360 these things are awesome, but I don't run very many Windows 224 00:15:11,360 --> 00:15:16,080 machines on my home network. And so I was thinking, who, how am I 225 00:15:16,080 --> 00:15:19,460 going to test these? What sort of company might have a lot of 226 00:15:19,460 --> 00:15:21,060 these to run against? 227 00:15:28,720 --> 00:15:32,220 So I thought, you know, it would be pretty interesting. 228 00:15:32,400 --> 00:15:35,300 Since it's their own darn protocol, you would think if 229 00:15:35,300 --> 00:15:41,300 anyone can secure it, Microsoft would be able to. And I thought 230 00:15:41,740 --> 00:15:44,620 it might be interesting to see what sort of policies they take. 231 00:15:44,780 --> 00:15:48,100 Do they just ban it at the perimeter? Do they lock the 232 00:15:48,100 --> 00:15:51,100 servers down so that they don't allow the guest access and the 233 00:15:51,100 --> 00:15:54,760 IPC share and that sort of thing? What is it that they really do? 234 00:15:55,020 --> 00:15:59,180 So I designed a scan. Step one was finding the target IP 235 00:15:59,180 --> 00:16:03,600 addresses allocated to Microsoft and I used typical things, you 236 00:16:03,600 --> 00:16:06,460 know, look up the error in database to find allocations and 237 00:16:06,460 --> 00:16:09,420 eventually I found more than a million of them and decided to 238 00:16:09,420 --> 00:16:10,080 scan them all. 239 00:16:13,680 --> 00:16:18,440 I started with a broad version detection scan. So basically 240 00:16:18,440 --> 00:16:21,780 this scan, I didn't want it to be super, super intrusive and 241 00:16:21,780 --> 00:16:24,760 detailed for the first scan. I kind of wanted to have an idea 242 00:16:25,020 --> 00:16:29,400 of what was there and then I could scan further on once I've 243 00:16:29,400 --> 00:16:32,440 seen the initial results. That gives me faster results and 244 00:16:32,440 --> 00:16:36,040 makes it less likely to raise a lot of eyebrows. So we say end 245 00:16:36,040 --> 00:16:39,900 map, do aggressive timing, scan what we've empirically found to 246 00:16:39,900 --> 00:16:43,320 be the 50 most likely ports to be open, do version detection, 247 00:16:43,740 --> 00:16:49,660 OS detection, do a minimum host group size of 128, which makes 248 00:16:49,660 --> 00:16:53,200 it faster because it scans more in parallel, set a host timeout 249 00:16:53,200 --> 00:16:55,000 of 10 minutes so that we don't waste time. So we don't waste 250 00:16:55,020 --> 00:16:58,480 too much time on any single host, send the output to files 251 00:16:59,010 --> 00:17:03,100 and I give it the list of IP addresses. And this sort of scan 252 00:17:03,100 --> 00:17:07,080 not many years ago could have taken a month to complete. And 253 00:17:07,080 --> 00:17:09,780 then if you wanted it any faster, you would have to use a 254 00:17:09,780 --> 00:17:13,520 bunch of really detailed performance options to tune it so 255 00:17:13,520 --> 00:17:16,700 that it goes faster but not too fast that you get inaccurate 256 00:17:16,700 --> 00:17:20,600 results. Fortunately, end map's gotten a lot smarter in the last 257 00:17:20,600 --> 00:17:24,220 few years, developed a lot of more clever algorithms and in 258 00:17:24,220 --> 00:17:25,000 this case, we were able to do a lot of things that we didn't 259 00:17:25,000 --> 00:17:27,300 want to do. We were able to scan the million IP addresses in about 260 00:17:27,300 --> 00:17:33,960 one day, 26 hours, and we have 74,293 hosts up. So let's take a 261 00:17:33,960 --> 00:17:49,920 quick look at the results here. And I'll zoom this. So this is 262 00:17:57,140 --> 00:18:03,940 about all on the screen. Good. And so basically this file is a 263 00:18:03,940 --> 00:18:08,060 big one and that's actually the problem with it. I mean, more 264 00:18:08,060 --> 00:18:11,400 than a third of a million lines. This file is intimidating on its 265 00:18:11,400 --> 00:18:15,180 face and for us to go through all these, it would basically be 266 00:18:15,180 --> 00:18:19,900 next DEF CON by the time we got it all done. So I want to show 267 00:18:19,900 --> 00:18:22,180 you a little trick I like to use in those sorts of cases. 268 00:18:26,920 --> 00:18:30,860 And so here's a scan or a simple UNIX command that I'm going to 269 00:18:30,860 --> 00:18:34,740 run which basically says take all of the open ports found 270 00:18:34,740 --> 00:18:38,360 during the scan and look at the different versions running and 271 00:18:38,360 --> 00:18:42,020 give me a reverse sorted list of how often every sort of service 272 00:18:42,020 --> 00:18:45,940 is running. So we take a look at the results. We see the highest 273 00:18:45,940 --> 00:18:51,140 is IIS 6. And by the way, I did give these results, I did these 274 00:18:51,140 --> 00:18:54,980 scans last year and gave these results to MSRC. So I hope you'll 275 00:18:55,000 --> 00:18:57,960 see them. Hopefully they fixed it by now. If not, it's going to 276 00:18:57,960 --> 00:19:04,800 be some long nights in Redmond coming up. We have IIS 6, so at 277 00:19:04,800 --> 00:19:08,200 least we can give them eating their own dog food here, running 278 00:19:08,200 --> 00:19:11,200 some of their own stuff. But rather than look at the top of 279 00:19:11,200 --> 00:19:14,940 the list, what I like to do is go down near to the bottom and 280 00:19:14,940 --> 00:19:17,140 look at the more obscure services that they're running 281 00:19:17,140 --> 00:19:19,780 because those are the ones you're more likely to be able to 282 00:19:19,780 --> 00:19:23,480 find a little bug in. I found little printers that I could get 283 00:19:23,480 --> 00:19:24,980 into the administration portal. I found a little printer that I 284 00:19:25,000 --> 00:19:27,300 could get on, check their toner levels, make sure everything is 285 00:19:27,300 --> 00:19:33,100 okay there. Various teleconferencing systems. 286 00:19:33,480 --> 00:19:35,980 There's just all sorts of bizarre stuff on here. But we're 287 00:19:35,980 --> 00:19:38,780 kind of getting distracted. As much fun as it would be to take a 288 00:19:38,780 --> 00:19:43,040 voyeuristic view into Microsoft's network right now, it's really 289 00:19:43,040 --> 00:19:47,480 NSE and SMB that we're most interested in. So let's take a 290 00:19:47,480 --> 00:19:54,980 look at those results. So this is a list of all the services 291 00:19:55,000 --> 00:19:57,080 that Microsoft's network blocks. The vast majority of Microsoft's 292 00:19:57,080 --> 00:20:01,580 network blocks, I'm happy to say, they basically filtered all 293 00:20:01,580 --> 00:20:07,420 of the MSRPC and SMB ports at their gateways. And so that's 294 00:20:07,420 --> 00:20:09,980 something that enterprises and businesses should really take in 295 00:20:09,980 --> 00:20:12,580 mind, although you should have already. I mean, if Microsoft 296 00:20:12,580 --> 00:20:15,920 feels that it should be blocked at the network and can't be 297 00:20:15,920 --> 00:20:19,020 really secured, it's probably a good idea for other businesses 298 00:20:19,020 --> 00:20:22,640 to do the same. But note that I said the vast majority of 299 00:20:22,640 --> 00:20:24,980 Microsoft's networks block these ports. Microsoft's network blocks 300 00:20:25,000 --> 00:20:26,960 are actually not. There were actually some that didn't and I 301 00:20:26,960 --> 00:20:31,480 found dozens of hosts that had port 445, the more modern of the 302 00:20:31,480 --> 00:20:35,540 ports available. So from that I designed a new scan. And 303 00:20:35,540 --> 00:20:39,940 basically I said N map and the key new option we're going to 304 00:20:39,940 --> 00:20:43,980 look at is hyphen hyphen script equals to say run N map 305 00:20:43,980 --> 00:20:47,160 scripting engine and instead of doing the default scripts I 306 00:20:47,160 --> 00:20:50,800 showed you, we're going to do SMB and new domains and new 307 00:20:50,800 --> 00:20:54,840 processes. Basically all of the scripts that I showed you before 308 00:20:55,000 --> 00:20:59,700 that are in the less intrusive categories, like the enumeration 309 00:20:59,700 --> 00:21:02,960 scripts, the information gathering scripts. Even I'm not 310 00:21:02,960 --> 00:21:05,820 crazy enough to do brute force authentication cracking and 311 00:21:05,820 --> 00:21:10,900 crack their passwords and then present it at DEF CON. But even 312 00:21:10,900 --> 00:21:15,000 from there, we ran the scan and got the results. And I would 313 00:21:15,000 --> 00:21:17,640 like to get some commitment from the audience here before we look 314 00:21:17,640 --> 00:21:21,020 at the results. Who here thinks Microsoft was totally secure? 315 00:21:24,280 --> 00:21:24,980 We've got one here. We've got one here. We've got one here. 316 00:21:24,980 --> 00:21:27,380 We've got one person. But I think there's probably several 317 00:21:27,380 --> 00:21:30,620 Microsoft people in the room who still aren't raising their 318 00:21:30,620 --> 00:21:35,380 hands. But let's take a look. Maybe Microsoft will surprise us 319 00:21:35,380 --> 00:21:45,740 here. So we're going to look at the results and we don't have 320 00:21:45,740 --> 00:21:48,520 time to go through all that many of them. So I'm going to go 321 00:21:48,520 --> 00:21:54,000 through one of my favorite machines. Can you guys, can you 322 00:21:54,000 --> 00:21:54,400 read this? 323 00:21:56,300 --> 00:22:01,940 Okay. So we have 976 closed ports. So that means they've 324 00:22:01,940 --> 00:22:05,000 defaulted the ports to be accessible. So you can tell if 325 00:22:05,000 --> 00:22:08,600 they're open or closed rather than filtered. And so instead of 326 00:22:08,600 --> 00:22:13,020 default deny and allow what you want, they've default allow and 327 00:22:13,020 --> 00:22:18,440 they've filtered a few ports like telnet and off that they 328 00:22:18,440 --> 00:22:21,840 specifically wanted to prohibit. So that's the less secure way to 329 00:22:21,840 --> 00:22:24,960 do it. So we'll deduct two points for that. So we're going 330 00:22:24,960 --> 00:22:28,440 to look at that. Next we look at mMap's open port list. And as you 331 00:22:28,440 --> 00:22:32,400 can see, there are quite a few of them. More than is really easy 332 00:22:32,400 --> 00:22:36,240 to secure. And so for having that many ports open, I think 333 00:22:36,240 --> 00:22:40,740 another two or three point deduction is warranted. But the 334 00:22:40,740 --> 00:22:43,740 part we're really interested in is the host script results. 335 00:22:44,500 --> 00:22:49,500 This is where our NSE action comes in. First we have their 336 00:22:49,500 --> 00:22:53,660 shares to enumerate. They have some sort of admin share, a C 337 00:22:53,660 --> 00:22:54,940 drive, a D drive, a C drive, a D drive, a C drive, a D drive, a 338 00:22:54,960 --> 00:22:57,680 D drive. Now these ones are restricted shares, so you need a 339 00:22:57,680 --> 00:23:00,520 password, which you could get thanks to maybe our SMB brute 340 00:23:00,520 --> 00:23:04,300 script. But one can argue that it's not best practice to share 341 00:23:04,300 --> 00:23:06,860 your hard drive over the Internet, even with a password. 342 00:23:09,380 --> 00:23:13,780 And so we're going to give them some points off for that, maybe 343 00:23:13,780 --> 00:23:20,620 four or five. Now we're going to continue on and we get to the 344 00:23:20,620 --> 00:23:24,940 SMB enum user script, which is one I talked about. Now we're 345 00:23:24,960 --> 00:23:26,260 going to give them a few more points. And here we get the list 346 00:23:26,260 --> 00:23:32,380 of user names on their domain controller. And we have some of 347 00:23:32,380 --> 00:23:33,920 them are actually pretty interesting. Here's the 348 00:23:33,920 --> 00:23:40,300 administrator user. This guy I like. I took off some of the 349 00:23:40,300 --> 00:23:43,080 last names to give them a modicum of privacy, but Richard, 350 00:23:43,240 --> 00:23:48,340 his user name is the boss man, which I thought was pretty cool. 351 00:23:49,960 --> 00:23:53,200 Let's see what else. There are a few other ones that are worth 352 00:23:53,200 --> 00:23:54,940 pointing out here. I'm going to give them a few more points. So 353 00:24:00,580 --> 00:24:04,740 let's see what else we have. We've got this MSB 50 net. That's 354 00:24:04,740 --> 00:24:08,580 the building 50 networking team. A nice thing about this script is 355 00:24:08,580 --> 00:24:11,980 that in the verbose mode, hyphen V, it shows you all this extra 356 00:24:11,980 --> 00:24:16,220 information rather than just the list of user names. There's a 357 00:24:16,220 --> 00:24:24,940 user not a guest exclamation point. And then we've got a 358 00:24:28,360 --> 00:24:28,920 little bit of a 359 00:24:28,920 --> 00:24:31,120 thing called the app. There's this support user, Microsoft 360 00:24:31,120 --> 00:24:34,120 corporation, Redwood, Washington, but my favorite is 361 00:24:34,120 --> 00:24:46,420 the T-shirt hoe. So that's the sort of information that you can 362 00:24:46,420 --> 00:24:52,040 get by doing large scale scans with this SMB scripts and with 363 00:24:52,040 --> 00:24:54,940 NSE in general. As you can see, they're a lot of fun. I'm going 364 00:24:54,940 --> 00:25:01,560 I'd like to mention again that these scripts were actually written by a fellow named Ron Bowes. 365 00:25:02,160 --> 00:25:07,160 And all I really did was take them and point them at Microsoft and pull the trigger. 366 00:25:07,680 --> 00:25:09,720 So Ron really deserves most of the credit. 367 00:25:09,820 --> 00:25:11,620 And I think if he was able to get in the room. 368 00:25:18,360 --> 00:25:19,420 Yeah, there he is. 369 00:25:21,940 --> 00:25:23,840 Yes, thank you, Ron. These scripts are awesome. 370 00:25:24,940 --> 00:25:32,220 We also have a fellow named Drazen Popovich who's been working on us this summer to improve our SMB stuff even further. 371 00:25:33,640 --> 00:25:39,320 So now we've gone on how to use SMB scripts, basically what they do. 372 00:25:39,760 --> 00:25:44,260 But the next question is, what about writing NSE scripts? 373 00:25:46,700 --> 00:25:54,160 If you think about it, using them is probably as much as your average casual MMAP user is likely to do. 374 00:25:54,940 --> 00:25:57,100 But really, any script kitty could do that. 375 00:25:57,480 --> 00:26:03,360 What do you do if you want a networking task which we don't already have a canned script for? 376 00:26:03,660 --> 00:26:08,920 What if we have a script, but it doesn't behave in exactly the way that you believe it should? 377 00:26:09,420 --> 00:26:14,960 This next section is going to show you what we provide to let you go to the next step. 378 00:26:15,160 --> 00:26:21,580 And even if you don't consider yourself a great programmer, how you can build these scripts to run your own tasks. 379 00:26:27,580 --> 00:26:33,160 And we're going to start, basically, with these scripts, the language that they use is called Lua. 380 00:26:33,480 --> 00:26:35,960 It's a great little language. It's easy to learn. 381 00:26:36,160 --> 00:26:42,340 If you know other languages like Python or Pearl or compiled languages like C, you can probably figure it out. 382 00:26:42,680 --> 00:26:46,000 It's tiny to embed because we didn't want to bloat your NMAP. 383 00:26:46,300 --> 00:26:52,860 The Lua book says, the complete distribution, source code, manual, plus binaries for some platforms, 384 00:26:53,160 --> 00:26:54,920 fits comfortably on a floppy disk. 385 00:26:54,920 --> 00:27:04,160 So for those of you young people in the audience, a floppy disk is a small storage technology. 386 00:27:06,640 --> 00:27:14,580 Now, Lua is also widely used, known, and debugged, so we weren't taking something brand new that they might stop developing the next day. 387 00:27:14,840 --> 00:27:16,540 It's been in use since 1993. 388 00:27:17,260 --> 00:27:22,620 It's best known use is in the game industry, with games like World of Warcraft or Crysis. 389 00:27:22,960 --> 00:27:24,900 But what we've been seeing more and more, 390 00:27:24,900 --> 00:27:27,280 is that security tools have been picking it up. 391 00:27:27,600 --> 00:27:31,820 We're talking in this talk about how NMAP uses it for NSE. 392 00:27:32,720 --> 00:27:35,400 Wireshark can use it now for protocol dissectors. 393 00:27:35,620 --> 00:27:41,360 And the Snort 3.0 beta has its own Lua interpreter to extend Snort as well. 394 00:27:41,980 --> 00:27:47,940 Basically, the only holdout now on the Lua bandwagon is probably Metasploit, which is in Ruby. 395 00:27:48,280 --> 00:27:54,120 But whenever I see H.D. Moore at these conferences, I talk his ear off about why he should rewrite it yet again. 396 00:27:54,900 --> 00:27:55,640 In Lua this time. 397 00:27:56,120 --> 00:27:59,300 I think that's why he's been avoiding me the last couple of days. 398 00:28:01,080 --> 00:28:02,360 It's also extensible. 399 00:28:02,700 --> 00:28:05,820 We can hook it up to NMAP's fast parallel scripting engine. 400 00:28:06,180 --> 00:28:07,300 It's safe and secure. 401 00:28:08,160 --> 00:28:10,360 No buffer overflows, format strings. 402 00:28:10,960 --> 00:28:14,620 I mean, Wireshark showed us the problem with doing their dissectors in C. 403 00:28:14,920 --> 00:28:17,560 They got a lot of contributions, but not all of them were secure. 404 00:28:17,900 --> 00:28:23,060 And it seemed like every week you got a new vulnerability in a dissector that someone contributed. 405 00:28:23,780 --> 00:28:24,520 It's portable. 406 00:28:24,520 --> 00:28:26,240 Works on all the systems NMAP does. 407 00:28:26,520 --> 00:28:28,920 And it's interpreted, so you don't have to keep recompiling. 408 00:28:29,620 --> 00:28:31,640 NMAP adds a few capabilities to that. 409 00:28:31,920 --> 00:28:33,820 We have protocol and helper libraries. 410 00:28:34,160 --> 00:28:42,840 They help you make, say, an SMB query or an HTTP request without getting bogged down in the details of the protocol for making those requests. 411 00:28:43,480 --> 00:28:50,860 We have protocol bruteforcers, like we looked at SMB brute, so that it can find the passwords for you in those times when you really need them. 412 00:28:51,100 --> 00:28:52,440 We have SSL. 413 00:28:52,520 --> 00:28:54,240 And we have the dependency system. 414 00:28:54,520 --> 00:29:05,660 We talked about how SMB enum users can then take that user name list and SMB brute knows to have users run fast, take those results, and crack them. 415 00:29:06,800 --> 00:29:10,700 So that's a really quick overview of what we've added. 416 00:29:10,980 --> 00:29:12,880 Let's look at an actual example script. 417 00:29:16,260 --> 00:29:21,680 So I think the script that I'm going to show you this time is called rpcinfo.nsc. 418 00:29:21,680 --> 00:29:24,480 And it basically does exactly what you would expect. 419 00:29:27,160 --> 00:29:34,980 NMAP users and pen testers in general who have been around a long time, you kind of get used to seeing port 111 RPC bind open. 420 00:29:35,220 --> 00:29:43,260 So you just run rpcinfo hyphen e host name to see what's there and what RPC services are listening and what ports. 421 00:29:43,540 --> 00:29:48,860 Well, it would be nice if NMAP could do that for you whenever it detects the port open. 422 00:29:49,060 --> 00:29:51,660 And it could put the results right there in your NMAP. 423 00:29:51,680 --> 00:29:53,900 So you don't have to keep it all separate. 424 00:29:54,220 --> 00:30:08,340 And the nice thing is thanks to these protocol helper libraries and the like, writing such a script took us, it is 46 lines long. 425 00:30:09,040 --> 00:30:11,440 So let's take a quick look at what it does. 426 00:30:12,740 --> 00:30:13,780 We have a description. 427 00:30:14,280 --> 00:30:16,140 We have a sample output. 428 00:30:16,400 --> 00:30:18,300 These are for the NSE doc page I showed you. 429 00:30:18,840 --> 00:30:21,660 We have a port rule. 430 00:30:21,660 --> 00:30:28,500 It tells you when it should run because it would be terribly inefficient if rpcinfo.nsc was running against every port. 431 00:30:28,780 --> 00:30:36,840 This says only run if it's port 111 or if version detection detects it as RPC bind and for either TCP or UDP protocols. 432 00:30:37,260 --> 00:30:39,420 If that matches, it runs this action. 433 00:30:41,040 --> 00:30:47,300 The key line in this whole script is this one that says rpc.helper.rpcinfo. 434 00:30:48,360 --> 00:30:49,780 It grabs that information. 435 00:30:49,780 --> 00:30:52,220 If it failed, it gives you an error message. 436 00:30:52,620 --> 00:30:54,440 It sorts it into a pretty table. 437 00:30:54,660 --> 00:30:55,620 Sorts the results. 438 00:30:55,960 --> 00:30:57,940 And prints it out to NMAP's output. 439 00:30:58,380 --> 00:30:58,920 I'm sorry. 440 00:30:59,040 --> 00:31:00,160 That was a real quick overview. 441 00:31:00,580 --> 00:31:04,360 But as you can see, you can do a script that actually does really useful things. 442 00:31:04,720 --> 00:31:06,180 Half of it is just documentation. 443 00:31:06,740 --> 00:31:09,140 And the other half is pretty simple. 444 00:31:13,200 --> 00:31:18,100 So I could go on with all 131 of these scripts and show you them one by one. 445 00:31:18,300 --> 00:31:19,760 But like I said before, I'm not going to go through all of them. 446 00:31:19,780 --> 00:31:25,400 It seemed like it would be much more fun to have a live demonstration to show just how easy it is. 447 00:31:25,620 --> 00:31:33,620 And so David is going to write one right in front of us that actually does useful things and execute it and hope that it works. 448 00:31:34,000 --> 00:31:34,820 Thank you, David. 449 00:31:35,220 --> 00:31:35,760 Thank you. 450 00:31:38,660 --> 00:31:39,300 All right. 451 00:31:39,320 --> 00:31:45,700 So to demonstrate how easy it is to write NSE scripts, I set up a little example here. 452 00:31:45,820 --> 00:31:46,780 And we're going to work our way through it. 453 00:31:46,780 --> 00:31:48,220 Anyone in this audience a programmer? 454 00:31:49,480 --> 00:31:52,380 If you're a programmer, you can write NSE scripts. 455 00:31:52,940 --> 00:31:57,540 So before I left home, I set up a webcam pointing out my window at downtown Denver. 456 00:31:57,920 --> 00:32:01,020 And I want to find it and see what's on the webcam picture. 457 00:32:01,680 --> 00:32:03,600 The problem is I'm on a dynamic IP address. 458 00:32:03,740 --> 00:32:05,020 So I don't know exactly where it is. 459 00:32:05,180 --> 00:32:06,680 But we're going to write a script to find it. 460 00:32:06,820 --> 00:32:10,740 Before I left, I found out some attributes of this webcam that can help us fingerprint it. 461 00:32:10,800 --> 00:32:12,440 It uses THTPE to serve. 462 00:32:12,660 --> 00:32:15,280 And it serves up a file called cam.jpeg. 463 00:32:15,380 --> 00:32:16,760 So we're going to write a script that looks like this. 464 00:32:16,780 --> 00:32:18,800 And it looks for those two things and finds my webcam. 465 00:32:22,840 --> 00:32:23,980 So we're going to start. 466 00:32:24,200 --> 00:32:27,900 Let's call this httpwebcam.nse. 467 00:32:28,740 --> 00:32:29,260 Sorry. 468 00:32:31,500 --> 00:32:32,020 Oh. 469 00:32:34,340 --> 00:32:35,700 Let's, like, redo this. 470 00:32:37,880 --> 00:32:38,540 All right. 471 00:32:38,580 --> 00:32:40,040 So the customary extension is NSE. 472 00:32:42,300 --> 00:32:43,740 Every script needs a description. 473 00:32:46,240 --> 00:32:46,760 All right. 474 00:32:47,100 --> 00:32:47,500 Ooh. 475 00:32:48,780 --> 00:32:49,480 Syntax highlighting. 476 00:32:50,040 --> 00:32:50,440 Sexy. 477 00:32:52,880 --> 00:32:55,240 So this script is going to be in the safe category. 478 00:32:55,600 --> 00:32:56,980 Because we're not doing anything weird. 479 00:32:57,160 --> 00:32:58,700 Also I would put this in discovery. 480 00:33:03,300 --> 00:33:04,640 Every script needs a rule. 481 00:33:04,860 --> 00:33:06,480 In this case we're going to use something called a port rule. 482 00:33:06,700 --> 00:33:08,700 Which decides when the script is going to run. 483 00:33:09,020 --> 00:33:11,980 And in this case we just want it to run when the port number is 80. 484 00:33:12,140 --> 00:33:12,980 So this is real simple. 485 00:33:14,300 --> 00:33:16,060 Return port number equals equals 80. 486 00:33:16,880 --> 00:33:20,200 And then finally the action is where the script really does its work. 487 00:33:20,300 --> 00:33:21,180 Again, it takes two parameters. 488 00:33:21,380 --> 00:33:22,240 The host and the port. 489 00:33:22,840 --> 00:33:24,960 Now we're going to be using http functions. 490 00:33:25,220 --> 00:33:26,600 So we need to require that library. 491 00:33:27,240 --> 00:33:30,260 This is just like an import in any other language. 492 00:33:31,240 --> 00:33:33,600 Let's define a local variable here for our response. 493 00:33:37,020 --> 00:33:39,680 And we want to retrieve cam.jpeg. 494 00:33:40,720 --> 00:33:43,200 Now let's just test what we got from the response here. 495 00:33:43,320 --> 00:33:45,480 If response.status. 496 00:33:46,320 --> 00:33:46,760 We're going to do that. 497 00:33:46,760 --> 00:33:47,760 We're just going to make sure that it worked. 498 00:33:48,400 --> 00:33:52,000 And response.status is not 404. 499 00:33:53,380 --> 00:33:55,140 And remember what else we're looking for. 500 00:33:55,420 --> 00:33:58,560 Response.header. 501 00:33:58,640 --> 00:34:00,320 We want to check that the server header exists. 502 00:34:05,520 --> 00:34:06,340 Just a minute. 503 00:34:12,900 --> 00:34:15,920 And string.match is a standard Lua function. 504 00:34:21,740 --> 00:34:24,400 And we're going to match it against the pattern THTPD. 505 00:34:27,040 --> 00:34:29,460 Then it's easy to return results from an NSE script. 506 00:34:29,620 --> 00:34:30,460 You just return a string. 507 00:34:34,340 --> 00:34:36,680 In case we don't have any results, we just return 508 00:34:36,680 --> 00:34:37,000 nothing. 509 00:34:37,180 --> 00:34:38,560 And then the script isn't going to report anything. 510 00:34:41,760 --> 00:34:42,760 So let's run it. 511 00:34:43,040 --> 00:34:45,080 I'm going to add a couple of flags on here to make this a 512 00:34:45,080 --> 00:34:45,600 little faster. 513 00:34:45,700 --> 00:34:46,740 So pay attention if you have trouble with that. 514 00:34:47,540 --> 00:34:49,600 Turn off reverse name resolution. 515 00:34:50,420 --> 00:34:51,580 Turn off ping scanning. 516 00:34:51,820 --> 00:34:52,740 We only want port 80. 517 00:34:52,980 --> 00:34:54,840 Only tell me about host with an open port. 518 00:34:55,200 --> 00:34:57,100 We want to run HTTP webcam. 519 00:34:58,300 --> 00:35:00,440 The address range I'm going to scan. 520 00:35:02,400 --> 00:35:07,300 The address range I'm going to scan is this one. 521 00:35:07,600 --> 00:35:08,660 Do you have to zoom it? 522 00:35:12,920 --> 00:35:13,480 Oh. 523 00:35:13,600 --> 00:35:13,900 Maybe. 524 00:35:14,220 --> 00:35:14,780 Oh. 525 00:35:14,860 --> 00:35:16,460 I got you. 526 00:35:16,540 --> 00:35:16,740 Oh. 527 00:35:16,760 --> 00:35:16,820 Okay. 528 00:35:16,980 --> 00:35:17,420 Thanks. 529 00:35:18,120 --> 00:35:20,600 And we're going to scan these addresses. 530 00:35:21,280 --> 00:35:23,780 Let's write the results to a file in case it scrolls off the 531 00:35:23,780 --> 00:35:24,040 screen. 532 00:35:24,360 --> 00:35:26,520 And when you're testing your scripts for the first time, 533 00:35:26,560 --> 00:35:29,400 you always want to add the debug flag in case you're a 534 00:35:29,400 --> 00:35:31,040 programmer who makes mistakes. 535 00:35:31,360 --> 00:35:33,680 It will tell you where it will give you a back trace to your 536 00:35:33,680 --> 00:35:34,340 syntax errors. 537 00:35:35,340 --> 00:35:36,020 Yeah, right. 538 00:35:37,840 --> 00:35:38,540 Oh, no. 539 00:35:43,320 --> 00:35:44,460 So what is that? 540 00:35:46,760 --> 00:35:47,060 Is it hubris? 541 00:35:48,360 --> 00:35:49,140 All right. 542 00:35:57,140 --> 00:35:57,880 There we go. 543 00:36:00,680 --> 00:36:02,320 Oh, that's the problem. 544 00:36:02,980 --> 00:36:04,680 We need to update the voice recognition. 545 00:36:06,820 --> 00:36:07,340 Okay. 546 00:36:07,380 --> 00:36:07,640 So. 547 00:36:07,960 --> 00:36:08,960 Nmap is fast. 548 00:36:09,320 --> 00:36:10,200 Let's look at the log. 549 00:36:13,360 --> 00:36:14,120 There we go. 550 00:36:14,280 --> 00:36:16,740 This is the address of the webcam, 66.7. 551 00:36:16,760 --> 00:36:17,840 171.5. 552 00:36:19,160 --> 00:36:21,280 And that's how easy it is to write an NSE script. 553 00:36:21,760 --> 00:36:23,000 Let's take a look at it. 554 00:36:34,880 --> 00:36:35,320 Huh. 555 00:36:41,600 --> 00:36:42,040 Okay. 556 00:36:42,220 --> 00:36:43,900 So let's not let this scare us. 557 00:36:44,100 --> 00:36:46,120 This is just an opportunity for. 558 00:36:46,980 --> 00:36:51,360 Nmap developers to do what we do best, which is scan. 559 00:36:53,640 --> 00:36:55,780 I want to show you a script that I've been working on. 560 00:37:00,540 --> 00:37:01,140 All right. 561 00:37:01,180 --> 00:37:01,680 You follow me? 562 00:37:03,080 --> 00:37:03,480 . 563 00:37:08,460 --> 00:37:09,020 All right. 564 00:37:09,040 --> 00:37:10,240 So let's go through this one real quick. 565 00:37:10,420 --> 00:37:12,260 The structure is going to be familiar to you. 566 00:37:12,360 --> 00:37:12,760 Description. 567 00:37:12,960 --> 00:37:14,020 Guesses HTTP passwords. 568 00:37:14,660 --> 00:37:15,060 Categories. 569 00:37:15,860 --> 00:37:16,660 I can't really. 570 00:37:16,760 --> 00:37:17,880 With a good conscience. 571 00:37:18,000 --> 00:37:18,980 Put this in safe anymore. 572 00:37:21,080 --> 00:37:22,180 Put it in off category. 573 00:37:22,520 --> 00:37:23,900 We need the HTTP library again. 574 00:37:24,120 --> 00:37:25,160 This is another password. 575 00:37:25,320 --> 00:37:27,720 This is our user name password database library. 576 00:37:27,960 --> 00:37:29,220 Which all our brute scripts use. 577 00:37:29,980 --> 00:37:32,380 And I'll talk to you a little bit more about that in a second. 578 00:37:32,560 --> 00:37:33,860 Port rule is exactly the same. 579 00:37:34,700 --> 00:37:36,860 And the action is pretty simple. 580 00:37:37,000 --> 00:37:38,380 Just a few technical details here. 581 00:37:38,500 --> 00:37:39,580 We have a user name iterator. 582 00:37:39,680 --> 00:37:40,700 A password iterator. 583 00:37:40,820 --> 00:37:42,080 We have a nested loop here. 584 00:37:42,460 --> 00:37:43,700 We're getting cam.jpeg. 585 00:37:47,100 --> 00:37:50,820 And if we get a result that is not 401 authentication required. 586 00:37:51,080 --> 00:37:53,580 We're going to return user name colon password. 587 00:37:55,240 --> 00:37:56,780 So let's run that scan. 588 00:37:57,120 --> 00:37:58,940 It's going to be very similar. 589 00:37:59,260 --> 00:38:00,740 Just take off a few of this stuff. 590 00:38:00,860 --> 00:38:02,040 Some of this stuff we don't need. 591 00:38:07,220 --> 00:38:07,660 And. 592 00:38:08,500 --> 00:38:08,940 Oh. 593 00:38:09,080 --> 00:38:10,240 Change the name of the script. 594 00:38:11,500 --> 00:38:12,200 Thank you. 595 00:38:15,160 --> 00:38:16,140 And let her rip. 596 00:38:16,340 --> 00:38:16,740 So we're going to run this. 597 00:38:18,520 --> 00:38:20,820 The thing about password cracking is it tends to take a 598 00:38:20,820 --> 00:38:21,260 long time. 599 00:38:22,720 --> 00:38:24,860 Let me tell you a little bit about our user name password 600 00:38:24,860 --> 00:38:25,780 database library. 601 00:38:26,420 --> 00:38:29,200 Whenever we're shipping databases with nmap we like 602 00:38:29,200 --> 00:38:31,220 to base them on real results. 603 00:38:31,480 --> 00:38:33,400 You know it's easy to go download somebody's random 604 00:38:33,400 --> 00:38:34,140 password database. 605 00:38:34,380 --> 00:38:35,560 But you don't know how good it is. 606 00:38:35,920 --> 00:38:37,460 You don't really know where it came from. 607 00:38:37,600 --> 00:38:39,440 You don't know if it's going to help you in your situation. 608 00:38:39,780 --> 00:38:41,820 So we try to base this on. 609 00:38:42,280 --> 00:38:43,480 Hey that was too fast. 610 00:38:43,480 --> 00:38:45,560 I'm not done talking about the password database. 611 00:38:45,900 --> 00:38:48,520 I want to say our password database is based on some real 612 00:38:48,520 --> 00:38:49,320 measured results. 613 00:38:50,060 --> 00:38:52,000 From some like public information. 614 00:38:52,320 --> 00:38:53,320 Some data breaches. 615 00:38:53,760 --> 00:38:55,440 Password disclosures and things like that. 616 00:38:55,660 --> 00:38:58,000 We've curated them and built them into a pretty decent list 617 00:38:58,000 --> 00:38:59,780 that you'll get if you download nmap. 618 00:39:00,000 --> 00:39:01,060 So that's what we've used here. 619 00:39:01,260 --> 00:39:05,080 So now in 25.90 seconds it has cracked the password. 620 00:39:06,800 --> 00:39:07,720 User name web. 621 00:39:07,920 --> 00:39:08,540 Password monkey. 622 00:39:08,720 --> 00:39:10,520 That's in honor of the goon who introduced us. 623 00:39:12,280 --> 00:39:13,260 Let's give it a try. 624 00:39:21,740 --> 00:39:22,140 Okay. 625 00:39:25,400 --> 00:39:26,540 And there we go. 626 00:39:38,220 --> 00:39:39,020 All right. 627 00:39:39,080 --> 00:39:39,800 So I had to. 628 00:39:40,060 --> 00:39:43,380 I made the script very small so it could be understood in a 629 00:39:43,480 --> 00:39:43,820 short time. 630 00:39:44,080 --> 00:39:46,660 Before I add this script to nmap there are a few changes I'm 631 00:39:46,660 --> 00:39:47,020 going to make. 632 00:39:47,220 --> 00:39:48,780 The port rule has to be more generic. 633 00:39:49,020 --> 00:39:50,640 It's lame to just match port 80. 634 00:39:50,920 --> 00:39:54,000 I want to match all the common HTTP ports and also any ports 635 00:39:54,000 --> 00:39:55,860 that version detection is found to be HTTP. 636 00:39:56,300 --> 00:39:58,900 We have a library called short port that makes that very easy. 637 00:39:59,440 --> 00:40:01,680 I would add script arguments so we don't have to hard code 638 00:40:01,680 --> 00:40:02,540 cam.jpg. 639 00:40:02,800 --> 00:40:04,460 You could just specify that on the command line. 640 00:40:04,760 --> 00:40:07,780 Add documentation for usage and output so it can go on our 641 00:40:07,780 --> 00:40:09,540 online documentation portal. 642 00:40:09,800 --> 00:40:11,160 And finally this is very important. 643 00:40:11,320 --> 00:40:13,220 I want it to be able to cache credentials in our 644 00:40:13,480 --> 00:40:16,180 registry so that other scripts that run later through our 645 00:40:16,180 --> 00:40:18,200 dependency system have access to these. 646 00:40:18,600 --> 00:40:21,440 Now let me turn it back over to Fyodor with some final notes. 647 00:40:21,740 --> 00:40:22,120 All right. 648 00:40:22,200 --> 00:40:24,740 We're going to just run through these last slides really 649 00:40:24,740 --> 00:40:25,020 quickly. 650 00:40:25,440 --> 00:40:28,500 First of all, we have a lot of stuff coming in NSE. 651 00:40:28,700 --> 00:40:29,760 We have scripts in the queue. 652 00:40:30,080 --> 00:40:33,540 We have an idea for scripts that can run before and actually 653 00:40:33,540 --> 00:40:34,700 accumulate targets. 654 00:40:34,800 --> 00:40:38,480 So you could do like a zone transfer or a broadcast ping or 655 00:40:38,480 --> 00:40:41,300 the like and hand those targets straight to nmap. 656 00:40:41,960 --> 00:40:43,460 We have ZenMap. 657 00:40:43,480 --> 00:40:44,400 NSE integration. 658 00:40:45,320 --> 00:40:47,280 That was going to be on the coming soon slide. 659 00:40:47,620 --> 00:40:51,040 But instead it's here because we actually put it in the 660 00:40:51,040 --> 00:40:53,240 repository just about three days ago. 661 00:40:53,660 --> 00:41:00,200 David was working with a fellow named Curubicon to create this 662 00:41:00,200 --> 00:41:03,740 extra panel in ZenMap which shows you all the scripts we 663 00:41:03,740 --> 00:41:06,640 have available, what categories they're in, the descriptions, 664 00:41:07,080 --> 00:41:09,520 what arguments they can take and lets you set those. 665 00:41:09,780 --> 00:41:12,400 So it's a nice feature if you don't have all the scripts 666 00:41:12,400 --> 00:41:12,860 memorized. 667 00:41:13,280 --> 00:41:13,460 All right. 668 00:41:13,480 --> 00:41:16,080 I wanted to mention credit where credit is due. 669 00:41:16,400 --> 00:41:20,040 I wrote nmap 13 years ago and sometimes get way more of the 670 00:41:20,040 --> 00:41:20,980 credit than I deserve. 671 00:41:21,360 --> 00:41:24,620 It's really an open source project in the true sense with 672 00:41:24,620 --> 00:41:26,500 tons of contributors all over the world. 673 00:41:26,700 --> 00:41:29,720 And this is just a list of the people who have written scripts 674 00:41:29,720 --> 00:41:34,360 for NSE which is just a subset of the contributor set as a 675 00:41:34,360 --> 00:41:34,520 whole. 676 00:41:35,180 --> 00:41:36,040 Final notes. 677 00:41:36,220 --> 00:41:38,980 The slides are up now at insecure.org slash 678 00:41:38,980 --> 00:41:39,600 presentations. 679 00:41:40,120 --> 00:41:43,120 You've got to scroll down a little bit to get to the 2010 680 00:41:43,120 --> 00:41:43,460 version. 681 00:41:44,080 --> 00:41:48,220 Here's the URLs for downloading Nmap, the NSE doc portal, the 682 00:41:48,220 --> 00:41:51,800 system docs and for Q&A we're going to take that right across 683 00:41:51,800 --> 00:41:53,660 the hall in 118. 684 00:41:53,680 --> 00:41:54,500 Thank you very much.