Good morning, DEF CON. Can you hear me? Yeah? Well, thanks for coming this morning, Sunday morning at 10. It's not too many of you, but hopefully those of you that are here are either very interested in OpenVMS or just had nothing better to do. Right, so the goal, first of all, I want to let you know that we know absolutely nothing about OpenVMS. But we do know how to break it. The goal of this talk is to prove to you that even though an operating system that has been considered very, very secure and reliable for 30 years can be broken, and actually can be broken quite easily. Some of the bugs that we found were very trivial to find, a little more, a little harder to exploit. But were quite easy to find. Anyone here an OpenVMS user? Good. Anyone from HP? No? Right, the OpenVMS user can take a short nap. The talk is broken into three parts. There will have a lightweight introduction to OpenVMS, where we'll just cover the... Some of the history. Some of the fundamentals of the operating system. History of bugs, et cetera. Then we'll have Christa and my colleague Klaus talk about the VACs and alpha architecture, and in particular how they managed to exploit that. And how they managed to write shellcode for it. The challenges that they faced and how they managed to overcome those challenges. And most importantly, And finally, the last part will show you the root prompt. So let's go right ahead. OpenVMS was developed in the late 70s by Digital, and it has some of the standard features that nowadays are considered, well, standard for an operating system, but then they were quite innovative. So all of the standards such as multi-user, multi-processing, virtual memory, real-type processing, transaction processing, those were pretty cool at the time. As far as the ownership goes, Digital developed it and owned it up until 98 when Compaq took over, and then the HP owns it today. Initially, it was called VaxVMS. Vax was the hardware that ran on, and it was developed at the same time as the operating system, probably the first time that that happened. Then the Vax name dropped, and it was just called VMS, and then later OpenVMS in the 90s when the open standards gained more and more popularity. VMS is not similar to Unix in any way. However, it does share some similarities with Windows NT, because one of the developers, Dave Cutler, who initially developed VMS, was then called at Microsoft to develop Windows NT. It runs on three hardware architectures, Vax, which is a 32-bit system, CISC, and also Alpha and Itanium. Krista and CMN will talk more about the Vax and Alpha later on. It is considered secure and reliable, even more so than OSX. So why would we want to hack OpenVMS? Well, first of all, nobody hacks it. And it's considered very secure, unbreakable. It runs critical operations in financial systems. Lots of banks and the majority of stock exchanges have some OpenVMS systems running. It runs your SCADA infrastructure systems, your railway, your electricity boards. They're all controlled by OpenVMS systems. In the UK, the NHS system uses it a lot for their back-end system. And in other areas, you can find it, such as manufacturing, Intel uses it, and education and the military also use it. It is also certified by the Department of Defense for its security. It's challenging and it's a lot of fun. If you want to try out OpenVMS, you can do that. You can get an account online with the guys at Death Row, which we've used. And it's pretty cool because they give you access to a cluster of both alpha and vac systems. And they also encourage security research so you can play around with it. And they also have a small deck net so you can play around with deck nets as well. There's also this crazy guy in Germany, which is great. He runs a vacs cluster in his basement. And he'll give you access for free. If you're particularly interested in testing out the Itanium features, then HP will give you a limited access to Itanium. So as far as getting the software goes, the best way to do that is to go through the Hobbist program, which is a cheap way of getting a license. And for, at least in the UK, for 30 bucks and a local subscription of 100. Dollars a year. You can get a valid OpenVMS license. We use emulators. There's a free version of Personal Alpha available. It has limited functionalities such as you can only use 128 megabytes of RAM, one Ethernet card, and four hard disks. But it's absolutely fine. It runs fine on my laptop. It is Windows only, so if you're looking at running it on any other platforms, it won't work. There's also Shaft. There's ARIN, which emulates VAC system. There's a demo version available. And SIM, which is, again, emulates VACs. It's free and it runs on most operating system. If you do go out and buy your own hardware, be aware that size can be pretty big, so do check with the wife. The user environment, well, it does run an X server with CD, so Unix users will be familiar with that. Although it is pretty hard to get it right. It's running on an emulator and it really isn't worth it. The DCL, which is the default shell of VMS, is what you'll be interacting with. It is case insensitive, so if you're a Unix user, that's different. And you can't run commands explicitly. You have to either use run or define a foreign command before you can run a binary. Back in 88, 89, a couple of worms propagated through DECnet. They were relatively simple. They just exploited weak passwords on finger and FTP. But they did cause a lot of havoc, bringing down thousands of VMS systems in a short period of time. As far as vulnerabilities reported in open VMS, there aren't that many. And most reported vulnerabilities are pretty old. And you can't find much information on them. Pretty much the only source where you'll find that is textfiles.com. Quick vulnerability graph. These are very rough figures. But they kind of show that open VMS was way below the average. We're looking at increasing that a little bit. So, VMS survived DEFCON 9. A bunch of guys set up these alpha clusters running VMS back in 2001. And apart from someone compromising the telnet password of the system admin logging in, no one managed to break into those systems. So, the VMS users were really proud of that. One of the great things of VMS, which can bite back though, is it's very fine grain controlled. So, you don't need the system user for everything. When is the last time that you saw a VMS exploit? Well, if you want to get an account on VMS to run our exploits that we'll show later on, you can try the usual stuff. Try some default accounts and weak passwords. The system user never locks out. The passwords are also capital by default. You can change that, but it is a pain. So, the chances are that you'll have no case. The default password hash algorithm is pretty weak as well. So, you could try to crack that. And some default accounts that you can try, a system field, operator default backup, et cetera. Some important files that you want to be looking at are the vmsimages.dat. It's a binary file, and it lists all the VMS images, programs, and their respective privileges. So, if you want to start breaking some of the software, you want to look at this file, look through it, and grip. Through the images that run with certain high privileges. We have the rightslist.dat, which again is a binary file, and it's not readable by default by a normal user. And it contains all the user list and their rights. The system user authorization file, which is like the password file in Unix, contains the users and the hashed passwords. This is a binary file, but if the administrator has converted that to a text file, it will have created a .list file in the same directory, and by default that will be readable by everyone. So, check out that file. When you log into a VMS system, it executes the login.com script. So, check that out for malicious lines of code. Or, if you have the right access then, you can run some commands in there, put some evil commands. The WASP is an open source web server for VMS. It was specifically written for VMS, and it's the default choice for running a web server. It's pretty fast and reliable. But, unfortunately, the initial release was really full of security holes, which allowed you to compromise the system fully. Loads of bugs, such as full directory traversal, completely bypassed the ACLs on the system. And, by default, it had some sample CGI scripts, which could be compromised to, again, gain access to the system. There are still all sorts of things, but not all versions out there I have found. So, if you come across a VMS system on the internet running a web server, do check out that they're running WASD. Maybe it's outdated. If you run across a website running on a VMS system, do check out the dash character for directory traversal. Use your stuff for enumerating users on the network through SMTP, Verify, eXPN, Finger, all those work. Again, you can try default accounts, or you can try some easy-to-guess accounts, such as Postmaster, Default, et cetera. Again, you can do that through the files that I've mentioned before, the rightslist.dat and sysuaf.dat. The way that OpenVMS protects the files is using three main ways. The first way is to run a web server, one of them is through the UIC, which is a user identification code that's made up of the group ID and the user pair. It isn't necessarily unique, although it is preferably unique. And group ID 1 to 10 by default belong to system users, although you can change that. There are many privileges on OpenVMS, and again, you can use those to control, access to files in a more fine manner. You can also add specific ACL files, and those will take priority over any other protection. As I said, there are really loads of privileges on OpenVMS. VMS users will tell you that for this reason, VMS is much more secure. But unfortunately, although the default usually are very restrictive, there are many of these privileges that directly enable you to get system privileges. So it is very similar to then having root directly. There's high usage of logical names in VMS systems. These are like aliases to shorten up the really long paths that they have. They have a record management service which lists all the files in a database form. It's also pretty cool that they have file versioning by default, so each new file that you create has an appendix, 1, 2, 3, etc., and can go up to thousands. This is just an example of what VMS path looks like. Files are owned by a user group. We have four permissions. We have read, write, execute, and delete, and these are applied to four groups, system, owner, group, and world. Again, we have privileges such as bypass, which will allow you to bypass all privileges, read all. Again, you can read everything, system privileges and group privileges, which again gives you complete access. We have ACLs as well for fine-grained control, which I mentioned earlier, and every file can have an optional ACL, and that takes priority over everything else. Krista is now going to talk about his research and his bugs that he found. Okay, I'm going to talk about a couple of bugs I found in the finger client, and I find it a bit interesting that 20 years after the big Internet forum exploited finger, a supposedly secure operating system like OpenVMS is still absolutely trivial to own with the finger, binary. So finger, when you finger a user, it will try to open two files for that user, the .plan file and the .project file. The problem is on OpenVMS, the finger client runs with high privileges, and it follows links, so what you can do is you can link your .plan file to a file you want to read, and then finger yourself, and finger will try to open that file for you and display the content. I don't have a demo for it, because it's such an easy bug. The next bug is a bit more interesting, because it can actually give you a root prompt. So at first I thought about trying to find a buffer overflowing finger, but I figured that they probably fixed all of them, so I checked for some former string vulnerabilities instead, and found that I could, could trigger former string vulnerabilities through the use of the .plan file and the .project file, and also through the command line. I choose to use the .plan file in my exploit. This is a screenshot of finger misbehaving a bit. What I'm doing first is I'm using the installed program to list the privileges of the finger image, and as you can see, I hope it runs with system privilege and world privilege. What I'm doing next is I'm opening my .plan file, and you can see a couple of former string characters in there, and then I finger my user, and when finger tries to process my .plan file, it triggers the former string vulnerability. So to exploit this vulnerability, you're going to need, uh, shell code, and to write a shell code, you need to know a little bit about that platform. VAG stands for Virtual Address Extension. It's a 32-bit platform. It has an executable stack, at least in OpenVMS. I don't know about other operating systems. It has four privilege modes, and OpenVMS uses all of them. It's a CISC platform. It has instructions for absolutely everything. And the platform has been discontinued, but you can still get a lot of information online, so it's not a problem finding documentation. This slide isn't very useful for use-land exploitation, but at least according to the documentation, the top two gigs of virtual memory is reserved for the kernel. Below that, you have P1 space with DCL stacks, symbol tables, et cetera. And finally, you have P0 space, where your program is loaded in for execution. The first problem I ran into trying to develop a shell code is that I'm a Unix user, and I found OpenVMS environment to be very, very hard to work in. And I didn't like the tools at all, especially the debugger. So to speed up development, I installed NetBC in my emulator and used GCC and GDB instead. My first idea for a shell code was to use libc-based shell code. And the calling standard is pretty simple. So what you do is you push all the arguments onto the stack in reverse order, and then use the call s instruction to call a function address with the number of parameters you want to pass to the function. The call instruction does a few things. It saves registers if the called function requires it. It saves the flag register and the return address on the stack. Return values are passed back in a register as well. So it's very, very simple and it works, but sometimes you don't have access to a good libc function to call. And if that happens, you have to use system services. System services are a bit like system calls in Unix. So this is a simple libc-based shell code example. I think what it does is it just calls systems and executes a program for me. Then I developed a shell code that uses system services. And again, to call a system service, you push all the arguments onto the stack in reverse order, then you call a function that executes a chmk, chme, or chms instruction with an operand. This operand is just a number that lets OpenVMS know which system service you want to call. A major drawback with this approach is that system services usually takes a lot of arguments, and they also take the arguments in the form of descriptors. So instead of passing a string, you pass a string descriptor to the system call. This is what a descriptor looks like, basically. The top one is a string descriptor. Since you have to write position-independent code, you have to update all these fields at runtime, and that leads to the shell code growing even larger. There are a few things you can do to make exploitation a bit easier. Like, for example, you can exploit symbols. Symbols are executable, and this is really important on alpha in particular, because they have a non-executable stack. There are also string descriptors, and as such, they can contain pretty much any characters, including null bytes. And that makes writing the payload much, much easier. We haven't actually found a really good way of finding the right service numbers, so the way we do it is we write a small program that calls one service, and then we set a breakpoint on the chmk, chms, and chme instructions, run it in debugger until the breakpoint hits, and then we just look at the operand for that instruction, and get the number that way. This doesn't work on the alpha platform, unfortunately, because they don't support this particular feature in their debugger. So on alpha, you pretty much have to single-step through the entire program. Interesting system services to call from your payload are system services that create processes, modify user records, or grant privileges to a process, and these are just a few examples. You can find a lot more if you read the documentation provided by HP. So here's a bit of an interesting note. When I was getting familiar with VAX, I tried to exploit a really, really simple stack overflow, and I knew I hit the return address with the address of my payload, but the program just kept crashing without even trying to execute my payload. And I discovered that it was because the flag register, which is saved below the return address on the stack, contains a byte that is defined, as MB said, it has to be zero, otherwise the program will crash when it tries to return. So I thought, well, I knew that Morris exploded a bug in the FingerD service in his internet worm, but it turns out that he didn't have to use any magic tricks or anything like that, because his bug was triggered through a call to gets, so he didn't have to worry about null bytes. So my conclusion to this is that there are probably a lot of really, really stupid bugs on this platform that are really, really hard, if not impossible to exploit, but then again, you don't have to worry too much about it because you still have a lot of special cases like gets, for example, or pointers on the stack that can overwrite and entire other bug clauses like form string vulnerabilities. So just to summarize before I show you my demo, my bug is a very, very simple form string vulnerability. I used a .plan file to hold my form string and my shell code. I used a system service to modify my user record, and this particular service will send a log message, so it's not very stealthy. My username is hard-coded into the exploit, so if you have a different username, the exploit is not going to work for you, but that's not my problem. So let me show you the exploit. Okay, so I'm logging in as my user on my box. No, it doesn't work. Oh. I don't think so. What's this? What? Okay, what we'll do is we'll carry on with CMN's talk, and then at the end we'll try and get these videos working. Yes? If you can see the screen, . . . . . . . . . . . The alpha architecture, which we also took a look at. As we all know, it's a 64-bit architecture, RISC. And you can find a lot of information about the instruction using MSDN. It's very good organized, so it's really neat. You have to keep in mind to flush the instruction cache when writing shell code for this architecture, especially when writing self-modifying code, of course. As we mentioned earlier, you can use Personal Alpha, which is a free emulator, if you want to play around with it. We did not manage to boot BSD, and we never tried Linux. But you can also build the new binutils with AlphaTarget and create your shell code in your local PC. However, as Krister mentioned, it does not work with the function pointers the way it does in Unix, because it's not a simple address that you jump to. You have to construct a function descriptor instead. And to fully understand that, you really need to take a look at the OpenVMS calling standard. The vulnerability that I found resists in the command line interface library. It's used by a lot of applications, so it's widespread and got a lot of targets. It fails to handle crafted command lines. This vulnerability has been verified on OpenVMS Alpha 8.3 in the default install. And basically, it gives you total control of the program counter. To trigger this vulnerability, you simply find a target program that uses the command line interface. And while you're at the prompt, you paste or type 511 characters. And then the up arrow key three times. And then you manually type. And then you manually type the return address. Just wait for it. Here's a screen dump of a crash in the TCP IP program. And here's a similar crash in the install program. As you can see, the return address is a bunch of Bs. And at the end of the screen dump, we get an error message saying that we don't have enough privileges to dump core for this process, which is quite interesting. Since that... Implied that we have a set of privileges that is interesting. As I said, we have multiple targets with this vulnerability. For instance, we have the install program, which has the privileges to run kernel code. We have the TCP IP program, which has the privileges to perform physical I.O. And we have the Telnet client, which gives you the operator privileges. You can use that for roll sockets and stuff like that. Yeah, now that we have control of the program counter, we obviously need some shellcode. So the C calling standard is complex, as we mentioned before. So you actually need to know pretty much about it. And there is a document that covers everything. Everything on manager. The stack is not executable, but as Christian mentioned, we could execute code in logicals. That's useful for local exploitation. When it comes to remote, we have to do other tricks. Perhaps copy the code to an executable location or similar things. And, yeah, flushing the instruction cache is important for self-modifying code. Okay, cool. I'll try that. My exploit doesn't need... I don't really need to get... To know the location of the shellcode, but that's sometimes the case. So you obviously need to get PC code running in some cases. The PC register can't be directly read. It's a bit of a fiddle to get this running. But the shellcoder's handbook has a really nice solution, which... Stores the IMB instruction with the opcode of 86 and then overwrites the branch instruction in the second loop and saves the PC register in the 16th register before the shellcode continues to execute. To do something really useful, you need to be able to call system services or as system calls in Unix. You pass the six first arguments in the A registers and then you push additional... additional arguments onto the stack. You also keep an argument counter in the 25th register and the system service index in the zero register. Keep in mind that the index vary from OpenBSD versions. You really have to make sure that you have the right index for the target that you are exploiting. And the instructions used to jump into kernel mode and run execute the system service contains null bytes, which even the IMB instruction does. It's a bit tricky to get stuff null-free. The create process system call is interesting for exploitation since it allows us to execute an arbitrary binary on the file system. And when this binary is executed, we inherit the current privileges of the process. This particular code doesn't do a clean exit, so... So... It'll actually crash when the program has been executed. So, where do we inject the shell code? We could use the command line in the overflow, but that suffers from a lot of heavy input restrictions, control codes and stuff like that in the command line interface. I also use Telnet to automate this exploitation, and you get... You get some input restrictions there as well, but you can easily overcome them with the terminal settings. What I did was that I populated a target process with data in certain areas, and then crashed it and scanned the core dump, basically, to see where the data was located. You can use the analyze program to take a look at core dumps, to eval registers, dump certain area of memories, and assemble instructions. You can also use the analyze program to get a nice list of the different memory segments in the process. This gives you hints about where you could search for the data you have injected. I first found my string or my shell code in the command line interface data segment, but I couldn't execute it there. I got an access violation, so I decided to fiddle a little with the input restrictions, and tried to make a shell code that copies the shell code to another location, and removed some input filtering in the Telnet client. I ended up with a shell code that only uses the LDA instructions, since I got an opcode that was accepted by the input filtering. However, this didn't work, since I didn't even have permissions to read at that, in the command line interface data segment. So, it didn't really help me much, but it's a nice code to use in other exploits. So, we can actually use and execute code in logicals, with nulls even, so you just have to upload your shell code into a logical, and then dump there to execute it. When analyzing when finding the address of the shell code, you can use the analyze program as well, and they use the clue process logical command to get the direct address of the shell code, but you need system for this, so if you don't have the possibilities to increase those permissions when researching, you could simply just scan the core dump as well. Yeah. So, what I did was that I wrote a proof of concept exploit that calls the creative process system service. I first uploaded the shell code using a tool that simply just adds it to logical and spawns a sub-process, and then I wrote a little program called file.exe, which simply just prints the privileges of the current process. I need to wait to see what kind of privileges you gain from the target. Unfortunately, we got some problems with the video, so... What's going on? That's fine. Yeah? Do you have... Hopefully we've got a tip. Just do that. Just do that. Yeah, I gotta tell you this, . Okay. Okay. Okay. Okay. Thank you. Any more tips? What? Yes, sir. Okay. It worked? Yeah. Okay. Thank you. Okay, so this is my proof of concept code exploit. We start by attacking the install program. So we connect to the target machine, and I first delete the privilege file that is generated by the file.exe program, and then just run it and take a look at what kind of privileges we have, and it's only the default. Then we load the shell code into the logical, spawns the subprocess for us, then we run the install program and trigger the vulnerability. Now the install program will crash when the shell code is executed, since it doesn't handle the exit after that. So now we just have to take a peek into the briefs.txt file to see what privileges the program has when it was executed. And as you can see, we got kernel privileges now, so we can actually run kernel code. And this exploit also works for a lot of other targets, as I mentioned. In this case, we are attacking the TCP IP program the same way. Okay, so... Still have the default. Default set of privileges for this user. Load the shell code, spawn a subprocess, and then the TCP IP program, trigger the vulnerability, and the program will crash. And we peek into the privilege file to see that we gained, actually, physical IO privileges, and we can see that we gained a lot of privileges. Yeah. I can show you the last one as well. It's for the Telnet program. So we run the exploit again with Telnet as target, just as we did before. Just as we did before. All right. Let's hug one another here. So, try to get created all the painful components and fruit problems. All right. Thank you. And now we got Oprah privileges as well. Okay, I think that Krister is going to show his video of his exploit as well. So, I'm logging on to my books with my normal user. And I tried to set all privileges for my process and it's not working. And I look at what privileges I do have, and I just have the default ones. So, I compile the exploit. And I link the exploit. And run it. So, at this point, the exploit has run. And I've modified my user record. So, next time I'm logging in, I'm going to have full privileges. So, let's try that. So, I'm enabling all privileges. And then I show all privileges. And you can see I've got a lot more privileges now. Actually, I've got all of them. So, I think that's it. Any questions? Okay. Okay. Okay. Thank you. . It seems like this is a privilege escalation attack. Did you find any vulnerabilities you can take advantage of without having an actual account in the first place? These are local. These are local, yes. Yeah, but . Okay. Okay. Thank you. Thank you.