如何为400个用户生成用户帐户以进行负载测试?
Htdigest每次都会强制你输入密码,我尝试过这样的dos管道
echo password > htdigest -c realm username%1
htdigest -c realm username%1 < password.txt 但它不起作用。
发布于 2009-03-14 09:55:42
您还可以查看trac在其网站上分发的python脚本,以获取htdigest密码,然后您可以将其自动化:
Generating htdigest passwords without Apache
他们还提出了以下几点建议:
可以使用md5sum实用程序通过以下方法生成摘要密码文件:
$ printf "${user}:trac:${password}" | md5sum - >>user.htdigest用户并手动删除末尾的“-”,并将“${
}:trac:”添加到“to -”中的行首。
我已经在FreeBSD上测试过了,不确定这是否能在Linux或Windows上工作,所以你可能需要稍微修改一下:
(echo -n "user:realm:" && echo -n "user:realm:testing" | md5) > outfile输出文件包含:
user:realm:84af20dd88a2456d3bf6431fe8a59d16htdigest也是如此:
htdigest -c outfile2 realm user以outfile2格式输出
user:realm:84af20dd88a2456d3bf6431fe8a59d16它们都是相同的,从而证明了命令行实现的正确性!
发布于 2009-03-14 09:53:15
(旁白:在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版本的操作留给用户作为练习。
发布于 2009-06-05 18:24:00
下面是一个脚本,它将读取用户名列表,为每个用户名生成随机密码,并将它们输出到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:7v7m6mXYhttps://stackoverflow.com/questions/645659
复制相似问题