IT运维管理,创造商业价值!
中国IT运维网首页 | 资讯中心 | 运维管理 | 信息安全 | CIO视界 | 云计算 | 最佳案例 | 运维资源 | 专题策划 | 知识库 | 论坛

如何通过WEB方式安全添加系统用户

2007年06月21日
/

在网上看到一些通过php直接添加系统用户的解决方法,这些方法都在脚本中保存系统超级用户密?很大的安全性问题。这里提供的方法是通过php在前台添加用户、密码记录到mysql数据库中,后台通过cron 隔时(时间可以自己设定)执行添加用户的程序。程序中都没有记录系统超级用户密码,这样能保证系统的安 全。如下为添加用户的后台程序,这个程序只是为很粗糙的演示程序,功能为把addornot=0的用户加入系统中 而已,仅供读者参考。php添加用户信息到数据库的程序略去。程序在RedHat6.0 下通过

adduserfromdb.pl
#!/usr/bin/perl
use DBI;
$dbuser = "xxxx";
$dbpasswd = "xxx";
$db = "xxxx";
$dbh = DBI->connect("DBI:mysql:$db",$dbuser,$dbpasswd);
$query = "select user,passwd from usertable where addornot=0";
$sth = $dbh->prepare($query);
$rv = $sth->execute or die "Can't execute the query:$sth->
errstr\n";while(@row = $sth->fetchrow_array) { #print "user=".$row[0]."\n"; #print "password=".$row[1]."\n"; @saltchars = (a .. z, A .. Z, 0 .. 9); srand(time||$$); $salt = $saltchars[rand($#saltchars)] .$saltchars[rand($#saltchars)]; #print "$salt\t$row[1]\n"; $encrypt_passwd = crypt($row[1],$salt); #print $encrypt_passwd."\n"; $add_exec = "/usr/sbin/useradd -p ".$encrypt_passwd." ".$row[0]; #对useradd增加参数,可以控制用户的组别、目录、登陆与否、shell等等 #print $add_exec."\n"; system($add_exec); } #1; 用户信息表 usertable: CREATE TABLE usertoadd ( user tinytext NOT NULL, passwd tinytext NOT NULL, addornot tinyint(4) DEFAULT '0' NOT NULL );


发表评论请到:http://bbs.cnitom.com

相关阅读

图文热点

详细剖析:企业采用Linux系统注意事项
详细剖析:企业采用Linux系统注意事项你是否已经厌烦了整日为Windows Sever打补丁,是否已经开始怀疑Windows Sever 服...
揭穿零日漏洞的七大误区
揭穿零日漏洞的七大误区又过了一个月,又有一个零日漏洞被报告,而恶意攻击者借助恶意软件,发动了钻这个...

本类热点