Meksilon
August 16th, 2006, 04:36
This will thread track my progress, but I've hit the first successful part of doing this task. First the url to my php backend is plamdi.com/page.php - but you cannot access it directly. I've hit the first major success in creating the backend.
Basically this is as far as I've gotten:
1. added some lines of code to my .htaccess file:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} ^(.+)/(.+).htm$
RewriteRule ^(.+)/(.+)\.htm http://plamdi.com/page.php?p=$2&l=$1 [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} ^(.+).htm$
RewriteRule ^(.+)\.htm http://plamdi.com/page.php?p=$1&l= [NC]This basically means, if and only if someone tries to access a .htm address at my site that does not exisit (for example plamdi.com/wotc/somepage.htm) it will be redirected to page.php. However, if the htm file does exisit there's no redirection.
2. The next part is page.php itself. It's programmed to ignore requests for files called *page.htm (this way it cannot read itself - or any other script ending in page.php - for instance... http://plamdi.com/files/hpage.php). Also it ignores requests that do not come from a genuine htm redirect - thus if you try to access the page directly by putting page.php?p=whatever&l=whatever in the browser the request will be ignored. The request is also ignored if a required .php file to read cannot be found (so if you type in plamdi.com/badurl.htm then the request will be ignored).
All ignored requests return a genuine 404.
These have been the first major steps in creating the PHP backend. It works 100%, and so now I can get started with making the "dynamic" content. I will continue to report on my progress here, as it's made.
I've never programmed in PHP before (well aside from hpage.php linked to above, but I wrote that like a week ago), but here's the current source code for page.php:
<?
$dir=strtolower(stripslashes($_GET["l"]));
$page=strtolower(stripslashes($_GET["p"]));
if($dir==""){$file=$page.".php";}
else{$file=$dir."/".$page.".php";}
if(strlen($page)>=4){$x=(strcmp(substr($page,-4),'page'));}
else{$x=1;}
if(strlen($_SERVER["REQUEST_URI"])>=4){if(strcmp(substr($_SERVER["REQUEST_URI"],-4),'.htm')){$x=0;}}
else{$x=0;}
if($x&&file_exists($file)){
// header("Last-Modified: ".date("D, d M Y H:i:s",filemtime(${file}))." GMT");
// include($file);
echo("${dir}<br>${page}<br>${file}<br>".$_SERVER["REQUEST_URI"]);
}else{
header("HTTP/1.0 404 Not Found");
header("Last-Modified: ".date("D, d M Y H:i:s",filemtime("404.htm"))." GMT");
readfile("404.htm");
}
?>Can you spot the current possible vulnerability? I can and trust me it'll be fixed before "include($file);" is un commented.
Basically this is as far as I've gotten:
1. added some lines of code to my .htaccess file:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} ^(.+)/(.+).htm$
RewriteRule ^(.+)/(.+)\.htm http://plamdi.com/page.php?p=$2&l=$1 [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} ^(.+).htm$
RewriteRule ^(.+)\.htm http://plamdi.com/page.php?p=$1&l= [NC]This basically means, if and only if someone tries to access a .htm address at my site that does not exisit (for example plamdi.com/wotc/somepage.htm) it will be redirected to page.php. However, if the htm file does exisit there's no redirection.
2. The next part is page.php itself. It's programmed to ignore requests for files called *page.htm (this way it cannot read itself - or any other script ending in page.php - for instance... http://plamdi.com/files/hpage.php). Also it ignores requests that do not come from a genuine htm redirect - thus if you try to access the page directly by putting page.php?p=whatever&l=whatever in the browser the request will be ignored. The request is also ignored if a required .php file to read cannot be found (so if you type in plamdi.com/badurl.htm then the request will be ignored).
All ignored requests return a genuine 404.
These have been the first major steps in creating the PHP backend. It works 100%, and so now I can get started with making the "dynamic" content. I will continue to report on my progress here, as it's made.
I've never programmed in PHP before (well aside from hpage.php linked to above, but I wrote that like a week ago), but here's the current source code for page.php:
<?
$dir=strtolower(stripslashes($_GET["l"]));
$page=strtolower(stripslashes($_GET["p"]));
if($dir==""){$file=$page.".php";}
else{$file=$dir."/".$page.".php";}
if(strlen($page)>=4){$x=(strcmp(substr($page,-4),'page'));}
else{$x=1;}
if(strlen($_SERVER["REQUEST_URI"])>=4){if(strcmp(substr($_SERVER["REQUEST_URI"],-4),'.htm')){$x=0;}}
else{$x=0;}
if($x&&file_exists($file)){
// header("Last-Modified: ".date("D, d M Y H:i:s",filemtime(${file}))." GMT");
// include($file);
echo("${dir}<br>${page}<br>${file}<br>".$_SERVER["REQUEST_URI"]);
}else{
header("HTTP/1.0 404 Not Found");
header("Last-Modified: ".date("D, d M Y H:i:s",filemtime("404.htm"))." GMT");
readfile("404.htm");
}
?>Can you spot the current possible vulnerability? I can and trust me it'll be fixed before "include($file);" is un commented.