1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
use strict;
use warnings FATAL => 'all';
use Apache::Test;
use Apache::TestUtil;
use Apache::TestRequest;
plan tests => 6, need 'LWP', { "PHP not installed", \&need_php };
use HTTP::Message;
my $url = Apache::TestRequest::resolve_url("/security/CAN-2004-0959.php");
sub multipart
{
my $name = shift;
my $filename = shift;
my $ctype = shift;
my $extra = shift;
my $req = HTTP::Request->new(POST => $url);
$req->header(Content_Type => 'multipart/form-data; boundary=XXXX');
$req->content("--XXXX\n".
"Content-Disposition: form-data; name=\"MAX_FILE_SIZE\"\n\n".
"30000\n".
"--XXXX\n".
"Content-Disposition: form-data; name=\"".$name."\"; filename=\"".$filename."\"\n".
"Content-Type: ".$ctype."\n\n".
"fish\n");
$req->add_content($extra) if $extra;
$req->add_content("--XXXX--\n");
Apache::TestRequest::user_agent->request($req);
}
my $resp = multipart("user_file", "fish.php", "text/plain");
ok t_cmp($resp->code, 200, "POST request success");
ok t_cmp($resp->content, "fish.php", "filename parsed safely");
$resp = multipart("user_file", "../../fish.php", "text/plain");
ok t_cmp($resp->code, 200, "POST request success");
ok t_cmp($resp->content, "fish.php", "filename parsed safely");
$resp = multipart
("user[file[name]123", "good.php", "/tmp/passt.php",
"--XXXX\n".
"Content-Disposition: form-data; name=\"user[file[type]123\"; filename=\"vg\"\n".
"Content-Type: text/plain\n\n".
"fishfood\n");
ok t_cmp($resp->code, 200, "POST request success");
ok t_cmp($resp->content, "FAILED", "filename parsed safely");
|