Advertisement
Guest User

devilzc0de rulez !!! perl jumping script

a guest
Feb 7th, 2012
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.04 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. # devilzc0de.org (c) 2012
  3.  
  4. use Socket;
  5.  
  6. $port = 13123;
  7.  
  8. $protocol=getprotobyname('tcp');
  9. socket(S,&PF_INET,&SOCK_STREAM,$protocol) || die;
  10. setsockopt(S,SOL_SOCKET,SO_REUSEADDR,1);
  11. bind (S,sockaddr_in($port,INADDR_ANY)) || die;
  12. listen (S,3) || die;
  13. while(1){
  14.     accept (CONN,S);
  15.     $req=<CONN>; chomp($req); $req=~s/\r//g;
  16.     $req =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;
  17.    
  18.     print $req."\r\n";
  19.    
  20.     $headers = "HTTP/1.1 200 OK\r\n";
  21.     $headers .= "Server: Perl\r\n";
  22.    
  23.     $target = $req;
  24.     if($req =~ /GET .* HTTP.*/){
  25.         $target =~ s/GET\ //;
  26.         $target =~ s/\ HTTP.*//;
  27.         $resp = "";
  28.         if(-d $target){
  29.             if(!($target =~ /.*\/+$/)){
  30.                 $target = $target."/";
  31.             }
  32.            
  33.             $resp = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">
  34.                     <html>
  35.                     <title>Directory listing for ".$target."</title>
  36.                     <body>
  37.                     <h2>Directory listing for ".$target."</h2>
  38.                     <hr><ul>";
  39.                    
  40.             if(opendir(DIR,$target)){
  41.                 while($file = readdir(DIR)){
  42.                     if(-d $target.$file){
  43.                         if(($file eq ".") || ($file eq "..")){ next; }
  44.                         $resp .= "<li><a href=\"".$target.$file."/\">".$file."/</a></li>\r\n";
  45.                     }
  46.                     elsif(-f $target.$file){
  47.                         $resp .= "<li><a href=\"".$target.$file."\">".$file."</a></li>\r\n";
  48.                     }
  49.                 }
  50.                 closedir(DIR);
  51.             }
  52.  
  53.             $resp .= "</ul><hr>
  54.                     </body>
  55.                     </html>";
  56.                    
  57.             $conlen = length($resp);
  58.             $contype = "text/html";
  59.             print "Dir : ".$target."\r\n";
  60.         }
  61.         elsif(-f $target){
  62.             $conlen = -s $target;
  63.             $contype = "text/plain";
  64.             print "File : ".$target." (".$conlen.")\r\n";
  65.         }
  66.  
  67.         print "contype : ".$contype."\r\n";
  68.         print "conlen : ".$conlen."\r\n";
  69.        
  70.         $headers .= "Content-Type: ".$contype."\r\n";
  71.         $headers .= "Content-Length: ".$conlen."\r\n";
  72.    
  73.         print CONN $headers."\r\n";
  74.        
  75.         if(-d $target){
  76.             print CONN $resp;
  77.         }
  78.         elsif(-f $target){
  79.             if(open(FILE,$target)){
  80.                 binmode FILE;
  81.                 while (($n = read FILE, $data, 1024) != 0) {
  82.                     print CONN $data;
  83.                 }
  84.                 close(FILE);
  85.             }
  86.         }
  87.     }
  88.     close CONN;
  89. }
  90. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement