2009-03-14 35 views
9

Làm cách nào để bạn tạo tài khoản người dùng cho 400 người dùng để thực hiện thử nghiệm tải?Làm cách nào để htdigest 400 tài khoản người dùng?

lực lượng Htdigest bạn gõ vào một mật khẩu mỗi lần, tôi đã cố gắng Ống dos như

echo password > htdigest -c realm username%1 

htdigest -c realm username%1 < password.txt 

nhưng nó không làm việc ...

Trả lời

6

(Ngoài: Trên unix/linux là người đầu tiên nên là:

echo password | htdigest -c realm username$1 

)

Như htdigest không có bất kỳ cách tốt đẹp để vượt qua pas thanh kiếm trong, tôi sẽ sử dụng expect để tự động hóa quy trình.

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" 

Nó còn lại như một bài tập cho người sử dụng để chuyển đổi này cho Windows nếu cần thiết.

16

Bạn cũng có thể kiểm tra kịch bản python mà trac phân phối trên trang web của họ cho các mật khẩu htdigest, bạn có thể sau đó tự động nó:

Generating htdigest passwords without Apache

Họ cũng đề nghị một cái gì đó dọc theo những dòng sẽ làm việc:

Có thể sử dụng tiện ích md5sum để tạo tệp mật khẩu thông báo bằng phương pháp như vậy:

$ printf "${user}:trac:${password}" | md5sum - >>user.htdigest 

và xóa thủ công "-" từ cuối và thêm "$ {user}: trac:" vào đầu dòng từ 'đến tệp'.


Tôi đã thử nghiệm này trên FreeBSD, không chắc chắn nếu điều này sẽ làm việc trên Linux hoặc Windows, do đó bạn có thể cần phải sửa đổi nó một chút:

(echo -n "user:realm:" && echo -n "user:realm:testing" | md5) > outfile 

outfile chứa:

user:realm:84af20dd88a2456d3bf6431fe8a59d16 

Điều tương tự với htdigest:

htdigest -c outfile2 realm user 

đầu ra trong outfile2

user:realm:84af20dd88a2456d3bf6431fe8a59d16 

Cả hai đều như nhau, qua đó chứng minh tính đúng đắn của việc thực hiện dòng lệnh!

+3

Trên GNU/Linux có thể sử dụng (được điều chỉnh từ lệnh FreeBSD ở trên): '(echo -n" user: realm: "&& echo -n" user: realm: passwd "| md5sum - | cut -d '' -f1) >> outfile' – blerontin

1

Đây là tập lệnh sẽ đọc trong danh sách tên người dùng, tạo mật khẩu ngẫu nhiên cho mỗi tệp và xuất chúng thành cả tệp htdigest và tệp văn bản thuần túy. Nó đã được thử nghiệm trên Linux, nhưng có thể cần phải được sửa đổi cho các hệ thống khác. Cụ thể, md5sum có thể là md5head không luôn chấp nhận cờ -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 

Đây là những gì đầu vào và kết quả như thế nào, đầu tiên nộp các tên người dùng:

$ cat users.txt 
joe 
curly 
larry 

Chạy kịch bản:

$ ./load_users.bash 

Kết quả là tập tin htdigest:

$ cat passwd.htdigest 
joe:MyRealm:2603a6c581f336f2874dbdd253aee780 
curly:MyRealm:fd3f9d87bba654439d5ba1f32c0286a8 
larry:MyRealm:c1c3c0dc50a9b97e9f7ee582e3fce892 

Và văn bản thuần túy le:

$ cat passwd.txt 
joe:aLnqnrv0 
curly:3xWxHKmv 
larry:7v7m6mXY 
Các vấn đề liên quan