1 00:01:17,840 --> 00:01:19,340 Okay, I'm Jeremiah Grossman. 2 00:01:19,340 --> 00:01:20,400 This is Lex Arquette. 3 00:01:20,400 --> 00:01:22,980 We're going to be doing a talk on web application security. 4 00:01:24,280 --> 00:01:25,220 Thank you. 5 00:01:28,220 --> 00:01:30,820 This talk is going to be different from the one we did last year. 6 00:01:30,820 --> 00:01:36,200 There's going to be a lot more exploit theory and a lot more exploits and how to beat different CGI filters. 7 00:01:36,760 --> 00:01:42,480 Things that every CGI application is going to be exposed to, if not now, later. 8 00:01:42,480 --> 00:01:44,020 So, let's just start. 9 00:01:44,440 --> 00:01:45,560 A lot to cover. 10 00:01:46,380 --> 00:01:48,340 What is web application security? 11 00:01:48,640 --> 00:01:51,600 Simple enough, it's the securing of web applications. 12 00:01:52,060 --> 00:01:53,120 It's pretty simple. 13 00:01:53,380 --> 00:02:03,980 Web applications, they're used everywhere, you know, they transfer money within bank accounts, you know, message boards, web mail, I mean, you name it, there's a web application for it. 14 00:02:04,180 --> 00:02:13,560 And the security that we're going to be showing applies to them all because they're all taking user input and sit between a web server with a web interface. 15 00:02:13,580 --> 00:02:18,580 Anything that does that, anything that processes via a web server is a CGI and this is what we're going to be covering. 16 00:02:21,440 --> 00:02:38,140 The difference between software programming, at least from a security standpoint, is different from the way that before when you wrote an application, you know, on a LAN or, you know, maybe like ten years ago, the application that you write, the user base is relatively small. 17 00:02:38,140 --> 00:02:42,320 So, you didn't see as much abuse of the applications that you do now. 18 00:02:42,320 --> 00:02:57,300 Now, when a web developer or any kind of software engineer writes a program that's shipped via the web, everybody has access to it and there's going to be some people, a thousand people, they're going to have an infinite amount of time to mess it up, you know, 19 00:02:57,300 --> 00:03:00,680 throw whatever they can at it to make it screw up or do whatever they feel. 20 00:03:01,620 --> 00:03:10,900 So, some of the attacks when we're talking about web application security is browser hijacking, which means is an attacker threw a web page on the client side. 21 00:03:10,900 --> 00:03:13,780 It's important to realize what client side is when we talk about it. 22 00:03:13,900 --> 00:03:24,200 Client side is like when you're viewing a web page, somebody injects JavaScript via like a message board or something and takes control over your browser. 23 00:03:24,200 --> 00:03:29,920 Client side through like document dot location or closes your window and a million different abuses like that. 24 00:03:29,920 --> 00:03:32,780 There's also cookie theft and we'll get into cookie theft in a minute. 25 00:03:32,780 --> 00:03:45,020 There's server and client side compromise, shipping weird characters and input validation manipulation to get the server to give up more than it should or more access than it should. 26 00:03:45,260 --> 00:03:55,300 There's also denial of service where creativity within a web application exploit, you can actually render a site useless by no one is allowed to get there. 27 00:03:55,300 --> 00:03:57,780 Every time they go there, they're pushed away. 28 00:03:58,440 --> 00:04:08,300 There's also different abuse mechanisms like cheating on games or cheating on auctions or buying a laptop for $20 where you should have paid $2,000. 29 00:04:09,660 --> 00:04:12,140 And there's also user privacy invasion. 30 00:04:12,280 --> 00:04:19,600 The client side scripting applications give you tremendous amount of power and information about the user of which they execute. 31 00:04:19,760 --> 00:04:27,520 You'll get IP addresses, host names, subnets, user names, email addresses, system configurations, you name it. 32 00:04:27,520 --> 00:04:32,500 There's all kinds of data you can access with a client side script. 33 00:04:34,060 --> 00:04:36,360 So, let's get right to it. 34 00:04:36,360 --> 00:04:40,800 How to steal cookies because it seems like many people aren't too sure how it's done. 35 00:04:42,000 --> 00:04:48,420 Cookies are, the cookie security is, you know, according to the RFCs and different documentation you might read, they're restricted to domains. 36 00:04:48,420 --> 00:05:00,320 So when a cookie is set within a client, there is a domain that is attached to the cookie which the client should only send the cookie back to cookies within that domain. 37 00:05:00,420 --> 00:05:08,260 Cookies bleeding over into another domain is considered not good and that's a cookie theft and can lead to all types of user compromise. 38 00:05:09,340 --> 00:05:19,600 Basically how a cookie is stolen is by somebody injecting JavaScript or some kind of cookie thieving tool onto the domain that steals a cookie. 39 00:05:19,600 --> 00:05:27,640 So basically if you're a web administrator, you do not want to have uncontrolled web data on your domain or at least on a protected domain. 40 00:05:28,020 --> 00:05:34,460 So, I just use JavaScript, you know, you can do the same thing with VB scripts and a lot of other, you know, web application scripting languages. 41 00:05:34,800 --> 00:05:37,040 But we have the expression document.cookie. 42 00:05:37,240 --> 00:05:44,140 Basically that's just a string of the cookie data of the domain of which the script is executed on. 43 00:05:44,760 --> 00:06:02,320 Now what you can do here is with these following functions like window.open, document.image.source, you set window.open equals to attacker.com.cgi.bin pointed at your CGI and append the cookie data to it. 44 00:06:02,320 --> 00:06:10,100 What happens is the cookie data actually gets passed over a get connection or an HTTP post or get or whatever and you can actually pick it up off domain. 45 00:06:10,100 --> 00:06:16,080 So you're basically just moving strings around and using the power of HTML and JavaScript to move the cookie off the domain. 46 00:06:16,080 --> 00:06:17,480 So there's lots of ways to do it. 47 00:06:17,480 --> 00:06:23,840 You know, I've written utilities on it, but I've been hesitant to do it recently because I don't feel like a bunch of script kiddies need to be running around stealing everybody else's cookies. 48 00:06:27,950 --> 00:06:30,650 So, what are secure web programming practices? 49 00:06:30,750 --> 00:06:31,790 You'll hear this a lot. 50 00:06:31,790 --> 00:06:33,750 Do not trust client-side data. 51 00:06:33,850 --> 00:06:39,710 You'll understand more why later, but as a whole, you cannot trust anything coming from a client. 52 00:06:39,710 --> 00:06:42,650 You have to validate it, you have to sanity check it. 53 00:06:42,690 --> 00:06:44,050 You do not trust it. 54 00:06:45,730 --> 00:06:48,850 There's also hidden form elements are not hidden. 55 00:06:49,230 --> 00:06:55,430 If you put a price inside of like an online order form, they're not hidden. 56 00:06:56,270 --> 00:06:59,210 These are just common things that we see around. 57 00:06:59,350 --> 00:07:03,910 Password elements, still transferring clear text, just because you can't see it doesn't mean it's encrypted or anything. 58 00:07:04,590 --> 00:07:08,210 Use solid crypto when you're doing anything online. 59 00:07:08,650 --> 00:07:12,590 Don't use DoubleRot13, no matter how secure your friend thinks it is. 60 00:07:14,190 --> 00:07:19,530 Of course, stick to DES, triple DES, Blowfish, there's lots of good ones out there, but stick to the ones you know that have been proven. 61 00:07:20,530 --> 00:07:23,830 Avoid authentication mechanisms using JavaScript. 62 00:07:25,750 --> 00:07:34,230 Basically everything happens client-side using authentication via JavaScript, all the passwords or at least all the authentication credentials are going to be at your fingertips. 63 00:07:35,710 --> 00:07:45,710 Re-authenticate the user with a password before issuing new passwords, you know, just goes right towards like the Unix mindset, you know, they have to type in their own password before you issue new ones. 64 00:07:45,710 --> 00:07:54,250 You'd be surprised or maybe not so surprised how many sites allow you to change password just by manipulating some of the input fields to change a password once you have a stolen cookie. 65 00:07:55,270 --> 00:07:56,170 Let's see. 66 00:07:57,190 --> 00:08:01,210 Do not host uncontrolled data on a protected domain. 67 00:08:01,230 --> 00:08:06,690 I realize for some people doing this is hard, but as a general rule, try not to do this. 68 00:08:07,350 --> 00:08:17,450 Sanity check and qualify all incoming data and another great resource is the World Wide Web Security FAQ, if you haven't read it already. 69 00:08:17,870 --> 00:08:22,950 By the way, all this material will be available on whitehatsec.com probably Monday when we get home. 70 00:08:25,590 --> 00:08:28,570 These are the basic client-side scripting languages. 71 00:08:30,570 --> 00:08:31,810 There are a lot of them. 72 00:08:31,810 --> 00:08:33,470 This is not a finite list. 73 00:08:33,470 --> 00:08:34,430 There are more. 74 00:08:35,310 --> 00:08:42,290 We have DHTML, JavaScript, Java, Applets, VBScript, Flash, ActiveX, XML, and XSL. 75 00:08:42,550 --> 00:08:46,090 Getting to XML, most people are using on the backside right now. 76 00:08:46,090 --> 00:08:56,110 However, browsers are supporting it on the client side and when you get to some of the security issues about XML and XSL and Microsoft.net at the end. 77 00:08:56,250 --> 00:08:57,930 And there's also CSS. 78 00:08:58,530 --> 00:09:00,970 We have the document object model. 79 00:09:01,330 --> 00:09:11,950 Basically, this is like the object-oriented model for HTML and JavaScript to access different functions and features and information within the browser. 80 00:09:12,350 --> 00:09:23,950 Basically, with all these client-side scripting languages, all their complexities, all the different things they can do can be combined to gain increased access to the DOM, which they really shouldn't. 81 00:09:25,930 --> 00:09:32,850 Basically, you can get background colors, you can get files, and you can even execute system calls. 82 00:09:36,760 --> 00:09:43,260 Okay, if you're running a web application, or at least with some kind of complexity, you're going to be taking input from the user. 83 00:09:43,500 --> 00:09:46,160 So again, never trust client-side data. 84 00:09:46,660 --> 00:09:50,080 Escape, validate, parse, filter, and sanity check all data. 85 00:09:50,400 --> 00:09:51,540 All of it. 86 00:09:51,540 --> 00:09:55,180 Not just like the ones where they're typing in like a search field. 87 00:09:55,200 --> 00:09:56,480 Get the hidden ones. 88 00:09:56,480 --> 00:09:59,100 Everything coming over has to be checked. 89 00:10:00,840 --> 00:10:03,020 With client-side data, you can never be too paranoid. 90 00:10:03,020 --> 00:10:04,600 Let your paranoia be your guide. 91 00:10:06,220 --> 00:10:07,560 Let's see, common input. 92 00:10:07,780 --> 00:10:08,660 Mistakes. 93 00:10:10,020 --> 00:10:11,580 Sanity check all input. 94 00:10:12,940 --> 00:10:31,460 When I say sanity checking, a lot of CGI's that we find, like, for instance, the yes or no, we find that a lot of times, you know, the pull-down menu says yes or no, but we can actually add like a nothing or some other string in there to cause panic within or an error within the web application. 95 00:10:31,500 --> 00:10:39,540 So for instance, if you're using a numeric value or a yes or no, check the input for what you're expecting and ditch the rest. 96 00:10:39,540 --> 00:10:40,520 Escape it. 97 00:10:40,780 --> 00:10:45,200 Don't be just taking in whatever you want or whatever they send to you. 98 00:10:45,380 --> 00:10:47,180 Same goes for file names, paths. 99 00:10:47,260 --> 00:10:50,860 Don't parse and especially don't use what you don't know. 100 00:10:53,380 --> 00:10:55,660 Escape all input special characters. 101 00:10:58,400 --> 00:11:08,340 So it's important to understand that special characters have a lot of meanings on a lot of different operating systems where it's piping, redirecting, semi-colons, stars, file-globbing. 102 00:11:08,580 --> 00:11:15,380 Special characters can do a lot to your system so they all have to be escaped or replaced or something has to happen to them. 103 00:11:15,380 --> 00:11:18,940 Preferably, if you need to use special characters, escape them. 104 00:11:18,940 --> 00:11:20,760 If you don't, remove them. 105 00:11:21,140 --> 00:11:23,060 And null characters is very important. 106 00:11:23,060 --> 00:11:32,140 Null characters don't belong in, should not come over the wire unless there are some really weird circumstances, but they all should be ripped out completely. 107 00:11:35,290 --> 00:11:44,740 If you have need to allow HTML into your site, however it's not supposed to execute, use these little guidelines so it doesn't. 108 00:11:44,740 --> 00:11:49,720 Basically, you just want to convert the less than and greater than signs and the quotes into HTML entities. 109 00:11:49,720 --> 00:11:51,560 It's real simple, very important though. 110 00:11:51,560 --> 00:11:57,240 Everything from file not founds to search fields to search errors. 111 00:11:59,520 --> 00:12:07,520 A few other things that you got to watch out for, you know, the directory transversals, the file-globbing, appending commands. 112 00:12:07,860 --> 00:12:18,580 We find a lot of times registering for, for instance, like a mailing list or something, you type in your email address and it auto-responds, it'll just do a quick send mail, send mail to this email address. 113 00:12:18,880 --> 00:12:25,640 Well, pipe a semi-colon on and execute another command, cat direct etc password and you got it. 114 00:12:27,860 --> 00:12:36,240 Data piping, quotes are, quotes can do a lot of damage, especially when you're using fixed strings like in a sequel and things like that. 115 00:12:36,240 --> 00:12:40,680 So if you're not wanting these, you know, strip them out or escape them. 116 00:12:42,100 --> 00:12:45,100 Output filtering a lot of times is ignored. 117 00:12:46,040 --> 00:12:58,020 Output filter queries from a database, for instance, somebody might be updating their profile information and put a lot of nice, a lot of little cool HTML and stuff and they go, hey, see my profile. 118 00:12:58,020 --> 00:13:04,680 So, does a query, ships it back to the person that saw and there's XML or HTML executing on the client side. 119 00:13:04,680 --> 00:13:06,760 So you have to output filter as well as input filter. 120 00:13:08,560 --> 00:13:16,080 And if you want to take a quick note, here's some other good CGI examples that give a lot of, a lot of really good data. 121 00:13:19,250 --> 00:13:20,890 HTML is dangerous. 122 00:13:21,150 --> 00:13:27,910 You know, it's, you know, it seems light, loose, everybody uses it, but it is dangerous, especially for web applications or client side security. 123 00:13:28,750 --> 00:13:38,130 If your system, if it's web mail, message boards or whatever, if it's using HTML input from users, it's very hard to get it secure. 124 00:13:38,410 --> 00:13:42,050 Even when the proper precautions are taken, it's very hard to lock it down. 125 00:13:42,790 --> 00:13:47,530 So the best way I could suggest to lock it down is use allow permit lists. 126 00:13:47,950 --> 00:13:54,030 Know what HTML you want your users to be able to send in and only allow those. 127 00:13:54,030 --> 00:13:55,670 This goes for attributes too. 128 00:13:56,610 --> 00:13:58,390 Also, let's see. 129 00:14:00,010 --> 00:14:08,070 Yeah, limit your lists, keep them short, know what they are, and know what attributes and tags are harmful so you don't put them on your allow list. 130 00:14:08,070 --> 00:14:09,910 We'll get to the list in a second. 131 00:14:10,450 --> 00:14:11,330 Well, there it is. 132 00:14:11,330 --> 00:14:16,190 So these are the common tags that are known to be dangerous for various reasons. 133 00:14:16,190 --> 00:14:19,570 Applet, you can input Java and gain a lot of access. 134 00:14:20,010 --> 00:14:22,110 Image, inline images can grab cookies. 135 00:14:22,130 --> 00:14:24,130 Layers, you can source in other data. 136 00:14:24,290 --> 00:14:29,050 You know, object, ActiveX controls. 137 00:14:29,910 --> 00:14:32,550 Style and script are pretty self-explanatory. 138 00:14:33,030 --> 00:14:43,850 But these are basically the tags that are known to be dangerous that every system allowing HTML has danger inherent when they are allowing these tags. 139 00:14:43,990 --> 00:14:49,270 Any tags with attributes that have style, source, href, or type are also at risk. 140 00:14:49,270 --> 00:14:52,530 So you have to watch out for these attributes in any tag that allows them. 141 00:14:55,210 --> 00:14:58,050 Now we're going to get a bit into user authentication. 142 00:15:04,650 --> 00:15:10,790 Web applications a lot of times have need to authenticate the user, whether it's username and password or persistent cookies and that nature. 143 00:15:10,790 --> 00:15:15,810 So we're going to get... go into a lot of things in that nature that we see out there. 144 00:15:16,370 --> 00:15:20,330 And some guidelines to help out people so they know what to do and what not to do. 145 00:15:21,330 --> 00:15:24,530 Passwords, as a general rule, are your user's weakest link. 146 00:15:24,530 --> 00:15:27,290 Users are always picking easy passwords. 147 00:15:27,290 --> 00:15:29,370 Users are always giving up their passwords. 148 00:15:29,610 --> 00:15:32,650 So, never store passwords in plain text. 149 00:15:32,670 --> 00:15:33,870 Age all passwords. 150 00:15:33,870 --> 00:15:42,010 It's very important that passwords, at least at a given amount of time, they die or they invalidate themselves. 151 00:15:42,010 --> 00:15:43,050 Age all passwords. 152 00:15:43,050 --> 00:15:45,750 Otherwise, make sure good system maintenance. 153 00:15:45,750 --> 00:15:52,850 So you don't have a password that's on the system for about, you know, six years and you forgot about and somebody can still log in or steal it. 154 00:15:53,090 --> 00:15:55,090 Age them and deny them. 155 00:15:55,330 --> 00:15:58,610 Password restrictions, we'll get to that next. 156 00:15:59,210 --> 00:16:00,530 General guidelines. 157 00:16:00,730 --> 00:16:04,090 Passwords should be, at least in my opinion, should be six letters in length. 158 00:16:04,090 --> 00:16:05,870 Six letters in length. 159 00:16:05,870 --> 00:16:07,570 Not matching the username. 160 00:16:08,070 --> 00:16:11,950 And not a common password and contains one capital letter. 161 00:16:11,950 --> 00:16:16,210 It's a very simple password, but however, it gets a decent amount of security. 162 00:16:16,410 --> 00:16:24,170 Now, a lot of usability experts and security people have different mindsets on it as far as usability versus security. 163 00:16:24,710 --> 00:16:31,070 This should, for the most part, secure your passwords to at least a minimum level. 164 00:16:31,170 --> 00:16:33,330 You know, it's better than password being password. 165 00:16:33,910 --> 00:16:37,790 If they have to have password as their password, make it a capital P with a 1 at the end. 166 00:16:40,050 --> 00:16:41,910 Passwords should be six letters in length. 167 00:16:42,310 --> 00:16:47,610 For an increased security, passwords should be six letters in length, not matching the username or part of it. 168 00:16:47,610 --> 00:16:50,910 Not a common password and must contain one capital and one special character. 169 00:16:51,110 --> 00:16:52,230 This is pretty good. 170 00:16:52,230 --> 00:16:55,970 This would be pretty hard to crack, at least on a brute force level on a web basis. 171 00:16:56,830 --> 00:16:58,850 Again, let your paranoia be your guide. 172 00:17:00,070 --> 00:17:01,050 What not to do. 173 00:17:01,050 --> 00:17:02,830 Now, we see this out there a lot. 174 00:17:03,490 --> 00:17:05,590 Placing a maximum password length. 175 00:17:05,770 --> 00:17:07,130 Okay, don't do that. 176 00:17:07,610 --> 00:17:11,810 I've seen places where they're allowing like, you know, no passwords over 4 or 5 characters. 177 00:17:11,810 --> 00:17:13,330 Now, how long does that take to crack? 178 00:17:15,590 --> 00:17:18,010 Passwords that are allowed to be changed into the old ones. 179 00:17:18,010 --> 00:17:19,650 So, let's say you're doing aging. 180 00:17:19,750 --> 00:17:23,110 Don't let your users change their password into the current password. 181 00:17:23,110 --> 00:17:24,050 Check for that. 182 00:17:27,960 --> 00:17:34,620 A lot of sites we've seen, well, maybe not a lot, but it does happen, echo the new password that they typed in over a non-SSL link. 183 00:17:34,620 --> 00:17:35,920 No need for sniffer bait. 184 00:17:37,360 --> 00:17:38,780 Password restrictions are too high. 185 00:17:38,780 --> 00:17:40,980 This is kind of like a sticky point. 186 00:17:40,980 --> 00:17:44,980 You can make your password restrictions pretty high for, you know, most competent users. 187 00:17:44,980 --> 00:17:48,420 But if you make them like too high, like, you know, really, really high. 188 00:17:54,550 --> 00:17:55,010 Both. 189 00:17:55,010 --> 00:17:55,830 These are like general guides. 190 00:17:55,830 --> 00:17:58,430 You can actually adapt these to a lot of secure programming. 191 00:17:59,670 --> 00:18:01,750 Making password restrictions too high. 192 00:18:03,930 --> 00:18:05,790 What happens if you make a password too high? 193 00:18:05,790 --> 00:18:08,730 You know, they're typing upper and lower case and numbers and symbols and stuff. 194 00:18:09,210 --> 00:18:15,230 Users are, at least on like a web sense when you're dealing with like a, you know, 50 million users or 30 million users or what have you. 195 00:18:15,450 --> 00:18:18,910 They're going to write down their password and stick it on a sticky note and put it on their monitor. 196 00:18:19,190 --> 00:18:21,930 So, you know, so you have to walk that line. 197 00:18:21,930 --> 00:18:26,510 You want to make it secure, yes, but not too secure where they're tempted to do stupid things. 198 00:18:29,110 --> 00:18:30,350 Okay, brute force attacks. 199 00:18:30,350 --> 00:18:32,590 We're going to go real quick over this because this is Uber Hacker. 200 00:18:32,590 --> 00:18:34,030 You guys should be all aware of this stuff. 201 00:18:35,730 --> 00:18:42,710 Brute force in a web account, web accounts, there's two main attacks, at least from like a web sense, for instance, like, you know, banking and stuff like that. 202 00:18:42,710 --> 00:18:49,890 One user name against many passwords or less common but very effective, one password against many usernames. 203 00:18:49,890 --> 00:18:58,470 So some systems, if they don't have password restrictions, pick the password password and level it against 1,000 user accounts and you're probably going to crack a couple. 204 00:18:59,390 --> 00:19:03,390 Each attack can be very effective and both must be defended against. 205 00:19:03,970 --> 00:19:08,230 We're going to state some defense mechanisms against it. 206 00:19:08,830 --> 00:19:11,830 So how do you defend your web apps against brute force? 207 00:19:12,110 --> 00:19:23,710 Set an acceptable threshold of the amount of failed attempts a single account can receive before that offender is blocked at an IP level, because you don't want to keep doing it, and the account itself is locked. 208 00:19:24,090 --> 00:19:27,330 Same thing goes for multiple accounts from the same IP. 209 00:19:27,630 --> 00:19:32,830 Okay, when an IP set, you know, goes over like 10 failed attempts, you have to block them. 210 00:19:32,990 --> 00:19:38,010 Okay, so for instance, like on the reverse brute force, a single account isn't going to get like 10 attempts. 211 00:19:38,690 --> 00:19:43,410 10 attempts, however, you still want to block the IP. 212 00:19:43,450 --> 00:19:47,550 Now a lot of people are thinking like, you know, wait a minute, there's like DOS attacks regarding this, right? 213 00:19:47,550 --> 00:19:56,750 Like, for instance, if, you know, somebody's, two people are competing at an auction, you know, and I want to win, so I'm going to lock my opponent's account so he can't make a bid. 214 00:19:56,770 --> 00:19:59,070 So where to get to the point? 215 00:20:00,230 --> 00:20:01,190 Did you guys get that? 216 00:20:01,190 --> 00:20:02,370 I'll say that one more time. 217 00:20:02,370 --> 00:20:15,370 So let's say I'm, you know, I like this Dell laptop and I want to get another, so I log on to my favorite auction, and there's a bid war, you know, going up and up and up and up, and I'm sick of having to, you know, bid-bask my opponent. 218 00:20:15,370 --> 00:20:24,170 So what I do is, I sent, I knowingly send 10 failed attempts against his account, and now he can't bid, and I win. 219 00:20:24,170 --> 00:20:31,190 So, however, like, one second, yes please. 220 00:20:35,030 --> 00:20:37,750 He asked about proxied users, we'll get to that in a second. 221 00:20:39,090 --> 00:20:39,650 Okay. 222 00:20:41,390 --> 00:20:45,750 So, now, there's DOS attacks against these systems, as I just said. 223 00:20:45,950 --> 00:20:53,350 Basically if an attacker wanted to DOS an account, he could, because he doesn't really care about cracking the account, he just wants to block the user, many abuses in this regard. 224 00:20:53,830 --> 00:21:02,250 Now, also as a result from IP blocking, AOL and proxied users are blocked also, because they're amassed behind like a single subnet. 225 00:21:02,850 --> 00:21:03,890 Know your users. 226 00:21:03,890 --> 00:21:10,710 If you're in a restricted environment, you can IP block without restriction. 227 00:21:10,710 --> 00:21:20,010 However, if you're, like, servicing the entire web, you're going to have to make allowances for proxy users and AOL users, so, you know, basically, you can't block AOL. 228 00:21:20,010 --> 00:21:23,650 So, basically, you just have to set the rules, then, that you can't block AOL. 229 00:21:25,590 --> 00:21:26,390 Bummer! 230 00:21:28,910 --> 00:21:30,190 Possible solutions. 231 00:21:30,530 --> 00:21:33,610 When blocking an account, log the offending IP with the account block. 232 00:21:33,710 --> 00:21:47,630 Now, what happens is, if the legitimate user logs on to the account, and the system is going, okay, this account's blocked, but I want to take, I want to do a comparison against the new requesting IP and the one that was the original offending one. 233 00:21:47,630 --> 00:21:51,830 If they don't match, and if they get the password right, let's say in, like, three attempts, you can allow them. 234 00:21:52,090 --> 00:21:54,790 However, if they get it wrong over three attempts, then you can block them, too. 235 00:21:54,810 --> 00:22:02,110 So, basically, these are some of the solutions against the DOS attacks, against these types of anti-brute force mechanisms. 236 00:22:04,250 --> 00:22:06,210 Okay, we're going to get to cookie authentication. 237 00:22:11,630 --> 00:22:20,270 Cookies, everyone knows, this is UberEcker again, that cookies are used a lot of times for authentication, you know, maybe not htaccess or something like that, but cookies are used for authentication. 238 00:22:21,330 --> 00:22:32,150 Now, we're not going to get into all the different kind of ways people are doing the authentication, but we're going to show you some of the basic steps on how to increase the security of your cookie authentication that you're already using. 239 00:22:33,670 --> 00:22:39,150 Use SSL for, these are very simple, use SSL for username and passwords, again, no need for sniffer bait. 240 00:22:39,430 --> 00:22:42,550 Don't store plain text passwords or weakly encrypted passwords in a cookie. 241 00:22:42,570 --> 00:22:46,350 Again, don't use ROT13 for passwords in cookies, that's very bad. 242 00:22:47,330 --> 00:22:49,070 Cookies are going to get stolen. 243 00:22:49,330 --> 00:22:55,390 Now, there are just far too many ways this is going to happen, so you have to remember this, cookies are going to get stolen, okay? 244 00:22:55,510 --> 00:23:01,210 You know, there's plenty of IE bugs, there's plenty of cross-scripting exploits, cookies are going to get stolen. 245 00:23:01,810 --> 00:23:04,690 It's too bad, it's sad, but it's going to happen. 246 00:23:05,270 --> 00:23:08,190 Now, if a cookie is compromised, two things should not happen. 247 00:23:08,510 --> 00:23:13,410 The cookie should not be able to be reused or reused easily by another person on another computer. 248 00:23:13,890 --> 00:23:20,130 The password should not, information from the password should not be extracted that's confidential, okay? 249 00:23:20,130 --> 00:23:21,470 That's two very important things. 250 00:23:21,470 --> 00:23:25,710 If a cookie is to be compromised, those two things should not happen. 251 00:23:26,030 --> 00:23:27,550 Also, cookie timeout. 252 00:23:27,550 --> 00:23:29,850 Cookies should not be valid for an extended period of time. 253 00:23:29,850 --> 00:23:36,230 You know, time them out after every 24 hours, no sense putting a validated cookie out there that's infinitely usable. 254 00:23:37,530 --> 00:23:39,530 Now, how do you increase cookie security? 255 00:23:41,510 --> 00:23:44,190 Tie cookie authentication credentials to an IP address. 256 00:23:44,490 --> 00:23:51,530 However, again, this is going to, you know, this is going to be tricky for a lot of the AOL users and a lot of the SSL users. 257 00:23:52,410 --> 00:24:00,870 However, if you're on a small business internet, maybe, you know, a few hundred people, you can tie the cookie to an IP address or the authentication credential to an IP address without worry. 258 00:24:00,870 --> 00:24:02,410 You have to know your users. 259 00:24:03,490 --> 00:24:09,690 If you're servicing the entire web, use a portion of the IP address, it's better than nothing, okay? 260 00:24:10,870 --> 00:24:15,290 Now, this is an experimental security practice we've been working on, we've seen other people try to work on it. 261 00:24:15,290 --> 00:24:17,550 They've had mixed results, so your mileage may vary. 262 00:24:17,870 --> 00:24:24,270 You can actually add salt to your cookie authentication credentials by hashing in, like, an IE or a Netscape user agent. 263 00:24:24,270 --> 00:24:25,550 It gives you a lot of salt. 264 00:24:25,550 --> 00:24:29,410 It gives you, like, system type, it gives you browser version, things of that nature. 265 00:24:29,410 --> 00:24:37,090 So if you're tying it to an IP address, the user agent, a stolen cookie moved is going to have a lot harder time being used by another person. 266 00:24:37,830 --> 00:24:39,370 It's the basic trick. 267 00:24:41,110 --> 00:24:43,410 It's not limited to user agent and accept language. 268 00:24:43,410 --> 00:24:46,290 Any header that stays constant within a browser can be used. 269 00:24:46,290 --> 00:24:50,670 So, again, you have to know your users, you know, sniff the wire, look at your logs, and see what's going on. 270 00:24:53,940 --> 00:24:55,800 Further authentication credentials. 271 00:24:56,960 --> 00:24:57,540 Yes. 272 00:24:58,980 --> 00:25:00,220 Oh, sure. 273 00:25:04,820 --> 00:25:05,820 Yes, it is. 274 00:25:10,300 --> 00:25:13,520 He said, basically, user agent and accept language is spoofable. 275 00:25:13,520 --> 00:25:14,100 Yes, it is. 276 00:25:14,100 --> 00:25:26,800 However, if the user, let's say a legitimate user is logged in, okay, the user agent and the accept language came over from the user, it's hashed up, MD5, SHA1, whatever you want, with their password, wherever you want to do it. 277 00:25:27,040 --> 00:25:36,200 If somebody were to compromise that cookie, they have no idea what that other user had or submitted to begin with and they're not going to be able to reverse it if you use strong crypto mechanisms. 278 00:25:56,900 --> 00:26:02,160 The question was, if he logs in from home and you log in from work, there might be conflict? 279 00:26:04,100 --> 00:26:04,860 Sure. 280 00:26:08,040 --> 00:26:10,300 Oh, you're going to have to have logout mechanisms for that. 281 00:26:10,300 --> 00:26:12,460 If you stay logged in, you're going to have trouble. 282 00:26:12,460 --> 00:26:14,260 You should provide logout mechanisms. 283 00:26:17,720 --> 00:26:19,940 Like I said, the session should not last forever. 284 00:26:19,940 --> 00:26:21,020 There should be timeout. 285 00:26:21,320 --> 00:26:23,940 He asked about, you know, what if he upgrades his browser? 286 00:26:23,940 --> 00:26:26,440 Well, the session cookie should not last forever. 287 00:26:28,820 --> 00:26:31,540 Right, so, I'm sorry, I missed that one. 288 00:26:32,760 --> 00:26:33,480 Yes, please. 289 00:26:40,670 --> 00:26:46,250 Right, basically he said, if they can get the cookie, why can't they get the user agent? 290 00:26:46,410 --> 00:26:51,610 Basically because, you can in JavaScript, but it's not foolproof. 291 00:26:51,610 --> 00:26:52,470 You know, let me just state that. 292 00:26:52,470 --> 00:26:53,330 This is not foolproof. 293 00:26:53,330 --> 00:26:54,230 It's just increased. 294 00:26:54,230 --> 00:26:58,430 The level of skill of the attacker is going to be a lot greater than your average person. 295 00:26:59,430 --> 00:27:00,250 Yes, please. 296 00:27:06,930 --> 00:27:08,730 Could you stand up, please? 297 00:27:12,800 --> 00:27:14,300 I'm like a MAC address. 298 00:27:18,620 --> 00:27:21,360 All right, you could do that, but then, you know, you have key sharing. 299 00:27:21,560 --> 00:27:29,620 He basically said , yeah, you can solve it on the server side, but again, we're not going to get to that level yet . 300 00:27:29,720 --> 00:27:38,360 But again, this is not foolproof, but however, it is a lot better than a lot of things where you can move a cookie from one computer over to another and clone that user. 301 00:27:38,360 --> 00:27:44,420 I mean, imagine you can pop into any, you know, financial transaction, steal a cookie, and then you're them. 302 00:27:44,620 --> 00:27:49,560 So basically, if you're just hashing in a little bit more data, it's going to be that much harder for a person doing it. 303 00:27:51,380 --> 00:27:55,660 This is a new paper that came up from some people at MIT. 304 00:27:56,160 --> 00:28:01,740 It gives a lot of... it's one main reason why we didn't go over different cookie authentication mechanisms. 305 00:28:01,800 --> 00:28:08,320 They did an excellent job and pointed out some very good mechanisms that a lot of major sites are using. 306 00:28:08,320 --> 00:28:10,880 So if you have need, go check it out. 307 00:28:13,220 --> 00:28:14,920 Session tickets and passwording. 308 00:28:16,480 --> 00:28:22,540 A lot of times, when you're getting data from a web form or something from a user, you want to make sure it's not tampered with. 309 00:28:22,540 --> 00:28:27,540 You know, you can use SSL for that and has not been sent fraudulently on the behalf of a user. 310 00:28:27,540 --> 00:28:32,760 For instance, like a CGI action to delete a database or something. 311 00:28:32,760 --> 00:28:37,080 You want to make sure that the user sending that actually did that purposely. 312 00:28:37,840 --> 00:28:39,180 So how do you do that? 313 00:28:39,520 --> 00:28:45,880 Well, if the CGI is performing a particular critical action, have them reconfirm their password. 314 00:28:45,880 --> 00:28:47,120 It's a real simple step. 315 00:28:47,180 --> 00:28:49,100 It buys you a lot of security. 316 00:28:49,760 --> 00:28:50,960 Have a yes or no button. 317 00:28:50,960 --> 00:28:52,140 Very simple again. 318 00:28:52,320 --> 00:28:55,200 Yes, I did want to delete my entire domain off this web server. 319 00:28:55,260 --> 00:28:59,620 Instead of, like, just basically sending a get request, they have to say yes or no. 320 00:28:59,780 --> 00:29:01,060 Very simple stuff. 321 00:29:01,260 --> 00:29:03,480 Entirely underused out there. 322 00:29:05,440 --> 00:29:07,320 I can't stress the importance enough of this. 323 00:29:07,320 --> 00:29:21,340 Basically, if you know a user is logged into, like, you know, any kind of service, any kind of message board, you send it to a chat room or a message board administrator, you send them a personal message or some kind of message and they read it, guess what? 324 00:29:21,360 --> 00:29:23,940 You can perform any action as them, at least for the moment. 325 00:29:24,140 --> 00:29:28,260 So basically, if it's a critical action, say yes or no or a new password. 326 00:29:29,780 --> 00:29:30,620 Referrer checking. 327 00:29:30,620 --> 00:29:32,120 This is something I don't recommend. 328 00:29:32,120 --> 00:29:33,500 This is entirely spoofable. 329 00:29:33,500 --> 00:29:37,100 However, if you know your users, this can be done. 330 00:29:37,100 --> 00:29:40,520 Like, for instance, on a business internet, we're just going to kind of gloss over this. 331 00:29:40,520 --> 00:29:44,580 But as far as referrers are concerned, don't trust client-side data. 332 00:29:44,840 --> 00:29:46,080 Okay, that's very important. 333 00:29:47,540 --> 00:29:48,800 Get versus post. 334 00:29:49,060 --> 00:29:54,160 A lot of times the same results can be had from a CGI by using gets and posts. 335 00:29:54,160 --> 00:30:01,880 If a form is, if the legitimate form is supposed to be being sent as a post request, accept only post requests. 336 00:30:01,980 --> 00:30:12,460 This stops a lot of automated scripting because basically because if you send like a cross-scripting exploit to someone, it's, and it sends like a get request, it's going to, it sends a get request and not a post. 337 00:30:12,460 --> 00:30:16,380 So that way it buys you a little bit more security by checking the request method. 338 00:30:18,280 --> 00:30:20,700 Off-domain hosting of user data. 339 00:30:21,100 --> 00:30:25,980 If you can't control or if you don't want to control user data, host it on a different domain. 340 00:30:26,060 --> 00:30:31,140 Basically if you're using, if you're hosting on like acme.com, host user data on acme.net. 341 00:30:31,140 --> 00:30:34,160 It might be a little painful, however, it does buy you a lot of security. 342 00:30:35,680 --> 00:30:41,120 Now, the parts that I find most interesting and most fun to screw around with. 343 00:30:41,120 --> 00:30:41,980 Filter bypassing. 344 00:30:41,980 --> 00:30:43,540 JavaScript is a cockroach. 345 00:30:43,540 --> 00:30:44,820 It's hard to stamp out. 346 00:30:46,120 --> 00:30:52,580 There are all kinds of, you know, input filters in web applications that try to prevent HTML and JavaScript from entering into a system. 347 00:30:52,580 --> 00:30:57,980 So this next section is basically how do you audit, how do you beat HTML filters. 348 00:30:58,020 --> 00:30:59,320 A lot of data inside. 349 00:30:59,320 --> 00:31:01,120 Again, you don't have to scribble it all down. 350 00:31:01,120 --> 00:31:02,380 It'll be available later. 351 00:31:03,460 --> 00:31:11,240 So basically what these exploits or methods show is how to do, you know, cross-scripting exploits, browser hijacking. 352 00:31:11,240 --> 00:31:14,380 We've already kind of glossed over how you can do some of those attacks. 353 00:31:14,380 --> 00:31:15,960 These are how to execute them. 354 00:31:17,420 --> 00:31:21,120 Testing the filters, first of all, we're going to start real simple and work our way up pretty fast. 355 00:31:21,480 --> 00:31:30,600 If you're auditing your own application, send as much HTML to it as you can, every single tag in the arsenal, with every attribute you can find, and view the output and see what changed. 356 00:31:30,780 --> 00:31:33,360 Okay, it goes a long way towards auditing. 357 00:31:35,780 --> 00:31:39,280 The script tag, you know, still very simple. 358 00:31:39,280 --> 00:31:42,800 Script tag, you can enter any JavaScript expression, including document.cookie. 359 00:31:43,040 --> 00:31:44,080 This is important here. 360 00:31:44,080 --> 00:31:48,700 Anytime you can get like an alert to show up in an environment, basically that's cause for alarm. 361 00:31:51,370 --> 00:31:53,190 Sourcing JavaScript protocol. 362 00:31:53,330 --> 00:32:02,750 Basically, in Netscape, I don't think it works in IE, I have to double check, the JavaScript protocol, and after the colon, you can execute any expression that you want. 363 00:32:03,110 --> 00:32:04,730 The image that's source equals. 364 00:32:04,790 --> 00:32:09,010 Any tag that you can source has that problem. 365 00:32:09,010 --> 00:32:15,610 So you're going to have to substitute the JavaScript string inside a source attribute. 366 00:32:15,690 --> 00:32:17,170 You know, just change it a little bit. 367 00:32:17,170 --> 00:32:23,990 You can use the underscore, or you can erase a letter, or put a hyphen in it, whatever you want, but you have to do something with it. 368 00:32:24,170 --> 00:32:32,690 So, again, any tag that has a source attribute, you're going to have to put your pattern matching in and search for all the source attributes for this type of thing. 369 00:32:33,230 --> 00:32:40,390 Even worse, LiveScript and Mocha achieved the same results in Netscape, old Netscape codename throwback that still works to execute JavaScript. 370 00:32:40,650 --> 00:32:51,870 What you're going to find in this, HTML is so loose that you can actually just totally manipulate and warp everything, and things still execute, which is one of the good things about XML that it'll help out with. 371 00:32:52,670 --> 00:32:54,530 Another one, the line breaks. 372 00:32:54,530 --> 00:32:56,290 Same thing, JavaScript and alert. 373 00:32:56,290 --> 00:32:58,850 Line break it, and it'll probably beat the pattern match. 374 00:32:59,970 --> 00:33:06,570 Basically, if you visualize the regular expression, it's going to be trying to match JavaScript as a string inside a source. 375 00:33:06,790 --> 00:33:12,050 However, if there's a carriage return in it, it's not going to match, and it's just going to blow up, and that will still execute. 376 00:33:12,750 --> 00:33:17,870 Oh, tabs, new lines, carriage returns in all whitespace count for this type of thing. 377 00:33:18,750 --> 00:33:27,350 HTML entities, kind of a derivative of the previous one, using HTML entities to put whitespace into the strings. 378 00:33:27,690 --> 00:33:35,950 This works, as well as the decimal, the hex, and multiple zeros in front will all execute JavaScript expressions inside any source attribute. 379 00:33:38,600 --> 00:33:40,300 I call this and curly. 380 00:33:40,560 --> 00:33:41,800 I don't know where this came from. 381 00:33:41,800 --> 00:33:42,820 I kind of saw it online. 382 00:33:42,820 --> 00:33:44,620 I was kind of screwing around with it, but the syntax is very...