Forum Moderators: bakedjake

Message Too Old, No Replies

Decoding AOL encquery encoded search strings

Found a solution - a bit hackish though.

         

barofsoap

9:30 pm on Aug 30, 2005 (gmt 0)

10+ Year Member



Hi guys,
I've noticed some recent hits from AOL search URLs ending in something like:
encquery=eed6092f[..snip..]fb15a424bb9ba&invocationType=keyword_rollover&ie=UTF-8

I googled around, tried utf16 decoding, and so forth, but I can't seem to figure out how they encode and decode this pattern. I did find a quick little C++ app on a pastebin:


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/ip.h>
int get(char *server, unsigned short port, char *file, char **out) {
char buffer[256], *content = NULL;
struct hostent *he;
struct sockaddr_in sai;
int s, i, len;
he = gethostbyname(server);
memcpy((char *)&sai.sin_addr, (char *)he->h_addr, sizeof(sai.sin_addr));
sai.sin_family = AF_INET;
sai.sin_port = htons(port);
s = socket(AF_INET, SOCK_STREAM, 0);
if(s < 0) return -1;
if(connect(s, (struct sockaddr *)&sai, sizeof(sai)) < 0) return -2;
len = snprintf(buffer, sizeof(buffer), "GET %s HTTP/1.0\nHost: %s\n\n", file, server);
if(send(s, buffer, len, 0)!= len) return -3;
i = 0;
while(recv(s, &buffer[i], 1, 0)) {
if(i >= sizeof(buffer)) return -4;
if(buffer[i] == (char)10) {
if(buffer[0] == 13) goto GETFILE;
buffer[i-1] = 0;
i = 0;
} else {
i++;
}
}
GETFILE:
len = 0;
while((i = recv(s, buffer, sizeof(buffer), 0))) {
content = realloc(content, len+i+1);
memcpy(&content[len], buffer, i);
len += i;
}
content[len] = 0;
*out = content;
return len;
}
int decode(char *in, char *out) {
char url[256], *content = NULL;
char *start, *end;
int ret = 0;
sprintf(url, "/aol/search?encquery=%s", in);
if(get("aolsearch.aol.com", 80, url, &content)) {
start = strstr(content,"adSetSearch(\'");
if(start) {
start += 13;
end = strchr(start, '\'');
if(end) *end = '\0';
strcpy(out, start);
ret = 1;
}
}
if(content) free(content);
return ret;
}
int main(int argc, char **argv) {
int i;
char *decoded;
if(argc < 2) {
printf("Usage: %s [ENCODED]\n", argv[0]);
return 1;
}
i = strlen(argv[1]);
decoded = malloc(i/2);
if(decode(argv[1], decoded))
printf("[%s]\n", decoded);
else
printf("Nothing found.");
return 0;
}

This little sucker grabs the search term(s) from AOL - so it's not super fast. But it's not really all that slow, either.

Here's how I implemented it in my homebrew stats package:

Paste the contents of the code block above into a new text file on your webserver using pico or whatever. save it as something like 'aoldecode.c'.
Type: gcc -o decoder aoldecode.c
It should work for a moment and then kick you back to the command line.
Type: chmod +x decoder
Finally, for reference,
Type: pwd
and record the path given.

Now, assuming you use PHP, here's how I implemented it:
(note: this assumes you have two variables - the full URL of the search string ($url) and just the search terms (which in this case will just be the long hash), called $terms.)


if(strpos($url, 'encquery=')!== false)
$terms= substr(shell_exec("/path/you/recorded/decoder $terms"), 1, -2);

This'll spit out the decoded search terms in plain text, using AOL's servers for the legwork.

Hope this helps someone!

P.S. here's a string you can use for testing:


D1FB6D1ED141885710F2B93F269B3E5F

Longhaired Genius

9:50 pm on Aug 30, 2005 (gmt 0)

10+ Year Member



I was looking for a solution to this a few days ago and, luckily, I found this:

<?php

$ec=$_GET['q'];
$url = 'http://aolsearch.aol.com/aol/search?encquery='.urlencode($ec);

$f=@join('',@file($url));

$e=@explode("adSetSearch('",$f);
$q=@explode("'",$e[1]);
echo $q[0];

?>

then you use it like this:

[http://41166.com/taol.php?q=c508948d23cba044fab0a302f642fcbb6a50f739b4e7c03ec203b263c0570005]

It was posted in highrankings.com forum by waitman on Sep 28 2003.

barofsoap

10:31 pm on Aug 30, 2005 (gmt 0)

10+ Year Member



I saw that too, but I believe my method is faster, especially since the one you posted requires the use of two separate scripts (although it could easily be modified to be just one).