Throw me a bone here!

27 views
Skip to first unread message

Beaver6813

unread,
May 23, 2010, 5:54:51 PM5/23/10
to Google Safe Browsing API
Hi Guys,

I discovered Google Safe Browsing today and have read and re-read the
V2 documentation a few times over to try and fully understand it. I'm
trying to build up a PHP version and am trying to get some sort of
download going so I can see some data and work on matching/processing
it (I'll work fully on the ADD/SUB at a later date). I keep getting
400 errors but can't see where I'm going wrong, any ideas?

<?php
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://safebrowsing.clients.google.com/
safebrowsing/downloads?
client=api&apikey=<my_api_key>&appver=1.5.2&pver=2.2");
//Comment the above and comment out the below to switch to debugger
(shows POST request body)
//curl_setopt($ch, CURLOPT_URL, "http://beaver6813.com/dev/xvu/class/
debug.php");
//Don't return any header stuff (I can see the response is 400 anyways
at the moment!)
curl_setopt($ch, CURLOPT_HEADER, 0);
//Return what it downloads
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Use POST
curl_setopt($ch, CURLOPT_POST, true);
//Set POST data
curl_setopt($ch, CURLOPT_POSTFIELDS, 'googpub-phish-shavar;a:1-3,5,8:s:
4-5');

//Temporary for debugging
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

echo curl_exec($ch);
curl_close($ch);
?>

Any pointers would be greatly appreciated!!
Thanks!!

--
You received this message because you are subscribed to the Google Groups "Google Safe Browsing API" group.
To post to this group, send email to google-safe-...@googlegroups.com.
To unsubscribe from this group, send email to google-safe-browsi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-safe-browsing-api?hl=en.

Stratsimir Kolchevski

unread,
May 24, 2010, 2:42:54 PM5/24/10
to google-safe-...@googlegroups.com
On 24 May 2010 00:54, Beaver6813 <s...@beaver6813.com> wrote:
> Hi Guys,
>
> I discovered Google Safe Browsing today and have read and re-read the
> V2 documentation a few times over to try and fully understand it. I'm
> trying to build up a PHP version and am trying to get some sort of
> download going so I can see some data and work on matching/processing
> it (I'll work fully on the ADD/SUB at a later date). I keep getting
> 400 errors but can't see where I'm going wrong, any ideas?
>
> curl_setopt($ch, CURLOPT_POSTFIELDS, 'googpub-phish-shavar;a:1-3,5,8:s:4-5');


The LF is missing, try with:
curl_setopt($ch, CURLOPT_POSTFIELDS, "googpub-phish-shavar;a:1-3,5,8:s:4-5\n");

--
Stratsimir

Beaver6813

unread,
May 24, 2010, 3:15:18 PM5/24/10
to Google Safe Browsing API
Hi Stratsimir,

I woke up this morning and noticed that, got it working all to a point
and after reading the developer's guide a thousand times am beginning
to fully understand how the system works; however on my subs when
there is more than one [ADDCHUNKNUM PREFIX] pair, the final pair
always appears to be missing data, I've converted to hex to make it
easier to deal with, any idea whats going wrong here: ([0] in the
array is the header and [1] is the hex of the full CHUNKDATA)

[74] => Array
(
[0] => 1622:4:26
[CHUNKNUM] => 1622
[HASHLEN] => 4
[CHUNKLEN] => 26
[1] =>
bfddc569010000dc7e491e4283b5f74021010000dec25b600c94
[HOSTKEY] => bfddc569
[COUNT] => 01
[PAIRS] => Array
(
[0] => Array
(
[ADDCHUNKNUM] => 0000dc7e
[PREFIX] => 491e4283
)

[1] => Array
(
[ADDCHUNKNUM] => b5f74021
[PREFIX] => 010000de
)

[2] => Array
(
[ADDCHUNKNUM] => c25b600c
[PREFIX] => 94
)

)

)

Any pointers in the right direction would be awesome!!

Cheers,

Sam

On May 24, 7:42 pm, Stratsimir Kolchevski <stratsi...@gmail.com>
wrote:

Stratsimir Kolchevski

unread,
May 24, 2010, 4:02:44 PM5/24/10
to google-safe-...@googlegroups.com
Seems that you're doing it wrong :-) If you provide us with a snipped
of your code, we might help. You can check my implementation, but I
can't guarantee that it's correct, because it's not finished and I
haven't tested it yet:

while (strlen($chunk) > 0) {
$ret = unpack('C4hostkey/Ccount', $chunk);
$chunk = substr($chunk, 5);

if ($ret['count'] > 0) {
for ($i = 0; $i < $ret['count']; $i++) {
$ret2 =
unpack("Naddchunknum/C{$hashlen}prefix", $chunk);
$chunk = substr($chunk, 4 + $hashlen);
}
} else if ($ret['count'] == 0) {
$ret2 = unpack("Nchunknum", $chunk);
$chunk = substr($chunk, 4);
} else {
echo "unknown size {$ret['size']}\n";
break;

Beaver6813

unread,
May 25, 2010, 6:43:42 AM5/25/10
to Google Safe Browsing API
After reading the developer guide yet again it seems I was doing it
wrong! I didn't see that the host key part could be repeated in a
chunk and so didn't take that into consideration. However I can't for
the life of me work out what:

Array
(
[hostkey1] => 90
[hostkey2] => 224
[hostkey3] => 118
[hostkey4] => 220
[count] => 1
)
Array
(
[addchunknum] => 52326
[prefix1] => 156
[prefix2] => 187
[prefix3] => 54
[prefix4] => 38
)


Would represent, presumably hostkey1, hostkey2, hostkey3 and hostkey4
would need to be combined but what format are that in currently? For
reference the hex it should produce (I'm using a less efficient
algorithym) 5ae076dc

Thanks a lot for all your help!!!

--Sam

On May 24, 9:02 pm, Stratsimir Kolchevski <stratsi...@gmail.com>
wrote:

John Smith 8761

unread,
Jun 27, 2010, 7:54:16 AM6/27/10
to Google Safe Browsing API
*Beaver6813*
Its been a month since you posted last.. any chance you could share
your valuable php code for the rest of us who are as confused as you
were to start with.
The Google Safe Browsing API documentation is quite lacking and I
would really appreciate your php solution.

Beaver6813

unread,
Jul 4, 2010, 12:26:44 PM7/4/10
to Google Safe Browsing API
Hey,

Yeah sure, its probably not the efficient in many areas but really I
was just focusing on getting it working which I can proudly say for
the most part it does. It takes overnight to populate the database to
near complete (or as complete as it can be) from my tests:

I've released it here:
http://code.google.com/p/phpgsb/
Theres a couple of things that need to be brought into the main
download that are currently still in the SVN,

Let me know if you have any questions or can help improve it!

Cheers,

Sam

John Smith 8761

unread,
Aug 23, 2010, 4:13:30 PM8/23/10
to Google Safe Browsing API
It might be a bit late but thanks for the code!
Reply all
Reply to author
Forward
0 new messages