TL;DR How does for example su or sudo work with no PAM?
Hello,
I want to play around with suid and stuff, I already got the SUID part and the SUID bit and stuff, but the problem is that it's not asking me for a password and as I want it to ask a password and find su and sudo quite mangled in source I am very confused.
I looked into setsuid() and getuid() documentation and it doesn't seem like there is anything about password authentication.
How would one achieve password authentication with no PAM, I use sudo with no pam and it works fine, su with pam, both work fine, I am confused how I'd make it work
This C++ code is what I have right now:
// a.cc //
#include <iostream>
#include <unistd.h>
#include <cerrno>
#include <cstring>
int main(int argc, char *argv[]) {
uid_t user = getuid();
if (setuid(0) == -1) {
std::cerr << strerror(errno) << '\n';
return 1;
}
system(argv[1]);
if (setuid(user) == -1) {
std::cerr << errno << '\n';
return 1;
}
return 0;
}
and after compiling it with for example GCC and the file being named a.cc:
$ g++ a.cc -o a
and giving it execute and SUID permissions and giving the ownership to root
$ sudo chown root:root ./a
$ sudo chmod 4555 ./a
it just works, but without password authentication
$ ./a id
uid=0(root) gid=1000(ari) groups=1000(ari),5(tty),10(wheel),27(video),78(kvm),250(portage)
(ari is my user)
Even after logging out or running sudo -k to
end sudo timeout it still works with no password
authentication.
- Su souce: https://github.com/shadow-maint/shadow/blob/master/src/su.c
- Sudo source: https://github.com/sudo-project/sudo/blob/main/src/sudo.c
Thanks for answers in advance