Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- # devilzc0de.org (c) 2012
- use Socket;
- $port = 13123;
- $protocol=getprotobyname('tcp');
- socket(S,&PF_INET,&SOCK_STREAM,$protocol) || die;
- setsockopt(S,SOL_SOCKET,SO_REUSEADDR,1);
- bind (S,sockaddr_in($port,INADDR_ANY)) || die;
- listen (S,3) || die;
- while(1){
- accept (CONN,S);
- $req=<CONN>; chomp($req); $req=~s/\r//g;
- $req =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;
- print $req."\r\n";
- $headers = "HTTP/1.1 200 OK\r\n";
- $headers .= "Server: Perl\r\n";
- $target = $req;
- if($req =~ /GET .* HTTP.*/){
- $target =~ s/GET\ //;
- $target =~ s/\ HTTP.*//;
- $resp = "";
- if(-d $target){
- if(!($target =~ /.*\/+$/)){
- $target = $target."/";
- }
- $resp = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">
- <html>
- <title>Directory listing for ".$target."</title>
- <body>
- <h2>Directory listing for ".$target."</h2>
- <hr><ul>";
- if(opendir(DIR,$target)){
- while($file = readdir(DIR)){
- if(-d $target.$file){
- if(($file eq ".") || ($file eq "..")){ next; }
- $resp .= "<li><a href=\"".$target.$file."/\">".$file."/</a></li>\r\n";
- }
- elsif(-f $target.$file){
- $resp .= "<li><a href=\"".$target.$file."\">".$file."</a></li>\r\n";
- }
- }
- closedir(DIR);
- }
- $resp .= "</ul><hr>
- </body>
- </html>";
- $conlen = length($resp);
- $contype = "text/html";
- print "Dir : ".$target."\r\n";
- }
- elsif(-f $target){
- $conlen = -s $target;
- $contype = "text/plain";
- print "File : ".$target." (".$conlen.")\r\n";
- }
- print "contype : ".$contype."\r\n";
- print "conlen : ".$conlen."\r\n";
- $headers .= "Content-Type: ".$contype."\r\n";
- $headers .= "Content-Length: ".$conlen."\r\n";
- print CONN $headers."\r\n";
- if(-d $target){
- print CONN $resp;
- }
- elsif(-f $target){
- if(open(FILE,$target)){
- binmode FILE;
- while (($n = read FILE, $data, 1024) != 0) {
- print CONN $data;
- }
- close(FILE);
- }
- }
- }
- close CONN;
- }
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement