发信人: tcpip (俺的昵称改了), 信区: cnunix
标 题: [转载] badpwd.c, 你的系统安全吗?
发信站: 哈工大紫丁香 (Sun Sep 26 14:56:25 1999), 转信
发信人: cpu (奔腾的心), 信区: Solaris
发信站: 华南网木棉站 (Thu Jun 25 14:30:21 1998), 转信
【 以下文字转载自 Hacker 讨论区 】
【 原文由 cpu 所发表 】
/* badpwd.c for solaris, by CPU. u can move it to other unixes
* this program check if there is any user whose password
* is as same as user-name or is empty. compile it and
* change it's owner as root, then exec it then u can see
* how secure ur system is ...
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <pwd.h>
#include <shadow.h>
#include <crypt.h>
#define TRUE 0
#define FALSE -1
#ifndef PASSWD
#define PASSWD "/etc/passwd"
#endif
#ifndef SHADOW
#define SHADOW "/etc/shadow"
#endif
int main(int argc, char **argv)
{
char salt[3];
struct passwd *p_passwd;
struct spwd *p_spwd;
uid_t uid;
FILE *fp_passwd;
FILE *fp_shadow;
if (argc == 3) {
fp_passwd = fopen(argv[1], "r");
if (!fp_passwd) {perror("fopen passwd file"); exit(-1);}
fp_shadow = fopen(argv[2], "r");
if (!fp_shadow) {perror("fopen shadow file"); exit(-1);}
} else if (argc == 1) {
fp_passwd = fopen(PASSWD, "r");
if (!fp_passwd) {perror("fopen passwd file"); exit(-1);}
fp_shadow = fopen(SHADOW, "r");
if (!fp_shadow) {perror("fopen shadow file"); exit(-1);}
} else {
printf("usage: badpwd [passwd_file shadow_file]\n");
exit(0);
}
while (p_passwd = fgetpwent(fp_passwd)) {
fseek(fp_shadow, 0, SEEK_SET);
while (p_spwd = fgetspent(fp_shadow)) {
if (strcmp(p_passwd->pw_name, p_spwd->sp_namp) == TRUE)
break;
}
if (p_spwd == NULL) continue;
salt[0] = p_spwd->sp_pwdp[0];
salt[1] = p_spwd->sp_pwdp[1];
salt[2] = '\0';
if (strcmp(p_spwd->sp_pwdp, crypt(p_passwd->pw_name, salt))
== TRUE) {
printf("%s: passwd is same as user's login name\n",
p_passwd->pw_name);
} else if (strcmp(p_spwd->sp_pwdp, crypt("", salt))
== TRUE) {
printf("%s: passwd is empty\n",
p_passwd->pw_name);
}
}
fclose(fp_passwd);
fclose(fp_shadow);
}
--
******************************************************
蓦然回首,老子已是高级战友 。。。 。。。
******************************************************
※ 修改:.trueip 于 Sep 26 15:00:13 修改本文.[FROM: dns.mtlab.hit.ed]
※ 来源:.华南网木棉站 bbs.gznet.edu.cn.[FROM: 202.101.248.6]
--
--
※ 转寄:.华南网木棉站 bbs.gznet.edu.cn.[FROM: dns.mtlab.hit.ed]
--
☆ 来源:.哈工大紫丁香 bbs.hit.edu.cn.[FROM: trueip.bbs@melon.gzn]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.121毫秒