Oktober 22nd, 2006 by admin
REMEMBER: TRANCE or DiE… that’s all !
Posted in fun | No Comments »
Oktober 19th, 2006 by admin
on all my servers the php configuration value short_open_tag is disabled. that means i must write < ?php and can not use the short < ? to open the php session. another fact is "quote from php.net/eval):
eval() is used to protect (read: hide) source code. A well known way to encrypt some php code is security through obscurity. Someone used eval(base64_encode(".....")); - which basically had 10-16 nested calls to eval(base64_encode()) inside the data.
the most of these protected scripts use the short version to open php. so i can not execute them. therefor i coded a little function that deals with the problem. but the old function just decrypt "gzinflate(str_rot13(base64_decode(.....)))" and "gzinflate(base64_decode(...))" that is crap an does not work on most scripts (see comments). now i coded a whole class that deals with this problem. the class can recursive "decrypt" these scripts and let you download the original source code. i tested the class with scripts that are protected with the following functions (of couse recursive).
note: the class is really easy to use. look at the source and you know how.
note2: please do not edit the class and ask for help if you get any error (see comments).
note3: THIS IS IMPORTANT -> do NOT use the class to break any license,law or copyright.
the last note: check the decrypted source code and you will see 2 little errors. correct them and you are done.
PHP:
-
class decode
-
{
-
function __construct($file)
-
{
-
-
$this->result = $this->org_data;
-
$this->done = false;
-
$this->file = $file;
-
}
-
-
function strip_php_tags($str)
-
{
-
-
-
}
-
-
function strip_what_to_execute()
-
{
-
$possible_code =
substr($this->
result,
0,
strpos($this->
result,
"'"));
-
$possible_code_end =
strrpos($this->
result,
"'");
-
if($this->
test_possible_code($possible_code) &&
count($this->
execute)>
0)
-
{
-
$possible_code_start =
strlen($possible_code)+
1;
-
$this->
result =
substr($this->
result,
$possible_code_start,
$possible_code_end-
$possible_code_start);
-
}
-
}
-
-
function clean_string($str)
-
{
-
$str =
trim($str,
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f");
-
$str =
trim($str,
"\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff");
-
-
return $str;
-
}
-
-
function test_possible_code($str)
-
{
-
$str = $this->clean_string($this->strip_php_tags($str));
-
//echo $str."\n";
-
-
$this->
execute =
array();
-
-
{
-
$this->done = true;
-
return false;
-
}
-
foreach($functions as $function)
-
{
-
if($function!='' && $function!='eval')
-
{
-
-
$this->error('sorry but i can not access the function:"'.$function.'"');
-
else
-
$this->execute[] = $function;
-
}
-
}
-
return true;
-
}
-
-
function execute()
-
{
-
$cmd_str = '';
-
$cmd_end = '';
-
foreach($this->execute as $cmd)
-
{
-
$cmd_str .= $cmd.'(';
-
$cmd_end .= ')';
-
}
-
$eval = $cmd_str."'".$this->result."'".$cmd_end;
-
eval ("\$this->result = ".
$eval.
";");
-
}
-
-
function error($msg)
-
{
-
-
}
-
-
function decode()
-
{
-
$this->strip_what_to_execute();
-
if($this->
done==
false &&
count($this->
execute)>
0)
-
{
-
$this->execute();
-
$this->decode();
-
}
-
else
-
{
-
//i think this is the "decrypted"
-
$this->download();
-
}
-
}
-
-
function download()
-
{
-
header('Content-Disposition: attachment; filename="decrypted_'.
$this->
file.
'"');
-
header('Content-Type: application/php');
-
-
-
}
-
}
-
$decode = new decode('test.php');
-
$decode->decode();
Posted in coding, php | 43 Comments »
Oktober 18th, 2006 by admin
Lostmon reported some xss(Cross Site Scripting) for the admin.
also the latest version "osCommerce 2.2 Milestone 2 Update 060817" is VULNERABLE.
here is my fix for the "tep_href_link" function wich is located in "osc-dir/admin/includes/functions/html_output.php" just add after this code:
PHP:
-
function tep_href_link($page = '', $parameters = '', $connection = 'NONSSL') {
add:
PHP:
-
$parameters = tep_output_string($parameters);
and the xss is gone.
Posted in coding, php | 1 Comment »
Oktober 15th, 2006 by admin
wer seine website (shop,forum,homepage,cms,blog...) optimiert kennt das problem.
ist die eine funktion schneller als die andere (for und foreach). soll ich lieber mehr sql abfragen machen oder doch lieber eine große. fragen über fragen. um das ganze zu testen und durchschnittswerte zu erhalten hab ich hier ein benchmark script.
über parameter im script kann man die url der seite eingeben, parameter festlegen und zusätzlich noch einstellen wie oft die seite geladen werden soll. als ergebniss bekommt man dann:
- durchschnittliche seitengröße und die vergangene latenzzeit zeit seit dem http request
- benötigte gesamtzeit
- maximale bzw. minimale zeit für den seitenaufruf
und zum schluß wird dann noch die letzte meldung von webserver angezeigt. das ganze sollte dan aufschuß geben welche funktion schneller ist und welche man lieber löschen sollte.
parameter im script:
$host = 'host.de';
$url = '/osc-22/index.php';
$data = 'products_id=7&test=2636';
$rand = 30;
PS: bitte das script nicht mißbrauchen und fremde server mit anfragen bombardieren. es dient NUR zum optiemieren der eigenen website.
PHP:
-
class http_request
-
{
-
-
function __construct($type,$host,$file,$port = 80,$http_v = 'HTTP/1.1')
-
{
-
$this->host = $host;
-
$this->port = $port;
-
if(!$this->set_type($type))
-
die('sorry: please set a request type');
-
$this->file = $file;
-
$this->http_v = $http_v;
-
$this->add_header('Host',$host);
-
$this->add_header('Connection','Close');
-
}
-
function proxy($host,$port)
-
{
-
$this->con = @$this->connect($host,$port);
-
if(!$this->con)
-
die('sorry: the proxy on host "'.
$host.
'" did not response on port '.
$port);
-
$this->proxy_con = true;
-
}
-
function connect($host,$port)
-
{
-
-
die('sorry: but this is not a port');
-
preg_match('@^(?:(?:25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)(?(?=\.?\d)\.)){4}$@i',
$host,
$ip);
-
if($ip[0]!='')
-
-
else
-
-
}
-
function get_ascii_file_content($file)
-
{
-
-
if($content=='')
-
die('sorry: can not access file or file is empty');
-
return $content;
-
}
-
-
function get_bin_file_content($file)
-
{
-
$handle = @
fopen($file,
"rb");
-
if(!$handle)
-
die('sorry: can not access file');
-
-
-
return $content;
-
}
-
-
function send($set_ct = true)
-
{
-
if($set_ct==true)
-
$this->set_content_type();
-
if($this->proxy_con != true)
-
{
-
$this->con = @$this->connect($this->host,$this->port);
-
if(!$this->con)
-
die('sorry: "'.
$this->
host.
'" did not response on port '.
$this->
port);
-
}
-
$this->send_data = '';
-
$contentlength = 0;
-
if($this->type=='GET')
-
{
-
$get_str='';
-
foreach($this->data as $name => $value)
-
{
-
$get_str .= $name.'='.$value.'&';
-
}
-
if($get_str !='')
-
$this->
get_str =
'?'.
substr($get_str,
0,-
1);
-
}
-
else //// all other request types (POST, CONNECT ...)
-
{
-
$this->send_data ='';
-
if($this->boundary)
-
{
-
foreach($this->data as $name => $value)
-
{
-
$contentlength +=
strlen("--".
$this->
boundary.
"\nContent-Disposition: form-data; name=\"".
$name.
"\"\n\n".
$value.
"\n");
-
$this->send_data.=("--".$this->boundary."\nContent-Disposition: form-data; name=\"".$name."\"\n\n".$value."\n");
-
}
-
$contentlength +=
strlen($this->
boundary)+
3;
-
$this->add_header('Content-length',$contentlength);
-
$this->send_data.= "--".$this->boundary."--\n";
-
}
-
else
-
{
-
foreach($this->data as $name => $value)
-
{
-
$this->send_data.= $name.'='.$value.'&';
-
}
-
$this->
send_data =
substr($this->
send_data,
0,-
1);
-
$contentlength =
strlen($this->
send_data);
-
$this->add_header('Content-length',$contentlength);
-
}
-
}
-
if($this->proxy_con==true)
-
$this->send_header = $this->type.' '.'http://'.$this->host.$this->file.$this->get_str.' '.$this->http_v."\r\n";
-
else
-
$this->send_header = $this->type.' '.$this->file.$this->get_str.' '.$this->http_v."\r\n";
-
foreach($this->header as $head_name => $head_value)
-
$this->send_header .= $head_name.': '.$head_value."\r\n";
-
$this->send_header .= "\n";
-
$this->packet = $this->send_header.$this->send_data;
-
$this->send_to_host($this->packet);
-
}
-
-
function send_to_host($packet)
-
{
-
-
die('sorry: no connection');
-
fputs($this->
con,
$packet);
-
if($this->proxy_con==true)
-
{
-
$this->response='';
-
while (!
feof($this->
con)) {
-
$this->
response.=
fgets($this->
con);
-
}
-
}
-
else
-
{
-
$this->response='';
-
-
$this->
response.=
fread($this->
con,
1);
-
}
-
}
-
-
}
-
-
function set_content_type()
-
{
-
if($this->files> 0)
-
{
-
$this->
boundary =
'---------------------------'.
rand(1,
9999999999);
-
$this->add_header('Content-Type','multipart/form-data; boundary='.$this->boundary);
-
}
-
elseif($this->type!='GET')
-
$this->add_header('Content-Type','application/x-www-form-urlencoded');