#!/bin/sh

#######
##### This file will generate the JCL to submit a run the Unix Enumeration
##### tooling. 
######

##### 
##  Change the following 4 lines as required to run on your system 
####

STDOUT="SYSOUT=*" # <--- Where you want the output from ENUM and OMVSENUM to go
folder='/home/phil/tet/' # <--- Folder to run tools from Make sure you have the trailing /
JAVAC='/usr/lpp/java/J8.0_64/bin/javac' # <--- Must point to a valid javac
JAVA='/usr/lpp/java/J8.0_64/bin/java' # <--- Must point to a valid java
cat << EOF
//OMVSENUM JOB (JOB),'JOB',CLASS=A,MSGCLASS=A,
//         NOTIFY=&SYSUID,REGION=0M
//*********************************************************************
//****
//**** DO NOT EDIT THIS FILE IT IS AUTO GENERATED BY THE ALL.SH SCRIPT
//****
//*********************************************************************
//*********************************************************************
//* Delete the files if they exist
//*********************************************************************
//REMOVE    EXEC PGM=BPXBATCH
//STDIN     DD DUMMY
//STDOUT    DD DUMMY
//STDERR    DD DUMMY     
//STDPARM   DD *
SH cd $folder;
 rm ENUM.rexx;
 rm OMVSEnum.sh;
 rm FileSystemTraversal.java;
 rm portscan.java;
//*********************************************************************
//PUTFILE  PROC FOLDER='$folder',FILENAME=''
//*********************************************************************
//**** Put the files in unix
//*********************************************************************
//PUTFILE  EXEC PGM=IEBGENER
//SYSPRINT DD SYSOUT=*
//SYSUT1   DD DUMMY
//SYSUT2   DD PATH='&FOLDER.&FILENAME',
//            PATHOPTS=(ORDWR,OCREAT), 
//            PATHDISP=(KEEP,DELETE),
//            PATHMODE=(SIRWXU,SIRGRP),            
//            FILEDATA=TEXT               
//SYSIN   DD  DUMMY
// PEND
//*********************************************************************
//PUTENUM EXEC PUTFILE,FILENAME='ENUM.rexx'
//PUTFILE.SYSUT1 DD DATA,DLM='@@'
EOF
cat ../ENUM
cat << 'EOF'
@@
//*********************************************************************
//PUTFSTJ EXEC PUTFILE,FILENAME='FileSystemTraversal.java'
//PUTFILE.SYSUT1 DD DATA,DLM='@@'
EOF
cat FileSystemTraversal.java
cat << 'EOF'
@@
//*********************************************************************
//PUTPOMVS EXEC PUTFILE,FILENAME='OMVSEnum.sh'
//PUTFILE.SYSUT1 DD DATA,DLM='@@'
EOF
cat OMVSEnum.sh
cat << EOF
@@
//*********************************************************************
//PUTPORTS EXEC PUTFILE,FILENAME='portscan.java'
//PUTFILE.SYSUT1 DD DATA,DLM='@@'
EOF
cat portscan.java
cat << EOF
@@
//*********************************************************************
//* Run ENUM
//*********************************************************************
//ENUMREXX  EXEC PGM=BPXBATCH
//STDIN     DD DUMMY
//STDOUT    DD $STDOUT
//STDERR    DD SYSOUT=*     
//STDPARM   DD *
SH cd $folder;
 ./ENUM.rexx SEC; 
 ./ENUM.rexx SVC; 
 ./ENUM.rexx APF; 
 ./ENUM.rexx USSU;
//*********************************************************************
//* Run OMVSENUM
//*********************************************************************
//OMVSENUM  EXEC PGM=BPXBATCH
//STDIN     DD DUMMY
//STDOUT    DD $STDOUT
//STDERR    DD SYSOUT=*     
//STDPARM   DD *
SH cd $folder;
 sed 's/[[:space:]]*$//' OMVSEnum.sh > OMVSSed.sh;
 chmod +x OMVSSed.sh;
 ./OMVSSed.sh;
//*********************************************************************
//* Compile Java Program
//*********************************************************************
//JAVAC     EXEC PGM=BPXBATCH
//STDIN     DD DUMMY
//STDOUT    DD SYSOUT=*
//STDERR    DD SYSOUT=*     
//STDPARM   DD *
SH set JAVA_HOME=/usr/lpp/java/J8.0_64;
 cd $folder;
 $JAVAC  FileSystemTraversal.java;
 $JAVAC  portscan.java;
//*********************************************************************
//* Run FileSystemTraversal 
//*********************************************************************
//RUNFSTJ   EXEC PGM=BPXBATCH
//STDIN     DD DUMMY
//STDOUT    DD SYSOUT=*
//STDERR    DD SYSOUT=*     
//STDPARM   DD *
SH set JAVA_HOME=/usr/lpp/java/J8.0_64;
 cd $folder;
 $JAVA FileSystemTraversal -w /u > u.writeable.txt;
 $JAVA FileSystemTraversal -w /etc > etc.writeable.txt;
 $JAVA FileSystemTraversal -w /opt > opt.writeable.txt;
 $JAVA FileSystemTraversal -w /usr > usr.writeable.txt;
 $JAVA FileSystemTraversal -w /var > var.writeable.txt;
//*********************************************************************
EOF
