http://dev.poetpalace.org/?p=363
http://dev.poetpalace.org/?p=363
通过环境变量USER和PASS指定用户密码,如果验证失败则sleep 2秒防止恶意攻击。程序需要owner为root来运行,并设置suid保证其他用户能运行。 这个简单的程序会有什么漏洞不?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#define _XOPEN_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <shadow.h>
#include <unistd.h>
#include <errno.h>
int
check_password (
const
char
*user,
const
char
*password)
{
struct
spwd *user_data;
if
(
strcmp
(user,
"root"
) == 0)
{
fprintf
(stderr,
"root not allowed\n"
);
return
3;
}
errno
= 0;
user_data = getspnam (user);
if
(user_data == NULL)
{
fprintf
(stderr,
"No such user %s, or error %s\n"
, user,
strerror
(
errno
));
sleep (2);
return
1;
}
if
(
strcmp
(crypt (password, user_data->sp_pwdp), user_data->sp_pwdp) != 0)
{
fprintf
(stderr,
"Auth user %s failed\n"
, user);
sleep (2);
return
2;
}
return
0;
}
int
main (
void
)
{
char
*user, *password;
if
((user=
getenv
(
"USER"
)) == NULL)
exit
(2);
if
((password=
getenv
(
"PASS"
)) == NULL)
exit
(3);
exit
(check_password(user, password));
}
|
Makefile:
1
2
3
4
5
6
|
all:
gcc -Wall -o cgitauth cgitauth.c -lcrypt
chmod u+s cgitauth
install:
cp -a cgitauth /usr/bin
|
这东西用来干嘛的?
好吧,是配合apache2的mod_authnz_external 做系统用户验证的,数据文件就是/etc/shadow咯。