• caglararli@hotmail.com
  • 05386281520

How Can I Modify a C Program to Gain Root Shell Access Without Using Sudo or Editing the Sudoers File?

Çağlar Arlı      -    15 Views

How Can I Modify a C Program to Gain Root Shell Access Without Using Sudo or Editing the Sudoers File?

I have a C program that, when executed on my Ubuntu virtual machine, provides a regular shell. The program includes the following code:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main() {
    setuid(0);
    setgid(0);
    system("/bin/sh");
    return 0;
}

I am trying to obtain a root shell without entering my root password (which is "123"). I understand that using chown and chmod also requires root privileges, which I want to avoid. Additionally, I do not want to edit my sudoers file. I am also unable to get a root shell even though the code uses setuid(0); and setgid(0); for setting the UID and GID for root. What modifications can I make to this C code or what other methods can I use to achieve a root shell without needing to enter my sudo password at all?

Note: I am aware of the security implications and risks associated with this approach, but I am looking for technical guidance on how to implement it. Feel free to use this version directly or make any further adjustments as needed!