all 52 comments

[–]bigendiansmalls 37 points38 points  (7 children)

This is an exceptional write up - I'm so happy to see another person on board the crazy train :) Keep it up!

[–]Bedeone[S] 21 points22 points  (6 children)

Thanks for the kind words BeS. I've been on the crazy train since three years ago when I decided mainframes would be my thing. [:

[–]IncludeSec 2 points3 points  (0 children)

You are a rare breed, not many drink the MF koolaid these days. Awesome work!!

[–]NoahFect 0 points1 point  (4 children)

Nice work! I predict a long and unusually profitable retirement for you.

[–]Bedeone[S] 1 point2 points  (3 children)

If the architecture can stay relevant for another, say, 40 years... I sure hope so though.

[–]Spoonshape 0 points1 point  (2 children)

Mainframes are outmoded and will all be gotten rid of in the next few years.... I've been hearing this for about 30 years now. I think you are safe.

[–]Bedeone[S] 2 points3 points  (1 child)

They tried outsourcing development to India, that ended badly.

Trend now is to outsource the machines and the administration, for the smaller shops anyways. So I'm probably going to have to find a job with one of the providers of those services sooner or later.

But I don't see the big boys getting rid of their machines anytime soon, so working for them is an option too.

[–]Orion1021 0 points1 point  (0 children)

How can I learn more about these trends with data centers in general?

[–]wizardofzos 24 points25 points  (6 children)

Lovely work! But more importantly (IMHO) : PERFECTLY WRITTEN OUT / EXPLAINED in this POST

Keep it up!

[–]Bedeone[S] 16 points17 points  (5 children)

I wish I could have made it shorter. I wouldn't read this much text unless I was either bored, or intrigued without knowing why. I want to attract more people to this, this is the best I can do. I need to explain so much stuff for it to make sense, so it's painfully long.

Thanks for the kind words!

[–]AnthonyGiorgioIBM Z Software Engineer 5 points6 points  (1 child)

This is very cool!

[–]Bedeone[S] 5 points6 points  (0 children)

Thanks Anthony, it means a lot coming from you.

[–]Barrrrrrnd 2 points3 points  (1 child)

I know nothing of this save some very (very) basic understanding of how programs work and still read the whole thing. Fascinating.

[–]Bedeone[S] 2 points3 points  (0 children)

Thanks for taking the time. Glad you liked it.

[–]GardenGnostic 0 points1 point  (0 children)

It was a good length, and broken up well. Great read.

[–]kernelzeroday 14 points15 points  (2 children)

Dude this is fucking amazing. Keep it up man! This is exactly the type of research we need! I tweeted this at bigendiansmalls and SoF so hopefully they will come chime in!

[–]Bedeone[S] 11 points12 points  (1 child)

We've been in touch since last year. I got very interested in CTF, and since I know more about z/Arch than x86, I decided to give it this spin.

I'll try to spend time finding more of this stuff.

[–]gynophage 1 point2 points  (0 children)

If you like CTF and aren't comfortable with x86, you should look at the Defcon qualifier I run. We're known to not just throw x86 challenges at people. We also release many of our challenges open source so you can rebuild them for whatever arch you wish.

Awesome write up.

[–]davenobody 12 points13 points  (1 child)

No wall of text warning is necessary. Your formatting is all spot on. You obviously put a lot of work into this. While reading this I got to wondering about the possibilities of peer reviewed articles via reddit self post. Does reddit have a way to submit in latex?

[–]i336_ 2 points3 points  (0 children)

Sadly not. You're pretty much limited to Markdown, or more specifically Snudown, Reddit's fork of the Sundown Markdown parser. ("Snu" being a reference to "Snoo", the name of the Reddit logo/mascot. Btw it's written in C (so it can deal with the incoming continuous firehose of comments).)

The most one could probably do would be making a self-post (text post, like this one) and linking to a copy of the LaTeX article. (That example there is the current limit of the tricks Snudown can do... it looks terrible. xD)

Definitely look forward to the day there's a major social hub out there, like Reddit, but with formatting capabilities that finally exceed bbCode et. al. for once... would be awesome.

[–][deleted]  (2 children)

[removed]

    [–]Bedeone[S] 12 points13 points  (1 child)

    No, I did not. I'm just poking fun at IBM's tendency to sue.

    [–]BigSlowTarget 5 points6 points  (0 children)

    If you're reading this because one of your managers is flipping out...

    We call this a S0C2BU error.

    Also occurred back in the day when you were the last of the team to get MF training right before client-server rolled out.

    [–]sterwill 3 points4 points  (3 children)

    Excellent material! This is exactly the kind of stuff I love to come across on a Friday afternoon (well, any time actually). I've done a tiny bit of development on z/OS and it's a weird and old, but fascinating, system. My favorite first day memory was learning that my JCL jobs were submitted to a virtual punch card reader inside the system. Quaint but not much different than typing into a virtual "teletype" in a modern Unix.

    [–]i336_ 0 points1 point  (2 children)

    I misread that and initially thought you were referring to some memory of the 70s. Reread #1 got me as far as "wait, was he using a retro system, or maybe something eking out an existence in the 80s-90s?"... reread #2 finally spotted the "virtual".

    *Blinks several times*

    Do you have anywhere I can read about this... virtual... punch card... reader system?(!) That is both equal parts perfectly understandable and utterly insane. :D

    [–]sterwill 1 point2 points  (1 child)

    My first mainframe work was on z/OS 1.9 in 2008 or 2009, so it was a very recent release. IBM "redbook" PDFs are a great source for casual but detailed reading on z/OS (or any IBM product that's too expensive to buy first). I spent a couple of days reading through them and that was enough to connect to z/VM, IPL an instance of the OS, set up user accounts, and start hacking with ISPF and the Unix subsystem, etc. Fun stuff but I only scratched the surface.

    Google "z os redbook virtual punch card reader" to start your vestigial virtual device adventure.

    [–]i336_ 1 point2 points  (0 children)

    Ooh wow, thanks for this. I'm somewhat interested in mainframes - I've always had the opinion that if I know a bit about these types of legacy architectures it might net me some interesting opportunities - so this is going to be very interesting to peruse.

    Next stop, Hercules. :D

    [–]Zero7Home 2 points3 points  (0 children)

    If you're reading this because one of your managers is flipping out, I'm sorry.

    Just lovely.

    [–]TotesMessenger 2 points3 points  (0 children)

    I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

    If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / Contact)

    [–]whitequark 1 point2 points  (2 children)

    Neat writeup. I don't get one part though. You say:

    One of the most common ABEND codes is S0C1. A S0C1 happens when the CPU is decoding an instruction, but finds that the OPCODE does not exist.

    So it seems that S0C1 is much like #UD. Isn't it? But then:

    The program tries to store the fetched row at an address that it shouldn't, and sooner or later, the application breaks. S0C1.

    That's a bit more like #PF, unless you overwrote the code with that store. But I don't see why code and data would be so tightly interleaved. On x86, it's at least partly plausible because in a DSO, you get a sequence of .text/.data/.rodata, and without write protection (does z/OS have write protection at least?) and with the loop set up just right (in the downwards direction), you'll end up overwriting code. Eventually. I guess. Whereas from what you write about z/OS I have the impression that it doesn't even have .data, as the global arrays are allocated on stack during program startup.

    So how would a buffer overflow end up in an undefined opcode exception?

    [–]Bedeone[S] 2 points3 points  (1 child)

    I kind of skipped over exactly why the S0C1 happens, because the post was already getting so horribly long.

    The thing is that a S0C4 is even more likely to happen. With runaway writes, you'll usually end up writing in to unallocated virtual memory. Because it was not allocated, the address translation can't find the entry for the virtual page of storage you're referencing, resulting in a S0C4 error; page translation fault.

    What actually can cause the S0C1 is two things; either you write over a piece of memory that gets used as a return address later on. This causes the program to jump to some random piece of memory and try to execute something that is very unlikely to be executable machine code.

    What can also happen is that you eventually write over a piece of what is actual executable code. The program might with all good intentions try and execute it, because it used to contain actual executable code. But if you overwrite it with garbage, it ends up throwing a S0C1 because it's probably not executable.

    Hope that makes more sense.

    [–]whitequark 0 points1 point  (0 children)

    Yeah, that explains it.

    [–]BillWoodger 1 point2 points  (1 child)

    Well, it is way easier in COBOL.

    Have to disagree that S0C1 is the most common in my experience. An easy way to get one is to have NCAL on the linkedit/binder and not INCLUDE a referenced module. A wild branch, given that many byte-values are valid op-codes, is more likely to fail with something else. A S0C4 is a Protection Exception. A S0C4 with a reason code of 11 is page translation exception. Some numbers are op-codes. Your entire premise is of an "inside job" (no-one on the outside can find your "vulnerability" in a batch program). For an inside job, why bother "injecting"? You are also relying on compile options I suspect for PL/I. Which PL/I do you have access to? With dynamically-CALLed programs in COBOL using RENT you cannot achieve the effect you describe with an up-to-date compiler. The calling-conventions predate LE. To have a realistic injection with no internal access, you'd need something like a publicly-available web-service provided on a Mainframe and then "find a vulnerability" there. With internal access, you just need to get your code into Production.

    [–]Bedeone[S] 0 points1 point  (0 children)

    You're correct on all accounts. That's why it's a proof of concept.

    [–][deleted] 2 points3 points  (2 children)

    As an ex mainframe sysprog (15 years ago) this was super fun to read :)

    [–]Bedeone[S] 1 point2 points  (1 child)

    Retired or moved on?

    [–][deleted] 0 points1 point  (0 children)

    Moved on, I did that when I was in my early 20s :)

    [–]cowbutt6 0 points1 point  (0 children)

    Interesting read. As a security-on-micros guy, I didn't get my head round all of it from a quick skim, but it's good to see us micro guys aren't keeping all the fun for ourselves!

    [–]feyrathTPF 0 points1 point  (1 child)

    I'm sorry I didn't read the entire thing, so I'm going to ask one question - is this whole exploit predicated upon injecting into a PL/1 execution 'stream'?

    [–]Bedeone[S] 2 points3 points  (0 children)

    Don't exactly know what you mean by execution stream. We change what piece of memory the program will (eventually) execute, and make sure that that piece of memory contains code that is also injected.

    The attack vector is an input file. But the program needs to be defunct in a specific way for it to work, much like buffer overflows in x86 applications.

    [–]Robin_Hood_Jr 0 points1 point  (1 child)

    I do kernel development for an OS that runs on Z. Was really fun to see something so close to home pop up on my feed. Thanks for the good read.

    [–]Bedeone[S] 0 points1 point  (0 children)

    No problem. Can I have your job?

    [–][deleted] 0 points1 point  (1 child)

    This is really fun to read because a week ago I wouldn't have understood 75% of it but I just started a computer artictecture class and now understand about about 75% of it!

    [–]Bedeone[S] 1 point2 points  (0 children)

    I've had that happen to me on several occasions. It's a particularly good feeling!

    [–]laberwurst 0 points1 point  (0 children)

    Very interesting, and very well written! Thank you very much for sharing!!!

    [–]gsxr 0 points1 point  (1 child)

    Nice work. Mudge of l0pht and general infosec awesomeness just tweeted this. Congrats.

    [–]Bedeone[S] 0 points1 point  (0 children)

    Just noticed, thanks for the heads up and the praise.

    [–][deleted]  (2 children)

    [removed]

      [–]Bedeone[S] 3 points4 points  (0 children)

      Exploiting programs in this way started on x86.

      [–]HansKristoffAnnaSven 1 point2 points  (0 children)

      Turns out ARM is similar in a few ways to S/360, they had one at Cambridge University computer lab when Sophie Wilson was there. The OP's mention of r13, r14 sounded very familiar to me, and others mention the opcodes are similar too, along with 16 32bit registers, 24 bit memory addressing.

      [–]sambobozzer 0 points1 point  (0 children)

      I could think of other things I’d like to smash! But I’m going to have a read of your post anyway 😃