Here's Jay Beale. He is with JJB Consulting. He is best known for the Bastille Linux scripts, available in all the usual mirrors. Jay is going to be talking today about hacking and securing FTP. So, take it away. Jay is also not going to be up here. He's going to be down here. That's Jay. I'm Jay. Oh, my God, that's a nice mic. Yeah. So, yeah, I'll be down here. It's slightly harder to see, but I'm trying to do a little bit of demonstration here today. So, this is the only way I see my screen. Someone say, speak up. Okay, cool. Stand. Anybody got a baseball bat? Okay. So, basically, the talk's kind of simple. There are a bunch of exploits against FTP servers, because FTP servers, especially real FTP, but most of the rest, too, have been bad. And by bad, I mean they have loved giving out root access remotely to anybody who can go and pick up scripts. So, what I want to do is... So, what I want to do is show you how to configure an FTP daemon so that it'll actually, you know, so that for most of the attacks that would have worked, the attack fails to work. This is not black magic. This is really simple hardening steps that you can take. And so, the idea is the next time that an exploit comes out, even if your version of the software is vulnerable, maybe you aren't vulnerable. Okay? Or maybe the attack doesn't get very far. And as far as I'm concerned, that's a good thing. Okay. So, the very first and the very last slide in these talks is often one encouraging you to just throw out your FTP daemon. Get rid of it. Delete it. Remove it. You know your vendor. Ask them to remove it from the CD. Well, maybe not go that far, but try to get it off... try to get off it yourself. Okay? FTP is, you know, is probably like some of the lesser drugs. It's a little, you know, it's really convenient, and it's definitely hard to get off of. I guess it's kind of like caffeine, you know? It turns out to be useful, but then you find that it was bad for you. So, you know, it's really hard to get off of. I guess it's kind of like caffeine, you know? Okay. No, caffeine's not bad. It's okay. Keep drinking. Okay. So, why is FTP bad? Because me just saying it's bad doesn't sound, you know, it doesn't sound so good. So, the first is FTP, it's clear text. If you are typing a name and password, okay, if you're typing a name and password, especially, who's hooked into the wireless right now? We don't have wireless in here, do we? Okay. Well, if we were in the wireless, if you are right now typing, you're starting to get a call, up an FTP session, even some files up or down from some account somewhere, somebody else in this room, probably about 25 somebody else's, is probably right now collecting your username and password. They'll be back on your server later tonight. Thank you very much. So as far as I'm concerned, that's enough. That's enough for me to just throw out my FTP server. The next reason, which is not on here, and we're going to spend all day, well, not all day, but the next 40 minutes talking about it, is that FTP servers continue to get rooted eight ways from Sunday. And this seems to happen on the regular in recurring business. It seems to happen no matter what FTP server you're running. And it's very fun for everyone who's using it, not very fun for all of us who are getting nailed by the attacks. Okay, why is FTP bad? Why do all these bugs show up? One of the reasons is the damn thing was designed by a committee. Okay, I don't know how big a committee it was. It was probably one of those, you know, it was probably, it was designed in RFC, so probably it ended up starting. Now it's small and getting bigger and bigger, as everyone threw in their own pet feature. Okay, anything that has everyone's own pet feature get thrown in here and there and here and there willy-nilly is generally going to end up having a good number of vulnerabilities, or at least one or two. Okay, why else is FTP bad? Okay, anybody ever notice that when you're using an FTP client, the data comes to you through a second channel, there's a second port. If you've ever, if you've ever run into our last problem, that it's hard to firewall. Okay, so if you've ever run into our last problem, that it's hard to firewall. Okay, especially when you've got a stateful firewall and you've experienced this, you know, you've authenticated. You've told the server who you are. It's sending you, you know, it's responding, everything's good. You ask it to send you a file. It goes to send you a file. Well, that second channel in FTP session isn't authenticated. Okay, which means there are some nice tools out there to help you steal other people's FTP file transfers. Okay, now, each of these could definitely be defeated if you used something like, if you used something like SSH, SFTP, there are Windows clients, there are Mac clients. There's really virtually no reason not to use it. But, you know, if you use something like this, you dodge all this. One of the issues is it's all encrypted, so they can't steal your name and password. It's all encrypted, so they can't steal your data on the way. So it's, you know, it's pretty nice. It's also pretty easy to firewall properly, so we all get to be happy. Okay, so now what I want to do is show you a bunch of vulnerabilities. I'm only going to demo one, but I want to show you a bunch of vulnerabilities and talk about how you can defeat each one of them. Okay? The first one, the first one, FTP conversion, the first one basically the way it worked was anybody ever gone into like, I don't know, Packet Storm, you know, to an FTP site like Packet Storm, and, you know, you want everything in the directory. So instead of pulling it down, you say, you know, get directory.tar and it builds you a tar ball and sends you a directory. And you get a directory.tar for the tar ball. Anybody use that? Raise your hand if you have. Okay, five, six, seven. Okay, so a few of us have used this. Eight, eight, I'm happy. Okay, so this thing is getting used. This was a nice little feature that was added into FTP service. Unfortunately, in this case, and this was room 24 through 260. So this was a while ago for Red Hat and SUSE and Immunix, but they are, who's running Red Hat before, before 6.2, 6.2 earlier right now. Oh, come on, someone is. Okay, we got one. How's your FTP server, dude? No, I'm just playing. Okay, so I want to show you how this works. I'm going to show you on the slides and then I'll actually demo it because it's a lot easier to just talk about it. Okay, the first is what we've got to do, it turns out if you tell the FTP server, if you can pass the FTP server a real weird file name, okay, if you can pass a real weird file name, you ask for that file name back, that file name ends up getting passed to tar.tar.tar. Because when your FTP server creates a tar ball for you, it actually, it's actually running the tar command. Okay, it's running tar. So it runs tar, if we can get it to run tar and pass it, you know, pass it something to, pass it a weird, you know, pass it a, just something that the original user, the original designers of the FTP program didn't think of, then we can have some fun. Okay, so the first thing you do to make this exploit work is you've got to build, you've got to build a single backdoor program or script that you can run. Okay, you've got to be, it, it, it, it, it, it, it, it, it, it, it, it, it, you can't pass it any options. Okay, you can't pass it any options, or at least I can't make it, I can't pass it any options. So I'm building a backdoor, which is just a shell script called script, and what that script's going to do is it's going to run netcat, it's going to tell it to listen on port 6666, nice and easy to remember, and to run a root shell. Well, I mean, not to run a root shell, but to run a shell. Okay, that'll be as whatever user I'm at. What I'm going to do is I need that program to be executable, and I'll talk about this later a little bit if you ask me to. I'm going to So I tar that, I tar up a copy of netcat, and that script, into a little tar ball, okay, called b.tar, and the last thing is, this is blah, is the script name we'll be seeing. I create a script called blah that says, untar my tar ball, and run the back, run my backdoor, run my backdoor script. Okay, you're going to get to see this a second time. The next thing is, I create a special file name that the FTP, that the FTP server people were not expecting me to create. Which is, minus, minus, use, minus, compress, minus, program, equals, bash, blah. The deal is, if I can pass that, if I can pass that option, if I can pass that option to, to, to tar, and what I'm doing is saying, hey, by the way, you know, I'd like to, I'd like to run tar and pull down a directory, but actually, while we're at it, you know, I'm kind of, I'm kind of chintzy about the bandwidth, why don't you, why don't you compress it? Why don't you compress it? Use this program I've got called bash, blah. You know, just use that one. Okay, and tar would be happy to do that for you, okay, because tar's not expecting that you're, you know, that you're running this remotely, okay? So tar would be happy to do that for us. And what we're going to do is we're going to FTP up to the target, as I'll show you. We're going to put our, put our, put b.tar, which is basically our backdoor. We're going to put the blah script there. We're going to put this weird file name, and then we're going to ask it, we're going to ask us to get that file name back, but with a .tar on the end. And so what'll happen is, okay, what'll happen is the server will run our little script. They'll end up running bash, blah. Okay, that'll run blah. And what blah will do, it'll run bash, blah. And then it'll run bash, blah. Not that. What blah will do, if we all remember, is it'll open up that tar ball and run our backdoor. Okay? So it's a little convoluted, but actually that's the way a lot of these exploits end up being, as some of you have probably found out on your own. Okay. So what I'll do is I've got to switch to another screen. Oh, no. Sorry. Freaking Microsoft. Okay. So I'm going to connect to the FTP server to show you how this works. Oh, or not. Okay, as soon as that, this is, we're running VMware, so it takes a couple seconds. We'll see. So jay, password, jay, right? Okay. We pick nice, strong passwords here. So put, blah, put, b.tar, put, minus, minus, use, compress, program, equals, bash, blah. It takes that. Mistake number one. It shouldn't be taking a file name that looks like that. Okay. And now let's get it with the dot tar. Oh, no. That's not good. What's that? They say fix the dashes as soon as you back the code. Oh, yeah. No, no, no. I need the double dash. Period. It's a period. You can't bash the clock. Period. Oh, come on. What's wrong with this? . Well, let's run our put. It's there. Okay, there we go. I'm sure I missed why it didn't work the first time. It's worked this time. I'm happy. Okay. What's happening now? Okay, the FTP server's not doing anything. So it's doing the transfer. It's just hanging there. Okay, why is it hanging? I didn't crash it. No, it's not that. It's the right now. It's waiting for that tar command to finish running. Because it's, you know, it's tarring up whatever directory we just asked for. So it's waiting for the tar command to finish running. That tar command, well, that tar command's waiting for the, it's waiting for Netcat to finish running. Okay, well, Netcat is, Netcat's waiting for us. Okay, so let's move that screen up. We'll Netcat 192.168.3.129.4.666. Oh. Okay, I have a, I have a specially compiled version of Netcat. Okay, so I get a blank. What is that blank? That, believe it or not, guys, is my little prompt. I promise. This is, this is the real deal. You're welcome to try this out later on. Okay, so now what I have right now is user j. Okay, this exploit gets you whatever user j is. So you're able to log in as, if you log in anonymous, you end up getting an FTP. Okay, but we got user j because it's a lot easier to show this version of the exploit. So we got user j. Well, that's kind of no fun. I mean, it is fun, but we'd like to have a little bit more. Yeah, okay. Thanks. Okay, so we've got j. We'd like to have a little bit more. I have a little bit more. I happen to know that I'm, I happen to know just from my Nmap scan or how Telnet was running on this machine, too, and the banner told me I'm actually talking to a Red Hat 6.1 box. Okay, so if I know I'm on a Red Hat 6.1 box, it turns out there's a program on the box called User Helper. And User Helper has a problem, and we've got a tool to help it, to help exploit that problem, and that tool is called User Rooter. By the way, as long as I'm at DEF CON, did anybody in this room write that tool? Okay. Well, just in case. I've had that happen a few times here. Said the person who wrote the, the person who wrote the tool is like, yeah, yeah, I wrote that one. Thanks, dude. Okay. So, the tool is called User Rooter, and it's a real, it's a real simple script. And the reason it works is there's a program called User Helper, it's like User Bin User Helper, that has a vulnerability in it. And it's a really dumb little vulnerability. I could explain it to you sometime, but not right now. Okay. But anyway, it's a dumb little vulnerability. I got a tool that exploits it, and because we can find that file, and we can run that file, the way this thing works is it runs User Helper, passes it some weird data, and User Helper goes and craps out and gives us a, gives us a root shell. And this is another one of those root shells that doesn't come with a prompt, but that's all I need. I'm happy. Okay. Just in case I'm still wondering, do whatever I want in the box. There's Jay's encrypted password. There's Root's encrypted password. If anybody's got crack, we can go and find out what those are for fun. But we're Root, so we can do all kinds of stuff on this system. But we're not going to. I know we could spend, like, the entire talk just, you know, how are we going to nail this guy, Jay, but let's leave his box alone. Please. Okay. So this is what we did. We netcatted into our target. We got a remote shell. Okay. We got a remote shell. We ran User Rooter. Okay. What I've done is I've shown you how we can add, we can add User Rooter to the tarball. When we send up the tarball, just add User Rooter to it. So we run netcat, we connect to the port, and we grab Root, which is very nice. It was very helpful. Much joy. Woo! Okay. This exploit is actually a lot harder to pull off anonymously. Okay. So I'm not going to. You're going to have to get into the server. You're going to have to get into the server. It's a pain in the butt to get from there to Root. Okay. It is tougher to pull off. Okay. And one of the big reasons it's tougher to pull off is whenever you're on a real FTP server and you connect anonymously, it sticks you in a directory. It sticks you in a cheroot prison. Okay. On Red Hat, that's home FTP. You can't get out of home FTP. Okay. Kind of. I'm lying. But the way it's designed, you can't get out of home FTP. You're stuck as a non-Rooter. It's user FTP. And there's no fun toys to use, either to hit others systems, although I guess you could bring some with you, but there's no fun toys in the system to give you more privileges. We can't get to user help. We're stuck in this prison. Okay. That sucks. We end up with user FTP or user J. What's the point of that? I mean yeah we can read J's email, it's kind of good, but we can't actually you know knock that much havoc on the box. Okay. So as defenders, one of the things we're going to talk about is how we can use these you some of that shrewding stuff to every user. Now, how can we avoid the attack entirely? Well, we can avoid the attack entirely if we tell people they're not allowed to use tar. No, you can't ask for a tar ball in the directory. And you're not allowed to use the compress feature. You're not allowed to say, give me a GZIP version of that tar ball. Now, since there's only eight people in this room, I'd say that we're kind of the more and most knowledgeable of users because we're hanging out at conferences instead of doing what other people do. You know, there may be even fewer people in the general population who are still using FTP who are going to try to use tar and GZIP or whatever anyway through the FTP server. Okay? So what we can do, one of the ways we can break this exploit is we can just make it so that you can't actually get the FTP server to run tar. Okay? And get it so you can't run tar. You can get it so you can't run GZIP. Okay? There's other things you can do. Okay? One of them is... As far as the anonymous attack, we can make sure that any time an anonymous user puts files on the server, they can't pull the mic back down. Okay? And we're going to talk about how that's, you know, how that's really useful. The biggest issue is it stops you from getting turned into a... into a RARES or DivX site. Okay? People aren't going to use your FTP server if they find it randomly to... to exchange MP3 files. Okay? You may not like that because you're probably getting some good ones. But what we can do is we can say that so someone can't download any files that they put up right afterwards. The last thing we'll do is we'll put a password in there. We'll put a password in there. We'll put a tag filter. The reason that a tag worked was there was a... there was a minus-minus use compress. Dude, people shouldn't be giving us any files that begin in minus-minus. Okay? That, you know, if they want to, they can find some other way to give us those files. But I haven't found anybody who calls all their Word documents or, you know, whatever we do, any of their C programs, minus-minus. By the way, before you think that J-Man is a... is a... is a Microsoft lover, it's... we're just using PowerPoint because it worked. Okay? Don't... don't... don't be throwing anything at me. Laughed at a DEF CON. Okay. So, anyway, what we're going to be doing is we're going to play with the FTP access file. Sounds like it's the access control for... access control configuration file for FTP. Yeah, it is. It's about the only one, too. Okay? This is about the only configuration file for FTP. I don't know if the most FTP servers even came with this originally. I... I wouldn't know. But, you know, I... I strongly doubt it. This stuff probably got added. Anyway, what I'm going to do is I'm going to show you how we're going to be changing that file. So the first thing that we can do in that file is remember that these fi... that these six... six lines, six lines, I can count, six lines are there. Okay? If they are... if they are there, then they look different. We'll just change them to this. And what this says is anyone who's using the FTP client can't ask for compression, they can't ask for tarring, they can't change the... they can't change the permission bits on a file, they can't delete any files, they can't overwrite them, and they cannot rename them. Okay? Because the... some of that renaming would be really useful to us. We could upload a file with a different name and then rename it to dash-dash. So, rename's bad. So, we're just turning that stuff on. Okay? So, we're going to... we're off. We actually got pretty far. I've also included instructions on how you can make an anonymous upload area that we're not going to let anyone write to. I'm not going to go through each of the lines here. Okay? But I... I... I'm just giving them to use to... to be useful. Okay? And in the... basically, there... there's... there's two lines that we do. What we do is we're going to... we... we create an incoming directory. Okay? In home FTP, the place that all the anonymous users get stuck in, we can create another directory called incoming. And so, you can put files in there. Files go in. They don't go back out. Okay? And put files in there. You can't pull them back down. And the idea behind that is you don't get used as a Wares trading site unless you want to. You don't get used... you don't get... and you don't... you don't end up having exploits like this work. Okay? So, what if you want to exchange files? Well, the deal is people upload them. You have somebody or some proscript, okay, that goes and moves them over. Maybe after inspecting them, maybe not your call. Okay? But at least you stop the exploits and maybe you stop people you don't want to use... want to use them. I used to say in this case, you should stop using FTP. I'm putting this up when I was leaving. And now, I'm putting this up during a call, that's not the most effective way. I'm done. So, I can't put that file in. I can't put that file in here. I can't do Okay. Okay? Or by user FTP or whatever. And then finally, any file that's put on there may be readable. It's writable by you, but you can't run it. Okay? So if you're going to upload backdoors, you're going to have to find some other way to run it. Okay? The last trick did not depend on this UMASC, but this is just a decent thing to do. Okay? So another vulnerability, this one was a denial of service vulnerability. This is quoted, the exploit's quoted directly from security focus. And what this will do is it'll slam the UFTP server down. Okay? Maybe it'll reboot the box. Okay, this works on RADAT 6.2 and SUSE 7.3. It also works on OS X 10 and 10.01. It works on Solaris 8. It works on the latest version of HPUX. Yes, there are still a lot of extremely vulnerable HPUX boxes out there. More on that later. Okay? You can stop this. The only thing we can do in terms of stopping this attack, well, the one is we can contain it. Okay? We can contain it by making sure by putting in some resource limits. So if the FTP server, in a pattern that it can't resolve, okay, then, you know, it doesn't take over the entire, it doesn't take over all the runtime on the system, which is nice. Because any of you in the era of sysadmins on a, you know, on a busy shop passes the FTP server weird command. You'd rather just have the FTP server fall down. And you can take it back, you can bring it back up in the morning. You don't want to get called in because the whole machine hung, and whatever it is that's vital on that thing, like the web server. How to avoid it is a path filter. Path filter is an actual filter on what file names are allowed to be uploaded and downloaded from the FTP server. Okay? We tell FTP to run at a high NICE level. Tell it to be very NICE to other processes. Okay? The NICE command says, don't suck up all the CPU, darn it. Okay? I gave you 10. You can put it outside. I didn't do it. We're near the airport. Okay, we're near the airport. You can also, this is on a Linux box, there's a file called limits.conf. FC security limits.conf. And what you can do in there is actually go and put some really, really fine-tuned limits on how much memory, how much CPU that this thing can use. I don't have good numbers to recommend to you. They seem to vary very much by implementation and site. And if I had good numbers that I tested for me a lot, I still don't think I'd give them to you because I might break something and you might get really mad at me. So, you can use the proc info command on a running FTP process, or any process, to kind of find out how much memory it's using and so on, and try to set good limits. And once you do, these are the kind of limits you can set in limits.conf. Okay? Basically, most of them deal with how much memory, with how much, with how much memory and what kind of memory the thing can use. Okay? Another exploit, there was an FTP, there was another, there was another globbing vulnerability. Globbing is whenever you put star in, or question mark in, and it matches. It changes different file names. It changes those stars and it expands them into a bunch of file names. It's called globbing. Okay? Globbing is something we can't turn off or I'd be telling you how to. Okay? Real FTP 261 had another, had another vulnerability in the globbing code. Okay? It was in, it was in up through 261. Red Hat 7.2, SUSE 7.3, Mandrake 8.1. There are a lot of those systems out there right now that probably, probably a good number of them are vulnerable. This slide originally said exploit is, is, is, is out, is believed to be in circulation but not publicly available. I got a really good, I got it on a, on a very trustable, on a very trustable not word yesterday that there actually is an exploit out. Does anybody have it? If anybody has that exploit, I'd really appreciate getting it. I'm serious. I'd really appreciate giving it because I could show it to other people. Or, or just see it. Or something. Okay? You can test to see whether a server is vulnerable and I, I recommend you try this with your printers or whatever if you've got, if you've got printers with FTP servers. By the way, if you've got a printer attached to your network and you've got a FTP server, you think it doesn't have an FTP server, most of the time the answer is think again. A lot of them do and they, and, and they're running old, they're running old FTP servers that have a whole bunch of vulnerabilities. If you run this, you just ls tilde, tilde left bracket, you'll see the FTP server hang. Okay? Like I said, this isn't a robbing code. We can't shut it off. The best thing you can do is since somebody needs an authenticated session to actually run that, don't let them have one. Okay? If you, if you're not using the, the anonymous mode, you're running your FTP server or if you decide as a result of this talk or others that instead of running, instead of running that part of the FTP, you're going to do it out of the web server, turn anonymous mode off and you don't get nailed by this unless someone steals an account. Now note, the way we did it was, you know, the way we did the export that I showed you was we assumed that I'd stolen Jay's account. Okay? That might have been a weak, that might have been a weak assumption, but in this room, it's probably not that weak because maybe Jay's sitting in the front row and he's, and he's FTPing away and I'm like, name and password, really good, okay, I know where to go. Okay? So, you can't necessarily stop someone from stealing an account, especially if you, especially if you're at a university. How many people in here work at universities? Okay? For those of you at universities, how many stolen accounts do you guys think you see in a month? Don't know? Okay. When I was at a university, we saw, we saw a big number. Yes, I gave this talk at Black Hat as well and the answer, the answer somebody gave me was about 20 a month. Okay? Let's just say it happens every day. It happens probably often enough for the university. It happens often enough anywhere you've got people using FTP. One of the best things you can do is try to stop those accounts from getting stolen. That one's hard. In terms of actually containing the attack, okay, this one, this one is a DOS, but actually, the other thing it can do, I don't have the exploit, but if I did, what it could do is actually run remote code as root. Okay? It can run remote code as root. That's no fun. This, this attack, just like another one, is actually able to get the FTP server, which is supposed to, which is supposed to drop down from root, to go back up. Okay? And when it goes back up, you're able to break out of it, you're also able to break out of the troop jail if you're stuck in one. Okay? The deal is, you can stop this, and I'm going to show you how to do this in a couple slides, but you can stop this kind of attack from giving somebody root by never running the FTP server as root in the first place. Okay? An FTP server is run by INETD or XINETD. Okay? That program runs as root, and it passes off, when it gets connections in on the FTP port, it starts up the FTP program. And it passes in a connection, and it runs it as whatever user it's told to run it as, which is generally root. The reason it's going to run as root is if I log in, if I log in as user J, it has to be able to switch over to user J and only let me write files and get files that J should be allowed to get. If it stayed as root, I could just like say, hey, give me the shadow password, you know? Oh, by the way, while you're at it, why don't you put up this replacement shadow file for me, you know? So, we don't want to, we don't, it doesn't run as root. It starts as root, drops down. The deal is if you're only using FTP for anonymous, I don't know how many of you are running FTP and are running it as, you know, running it to help users out, to allow ordinary users to log in and push up their files and pull their files down. But if you're not, and you're only using anonymous mode, then you can set this thing to just start as root and stay, I mean, start as user FTP and stay as FTP. Because remember, when somebody logs in anonymous, the server is switching. It's switching into user FTP and it's staying there until they disconnect. And the next person logs in, starts as root, switches to user FTP. Again, it keeps going like that. Well, you can just start it as FTP and leave it that way. Because if it does, then any attacker that would have given somebody root, that would have had the FTP server go and give them root directly by going up, by going straight up from one user up to root, that won't work. Because it can't go up to a privilege that it never had. That's just the way Unix works. Okay? So, I'll show you how to do that. I just want to show you one more vulnerability where this kind of defensive measure is useful. Okay? WooFTP had a format string vulnerability. Back when all the format string vulnerabilities came out, it had a format string vulnerability. These things are still getting discovered. I'm sure they're not all out yet. Okay? The nice thing was that you could log in as anonymous and go directly to root. Okay? You didn't have to use any privilege escalation, nothing like that. Start as anonymous, go to root. It's great. I've seen the code. I've got the code if anybody wants to look at it after the talk. It's really nice. Okay? One of the things it does is it says, hey, can you switch me back to root? I mean, we were just root. So, can't we just go back? So, you know, it switches the FTP server back to root. Breaks out of the root. Prisoner was stuck in and has your root shell. Very, very, very useful thing. Okay? The TASO's got a vulnerability from what I called 7350, root.c. Okay? And like I said, you can use this to get back to root even when you're logging in as user FTP. So, if you're logging in as user FTP through anonymous session, the nice thing about this particular thing is if it's run by the script kiddies in its default mode, when FTP server asks you for a password on anonymous mode, it says, hey, give me your email address as your password. It just gives it Mozilla at. Okay? The nice thing about Mozilla at is that's not a real email address. You know, you've all typed, you know, if you've all gone to an anonymous FTP site and it says, you know, give me, you know, you type in, it says anonymous access. Okay. Type, you know, type your email address as a password. Okay? Well, most of them, if you type in, you know, screw you, it's like, yeah, it's a password. Yeah, okay, I'll screw myself and you can have access just next time, please, be nicer. So, what we can do is we can tell it, one of the things I'll show you how to do is we can tell it no. And we accept something if it actually looks like a real FTP, a real email address. It doesn't have to be a real email address, but it has to look like one. Okay? So, if it looks like one, if we tell it, if we enforce this, this exploit breaks. Okay? It's really kind of cool. Additionally, if we start the FTP server off as user FTP, this exploit will still work, but it won't give you root. It'll give you a password. It'll give you user FTP. Okay? It'll give you user FTP, and while people have figured out easily how to get root to break out of true root presence, as user FTP, I don't know of any techniques. It doesn't mean that somebody in this room doesn't have one, so if you do, please don't throw anything at me. Okay? But it means that at least I don't know about it, and it's not widely publicized, which is great for us, because we're getting attacked by tons of people who don't have the coolest new tools. Another airplane. Okay. So, I'll show you how to do each of these. The first is, there's usually a line in most of your FTP, FTP access files that says password check, RFC822, and then it says warn, or it says trivial. No, it says warn. It says warn. Okay? Remember, it's like screw you. Yes, I will go screw myself, you know, but be nice to you next time. Don't say enforce. Okay? What enforce says is don't let someone in. Break the connection. The nice thing is that when you have a script kitty who's running Terrasource exploit, and you have a script kitty who's running Terrasource exploit, and you have a script kitty who's running Terrasource exploit, when you have a worm that's running Terrasource exploit, each of them, well, this, I don't know what, I generally think the script kitty's about as smart as worms. If you are a script kitty, don't hurt me. But, you know, I think script kitty's about as smart as worms. Each of them generally doesn't recover from the first error very well. Even if the error was, what the hell, I need a real email address. Script kitty doesn't know how the exploit works, doesn't notice that Mozilla thing, says, ah, fuck it, I'll go and try another exploit. Or, I'll go and try another server. Okay? Either way, either thing, the exploit is working. Either way, we're good. The worm just doesn't hit you. Okay? It attacked. It didn't work. That's fine. It goes on from the server it was at, attacking other people. Hey, that's, that's all right there, mate. Okay? The site exec problem was Red Hat up to 6.2, SUSE up to 7.3, HPX, hey, their most recent release, 11.11. Very new, still got an old FTP server version. Okay? Now, site exec, again, very annoyingly, can't be deactivated. I've learned it. I can't figure out how to do it. You really can't do much. There is a command that tells it how many lines of output to give you. I don't know if, I don't know if we're going to get anywhere with that. But, what you can do is, like I said, first, do that little trick we did. It's going to, it's going to halt the worms, at least. Additionally, make the FTP server run as user FTP instead of as root. Okay? If we can do that, if we can do that, we're in good shape, because the, the, the, the script kitty, heck, the, you know, the real hacker, or even the worm, they all, you know, if they can do that, we're in good shape, because the, the, the, the script kitty, heck, they're in good shape, because they're in good shape. And, so, they can get access, they get it as, they get it as user FTP, not as root. They're stuck in a little cheroot prison if they got in anonymously, they don't get very far. They can't do very much. They try uploading programs, maybe, and running their own programs, okay, but they had to have made sure to upload those programs before they broke the FTP server, because the FTP server is broken now. Okay? Or maybe it's not. Okay, so they can bring programs with them, but they're not going to get anywhere, because no local exploit's going to work, unless, you know, the one or two programs that's in, that's in the cheroot prison is actually vulnerable. You all know that. understand how this true prison idea works? Anybody confused? Okay, you're liars, but no, no, it's cool. Okay, basically there's nothing in there, there's stuff in the directory that's got like six files, whatever files the FTP server needed to run, and only one program, and that's LS. So unless there's a vulnerability in LS, and it could be, but unless there's a vulnerability in LS, you don't get anywhere. And by the way, it's a statically linked LS, so don't give me any of that dynamically linked stuff. Okay, so how do we do that? How do we run this FTP server as user FTP instead of root? Well, if you're using root FTPD, you change user from user equals root to user equals FTP. If you're using an id.conf, then you just change this little thing right here, it was root, we change it to FTP, and we're good. Okay? Any questions so far? Okay, cool. Okay, now, we said before, truiting is going to contain, truiting, the nice thing is, truiting doesn't really contain someone who can get, who can get root. Okay, but root can break out of it. What we've done is we've just, we've just basically decided, we're not going to, we're not going to trust the FTP server to actually, to actually drop privilege. We're going to force it to have less privilege in the first place. So it doesn't have to drop privilege and maybe get it back, it just starts out with nothing. Okay? There's, I think this is the last, last vulnerability I'm going to show you, and this vulnerability is basically, you ever go to an FTP site and greet you with a nice little message? It says, we have 43 users on right now, how are you doing? You know? The admin at this site is so-and-so. You might want to look in this other directory, because that's where all the, that's where all the mp3s are. Okay? If you're not using this message function, it's called message, if you're not using it, we can turn this off. The reason that the vulnerability exists is the message, the message thing is a nice feature. It's a nice little thing like, oh, hey, every time you send me this message, and this message can, this message can have little tags, like percent R, which says, whenever you see percent R, give me the client host name, because I'm too lazy to type the client host name myself. Or, you know, percent N, how many users are currently logged in. This is another feature. Okay? One of the biggest things I do when I'm trying to harden applications, when I'm trying to harden servers, is I try to turn off all the features that I'm not using. And if I can, I try to convince myself, the other users, that maybe there's some features that we don't need as much that we can turn off too. Because the big deal is, the fewer, you know, the, the, the, the, the, the, the, the fewer features that are actually activated, and most of us don't use them all, okay, the fewer features that are actually activated, the fewer attack vectors somebody has when they, when they find a vulnerability in a piece of software. Okay? The great thing here, I mean, I know you all think I'm right, but wait, I like my features. Okay? Well, the thing is that, you know, yeah, you like your features, choose which ones you like, keep those. The rest, turn them off, because maybe one of them ends up having a vulnerability, you'd rather not have the vulnerability, especially if it's a real, real, real word grab. Trust me on this. Okay? The bulk, there's a buffer that will flow in that feature. It can be exploited if somebody, if somebody can write a message file. Okay? It gives you, if you can write a message file. It's just pretty nice. Now, you can turn this off, because what you do is you just remove those two message lines. Another possibility, if you have to keep this functional, is you just make sure that every single freaking directory that can have a message file, okay, isn't writeable. Now, what else does that mean? What about the directories that don't exist? We have to make sure they can't make directories that don't have directories, because if they can make directories or upload directories, that's not so good, because then they can put their own message file in there and grab root. Okay? Well, one of the things we did with that, with that upload area, the upload instructions I gave you, it has something called no-dos in it, which says somebody who's uploading cannot create directories in the incoming area. They can't create new directories. Okay? All they can do is switch around and move among directories. And, you know, that's a, these are basically standard, you know, that kind of thing is just a standard recommendation, and it's to stop specifically things like this. People creating directories, they're going to stop, stick dot message files in. Okay? The other big way to, the other big way to stop this dot message file thing is with that path filter we were talking about, the thing that's going to, the thing that stops anybody from uploading something that begins in a dot or a dash. Okay? So, if we, if we can set a path filter, this is, this is avoidance. It's all about avoidance or containment. This is avoidance. If we can stop somebody from writing any file that begins in a period, they can't upload their own dot message file. Okay? This is, again, the path filter thing, if you look at the FTP man page, it's a standard, it's a standard recommendation. Because the idea is if somebody could FTP, if people could upload files that begin in a period, okay, if they could upload files that begin in a period, then they'd end up uploading hidden files. You wouldn't see them. Maybe they're real big. Maybe they're bad. Whatever. So, we don't want, you know, you don't want that in general. And it also helps to stop this exploit. Okay? The big message here is, okay, what I'm doing is I'm teaching you how to harden an FTP server. Not just to break the five exploits that I brought with me, but to break the five exploits that I brought with me. Not just to break the sixth one. The next one that comes out. The idea is when the next exploit comes out, and it might be out right now and most of us don't know about it. And there's one guy in the back of the room chuckling. You know, he's going to get J. Okay? The idea is to be hardened, to harden the server. Okay? So, when that guy's got his exploit, none of us know about it. The vendor sure as heck doesn't know about it. Whatever. The guy who writes FTP doesn't know about it, so then nobody's issuing a patch because nobody knows about it. The idea is we don't get hit. He tries it on us, it doesn't work because we're hardened. He tries it on other people, they get hit. They wonder, is there a new vulnerability of FTP that I don't know about? You know, and the answer is yes. So, the idea is we're trying to apply this stuff, best practices, whatever, ideas that J comes up with, ideas that somebody else came up with, to try to stop people from breaking us with vulnerabilities, either ones that we're vulnerable to now and we know about, or the ones we're vulnerable to and we don't know about yet. Y'all having fun, by the way? Okay, cool. Okay. What else can we do? We can also remove open message lines. We can also remove open message lines from the configuration file. I showed you which ones those were. Pull them the heck out. If we pull them the heck out, then somebody can't use this against us, which is really nice. Okay? It's really nice. We didn't have to do much. Just pull out those two configuration lines and all of a sudden we're not vulnerable anymore. I'm really liking that. Here's how you pull them out. There's a little grep command. It just says remove any lines that look like message. Okay? Avoidance is really good. If we're not able to avoid, we definitely want to contain. And I showed you, I talked at some length about how you want to do this. You want to just run your FTP server as user FTP. If you're only using anonymous mode, this is exactly what you want. Okay? I showed you how to do that. What else do we want to do? There's some additional stuff. Here's logging. Logging is the second most boring area of security. Okay? First most boring area of computer security is patching. Patching and logging. Patching helps you avoid this stuff. Logging helps you know when you've gotten hit by it or when you've gotten hit by it. You know, we want logging. I'm sorry we want it, but it's very useful. Logging security says logging looks like a security violation. Somebody mistypes their password, let me know about it. Because it might be somebody just carelessly missing it. But if they miss it 50 times in a row, that might be someone trying to guess a password. Okay? Log all the commands. What the hell? Let's be paranoid. Every time somebody types a command, let's log it. Disk space is cheap these days. You can cycle your logs if you're worried about it. Let's log it. Okay? What else can we do? There's an FTP users file on every system. That file says what users aren't allowed to use FTP. Okay? Normally one of the things I stand up here and say is, okay, make sure to put every single user that's like a normal, that's like a system user, not a human, into this file. I'm like, okay, don't miss any of them. Well, screws don't miss any of them. If you know the UID, if you know the user ID that the system users end at, you just say, deny UID. Don't let anyone log in. If they're between zero, that's what the lack of number means. Between zero and 499. On a Red Hat system, it's zero through 499. Okay? On a Solaris system, it's zero through 99. If you want to know on yours, you'd probably have to take a look. But yeah, so we set that. Okay? The last thing I want to, the last major thing I want to talk about is worms and auto-routers. Nice little tools that run around rooting boxes for you and just, you know, they just go and root a bunch of boxes and then tell their owner, potentially, hey, these are all the systems I got for you. What have you done for me? Okay? These give you really nice gifts. Okay, the Honey Nut project, Honey Nut project has a few fun statistics. One of them is, they took a machine, well, this isn't a statistic, it's anecdotal, right? They took a machine, installed Red Hat 6.2. They put it down, plugged it into the network. 92 seconds later, the system had been scanned, it had been compromised, and it was now working for other systems. Because a worm had come through, had gone and been scanning that portion of the IP address space, found it, exploited it, started up shop. Then it went up there and started going and scanning for more machines. 92 seconds, okay? The fastest one, the fastest time with a human was 15 minutes. So, remember, this is just like automated hackers. ScriptKitties will get you real quick. There are ScriptKitties in the room? Yeah, I know. Okay? Now, the nice thing is, about worms and ScriptKitties, is often they sacrifice, they sacrifice knowledge for intelligence for speed or for laziness or whatever. So, in the case of the worm, they generally do it for speed's sake or they do it because the person who's writing it just didn't think to write or add more. Maybe they're lazy, maybe they didn't know how. What Raman does is it goes around scanning FTP server banners for build dates. Not for version numbers, but actually for build dates. Because it knows the particular things that it's got working shell code for, so it's looking for them. The secret to this is actually we can avoid being attacked. Even when we're freaking vulnerable, we don't have to get attacked by this thing. The bitch just thinks that we don't have a real FTP server. Is that a two-minute warning or a ten-minute? Two minutes. Go fast, Jay. Okay? This tool, what it does, okay, there's also another one, auto-roo. Okay? And I don't know, anybody in the room write auto-roo? Nobody wants to raise their hand. Okay, fine. What this tool does is it scans, it scans big old networks looking for vulnerable versions. And I think that one actually looks by versions. And if your banner matches the right one, then it attacks you. Each of these two tools, this is an auto-roo. So, you fire it and it attacks you. So, you fire it and it attacks you. So, you fire this off. You give it a class B that you want to target. And it goes root. So, as many machines as account like class B, it let you know which machines you now own. Okay? Class B is like 65,536 addresses, few less usually. Okay? You might get a thousand systems, what everybody wouldn't give for a thousand systems. Okay? The nice thing is, if your banner doesn't look like wooFTP, this doesn't work. Okay. So, what do you do? Well, wooFTP will actually let you set your banner. You can say greeting tourists, which means don't give out your version number. Just give out the version number of the banner. And FTP server ready. Okay? Well, you can also give it, let it do arbitrary text. I don't know how many of you can read this, but what I did is instead of greeting text, I put greeting text, and now mine says, pro-ftpd 1.2.0.10 server. Why is this nice? If you're a worm, this doesn't match any of your patterns. It doesn't have the build date you're looking for. Okay? It doesn't have the version numbers you're looking for. It doesn't even say rule. Okay? If you're a script kitty, or maybe even a hacker, hacker, okay, what does it do? It says, I'm pro. You're like, okay, I'll get out my pro tools. This one's not a rule. This one's not a rule server. I can't use my rule exploits. I'll have to come up with my pro exploits. So you're sitting there firing your pro exploits at a rule server. It's not vulnerable. At least if it is vulnerable to the same problems, it generally the attack has to be very, very, very tied to the target. So it doesn't get anywhere. And this is like really easy. How many of you are shouting security through obscurity? Security. Okay, nobody's shouting that. But whenever I get people to shout that, my first answer is, hey, it worked. You know? It's like, okay, I'm going to do everything possible I can to protect this thing. I'm going to do everything I can to keep the sucker patched. It would be really nice if I didn't get hit with some of the exploits, because whoever it was that was going to exploit me figured I wasn't vulnerable. That'd be nice, too. Okay? By the way, you also have to, that greeting banner, you also have to change your stat banner. Okay? Stat is once you log in, you can type stat. It'll tell you what kind of server it is. So you've got to make sure to get it in both places. Okay, quick recap of all the stuff we put. This is an FTP access file. This is the one we just built with all of those little things I was showing you. I do this so you've got something to copy and take home. First couple lines were already there. Compress, charge, mod, delete, overwrite, rename. You can't do any of that stuff? Good. Okay, most of the recent FTP servers don't let you do the last four. We're going to add the first two to that, too. Okay? We created an upload area. We said you could upload stuff, but you can't pull it back down. You can't create any directories. We're going to make sure you enter a real password. That means if one of these other routers or one of these worms run around and it gives out, you know, Mozilla as a password, it's not going to work. Because it's not actually going to get to log in to the FTP server to deliver the payload. Okay, what else? Tons of logging, like we said. Finally, basically, we said non-human users can't use this. Greeting text, stat text, we're going to call ourselves a pro-FTP server, just to throw people off. Def unasked to get good permissions. Nice has been set so if this thing gets dosed, it doesn't take down the whole box. Okay? I've also included some slides. By the way, these slides are at my website. I'll put it back. I'll give you my website again. The website basically is Jay's page on bastio-linux.org. But I've given you a pattern for how you can use the guest functionality to basically make sure that every user that logs in or at least every user you define as guest is stuck in a truited directory. So if someone steals one of the accounts on your system, okay, they stole an account, great, but they can't get to root because they can't go and find the user helper program that we used in the beginning of this to actually get root from when we just stole an account. So I've given you slides on how to do this. Okay? I have two more ideas. Okay? I have two more ideas. One of the ones I heard at a party the other night. Try it out. It's really good. Turn your FTP server into a virtual server. Someone has to know the name of the server to interact with it. Okay? If we turn off normal server use and turn this into a virtual server, someone has to know the name of your FTP server just to talk to it, much less to exploit it. If they're just scanning by IP address, they won't find it. Because your FTP server only answers back when someone actually talks to it by its right name. This virtual server stuff is just like on web servers. Okay? And what I do is I show you how to do this. Okay? The other issue is you can try to get rid of root. You can go pro or open BSDs, but they've each been rooted at some point. So that only gets you so far. Okay? The big alternative is VSFTPD. It's got a much, much, much better design. Design for security from the get-go. Okay? It's not that old, and so they were able to just start it as a small thing, not a huge number of features, and it shouldn't be exploited too easily. Basically, it's real simple. Lots of small little programs. The programs that I have privilege aren't really directly interacting with you, and it's all good. Pull it down beast.org. I'd love to know how they came up with the name. The last thing is try to get away from FTP. Like I said earlier, use SFTP. Use SCP. Okay? There are, there are, this is part of SSH. There are clients for MacOS. There are clients for Windows. They're free. No excuse now. Okay? Also, use your web server to give out files to everybody and their brother. They've been a lot better in terms of security history. Okay? So now, go in peace. My talk has ended. Okay? Um, please go, and if you're running an FTP server, do this stuff. Problem I always have is I go and I give these talks. I tell people to harden systems. They go home. They don't harden them. They call me back up later and ask me if I can do forensics. Okay? Yes, I'll do forensics for you, but I'd much rather you just call me up and say, thanks a lot for that talk. We were able to do some cool stuff. Okay? That's it. I'm Jay. I'm out of here. Next show's tomorrow. We're talking about Bastille Linux. Okay? New tomorrow, I'm talking about Bastille Linux in the, uh, well, somewhere in the hotel. Do you have a card? I got cards. Anyone who wants a card, come up and get one. Yeah. I got a card. I got a card. I got a card. I got a card. I got a card. I got a card. I got a card. I got a card. I got a card. I got a card. I got a card. I got a card. I got a card. I got a card. I got a card. I got a card. Thank you. Thank you.