ログインパラメーターを使用して、GET と POST を受け入れる CGI サーバー側スクリプトがあります。脆弱性がないことを確認するためにテストしたいと思います。そのため、Perl LWP を使用し、GET と POST でログイン パラメータを送信し、結果を比較する計画です。インターフェイスが変更されたため、POST でのみセッション Cookie でユーザー名とパスワードを送信できるようになりました (それが良いアイデアかどうかはわかりません)。どうすればテストできますか? これが私がこれまでに持っているものです:
#!/usr/bin/perl
use LWP;
print "This is libwww-perl-$LWP::VERSION\n";
# Create a user agent object
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");
# Create a request
#my $req = HTTP::Request->new(POST => 'http://search.cpan.org/search');
#my $req = HTTP::Request->new(GET => 'https://qa.co.net:443/cgi-bin/n-cu.cgi');
my $req = HTTP::Request->new(GET => 'https://qa.co.net:443/cgi-bin/n-cu.cgi?mode=frameset&JScript=1&remote_user&login=foo&password=foo HTTP/1.1');
$req->content_type('application/x-www-form-urlencoded');
$req->content('query=libwww-perl&mode=dist');
# Pass request to the user agent and get a response back
my $res = $ua->request($req);
# Check the outcome of the response
if ($res->is_success) {
print $res->content;
#print $res->code;
#print $res->message;
}
else {
print $res->status_line, "\n";
}
セッション Cookie がないため、これは実行されません。しかし、良いスタートかもしれません。これは GET と POST をテストする正しい方法ですか?
これがcgiで実装されたものです:
#cr_login for POST && login for GET -- leave GET param as it used to be.
if ($m eq 'GET' && defined($req->param('login'))) {
$msg = 'parameter "login" is invalid for this request type.';
+ my $seclog = $event_logging_directory . '/invalid_request.log';
+ open(S, ">>$seclog") or die $!;
+ my $logmsg = sprintf("%4d-%02d-%02d %02d:%02d:%02d",Today_and_Now())
+ . "|mode:" . $req->param('mode')
+ . "|login:" . $req->param('login')
+ . "|remote_addr:" . $ENV{REMOTE_ADDR}
+ . "|$msg\n";
+ print S $logmsg;
と :
POST request to n-cu.cgi should use parameter "cr_login". If the parameter "login" is passed in a post request, it should throw error and return to login screen.
GET request to n-cu.cgi should use the parameter "login". If the parameter "cr_login" is passed in a post request, it should throw error and return to login screen.
だからここに私たちがそれを行う方法があります:
セッション Cookie とコンテキストを維持します。
私の $browser = LWP::UserAgent->new(keep_alive => 10); $browser->cookie_jar( {} ); $browser->agent('Mozilla/8.0'); #$browser->ssl_opts({ verify_hostname => 0 }); $browser->show_progress(1);
以降: 応答を出力する
print "Cookies:\n", Dumper($browser->cookie_jar()), "\n\n";
my $content = $response->as_string;
print "$content\n";