Kuro5hin.org: technology and culture, from the trenches
create account | help/FAQ | contact | links | search | IRC | site news
[ Everything | Diaries | Technology | Science | Culture | Politics | Media | News | Internet | Op-Ed | Fiction | Meta | MLP ]
We need your support: buy an ad | premium membership

[P]
Hacking Google Print

By isometrick in Internet
Tue Mar 08, 2005 at 05:13:53 AM EST
Tags: Software (all tags)
Software

Many people are curious about the inner workings of Google, but they are mostly interested in keeping it a secret. So, any information we can glean comes from "black box" analysis. Recently, I wrote a short article that explains how I wrote some simple code that can instantly create PDFs of entire books from Google Print. Maybe some k5ers have more ideas on how to expand the concept, but, as you'll soon find out, I probably can't help in the efforts. Read on ...


Introduction

Many people are interested in how Google works, and Google is mostly interested in keeping it a secret. I'm going to tell you a few things I've learned about Google by playing around with their software . It's not terribly advanced, but I think it's interesting nonetheless. The first thing I will cover is Google's cookie, and then I will explain how I used this information to exploit Google Print.

Google's Cookie

Most web browsers allow small text files, called cookies, to be stored on behalf of web servers ... this allows a persistent state to be associated with a user. After a cookie is created, it will be sent back to the web server every time you request a page (but only when you request a page from the server that originally requested the cookie). For example, when you set your SafeSearch preferences on the Google web site it stores your choice in the Google cookie. Then, whenever you request a page from Google it can see what you set your preference to earlier and use it without having to ask you again. If you delete your cookie, you'll just get a new cookie the next time you visit ... but you'll have to set your preference again. Pretty useful, huh?

Google does some more interesting things with its cookie, though. Some of them are hard to figure out. The first thing to notice is that your cookie will store some preferences locally, like SafeSearch, because Google probably doesn't care if you see that information (it won't bother you to see that they are storing your preferences). Otherwise, they probably have a server side system that uses the following characteristics of the cookie to store more .. ahem .. personalized information about you.

Here is an example of a Google cookie:

GPREF=ID=26b2149fe108b391:TM=1109736400:LM=1109736400:S=pbbDWyL8tVmJrILc

You can see that after "GPREF=", there are name-value pairs ID, TM, LM, and S (separated by colons). In this case, our ID is 26b2149fe108b391. This is a (hopefully) unique ID, and it is most likely generated randomly. Google probably doesn't worry about "collisions" (two users getting the same ID) because this is a 16-digit hexadecimal number, and there are 16^16 = 18446744073709551616 = 18.44674 x 10^18 possible IDs that could be assigned. Even if everyone on the planet used Google, the chance of collision would be very low. Google's cookie has an expiration date of January 17, 2038. Essentially, unless you purposely clear your cookies, format your hard drive, etc. this means it will be with you for a very long time.

The TM value is a timestamp of the moment (to the second) that Google generated your cookie. Here it is 1109736400, measured in seconds since January 1, 1970, or March 1, 2005 at 10:06:40 PM (CST).

LM seems unimportant because it is a timestamp of when the user last changed their preferences. Many other name-value pairs can appear, but the only others that I have seen represent more preferences. Having the unique ID means they are most definitely storing *something* on the server side, but don't worry it's probably only analyzed in aggregate unless you are one of Sergey's ex-girlfriends :-p.

Now, S is the most interesting value in the cookie. Some have hypothesized that it is a checksum of some sort. It could be a hash, for instance. In my experience, the signature only varies with different ID and/or TM values. Thus, Google is assured that THEY generated the cookie at a given time by doing a simple calculation of the hash. But relying on a pure hash would be security through obscurity, i.e. Google would basically be relying on the secrecy of the hash function. Instead, I think that Google probably uses a digital signature algorithm of some kind to generate it. So, maybe S stands for signature. It appears that the signature is 16 characters long, case-sensitive, and alpha-numeric only, giving (10+26+26)^16 possibilities or roughly the equivalent of a 93-bit hash (not incredibly strong by today's standards, but definitely a good chunk of hash). I tried my luck at guessing a hash function and mapping parts to base 62 numbers, but I just don't think that they are stupid enough to do it that way. Sucks for me, because I'm no Bruce Schneier when it comes to cryptography. My instinct is that an attack against the signature would be futile.

Now, the payoff. Well, after another explanation that is :) What are some reasons that Google needs to know you by an ID and when your cookie was created?

Google Print

Google Print URLs are of the form:

http://print.google.com/print?id=VvBRboW2icUC&pg=1&sig=hoLj_9Ot12vG6mSjZ vK547vbP3E

Anything look familiar here? Another signature! Maybe this one is generated in a similar manner (then again, maybe not ... they are probably different teams). The ID in the URL points to the book that you are viewing, and PG points to the page number. Now click the "Next Page" arrow. You'll get a URL like:

http://print.google.com/print?id=VvBRboW2icUC&lpg=1&pg=2&sig=gBBbI6T 0FzHxgVeJJQKQqmZ_MNk

The signature changes when you change pages, and LPG points to the page you started from! Eventually, you will not be able to advance through the pages any more. Google wants to limit you on the amount of pages you can scroll just so you can't read an entire book for free (that would make the publishers very unhappy, and here's my sad face for it :(). Try removing LPG and going to the resulting URL. You'll get a "page not found". So, apparently, the signature depends on the page you entered on, the page you are at, and the book you are viewing. This allows Google to impose their "page lookahead/lookbehind" limit.

You may see a search box on the side of the Google Print page to search within the book. Funny enough, you can use this to search for page numbers and skip through parts of the book. However, it will eventually hit a hard limit based on your unique ID ... i.e. you've viewed too many pages overall in this book; nothing to see here, please move along. Google probably already knows you can skip around pages like this because the search box doesn't appear unless your cookie is 24 hours old or more! Try it, if you have the search box now delete your cookie and refresh the page. The box will disappear! If you saved some of the URLs for the search results of the search-in-book feature, they will also not work! Wait 24 hours or so and try again. Now it works. Here's where the timestamped cookie comes to play. This way, if a user hits the hard limit they cannot clear their cookie and come back instantaneously to leech more pages.

So recently I wrote some software to grab and store up a bunch of cookies, keep them for more than 24 hours, and then automate searching for pages by this method. If I wanted to view page 100, the software would search for it and attempt to extract the image with a regular expression. If that doesn't work, it will search for page 99 and extract the "next page" link to get to page 100. It will continue doing this for page 101, 98, and 102 until it finds the correct page. Whenever a cookie would hit the hard limit, I'd replace it with a new cookie from the queue. By grabbing the "next" and "previous" links automatically in this "inductive" fashion and using the search for skipping, I could view an entire book on Google Print with one click every time. I later modified the software to spit out a PDF of the book. I used simple components like GoogleCookie (cookie with accessible properties), GoogleCookieOven (queue with "baking time", i.e. it only pops when the head of the queue is old enough to get the ability to search), and GoogleCookieBaker (thread that keeps the oven full of baking cookies by querying Google for new ones when the number drops below a certain threshold). Theoretically, if you set the cookie limit to a high enough number, the new cookies being fed in will have aged enough by the time you need them. This is a lot simpler than breaking an unknown digital signature algorithm, but of course that solution *would* be a lot more elegant. Oh well.

I sent a link to this software (web-based) to Google, and I actually got a response! I think they actually changed up some things because the software broke now and then, but it seemed to work consistently after many algorithm improvements. I'll be honest, I was trying to impress them to get in on some of that rumored Google goodness (a.k.a. a job), but they ended up just sending me a Google t-shirt and some pens. Oh, and a note reminding me that my software violated their terms of service.

Instead of giving you the software, I'll give you a general overview of the algorithm and the regular expressions used to extract information:

(read code snippets at the page due to formatting issues.)

The regular expressions are not too advanced, but here they are (I think these are POSIX compliant, but don't quote me on that, and they may be really poorly written since I'm still learning the ropes on regexes):

Individual search-in-book results (captures URL only): <a href="(http://print.google.com/print\?.*?)">
Next page link on book viewing page (captures URL only): <a href="([^<>"]*)"><img align=middle alt="Next
Previous page link on book viewing page (captures URL only): <a href="([^<>"]*)"><img align=middle alt="Previous
The image URL on the book viewing page (it's hidden in CSS): \.theimg\s*\{\s*background-image:\s*url\(\s*"(.*)"\s*\)
Parsing Google's Cookie: \APREF=ID=([a-f0-9]{16}):TM=(\d{10}):LM=(\d{10}):S=([a-zA-Z0-9-_]{16})\z

Conclusion

Sorry, I'd distribute the software (open source, of course), but I don't want to incur "teh wrath of teh google." They have billions of dollars, and I'm a college student. Oh well. Back to the drawing board. Hope you enjoyed this little write up!

Sponsors

Voxel dot net
o Managed Hosting
o VoxCAST Content Delivery
o Raw Infrastructure

Login

Related Links
o Google
o short article
o Google Print
o the page
o Also by isometrick


Display: Sort:
Hacking Google Print | 101 comments (68 topical, 33 editorial, 0 hidden)
-1 DNPIB (1.80 / 10) (#7)
by WetherMan on Mon Mar 07, 2005 at 02:15:39 PM EST

Do Not Post Intro In Body.
---
fluorescent lights make me look like old hot dogs
Can we actually use google print consistently? (none / 0) (#17)
by ultimai on Mon Mar 07, 2005 at 07:10:18 PM EST

A way to actually use google print consitently would be nice too. In all my searches (including the ones given as examples on the http://print.google.com/ page) have come up with nothing.

I have no idea what the fuck you're talking about. (1.04 / 23) (#18)
by kitten on Mon Mar 07, 2005 at 07:52:26 PM EST

And nowhere in the article do I see anything that would make me care to know, either.

-1 for that. Another -1 for "teh wrath of teh google". And a final -1 for basically saying "I know something cool but I'm not telling you".

A combined total of -3 for this miserable, dreary disaster.
mirrorshades radio - darkwave, synthpop, industrial, futurepop.
disturbingly obnoxious Google Print bug (none / 0) (#33)
by Blarney on Mon Mar 07, 2005 at 10:33:33 PM EST

I'm seeing quite a few comments in this thread where people dispute the actual existence of Google Print. Probably this relates to a certain bug which seems to be present with the service.

If you do a Google search for "Pride and prejudice", WITHOUT the quotes, you will get a Google Print link at the top of your search results. But if you enclose "Pride and Prejudice" in quotes, as you would ordinarily to request that Google provide an exact phrase match, there will be no Google Print link.

So if it's your habit to search this way, you won't see Google Print at all. I did just report this bug to the Google Print feedback, hopefully it will not be present forever, perennially confusing people into believing the service to be a bizarrely prankish rumor.

Writing -1 + Content +2 = +1 (1.00 / 4) (#35)
by quincunx on Mon Mar 07, 2005 at 11:48:21 PM EST



-1, Computer Hacking. (1.03 / 28) (#39)
by the ghost of rmg on Tue Mar 08, 2005 at 12:21:34 AM EST

If it's not liberal propaganda it's some sort of illegal computer related activity. Reverse engineering, port scanning, and all the rest of the hacker tools are just the sort of thing Kuro5hin wants to put in the hands of whatever yahoo with internet access decides to show up and take them.

Frankly, I'm tired of worms, tired of increasing music prices, and tired of my second favorite search engine getting screwed with by a bunch of anarchists whose idea of a good time is bilking people out of money, then bitching when they try to recover it.

This is a -1. There are many others like it, but this one is mine.


rmg: comments better than yours.

Nice. (none / 0) (#42)
by Polverone on Tue Mar 08, 2005 at 01:47:02 AM EST

Ideally, though, you would have kept vewwwy quiet (hunting wabbits) about this until you had 50 GB or so of complete books accumulated, then upload them to Usenet. There are lots of web services with imperfect access control measures, but this service has (or will have) a lot of stuff worth taking. It would be a shame if they improved the controls thanks to public discussion of their weaknesses.

For your next trick, can you show how to use cookies and regexes to turn Google Groups into the nice Usenet archive it used to be and not the abomination it has become?
--
It's not a just, good idea; it's the law.

Nice article (3.00 / 3) (#45)
by m a r c on Tue Mar 08, 2005 at 06:43:56 AM EST

Very interesting read. Now that you have informed google, I wonder what they can do about it? How can they differentiate between a user with 'baked' (like yr use of language on this one) cookies and several different users? A heavy handed way would be to record the IP of the user, and if consecutive accesses to the same book with the same IP but a different cookie it might indicate use of a program such as yours.
I got a dog and named him "Stay". Now, I go "Come here, Stay!". After a while, the dog went insane and wouldn't move at all.
Where is the google print... (none / 1) (#51)
by anmo on Tue Mar 08, 2005 at 10:08:34 AM EST

... search page? I can't find a link in the FAQ and I tried everything.

Simple fix? (none / 0) (#59)
by StangDriver on Tue Mar 08, 2005 at 03:00:21 PM EST

If they want to restrict the pages you can read, why not just cutoff the book after page 15? Meaning, no matter how many pages they have you tagged for, you cant read past page 15.

That sounds overly simplistic so what am I overlooking?

And in related news .... (3.00 / 2) (#62)
by isometrick on Tue Mar 08, 2005 at 06:19:29 PM EST

I don't want to jump the gun too soon, but it looks like my site has been blacklisted on Google!

Searching for "greg duffy" returned my site first yesterday, now it is nowhere to be found ... if I can't be Googled, do I exist?

Wonderful. I hope this isn't a precursor of things to come ...

2600 (none / 0) (#69)
by Jebediah on Wed Mar 09, 2005 at 02:53:27 AM EST

Thanks. I have no clue about some of this but it reminds me of the old 2600 mags I used to flip through. Good stuff.

create a p2p to retrive entire book? (none / 0) (#77)
by chucklarge on Wed Mar 09, 2005 at 05:24:28 PM EST

seems like you could expand your idea and create a p2p that farms out the page requests. by equally distruting them, you can help to avoid the hard limits. just an idea...

Google print is gone? (none / 0) (#81)
by flute on Thu Mar 10, 2005 at 07:47:44 AM EST

Looks like someone at Google has read this story. Google print no longer seems to be working for me.

Here's a followup on some of the issues ... (none / 1) (#85)
by isometrick on Thu Mar 10, 2005 at 01:32:41 PM EST

Followup

the first rule of hacking google (none / 0) (#90)
by soundproofing on Fri Mar 11, 2005 at 06:38:31 PM EST

is you do NOT talk about hacking google.
soundproofing, noise control, vibration damping, and acoustics consultant and engineer. http://soundproof.mine.nu/
Anonymous use of Google Print (none / 0) (#91)
by Milly on Sun Mar 13, 2005 at 01:45:11 AM EST

"Having the unique ID means they are most definitely storing *something* on the server side, but don't worry it's probably only analyzed in aggregate unless you are one of Sergey's ex-girlfriends :-p."
As a rule, Sergey's ex-girlfriends take precautions ;)
"It appears that the signature is 16 characters long, case-sensitive, and alpha-numeric only, giving (10+26+26)^16 possibilities"
Both hyphens and underscores are definitely allowed too. Er, I'm no Greg Duffy, so you do the math ...

Thanks for the analysis, from which I've added a section on the potential drawbacks of becoming largely anonymous to Google.

Using a zeroed (or otherwise anonymized) cookie GUID doesn't preclude using Google Print, but it seems that if you browse a book at Google Print, and if someone else has been browsing the same book in the last 24 hours (quite a coincidence), you might find that the content viewing limits have already been reached, or will be reached sooner than otherwise, and you might have to wait 24 hours to read some more.

Also, using the GoogleAnon bookmarklet will attract a reset of the date of the cookie next time it is read by Google, (because the signature/hash will be incorrect: so the server will generate a new date and signature/hash). The anonymous ID will not be overwritten, but if you've used GoogleAnon and visited Google within the last 24 hours, the 'Search within this book' feature may be missing, even if another zeroed cookie user hasn't browsed the same book (but you'll still be able to browse pages/snippets yourself, until you reach the normal content viewing limits).

I guess very heavy users of Google Print might want to save a few old cookies themselves. And of course it's entirely incompatible with your clever hack ;)

That wrinkle apart, I think most people could use an anonymized cookie and Google Print without difficulty.

In a nutshell... (none / 0) (#92)
by Vesperto on Sun Mar 13, 2005 at 03:22:28 PM EST

<quote>I'll be honest, I was trying to impress them to get in on some of that rumored Google goodness (a.k.a. a job), but they ended up just sending me a Google t-shirt and some pens. Oh, and a note reminding me that my software violated their terms of service.</quote> I find the last sentence particulary amusing.
_____________________________
If you disagree post, don't moderate.
Not a Premium User.
Also Skeptical about Google (none / 0) (#95)
by bulk sms on Thu Apr 28, 2005 at 08:24:58 PM EST

I too am sceptical of the inner workings of Google. Although i am yet to experience it myself, i have heard from others that google is placing adverts on people site's without their permission. Even adverts of their competitors. As Google likes to keep their work a secret, this kind of research IS useful, but i doubt we'll ever know the truth unless one of their employees gets overcome with guilt and spills the beans. Let's see.
Save me please from my life of sms online!
Google makes everyone better (none / 0) (#96)
by dogeye on Fri Jun 10, 2005 at 01:21:50 AM EST

Has anyone noticed that anytime google touches anything, their product is always superior to everything else on the market and it immediately causes the competition to improve themselves?

They've made recently invested in keyhole.com, and now keyhole has maps of the entire world! The faster google expands, the happier I'll be.

-Ryan the Infrared Sauna guy

good print (none / 0) (#99)
by soart on Mon Jun 20, 2005 at 11:01:11 PM EST

A way to actually use google print consitently would be nice too.
机票打折机票
THIS IS VERY FUNNY (none / 0) (#100)
by prima1 on Tue Jun 21, 2005 at 12:11:25 PM EST

man this is very funny because just yesterday i found a way to browse through whole books and save their pages and i am no computer expert i found out that if i type the number 200 in the search box inside the book it will show all the pages of the book not missing one single page and everytime my account doesn't allow to view more pages i simply create a new account with a fake email and password no need to verify i have tons of accounts now i just enter a new one everytime and continue browsing but some pages of the books are restricted no matter what actually the restricted pages start at the middle of the book to the end whileas first half of the book is always viewable all of it anyway it doesn't seem to work anymore i am happy i saved everything that i needed they do not have everything anyway many books do not exist and many are old editions

Low text resolution:( (none / 0) (#101)
by azerty on Thu Jun 30, 2005 at 04:17:45 AM EST

In fact you don't need to know anything about cookies to download the whole book. I did this by entering the next page number in the search box and logging in and out from time to time. But what's a really problem is that when I tried to print out the book I realized that the quality is too bad for me to read from the paper. Oups:( spent some 5 hours downloading... The problem is that the resolution is too low for the text to be recognised. At least, I have used ABBY FineReader, and it failed to recognize the text. Anybody knows how to solve this problem?

tonmi (none / 0) (#102)
by tonmi on Tue Jan 03, 2006 at 11:14:01 AM EST

They've made recently invested in keyhole.com, and now keyhole has maps of the entire world! The faster google expands, the happier I'll be.

ocr (none / 0) (#103)
by Seifer on Mon Jan 16, 2006 at 10:21:12 AM EST

well i can not ocr with finereader either. does anyone know why? 'cause picture seems ok but when try to ocr it gets messy.

Hacking Google Print | 101 comments (68 topical, 33 editorial, 0 hidden)
Display: Sort:

kuro5hin.org

[XML]
All trademarks and copyrights on this page are owned by their respective companies. The Rest © 2000 - Present Kuro5hin.org Inc.
See our legalese page for copyright policies. Please also read our Privacy Policy.
Kuro5hin.org is powered by Free Software, including Apache, Perl, and Linux, The Scoop Engine that runs this site is freely available, under the terms of the GPL.
Need some help? Email help@kuro5hin.org.
My heart's the long stairs.

Powered by Scoop create account | help/FAQ | mission | links | search | IRC | YOU choose the stories!