WEBVTT

00:00.000 --> 00:00.780
All right.

00:00.780 --> 00:05.560
You may have heard of mainframe pen testing and exploitation.

00:05.980 --> 00:07.520
Mainly from our next speaker.

00:08.260 --> 00:11.720
DEF CON, please give a welcome to the soldier of Fortran.

00:14.520 --> 00:15.400
Wow.

00:15.540 --> 00:16.400
That was awesome.

00:16.400 --> 00:17.520
The other room cheered for me.

00:17.520 --> 00:18.360
That was great.

00:19.320 --> 00:20.220
Morning, everybody.

00:20.220 --> 00:23.600
I really appreciate you all coming to a Sunday morning talk at DEF CON.

00:23.780 --> 00:25.360
Front row, I'm going to need your help.

00:25.360 --> 00:27.200
I can't see anybody else.

00:27.520 --> 00:31.700
And if my hand starts to drop and you can't hear me anymore, can you guys just be like, hey.

00:32.180 --> 00:32.620
Thank you.

00:32.620 --> 00:33.940
Thank you so much.

00:34.040 --> 00:34.700
All right.

00:34.700 --> 00:38.600
So for those who don't know, my name is Phil Young.

00:38.600 --> 00:42.100
I'm the director of ‑‑ I'm just waiting for them to calm down.

00:42.100 --> 00:43.580
I don't know what's going on over there.

00:44.520 --> 00:47.400
So I'm the director of mainframe pen testing at NetSpy.

00:47.620 --> 00:51.160
You might also know me by my other name, soldier of Fortran.

00:51.480 --> 00:55.700
I was a mainframe hacker, like a 90s hacker kid.

00:55.940 --> 01:00.860
I was a mainframe security enthusiast before I started doing this professionally.

01:01.460 --> 01:04.680
I'm a terrible karaoke singer.

01:05.340 --> 01:10.680
And just so folks know, I always felt like an outsider, even in this community.

01:10.680 --> 01:15.400
This is my third time speaking at DEF CON, and I still sometimes feel like an outsider.

01:15.400 --> 01:18.640
So if you feel like that, don't ‑‑ everybody feels like that.

01:18.720 --> 01:23.340
I've been doing professional mainframe pen testing for about ten years.

01:24.020 --> 01:26.740
This was supposed to be a co‑talk.

01:27.500 --> 01:30.540
But unfortunately, my co‑speaker is no longer with us.

01:31.460 --> 01:34.980
He had to go home to take care of his kid going to college.

01:34.980 --> 01:36.280
So he's not here.

01:38.080 --> 01:40.420
So ‑‑ but still going to talk about him.

01:40.420 --> 01:42.280
So he was a 90s hacker kid.

01:42.760 --> 01:44.480
He was also a mainframe security enthusiast.

01:44.480 --> 01:45.680
He loves show tunes.

01:45.680 --> 01:47.360
He's really good at reverse engineering things.

01:47.360 --> 01:50.360
Probably the best reverse engineer I know, especially when it comes to mainframes.

01:50.940 --> 01:52.120
Dude's a freaking genius.

01:52.600 --> 01:55.520
He's also been testing mainframes for ten years.

01:55.600 --> 02:00.200
Now, there's a third person in this photo who we didn't invite.

02:00.260 --> 02:04.620
But he's the OG mainframe hacker.

02:04.880 --> 02:07.820
And we want to make sure we shine a light on him as well.

02:08.100 --> 02:16.740
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.

02:17.020 --> 02:17.360
Right?

02:17.360 --> 02:19.460
At mainframe conferences, not places like DEF CON.

02:19.460 --> 02:21.300
We're trying to get him to come to DEF CON for years.

02:21.560 --> 02:26.460
But I want to make sure we talked about him because he is the OG for mainframe hacking.

02:26.960 --> 02:32.900
Now, since Chad and I have been friends for the better part of ten years, I need help with my code.

02:32.900 --> 02:35.240
I'm a great coder, especially when it comes to assembly.

02:35.460 --> 02:43.600
And so I will oftentimes send my code to Chad so that he can help review the code because it doesn't work.

02:43.900 --> 02:44.420
Right?

02:44.580 --> 02:50.080
And every time I send him a piece of code, he puts me on blast on Twitter first.

02:50.380 --> 02:52.300
Then he fixes it.

02:52.740 --> 03:00.960
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.

03:01.540 --> 03:03.740
Not telling him what they're going to be for.

03:04.140 --> 03:10.480
And then I said, hey, I want you to give me quotes that I will put in the talk.

03:10.580 --> 03:12.020
So remember this slide.

03:12.100 --> 03:13.160
Look at the bottom.

03:13.160 --> 03:14.460
Yes, I did write that.

03:14.460 --> 03:15.820
I hope it's enough.

03:16.300 --> 03:16.800
Okay?

03:17.040 --> 03:27.980
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.

03:28.860 --> 03:33.820
So the first thing he sends me with respect to this slide is he said, it was not enough.

03:34.180 --> 03:35.180
So thanks, Chad.

03:35.180 --> 03:36.340
I appreciate you.

03:36.800 --> 03:37.600
This is not so bad.

03:37.600 --> 03:40.580
I can actually see a bunch more of you than I thought.

03:40.580 --> 03:42.240
So we're going to try this out.

03:42.480 --> 03:49.320
Who here can tell me where the main frame is in this picture?

03:51.700 --> 03:52.480
Don't be shy.

03:52.480 --> 03:53.580
You can just yell it out.

03:55.360 --> 03:58.040
The system... someone said system in the back.

03:58.040 --> 03:59.820
Can you be a little more specific?

04:03.620 --> 04:04.440
Where the tapes are.

04:04.440 --> 04:04.920
No.

04:07.220 --> 04:08.220
This guy put his hand up.

04:08.220 --> 04:08.700
Yes.

04:12.010 --> 04:16.190
The red box in the corner that says 360 on it, that's the main frame.

04:16.190 --> 04:18.110
That is the main frame.

04:18.110 --> 04:23.290
The reason it's called a main frame is because it holds all the CPUs and memory.

04:23.450 --> 04:30.730
It is the main frame, that's where the word comes from, where you host all the CPU, all that stuff.

04:30.730 --> 04:32.650
The rest of this is just IO.

04:32.890 --> 04:38.330
You've got your terminal, you've got your card reader, you've got a dude pressing buttons for some reason.

04:38.950 --> 04:41.450
But everything in that one thing, that's the main frame.

04:41.450 --> 04:46.750
Now, today, in a modern data center, this is what the main frame looks like.

04:46.790 --> 04:48.210
It's exactly the same.

04:48.210 --> 04:53.090
The only difference is, this is the main frame.

04:53.510 --> 05:06.830
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.

05:06.830 --> 05:11.930
And it's doing it flawlessly, and it's the workhorse of the enterprise.

05:12.570 --> 05:15.910
And lots of enterprises still rely on this platform.

05:15.910 --> 05:25.650
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.

05:25.650 --> 05:32.970
There's so many announcements, this company's moving off the main frame, there's never announcements, we successfully moved off the main frame.

05:33.190 --> 05:34.610
They never do.

05:34.850 --> 05:38.550
Some CIO comes in, starts the process, they got about halfway, and that CIO quits.

05:38.670 --> 05:40.190
That's usually the steps.

05:40.310 --> 05:43.750
But so many companies rely on this platform today.

05:44.210 --> 05:46.430
You've got airlines rely on it.

05:46.430 --> 05:50.370
I mean, if you flew on any of the major airlines, a main frame was processing your transactions.

05:50.530 --> 05:56.050
Every time you use your credit card or debit card, main frames are involved in some capacity.

05:56.410 --> 06:01.950
Auto manufacturers, obviously banks, but even companies like UPS use main frames.

06:02.230 --> 06:08.790
If it's older than, say, like, it's like a 50 year old plus company, guaranteed they're using a main frame.

06:09.090 --> 06:18.070
Before we get too far into the talk, I need to talk about some terminology that's important for you all.

06:18.450 --> 06:23.830
So, you know, RACF is what's called an external security manager.

06:23.830 --> 06:26.310
So there's actually three of them.

06:26.410 --> 06:28.890
RACF, top secret, and ACF2.

06:29.010 --> 06:35.210
Now, it's called external security manager even though it runs on the main frame as part of the operating system.

06:35.590 --> 06:40.290
But think of it like Active Directory if you could replace Active Directory with something else.

06:40.350 --> 06:40.550
Right?

06:40.550 --> 06:41.830
Better or worse.

06:41.850 --> 06:43.630
It's the same concept, right?

06:43.630 --> 06:48.550
So the reason is the operating system itself doesn't really care.

06:48.550 --> 06:51.450
It just asks what's called the SAF router.

06:51.450 --> 06:52.570
And it says, hey, is this okay?

06:52.570 --> 06:54.570
And the router knows which product to route it to.

06:54.570 --> 06:56.550
You can only run one at a time.

06:56.690 --> 06:58.030
So that's RACF.

06:58.070 --> 07:02.970
Now, RACF controls sort of all the security permissions on the main frame.

07:03.630 --> 07:08.570
In RACF, there are user attributes called special and operations.

07:08.870 --> 07:19.930
Special and operations allows you to edit any file, to change any file, to give yourself whatever permissions you want in the RACF.

07:19.930 --> 07:24.970
If you have system special but not operations, you can give yourself operations.

07:25.390 --> 07:25.870
Right?

07:25.870 --> 07:32.030
If you have operations but not special, you can download the RACF database and crack all the passwords.

07:32.030 --> 07:32.270
Right?

07:32.270 --> 07:36.150
So either or gives you complete control over the system.

07:36.190 --> 07:47.930
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.

07:48.190 --> 07:54.350
Very similar concept, but you can get into essentially ring zero so long as you put your binaries in there.

07:54.350 --> 07:56.970
That is the control that mainframes use.

07:57.090 --> 08:05.150
Basically, when you put a program in that folder, it is allowed to run in a supervisor state with the CPU.

08:05.150 --> 08:06.230
That's what it means .

08:06.230 --> 08:08.670
That's how they control how programs can run.

08:08.970 --> 08:12.890
Key zero is ‑‑ this is all terminology you know.

08:12.890 --> 08:17.850
Key zero is the ‑‑ every page of memory has a key.

08:18.350 --> 08:26.350
Key zero, if your process is running in key zero, you can edit any page of memory you want.

08:26.450 --> 08:29.710
Otherwise, the only other time that works is if your keys match.

08:29.710 --> 08:29.850
Right?

08:29.850 --> 08:35.070
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.

08:35.070 --> 08:36.430
But if not, I can't.

08:37.390 --> 08:44.630
Now, we would like to think that, you know , there are myths about mainframes, right?

08:44.630 --> 08:53.030
But when it comes to these myths, this is a slide that Chad gave a talk on ten years ago.

08:53.450 --> 08:57.390
And even today, we keep hearing about these myths.

08:57.390 --> 08:57.570
Right?

08:57.570 --> 08:58.870
It is crazy.

09:00.010 --> 09:00.250
Okay.

09:00.250 --> 09:04.970
So there's really four main attack paths on the mainframe.

09:05.150 --> 09:08.410
You get your network attacks, right?

09:09.170 --> 09:10.950
Normal network type attacks, right?

09:10.950 --> 09:12.650
Nmap works fine, all these things.

09:12.650 --> 09:14.830
On top of that, though, we have SNA networks.

09:14.830 --> 09:18.590
That's a completely different type of network that runs.

09:19.090 --> 09:20.870
We have the file system, right?

09:20.870 --> 09:27.810
You would be surprised sometimes on pen test, I go in and I see ‑‑ I have, like, write access to 30,000 data sets.

09:28.190 --> 09:33.450
Or read access to, like, sensitive company information, like, 110,000 data sets.

09:33.450 --> 09:34.530
It is crazy.

09:35.190 --> 09:36.450
External security manager.

09:36.450 --> 09:37.590
That's the other attack path.

09:37.590 --> 09:41.250
That's where we go in and we look at, oh, do I have access to this?

09:41.250 --> 09:41.970
Do I have access to that?

09:41.970 --> 09:48.070
And in fact, some of the things we're going to talk about today are because of misconfigurations in the external security manager.

09:48.390 --> 09:52.690
And lastly, what this bulk of this talk is about is ZOS Unix.

09:53.110 --> 10:06.910
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?

10:06.910 --> 10:10.790
It is such a familiar thing to you, especially if you use Linux.

10:10.790 --> 10:12.870
In fact, I have a pretty good view of the audience.

10:12.870 --> 10:15.590
Can I have a show of hands who's familiar with Linux?

10:16.070 --> 10:16.510
Right?

10:16.510 --> 10:18.030
Like, most of the audience, right?

10:18.030 --> 10:19.050
So that's good.

10:19.090 --> 10:23.130
Because it's very similar, but also a little bit different.

10:23.210 --> 10:23.870
Right?

10:24.510 --> 10:26.990
So it's based on system V, right?

10:26.990 --> 10:28.110
Or system V.

10:28.650 --> 10:34.030
And it really didn't get built out until mid‑90s, right?

10:34.030 --> 10:38.090
So the IBM operating system is called ZOS, right?

10:38.090 --> 10:39.550
So it runs ZOS.

10:39.550 --> 10:42.430
And inside ZOS, you run Linux.

10:42.430 --> 10:43.970
Or you run Unix, sorry.

10:44.750 --> 10:46.610
It was developed in 1994.

10:46.790 --> 10:49.230
It wasn't really a core part of the operating system.

10:49.230 --> 10:54.190
It was based on, those kind of things.

10:54.550 --> 11:00.950
And in 96, it obtained POSIX compliant, and it took over running TCPIP for ZOS.

11:00.950 --> 11:03.430
Prior to that, it was all jobs and stuff.

11:03.430 --> 11:08.470
But instead, they just built the TCPIP implementation on Unix.

11:08.490 --> 11:12.930
They rebranded it in 98 to Unix system services.

11:13.210 --> 11:15.490
And it continued to grow a little bit more.

11:15.530 --> 11:20.370
And then today, they rebranded it again to ZOS Unix.

11:20.430 --> 11:23.330
And for those curious, Linux was released in 91.

11:23.410 --> 11:25.210
So just a little timeline.

11:25.530 --> 11:29.430
Now, when it comes to Unix, again, it's like Linux.

11:29.470 --> 11:31.030
It's a little bit different.

11:31.210 --> 11:33.010
You only get two shells.

11:33.450 --> 11:35.350
BINSH, which sucks.

11:36.030 --> 11:37.930
BINTCSH, which sucks a little less.

11:37.930 --> 11:39.310
They're both not great.

11:39.630 --> 11:41.370
But that's all we get.

11:43.330 --> 11:44.490
Everyone here knows Linux.

11:44.490 --> 11:48.230
I'm not gonna explain how file systems work in POSIX environments.

11:48.310 --> 11:50.470
You get file permissions, right?

11:50.470 --> 11:51.410
Regular file permissions.

11:51.410 --> 11:52.910
But here's where it gets a little funky.

11:53.470 --> 11:58.870
You can also have other permissions that you put into your ESM, right?

11:58.870 --> 11:59.710
Like RACF.

12:00.070 --> 12:05.290
So you can have, say, I have read access to this file according to the file system.

12:05.290 --> 12:07.550
But when I try to read it, RACF says no.

12:07.650 --> 12:09.630
That folder is only for admins.

12:09.970 --> 12:10.610
Right?

12:10.690 --> 12:14.790
Where that gets challenging is sometimes you can mix those up and not do a great job.

12:15.950 --> 12:17.370
You access the Unix environment.

12:17.370 --> 12:19.450
There's a whole bunch of ways to access the Unix environment.

12:19.750 --> 12:24.130
You access it through the OMVS command in TSO.

12:24.250 --> 12:27.890
So there's other talks about hacking in TSO.

12:27.890 --> 12:30.590
But you just type OMVS and you get a Unix prompt.

12:31.570 --> 12:34.590
SSH sessions, which is what we're gonna use for this talk, right?

12:34.590 --> 12:39.370
Because we're trying to demonstrate how you can do all of this in Unix.

12:39.790 --> 12:48.290
Or you can use JCL, you can use BPX bash, you can use REC scripts, you can call it from C programs.

12:48.290 --> 12:49.270
There's all kinds of things you can do.

12:49.270 --> 12:50.730
Assembly programs.

12:50.870 --> 12:50.930
Right?

12:50.930 --> 12:57.490
I know Chad wrote a module for Metasploit that spawns a Unix shell using assembly.

12:57.490 --> 12:59.490
So you can call it all kinds of ways.

12:59.490 --> 13:07.470
What's interesting is you can also access datasets from within Unix using this super funky command, right?

13:07.470 --> 13:15.570
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.

13:15.790 --> 13:18.930
It's frustrating because only a handful of commands support it, and it's not clear.

13:18.930 --> 13:21.230
So, like, I know copy works.

13:21.390 --> 13:25.510
I know cat works, because a client I was on wouldn't let you copy a dataset.

13:25.670 --> 13:29.290
So I just catted it and piped it out, like, redirected the output.

13:30.090 --> 13:32.710
Grep does not support it for some reason.

13:32.710 --> 13:35.890
So it just sort of, like, depends on what IBM wanted to do.

13:37.050 --> 13:41.430
Now, again, if you're familiar with Linux, this should all be very familiar.

13:41.790 --> 13:42.230
Right?

13:42.810 --> 13:44.530
It's close enough.

13:44.810 --> 13:44.970
Right?

13:44.970 --> 13:47.790
You've got normal commands.

13:47.790 --> 13:49.550
You've got your normal stuff going on here.

13:49.550 --> 13:50.930
You can cat files.

13:51.290 --> 13:57.270
The fact that it's positive compliant means you can do all the normal things you can do in a Unix environment.

13:57.350 --> 13:57.930
Right?

13:57.930 --> 14:02.250
It's not some crazy thing going on.

14:03.130 --> 14:03.790
Okay.

14:03.790 --> 14:06.490
So here's the next Chad quote.

14:07.890 --> 14:09.810
I can see it on my screen here.

14:09.810 --> 14:10.130
I don't...

14:11.210 --> 14:13.230
Ask me about Vegas fill.

14:13.690 --> 14:14.390
That's it.

14:14.390 --> 14:16.270
So I'm not going to leave time for questions, just so you know.

14:16.270 --> 14:18.130
So don't... so good luck.

14:18.270 --> 14:18.910
All right.

14:19.530 --> 14:27.110
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.

14:27.110 --> 14:27.470
Right?

14:27.570 --> 14:32.990
Because there's lots of tools and stuff that exist now that we didn't have, like, ten years ago.

14:33.350 --> 14:36.190
And it's important to understand how we start...

14:36.190 --> 14:38.890
Jumping in straight to the end sucks.

14:39.550 --> 14:42.750
So there's a whole bunch of tools that exist today.

14:43.250 --> 14:46.490
These didn't exist ten years ago because Chad and I wrote them.

14:46.630 --> 14:48.990
So you have a tool called enum.

14:48.990 --> 14:50.390
That's a Rex script.

14:50.670 --> 14:53.950
So for those who don't know, Rex is a scripting language.

14:54.370 --> 14:54.670
If you...

14:54.670 --> 14:55.290
Actually, quick question.

14:55.290 --> 14:57.090
Who here ever used an Amiga?

14:58.170 --> 14:58.970
Yeah!

14:59.270 --> 15:00.750
That's way more than I thought.

15:00.750 --> 15:02.470
Amiga came with Rex.

15:02.910 --> 15:04.950
Rex is a scripting language.

15:04.950 --> 15:08.110
It was created by IBM as a 10% project.

15:08.110 --> 15:11.730
But anyways, Rex runs in Unix natively.

15:11.850 --> 15:14.490
And so we write a bunch of our scripts in Rex.

15:14.710 --> 15:18.770
We also have another script called OVS enum.

15:18.930 --> 15:21.890
And that script is based on Linium.

15:21.890 --> 15:23.270
I'll get into that script in a bit .

15:23.270 --> 15:27.270
We also have a couple of Java tools called File Traversal and Zoss Hog.

15:27.270 --> 15:29.970
Those allow us to map out the file system.

15:29.970 --> 15:31.210
Do we have read access?

15:31.210 --> 15:32.970
Are there passwords in them?

15:33.290 --> 15:37.970
And then we have another tool called Port Scan, which we'll talk about when we get to egress.

15:38.610 --> 15:42.310
All of this is freely available on my GitHub.

15:42.410 --> 15:47.350
So if you wanted to test them out or play with them, they're freely available.

15:47.670 --> 15:48.230
Right?

15:49.310 --> 15:53.970
And if you have a keen eye, you may have saw there was a file called all.jcl.

15:55.650 --> 16:01.210
Getting things onto the mainframe during a pentest can be very challenging sometimes.

16:02.310 --> 16:04.170
If you have to upload one file, it's a pain.

16:04.170 --> 16:06.510
If you have to upload multiple files, it's a bigger pain.

16:06.530 --> 16:09.750
Companies, for some reason, try to limit your ability to upload.

16:09.910 --> 16:11.390
There's always a way around it.

16:11.390 --> 16:11.450
Right?

16:11.450 --> 16:12.810
There's always a way around it.

16:12.810 --> 16:19.190
So what we do is we package everything up, all of those scripts into one JCL, and then it just runs by itself.

16:19.570 --> 16:20.950
It adds all those programs.

16:20.950 --> 16:24.510
Now, how do we get it to the mainframe?

16:25.010 --> 16:26.910
You can just use SCP.

16:27.570 --> 16:33.490
Problem is, SCP only supports binary file transfer.

16:34.750 --> 16:36.810
And I'm sure as you're reading the slide, you're kind of seeing why.

16:36.810 --> 16:39.170
Does anybody want to guess why that's a problem?

16:40.690 --> 16:40.950
Okay.

16:40.950 --> 16:41.110
Yes.

16:41.110 --> 16:41.510
A hand up.

16:41.510 --> 16:45.630
You don't have to yell because there's like... yes, character encoding.

16:45.630 --> 16:49.990
So code pages are files written in ASCII or UTF-8.

16:50.510 --> 16:52.470
The mainframe speaks EBCDIC.

16:52.750 --> 16:54.830
So we have to convert it to EBCDIC.

16:55.070 --> 16:57.810
So that's what we do, and then we upload it, and it's all good.

16:58.190 --> 17:05.330
For the purposes of this talk, whenever you see the blue prompt, that's when we're in Linux.

17:05.330 --> 17:06.950
So we're doing something to prep.

17:06.950 --> 17:08.110
That's our staging.

17:08.670 --> 17:13.010
If you see this prompt, that means we're on the mainframe.

17:13.010 --> 17:13.570
Okay?

17:13.810 --> 17:15.590
Now, let's take a look at enum.

17:15.590 --> 17:17.270
So this is that enum rec script.

17:17.470 --> 17:21.710
So what this script does is it pulls information from memory.

17:21.790 --> 17:28.570
So it does a really good job of accessing things from memory, because we have read access to a lot of memory space.

17:28.570 --> 17:34.530
And it dumps information out about the operating system, about the current running environment.

17:34.850 --> 17:36.930
And it's been built... like, it wasn't just me.

17:36.930 --> 17:40.510
There's other people that helped JTAY and other people who have helped build this.

17:40.990 --> 17:43.870
Some things in memory are not documented.

17:44.150 --> 17:46.330
And so we sort of reverse engineer those.

17:46.330 --> 17:50.390
And what's interesting about this program is sometimes you're limited.

17:50.390 --> 17:52.750
You can't list these things.

17:52.750 --> 17:54.990
But it exists in memory if you know where to look.

17:54.990 --> 17:56.050
So that's what this rec script does.

17:56.050 --> 17:59.050
I use it on every single pentest.

17:59.250 --> 18:04.030
The next script we have is based on linenum.

18:04.270 --> 18:05.050
Okay?

18:05.050 --> 18:07.530
But I had to rewrite it for TCSH.

18:07.690 --> 18:13.550
And then what we did is we added a whole bunch of mainframey type stuff to it.

18:13.750 --> 18:15.930
So you'll see us running it here in a second.

18:16.290 --> 18:20.570
And if you're wondering why it's going to be on VS said here, you can come talk to me after.

18:20.930 --> 18:22.130
But we're going to run it.

18:22.150 --> 18:23.890
We're going to tell it to send it to a report.

18:23.890 --> 18:28.150
And what's going to happen is it's going to go through and dump all kinds of information, right?

18:28.150 --> 18:29.910
And you'll see some more mainframey stuff.

18:29.910 --> 18:35.670
So the stuff that's going to be in all caps here in a second, that's a list user command from RACF, right?

18:35.670 --> 18:37.110
So it dumps all kinds of information.

18:37.110 --> 18:38.830
And then we comb through it later.

18:39.670 --> 18:42.470
The other thing we always test for is egress busting.

18:42.650 --> 18:53.190
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.

18:53.970 --> 18:58.730
But we're able to go from the mainframe directly to AWS or some other cloud provider, right?

18:58.730 --> 19:01.310
It is crazy how often that works.

19:01.530 --> 19:05.110
And so, in fact, one of my clients, we did the test.

19:05.190 --> 19:11.810
I wrote it up saying, hey, you have, like, thousands of ports, like, are allowed to no egress filtering out to this AWS host.

19:11.910 --> 19:16.590
And they go, we haven't used that ISP for ten years.

19:16.630 --> 19:19.210
We have no idea how this is routing, right?

19:19.210 --> 19:21.890
So anyway, it's not really that hard.

19:21.890 --> 19:23.490
We use a Java program.

19:23.490 --> 19:27.450
The reason it's in Java is most mainframes come with Java, right?

19:27.450 --> 19:28.570
By default.

19:28.690 --> 19:32.170
Also, it allows us to control the time out of the packets.

19:32.510 --> 19:35.130
And then we just do a port scan, essentially a SYN scan.

19:35.170 --> 19:40.250
And then on the Linux box, we run a tool called egress tester, which is a fork of egress buster.

19:40.530 --> 19:42.070
And you can see all the open ports.

19:43.450 --> 19:43.790
Okay.

19:43.790 --> 19:45.250
Next picture of Chad.

19:47.070 --> 19:51.830
He wanted me to say that I sent him this hat after I told him after he told me he bought a boat.

19:51.830 --> 19:52.770
That's a true story, actually.

19:52.770 --> 19:54.710
He bought a boat and I was like, you know what he needs?

19:54.970 --> 19:56.530
Is a dumb hat with hair.

19:56.530 --> 19:58.010
Because he does not have hair.

19:58.710 --> 19:59.050
Okay.

19:59.050 --> 20:00.150
Let's talk about some analysis.

20:00.150 --> 20:03.490
Now that we've done the enumeration, we've gone through the enumeration.

20:03.490 --> 20:05.130
Let's look at some of the output.

20:05.250 --> 20:07.850
This is from enum.rex, okay?

20:07.850 --> 20:18.110
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.

20:18.190 --> 20:18.530
Okay?

20:18.590 --> 20:24.810
RACF uses either DES for the hashing algorithm or KDF AES.

20:25.250 --> 20:30.530
John the Ripper and Hashcat both support cracking RACF databases.

20:30.550 --> 20:38.210
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.

20:38.450 --> 20:42.470
It's trivial for us to crack every single password in that database.

20:42.610 --> 20:52.810
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.

20:52.930 --> 20:56.730
So if you do run a main frame, please make sure you turn on KDF AES.

20:57.490 --> 21:02.230
Now, when we look at the output, we see there's a bunch of stuff here, right?

21:02.990 --> 21:05.270
We can suit a route without a password.

21:05.790 --> 21:07.990
And we'll talk about that in detail.

21:08.390 --> 21:13.210
Files that should not be world readable, like someone obviously CH modded some stuff 777.

21:14.090 --> 21:18.010
We can mount datasets, right?

21:18.010 --> 21:23.050
Which you can normally do, but this one gives us more access than we should have.

21:23.050 --> 21:27.570
And this last one is we can issue the EXT ATTR plus A command.

21:28.670 --> 21:33.190
Now, the other tool we ran that gave some interesting output was ZossHog.

21:33.250 --> 21:40.690
ZossHog is based on TruffleHog, and it uses Regex to find secrets inside files in Unix.

21:40.690 --> 21:43.370
And when we ran it, obviously we found a password.

21:44.830 --> 21:45.230
All right.

21:45.230 --> 21:46.490
Here's the next one.

21:46.490 --> 21:47.850
God, I hate this one.

21:50.560 --> 21:54.140
Ask Phil to pronounce Java and then wiki.

21:55.160 --> 21:56.440
Java wiki.

21:57.480 --> 21:59.320
I don't think I say it incorrectly.

22:00.080 --> 22:00.340
All right.

22:00.340 --> 22:01.520
Next is privilege escalation.

22:01.520 --> 22:04.000
So now that we know what's wrong, right?

22:04.000 --> 22:06.060
We know there's some vulnerabilities on the system.

22:06.120 --> 22:08.260
We definitely have to demonstrate impact.

22:08.620 --> 22:10.860
Especially when it comes to mainframe hacking.

22:11.180 --> 22:12.940
You have to show impact.

22:12.940 --> 22:20.420
Because every not every time, I would say 99% of the time, my findings are an uphill battle with the mainframers, okay?

22:20.420 --> 22:21.680
I get so much pushback.

22:21.680 --> 22:24.900
You have to show, like, no, actually this setting is very dangerous.

22:24.900 --> 22:25.820
Look what I did.

22:25.820 --> 22:26.420
Okay?

22:26.420 --> 22:28.400
So let's talk about privilege escalation.

22:28.620 --> 22:30.880
Obviously the first one is the super easiest one.

22:30.880 --> 22:32.820
We found stored credentials, okay?

22:32.820 --> 22:34.360
So this could be lateral movement.

22:34.660 --> 22:36.320
Nine times out of ten it's not.

22:36.360 --> 22:40.440
And I would love to say this is a rare thing that I've only found once.

22:40.440 --> 22:43.760
No, I've found this multiple times, okay?

22:43.860 --> 22:46.760
So do not store password in files.

22:46.880 --> 22:50.080
Obviously if you have to, make sure the permissions are correct.

22:50.140 --> 22:51.600
And make sure you test those permissions.

22:51.600 --> 22:57.880
Because maybe your ESM is overriding those permissions and everyone has read access to it.

22:58.700 --> 22:59.920
So this is an example.

22:59.920 --> 23:02.800
This is an actual example from a client.

23:02.880 --> 23:04.660
Obviously not I rewrote it.

23:04.660 --> 23:05.900
It's not their work.

23:05.900 --> 23:07.180
But it's very similar.

23:07.240 --> 23:09.800
And we found a script like this in the user's home folder.

23:10.080 --> 23:12.280
And it was chmod 7777.

23:12.420 --> 23:14.940
Obviously because it wasn't working until someone did that, right?

23:14.940 --> 23:16.380
And then all of a sudden it started working.

23:16.880 --> 23:18.880
And had user credentials in it.

23:19.200 --> 23:21.860
And so super, super easy hack, right?

23:21.860 --> 23:23.740
Because mainframe hacking is not hard.

23:23.740 --> 23:24.760
It's not that hard.

23:25.260 --> 23:29.980
We just SSH in with the username and password, right?

23:29.980 --> 23:32.360
Like this is not rocket science, right?

23:32.360 --> 23:36.300
We type their username, we type their password, and then we get in.

23:36.440 --> 23:39.880
And the first thing you do once you connect is you make sure you know who you are, right?

23:39.880 --> 23:41.340
So I'm logged in as me.

23:42.060 --> 23:44.140
And then we have some fun.

23:44.420 --> 23:48.280
And then the next thing we do is we run the command list user.

23:48.420 --> 23:48.860
Okay?

23:48.860 --> 23:51.020
Because that actually tells us what we can do.

23:51.020 --> 23:53.200
And if you'll notice, this user has special in operation.

23:53.200 --> 23:54.380
So at this point, it's game over.

23:54.380 --> 23:56.120
We can kind of do anything we want.

23:56.220 --> 24:00.620
And the pen test turns from a pen test to now an assessment because we can read everything.

24:01.440 --> 24:02.420
Oh, great.

24:02.640 --> 24:04.480
This one's finally one not about me.

24:04.480 --> 24:15.520
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.

24:15.660 --> 24:20.840
I asked him for, like, technical quotes or inspirational quotes, and this is what he gave me.

24:22.040 --> 24:22.600
Okay.

24:22.600 --> 24:29.780
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.

24:29.780 --> 24:35.220
That is a only on the main frame command, and it's very important to understand.

24:35.460 --> 24:39.500
So we're only talking about APF authorized programs.

24:39.500 --> 24:42.660
So APF authorized programs are allowed to get into supervisor state.

24:42.820 --> 24:44.360
That's what they're allowed to do.

24:44.360 --> 24:44.820
Right?

24:44.820 --> 24:46.540
And that comes with a bunch of different things.

24:47.560 --> 24:53.980
On the regular mainframe side, you have to put them in an APF authorized program library, otherwise known as a folder.

24:54.560 --> 25:01.100
On Unix, you can actually assign programs the extra attribute A.

25:01.220 --> 25:03.640
That makes it APF authorized.

25:03.900 --> 25:04.140
Right?

25:04.140 --> 25:05.340
That's all that does.

25:05.780 --> 25:06.060
Okay?

25:06.060 --> 25:10.080
So the access to control that is BPX.file.

25:10.080 --> 25:14.200
I know it says extra, but it's fileattr.APF.

25:14.220 --> 25:16.660
So read access to that profile.

25:16.660 --> 25:18.800
Interact F lets you issue this command.

25:19.920 --> 25:22.180
Most people should not have access to do that.

25:22.380 --> 25:24.420
Now, why is it important to get APF authorized?

25:24.420 --> 25:30.980
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.

25:30.980 --> 25:32.660
Because it's the thing I didn't understand.

25:32.940 --> 25:44.020
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.

25:44.620 --> 25:44.740
Right ?

25:44.740 --> 25:46.940
And it refers to that memory region.

25:46.940 --> 25:51.160
Think of this like your ID in Linux, right?

25:51.160 --> 25:53.900
And if you can change your ID to something else.

25:53.900 --> 25:54.420
Right?

25:54.420 --> 25:55.300
Similar concept.

25:55.300 --> 25:56.520
So it sits in memory.

25:56.520 --> 26:01.900
Problem is that memory region is locked under key zero.

26:02.220 --> 26:06.900
And user processes only run under key eight.

26:06.900 --> 26:09.880
So we cannot change this region of memory.

26:09.880 --> 26:13.220
If we could, we could take over the mainframe.

26:13.220 --> 26:13.840
Right?

26:13.840 --> 26:22.700
If there's a way for us to change our key to key zero, then what we do is we just replace this.

26:22.700 --> 26:23.640
It's called the ACE.

26:24.160 --> 26:30.760
We replace our ACE with whatever user we want that exists on the system.

26:30.840 --> 26:33.220
And now we can become someone else.

26:33.220 --> 26:34.860
Preferably an admin.

26:35.340 --> 26:38.160
But how do we change our key to key zero?

26:38.160 --> 26:41.820
Well, luckily, there's an assembly macro called mode set.

26:42.360 --> 26:45.180
And we just change it to key zero.

26:46.200 --> 26:54.860
And then once we do that, to issue that macro, you must be APF authorized to issue that.

26:54.860 --> 26:55.140
Right?

26:55.140 --> 27:01.700
So in Unix, if we use that EXT ATTR command, we can make it APF authorized.

27:01.700 --> 27:03.740
Now, what does that look like technically?

27:03.740 --> 27:05.340
What does it look like in practice?

27:05.340 --> 27:07.320
So here is what it looks like in assembly.

27:07.320 --> 27:08.600
Any questions?

27:10.120 --> 27:11.060
We can move on?

27:11.060 --> 27:11.660
Great.

27:11.840 --> 27:14.200
So really, this is the command here.

27:14.200 --> 27:15.120
Oh, that's great.

27:15.640 --> 27:17.940
The boxes on my laptop worked.

27:17.940 --> 27:20.100
So this is their laptop problem.

27:20.320 --> 27:22.420
So mode set key zero.

27:22.840 --> 27:24.040
That's the command.

27:24.040 --> 27:27.440
If the program will abend if it's not APF authorized here.

27:27.440 --> 27:28.620
So that means crash.

27:28.780 --> 27:29.020
Right?

27:29.020 --> 27:30.800
So once it gets past that, you're golden.

27:30.860 --> 27:34.160
The next thing we do is we issue what's called a rack route.

27:34.160 --> 27:37.360
So this is going to build that new ACE for us.

27:38.140 --> 27:49.000
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.

27:49.440 --> 27:49.700
Okay?

27:49.700 --> 27:51.680
So all we do is we write this program up.

27:52.220 --> 27:58.000
Then we put it into a file in Unix.

27:58.500 --> 28:02.080
So if you've ever used the assembler on Linux, it's the same thing.

28:02.080 --> 28:02.280
Right?

28:02.280 --> 28:03.820
Very similar commands.

28:04.240 --> 28:05.500
Then we link it.

28:05.500 --> 28:05.740
Right?

28:05.740 --> 28:06.940
Because we have to link it.

28:07.240 --> 28:09.840
And then we make it APF authorized.

28:10.280 --> 28:10.760
Okay?

28:10.760 --> 28:11.480
So that's it.

28:11.480 --> 28:13.100
That's all the steps you have to take.

28:13.500 --> 28:16.560
And then here's a demo that we put together.

28:17.040 --> 28:20.900
It's going to show Chad taking over my account.

28:21.220 --> 28:21.640
Right?

28:21.640 --> 28:23.160
So he's trying to access a file.

28:23.300 --> 28:25.200
He's unable to access that file.

28:31.070 --> 28:33.650
He's going to run his APF authorized program.

28:33.650 --> 28:36.330
And now you can see he's become Phil.

28:36.350 --> 28:36.650
Right?

28:36.650 --> 28:38.150
He's become my user ID.

28:38.250 --> 28:41.750
And now he's able to cat that file.

28:42.770 --> 28:45.610
It's a file I wrote for him especially.

28:45.830 --> 28:47.970
Because he is the coolest.

28:47.970 --> 28:48.750
I did not write that.

28:48.750 --> 28:50.510
This is 100% Chad demo.

28:50.570 --> 28:51.150
All right.

28:51.150 --> 28:52.890
Next picture of Chad.

28:54.430 --> 28:58.470
Take Phil to a karaoke bar and get him to do regulate.

28:58.470 --> 28:59.890
You won't be disappointed.

28:59.910 --> 29:01.350
You will be disappointed.

29:01.350 --> 29:02.330
I promise.

29:02.930 --> 29:03.450
Okay.

29:03.450 --> 29:04.350
Let's look at the next one.

29:04.350 --> 29:05.090
Sudo root.

29:05.090 --> 29:06.630
I know it says sudo root.

29:06.710 --> 29:11.110
There's not really a concept of root users on the mainframe.

29:11.110 --> 29:11.530
Okay?

29:11.690 --> 29:16.350
So on the mainframe we actually call it super user or UID zero.

29:16.350 --> 29:16.890
Okay?

29:16.890 --> 29:26.890
The problem is, you know, on Linux, if you get, you know, root like UID zero, it's game over for that box.

29:26.890 --> 29:27.110
Right?

29:27.110 --> 29:28.250
You can do anything you want.

29:28.250 --> 29:30.090
You can change anything you want.

29:30.430 --> 29:31.790
World's your oyster.

29:31.790 --> 29:33.910
That's not really true on the mainframe.

29:34.050 --> 29:39.330
Yes, you have UID zero in Unix, but that doesn't convey anything outside of Unix.

29:39.330 --> 29:50.950
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.

29:52.250 --> 29:53.210
So here's an example.

29:53.210 --> 29:54.610
So here I am.

29:56.110 --> 29:57.970
My user ID is Phil.

29:58.150 --> 29:59.510
I type the sue command.

29:59.510 --> 30:00.930
Notice I don't have to write a password.

30:00.970 --> 30:02.310
So I type the sue command.

30:03.010 --> 30:04.970
Now I'm a different user.

30:05.870 --> 30:06.570
Theoretically.

30:06.570 --> 30:07.170
Right?

30:08.090 --> 30:12.370
But when I do the command LU, I'm still me.

30:13.830 --> 30:14.810
That's fine.

30:14.810 --> 30:16.210
There's a billion ways around this.

30:16.210 --> 30:17.810
This is just one dumb example.

30:17.910 --> 30:21.270
I'm sure if you're creative enough, you can find a thousand different ways to do this.

30:21.270 --> 30:25.470
But the easiest thing for us is just to add an SSH key for an admin.

30:25.930 --> 30:27.390
So and that's really easy.

30:27.390 --> 30:29.330
So we pick Mark, of course.

30:29.570 --> 30:32.150
And we make the .SSH folder for him.

30:32.530 --> 30:34.490
We then make the authorized key file for him.

30:34.490 --> 30:36.770
Make sure the permissions are good on that file.

30:36.850 --> 30:39.270
And then we put our public key in there.

30:39.330 --> 30:39.810
Right?

30:39.810 --> 30:41.150
And that's what it looks like.

30:41.370 --> 30:42.070
Everything's fine.

30:42.070 --> 30:43.090
Everything's good.

30:43.430 --> 30:46.610
And then we just SSH in as them.

30:46.610 --> 30:47.010
Right?

30:47.010 --> 30:50.110
With our private key that we generated ourselves.

30:50.790 --> 30:52.270
And then we're logged in as Mark.

30:52.290 --> 30:55.990
And if you look at Mark, Mark is special operations.

30:56.030 --> 30:56.630
So it's game over again.

30:56.630 --> 31:03.190
I don't know if you're noticing a trend, but our two goals is either to get special operations or APF authorized.

31:03.190 --> 31:04.710
Those are the two things.

31:05.230 --> 31:05.490
All right.

31:05.490 --> 31:06.330
Next one.

31:08.390 --> 31:11.570
The lucky among you might get to play crafts with Phil later.

31:11.570 --> 31:13.190
Damn, I'm sad I'm missing that.

31:13.190 --> 31:13.990
Oh, thanks, Chad.

31:14.810 --> 31:15.130
Okay.

31:15.130 --> 31:15.830
Next.

31:16.030 --> 31:17.290
This mount one.

31:17.410 --> 31:17.610
Okay.

31:17.610 --> 31:27.450
When you look at the mount points, if you've ever mounted an ISO in Linux, it's very similar.

31:27.670 --> 31:28.070
Right?

31:28.070 --> 31:31.770
Think of it almost like volumes in a container.

31:31.770 --> 31:32.290
Right?

31:32.290 --> 31:35.950
So you take every the whole file system is based on data sets.

31:36.010 --> 31:36.150
Right?

31:36.150 --> 31:41.350
And you mount those data sets into a location on the file system.

31:41.350 --> 31:42.050
That's all it is.

31:42.150 --> 31:48.810
Now, if we have update access to either of these two profiles, right?

31:48.810 --> 32:03.730
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.

32:03.730 --> 32:08.570
If we have read access to either of those profiles, then those bits are ignored.

32:09.110 --> 32:15.330
But so and as you saw in our output, we definitely did have access to superuser.filesys.user mount.

32:15.430 --> 32:21.310
So what we do is we create a payload on a mainframe we own.

32:21.310 --> 32:21.450
Right?

32:21.450 --> 32:23.070
I have a mainframe at work.

32:23.070 --> 32:24.870
Chad has his own mainframe at his work.

32:24.870 --> 32:29.150
So we create a data set that we that's going to be malicious.

32:30.010 --> 32:36.990
Then we create our programs, the ones you just saw, we can make them APF authorized in our own system, right?

32:36.990 --> 32:38.490
We can craft this payload.

32:38.770 --> 32:48.990
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.

32:49.250 --> 32:52.010
So this is the JCL to mount that data set.

32:52.270 --> 32:54.650
It's very familiar to, like, the mount command, right?

32:54.650 --> 33:01.790
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.

33:02.390 --> 33:17.470
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.

33:17.990 --> 33:21.250
And you notice these programs here that are APF authorized.

33:21.250 --> 33:27.930
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.

33:27.930 --> 33:37.990
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.

33:40.570 --> 33:41.530
Great.

33:42.090 --> 33:47.530
He wanted to tell you that he grew up on a farm and the tractors all ran on COBOL.

33:47.530 --> 33:52.710
I highly doubt that, but all right, let's talk about buffer overflows on the mainframe.

33:54.410 --> 33:59.570
You know that slide earlier with Ralph, and it said you can't do buffer overflows on the mainframe?

34:00.210 --> 34:15.170
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.

34:15.170 --> 34:19.230
And I'm like, guy, the whole talk is about mainframe buffer overflows, and I'm teaching you how to do it.

34:19.430 --> 34:21.230
And he still wouldn't believe, right?

34:21.230 --> 34:24.550
So there's still this myth that you can't overflow buffers on the mainframe.

34:24.550 --> 34:25.870
It is so false.

34:25.870 --> 34:30.730
Anyways, lots of programs in Unix are written in C.

34:30.730 --> 34:33.730
C is not a memory safe programming language.

34:33.930 --> 34:49.150
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?

34:49.150 --> 34:51.790
How do we find APF authorized programs?

34:52.050 --> 34:54.550
Oh, boy, this red box is way off.

34:55.170 --> 34:57.830
So how do we find them?

34:58.250 --> 35:00.210
We use the dash EXTA.

35:00.210 --> 35:01.570
This is a find command.

35:01.590 --> 35:04.770
And you use find and then dash EXTA, that's extra attribute A.

35:04.770 --> 35:10.530
That will show us all the APF authorized programs that exist on that LPAR.

35:10.530 --> 35:11.830
This is just one screenshot.

35:11.830 --> 35:13.130
It kept going forever.

35:13.130 --> 35:14.630
Am I saying that all these are vulnerable?

35:14.630 --> 35:15.650
Probably not.

35:15.790 --> 35:18.070
A whole bunch of them are probably not vulnerable at all.

35:18.270 --> 35:23.230
But I know researchers who have found vulnerable programs that were APF authorized.

35:24.150 --> 35:27.530
Unfortunately, we have like 10 minutes left.

35:27.810 --> 35:36.130
Getting into the complexities of writing a ZOS buffer overflow would take hours of content to get you to understand it.

35:36.250 --> 35:43.530
Fortunately for everyone here, there is hours of content available to you to learn this on your own.

35:43.530 --> 35:54.650
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.

35:54.650 --> 35:55.490
Don't take a picture yet.

35:55.490 --> 35:57.490
There's like two more things to go through.

35:58.810 --> 36:00.030
Chad gave a talk.

36:00.030 --> 36:04.710
In fact, if he was here on stage, this would have been our 10‑year anniversary giving co‑talks.

36:05.130 --> 36:07.370
We gave a talk 10 years ago.

36:07.730 --> 36:13.330
And part of that talk, he explained how he could do buffer overflows in ZOS Unix.

36:14.090 --> 36:20.570
And Jake and I, DEF CON 30, we taught a class on mainframe buffer overflows.

36:20.570 --> 36:23.010
And that class is freely available.

36:23.490 --> 36:25.050
There's a Docker container.

36:25.050 --> 36:35.310
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.

36:35.710 --> 36:35.950
Okay?

36:35.950 --> 36:36.790
Did anyone get their picture?

36:36.790 --> 36:37.910
I saw some people trying to take pictures.

36:37.910 --> 36:38.830
You want me to go back?

36:39.170 --> 36:39.730
Everyone's good?

36:39.730 --> 36:40.310
All right.

36:40.590 --> 36:46.910
So this is doing, like, the stuff we were talking about earlier, right?

36:46.910 --> 36:48.070
The rack routes and all that.

36:48.070 --> 36:52.590
So this is machine code that we're going to use to overflow the buffer.

36:52.590 --> 36:53.790
So that's shell code.

36:53.790 --> 36:56.230
We don't call it shell code, but it's shell code.

36:57.910 --> 36:58.370
All right.

36:58.370 --> 36:58.850
Here we go.

36:58.850 --> 36:59.970
Here's the next one.

37:01.450 --> 37:06.790
You want me to say that Phil and I had a tradition of going to piano bar after every evil mainframe training.

37:07.010 --> 37:08.950
Ask him about the fish bowls.

37:09.470 --> 37:10.150
Be my guest.

37:10.150 --> 37:11.070
It's fine.

37:11.390 --> 37:11.570
Okay.

37:11.570 --> 37:14.570
Let's talk about some honorable mentions that I see on pentests.

37:14.730 --> 37:26.390
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?

37:26.650 --> 37:45.590
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.

37:46.290 --> 37:47.650
This one's fun.

37:47.650 --> 37:51.230
There was a shell script in bin that was world writeable.

37:51.230 --> 37:56.710
It was in slash et cetera slash profile.

37:56.710 --> 37:58.770
So every time someone logged in, it ran.

37:58.850 --> 38:06.230
So I just modified it a little bit, and then when a user that was special logged in, it then made my account special.

38:07.710 --> 38:12.150
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.

38:12.350 --> 38:25.150
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.

38:25.490 --> 38:26.590
So please don't do that.

38:27.550 --> 38:37.890
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.

38:38.070 --> 38:41.430
So I was like, I could see where they were, but I couldn't read them, but the web app could .

38:42.710 --> 38:47.430
Now, I would be remiss if I didn't tell you how to prevent and detect these, right?

38:47.430 --> 38:51.690
I hate watching talks at DEF CON, it's like, oh, my God, that's terrible, what do we do about it?

38:51.970 --> 38:52.870
Too bad.

38:53.330 --> 38:54.210
That's not what I'm here for.

38:54.210 --> 38:55.230
That is what I'm here for.

38:55.230 --> 38:58.490
I'm going to tell you how you prevent it and how you detect it.

38:59.150 --> 39:01.390
So first prevention, right?

39:01.690 --> 39:03.510
Review your file permissions.

39:03.650 --> 39:07.370
You can just run a find command to find everything that's been chmod 7777.

39:08.210 --> 39:12.330
Every single pentest I do, I have file permission findings.

39:12.470 --> 39:13.930
Please check your file permissions.

39:15.150 --> 39:18.950
Review and control access to these profiles in your ESM.

39:18.950 --> 39:28.270
They are the same profiles, doesn't matter if you're on ACF2, top secret, RECF, make sure access to these profiles is limited.

39:28.270 --> 39:35.610
In fact, I would argue no one needs to have this access unless it's a break glass account, right?

39:36.790 --> 39:38.690
Test your file permissions.

39:38.690 --> 39:45.710
Even though the file permissions look correct, there might be something in your ESM that's overriding those permissions.

39:46.950 --> 39:48.850
Okay, now let's talk about detection.

39:49.950 --> 39:54.790
Monitor, we put, we say log, monitor your SMF messages.

39:54.790 --> 39:58.210
SMF is the logging facility for ZOS.

39:59.870 --> 40:02.250
Someone who's using BPX.superuser.

40:02.250 --> 40:07.550
So every time you type sue, the operating system goes and says, hey, does this user have BPX.superuser?

40:07.790 --> 40:09.190
And then it says yes.

40:09.190 --> 40:10.190
Or it says no.

40:10.630 --> 40:12.810
If it says yes, you should probably be monitoring for that.

40:12.810 --> 40:13.570
Who's using it?

40:13.570 --> 40:14.750
Why are they using it?

40:14.750 --> 40:18.250
Same with the BPX.fileATTR.APF.

40:18.310 --> 40:19.650
No one should really have that.

40:19.650 --> 40:23.010
That should be something that you're installing updates or patches.

40:23.010 --> 40:25.550
But no one should just have that as a blanket access, right?

40:25.610 --> 40:31.350
If someone is using it, it should be traceable back to a request or a ticket of some sort.

40:31.470 --> 40:37.270
And then obviously the mount commands, again, users shouldn't be mounting things as a superuser.

40:37.270 --> 40:40.570
That should be all done by the operating system during startup, right?

40:41.390 --> 40:43.490
No one should really have that access.

40:43.650 --> 40:45.810
Unless it's like a break glass situation.

40:47.530 --> 40:51.310
Detect large number of unauthorized attempts to access files.

40:51.310 --> 40:57.490
You'll understand, like, it will log every failure when I run my OBS enum script.

40:57.490 --> 41:00.370
It's looking for files and it'll tell you, like, access denied, access denied.

41:00.790 --> 41:02.730
Those all get logged somewhere, right?

41:02.730 --> 41:07.230
No one has ever come to me after a pen test and be like, hey, did you try to access, like, 30,000 files?

41:07.390 --> 41:07.890
Never.

41:07.890 --> 41:09.530
Because no one's monitoring it.

41:10.490 --> 41:21.650
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?

41:21.650 --> 41:22.730
Something to check for.

41:22.730 --> 41:26.910
Because the mainframe should have very well understood and well-known patterns of connectivity.

41:26.910 --> 41:29.210
There should be nothing exciting happening there.

41:30.050 --> 41:33.310
And then we're going to talk about the Unix file system auditing.

41:33.310 --> 41:37.310
This is, like, very unique to ZOS Unix.

41:37.390 --> 41:49.130
So when we run ZOS Unix and we issue LS with a capital W, we get this new column here, right?

41:49.130 --> 41:52.970
And this column is the audit column, right?

41:52.970 --> 41:54.750
That's what's happening here.

41:54.750 --> 41:56.590
So let's take a closer look.

41:57.290 --> 41:59.470
It's split up into two parts.

41:59.470 --> 42:02.130
The first part is user controlled.

42:02.130 --> 42:11.070
So if you have read, write, execute access to that file, you can modify those settings.

42:11.170 --> 42:14.650
The other three are admin controlled.

42:14.810 --> 42:20.350
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.

42:20.350 --> 42:26.430
But your admin could set something that says, hey, I want to know anytime someone changes that file, right?

42:26.430 --> 42:29.510
And you as the user, you cannot change it back.

42:29.510 --> 42:30.930
This is the default.

42:30.930 --> 42:33.030
So FFF, F for fail.

42:33.330 --> 42:34.890
And then no admin control.

42:34.890 --> 42:38.210
This is the default for every file created in ZOS Unix.

42:38.210 --> 42:40.590
If you list any file, that's the default.

42:41.850 --> 42:47.110
And the way it's broken down is very Unix-y, read, write, execute.

42:47.110 --> 42:52.490
So if I try to read the file and it fails, it's going to write an SMF record.

42:52.510 --> 42:55.030
If I try to write the file and it fails, it's going to write.

42:55.030 --> 42:56.970
And if I try to execute, it's going to do that.

42:57.270 --> 43:02.270
Now, much like you can CH modify, you can CH audit a file.

43:02.810 --> 43:04.690
And so use the CH audit command.

43:04.690 --> 43:08.490
And what we're going to do is say I want success and failures.

43:09.050 --> 43:13.650
And now when we run that same command, you can see now they say all.

43:14.150 --> 43:20.210
So now I have all anytime someone accesses that file, anytime someone writes that file.

43:20.210 --> 43:22.510
Now, this is a little extreme.

43:22.710 --> 43:33.170
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?

43:33.170 --> 43:34.350
Things in slash et cetera.

43:34.350 --> 43:37.770
Probably a good idea to know who's mucking around in slash et cetera, right?

43:38.770 --> 43:39.430
Okay.

43:39.470 --> 43:43.310
So with that, we're nearing the end of the presentation.

43:43.770 --> 43:50.610
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.

43:50.790 --> 43:53.510
So first I want to say thank you to DEF CON for having me come here.

43:53.510 --> 43:54.990
I really appreciate you all.

43:55.430 --> 44:02.510
The mainframe hacker community, when Chad and I started doing this, the mainframe hacker community was two people.

44:02.550 --> 44:03.630
Chad and I.

44:03.750 --> 44:04.330
Okay?

44:04.930 --> 44:07.490
Over time, that has grown.

44:07.490 --> 44:10.230
The second ‑‑ the third member was Henry, Wizard of ZOS.

44:10.230 --> 44:14.890
And over time that has grown, so now there's like a good two dozen of us.

44:15.050 --> 44:18.950
And we chat and we all know each other and we share ideas and whatnot.

44:18.950 --> 44:21.130
So I have huge thanks for them.

44:21.230 --> 44:28.710
The MotionX Discord, if you're not a mainframe person and you're like, oh, man, this is interesting, go watch MotionX's videos.

44:28.970 --> 44:29.970
Go to the Discord.

44:29.970 --> 44:31.430
It's super welcoming.

44:31.730 --> 44:35.270
It's not very ‑‑ do not go to mainframe forums.

44:35.270 --> 44:37.250
It is the most adversarial place on earth.

44:37.430 --> 44:38.690
Go to the MotionX Discord.

44:38.690 --> 44:39.650
It's super chill.

44:39.650 --> 44:40.870
Everyone's there to help.

44:41.190 --> 44:46.750
The mainframe cybersecurity community, I went to share, share made the mainframe industry conference.

44:47.230 --> 44:51.850
And I was so nervous the first time because I thought they hated me and all these things.

44:52.010 --> 44:55.570
In fact, a major vendor threatened to pull out if I spoke at that conference kind of thing.

44:55.570 --> 45:01.010
But the mainframe cybersecurity community at that conference is the most welcoming and amazing community there.

45:01.010 --> 45:02.490
So huge shout out to them.

45:02.650 --> 45:08.090
And I do want to thank my co‑speaker, Chad, for like, you know, helping me out with this talk.

45:08.090 --> 45:10.050
And I really ‑‑ I do really wish he was here.

45:10.650 --> 45:19.170
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.

45:19.170 --> 45:21.430
I will take any pull request within reason.

45:21.590 --> 45:25.030
So if you want to look at my code, it's not good, but it works.

45:25.110 --> 45:25.310
Right?

45:25.310 --> 45:30.130
So if you want to take a look and reach out to me, that's totally fine.

45:30.410 --> 45:34.490
And I'm going to leave the talk with the last quote from Chad.

45:34.750 --> 45:39.950
So remember when I said there were two members to the mainframe hacker society and then Wizard of Zos joined us?

45:39.950 --> 45:41.910
That's Wizard of Zos in the middle there.

45:43.730 --> 45:45.210
It's a tight‑knit group of people.

45:45.210 --> 45:46.230
So this is what he wrote for me.

45:46.230 --> 45:47.530
I'm going to try to get through it.

45:48.270 --> 45:49.590
Because it's a little long.

45:49.590 --> 45:50.670
And I love it.

45:50.830 --> 45:54.650
So dear Phil, in all seriousness, I am really sad I couldn't be here.

45:55.010 --> 46:00.290
Even though I know that you absolutely kicked ass and you do not need me here to do so.

46:00.490 --> 46:03.290
You've been one of my best friends and partners in crime for a decade.

46:03.290 --> 46:08.490
I would not be here where I am without your friendship and knowledge and willingness to put up with my shit.

46:08.730 --> 46:13.070
I cannot wait to see what the next decade of hacking the Gibson with you brings.

46:13.630 --> 46:16.150
And with that, I want to thank everyone for being here.

46:16.330 --> 46:18.350
And that's the end of my talk.

46:19.430 --> 46:19.970
Yeah!

46:19.970 --> 46:21.110
I heard that!

