1 00:00:00,900 --> 00:00:04,220 This is Constricting the Web, Offensive Python for Web 2 00:00:04,220 --> 00:00:08,160 Hackers. So if you didn't know that, you're in the wrong talk. 3 00:00:08,560 --> 00:00:11,560 I am Nathan Hamill, I'm a principal consultant for fish 4 00:00:11,560 --> 00:00:14,660 net security on the application security team. And I'm also an 5 00:00:14,660 --> 00:00:16,460 associate professor at the University of Advancing 6 00:00:16,460 --> 00:00:19,780 Technology. And I'm Marcin Bielgoszewski. I'm not going to 7 00:00:19,780 --> 00:00:23,800 ask you guys to repeat that. But I'm a security engineer, Gotham 8 00:00:23,800 --> 00:00:31,560 Digital Science. I do web shit. Kind of the reason we decided to 9 00:00:31,560 --> 00:00:35,480 do this talk is because there's a lot of people who are starting 10 00:00:35,480 --> 00:00:39,980 to get more into testing web applications. And web 11 00:00:39,980 --> 00:00:44,780 applications are becoming more complicated. So when first 12 00:00:44,780 --> 00:00:48,820 things people usually reach for are their tool kits. So maybe 13 00:00:48,820 --> 00:00:53,020 it's app scan or web inspect. But they don't really give you 14 00:00:53,020 --> 00:00:53,580 the whole picture. 15 00:00:55,300 --> 00:00:58,120 A lot of times vendors are playing catch up. So with new 16 00:00:58,120 --> 00:01:01,480 technologies like flash and silver light, it might not be 17 00:01:01,480 --> 00:01:05,800 supported for quite a bit of time between the time people are 18 00:01:05,800 --> 00:01:10,180 using it and the time the technology catches up with to be 19 00:01:10,180 --> 00:01:14,180 able to test it. So it's not like you can just say we have 20 00:01:14,180 --> 00:01:17,240 this new technology, we'll just wait until everybody catches up 21 00:01:17,240 --> 00:01:19,540 and then we'll check to see whether it's secure. That's not 22 00:01:19,540 --> 00:01:22,900 really setting you up for success there. 23 00:01:23,820 --> 00:01:27,740 There's also difficult cases where your standard testing tools 24 00:01:27,740 --> 00:01:32,860 won't really help you. APIs for one. So if you're going through 25 00:01:32,860 --> 00:01:37,720 testing your application, you run into an API, you might not 26 00:01:38,320 --> 00:01:41,320 even see it. The scanner might not even see it unless it makes 27 00:01:41,320 --> 00:01:45,680 some sort of call. There's also sequenced operations as well. So 28 00:01:45,680 --> 00:01:48,960 if there's a sequence of steps that need to happen prior to a 29 00:01:48,960 --> 00:01:53,100 test case, sometimes standard tools will fall flat on their face. 30 00:01:53,800 --> 00:01:57,580 With randomized data, you know, if a page lays out and every 31 00:01:57,580 --> 00:02:00,880 single time the page lays out, the data is behind the menu 32 00:02:00,880 --> 00:02:04,060 options is randomized, there's pretty much no testing tool out 33 00:02:04,060 --> 00:02:06,560 there, standard testing tool that will help you. And that's 34 00:02:06,560 --> 00:02:10,500 why you need to write your own tools. So this is an 35 00:02:10,500 --> 00:02:13,660 intervention. You know, I see a bunch of people who love you 36 00:02:13,660 --> 00:02:18,400 like crazy and they want you to join the fight and not just use 37 00:02:18,400 --> 00:02:19,720 AppScan and WebInspect. 38 00:02:22,580 --> 00:02:23,780 Now, this wasn't a test case. It was a test case. It was a test 39 00:02:23,800 --> 00:02:26,680 case. And in our previous slide, so what we have already 40 00:02:26,680 --> 00:02:31,680 posted is the slides for this talk, as well as the code 41 00:02:31,680 --> 00:02:35,700 snippets that we're using. So we're releasing a few tools and 42 00:02:35,700 --> 00:02:38,580 we're releasing some example code. That's already available 43 00:02:38,580 --> 00:02:42,320 for download. So if you get a chance and you want to play 44 00:02:42,320 --> 00:02:46,180 around with that, that's all well and good. Here's kind of an 45 00:02:46,180 --> 00:02:50,500 example snapshot of some modern infrastructure. If you look at 46 00:02:50,500 --> 00:02:53,780 this infrastructure and how it's laid out, you know, the 47 00:02:53,800 --> 00:02:57,100 front-end web page, which, you know, vulnerability, web 48 00:02:57,100 --> 00:02:59,940 vulnerability scanners are really good at testing, isn't 49 00:02:59,940 --> 00:03:02,300 really the bigger picture. You know, it's only a small 50 00:03:02,300 --> 00:03:06,320 percentage of your entire attack surface. So that being the case, 51 00:03:07,000 --> 00:03:09,860 you know, if you just ran these standard tools and generated 52 00:03:09,860 --> 00:03:14,140 reports, you wouldn't even see any of these other things, these 53 00:03:14,140 --> 00:03:17,820 client APIs, server-to-server APIs, storage mechanisms on the 54 00:03:17,820 --> 00:03:20,400 back. And that's kind of just leading more up to the point 55 00:03:20,400 --> 00:03:23,700 that, you know, you're going to have to write your own tools 56 00:03:23,800 --> 00:03:29,740 if you want to be successful. So why do we use Python? I think 57 00:03:29,740 --> 00:03:34,020 we all know because it rocks, right? You know, you could 58 00:03:34,020 --> 00:03:37,780 quickly write tools, you know, on a whim. That's one of the 59 00:03:37,780 --> 00:03:39,860 things, like, when you're testing stuff, like, the 60 00:03:39,860 --> 00:03:44,060 lifetime, life span or whatever of your tool actually just lasts 61 00:03:44,540 --> 00:03:48,220 as long as the app stands up, you know? After that, it's, 62 00:03:48,220 --> 00:03:52,740 like, just a throwaway. Easy to understand. And I kind of like 63 00:03:52,740 --> 00:03:53,780 the white space. You know, it's kind of like, you know, it's 64 00:03:53,800 --> 00:03:54,280 a web site. But, you know, it's just one of the things that 65 00:03:54,280 --> 00:03:56,120 you can do with Python. And I guess most of you do, too. That's 66 00:03:56,120 --> 00:04:00,940 why you still use it. Otherwise, you'd be back to Perl. So. 67 00:04:01,760 --> 00:04:05,200 There's plenty of support out there for Python, as well. One 68 00:04:05,200 --> 00:04:08,740 thing I will advise against not doing, do not go into the Python 69 00:04:08,740 --> 00:04:12,140 room on Freenode and start lulling. They do not like that. 70 00:04:12,340 --> 00:04:18,340 I am permabanned from the Python IRC channel on Freenode. But I 71 00:04:18,340 --> 00:04:22,740 thought it was funny. So you can Google for plenty of examples. 72 00:04:23,800 --> 00:04:29,320 a search engine called knowledge that's a Python source code search engine which comes in helpful 73 00:04:29,880 --> 00:04:36,560 especially for poorly documented modules. You know, you might find that useful. I think I saw 74 00:04:36,560 --> 00:04:42,300 that from a tweet from Dave. He's like hey, knowledge and I'm like cool. I guess poorly 75 00:04:42,300 --> 00:04:46,960 documented Python code you don't even want to use any, you know, if you can't read the source 76 00:04:46,960 --> 00:04:52,000 might as well just skip it. So there's plenty of help available. So a few of the big tools out 77 00:04:52,000 --> 00:04:58,420 there, I mean like anyone coming from like network side knows Scapey. I love Scapey. Peach fuzzing 78 00:04:58,420 --> 00:05:04,120 shit, like that's awesome. From like the reverse engineering side of the house, like you got 79 00:05:04,120 --> 00:05:12,120 Python, you got PyDBG. My buddy Rich Smith just released a toolkit yesterday called Pyretic, 80 00:05:12,200 --> 00:05:21,540 basically deobfuscating or reversing out obfuscated Python bytecode which is pretty badass. W3AF, 81 00:05:21,700 --> 00:05:21,980 I don't know if you've heard of it. I don't know if you've heard of it. I don't know if you've 82 00:05:21,980 --> 00:05:25,920 heard of it. It's a little bit of a web scanner you guys are probably all familiar with written in 83 00:05:25,920 --> 00:05:31,440 Python as well. So a lot of stuff out there already and it's kind of like a lot of people's 84 00:05:31,440 --> 00:05:35,000 insecurity like to use Python. So those are the big ones. 85 00:05:35,340 --> 00:05:42,600 So it kind of gives you an opportunity to not only, to not only, you know, use tools that are 86 00:05:42,600 --> 00:05:46,100 already written in Python but also for extending them as well and contributing back to those 87 00:05:46,100 --> 00:05:51,960 projects. So where does Python fit? Python fits in the space between your front end and your 88 00:05:51,960 --> 00:05:58,040 fully automated testing tools and completely manual testing. So you can have just as much 89 00:05:58,040 --> 00:06:02,720 context over what you're testing as manual testing because you're basically writing the 90 00:06:02,720 --> 00:06:05,920 clients. You're basically using the tools. You know exactly what data is going to the 91 00:06:05,920 --> 00:06:10,400 application and what's coming back. So that's the place it fits. Automating your manual 92 00:06:10,400 --> 00:06:16,780 testing cases. There's a couple of different versions of Python. We only highlighted three 93 00:06:16,780 --> 00:06:21,620 here that may be of interest to you. CPython is the standard Python implementation that 94 00:06:21,620 --> 00:06:27,820 you probably have running on your system. Jython is Python in Java. And Iron Python is 95 00:06:27,820 --> 00:06:34,220 Python in .NET. So we'll go into that a little bit later. Other than just having an excuse to 96 00:06:34,220 --> 00:06:41,400 put Ron Jeremy in a slide. To piss off Ping. Yeah. You have to know, you have to be 97 00:06:41,400 --> 00:06:45,680 intimately familiar with your applications before you start testing them. And I realize that 98 00:06:45,680 --> 00:06:51,540 sounds kind of strange. But a lot of commercial testing tools are meant to abstract you 99 00:06:51,540 --> 00:06:56,200 from being familiar with the application. You can get down and dirty with them. But that's not 100 00:06:56,200 --> 00:07:00,860 typically how they're used in the infrastructure. So that's kind of what this slide was about. 101 00:07:03,000 --> 00:07:07,340 You guys are probably all familiar with standard library. You keep the docs under your 102 00:07:07,340 --> 00:07:11,660 pillow. Like, you know, whatever. Some of the third party modules that you might not be aware 103 00:07:11,660 --> 00:07:19,220 of, like HTTP lib 2, URL lib 3, LXML, a couple of the others, just make testing so much easier 104 00:07:19,220 --> 00:07:21,520 when you're writing your own tools. So you can get down and dirty with them, but that's not 105 00:07:21,540 --> 00:07:29,460 going to happen. How many people in here have used LXML? It's awesome. So we're going to talk 106 00:07:29,460 --> 00:07:33,340 about that in a little bit, too. We didn't really know how familiar everybody was going to be 107 00:07:33,340 --> 00:07:38,020 with Python. So inside the, if you wanted to see some examples of, like, cookie handling and a 108 00:07:38,020 --> 00:07:41,860 couple of other things, you can see those inside the code snippets thing that we released. 109 00:07:44,080 --> 00:07:51,300 So a little tool I wrote when I was writing Monkey Fist that I released last year is basically 110 00:07:51,540 --> 00:07:59,600 a reflector for requests. So when you're structing your requests together and you're adding headers 111 00:07:59,600 --> 00:08:03,320 and you're making modifications, you might want to know what the web server is going to see. 112 00:08:03,860 --> 00:08:08,020 And I wrote this little thing, and it's in the code snippets thing as well. It's called reflect 113 00:08:08,020 --> 00:08:13,240 request. You just, you hit it, you run it, and anything you send to it, it's going to send back 114 00:08:13,240 --> 00:08:16,520 to you. So any get, post, put, or delete. So when you're building your clients, you can verify 115 00:08:16,520 --> 00:08:21,420 without having to set up a separate web server. It just implements the base HTTP request handler, 116 00:08:21,540 --> 00:08:27,680 class, and handles those requests. Basically just trace, implement it in couple lines. 117 00:08:28,060 --> 00:08:35,920 So, whatever. Data representations, so we've kind of moved on from like building a client. 118 00:08:36,220 --> 00:08:41,700 You might want to represent that data in a different format. So whether it be URL encoding, 119 00:08:42,100 --> 00:08:47,660 Hex encoding, Python has everything in Python is an object so any string object has encoding 120 00:08:47,660 --> 00:08:51,520 methods. So you can do things like base 64, Hex, even raw, you could do things like PHP. So all the 121 00:08:51,520 --> 00:08:56,520 13. And I realize that rot 13 sounds kind of ridiculous to all of us as security people. But 122 00:08:56,520 --> 00:09:01,340 as recent as like two months ago, we were we were looking at an application that was trying to 123 00:09:01,340 --> 00:09:07,460 obfuscate paths with rot 13. It's actually ridiculous, because you actually get to see 124 00:09:07,460 --> 00:09:14,840 like where it's like mapping drives out and stuff. So just because I want I like having a standalone 125 00:09:14,840 --> 00:09:21,260 encoder when I'm doing assessments. I wrote this tool called Dharma encoder. And the magic of 126 00:09:21,260 --> 00:09:26,220 Dharma encoders in the encoder lib as you would imagine. So if you it's open source, you can 127 00:09:26,220 --> 00:09:31,600 download it and you can see all the different data representations there. So on the next page is a 128 00:09:31,600 --> 00:09:38,540 screenshot. And all you have to do is choose which method you want to encode to and then you can 129 00:09:38,540 --> 00:09:44,580 also wrap it in like script tags and there's probably bugs in it. So let me know so I can fix 130 00:09:44,580 --> 00:09:50,520 them or if there's features that can be added or that you would like. Let me know and I'll get 131 00:09:50,520 --> 00:09:50,960 those added. 132 00:09:52,040 --> 00:09:58,240 So when you're like breaking web apps, like the three most common formats that you're going to get back in 133 00:09:58,240 --> 00:10:10,300 response is like XML, HTML or JSON. You know, one of the things like, what was I going to say. 134 00:10:10,500 --> 00:10:12,300 You were going to talk about like beautiful soup. 135 00:10:12,420 --> 00:10:19,200 Yeah. So how many people here actually heard of beautiful soup or used beautiful soup. Okay. 136 00:10:20,220 --> 00:10:26,680 LXML, less than that. But basically if you're parsing like HTML content or XML content, you want to 137 00:10:26,680 --> 00:10:32,540 actually use LXML over beautiful soup. The author of beautiful soup just expressed interest or lack of 138 00:10:32,540 --> 00:10:40,180 interest in supporting beautiful soup. LXML is a lot better. It's a lot more fault tolerant. And 139 00:10:40,180 --> 00:10:48,500 also it's a lot better at handling malformed HTML content. So your parser doesn't break as soon as, 140 00:10:48,500 --> 00:10:50,280 like it's got some mismatched tags or something. 141 00:10:50,620 --> 00:10:56,080 So is there anybody in here that thinks that the web isn't broken? Like everything is all well and good in 142 00:10:56,080 --> 00:11:04,320 tags. Our browsers have become really good at handling malformed HTML. Also don't use the built in 143 00:11:04,320 --> 00:11:09,080 HTML parser either in Python and the standard library because it's not fault tolerant either. So you 144 00:11:09,080 --> 00:11:13,520 need to be able to, you need to send it clean HTML that's able to be parsed first. 145 00:11:13,920 --> 00:11:18,480 And the other nice thing about LXML, it's actually written in C, which actually kind of makes it a pain in the 146 00:11:18,480 --> 00:11:23,940 ass for like cross platform compatibility. But if you get it working, it's awesome. Basically it's a lot 147 00:11:23,940 --> 00:11:32,460 faster than the Python implementations of XML parsing. And it's fast. It's great. So just an 148 00:11:32,460 --> 00:11:39,760 example, just parsing HTML content with LXML, you know, say we want to get out all the links from 149 00:11:39,760 --> 00:11:47,120 a HTML response, we just iterate over every A tag and get the href attribute from it. Simple as that. 150 00:11:48,840 --> 00:11:53,980 One of the nice things or one of the things I find useful parsing XML content is like XML 151 00:11:53,980 --> 00:11:59,120 configurations. So you've got like a web.XML and you have a bunch of serverlet classes and 152 00:11:59,120 --> 00:12:06,540 serverlet names. When I do code reviews, I parse out these web XMLs and get like just a list of all 153 00:12:06,540 --> 00:12:13,020 the serverlet classes and the URL patterns and just kind of map to see what I've reviewed so far and 154 00:12:13,020 --> 00:12:18,460 what I've got to review in the future, black box and stuff like that. So that's kind of what I'm 155 00:12:18,480 --> 00:12:24,680 trying to do. So this is just an example showing using XPath expressions to actually get various 156 00:12:24,680 --> 00:12:28,120 XML nodes. So very simple. 157 00:12:30,820 --> 00:12:39,360 JSON is obviously very, very popular now. So JSON maps pretty much directly to Python types. So, I 158 00:12:39,360 --> 00:12:46,220 mean, a JSON object is a Python dictionary and, you know, JSON array is a Python list. So it makes it 159 00:12:46,220 --> 00:12:48,460 really nice. JSON as of, I don't know, I don't know, I don't know, I don't know, I don't know, I don't 160 00:12:48,460 --> 00:12:53,260 know. Python 2.6 is built into the standard library. This is just in a couple lines of code. We'll 161 00:12:53,260 --> 00:12:58,120 go out to Twitter and grab all the current trends and print them out for you. Pretty simple. 162 00:13:00,900 --> 00:13:06,340 So when you're building your test cases, you're building fuzz cases for testing your web apps, 163 00:13:06,520 --> 00:13:11,040 you're going to want to know, be familiar with your application, its parameters and its data. 164 00:13:11,860 --> 00:13:16,580 There's certain things that you're going to want to make sure you test and then certain things that 165 00:13:16,580 --> 00:13:17,660 might not be so important. 166 00:13:19,000 --> 00:13:23,700 So look, if you're fuzzing like an API, you're going to want to make sure that you're sending things in 167 00:13:23,700 --> 00:13:29,440 the correct data format. If you're not encoding the data properly, you might have invalid cases to 168 00:13:29,440 --> 00:13:31,760 where you never find specific vulnerabilities. 169 00:13:33,200 --> 00:13:37,300 And the other thing, like, when you're generating fuzz cases, like, work smart. There's various, 170 00:13:37,340 --> 00:13:43,620 like, error tool methods that make generating this stuff, like, really simple. And when you're 171 00:13:43,620 --> 00:13:47,820 actually, you know, throwing stuff at the app, don't throw everything you got at once. 172 00:13:48,560 --> 00:13:52,560 You're never going to test, never going to be able to, like, explore all the code paths if, like, 173 00:13:52,620 --> 00:13:55,940 you know, every parameter is just junk. So. 174 00:13:56,460 --> 00:14:01,520 So, yeah, if you have, like, a string of post data that you're testing, you're going to want to 175 00:14:01,520 --> 00:14:07,360 iterate through it one by one by one and not throw every single thing at every single variable every 176 00:14:07,360 --> 00:14:07,920 single time. 177 00:14:08,120 --> 00:14:11,940 So an example of this is using the product method from the iter tools module. 178 00:14:12,500 --> 00:14:18,440 Basically this creates a Cartesian product of two iterables, so two lists against each other. So that, 179 00:14:18,440 --> 00:14:25,720 like, our output is, like, just fuzzing one parameter at a time per each, like, attack string so that 180 00:14:25,720 --> 00:14:36,040 we could efficiently, you know, do our tests. So I'm, like, losing, like, the English language. 181 00:14:36,520 --> 00:14:39,740 It's not just Python. So bear with me, guys. 182 00:14:41,960 --> 00:14:48,420 So I created this Python module called PyWebFuzz. And what it does is it creates a 183 00:14:48,440 --> 00:14:49,560 create a queue, but we don't need to. It's just doing what it does. Has anybody ever heard of 184 00:14:49,560 --> 00:14:53,440 FuzzDB? Collection of values for testing? Well, today is your lucky day. 185 00:14:53,580 --> 00:15:02,240 Yeah, it's just like a huge dictionary of like, various fuzz strings. Like, thousands of different kind of fuzz strings that you just, like, use. 186 00:15:03,240 --> 00:15:09,340 so those are available inside of Python classes so if you wanted to pull all the values for doing 187 00:15:09,340 --> 00:15:13,800 active SQL injection you could do it into a variable name and then you could iterate over 188 00:15:13,800 --> 00:15:18,180 the top of those values so you don't have to go out to separate libraries or read in different 189 00:15:18,180 --> 00:15:24,420 files it started off just being an implementation of fuzz db but quickly grew into something larger 190 00:15:24,420 --> 00:15:29,160 so I actually took the encoder lib from Dharma encoder and included it there as well 191 00:15:29,160 --> 00:15:33,920 because when you're iterating through those those values you might want to add an encoding type to 192 00:15:33,920 --> 00:15:40,040 them or represent that data differently it also has request logic built into it and I haven't 193 00:15:40,040 --> 00:15:46,560 pushed the code back but so when you're doing the Cartesian product method that we talked about 194 00:15:46,560 --> 00:15:53,440 before it creates a dictionary well you can't pass a dictionary value for post data in URL of two so 195 00:15:53,440 --> 00:15:58,060 I created a web string method so you just pass the dictionary to the web string and it'll properly 196 00:15:58,060 --> 00:15:59,140 encode that for you. 197 00:16:01,840 --> 00:16:08,340 So you can do some custom range we're not going to go into the examples but there is a wiki on the 198 00:16:08,340 --> 00:16:15,200 Google code page so I don't know how well it'll help you so you might want to send me an email or 199 00:16:15,200 --> 00:16:24,820 something or just explore it you know. Sequenced operations are a particular pain when you're doing 200 00:16:24,820 --> 00:16:28,980 your testing because if you're if the tools you're using don't understand the sequences 201 00:16:28,980 --> 00:16:34,520 you know and a lot of tools are starting to support these but they're supporting them via you 202 00:16:34,520 --> 00:16:41,620 know the names so pretty much every single tool out there every single commercial tool uses replay 203 00:16:41,620 --> 00:16:49,820 so if you can't replay the data you're pretty much screwed so you might have randomized values so 204 00:16:49,820 --> 00:16:56,840 if you think of like laying out a web page for a bank and it might have you know home account all 205 00:16:56,840 --> 00:16:58,960 these different menu options well if underneath that you're just not going to be able to do that it's going to be a lot of work. 206 00:16:58,980 --> 00:17:03,840 those menu options is a randomized value that changes every single time, that's 207 00:17:03,840 --> 00:17:08,740 gonna throw your tools off. But when you're writing your own clients, I mean 208 00:17:08,740 --> 00:17:11,980 you know how to handle that. So you're becoming intimately familiar with the 209 00:17:11,980 --> 00:17:17,200 application. There's also things that tools take care of for you that you 210 00:17:17,200 --> 00:17:21,300 might not think about, such as processing headers, processing cookies, adding 211 00:17:21,300 --> 00:17:25,180 referrers, and there's also might be there might be content that you just 212 00:17:25,180 --> 00:17:28,420 can't parse. You're just gonna have to resort back to regular expressions for 213 00:17:28,420 --> 00:17:35,780 that stuff, and it's not fun. Then you got two problems right? Has anybody ever 214 00:17:35,780 --> 00:17:40,880 heard of Selenium? How many people that have heard of Selenium know that you can 215 00:17:40,880 --> 00:17:49,580 write these test cases in Python? You did? Awesome, so Selenium in web drive, 216 00:17:49,720 --> 00:17:54,340 has anybody ever heard of webdriver? Okay so those projects are emerging which is 217 00:17:54,340 --> 00:17:57,260 nice because it gives some advantages to doing that. 218 00:17:57,520 --> 00:17:58,400 Has anybody ever 219 00:17:58,400 --> 00:18:03,780 ever heard of Windmill? I figured about as much. It's like Selenium, but it's written in Python. 220 00:18:04,560 --> 00:18:10,080 So it's kind of nice. I had some frustrations with Windmill. So obviously it would be nice to 221 00:18:10,380 --> 00:18:16,340 do everything in Python, but the frustration just set in and I went back to Selenium. 222 00:18:17,700 --> 00:18:23,020 So Selenium has a couple of components. It has the server component, the remote control, 223 00:18:23,020 --> 00:18:31,080 and the IDE. The IDE is nice. It's a Firefox plugin. And as you're clicking through the web 224 00:18:31,080 --> 00:18:36,820 application, it's recording what you're doing and writing out your Python code for you. So at that 225 00:18:36,820 --> 00:18:41,500 point, all you have to do is take that Python code, copy and paste it into your IDE, and then start 226 00:18:41,500 --> 00:18:46,980 writing your test cases around it. When you fire up Selenium, it will go ahead and open the browser 227 00:18:46,980 --> 00:18:51,900 and start taking those actions that you programmed in. So I think it's pretty easy to see how you 228 00:18:51,900 --> 00:18:53,000 could sequence your options. 229 00:18:53,020 --> 00:18:56,840 So you can run operations that way and use the browser. The browser is going to process all the 230 00:18:56,840 --> 00:19:03,260 JavaScript and do all the dirty work for you. And in the end, your goal was to test for SQL 231 00:19:03,260 --> 00:19:07,460 injection on a form value or test for cross-site scripting or something like that. 232 00:19:07,920 --> 00:19:16,100 So we have a nice picture of Tom Selleck. So we have a little demo. 233 00:19:19,900 --> 00:19:20,840 It's behind it. 234 00:19:23,980 --> 00:19:33,040 Obviously, it doesn't fit on the screen. So here we have a bank, a bank website. And we want to do 235 00:19:33,040 --> 00:19:42,860 some testing. So we're going to open up Selenium IDE. And we're going to basically choose Python 236 00:19:42,860 --> 00:19:51,100 as our format. So as you can see, it already sets up and does some imports. Now, I'm clicking on 237 00:19:51,100 --> 00:19:52,520 different things that you can't see. 238 00:19:53,340 --> 00:19:59,840 So there's a sequence of operations going on. And you can see the IDE is filling out. So now we get to a 239 00:19:59,840 --> 00:20:03,980 login. And it really doesn't matter what we log in with, basically. 240 00:20:04,420 --> 00:20:09,760 So you guys came here expecting to get some Python code out of this. We're not even doing code right 241 00:20:09,760 --> 00:20:09,980 now. 242 00:20:10,260 --> 00:20:19,100 So as you can see, it basically built a case for us. So if we copy and paste that into our IDE, we can 243 00:20:19,100 --> 00:20:23,000 then run a for loop over the top of a SQL. So that's pretty easy. So we're going to do a little bit more 244 00:20:29,980 --> 00:20:39,160 off advance. Everybody wants to have some doubts in understanding how classes work. 245 00:20:39,160 --> 00:20:39,420 But this is what it goes like. Create a code. Okay, here you'll see that the casos that are 246 00:20:39,420 --> 00:20:44,380 running in the batch look like this one. Excuse me. And then we run this secretly. This map 247 00:20:44,380 --> 00:20:46,140 just sorts things out. So here we have data. We've got something called my disparate process and I'll 248 00:20:47,040 --> 00:20:50,080 see it in a second. Here's a whole bunch of doubts. So instead of having to run through all these 249 00:20:50,080 --> 00:20:52,980 initials. That was just Javagebra. This is what we've built into these apps and we choose to also have 250 00:20:55,980 --> 00:21:01,500 all I did was say get body text instead of get HTML source because it would be easier to read. 251 00:21:01,800 --> 00:21:07,980 So we ran a test case. We basically threw three values at it. If you look at the return from 252 00:21:07,980 --> 00:21:13,460 the first one, you can see there's a SQL error message. You can see the strings. The second 253 00:21:13,460 --> 00:21:20,820 one, as you can see, it looks like just a standard error message. Now the third one, it says 254 00:21:20,820 --> 00:21:27,600 I want to view my account summary. So now we know we had a valid case. So we detected the error 255 00:21:27,600 --> 00:21:32,460 first with the first one. And the second one, you can see we exploited the SQL injection. All in a 256 00:21:32,460 --> 00:21:37,600 couple lines of code. So we were able to test drive the browser, create our sequence, and then 257 00:21:37,600 --> 00:21:42,600 break into that sequence and do tests. That's pretty simple, right? Okay. You're supposed to 258 00:21:42,600 --> 00:21:45,240 say yes. All right. 259 00:21:53,960 --> 00:22:01,260 So one of the things that I like to use, I like to use burp when testing web apps. Besides 260 00:22:01,260 --> 00:22:06,540 being a great proxy, there's a lot of other stuff in burp that makes it really cool. One of the 261 00:22:06,540 --> 00:22:12,620 things that, like, I really like it for is I can record, like, a proxy log. Basically record 262 00:22:12,620 --> 00:22:20,800 into a text file all my requested responses. The thing that web scanners, you know, they're 263 00:22:20,820 --> 00:22:26,160 basically everyone that's building web scanner like spends too much time trying to make it better 264 00:22:26,160 --> 00:22:32,600 at spidering. That's too hard for me. So, like, whatever. I'll just click through the app and like 265 00:22:32,600 --> 00:22:39,380 every single link that I can and submit every post I could. So the thing about getting a good 266 00:22:39,380 --> 00:22:45,400 crawl log, you know, when you're testing, you have all this context to you. And that's one of the 267 00:22:45,400 --> 00:22:50,760 things that web scanners don't really provide for you when you're testing. You have no idea what a 268 00:22:50,820 --> 00:23:01,720 doing behind the hood. So I like to just work off that. So remote. What I did was basically 269 00:23:01,720 --> 00:23:09,460 I wrote this API. I call it the GDS burp API. Basically allows me to parse a burp proxy log 270 00:23:10,060 --> 00:23:16,040 and then every request and response basically gets bundled up into what I call a burp object. 271 00:23:16,040 --> 00:23:22,440 So a burp object basically looks like this. You have like the request properties, the 272 00:23:22,440 --> 00:23:28,260 response properties, the time, the URL, and the parameters that you sent it. Basically 273 00:23:28,260 --> 00:23:36,560 everything that burp recorded to the log. The thing that say like you have an index number 274 00:23:36,560 --> 00:23:41,520 here, like 123. Like if you look in your burp history session, like this number 123 would 275 00:23:41,930 --> 00:23:46,020 match up with 123 in your history. So like you could easily, like, you could easily 276 00:23:46,040 --> 00:23:52,240 go back and forth. But basically you have all this data now available to you in an API that 277 00:23:52,240 --> 00:24:00,860 you can now just like call various methods on and get data from or for build context. What am I 278 00:24:00,860 --> 00:24:09,620 saying? It's always nice when the presenter says what am I saying? So like, you know, I was a 279 00:24:09,620 --> 00:24:14,280 black cat and Ben Nagy gave a presentation on fuzzing and like he kind of made the comment 280 00:24:14,280 --> 00:24:19,340 that everyone writes their own fuzzing engine because everybody else's sucks. That's what I 281 00:24:19,340 --> 00:24:26,340 think with web scanners. Unless I wrote it or whatever, I have no idea what the web scanner 282 00:24:26,340 --> 00:24:31,440 is doing. I don't have time to dive into the internals of various web app scanners. The 283 00:24:31,440 --> 00:24:36,540 other thing is, like I said before, I don't have enough context to what a web scanner is 284 00:24:36,540 --> 00:24:43,620 doing at a particular time. So they don't do enough actual testing and they do too much 285 00:24:43,620 --> 00:24:49,100 hand holding. And that's like as testers, you know, like whatever. That's what you're 286 00:24:49,700 --> 00:24:55,140 supposed to be doing, right? As testers it's up to us to make sure that we properly explored 287 00:24:55,140 --> 00:25:00,780 every path. So when you have a vuln scanner, sometimes you don't know if it's doing all the 288 00:25:00,780 --> 00:25:05,100 right things. I mean, there was one particular vuln scanner who will remain nameless that was 289 00:25:05,100 --> 00:25:09,200 encoding all its cross-site scripting data wrong. So as it sent it off, as you know in 290 00:25:09,200 --> 00:25:12,460 cross-site scripting, that can be very bad. There's a bunch of vulnerabilities that never 291 00:25:12,460 --> 00:25:13,600 got identified until they found it. So that's one of the things that we're trying to do. 292 00:25:13,620 --> 00:25:21,120 So basically I have, with the API, basically it's the way I work. It makes stuff, all the 293 00:25:21,120 --> 00:25:27,520 context in my crawl log available to me in these Python objects. So what can we actually do 294 00:25:27,520 --> 00:25:34,140 with the API? Basically you can do comparisons. Like compare two proxy logs. Say you 295 00:25:34,140 --> 00:25:39,200 crawled an application as a user in one session and then you did it again as like an 296 00:25:39,200 --> 00:25:42,960 administrator. It's really useful to do a comparison of like the URLs that were 297 00:25:42,960 --> 00:25:47,680 requested, the parameters that were submitted. You can just do a diff and then like actually 298 00:25:47,680 --> 00:25:53,060 replay those request objects as say like that user level for the administrator page and 299 00:25:53,060 --> 00:25:59,540 easily see like what worked, what didn't. Comparing responses and content lengths of 300 00:25:59,540 --> 00:26:03,460 different requests. You have two users submit a request to the same page, but they have 301 00:26:03,460 --> 00:26:09,620 different content links. Let's like compare them, like why. Obviously searching through 302 00:26:09,620 --> 00:26:12,940 responses for particular keywords. And the other thing that we're trying to do is we're 303 00:26:12,960 --> 00:26:15,780 trying to do a lot of things in Python. So the nice thing I found is say you have like a 304 00:26:15,780 --> 00:26:20,840 sequenced operation like we said earlier, you have a login operation or say like some cart 305 00:26:20,840 --> 00:26:26,760 checkout sequence that might span like five, six, seven requests. Basically we can pull out 306 00:26:26,760 --> 00:26:33,920 specific objects from our list and replay them in order, out of order and just fuzz stuff along 307 00:26:33,920 --> 00:26:42,740 the way. So basically you're creating web scanners, the commercial vendors call macros. So I find it 308 00:26:42,740 --> 00:26:43,840 really useful for that. 309 00:26:44,260 --> 00:26:49,740 Yeah, you can also do state maintenance as well. So if you're checking for state, like let's say 310 00:26:49,740 --> 00:26:54,320 you're looking for, you're making a request every so often to make sure that you see the word log 311 00:26:54,320 --> 00:27:00,020 off on your application. If it notices that the word log off doesn't happen anymore, you can run 312 00:27:00,020 --> 00:27:04,840 your sequence and re-log back in and maintain state. And that's something that some web 313 00:27:04,840 --> 00:27:09,000 scanners have a little bit of a problem with too is falling out of state. So how do you know when 314 00:27:09,000 --> 00:27:12,660 the scanner is really falling out of state unless you're looking at a verbose list of 315 00:27:12,660 --> 00:27:12,940 messages? 316 00:27:14,120 --> 00:27:18,940 So replaying a request is just as simple as like say with HTTP lib 2, basically we just pass, 317 00:27:20,000 --> 00:27:24,640 you know, the object to and call various methods on it to get the original data from. And 318 00:27:24,640 --> 00:27:33,140 basically this is just replaying that verb object as it was. And one line of code, really. I know 319 00:27:33,140 --> 00:27:34,200 there's like three, but. 320 00:27:38,060 --> 00:27:39,220 Okay, that was funny. 321 00:27:40,800 --> 00:27:42,640 So how many people have seen this? 322 00:27:42,640 --> 00:27:49,920 People here familiar with diff lib in the Python standard library? Nobody. Two, four, five, 323 00:27:50,620 --> 00:27:52,500 three, six, seven, eight, nine. 324 00:27:54,000 --> 00:28:03,820 So basically, say you got like, we're adding or subtracting, say you got like two responses, we 325 00:28:03,820 --> 00:28:10,500 could compare those responses in like a diff style output and just easily see in the response like 326 00:28:10,500 --> 00:28:12,620 what was changed. Down to like, you know, like, you know, like, you know, like, you know, like, you 327 00:28:12,640 --> 00:28:19,320 just can see if it's like the actual characters, like per byte level with this module. So makes 328 00:28:19,320 --> 00:28:25,920 for a nice really visual representation of what's changed. So we've got a demo, just showing a 329 00:28:25,920 --> 00:28:28,180 couple things with the API. 330 00:28:32,640 --> 00:28:33,660 Which side do you need? 331 00:28:34,220 --> 00:28:42,620 That side's fine. So on the right, I just have like an open burped log. I'm just imperfecting the 332 00:28:42,640 --> 00:28:46,620 the GDS burp API, I'm going to import some logging and just do 333 00:28:46,620 --> 00:28:51,840 some logging so you actually see what's going on. Yeah, that's 334 00:28:51,840 --> 00:29:01,600 good. Can you guys all see that? No? Oh, damn. So basically right 335 00:29:01,600 --> 00:29:04,620 here I'm parsing a burp log. I'm just calling GDS.burp.parse. 336 00:29:04,860 --> 00:29:08,580 Basically I parsed out all the burp objects. Scroll down, dude. 337 00:29:09,540 --> 00:29:13,800 And here I'm just printing out the request properties with 338 00:29:13,800 --> 00:29:21,520 pprint. Can you move down? I'm trying to. Okay. Max. Here I'm 339 00:29:21,520 --> 00:29:24,920 just calling the get request headers on the second item in my 340 00:29:24,920 --> 00:29:29,960 list. I get all the headers that I parsed out. Here I just get a 341 00:29:29,960 --> 00:29:37,380 single request header, the user agent. Right now I'm going to do 342 00:29:37,380 --> 00:29:38,560 a fuzz. I'm going to do a fuzz. I'm going to do a fuzz. I'm 343 00:29:38,580 --> 00:29:39,080 going to send it through. So you can see that all the requests 344 00:29:40,260 --> 00:29:46,880 basically just sent it through. And each replayed request gets 345 00:29:46,880 --> 00:29:51,340 appended to a .replayed property. Basically a list. And 346 00:29:51,340 --> 00:29:54,780 then you can just call out those request properties, headers, 347 00:29:54,960 --> 00:29:57,360 things like that. Basically all that stuff that the original 348 00:29:57,360 --> 00:30:02,340 burp object had you now have in the replayed ones. So right here 349 00:30:02,340 --> 00:30:06,040 I'm just going to do a diff of all my replayed requests and 350 00:30:06,040 --> 00:30:11,700 and responses, just output it to a file. So the first one 351 00:30:11,700 --> 00:30:15,040 basically, you can't really see that but basically it's just 352 00:30:15,040 --> 00:30:21,500 showing a script alert tag in the response. Down below here I 353 00:30:21,500 --> 00:30:26,180 have on the right side there's a set cookie header being set in 354 00:30:26,180 --> 00:30:29,780 the response headers and it's also redirecting to some main 355 00:30:30,520 --> 00:30:34,880 bank page. So and then the fudge string that was sent was like 356 00:30:34,880 --> 00:30:40,000 or one equals one, basically the same fudge strings that Nathan 357 00:30:40,820 --> 00:30:46,320 replayed earlier with Selenium. One of the cool things basically 358 00:30:46,320 --> 00:30:51,720 just save state, basically I just pickle my burp log to a 359 00:30:51,720 --> 00:30:56,860 state file. All the replayed requests, responses, all that 360 00:30:56,860 --> 00:31:00,680 data is basically available to me if I choose to reload it 361 00:31:00,680 --> 00:31:04,860 later on. So I'm going to go ahead and show you the 362 00:31:06,380 --> 00:31:09,280 request. I find that really useful so I don't have to do 363 00:31:09,280 --> 00:31:13,300 everything between 9 and 5. I could actually do it tomorrow. 364 00:31:15,040 --> 00:31:18,640 So basically you got all the same stuff that you originally 365 00:31:18,640 --> 00:31:23,040 had when you replayed these requests. So. I know you 366 00:31:23,040 --> 00:31:26,360 couldn't see that but it's actually pretty cool. 367 00:31:37,400 --> 00:31:41,260 That's also available in the zip file. So the API is available in 368 00:31:41,260 --> 00:31:43,100 the zip file and all the other tools that we were talking about. 369 00:31:43,300 --> 00:31:45,860 We should post a link to the video so if you want to watch the 370 00:31:45,860 --> 00:31:48,680 video. We'll upload the videos to YouTube so you can actually, 371 00:31:48,840 --> 00:31:51,240 when you're thinking about it later, maybe you'll watch it. So 372 00:31:51,240 --> 00:31:53,940 like I said, you know, a couple of cool things is save state, 373 00:31:54,060 --> 00:31:57,820 load state. Parsing takes about like a minute per 100 megabyte 374 00:31:57,820 --> 00:32:01,600 file, which is I think relatively fast. But if you guys 375 00:32:01,600 --> 00:32:04,860 find a way to make it faster, that's cool. I think that's a 376 00:32:04,880 --> 00:32:07,080 good thing. I'd love to be faster because I'm all about 377 00:32:07,080 --> 00:32:12,340 performance, not security. Spoken like a true developer. 378 00:32:16,280 --> 00:32:20,260 Other times it's nice to have browser objects to play with. So 379 00:32:20,920 --> 00:32:24,300 who in here knows that you can write Firefox extensions in 380 00:32:24,300 --> 00:32:29,280 Python? Awesome. Nobody. Well, take my word for it and don't 381 00:32:29,280 --> 00:32:32,800 verify it. That's what we need to do. So you can write Firefox 382 00:32:32,800 --> 00:32:34,860 extensions in, in, in, in, in, in, in, in, in, in, in, in, in, in, 383 00:32:34,860 --> 00:32:42,980 in Python. There's actually an extension called PyXPyComXXT. And 384 00:32:42,980 --> 00:32:47,260 you use that and it loads up an entire Python environment. And I 385 00:32:47,260 --> 00:32:51,840 did this for a while. But my frustration really had me going 386 00:32:51,840 --> 00:32:55,040 when you can't really interface with the browser object too well 387 00:32:55,040 --> 00:32:59,240 using Python. Like you have to keep resorting to, you have to 388 00:32:59,240 --> 00:33:03,060 keep resorting to JavaScript. And JavaScript is kind of for 389 00:33:03,060 --> 00:33:04,840 SATIS too. So you can't really use Python. You can't really use 390 00:33:04,860 --> 00:33:07,200 Python. I mean, I don't like a language that just chokes and 391 00:33:07,200 --> 00:33:09,420 dies and never gives me any indication that it worked or 392 00:33:09,420 --> 00:33:13,120 didn't work. I mean, who thought that one up? But so I like to 393 00:33:13,120 --> 00:33:17,180 stay away from JavaScript. So recently I started switching to 394 00:33:17,180 --> 00:33:20,840 do more things in WebKit using some of the other GUI 395 00:33:20,840 --> 00:33:23,700 frameworks. So say for instance, you're doing a 396 00:33:23,700 --> 00:33:26,680 standalone ZulRunner object. And since we want, we're all about 397 00:33:26,680 --> 00:33:29,100 context when we're testing. We want to be able to make a 398 00:33:29,100 --> 00:33:32,680 request with like HTPLib2, modify our headers, do all this, 399 00:33:32,800 --> 00:33:34,840 get the response back. And then we just go through the 400 00:33:34,860 --> 00:33:41,860 render it in the browser object. Well, doing that in Zool Runner or Firefox is a pain. It's 401 00:33:41,860 --> 00:33:47,000 a nightmare. One thing that I noticed when I first started doing WebKit stuff is you could 402 00:33:47,000 --> 00:33:54,800 just say, you could call the object and say set HTML. So here's an example of using PyQt and just 403 00:33:54,800 --> 00:33:59,740 a couple lines of code and doing a test for cross-site scripting. Because cross-site scripting 404 00:33:59,740 --> 00:34:03,300 is one of those things that's nice to see a rendered response. Sometimes it's just easier 405 00:34:03,300 --> 00:34:08,880 to see that. So we have our URL, we have our request, and then we do the web object, set HTML, 406 00:34:09,140 --> 00:34:16,500 and then tell it to show. And on the next page, on the next page, you can see that once it 407 00:34:16,500 --> 00:34:20,600 renders, it's very easy to see that that was vulnerable to cross-site scripting. Obviously 408 00:34:20,600 --> 00:34:25,100 cross-site scripting is very browser dependent. So sometimes you'll have one in one engine and 409 00:34:25,100 --> 00:34:31,340 one in the other. But for very simple, universal cross-site scripting vulnerabilities, this 410 00:34:31,340 --> 00:34:32,860 could be very, very useful. 411 00:34:33,300 --> 00:34:40,600 Also, you can do other cool things like instantiate an inspector on some content. So you'd be 412 00:34:40,600 --> 00:34:49,940 able to open it up and have syntax highlighted, examples. In WebKit also, like PyQt, is starting 413 00:34:49,940 --> 00:34:55,260 to support more, have more support for plug-ins, which makes it nice when you're dealing with 414 00:34:55,260 --> 00:35:02,220 Silverlight. So that's all we had time for. But very simple. Couple lines of code and you've 415 00:35:02,220 --> 00:35:03,280 basically rendered a response with that. So, you can do that with any product, any type of content. 416 00:35:03,300 --> 00:35:06,620 response that you got from a different module. I think they 417 00:35:06,620 --> 00:35:09,140 were like hitting them with a bait and switch with a couple 418 00:35:09,140 --> 00:35:11,420 lines of code because everyone knows like a couple lines of 419 00:35:11,420 --> 00:35:15,020 code equals like several man hours. Well you already pointed 420 00:35:15,020 --> 00:35:17,120 out that you said here's a single line of code but it's 421 00:35:17,120 --> 00:35:20,460 actually three on the page. So you kind of gave it away right 422 00:35:20,460 --> 00:35:25,420 there. We can't count. Which is really bad when you're 423 00:35:25,420 --> 00:35:29,080 implementing ranges. Web services are also something 424 00:35:29,080 --> 00:35:34,740 else that scanners have a real problem with regardless of what 425 00:35:34,740 --> 00:35:38,940 vendor documentation says. Because it's really hard to tell 426 00:35:38,940 --> 00:35:41,960 if you're enumerating through a WSDL and you see different 427 00:35:41,960 --> 00:35:45,340 things that say admin obviously you might want to take a better 428 00:35:45,340 --> 00:35:51,320 look at that. With Python they have, so has anybody ever used 429 00:35:51,320 --> 00:35:56,140 SUDS before? A couple people. Three people. The best thing 430 00:35:56,140 --> 00:35:58,860 about SUDS is it has an object API. 431 00:35:59,080 --> 00:36:02,040 So everything is, you create the object and you call its 432 00:36:02,040 --> 00:36:06,980 methods. It's very nice. It's very, very Pythonic. It uses 433 00:36:06,980 --> 00:36:11,740 URLib2 for opener support. So URLib2 is an extensible library 434 00:36:11,740 --> 00:36:15,740 which means that you can create new protocols and handlers and 435 00:36:15,740 --> 00:36:19,460 install those. So as long as it's using URLib2 that means if 436 00:36:19,460 --> 00:36:21,880 you're handling basic auth, if you need to handle cookies, if 437 00:36:21,880 --> 00:36:25,060 you need to do all of that, it has support for it and it's 438 00:36:25,060 --> 00:36:26,920 familiar support because it's URLib2. 439 00:36:29,080 --> 00:36:34,100 So to just read a WSDL in a couple lines of code, actually 440 00:36:34,100 --> 00:36:38,380 this is two, so it really is a couple. You just basically point 441 00:36:38,380 --> 00:36:41,820 it to a URL and then print the client and that prints off the 442 00:36:41,820 --> 00:36:44,400 WSDL's methods. I guess we already have like two findings 443 00:36:44,400 --> 00:36:48,420 on this one page. Like we got published WSDL and basic auth in 444 00:36:48,420 --> 00:36:51,700 use. Yes. So yeah, there's two findings already by the time you 445 00:36:51,700 --> 00:36:57,000 get here. So the basic auth is supported by merely adding a 446 00:36:57,000 --> 00:36:59,060 username and password. And then two things that I wanted to 447 00:36:59,080 --> 00:37:01,720 point out is to perform functions based on the WSDL, you just 448 00:37:01,720 --> 00:37:05,520 basically call the method. So here's an example of doing a 449 00:37:05,520 --> 00:37:09,700 currency conversion. So from right here, you basically point 450 00:37:09,700 --> 00:37:12,660 it to the WSDL, you create the client, and you get your result 451 00:37:12,660 --> 00:37:17,740 and you print your result. So here's a real example of 452 00:37:18,540 --> 00:37:23,460 identifying SQL injection in a web service. And this is going 453 00:37:23,460 --> 00:37:26,840 against WebGoat's web service. So we're creating our own 454 00:37:26,840 --> 00:37:29,060 headers. And as you can see here, we've got a lot of 455 00:37:29,080 --> 00:37:32,940 code. The JSession ID is already set and the basic auth is already 456 00:37:32,940 --> 00:37:36,560 set. So we didn't need to use the username and password. We 457 00:37:36,560 --> 00:37:39,860 create a custom transport to add to our headers. So it's a little 458 00:37:39,860 --> 00:37:42,060 more complicated than it really needed to be just to kind of show 459 00:37:42,060 --> 00:37:45,040 you how it works. You create your client and then you iterate 460 00:37:45,040 --> 00:37:49,440 over the top of your SQL injection value. So here, I 461 00:37:49,440 --> 00:37:54,320 basically took PyWebFuzz and I imported the FuzzDB and then I 462 00:37:54,320 --> 00:37:58,940 asked for all of the generic SQL injection values and iterated over 463 00:37:59,080 --> 00:38:05,360 the top of them. So once you do that, there's some win because you 464 00:38:05,360 --> 00:38:09,000 can see the certain values that were printed off. The other values 465 00:38:09,000 --> 00:38:11,920 when it comes back successful, those are credit card numbers. So 466 00:38:11,920 --> 00:38:16,460 you know, pretty easy. Just a couple lines of code. Just a couple 467 00:38:16,460 --> 00:38:22,200 lines of code. You guys are all going to go back to work. You guys 468 00:38:22,200 --> 00:38:24,420 are all going to go back to work saying, oh, my God, you know, 469 00:38:24,420 --> 00:38:28,600 finding all these vulns with this is easy. So I do a lot of flex stuff. 470 00:38:29,080 --> 00:38:33,400 Flex basically is a framework for developers to write web 471 00:38:33,400 --> 00:38:37,740 applications on flash. One of the features of flex is you can 472 00:38:37,740 --> 00:38:43,120 encode messages in AMF action message format. Basically it's 473 00:38:43,120 --> 00:38:47,840 just a compact binary screen. Several tools support AMF. 474 00:38:47,960 --> 00:38:52,000 There's like Burp, Charles, WebScarab. Unfortunately, like 475 00:38:52,000 --> 00:38:56,180 the support for AMF is kind of limited. You can't really craft 476 00:38:56,180 --> 00:38:59,060 messages from scratch with Burp or like AMF. You can't really 477 00:38:59,080 --> 00:39:07,880 add properties to a request. And I just find, like, say hi to 478 00:39:07,880 --> 00:39:12,980 PyAMF. Basically I can work now with AMF in Python. Basically 479 00:39:12,980 --> 00:39:17,680 there's several AMF encoders and decoders. So you can serialize 480 00:39:17,680 --> 00:39:21,780 Python types to AMF. So if you have like a date time object, it 481 00:39:21,780 --> 00:39:25,760 gets serialized to action script date time. And then when it gets 482 00:39:25,760 --> 00:39:28,740 deserialized by like Blaze DS, which is the remoting 483 00:39:28,740 --> 00:39:29,060 server, it gets serialized to action script date time. And then 484 00:39:29,080 --> 00:39:29,840 when you want to use the arrived date on the server, that 485 00:39:29,840 --> 00:39:34,140 gets deserialized into a Java. So how many people in here have 486 00:39:34,140 --> 00:39:36,840 like assessed a flex app or dealt with something with the 487 00:39:36,840 --> 00:39:39,820 flash frontend? A few people. Yeah. Good luck with the web 488 00:39:39,820 --> 00:39:44,200 scanner on those. So basically with PyAMF, we can write our 489 00:39:44,200 --> 00:39:50,160 clients to test stuff. There's some remoting gateway support. 490 00:39:50,440 --> 00:39:54,220 So like for Djang. Go or Twisted, if you have a web app, 491 00:39:54,440 --> 00:39:57,720 you can write a web app in Python that serves up content in 492 00:39:57,720 --> 00:40:04,440 AMF and a flash client will be able to work with it. So I don't know how many people have 493 00:40:04,440 --> 00:40:09,280 heard of Dblaze, shout out to my buddy John Rose, last year he wrote this tool in Python, 494 00:40:09,460 --> 00:40:15,280 basically enumerated methods and services in a remoting server. But he did it by brute force, 495 00:40:15,340 --> 00:40:22,040 one HTTP request at a time. The cool thing about AMF, all AMF requests are packed inside an 496 00:40:22,040 --> 00:40:29,700 AMF envelope. So I thought like, shit, why not do this all at once? My HTTP request is like 497 00:40:29,700 --> 00:40:38,540 200 bytes long, 200,000 bytes long, but I just enumerated like 10,000 methods and services all 498 00:40:38,540 --> 00:40:44,120 on this one server and one HTTP request, which was just awesome because it only took like a 499 00:40:44,120 --> 00:40:52,020 minute to respond. So that's one of the cool things you can do. When testing flash clients, 500 00:40:52,920 --> 00:41:02,700 you're probably going to run into cases where when you're sending a value, it's not the 501 00:41:02,700 --> 00:41:07,820 correct type. So you might have some custom object, like an employee object in the flash 502 00:41:07,820 --> 00:41:13,440 client that's being sent over the wire to the remoting server. And just passing a string or 503 00:41:13,440 --> 00:41:21,060 boolean that says not going to work. So when this happens, your proxy is not going to understand the 504 00:41:21,060 --> 00:41:27,060 structure of that object. It's going to choke when it's going to try to deserialize it. So again, 505 00:41:29,100 --> 00:41:34,140 with just a couple lines of code, we can now create an object factory, basically a dictionary, 506 00:41:35,340 --> 00:41:42,820 and register that class with an alias namespace, or a class alias. So that when pyAMF goes to 507 00:41:42,820 --> 00:41:51,040 actually encode that Python object to the AMF stream, it encodes it as say that employee object. And then when the server gets back to the right address with the demo, it gets the same files. And this is how you can show the 508 00:41:51,040 --> 00:41:58,700 gets it, it deserializes it back to whatever object you're playing with. So it's pretty neat. 509 00:42:00,840 --> 00:42:10,400 Yeah. It's early. .NET integration, how many people here have ever used iron Python at 510 00:42:10,400 --> 00:42:16,040 all? So a few. Very good. So you might not be aware that you can use your Python code 511 00:42:16,040 --> 00:42:22,160 inside of .NET. And that provides some very useful advantages. For example, like being able 512 00:42:22,160 --> 00:42:28,720 to import .NET DLLs and call functions on them. You know, so it might be a silver light object 513 00:42:28,720 --> 00:42:37,540 or some other .NET environment. You also have integration into the .NET common language runtime. 514 00:42:37,800 --> 00:42:43,440 So you can import the CLR. So on the next page, you can do something like download the ZAP file, 515 00:42:43,580 --> 00:42:46,020 unzip it, grab the manifest, enumerate through it. And then you can import the CLR into the 516 00:42:46,020 --> 00:42:50,220 .NET and grab all the DLLs. So in the bottom is a simple example of importing the common 517 00:42:50,220 --> 00:42:55,280 language runtime, adding reference and importing all the functions out of the DLL. So pretty 518 00:42:55,280 --> 00:43:02,240 simple. Yeah, I know. Whatever. So basically, you know, as you're assessing web apps, you're 519 00:43:02,240 --> 00:43:06,760 going to come across cases where, you know, your app is actually speaking a binary protocol. I 520 00:43:06,760 --> 00:43:13,200 know it's not heard of before. But basically your scanner is going to choke when it's going to 521 00:43:13,200 --> 00:43:16,000 try hitting its binary protocol. You're probably going to choke. You're probably going to 522 00:43:16,000 --> 00:43:20,540 like spit your coffee, be like, damn it, why did I get stuck with this app. Now I got to like spend 523 00:43:20,540 --> 00:43:26,760 time reversing this thing. But whatever. Python has a module called struct. Has a module in the 524 00:43:26,760 --> 00:43:33,700 standard library called struct. Basically we could convert Python values into native C 525 00:43:33,700 --> 00:43:39,260 structures. Let's take an example, binary protocol. Basically this is kind of similar to what 526 00:43:39,260 --> 00:43:45,840 most binary protocols are. Basically we have like type markers before the types. Strings are 527 00:43:45,840 --> 00:43:50,840 encoded in UTF-8. Proceeded by after the type marker for a string, we have the length of the 528 00:43:50,840 --> 00:43:57,180 string encoded as like a short, a 16 byte integer. And web apps, I don't know, nobody knows 529 00:43:57,180 --> 00:44:06,820 what a short is. So then the value, your string. So parsing a string, basically, you know, as we 530 00:44:06,820 --> 00:44:15,800 run into that type marker, say 0x02, we unpack the following value into a short, which is the 531 00:44:15,840 --> 00:44:23,660 h format specifier. Advance our position by two bytes. And then unpack that string for the 532 00:44:23,660 --> 00:44:31,580 necessary length. Writing a string is basically the opposite. Write our type marker. Write the 533 00:44:31,580 --> 00:44:37,560 length of our string as a short. And write the string. So when you put it all together, 534 00:44:37,620 --> 00:44:45,240 basically, as we're iterating over every position in the stream, you know, as you run into these 535 00:44:45,840 --> 00:44:53,580 numbers, basically, you do the appropriate parsing of that data. So when all is said and done, you 536 00:44:53,580 --> 00:45:00,320 just wrote a simple state machine. Welcome back to compilers and college and oh, man. So 537 00:45:01,140 --> 00:45:06,860 basically, it's a wild loop. Iterates over every byte in the buffer and does the necessary 538 00:45:06,860 --> 00:45:15,820 action when you run into stuff. So that did not come out how I wanted it to. So that's 539 00:45:15,840 --> 00:45:22,440 it. You guys get the picture, hopefully. So that's the end of our talk. Hope you guys 540 00:45:22,440 --> 00:45:27,100 enjoyed it. If you just can't get enough of this stuff, we're actually writing a book on this 541 00:45:27,100 --> 00:45:33,800 topic. So if you just need to do the deep dive, it will be out in the next seven years. And 542 00:45:35,300 --> 00:45:41,540 like Python 3.1 will probably be used. We have like two minutes for questions. Anybody? 543 00:45:42,480 --> 00:45:45,320 We'll be hanging out afterwards. So next slide. 544 00:45:45,840 --> 00:45:46,600 1-1-3. 545 00:45:46,660 --> 00:45:49,860 1-1-3. Advance the slide. Thanks.