1 00:00:00,000 --> 00:00:06,000 >> All right. Mainframes, anybody? Yeah, four people! All right. Quickly show of hands and 2 00:00:09,250 --> 00:00:13,667 keep your hands up, how many people in the room do any kind of mainframe pen testing, 3 00:00:13,667 --> 00:00:21,250 auditing, any kind of that work at all? Hands up. 9, seven people. Keep your hands up, way, 4 00:00:21,250 --> 00:00:27,875 way, up. Now, yeah, yeah. No, no, how many of you have an account, ever had an account on 5 00:00:27,875 --> 00:00:33,875 a mainframe? Ever! Whoa, whoa! None of you guys do any security work. All their hands went down, 6 00:00:39,042 --> 00:00:46,250 little bit of disconnect but anyways... I got to put this slide up, disclaimer, I'm here 7 00:00:46,250 --> 00:00:52,250 of my personal volition, I'm not here in the name of or on behalf of my employer and any views 8 00:00:54,417 --> 00:01:00,042 expressed in my talk are those, not those of my employer. We're good. I'm sure a couple of you 9 00:01:00,042 --> 00:01:05,958 guys were expecting a awesome mainframe talk with a flaming skull or super awesome wizard 10 00:01:05,958 --> 00:01:11,958 with an IBM glove. But that's not me. I have a tiny beard, way too small to be a mainframe guy 11 00:01:14,208 --> 00:01:20,875 so I'm told but I'm just a regular security guy. I have always been into mainframes, I 12 00:01:20,875 --> 00:01:27,167 was auditing mainframes and just always been into the security of the mainframe and I never, ever 13 00:01:27,167 --> 00:01:32,583 touched one. I never got access to one. Until one year we have a contractor come in from an 14 00:01:32,583 --> 00:01:38,583 unnamed company and he comes in, and he's a PCI certifier, a mainframe security guru, he can 15 00:01:41,292 --> 00:01:47,292 do ISO 27002, 30 plus years experience on the mainframe. Super awesome guy. Wasn't too 16 00:01:49,458 --> 00:01:54,167 savvy on network controls and all that other stuff. He didn't know how to tell what ports were 17 00:01:54,167 --> 00:02:01,042 open on the mainframe. It has the net set command you'll see in a few minutes. So I realized 18 00:02:01,042 --> 00:02:05,208 like I have all this security background and mainframe background and finally got 19 00:02:05,208 --> 00:02:10,708 access to a mainframe and I was like, you would not believe some crazy stuff going on here that 20 00:02:10,708 --> 00:02:17,583 these engineers have told me bold-faced lies for years, I was like wait, you can totally do 21 00:02:17,583 --> 00:02:22,750 all these things they told me you cannot do on the mainframe. So I decided to sort of bring 22 00:02:22,750 --> 00:02:27,708 the awareness to the community. Started creating tools, writing articles for security people and 23 00:02:27,708 --> 00:02:31,208 instead of coming out from the mainframe perspective I'm coming at it from the hacker 24 00:02:31,208 --> 00:02:37,625 perspective. I spoke at all these conferences that have no mainframe representation at all 25 00:02:37,625 --> 00:02:40,125 to start raising awareness about this platform. Real quick another question. This is a 26 00:02:40,125 --> 00:02:46,125 chart that shows SSL versus non-SSL usage for Internet-facing mainframes. Who 27 00:02:49,875 --> 00:02:55,958 wants to bet the largest portion of the pie is encrypted SSL in the small ones? No takers. It 28 00:02:55,958 --> 00:03:03,917 gets even better. The ones that do do SSL that are Internet connected about 1/3 have valid 29 00:03:03,917 --> 00:03:11,708 certificates. Now, why is that port? Because there's crazy cool fucking mainframes on the 30 00:03:11,708 --> 00:03:17,708 Internet. Can you see that? It's hard to read. That says Egypt Air. (Laughter) I found Iceland, 31 00:03:22,917 --> 00:03:29,292 lot of governments ones like Raleigh, North Carolina court system. Plani text, just hanging 32 00:03:29,292 --> 00:03:36,417 out on the Internet. I'll get into why plain text is important. this is an all zOS 33 00:03:36,417 --> 00:03:43,500 talk, I won't talk about i series, won't talk about the Tandem, just the z series 34 00:03:43,500 --> 00:03:50,375 mainframes it blows my mind people call this platform Legacy because they just released a new 35 00:03:50,375 --> 00:03:55,875 version, state of the art hardware and operating system and it blows my mind people 36 00:03:55,875 --> 00:04:02,750 calling it Legacy because they don't know how it works. It's not really a Legacy platform if 37 00:04:02,750 --> 00:04:07,125 you are updating it and installing patches and keeping it up-to-date and current with 38 00:04:07,125 --> 00:04:13,083 current releases. So not a Legacy platform. There's all kinds of cool companies and 39 00:04:13,083 --> 00:04:19,083 infrastructure run it but what does it look like? 3270 emulator connecting like extended Telnet. 40 00:04:21,333 --> 00:04:28,125 I'll log into TSO, the equivalent of the shell in this environment. Take a little bit 41 00:04:28,125 --> 00:04:34,083 to log in. So here I am going to run the LU command, list user credentials or user information, 42 00:04:34,083 --> 00:04:38,625 what they have access to, or I can list another user's credentials or I can add other 43 00:04:38,625 --> 00:04:44,625 flags and filter out some of the information that I care about, right. Only care about the unix 44 00:04:52,625 --> 00:04:59,208 partition I'll talk about in a second. You can do other cool stuff, net stat, open ports, net 45 00:04:59,208 --> 00:05:07,000 stat home that shows the IP configuration, you can also do ping, you can ping Google, just 46 00:05:07,000 --> 00:05:12,167 regular normal, it's not any super special thing that everyone had to believe, just a 47 00:05:12,167 --> 00:05:17,208 regular computer with regular kind of commands and you can do cool stuff but nobody does it in 48 00:05:17,208 --> 00:05:23,833 this interface. They use ISPF, that's like the GUI interface with the mainframe. I use the 49 00:05:23,833 --> 00:05:29,833 editor, I go straight to the editor and I can edit files. Here I am editing login script 50 00:05:33,833 --> 00:05:40,542 and just a regular you know regular text editor, editing files. I'll go back to my home 51 00:05:40,542 --> 00:05:45,542 folder that I know is not a home folder to mainframers but for the sake of argument I'll keep 52 00:05:45,542 --> 00:05:53,375 it there. I only have 20 minutes. Here I'll edit JCL, like script language, basically 53 00:05:53,375 --> 00:06:00,292 you submit jobs and you can run a script, very similar. Here is a rex file, this file shows the 54 00:06:00,292 --> 00:06:06,167 current logged in TSO users and what is cool about this is you can actually execute TSO 55 00:06:06,167 --> 00:06:10,833 commands straight from the editor, you can do work, save it and execute commands, so this is 56 00:06:10,833 --> 00:06:16,833 showing you can execute, you can do a lot of cool things from this. Right. I'm going to log 57 00:06:19,417 --> 00:06:25,417 out and I'll show you that UNIX is running on top of zOS. Regular old UNIX, client 58 00:06:27,667 --> 00:06:33,417 environment. You can do, make a mistake and it will tell you. You can also do regular 59 00:06:33,417 --> 00:06:39,458 commands, remember the flag when you are recording. You can also do screen -- regular UNIX 60 00:06:39,458 --> 00:06:45,667 interaction. This is a 3270 session, you can do it over Telnet or SSH, Telnet runs on 61 00:06:45,667 --> 00:06:51,667 port 1023 and I've seen on ton on the Internet still acceptable on that port. Now, that's the 62 00:06:53,708 --> 00:06:59,042 mainframe, all mainframe experts, now how to break into a mainframe. Okay. How do you get 63 00:06:59,042 --> 00:07:05,708 a credential? I'll just sniff it off the wire, now we know they are not encrypted but up until 64 00:07:05,708 --> 00:07:11,708 recently Ettercap didn't support sniffing for TSO so we were like (?) we went and added here. 65 00:07:14,833 --> 00:07:21,417 Nothing changes there, totally credentials, now you can see I'm logged in on TSO, totally stole 66 00:07:21,417 --> 00:07:27,417 credentials as well. In case you missed it, this is what it looks like there. Oftentimes, large 67 00:07:30,125 --> 00:07:34,958 enterprise organizations, they'll set up a Web server on the mainframe because not 68 00:07:34,958 --> 00:07:39,625 everyone wants to learn the commands to say show user, they want to log in if they are doing 69 00:07:39,625 --> 00:07:43,542 simple administration tasks. So on the DEF CON mainframe I created a website that lets you 70 00:07:43,542 --> 00:07:49,542 list user information that -- you can check if they revoked or what not so here is what it 71 00:07:52,125 --> 00:07:58,208 looks like, shows you the detail. Super broken, on purpose for the demo. What's 72 00:07:58,208 --> 00:08:05,083 interesting is that the CGI thing called TSO command, that's cool right I can guess wait does 73 00:08:05,083 --> 00:08:11,083 and that's running LU because we just went through what LU does, I wonder if I add on the other 74 00:08:13,250 --> 00:08:18,208 part of the command and if it does something else, okay, it's totally just interpreting 75 00:08:18,208 --> 00:08:24,958 commands that you type in and run in the TSO environment, I'll run R very, that shows you -- 76 00:08:24,958 --> 00:08:30,417 RACF database is the most important file security wise on the mainframe because every 77 00:08:30,417 --> 00:08:35,917 single security setting user name, password hash, is stored in this one file. Technically 78 00:08:35,917 --> 00:08:41,042 two the primary and backup. If you access this file you are on the mainframe. I'll show you in 79 00:08:41,042 --> 00:08:46,833 a second. There you go, I typed rvary and thats it. Now oftentimes you'll come across a 80 00:08:46,833 --> 00:08:52,292 mainframe only FTP is available and it will tell you because it tells you in the banner it's 81 00:08:52,292 --> 00:08:58,000 mainframe. Can't do anything else. You have login credentials. What is awesome is 82 00:08:58,000 --> 00:09:05,125 mainframe lets you run commands through JCL and FTP, back in the day there was no way to submit 83 00:09:05,125 --> 00:09:11,125 jobs remotely so I can submit, if I create a JCL and upload it, and say hey go run this, it runs 84 00:09:14,375 --> 00:09:21,708 it for me. There's all kinds of cool stuff. I'll show you. Now, you have access, I'm trying to 85 00:09:21,708 --> 00:09:27,917 blow through this to get to the demo. We have access now, assume we got a credential and now 86 00:09:27,917 --> 00:09:33,917 what? That's what two lasts me. Great. That was easy, someone left it in a script. What do I 87 00:09:36,250 --> 00:09:43,625 do? Now we'll escalate privileges. First thing we'll do. So connect with any kind of 88 00:09:43,625 --> 00:09:49,792 thing you want to use, Telnet, and escalate. Here is where it gets funky. In 2012 there was a 89 00:09:49,792 --> 00:09:55,792 major breach of mainframe suite. Whole bunch of CVEs came out. I'll read the first little bit. 90 00:09:58,917 --> 00:10:06,167 Unspecified vulnerability in IBM net new blah, blah, blah. What the real vulnerability was, was 91 00:10:06,167 --> 00:10:12,167 the fact that any set UIDREC script, Python script, any set UIDrec script will allow you to 92 00:10:14,667 --> 00:10:21,917 escalate privileges. The attacker used a REC script that was used by Tivoli NetView. So 93 00:10:21,917 --> 00:10:27,917 when they released CDE, it's technically correct and then IBM did not talk about the other 94 00:10:32,083 --> 00:10:37,208 part and they quickly and quietly patched that up. It's all patched so this is not I'm 95 00:10:37,208 --> 00:10:42,167 not stupid enough to come up here and teach you guys how to really hack these things but if 96 00:10:42,167 --> 00:10:48,167 you have some that are not patched, this may definitely work. (Laughter) So just sayin'. 97 00:10:52,125 --> 00:10:58,917 We talked about this, -- works with any recs -- can you see that? Of course not. Let's see 98 00:10:58,917 --> 00:11:04,917 if I can get that going anywhere else. End of demo, great. Can you guys see down there? You can 99 00:11:24,833 --> 00:11:28,458 see I'm on a mainframe, no question this is on the mainframe. Okay. No question at 100 00:11:28,458 --> 00:11:34,458 all. Here I have a simple script all it does is say yay, doesn't do anything else, UID of 0. I 101 00:11:37,167 --> 00:11:43,167 run, get user RX, I supply it that very simple REC script. And I have root. Because of the way 102 00:11:55,083 --> 00:12:02,583 they are using spawn. So now the rest of the demo is whatever, just showing I did it and if I 103 00:12:02,583 --> 00:12:08,583 had time to show it to you guys, I would. (Pause) Someone earlier said -- you are using su, I have 104 00:12:15,750 --> 00:12:22,250 zero access to it, I have no access to run the su command at all with that user ID. So 105 00:12:22,250 --> 00:12:30,042 there's the same demo for pdf readers. So for this hack specifically I need to thank a 106 00:12:30,042 --> 00:12:33,750 couple people before I go and talk on the rest of the stuff. Swedish BlackHat community for 107 00:12:33,750 --> 00:12:40,417 figuring this out. They discovered this, and then it was all wrapped up and hush-hush 108 00:12:40,417 --> 00:12:46,417 Oliver Lavery, there was paperwork sent secretly and little tiny pieces and we had to 109 00:12:48,833 --> 00:12:54,792 reverse engineer it. We tried running net hue, so what we were doing, and figure out it was 110 00:12:54,792 --> 00:13:00,792 just a REC script, and then like I mentioned Sweden a mainframe that got breached, mainframe was 111 00:13:04,083 --> 00:13:11,625 run by a company called Logica. We have root. But we talk about TSO a lot. So how do we bypass 112 00:13:11,625 --> 00:13:17,083 the rest of the controls to get access to TSO Easiest thing to do at this point is just get a 113 00:13:17,083 --> 00:13:22,958 copy of the RACF database. If you are lucky the root ID has access to the database. If 114 00:13:22,958 --> 00:13:30,958 unlucky maybe the Web server has access to do user updates or you know of someone who has access 115 00:13:30,958 --> 00:13:37,625 and just set up I net D to open up a shell. There's multiple ways to get at it. Whatever you 116 00:13:37,625 --> 00:13:43,000 do, you get that part. Because John the ripper supports cracking the hatchets in RACF 117 00:13:43,000 --> 00:13:49,000 database. With a tool called RACF to John, you have taken it stripped all users names, it's 118 00:13:52,500 --> 00:13:59,667 great because it's dead. So the way that the hash (Laughter) The way they hash the password is 119 00:13:59,667 --> 00:14:05,667 they take your user ID and they encrypt it with your password. (Laughter) >> Yeah, there's a 120 00:14:05,667 --> 00:14:13,208 little bit of obfuscation, they shift it to the left one bit but essentially the same. Did I say 121 00:14:13,208 --> 00:14:19,167 it? Okay. Doesn't matter, it's open source, you guys could have read the code, not a see 122 00:14:19,167 --> 00:14:23,667 receipt, IBM is working to change this, they released saying we want suggestions on 123 00:14:23,667 --> 00:14:29,667 what to do next. What else can you do? IBM has a tool cold IRRDBU00, stands for database 124 00:14:34,042 --> 00:14:41,625 unload. What it does is takes a RACF database and dumps that to a flat text file, all 125 00:14:41,625 --> 00:14:47,208 permissions, all settings, everything. What you'll do with that is find all users that have 126 00:14:47,208 --> 00:14:53,667 special -- then go back to hash and say John just focus on these people. Then once you have that 127 00:14:53,667 --> 00:15:00,000 you'll log in with that special account. Then here is an example of JCL because it's cool to have 128 00:15:00,000 --> 00:15:06,000 JCL at DEF CON because that's so cyberpunk. That's the JCL users included on the CD, IRRDBU00. 129 00:15:11,292 --> 00:15:17,625 But now we have special. Special gives us full control of RACF. RACF lets us do anything we want 130 00:15:17,625 --> 00:15:22,042 because we're special. It doesn't mean we have access to anything but it does mean we can 131 00:15:22,042 --> 00:15:28,042 give ourselves access to anything we want. So I can create a user ID. I can have a 132 00:15:30,333 --> 00:15:37,542 regular -- regular USER ID in the mix well now I'll give it a user ID of 0, and I have 133 00:15:37,542 --> 00:15:43,583 permission to do that or I'll just give myself special, just create another ID and give it 134 00:15:43,583 --> 00:15:49,000 special in case I lose my special. You could also -- you know all the users who have 135 00:15:49,000 --> 00:15:55,000 special. You could remove their special access. (Laughter) Now, there's a really cool permission 136 00:15:57,833 --> 00:16:03,833 called BPX.SuperUser. You can see that demo, good, sort of all it's doing is typing Su and exit 137 00:16:06,958 --> 00:16:14,500 over and over in quick successes session, there's no time to type a password here. BPX.super user 138 00:16:14,500 --> 00:16:20,000 doesn't ask for a password if you want to Su up the root. If you have people with permission 139 00:16:20,000 --> 00:16:27,917 to BPX.SuperUser, you can just type Su and do a Get. That's how you do it if you want it to do 140 00:16:27,917 --> 00:16:33,917 that. Really long command, just change user ID right here to your user ID and do it that way. 141 00:16:36,083 --> 00:16:41,500 On top of that, I have a whole bunch of tools I've created to make it easier to deal with the 142 00:16:41,500 --> 00:16:45,958 mainframe. When I first came across I was like what is happening? All commands are 143 00:16:45,958 --> 00:16:51,375 crazy, no idea, I had no idea how to edit a document. Using this thing. What is happening? 144 00:16:51,375 --> 00:16:57,375 I started writing and said it would be really coal if nethack could work, now it's a cool 145 00:16:59,458 --> 00:17:05,500 project, only does UNIX, really cool if we could do like a reverse TSO shell. That's what I 146 00:17:05,500 --> 00:17:10,000 did with CATSO it's this really awesome script, it has a whole bunch of macros in it, So if you 147 00:17:10,000 --> 00:17:15,583 want to do a FTPL file off the mainframe you just type FTP, space 'the file name' and 148 00:17:15,583 --> 00:17:19,458 destination and it does it behind the scenes you don't have to deal with it. If you want to 149 00:17:19,458 --> 00:17:25,125 copy files, delete files, it's just all these macros, you want to look at the IPP 150 00:17:25,125 --> 00:17:32,417 configuration, RACF database, just type RACF and it will show you. It lets you run UNIX and 151 00:17:32,417 --> 00:17:39,375 TSO commands straight from the prompt. You open up listener or reverse shell out with net pad 152 00:17:39,375 --> 00:17:45,375 it all works fine. The shocker is a wrapper around that whole script. So remember earlier I 153 00:17:47,833 --> 00:17:55,375 was talking about can use FTP, then have it execute that JCL. That is what it's doing. It's 154 00:17:55,375 --> 00:18:00,292 compiling, taking all together, building it and then uploading it to the mainframe. This is 155 00:18:00,292 --> 00:18:05,958 what it looks like if you run path on the mainframe. If not, this is what it looks like 156 00:18:05,958 --> 00:18:12,208 shocker to run it from your Linux box. So it goes and builds and runs it and you have to 157 00:18:12,208 --> 00:18:17,083 connect with net pat or automatically listen on net pat and it would be already for you 158 00:18:17,083 --> 00:18:23,875 to go. If you only have FTP access and mainframe is left to call out, this is a way you can 159 00:18:23,875 --> 00:18:29,583 get interactivity with that mainframe. That's really cool but what would be even better is 160 00:18:29,583 --> 00:18:35,583 to get a root shell out of this so I could get root.REX and do the exact same thing, compiled 161 00:18:37,917 --> 00:18:45,083 it altogether, it has two C programs it compiles on the fly in the mainframe, uploads those 162 00:18:45,083 --> 00:18:51,083 files, executes it and let's see this demo better work -- awesome. You guys see the end of 163 00:19:00,708 --> 00:19:06,708 the demo again? Disconnecting on port 21, so we connect port 21, switches the mainframe to upload 164 00:19:15,000 --> 00:19:20,750 the JCL in the job cue and then doing its things behind the scenes and I have a root session 165 00:19:20,750 --> 00:19:26,750 all through FTP, that's all I needed. That's it. Then I have control and start doing what I 166 00:19:30,083 --> 00:19:36,083 was talking about that I never even had to do anything crazy, go back... now you're probably 167 00:19:42,458 --> 00:19:49,083 thinking to yourself that's awesome but they'll never let me touch our mainframes, are you 168 00:19:49,083 --> 00:19:53,333 kidding me? They are like multimillion dollar machines that they are unbreakable but 169 00:19:53,333 --> 00:20:00,042 they're afraid I'll break them. What's great is IBM has software called RDZ. a Rational developer 170 00:20:00,042 --> 00:20:07,375 for system z, full on emulated mainframe you can run in Linux, they offer it, if you have 171 00:20:07,375 --> 00:20:13,375 mainframe, put up your hands that they had an account on a mainframe, talk to your IBM rep 172 00:20:15,417 --> 00:20:19,000 and see if they will give you a demo license to check it out. Full on mainframe environment 173 00:20:19,000 --> 00:20:26,125 and now you can go get your hands dirty, you can break it and not worry, start creating 174 00:20:26,125 --> 00:20:32,417 overflows and just seeing how it works. I learned more setting up this machine to do demos than I 175 00:20:32,417 --> 00:20:38,542 did in seven or eight classes on mainframes. It's so awesome to have your hands on one and it 176 00:20:38,542 --> 00:20:44,042 looks cool as hell, just call your IBM guy, you should be good. Now I need to thank some 177 00:20:44,042 --> 00:20:51,042 people. Mike (?) is all operating systems based. Lot of application that is run on the 178 00:20:51,042 --> 00:20:57,958 mainframe that have been built not using best practices from 60 years ago. Gentleman by the name 179 00:20:57,958 --> 00:21:02,500 of Dominick White, he gave a talk at hack in the box, he called it BIRP big iron recon 180 00:21:02,500 --> 00:21:07,208 (?) does the exact same thing but does it for mainframe applications. There's another 181 00:21:07,208 --> 00:21:13,208 cool fact that 3270 client well anyways I'll let him talk about that. I need to thank the 182 00:21:17,333 --> 00:21:19,917 community. And IBM, I mean literally I know I was making fun of IBM here a little bit but 183 00:21:19,917 --> 00:21:23,750 I love the mainframe, really do, it's cool and I don't like want to have a stucks net happen on 184 00:21:23,750 --> 00:21:26,542 the mainframe here because people don't know how to (?) I will put this up. Yeah. Yeah. 185 00:21:26,542 --> 00:21:32,542 >> (Speaking off-mic). (Applause)