start	end	text
0	780	All right.
780	5560	You may have heard of mainframe pen testing and exploitation.
5980	7520	Mainly from our next speaker.
8260	11720	DEF CON, please give a welcome to the soldier of Fortran.
14520	15400	Wow.
15540	16400	That was awesome.
16400	17520	The other room cheered for me.
17520	18360	That was great.
19320	20220	Morning, everybody.
20220	23600	I really appreciate you all coming to a Sunday morning talk at DEF CON.
23780	25360	Front row, I'm going to need your help.
25360	27200	I can't see anybody else.
27520	31700	And if my hand starts to drop and you can't hear me anymore, can you guys just be like, hey.
32180	32620	Thank you.
32620	33940	Thank you so much.
34040	34700	All right.
34700	38600	So for those who don't know, my name is Phil Young.
38600	42100	I'm the director of ‑‑ I'm just waiting for them to calm down.
42100	43580	I don't know what's going on over there.
44520	47400	So I'm the director of mainframe pen testing at NetSpy.
47620	51160	You might also know me by my other name, soldier of Fortran.
51480	55700	I was a mainframe hacker, like a 90s hacker kid.
55940	60860	I was a mainframe security enthusiast before I started doing this professionally.
61460	64680	I'm a terrible karaoke singer.
65340	70680	And just so folks know, I always felt like an outsider, even in this community.
70680	75400	This is my third time speaking at DEF CON, and I still sometimes feel like an outsider.
75400	78640	So if you feel like that, don't ‑‑ everybody feels like that.
78720	83340	I've been doing professional mainframe pen testing for about ten years.
84020	86740	This was supposed to be a co‑talk.
87500	90540	But unfortunately, my co‑speaker is no longer with us.
91460	94980	He had to go home to take care of his kid going to college.
94980	96280	So he's not here.
98080	100420	So ‑‑ but still going to talk about him.
100420	102280	So he was a 90s hacker kid.
102760	104480	He was also a mainframe security enthusiast.
104480	105680	He loves show tunes.
105680	107360	He's really good at reverse engineering things.
107360	110360	Probably the best reverse engineer I know, especially when it comes to mainframes.
110940	112120	Dude's a freaking genius.
112600	115520	He's also been testing mainframes for ten years.
115600	120200	Now, there's a third person in this photo who we didn't invite.
120260	124620	But he's the OG mainframe hacker.
124880	127820	And we want to make sure we shine a light on him as well.
128100	136740	Before Chad and I came along, he was, like, the only mainframe hacker who was publicly talking about how to do, like, mainframe pen testing.
137020	137360	Right?
137360	139460	At mainframe conferences, not places like DEF CON.
139460	141300	We're trying to get him to come to DEF CON for years.
141560	146460	But I want to make sure we talked about him because he is the OG for mainframe hacking.
146960	152900	Now, since Chad and I have been friends for the better part of ten years, I need help with my code.
152900	155240	I'm a great coder, especially when it comes to assembly.
155460	163600	And so I will oftentimes send my code to Chad so that he can help review the code because it doesn't work.
163900	164420	Right?
164580	170080	And every time I send him a piece of code, he puts me on blast on Twitter first.
170380	172300	Then he fixes it.
172740	180960	Speaking of Chad, since Chad couldn't be here, what I did was I told him, hey, send me, like, 10 to 15 photos of yourself.
181540	183740	Not telling him what they're going to be for.
184140	190480	And then I said, hey, I want you to give me quotes that I will put in the talk.
190580	192020	So remember this slide.
192100	193160	Look at the bottom.
193160	194460	Yes, I did write that.
194460	195820	I hope it's enough.
196300	196800	Okay?
197040	207980	Now, when I sent Chad the deck and I said, hey, I want you to put inspirational quotes or technical quotes, but I mistakenly told him, I will read off whatever you put verbatim.
208860	213820	So the first thing he sends me with respect to this slide is he said, it was not enough.
214180	215180	So thanks, Chad.
215180	216340	I appreciate you.
216800	217600	This is not so bad.
217600	220580	I can actually see a bunch more of you than I thought.
220580	222240	So we're going to try this out.
222480	229320	Who here can tell me where the main frame is in this picture?
231700	232480	Don't be shy.
232480	233580	You can just yell it out.
235360	238040	The system... someone said system in the back.
238040	239820	Can you be a little more specific?
243620	244440	Where the tapes are.
244440	244920	No.
247220	248220	This guy put his hand up.
248220	248700	Yes.
252010	256190	The red box in the corner that says 360 on it, that's the main frame.
256190	258110	That is the main frame.
258110	263290	The reason it's called a main frame is because it holds all the CPUs and memory.
263450	270730	It is the main frame, that's where the word comes from, where you host all the CPU, all that stuff.
270730	272650	The rest of this is just IO.
272890	278330	You've got your terminal, you've got your card reader, you've got a dude pressing buttons for some reason.
278950	281450	But everything in that one thing, that's the main frame.
281450	286750	Now, today, in a modern data center, this is what the main frame looks like.
286790	288210	It's exactly the same.
288210	293090	The only difference is, this is the main frame.
293510	306830	And now this one box, I promise you right now, there is a box exactly like this in some bank or some airline's data center, and it is processing thousands of transactions a minute right now.
306830	311930	And it's doing it flawlessly, and it's the workhorse of the enterprise.
312570	315910	And lots of enterprises still rely on this platform.
315910	325650	You have no idea how many articles come out, main frame's dead, main frame's going away, this company's moving off the main frame, this other company's moving off the main frame.
325650	332970	There's so many announcements, this company's moving off the main frame, there's never announcements, we successfully moved off the main frame.
333190	334610	They never do.
334850	338550	Some CIO comes in, starts the process, they got about halfway, and that CIO quits.
338670	340190	That's usually the steps.
340310	343750	But so many companies rely on this platform today.
344210	346430	You've got airlines rely on it.
346430	350370	I mean, if you flew on any of the major airlines, a main frame was processing your transactions.
350530	356050	Every time you use your credit card or debit card, main frames are involved in some capacity.
356410	361950	Auto manufacturers, obviously banks, but even companies like UPS use main frames.
362230	368790	If it's older than, say, like, it's like a 50 year old plus company, guaranteed they're using a main frame.
369090	378070	Before we get too far into the talk, I need to talk about some terminology that's important for you all.
378450	383830	So, you know, RACF is what's called an external security manager.
383830	386310	So there's actually three of them.
386410	388890	RACF, top secret, and ACF2.
389010	395210	Now, it's called external security manager even though it runs on the main frame as part of the operating system.
395590	400290	But think of it like Active Directory if you could replace Active Directory with something else.
400350	400550	Right?
400550	401830	Better or worse.
401850	403630	It's the same concept, right?
403630	408550	So the reason is the operating system itself doesn't really care.
408550	411450	It just asks what's called the SAF router.
411450	412570	And it says, hey, is this okay?
412570	414570	And the router knows which product to route it to.
414570	416550	You can only run one at a time.
416690	418030	So that's RACF.
418070	422970	Now, RACF controls sort of all the security permissions on the main frame.
423630	428570	In RACF, there are user attributes called special and operations.
428870	439930	Special and operations allows you to edit any file, to change any file, to give yourself whatever permissions you want in the RACF.
439930	444970	If you have system special but not operations, you can give yourself operations.
445390	445870	Right?
445870	452030	If you have operations but not special, you can download the RACF database and crack all the passwords.
452030	452270	Right?
452270	456150	So either or gives you complete control over the system.
456190	467930	APF libraries are ‑‑ imagine if you had a folder where you could put set UID ‑‑ any program you put in there was automatically set UID.
468190	474350	Very similar concept, but you can get into essentially ring zero so long as you put your binaries in there.
474350	476970	That is the control that mainframes use.
477090	485150	Basically, when you put a program in that folder, it is allowed to run in a supervisor state with the CPU.
485150	486230	That's what it means .
486230	488670	That's how they control how programs can run.
488970	492890	Key zero is ‑‑ this is all terminology you know.
492890	497850	Key zero is the ‑‑ every page of memory has a key.
498350	506350	Key zero, if your process is running in key zero, you can edit any page of memory you want.
506450	509710	Otherwise, the only other time that works is if your keys match.
509710	509850	Right?
509850	515070	So if I'm in key eight and the memory space is in key eight, then I'm allowed to edit that region of memory.
515070	516430	But if not, I can't.
517390	524630	Now, we would like to think that, you know , there are myths about mainframes, right?
524630	533030	But when it comes to these myths, this is a slide that Chad gave a talk on ten years ago.
533450	537390	And even today, we keep hearing about these myths.
537390	537570	Right?
537570	538870	It is crazy.
540010	540250	Okay.
540250	544970	So there's really four main attack paths on the mainframe.
545150	548410	You get your network attacks, right?
549170	550950	Normal network type attacks, right?
550950	552650	Nmap works fine, all these things.
552650	554830	On top of that, though, we have SNA networks.
554830	558590	That's a completely different type of network that runs.
559090	560870	We have the file system, right?
560870	567810	You would be surprised sometimes on pen test, I go in and I see ‑‑ I have, like, write access to 30,000 data sets.
568190	573450	Or read access to, like, sensitive company information, like, 110,000 data sets.
573450	574530	It is crazy.
575190	576450	External security manager.
576450	577590	That's the other attack path.
577590	581250	That's where we go in and we look at, oh, do I have access to this?
581250	581970	Do I have access to that?
581970	588070	And in fact, some of the things we're going to talk about today are because of misconfigurations in the external security manager.
588390	592690	And lastly, what this bulk of this talk is about is ZOS Unix.
593110	606910	And the reason we want to talk ‑‑ we wanted to talk about ZOS Unix was because we really ‑‑ we used to joke that, like, Unix was the gateway drug to mainframe hacking because it's so familiar, right?
606910	610790	It is such a familiar thing to you, especially if you use Linux.
610790	612870	In fact, I have a pretty good view of the audience.
612870	615590	Can I have a show of hands who's familiar with Linux?
616070	616510	Right?
616510	618030	Like, most of the audience, right?
618030	619050	So that's good.
619090	623130	Because it's very similar, but also a little bit different.
623210	623870	Right?
624510	626990	So it's based on system V, right?
626990	628110	Or system V.
628650	634030	And it really didn't get built out until mid‑90s, right?
634030	638090	So the IBM operating system is called ZOS, right?
638090	639550	So it runs ZOS.
639550	642430	And inside ZOS, you run Linux.
642430	643970	Or you run Unix, sorry.
644750	646610	It was developed in 1994.
646790	649230	It wasn't really a core part of the operating system.
649230	654190	It was based on, those kind of things.
654550	660950	And in 96, it obtained POSIX compliant, and it took over running TCPIP for ZOS.
660950	663430	Prior to that, it was all jobs and stuff.
663430	668470	But instead, they just built the TCPIP implementation on Unix.
668490	672930	They rebranded it in 98 to Unix system services.
673210	675490	And it continued to grow a little bit more.
675530	680370	And then today, they rebranded it again to ZOS Unix.
680430	683330	And for those curious, Linux was released in 91.
683410	685210	So just a little timeline.
685530	689430	Now, when it comes to Unix, again, it's like Linux.
689470	691030	It's a little bit different.
691210	693010	You only get two shells.
693450	695350	BINSH, which sucks.
696030	697930	BINTCSH, which sucks a little less.
697930	699310	They're both not great.
699630	701370	But that's all we get.
703330	704490	Everyone here knows Linux.
704490	708230	I'm not gonna explain how file systems work in POSIX environments.
708310	710470	You get file permissions, right?
710470	711410	Regular file permissions.
711410	712910	But here's where it gets a little funky.
713470	718870	You can also have other permissions that you put into your ESM, right?
718870	719710	Like RACF.
720070	725290	So you can have, say, I have read access to this file according to the file system.
725290	727550	But when I try to read it, RACF says no.
727650	729630	That folder is only for admins.
729970	730610	Right?
730690	734790	Where that gets challenging is sometimes you can mix those up and not do a great job.
735950	737370	You access the Unix environment.
737370	739450	There's a whole bunch of ways to access the Unix environment.
739750	744130	You access it through the OMVS command in TSO.
744250	747890	So there's other talks about hacking in TSO.
747890	750590	But you just type OMVS and you get a Unix prompt.
751570	754590	SSH sessions, which is what we're gonna use for this talk, right?
754590	759370	Because we're trying to demonstrate how you can do all of this in Unix.
759790	768290	Or you can use JCL, you can use BPX bash, you can use REC scripts, you can call it from C programs.
768290	769270	There's all kinds of things you can do.
769270	770730	Assembly programs.
770870	770930	Right?
770930	777490	I know Chad wrote a module for Metasploit that spawns a Unix shell using assembly.
777490	779490	So you can call it all kinds of ways.
779490	787470	What's interesting is you can also access datasets from within Unix using this super funky command, right?
787470	795570	So you do, like, slash slash, then the name of the dataset you want to interact with, and then you pipe it to... that's where you're copying it to.
795790	798930	It's frustrating because only a handful of commands support it, and it's not clear.
798930	801230	So, like, I know copy works.
801390	805510	I know cat works, because a client I was on wouldn't let you copy a dataset.
805670	809290	So I just catted it and piped it out, like, redirected the output.
810090	812710	Grep does not support it for some reason.
812710	815890	So it just sort of, like, depends on what IBM wanted to do.
817050	821430	Now, again, if you're familiar with Linux, this should all be very familiar.
821790	822230	Right?
822810	824530	It's close enough.
824810	824970	Right?
824970	827790	You've got normal commands.
827790	829550	You've got your normal stuff going on here.
829550	830930	You can cat files.
831290	837270	The fact that it's positive compliant means you can do all the normal things you can do in a Unix environment.
837350	837930	Right?
837930	842250	It's not some crazy thing going on.
843130	843790	Okay.
843790	846490	So here's the next Chad quote.
847890	849810	I can see it on my screen here.
849810	850130	I don't...
851210	853230	Ask me about Vegas fill.
853690	854390	That's it.
854390	856270	So I'm not going to leave time for questions, just so you know.
856270	858130	So don't... so good luck.
858270	858910	All right.
859530	867110	When we made this talk, you know, we wanted it to sort of walk you through step by step how we do a pen test.
867110	867470	Right?
867570	872990	Because there's lots of tools and stuff that exist now that we didn't have, like, ten years ago.
873350	876190	And it's important to understand how we start...
876190	878890	Jumping in straight to the end sucks.
879550	882750	So there's a whole bunch of tools that exist today.
883250	886490	These didn't exist ten years ago because Chad and I wrote them.
886630	888990	So you have a tool called enum.
888990	890390	That's a Rex script.
890670	893950	So for those who don't know, Rex is a scripting language.
894370	894670	If you...
894670	895290	Actually, quick question.
895290	897090	Who here ever used an Amiga?
898170	898970	Yeah!
899270	900750	That's way more than I thought.
900750	902470	Amiga came with Rex.
902910	904950	Rex is a scripting language.
904950	908110	It was created by IBM as a 10% project.
908110	911730	But anyways, Rex runs in Unix natively.
911850	914490	And so we write a bunch of our scripts in Rex.
914710	918770	We also have another script called OVS enum.
918930	921890	And that script is based on Linium.
921890	923270	I'll get into that script in a bit .
923270	927270	We also have a couple of Java tools called File Traversal and Zoss Hog.
927270	929970	Those allow us to map out the file system.
929970	931210	Do we have read access?
931210	932970	Are there passwords in them?
933290	937970	And then we have another tool called Port Scan, which we'll talk about when we get to egress.
938610	942310	All of this is freely available on my GitHub.
942410	947350	So if you wanted to test them out or play with them, they're freely available.
947670	948230	Right?
949310	953970	And if you have a keen eye, you may have saw there was a file called all.jcl.
955650	961210	Getting things onto the mainframe during a pentest can be very challenging sometimes.
962310	964170	If you have to upload one file, it's a pain.
964170	966510	If you have to upload multiple files, it's a bigger pain.
966530	969750	Companies, for some reason, try to limit your ability to upload.
969910	971390	There's always a way around it.
971390	971450	Right?
971450	972810	There's always a way around it.
972810	979190	So what we do is we package everything up, all of those scripts into one JCL, and then it just runs by itself.
979570	980950	It adds all those programs.
980950	984510	Now, how do we get it to the mainframe?
985010	986910	You can just use SCP.
987570	993490	Problem is, SCP only supports binary file transfer.
994750	996810	And I'm sure as you're reading the slide, you're kind of seeing why.
996810	999170	Does anybody want to guess why that's a problem?
1000690	1000950	Okay.
1000950	1001110	Yes.
1001110	1001510	A hand up.
1001510	1005630	You don't have to yell because there's like... yes, character encoding.
1005630	1009990	So code pages are files written in ASCII or UTF-8.
1010510	1012470	The mainframe speaks EBCDIC.
1012750	1014830	So we have to convert it to EBCDIC.
1015070	1017810	So that's what we do, and then we upload it, and it's all good.
1018190	1025330	For the purposes of this talk, whenever you see the blue prompt, that's when we're in Linux.
1025330	1026950	So we're doing something to prep.
1026950	1028110	That's our staging.
1028670	1033010	If you see this prompt, that means we're on the mainframe.
1033010	1033570	Okay?
1033810	1035590	Now, let's take a look at enum.
1035590	1037270	So this is that enum rec script.
1037470	1041710	So what this script does is it pulls information from memory.
1041790	1048570	So it does a really good job of accessing things from memory, because we have read access to a lot of memory space.
1048570	1054530	And it dumps information out about the operating system, about the current running environment.
1054850	1056930	And it's been built... like, it wasn't just me.
1056930	1060510	There's other people that helped JTAY and other people who have helped build this.
1060990	1063870	Some things in memory are not documented.
1064150	1066330	And so we sort of reverse engineer those.
1066330	1070390	And what's interesting about this program is sometimes you're limited.
1070390	1072750	You can't list these things.
1072750	1074990	But it exists in memory if you know where to look.
1074990	1076050	So that's what this rec script does.
1076050	1079050	I use it on every single pentest.
1079250	1084030	The next script we have is based on linenum.
1084270	1085050	Okay?
1085050	1087530	But I had to rewrite it for TCSH.
1087690	1093550	And then what we did is we added a whole bunch of mainframey type stuff to it.
1093750	1095930	So you'll see us running it here in a second.
1096290	1100570	And if you're wondering why it's going to be on VS said here, you can come talk to me after.
1100930	1102130	But we're going to run it.
1102150	1103890	We're going to tell it to send it to a report.
1103890	1108150	And what's going to happen is it's going to go through and dump all kinds of information, right?
1108150	1109910	And you'll see some more mainframey stuff.
1109910	1115670	So the stuff that's going to be in all caps here in a second, that's a list user command from RACF, right?
1115670	1117110	So it dumps all kinds of information.
1117110	1118830	And then we comb through it later.
1119670	1122470	The other thing we always test for is egress busting.
1122650	1133190	You would be surprised how often we're able to go directly from the mainframe behind, like, I have to go through, like, two VPNs sometimes to even touch the mainframe.
1133970	1138730	But we're able to go from the mainframe directly to AWS or some other cloud provider, right?
1138730	1141310	It is crazy how often that works.
1141530	1145110	And so, in fact, one of my clients, we did the test.
1145190	1151810	I wrote it up saying, hey, you have, like, thousands of ports, like, are allowed to no egress filtering out to this AWS host.
1151910	1156590	And they go, we haven't used that ISP for ten years.
1156630	1159210	We have no idea how this is routing, right?
1159210	1161890	So anyway, it's not really that hard.
1161890	1163490	We use a Java program.
1163490	1167450	The reason it's in Java is most mainframes come with Java, right?
1167450	1168570	By default.
1168690	1172170	Also, it allows us to control the time out of the packets.
1172510	1175130	And then we just do a port scan, essentially a SYN scan.
1175170	1180250	And then on the Linux box, we run a tool called egress tester, which is a fork of egress buster.
1180530	1182070	And you can see all the open ports.
1183450	1183790	Okay.
1183790	1185250	Next picture of Chad.
1187070	1191830	He wanted me to say that I sent him this hat after I told him after he told me he bought a boat.
1191830	1192770	That's a true story, actually.
1192770	1194710	He bought a boat and I was like, you know what he needs?
1194970	1196530	Is a dumb hat with hair.
1196530	1198010	Because he does not have hair.
1198710	1199050	Okay.
1199050	1200150	Let's talk about some analysis.
1200150	1203490	Now that we've done the enumeration, we've gone through the enumeration.
1203490	1205130	Let's look at some of the output.
1205250	1207850	This is from enum.rex, okay?
1207850	1218110	And the important bits that we pull out of that are the location of the RACF datasets and the fact that and what hashing algorithm they're using.
1218190	1218530	Okay?
1218590	1224810	RACF uses either DES for the hashing algorithm or KDF AES.
1225250	1230530	John the Ripper and Hashcat both support cracking RACF databases.
1230550	1238210	And if you have read access to either of those two datasets, it's trivial, especially since we know that KDF AES encryption is not enabled.
1238450	1242470	It's trivial for us to crack every single password in that database.
1242610	1252810	I think Chad was telling me a story where he downloaded the database, cracked it, and maybe in an afternoon, like two, three hours, had every single password for every single user.
1252930	1256730	So if you do run a main frame, please make sure you turn on KDF AES.
1257490	1262230	Now, when we look at the output, we see there's a bunch of stuff here, right?
1262990	1265270	We can suit a route without a password.
1265790	1267990	And we'll talk about that in detail.
1268390	1273210	Files that should not be world readable, like someone obviously CH modded some stuff 777.
1274090	1278010	We can mount datasets, right?
1278010	1283050	Which you can normally do, but this one gives us more access than we should have.
1283050	1287570	And this last one is we can issue the EXT ATTR plus A command.
1288670	1293190	Now, the other tool we ran that gave some interesting output was ZossHog.
1293250	1300690	ZossHog is based on TruffleHog, and it uses Regex to find secrets inside files in Unix.
1300690	1303370	And when we ran it, obviously we found a password.
1304830	1305230	All right.
1305230	1306490	Here's the next one.
1306490	1307850	God, I hate this one.
1310560	1314140	Ask Phil to pronounce Java and then wiki.
1315160	1316440	Java wiki.
1317480	1319320	I don't think I say it incorrectly.
1320080	1320340	All right.
1320340	1321520	Next is privilege escalation.
1321520	1324000	So now that we know what's wrong, right?
1324000	1326060	We know there's some vulnerabilities on the system.
1326120	1328260	We definitely have to demonstrate impact.
1328620	1330860	Especially when it comes to mainframe hacking.
1331180	1332940	You have to show impact.
1332940	1340420	Because every not every time, I would say 99% of the time, my findings are an uphill battle with the mainframers, okay?
1340420	1341680	I get so much pushback.
1341680	1344900	You have to show, like, no, actually this setting is very dangerous.
1344900	1345820	Look what I did.
1345820	1346420	Okay?
1346420	1348400	So let's talk about privilege escalation.
1348620	1350880	Obviously the first one is the super easiest one.
1350880	1352820	We found stored credentials, okay?
1352820	1354360	So this could be lateral movement.
1354660	1356320	Nine times out of ten it's not.
1356360	1360440	And I would love to say this is a rare thing that I've only found once.
1360440	1363760	No, I've found this multiple times, okay?
1363860	1366760	So do not store password in files.
1366880	1370080	Obviously if you have to, make sure the permissions are correct.
1370140	1371600	And make sure you test those permissions.
1371600	1377880	Because maybe your ESM is overriding those permissions and everyone has read access to it.
1378700	1379920	So this is an example.
1379920	1382800	This is an actual example from a client.
1382880	1384660	Obviously not I rewrote it.
1384660	1385900	It's not their work.
1385900	1387180	But it's very similar.
1387240	1389800	And we found a script like this in the user's home folder.
1390080	1392280	And it was chmod 7777.
1392420	1394940	Obviously because it wasn't working until someone did that, right?
1394940	1396380	And then all of a sudden it started working.
1396880	1398880	And had user credentials in it.
1399200	1401860	And so super, super easy hack, right?
1401860	1403740	Because mainframe hacking is not hard.
1403740	1404760	It's not that hard.
1405260	1409980	We just SSH in with the username and password, right?
1409980	1412360	Like this is not rocket science, right?
1412360	1416300	We type their username, we type their password, and then we get in.
1416440	1419880	And the first thing you do once you connect is you make sure you know who you are, right?
1419880	1421340	So I'm logged in as me.
1422060	1424140	And then we have some fun.
1424420	1428280	And then the next thing we do is we run the command list user.
1428420	1428860	Okay?
1428860	1431020	Because that actually tells us what we can do.
1431020	1433200	And if you'll notice, this user has special in operation.
1433200	1434380	So at this point, it's game over.
1434380	1436120	We can kind of do anything we want.
1436220	1440620	And the pen test turns from a pen test to now an assessment because we can read everything.
1441440	1442420	Oh, great.
1442640	1444480	This one's finally one not about me.
1444480	1455520	He wanted me to tell you that Mark from that, like, intro, drove his Aston Martin into a washed out area of a road and had to climb out the window and be rescued from the roof.
1455660	1460840	I asked him for, like, technical quotes or inspirational quotes, and this is what he gave me.
1462040	1462600	Okay.
1462600	1469780	The next one we're going to talk about is this one at the bottom because I know none of you know what extattr plus a does.
1469780	1475220	That is a only on the main frame command, and it's very important to understand.
1475460	1479500	So we're only talking about APF authorized programs.
1479500	1482660	So APF authorized programs are allowed to get into supervisor state.
1482820	1484360	That's what they're allowed to do.
1484360	1484820	Right?
1484820	1486540	And that comes with a bunch of different things.
1487560	1493980	On the regular mainframe side, you have to put them in an APF authorized program library, otherwise known as a folder.
1494560	1501100	On Unix, you can actually assign programs the extra attribute A.
1501220	1503640	That makes it APF authorized.
1503900	1504140	Right?
1504140	1505340	That's all that does.
1505780	1506060	Okay?
1506060	1510080	So the access to control that is BPX.file.
1510080	1514200	I know it says extra, but it's fileattr.APF.
1514220	1516660	So read access to that profile.
1516660	1518800	Interact F lets you issue this command.
1519920	1522180	Most people should not have access to do that.
1522380	1524420	Now, why is it important to get APF authorized?
1524420	1530980	I'm going to walk you through what happens when you log into the mainframe and why getting APF authorized and all that stuff is important.
1530980	1532660	Because it's the thing I didn't understand.
1532940	1544020	So when you log in, the first thing the operating system does after you log in is RACF copies a bunch of user information about you into memory.
1544620	1544740	Right ?
1544740	1546940	And it refers to that memory region.
1546940	1551160	Think of this like your ID in Linux, right?
1551160	1553900	And if you can change your ID to something else.
1553900	1554420	Right?
1554420	1555300	Similar concept.
1555300	1556520	So it sits in memory.
1556520	1561900	Problem is that memory region is locked under key zero.
1562220	1566900	And user processes only run under key eight.
1566900	1569880	So we cannot change this region of memory.
1569880	1573220	If we could, we could take over the mainframe.
1573220	1573840	Right?
1573840	1582700	If there's a way for us to change our key to key zero, then what we do is we just replace this.
1582700	1583640	It's called the ACE.
1584160	1590760	We replace our ACE with whatever user we want that exists on the system.
1590840	1593220	And now we can become someone else.
1593220	1594860	Preferably an admin.
1595340	1598160	But how do we change our key to key zero?
1598160	1601820	Well, luckily, there's an assembly macro called mode set.
1602360	1605180	And we just change it to key zero.
1606200	1614860	And then once we do that, to issue that macro, you must be APF authorized to issue that.
1614860	1615140	Right?
1615140	1621700	So in Unix, if we use that EXT ATTR command, we can make it APF authorized.
1621700	1623740	Now, what does that look like technically?
1623740	1625340	What does it look like in practice?
1625340	1627320	So here is what it looks like in assembly.
1627320	1628600	Any questions?
1630120	1631060	We can move on?
1631060	1631660	Great.
1631840	1634200	So really, this is the command here.
1634200	1635120	Oh, that's great.
1635640	1637940	The boxes on my laptop worked.
1637940	1640100	So this is their laptop problem.
1640320	1642420	So mode set key zero.
1642840	1644040	That's the command.
1644040	1647440	If the program will abend if it's not APF authorized here.
1647440	1648620	So that means crash.
1648780	1649020	Right?
1649020	1650800	So once it gets past that, you're golden.
1650860	1654160	The next thing we do is we issue what's called a rack route.
1654160	1657360	So this is going to build that new ACE for us.
1658140	1669000	And if you'll see there where it says user ID equals user LEN, well, that's actually down here where we have the user ID that we want to assume the identity of.
1669440	1669700	Okay?
1669700	1671680	So all we do is we write this program up.
1672220	1678000	Then we put it into a file in Unix.
1678500	1682080	So if you've ever used the assembler on Linux, it's the same thing.
1682080	1682280	Right?
1682280	1683820	Very similar commands.
1684240	1685500	Then we link it.
1685500	1685740	Right?
1685740	1686940	Because we have to link it.
1687240	1689840	And then we make it APF authorized.
1690280	1690760	Okay?
1690760	1691480	So that's it.
1691480	1693100	That's all the steps you have to take.
1693500	1696560	And then here's a demo that we put together.
1697040	1700900	It's going to show Chad taking over my account.
1701220	1701640	Right?
1701640	1703160	So he's trying to access a file.
1703300	1705200	He's unable to access that file.
1711070	1713650	He's going to run his APF authorized program.
1713650	1716330	And now you can see he's become Phil.
1716350	1716650	Right?
1716650	1718150	He's become my user ID.
1718250	1721750	And now he's able to cat that file.
1722770	1725610	It's a file I wrote for him especially.
1725830	1727970	Because he is the coolest.
1727970	1728750	I did not write that.
1728750	1730510	This is 100% Chad demo.
1730570	1731150	All right.
1731150	1732890	Next picture of Chad.
1734430	1738470	Take Phil to a karaoke bar and get him to do regulate.
1738470	1739890	You won't be disappointed.
1739910	1741350	You will be disappointed.
1741350	1742330	I promise.
1742930	1743450	Okay.
1743450	1744350	Let's look at the next one.
1744350	1745090	Sudo root.
1745090	1746630	I know it says sudo root.
1746710	1751110	There's not really a concept of root users on the mainframe.
1751110	1751530	Okay?
1751690	1756350	So on the mainframe we actually call it super user or UID zero.
1756350	1756890	Okay?
1756890	1766890	The problem is, you know, on Linux, if you get, you know, root like UID zero, it's game over for that box.
1766890	1767110	Right?
1767110	1768250	You can do anything you want.
1768250	1770090	You can change anything you want.
1770430	1771790	World's your oyster.
1771790	1773910	That's not really true on the mainframe.
1774050	1779330	Yes, you have UID zero in Unix, but that doesn't convey anything outside of Unix.
1779330	1790950	When you log in that address space we talked about earlier in key zero, even though you sue up to root, it doesn't change your actual user and address space in the rest of the mainframe.
1792250	1793210	So here's an example.
1793210	1794610	So here I am.
1796110	1797970	My user ID is Phil.
1798150	1799510	I type the sue command.
1799510	1800930	Notice I don't have to write a password.
1800970	1802310	So I type the sue command.
1803010	1804970	Now I'm a different user.
1805870	1806570	Theoretically.
1806570	1807170	Right?
1808090	1812370	But when I do the command LU, I'm still me.
1813830	1814810	That's fine.
1814810	1816210	There's a billion ways around this.
1816210	1817810	This is just one dumb example.
1817910	1821270	I'm sure if you're creative enough, you can find a thousand different ways to do this.
1821270	1825470	But the easiest thing for us is just to add an SSH key for an admin.
1825930	1827390	So and that's really easy.
1827390	1829330	So we pick Mark, of course.
1829570	1832150	And we make the .SSH folder for him.
1832530	1834490	We then make the authorized key file for him.
1834490	1836770	Make sure the permissions are good on that file.
1836850	1839270	And then we put our public key in there.
1839330	1839810	Right?
1839810	1841150	And that's what it looks like.
1841370	1842070	Everything's fine.
1842070	1843090	Everything's good.
1843430	1846610	And then we just SSH in as them.
1846610	1847010	Right?
1847010	1850110	With our private key that we generated ourselves.
1850790	1852270	And then we're logged in as Mark.
1852290	1855990	And if you look at Mark, Mark is special operations.
1856030	1856630	So it's game over again.
1856630	1863190	I don't know if you're noticing a trend, but our two goals is either to get special operations or APF authorized.
1863190	1864710	Those are the two things.
1865230	1865490	All right.
1865490	1866330	Next one.
1868390	1871570	The lucky among you might get to play crafts with Phil later.
1871570	1873190	Damn, I'm sad I'm missing that.
1873190	1873990	Oh, thanks, Chad.
1874810	1875130	Okay.
1875130	1875830	Next.
1876030	1877290	This mount one.
1877410	1877610	Okay.
1877610	1887450	When you look at the mount points, if you've ever mounted an ISO in Linux, it's very similar.
1887670	1888070	Right?
1888070	1891770	Think of it almost like volumes in a container.
1891770	1892290	Right?
1892290	1895950	So you take every the whole file system is based on data sets.
1896010	1896150	Right?
1896150	1901350	And you mount those data sets into a location on the file system.
1901350	1902050	That's all it is.
1902150	1908810	Now, if we have update access to either of these two profiles, right?
1908810	1923730	Superuser.filesys.user mount or superuser.filesys.mount, what that means is we can mount a data set and preserve the APF bit and the set UID bits.
1923730	1928570	If we have read access to either of those profiles, then those bits are ignored.
1929110	1935330	But so and as you saw in our output, we definitely did have access to superuser.filesys.user mount.
1935430	1941310	So what we do is we create a payload on a mainframe we own.
1941310	1941450	Right?
1941450	1943070	I have a mainframe at work.
1943070	1944870	Chad has his own mainframe at his work.
1944870	1949150	So we create a data set that we that's going to be malicious.
1950010	1956990	Then we create our programs, the ones you just saw, we can make them APF authorized in our own system, right?
1956990	1958490	We can craft this payload.
1958770	1968990	We unmount it, we package it up with some JCL, we transfer it to the target mainframe, and then we receive it and do all those things, and then we run our tools.
1969250	1972010	So this is the JCL to mount that data set.
1972270	1974650	It's very familiar to, like, the mount command, right?
1974650	1981790	So we have, you know, we're going to mount the hack of the planet, and then we have a mount point that goes to slash temp slash hack the planet.
1982390	1997470	And then when we look at the output, you can see here, this one maintained the set UID bit, so now we can suit a route, get UID zero, bypass without having to do any of that fancy stuff, having access to BPX, that super user.
1997990	2001250	And you notice these programs here that are APF authorized.
2001250	2007930	Even though we don't have the ability to do that on the target mainframe, because we could mount a file system, we could do that.
2007930	2017990	Now, from here, the demos are exactly the same as the other two demos, we can either modify people's home folders or because we're APF authorized, become any user we want to become.
2020570	2021530	Great.
2022090	2027530	He wanted to tell you that he grew up on a farm and the tractors all ran on COBOL.
2027530	2032710	I highly doubt that, but all right, let's talk about buffer overflows on the mainframe.
2034410	2039570	You know that slide earlier with Ralph, and it said you can't do buffer overflows on the mainframe?
2040210	2055170	That's a myth that has been debunked multiple times, and I gave a talk last year at SHARE, SHARE being the mainframe industry conference, where someone in the audience was like telling me you can't do what you're telling us you can do.
2055170	2059230	And I'm like, guy, the whole talk is about mainframe buffer overflows, and I'm teaching you how to do it.
2059430	2061230	And he still wouldn't believe, right?
2061230	2064550	So there's still this myth that you can't overflow buffers on the mainframe.
2064550	2065870	It is so false.
2065870	2070730	Anyways, lots of programs in Unix are written in C.
2070730	2073730	C is not a memory safe programming language.
2073930	2089150	And so if you have a C program, and there's a buffer overflowable variable, and it's APF authorized, now we can execute APF authorized code because of this program, right?
2089150	2091790	How do we find APF authorized programs?
2092050	2094550	Oh, boy, this red box is way off.
2095170	2097830	So how do we find them?
2098250	2100210	We use the dash EXTA.
2100210	2101570	This is a find command.
2101590	2104770	And you use find and then dash EXTA, that's extra attribute A.
2104770	2110530	That will show us all the APF authorized programs that exist on that LPAR.
2110530	2111830	This is just one screenshot.
2111830	2113130	It kept going forever.
2113130	2114630	Am I saying that all these are vulnerable?
2114630	2115650	Probably not.
2115790	2118070	A whole bunch of them are probably not vulnerable at all.
2118270	2123230	But I know researchers who have found vulnerable programs that were APF authorized.
2124150	2127530	Unfortunately, we have like 10 minutes left.
2127810	2136130	Getting into the complexities of writing a ZOS buffer overflow would take hours of content to get you to understand it.
2136250	2143530	Fortunately for everyone here, there is hours of content available to you to learn this on your own.
2143530	2154650	Jake LaBelle gave a great talk at DEF CON 30 on how to find and exploit ZOS buffer overflows and explain the memory layout and all that stuff.
2154650	2155490	Don't take a picture yet.
2155490	2157490	There's like two more things to go through.
2158810	2160030	Chad gave a talk.
2160030	2164710	In fact, if he was here on stage, this would have been our 10‑year anniversary giving co‑talks.
2165130	2167370	We gave a talk 10 years ago.
2167730	2173330	And part of that talk, he explained how he could do buffer overflows in ZOS Unix.
2174090	2180570	And Jake and I, DEF CON 30, we taught a class on mainframe buffer overflows.
2180570	2183010	And that class is freely available.
2183490	2185050	There's a Docker container.
2185050	2195310	You run it and it walks you through step by step how to do a mainframe buffer overflow so that you can generate something that looks like this.
2195710	2195950	Okay?
2195950	2196790	Did anyone get their picture?
2196790	2197910	I saw some people trying to take pictures.
2197910	2198830	You want me to go back?
2199170	2199730	Everyone's good?
2199730	2200310	All right.
2200590	2206910	So this is doing, like, the stuff we were talking about earlier, right?
2206910	2208070	The rack routes and all that.
2208070	2212590	So this is machine code that we're going to use to overflow the buffer.
2212590	2213790	So that's shell code.
2213790	2216230	We don't call it shell code, but it's shell code.
2217910	2218370	All right.
2218370	2218850	Here we go.
2218850	2219970	Here's the next one.
2221450	2226790	You want me to say that Phil and I had a tradition of going to piano bar after every evil mainframe training.
2227010	2228950	Ask him about the fish bowls.
2229470	2230150	Be my guest.
2230150	2231070	It's fine.
2231390	2231570	Okay.
2231570	2234570	Let's talk about some honorable mentions that I see on pentests.
2234730	2246390	So remember how we mentioned that you can enhance your security by letting the ESM have, like, more security on top of the file system, right?
2246650	2265590	I have been on systems where that was done improperly, and while it looked like I didn't have read access to some folders or files, I could read every single file on the entire ZOS Unix because it was not done ‑‑ it was not secured properly.
2266290	2267650	This one's fun.
2267650	2271230	There was a shell script in bin that was world writeable.
2271230	2276710	It was in slash et cetera slash profile.
2276710	2278770	So every time someone logged in, it ran.
2278850	2286230	So I just modified it a little bit, and then when a user that was special logged in, it then made my account special.
2287710	2292150	This one is not really an exploit or anything like that, but this happened too many times, I want to let you know about it.
2292350	2305150	Please don't make your logs that go to the sim world readable or writeable, because I've been on, like, two or three mainframes now where the staging folder in Unix and the files in that folder are world writeable.
2305490	2306590	So please don't do that.
2307550	2317890	Last one is I was pentesting a mainframe, I couldn't access much in ZOS Unix, but they had a web app that had an LFI vulnerability, a local file included, and then I could read a whole bunch of files.
2318070	2321430	So I was like, I could see where they were, but I couldn't read them, but the web app could .
2322710	2327430	Now, I would be remiss if I didn't tell you how to prevent and detect these, right?
2327430	2331690	I hate watching talks at DEF CON, it's like, oh, my God, that's terrible, what do we do about it?
2331970	2332870	Too bad.
2333330	2334210	That's not what I'm here for.
2334210	2335230	That is what I'm here for.
2335230	2338490	I'm going to tell you how you prevent it and how you detect it.
2339150	2341390	So first prevention, right?
2341690	2343510	Review your file permissions.
2343650	2347370	You can just run a find command to find everything that's been chmod 7777.
2348210	2352330	Every single pentest I do, I have file permission findings.
2352470	2353930	Please check your file permissions.
2355150	2358950	Review and control access to these profiles in your ESM.
2358950	2368270	They are the same profiles, doesn't matter if you're on ACF2, top secret, RECF, make sure access to these profiles is limited.
2368270	2375610	In fact, I would argue no one needs to have this access unless it's a break glass account, right?
2376790	2378690	Test your file permissions.
2378690	2385710	Even though the file permissions look correct, there might be something in your ESM that's overriding those permissions.
2386950	2388850	Okay, now let's talk about detection.
2389950	2394790	Monitor, we put, we say log, monitor your SMF messages.
2394790	2398210	SMF is the logging facility for ZOS.
2399870	2402250	Someone who's using BPX.superuser.
2402250	2407550	So every time you type sue, the operating system goes and says, hey, does this user have BPX.superuser?
2407790	2409190	And then it says yes.
2409190	2410190	Or it says no.
2410630	2412810	If it says yes, you should probably be monitoring for that.
2412810	2413570	Who's using it?
2413570	2414750	Why are they using it?
2414750	2418250	Same with the BPX.fileATTR.APF.
2418310	2419650	No one should really have that.
2419650	2423010	That should be something that you're installing updates or patches.
2423010	2425550	But no one should just have that as a blanket access, right?
2425610	2431350	If someone is using it, it should be traceable back to a request or a ticket of some sort.
2431470	2437270	And then obviously the mount commands, again, users shouldn't be mounting things as a superuser.
2437270	2440570	That should be all done by the operating system during startup, right?
2441390	2443490	No one should really have that access.
2443650	2445810	Unless it's like a break glass situation.
2447530	2451310	Detect large number of unauthorized attempts to access files.
2451310	2457490	You'll understand, like, it will log every failure when I run my OBS enum script.
2457490	2460370	It's looking for files and it'll tell you, like, access denied, access denied.
2460790	2462730	Those all get logged somewhere, right?
2462730	2467230	No one has ever come to me after a pen test and be like, hey, did you try to access, like, 30,000 files?
2467390	2467890	Never.
2467890	2469530	Because no one's monitoring it.
2470490	2481650	Detect multiple, obviously, look, if you're trying to see someone do connections out to AWS on your, like, firewalls and whatnot from the mainframe, that's probably a good indicator of compromise, right?
2481650	2482730	Something to check for.
2482730	2486910	Because the mainframe should have very well understood and well-known patterns of connectivity.
2486910	2489210	There should be nothing exciting happening there.
2490050	2493310	And then we're going to talk about the Unix file system auditing.
2493310	2497310	This is, like, very unique to ZOS Unix.
2497390	2509130	So when we run ZOS Unix and we issue LS with a capital W, we get this new column here, right?
2509130	2512970	And this column is the audit column, right?
2512970	2514750	That's what's happening here.
2514750	2516590	So let's take a closer look.
2517290	2519470	It's split up into two parts.
2519470	2522130	The first part is user controlled.
2522130	2531070	So if you have read, write, execute access to that file, you can modify those settings.
2531170	2534650	The other three are admin controlled.
2534810	2540350	So if an admin wants to set so you could set it as, like, hey, I don't want any audit records for this file.
2540350	2546430	But your admin could set something that says, hey, I want to know anytime someone changes that file, right?
2546430	2549510	And you as the user, you cannot change it back.
2549510	2550930	This is the default.
2550930	2553030	So FFF, F for fail.
2553330	2554890	And then no admin control.
2554890	2558210	This is the default for every file created in ZOS Unix.
2558210	2560590	If you list any file, that's the default.
2561850	2567110	And the way it's broken down is very Unix-y, read, write, execute.
2567110	2572490	So if I try to read the file and it fails, it's going to write an SMF record.
2572510	2575030	If I try to write the file and it fails, it's going to write.
2575030	2576970	And if I try to execute, it's going to do that.
2577270	2582270	Now, much like you can CH modify, you can CH audit a file.
2582810	2584690	And so use the CH audit command.
2584690	2588490	And what we're going to do is say I want success and failures.
2589050	2593650	And now when we run that same command, you can see now they say all.
2594150	2600210	So now I have all anytime someone accesses that file, anytime someone writes that file.
2600210	2602510	Now, this is a little extreme.
2602710	2613170	Don't do this for every file, but you should know what files are critical to your mainframe and you should know, hey, if someone makes a change to this file, we want to know about it, right?
2613170	2614350	Things in slash et cetera.
2614350	2617770	Probably a good idea to know who's mucking around in slash et cetera, right?
2618770	2619430	Okay.
2619470	2623310	So with that, we're nearing the end of the presentation.
2623770	2630610	I have to do some shout outs to, you know, because I'm up here because of the efforts of a lot of other people.
2630790	2633510	So first I want to say thank you to DEF CON for having me come here.
2633510	2634990	I really appreciate you all.
2635430	2642510	The mainframe hacker community, when Chad and I started doing this, the mainframe hacker community was two people.
2642550	2643630	Chad and I.
2643750	2644330	Okay?
2644930	2647490	Over time, that has grown.
2647490	2650230	The second ‑‑ the third member was Henry, Wizard of ZOS.
2650230	2654890	And over time that has grown, so now there's like a good two dozen of us.
2655050	2658950	And we chat and we all know each other and we share ideas and whatnot.
2658950	2661130	So I have huge thanks for them.
2661230	2668710	The MotionX Discord, if you're not a mainframe person and you're like, oh, man, this is interesting, go watch MotionX's videos.
2668970	2669970	Go to the Discord.
2669970	2671430	It's super welcoming.
2671730	2675270	It's not very ‑‑ do not go to mainframe forums.
2675270	2677250	It is the most adversarial place on earth.
2677430	2678690	Go to the MotionX Discord.
2678690	2679650	It's super chill.
2679650	2680870	Everyone's there to help.
2681190	2686750	The mainframe cybersecurity community, I went to share, share made the mainframe industry conference.
2687230	2691850	And I was so nervous the first time because I thought they hated me and all these things.
2692010	2695570	In fact, a major vendor threatened to pull out if I spoke at that conference kind of thing.
2695570	2701010	But the mainframe cybersecurity community at that conference is the most welcoming and amazing community there.
2701010	2702490	So huge shout out to them.
2702650	2708090	And I do want to thank my co‑speaker, Chad, for like, you know, helping me out with this talk.
2708090	2710050	And I really ‑‑ I do really wish he was here.
2710650	2719170	If you want to contact, if you want to reach out to me in any capacity, I'm always interested if people have ideas or questions.
2719170	2721430	I will take any pull request within reason.
2721590	2725030	So if you want to look at my code, it's not good, but it works.
2725110	2725310	Right?
2725310	2730130	So if you want to take a look and reach out to me, that's totally fine.
2730410	2734490	And I'm going to leave the talk with the last quote from Chad.
2734750	2739950	So remember when I said there were two members to the mainframe hacker society and then Wizard of Zos joined us?
2739950	2741910	That's Wizard of Zos in the middle there.
2743730	2745210	It's a tight‑knit group of people.
2745210	2746230	So this is what he wrote for me.
2746230	2747530	I'm going to try to get through it.
2748270	2749590	Because it's a little long.
2749590	2750670	And I love it.
2750830	2754650	So dear Phil, in all seriousness, I am really sad I couldn't be here.
2755010	2760290	Even though I know that you absolutely kicked ass and you do not need me here to do so.
2760490	2763290	You've been one of my best friends and partners in crime for a decade.
2763290	2768490	I would not be here where I am without your friendship and knowledge and willingness to put up with my shit.
2768730	2773070	I cannot wait to see what the next decade of hacking the Gibson with you brings.
2773630	2776150	And with that, I want to thank everyone for being here.
2776330	2778350	And that's the end of my talk.
2779430	2779970	Yeah!
2779970	2781110	I heard that!
