如何为400名用户生成用户帐户以进行负载测试?
Htdigest强制你每次都输入一个密码,我尝试过像
这样的dos管道echo password > htdigest -c realm username%1
htdigest -c realm username%1 < password.txt
但它不起作用......
答案 0 :(得分:16)
您还可以查看trac在其网站上为htdigest密码分发的python脚本,然后您可以将其自动化:
Generating htdigest passwords without Apache
他们还建议沿着这些方向发挥作用:
可以使用md5sum实用程序使用以下方法生成摘要密码文件:
$ printf "${user}:trac:${password}" | md5sum - >>user.htdigest
并从末尾手动删除“ - ”并将“$ {user}:trac:”添加到“to-file”行的开头。
我在FreeBSD上测试了这个,不确定这是否适用于Linux或Windows,所以你可能需要稍微修改一下:
(echo -n "user:realm:" && echo -n "user:realm:testing" | md5) > outfile
outfile包含:
user:realm:84af20dd88a2456d3bf6431fe8a59d16
与htdigest相同:
htdigest -c outfile2 realm user
user:realm:84af20dd88a2456d3bf6431fe8a59d16
它们都是相同的,从而证明了命令行实现的正确性!
答案 1 :(得分:6)
(旁白:在unix / linux上,第一个应该是:
echo password | htdigest -c realm username$1
)
由于htdigest没有任何传递密码的好方法,我会使用expect
来自动化该过程。
An example from http://www.seanodonnell.com/code/?id=21:
#!/usr/bin/expect
#########################################
#$ file: htpasswd.sh
#$ desc: Automated htpasswd shell script
#########################################
#$
#$ usage example:
#$
#$ ./htpasswd.sh passwdpath username userpass
#$
######################################
set htpasswdpath [lindex $argv 0]
set username [lindex $argv 1]
set userpass [lindex $argv 2]
# spawn the htpasswd command process
spawn htpasswd $htpasswdpath $username
# Automate the 'New password' Procedure
expect "New password:"
send "$userpass\r"
expect "Re-type new password:"
send "$userpass\r"
如果需要,它可以作为练习留给用户将其转换为Windows。
答案 2 :(得分:1)
这是一个脚本,它将读入用户名列表,为每个用户名生成随机密码,并将它们输出到htdigest文件和纯文本文件。它已经在Linux上进行了测试,但可能需要针对其他系统进行修改。特别是,md5sum
可能是md5
,而head
始终接受-c
标记。
#!/bin/bash
# auth realm for digest auth
AUTH_REALM=MyRealm
# file locations
# a file containing a list of user names,
# one name per line, e.g.,
# $ cat users.txt
# joe
# curly
# larry
USER_FILE=users.txt
# htdigest file, needs to exist
HTDIGEST_FILE=passwd.htdigest
# insecure password file
PASSWD_FILE=passwd.txt
# read the names from the user file
while read username
do
# generate a pseudo-random password
rand_pw=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c8`
# hash the username, realm, and password
htdigest_hash=`printf $username:$AUTH_REALM:$rand_pw | md5sum -`
# build an htdigest appropriate line, and tack it onto the file
echo "$username:$AUTH_REALM:${htdigest_hash:0:32}" >> $HTDIGEST_FILE
# put the username and password in plain text
# clearly, this is terribly insecure, but good for
# testing and importing
echo "$username:$rand_pw" >> $PASSWD_FILE
done < $USER_FILE
这是输入和结果的样子,首先是用户名文件:
$ cat users.txt
joe
curly
larry
运行脚本:
$ ./load_users.bash
生成的htdigest文件:
$ cat passwd.htdigest
joe:MyRealm:2603a6c581f336f2874dbdd253aee780
curly:MyRealm:fd3f9d87bba654439d5ba1f32c0286a8
larry:MyRealm:c1c3c0dc50a9b97e9f7ee582e3fce892
纯文本文件:
$ cat passwd.txt
joe:aLnqnrv0
curly:3xWxHKmv
larry:7v7m6mXY