This is Constricting the Web, Offensive Python for Web Hackers. So if you didn't know that, you're in the wrong talk. I am Nathan Hamill, I'm a principal consultant for fish net security on the application security team. And I'm also an associate professor at the University of Advancing Technology. And I'm Marcin Bielgoszewski. I'm not going to ask you guys to repeat that. But I'm a security engineer, Gotham Digital Science. I do web shit. Kind of the reason we decided to do this talk is because there's a lot of people who are starting to get more into testing web applications. And web applications are becoming more complicated. So when first things people usually reach for are their tool kits. So maybe it's app scan or web inspect. But they don't really give you the whole picture. A lot of times vendors are playing catch up. So with new technologies like flash and silver light, it might not be supported for quite a bit of time between the time people are using it and the time the technology catches up with to be able to test it. So it's not like you can just say we have this new technology, we'll just wait until everybody catches up and then we'll check to see whether it's secure. That's not really setting you up for success there. There's also difficult cases where your standard testing tools won't really help you. APIs for one. So if you're going through testing your application, you run into an API, you might not even see it. The scanner might not even see it unless it makes some sort of call. There's also sequenced operations as well. So if there's a sequence of steps that need to happen prior to a test case, sometimes standard tools will fall flat on their face. With randomized data, you know, if a page lays out and every single time the page lays out, the data is behind the menu options is randomized, there's pretty much no testing tool out there, standard testing tool that will help you. And that's why you need to write your own tools. So this is an intervention. You know, I see a bunch of people who love you like crazy and they want you to join the fight and not just use AppScan and WebInspect. Now, this wasn't a test case. It was a test case. It was a test case. And in our previous slide, so what we have already posted is the slides for this talk, as well as the code snippets that we're using. So we're releasing a few tools and we're releasing some example code. That's already available for download. So if you get a chance and you want to play around with that, that's all well and good. Here's kind of an example snapshot of some modern infrastructure. If you look at this infrastructure and how it's laid out, you know, the front-end web page, which, you know, vulnerability, web vulnerability scanners are really good at testing, isn't really the bigger picture. You know, it's only a small percentage of your entire attack surface. So that being the case, you know, if you just ran these standard tools and generated reports, you wouldn't even see any of these other things, these client APIs, server-to-server APIs, storage mechanisms on the back. And that's kind of just leading more up to the point that, you know, you're going to have to write your own tools if you want to be successful. So why do we use Python? I think we all know because it rocks, right? You know, you could quickly write tools, you know, on a whim. That's one of the things, like, when you're testing stuff, like, the lifetime, life span or whatever of your tool actually just lasts as long as the app stands up, you know? After that, it's, like, just a throwaway. Easy to understand. And I kind of like the white space. You know, it's kind of like, you know, it's a web site. But, you know, it's just one of the things that you can do with Python. And I guess most of you do, too. That's why you still use it. Otherwise, you'd be back to Perl. So. There's plenty of support out there for Python, as well. One thing I will advise against not doing, do not go into the Python room on Freenode and start lulling. They do not like that. I am permabanned from the Python IRC channel on Freenode. But I thought it was funny. So you can Google for plenty of examples. a search engine called knowledge that's a Python source code search engine which comes in helpful especially for poorly documented modules. You know, you might find that useful. I think I saw that from a tweet from Dave. He's like hey, knowledge and I'm like cool. I guess poorly documented Python code you don't even want to use any, you know, if you can't read the source might as well just skip it. So there's plenty of help available. So a few of the big tools out there, I mean like anyone coming from like network side knows Scapey. I love Scapey. Peach fuzzing shit, like that's awesome. From like the reverse engineering side of the house, like you got Python, you got PyDBG. My buddy Rich Smith just released a toolkit yesterday called Pyretic, basically deobfuscating or reversing out obfuscated Python bytecode which is pretty badass. W3AF, 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 heard of it. It's a little bit of a web scanner you guys are probably all familiar with written in Python as well. So a lot of stuff out there already and it's kind of like a lot of people's insecurity like to use Python. So those are the big ones. So it kind of gives you an opportunity to not only, to not only, you know, use tools that are already written in Python but also for extending them as well and contributing back to those projects. So where does Python fit? Python fits in the space between your front end and your fully automated testing tools and completely manual testing. So you can have just as much context over what you're testing as manual testing because you're basically writing the clients. You're basically using the tools. You know exactly what data is going to the application and what's coming back. So that's the place it fits. Automating your manual testing cases. There's a couple of different versions of Python. We only highlighted three here that may be of interest to you. CPython is the standard Python implementation that you probably have running on your system. Jython is Python in Java. And Iron Python is Python in .NET. So we'll go into that a little bit later. Other than just having an excuse to put Ron Jeremy in a slide. To piss off Ping. Yeah. You have to know, you have to be intimately familiar with your applications before you start testing them. And I realize that sounds kind of strange. But a lot of commercial testing tools are meant to abstract you from being familiar with the application. You can get down and dirty with them. But that's not typically how they're used in the infrastructure. So that's kind of what this slide was about. You guys are probably all familiar with standard library. You keep the docs under your pillow. Like, you know, whatever. Some of the third party modules that you might not be aware of, like HTTP lib 2, URL lib 3, LXML, a couple of the others, just make testing so much easier when you're writing your own tools. So you can get down and dirty with them, but that's not going to happen. How many people in here have used LXML? It's awesome. So we're going to talk about that in a little bit, too. We didn't really know how familiar everybody was going to be with Python. So inside the, if you wanted to see some examples of, like, cookie handling and a couple of other things, you can see those inside the code snippets thing that we released. So a little tool I wrote when I was writing Monkey Fist that I released last year is basically a reflector for requests. So when you're structing your requests together and you're adding headers and you're making modifications, you might want to know what the web server is going to see. And I wrote this little thing, and it's in the code snippets thing as well. It's called reflect request. You just, you hit it, you run it, and anything you send to it, it's going to send back to you. So any get, post, put, or delete. So when you're building your clients, you can verify without having to set up a separate web server. It just implements the base HTTP request handler, class, and handles those requests. Basically just trace, implement it in couple lines. So, whatever. Data representations, so we've kind of moved on from like building a client. You might want to represent that data in a different format. So whether it be URL encoding, Hex encoding, Python has everything in Python is an object so any string object has encoding methods. So you can do things like base 64, Hex, even raw, you could do things like PHP. So all the 13. And I realize that rot 13 sounds kind of ridiculous to all of us as security people. But as recent as like two months ago, we were we were looking at an application that was trying to obfuscate paths with rot 13. It's actually ridiculous, because you actually get to see like where it's like mapping drives out and stuff. So just because I want I like having a standalone encoder when I'm doing assessments. I wrote this tool called Dharma encoder. And the magic of Dharma encoders in the encoder lib as you would imagine. So if you it's open source, you can download it and you can see all the different data representations there. So on the next page is a screenshot. And all you have to do is choose which method you want to encode to and then you can also wrap it in like script tags and there's probably bugs in it. So let me know so I can fix them or if there's features that can be added or that you would like. Let me know and I'll get those added. So when you're like breaking web apps, like the three most common formats that you're going to get back in response is like XML, HTML or JSON. You know, one of the things like, what was I going to say. You were going to talk about like beautiful soup. Yeah. So how many people here actually heard of beautiful soup or used beautiful soup. Okay. LXML, less than that. But basically if you're parsing like HTML content or XML content, you want to actually use LXML over beautiful soup. The author of beautiful soup just expressed interest or lack of interest in supporting beautiful soup. LXML is a lot better. It's a lot more fault tolerant. And also it's a lot better at handling malformed HTML content. So your parser doesn't break as soon as, like it's got some mismatched tags or something. So is there anybody in here that thinks that the web isn't broken? Like everything is all well and good in tags. Our browsers have become really good at handling malformed HTML. Also don't use the built in HTML parser either in Python and the standard library because it's not fault tolerant either. So you need to be able to, you need to send it clean HTML that's able to be parsed first. And the other nice thing about LXML, it's actually written in C, which actually kind of makes it a pain in the ass for like cross platform compatibility. But if you get it working, it's awesome. Basically it's a lot faster than the Python implementations of XML parsing. And it's fast. It's great. So just an example, just parsing HTML content with LXML, you know, say we want to get out all the links from a HTML response, we just iterate over every A tag and get the href attribute from it. Simple as that. One of the nice things or one of the things I find useful parsing XML content is like XML configurations. So you've got like a web.XML and you have a bunch of serverlet classes and serverlet names. When I do code reviews, I parse out these web XMLs and get like just a list of all the serverlet classes and the URL patterns and just kind of map to see what I've reviewed so far and what I've got to review in the future, black box and stuff like that. So that's kind of what I'm trying to do. So this is just an example showing using XPath expressions to actually get various XML nodes. So very simple. JSON is obviously very, very popular now. So JSON maps pretty much directly to Python types. So, I mean, a JSON object is a Python dictionary and, you know, JSON array is a Python list. So it makes it 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 know. Python 2.6 is built into the standard library. This is just in a couple lines of code. We'll go out to Twitter and grab all the current trends and print them out for you. Pretty simple. So when you're building your test cases, you're building fuzz cases for testing your web apps, you're going to want to know, be familiar with your application, its parameters and its data. There's certain things that you're going to want to make sure you test and then certain things that might not be so important. So look, if you're fuzzing like an API, you're going to want to make sure that you're sending things in the correct data format. If you're not encoding the data properly, you might have invalid cases to where you never find specific vulnerabilities. And the other thing, like, when you're generating fuzz cases, like, work smart. There's various, like, error tool methods that make generating this stuff, like, really simple. And when you're actually, you know, throwing stuff at the app, don't throw everything you got at once. You're never going to test, never going to be able to, like, explore all the code paths if, like, you know, every parameter is just junk. So. So, yeah, if you have, like, a string of post data that you're testing, you're going to want to iterate through it one by one by one and not throw every single thing at every single variable every single time. So an example of this is using the product method from the iter tools module. Basically this creates a Cartesian product of two iterables, so two lists against each other. So that, like, our output is, like, just fuzzing one parameter at a time per each, like, attack string so that we could efficiently, you know, do our tests. So I'm, like, losing, like, the English language. It's not just Python. So bear with me, guys. So I created this Python module called PyWebFuzz. And what it does is it creates a create a queue, but we don't need to. It's just doing what it does. Has anybody ever heard of FuzzDB? Collection of values for testing? Well, today is your lucky day. 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. so those are available inside of Python classes so if you wanted to pull all the values for doing active SQL injection you could do it into a variable name and then you could iterate over the top of those values so you don't have to go out to separate libraries or read in different files it started off just being an implementation of fuzz db but quickly grew into something larger so I actually took the encoder lib from Dharma encoder and included it there as well because when you're iterating through those those values you might want to add an encoding type to them or represent that data differently it also has request logic built into it and I haven't pushed the code back but so when you're doing the Cartesian product method that we talked about before it creates a dictionary well you can't pass a dictionary value for post data in URL of two so I created a web string method so you just pass the dictionary to the web string and it'll properly encode that for you. So you can do some custom range we're not going to go into the examples but there is a wiki on the Google code page so I don't know how well it'll help you so you might want to send me an email or something or just explore it you know. Sequenced operations are a particular pain when you're doing your testing because if you're if the tools you're using don't understand the sequences you know and a lot of tools are starting to support these but they're supporting them via you know the names so pretty much every single tool out there every single commercial tool uses replay so if you can't replay the data you're pretty much screwed so you might have randomized values so if you think of like laying out a web page for a bank and it might have you know home account all 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. those menu options is a randomized value that changes every single time, that's gonna throw your tools off. But when you're writing your own clients, I mean you know how to handle that. So you're becoming intimately familiar with the application. There's also things that tools take care of for you that you might not think about, such as processing headers, processing cookies, adding referrers, and there's also might be there might be content that you just can't parse. You're just gonna have to resort back to regular expressions for that stuff, and it's not fun. Then you got two problems right? Has anybody ever heard of Selenium? How many people that have heard of Selenium know that you can write these test cases in Python? You did? Awesome, so Selenium in web drive, has anybody ever heard of webdriver? Okay so those projects are emerging which is nice because it gives some advantages to doing that. Has anybody ever ever heard of Windmill? I figured about as much. It's like Selenium, but it's written in Python. So it's kind of nice. I had some frustrations with Windmill. So obviously it would be nice to do everything in Python, but the frustration just set in and I went back to Selenium. So Selenium has a couple of components. It has the server component, the remote control, and the IDE. The IDE is nice. It's a Firefox plugin. And as you're clicking through the web application, it's recording what you're doing and writing out your Python code for you. So at that point, all you have to do is take that Python code, copy and paste it into your IDE, and then start writing your test cases around it. When you fire up Selenium, it will go ahead and open the browser and start taking those actions that you programmed in. So I think it's pretty easy to see how you could sequence your options. So you can run operations that way and use the browser. The browser is going to process all the JavaScript and do all the dirty work for you. And in the end, your goal was to test for SQL injection on a form value or test for cross-site scripting or something like that. So we have a nice picture of Tom Selleck. So we have a little demo. It's behind it. Obviously, it doesn't fit on the screen. So here we have a bank, a bank website. And we want to do some testing. So we're going to open up Selenium IDE. And we're going to basically choose Python as our format. So as you can see, it already sets up and does some imports. Now, I'm clicking on different things that you can't see. So there's a sequence of operations going on. And you can see the IDE is filling out. So now we get to a login. And it really doesn't matter what we log in with, basically. So you guys came here expecting to get some Python code out of this. We're not even doing code right now. So as you can see, it basically built a case for us. So if we copy and paste that into our IDE, we can 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 off advance. Everybody wants to have some doubts in understanding how classes work. But this is what it goes like. Create a code. Okay, here you'll see that the casos that are running in the batch look like this one. Excuse me. And then we run this secretly. This map just sorts things out. So here we have data. We've got something called my disparate process and I'll see it in a second. Here's a whole bunch of doubts. So instead of having to run through all these initials. That was just Javagebra. This is what we've built into these apps and we choose to also have all I did was say get body text instead of get HTML source because it would be easier to read. So we ran a test case. We basically threw three values at it. If you look at the return from the first one, you can see there's a SQL error message. You can see the strings. The second one, as you can see, it looks like just a standard error message. Now the third one, it says I want to view my account summary. So now we know we had a valid case. So we detected the error first with the first one. And the second one, you can see we exploited the SQL injection. All in a couple lines of code. So we were able to test drive the browser, create our sequence, and then break into that sequence and do tests. That's pretty simple, right? Okay. You're supposed to say yes. All right. So one of the things that I like to use, I like to use burp when testing web apps. Besides being a great proxy, there's a lot of other stuff in burp that makes it really cool. One of the things that, like, I really like it for is I can record, like, a proxy log. Basically record into a text file all my requested responses. The thing that web scanners, you know, they're basically everyone that's building web scanner like spends too much time trying to make it better at spidering. That's too hard for me. So, like, whatever. I'll just click through the app and like every single link that I can and submit every post I could. So the thing about getting a good crawl log, you know, when you're testing, you have all this context to you. And that's one of the things that web scanners don't really provide for you when you're testing. You have no idea what a doing behind the hood. So I like to just work off that. So remote. What I did was basically I wrote this API. I call it the GDS burp API. Basically allows me to parse a burp proxy log and then every request and response basically gets bundled up into what I call a burp object. So a burp object basically looks like this. You have like the request properties, the response properties, the time, the URL, and the parameters that you sent it. Basically everything that burp recorded to the log. The thing that say like you have an index number here, like 123. Like if you look in your burp history session, like this number 123 would match up with 123 in your history. So like you could easily, like, you could easily go back and forth. But basically you have all this data now available to you in an API that you can now just like call various methods on and get data from or for build context. What am I saying? It's always nice when the presenter says what am I saying? So like, you know, I was a black cat and Ben Nagy gave a presentation on fuzzing and like he kind of made the comment that everyone writes their own fuzzing engine because everybody else's sucks. That's what I think with web scanners. Unless I wrote it or whatever, I have no idea what the web scanner is doing. I don't have time to dive into the internals of various web app scanners. The other thing is, like I said before, I don't have enough context to what a web scanner is doing at a particular time. So they don't do enough actual testing and they do too much hand holding. And that's like as testers, you know, like whatever. That's what you're supposed to be doing, right? As testers it's up to us to make sure that we properly explored every path. So when you have a vuln scanner, sometimes you don't know if it's doing all the right things. I mean, there was one particular vuln scanner who will remain nameless that was encoding all its cross-site scripting data wrong. So as it sent it off, as you know in cross-site scripting, that can be very bad. There's a bunch of vulnerabilities that never got identified until they found it. So that's one of the things that we're trying to do. So basically I have, with the API, basically it's the way I work. It makes stuff, all the context in my crawl log available to me in these Python objects. So what can we actually do with the API? Basically you can do comparisons. Like compare two proxy logs. Say you crawled an application as a user in one session and then you did it again as like an administrator. It's really useful to do a comparison of like the URLs that were requested, the parameters that were submitted. You can just do a diff and then like actually replay those request objects as say like that user level for the administrator page and easily see like what worked, what didn't. Comparing responses and content lengths of different requests. You have two users submit a request to the same page, but they have different content links. Let's like compare them, like why. Obviously searching through responses for particular keywords. And the other thing that we're trying to do is we're trying to do a lot of things in Python. So the nice thing I found is say you have like a sequenced operation like we said earlier, you have a login operation or say like some cart checkout sequence that might span like five, six, seven requests. Basically we can pull out specific objects from our list and replay them in order, out of order and just fuzz stuff along the way. So basically you're creating web scanners, the commercial vendors call macros. So I find it really useful for that. Yeah, you can also do state maintenance as well. So if you're checking for state, like let's say you're looking for, you're making a request every so often to make sure that you see the word log off on your application. If it notices that the word log off doesn't happen anymore, you can run your sequence and re-log back in and maintain state. And that's something that some web scanners have a little bit of a problem with too is falling out of state. So how do you know when the scanner is really falling out of state unless you're looking at a verbose list of messages? So replaying a request is just as simple as like say with HTTP lib 2, basically we just pass, you know, the object to and call various methods on it to get the original data from. And basically this is just replaying that verb object as it was. And one line of code, really. I know there's like three, but. Okay, that was funny. So how many people have seen this? People here familiar with diff lib in the Python standard library? Nobody. Two, four, five, three, six, seven, eight, nine. So basically, say you got like, we're adding or subtracting, say you got like two responses, we could compare those responses in like a diff style output and just easily see in the response like what was changed. Down to like, you know, like, you know, like, you know, like, you know, like, you just can see if it's like the actual characters, like per byte level with this module. So makes for a nice really visual representation of what's changed. So we've got a demo, just showing a couple things with the API. Which side do you need? That side's fine. So on the right, I just have like an open burped log. I'm just imperfecting the the GDS burp API, I'm going to import some logging and just do some logging so you actually see what's going on. Yeah, that's good. Can you guys all see that? No? Oh, damn. So basically right here I'm parsing a burp log. I'm just calling GDS.burp.parse. Basically I parsed out all the burp objects. Scroll down, dude. And here I'm just printing out the request properties with pprint. Can you move down? I'm trying to. Okay. Max. Here I'm just calling the get request headers on the second item in my list. I get all the headers that I parsed out. Here I just get a single request header, the user agent. Right now I'm going to do a fuzz. I'm going to do a fuzz. I'm going to do a fuzz. I'm going to send it through. So you can see that all the requests basically just sent it through. And each replayed request gets appended to a .replayed property. Basically a list. And then you can just call out those request properties, headers, things like that. Basically all that stuff that the original burp object had you now have in the replayed ones. So right here I'm just going to do a diff of all my replayed requests and and responses, just output it to a file. So the first one basically, you can't really see that but basically it's just showing a script alert tag in the response. Down below here I have on the right side there's a set cookie header being set in the response headers and it's also redirecting to some main bank page. So and then the fudge string that was sent was like or one equals one, basically the same fudge strings that Nathan replayed earlier with Selenium. One of the cool things basically just save state, basically I just pickle my burp log to a state file. All the replayed requests, responses, all that data is basically available to me if I choose to reload it later on. So I'm going to go ahead and show you the request. I find that really useful so I don't have to do everything between 9 and 5. I could actually do it tomorrow. So basically you got all the same stuff that you originally had when you replayed these requests. So. I know you couldn't see that but it's actually pretty cool. That's also available in the zip file. So the API is available in the zip file and all the other tools that we were talking about. We should post a link to the video so if you want to watch the video. We'll upload the videos to YouTube so you can actually, when you're thinking about it later, maybe you'll watch it. So like I said, you know, a couple of cool things is save state, load state. Parsing takes about like a minute per 100 megabyte file, which is I think relatively fast. But if you guys find a way to make it faster, that's cool. I think that's a good thing. I'd love to be faster because I'm all about performance, not security. Spoken like a true developer. Other times it's nice to have browser objects to play with. So who in here knows that you can write Firefox extensions in Python? Awesome. Nobody. Well, take my word for it and don't verify it. That's what we need to do. So you can write Firefox extensions in, in, in, in, in, in, in, in, in, in, in, in, in, in, in Python. There's actually an extension called PyXPyComXXT. And you use that and it loads up an entire Python environment. And I did this for a while. But my frustration really had me going when you can't really interface with the browser object too well using Python. Like you have to keep resorting to, you have to keep resorting to JavaScript. And JavaScript is kind of for SATIS too. So you can't really use Python. You can't really use Python. I mean, I don't like a language that just chokes and dies and never gives me any indication that it worked or didn't work. I mean, who thought that one up? But so I like to stay away from JavaScript. So recently I started switching to do more things in WebKit using some of the other GUI frameworks. So say for instance, you're doing a standalone ZulRunner object. And since we want, we're all about context when we're testing. We want to be able to make a request with like HTPLib2, modify our headers, do all this, get the response back. And then we just go through the render it in the browser object. Well, doing that in Zool Runner or Firefox is a pain. It's a nightmare. One thing that I noticed when I first started doing WebKit stuff is you could just say, you could call the object and say set HTML. So here's an example of using PyQt and just a couple lines of code and doing a test for cross-site scripting. Because cross-site scripting is one of those things that's nice to see a rendered response. Sometimes it's just easier to see that. So we have our URL, we have our request, and then we do the web object, set HTML, and then tell it to show. And on the next page, on the next page, you can see that once it renders, it's very easy to see that that was vulnerable to cross-site scripting. Obviously cross-site scripting is very browser dependent. So sometimes you'll have one in one engine and one in the other. But for very simple, universal cross-site scripting vulnerabilities, this could be very, very useful. Also, you can do other cool things like instantiate an inspector on some content. So you'd be able to open it up and have syntax highlighted, examples. In WebKit also, like PyQt, is starting to support more, have more support for plug-ins, which makes it nice when you're dealing with Silverlight. So that's all we had time for. But very simple. Couple lines of code and you've basically rendered a response with that. So, you can do that with any product, any type of content. response that you got from a different module. I think they were like hitting them with a bait and switch with a couple lines of code because everyone knows like a couple lines of code equals like several man hours. Well you already pointed out that you said here's a single line of code but it's actually three on the page. So you kind of gave it away right there. We can't count. Which is really bad when you're implementing ranges. Web services are also something else that scanners have a real problem with regardless of what vendor documentation says. Because it's really hard to tell if you're enumerating through a WSDL and you see different things that say admin obviously you might want to take a better look at that. With Python they have, so has anybody ever used SUDS before? A couple people. Three people. The best thing about SUDS is it has an object API. So everything is, you create the object and you call its methods. It's very nice. It's very, very Pythonic. It uses URLib2 for opener support. So URLib2 is an extensible library which means that you can create new protocols and handlers and install those. So as long as it's using URLib2 that means if you're handling basic auth, if you need to handle cookies, if you need to do all of that, it has support for it and it's familiar support because it's URLib2. So to just read a WSDL in a couple lines of code, actually this is two, so it really is a couple. You just basically point it to a URL and then print the client and that prints off the WSDL's methods. I guess we already have like two findings on this one page. Like we got published WSDL and basic auth in use. Yes. So yeah, there's two findings already by the time you get here. So the basic auth is supported by merely adding a username and password. And then two things that I wanted to point out is to perform functions based on the WSDL, you just basically call the method. So here's an example of doing a currency conversion. So from right here, you basically point it to the WSDL, you create the client, and you get your result and you print your result. So here's a real example of identifying SQL injection in a web service. And this is going against WebGoat's web service. So we're creating our own headers. And as you can see here, we've got a lot of code. The JSession ID is already set and the basic auth is already set. So we didn't need to use the username and password. We create a custom transport to add to our headers. So it's a little more complicated than it really needed to be just to kind of show you how it works. You create your client and then you iterate over the top of your SQL injection value. So here, I basically took PyWebFuzz and I imported the FuzzDB and then I asked for all of the generic SQL injection values and iterated over the top of them. So once you do that, there's some win because you can see the certain values that were printed off. The other values when it comes back successful, those are credit card numbers. So you know, pretty easy. Just a couple lines of code. Just a couple lines of code. You guys are all going to go back to work. You guys are all going to go back to work saying, oh, my God, you know, finding all these vulns with this is easy. So I do a lot of flex stuff. Flex basically is a framework for developers to write web applications on flash. One of the features of flex is you can encode messages in AMF action message format. Basically it's just a compact binary screen. Several tools support AMF. There's like Burp, Charles, WebScarab. Unfortunately, like the support for AMF is kind of limited. You can't really craft messages from scratch with Burp or like AMF. You can't really add properties to a request. And I just find, like, say hi to PyAMF. Basically I can work now with AMF in Python. Basically there's several AMF encoders and decoders. So you can serialize Python types to AMF. So if you have like a date time object, it gets serialized to action script date time. And then when it gets deserialized by like Blaze DS, which is the remoting server, it gets serialized to action script date time. And then when you want to use the arrived date on the server, that gets deserialized into a Java. So how many people in here have like assessed a flex app or dealt with something with the flash frontend? A few people. Yeah. Good luck with the web scanner on those. So basically with PyAMF, we can write our clients to test stuff. There's some remoting gateway support. So like for Djang. Go or Twisted, if you have a web app, you can write a web app in Python that serves up content in AMF and a flash client will be able to work with it. So I don't know how many people have heard of Dblaze, shout out to my buddy John Rose, last year he wrote this tool in Python, basically enumerated methods and services in a remoting server. But he did it by brute force, one HTTP request at a time. The cool thing about AMF, all AMF requests are packed inside an AMF envelope. So I thought like, shit, why not do this all at once? My HTTP request is like 200 bytes long, 200,000 bytes long, but I just enumerated like 10,000 methods and services all on this one server and one HTTP request, which was just awesome because it only took like a minute to respond. So that's one of the cool things you can do. When testing flash clients, you're probably going to run into cases where when you're sending a value, it's not the correct type. So you might have some custom object, like an employee object in the flash client that's being sent over the wire to the remoting server. And just passing a string or boolean that says not going to work. So when this happens, your proxy is not going to understand the structure of that object. It's going to choke when it's going to try to deserialize it. So again, with just a couple lines of code, we can now create an object factory, basically a dictionary, and register that class with an alias namespace, or a class alias. So that when pyAMF goes to 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 gets it, it deserializes it back to whatever object you're playing with. So it's pretty neat. Yeah. It's early. .NET integration, how many people here have ever used iron Python at all? So a few. Very good. So you might not be aware that you can use your Python code inside of .NET. And that provides some very useful advantages. For example, like being able to import .NET DLLs and call functions on them. You know, so it might be a silver light object or some other .NET environment. You also have integration into the .NET common language runtime. So you can import the CLR. So on the next page, you can do something like download the ZAP file, unzip it, grab the manifest, enumerate through it. And then you can import the CLR into the .NET and grab all the DLLs. So in the bottom is a simple example of importing the common language runtime, adding reference and importing all the functions out of the DLL. So pretty simple. Yeah, I know. Whatever. So basically, you know, as you're assessing web apps, you're going to come across cases where, you know, your app is actually speaking a binary protocol. I know it's not heard of before. But basically your scanner is going to choke when it's going to try hitting its binary protocol. You're probably going to choke. You're probably going to like spit your coffee, be like, damn it, why did I get stuck with this app. Now I got to like spend time reversing this thing. But whatever. Python has a module called struct. Has a module in the standard library called struct. Basically we could convert Python values into native C structures. Let's take an example, binary protocol. Basically this is kind of similar to what most binary protocols are. Basically we have like type markers before the types. Strings are encoded in UTF-8. Proceeded by after the type marker for a string, we have the length of the string encoded as like a short, a 16 byte integer. And web apps, I don't know, nobody knows what a short is. So then the value, your string. So parsing a string, basically, you know, as we run into that type marker, say 0x02, we unpack the following value into a short, which is the h format specifier. Advance our position by two bytes. And then unpack that string for the necessary length. Writing a string is basically the opposite. Write our type marker. Write the length of our string as a short. And write the string. So when you put it all together, basically, as we're iterating over every position in the stream, you know, as you run into these numbers, basically, you do the appropriate parsing of that data. So when all is said and done, you just wrote a simple state machine. Welcome back to compilers and college and oh, man. So basically, it's a wild loop. Iterates over every byte in the buffer and does the necessary action when you run into stuff. So that did not come out how I wanted it to. So that's it. You guys get the picture, hopefully. So that's the end of our talk. Hope you guys enjoyed it. If you just can't get enough of this stuff, we're actually writing a book on this topic. So if you just need to do the deep dive, it will be out in the next seven years. And like Python 3.1 will probably be used. We have like two minutes for questions. Anybody? We'll be hanging out afterwards. So next slide. 1-1-3. 1-1-3. Advance the slide. Thanks.