The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. February 12, 2012, 07:16:28 AM

Login with username, password and session length


Pages: [1] 2
  Print  
Author Topic: Ajax++ Cloaking  (Read 1679 times)
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 9792



View Profile
« on: April 18, 2007, 04:55:37 PM »

Hey NBs-

I see you in here  Wink

Lemmee know when you have enough bandwidth for some code and I'll start barfing it out. Take me just a few minutes to get it clean and separate enough to make sense.

Nice to have you here,
/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 9792



View Profile
« Reply #1 on: April 18, 2007, 06:54:56 PM »

Here's the code for my Ajax Requestor (I'll post usage in a moment):

Code:
// ----------------------------------------------------------- //
//                       ajaxRequestor                         //
// ----------------------------------------------------------- //
function ajaxRequestor() { this.clearAll(); }

ajaxRequestor.prototype.__defaultError = function(sender)
{
var tempStr = "ajaxRequestor Error:\n" +
                  "status: " + this.requestor.status + "\n" +
          "headers: " + this.requestor.getAllResponseHeaders();
alert(tempStr);
}
ajaxRequestor.prototype.__defaultSuccess = function(sender)
{
alert("ajaxRequestor successfully returned from a request - but there is no handler assigned to receive it");
}
ajaxRequestor.prototype.__decodeString = function(inputStr)
{
var decoded = unescape(inputStr);
decoded = decoded.replace(/\%2F/g, "/");
decoded = decoded.replace(/\%3F/g, "?");
decoded = decoded.replace(/\%3D/g, "=");
decoded = decoded.replace(/\%26/g, "&");
decoded = decoded.replace(/\%40/g, "@");
return decoded;
}
ajaxRequestor.prototype.__encodeString = function(inputStr)
{
var encoded = escape(inputStr);
encoded = encoded.replace(/\//g,"%2F");
encoded = encoded.replace(/\?/g,"%3F");
encoded = encoded.replace(/=/g,"%3D");
encoded = encoded.replace(/&/g,"%26");
encoded = encoded.replace(/@/g,"%40");
return encoded;
}
ajaxRequestor.prototype.__getParams = function()
{
if (this.getNames.length == 0) { return ""; }
var out = (this.url.indexOf('?') == -1) ? '?' : '&';
for (var i=0; i<this.getNames.length; i++)
{
out += this.getNames[i] + '=' + this.getValues[i];
if (i < (this.getNames.length - 1)) { out += '&'; }
}
return out;
}
ajaxRequestor.prototype.__getRequestor = function()
{
if ((this.requestor != null) && (!this.reqIsIE)) { return true; }

try {
this.requestor = new XMLHttpRequest();
this.reqIsIE = false;
return; true;
} catch(e) {}

try {
this.requestor = new ActiveXObject("Msxml2.XMLHTTP.6.0");
this.reqIsIE = true;
return; true;
} catch(e) {}

try {
this.requestor = new ActiveXObject("Msxml2.XMLHTTP.3.0");
this.reqIsIE = true;
return; true;
} catch(e) {}

try {
this.requestor = new ActiveXObject("Msxml2.XMLHTTP");
this.reqIsIE = true;
return; true;
} catch(e) {}

try {
this.requestor = new ActiveXObject("Microsoft.XMLHTTP");
this.reqIsIE = true;
return; true;
} catch(e) {}

alert('ajaxRequestor Fatal Error: Cannot instantiate an XMLHTTP Object');
}
ajaxRequestor.prototype.__xmitLog = function(theMsg)
{
var bodyArr = document.getElementsByTagName('body');
var theBody = bodyArr[0];
theBody.appendChild(document.createTextNode(theMsg));
theBody.appendChild(document.createElement('br'));
}
ajaxRequestor.prototype.__onRTS = function()
{
if ((this.requestor.readyState >= 2) && (this.timeoutHandle))
{
clearTimeout(this.timeoutHandle);
this.timeoutHandle = false;
}

    if (this.requestor.readyState == 4)
{
if (this.masterStatus) { this.masterStatus.handleChange(false); }
if ((this.requestor.status==200) || (this.requestor.status==0))
{
this.lastResponse = this.__decodeString(this.requestor.responseText);
if (!this.lastResponse)
{
return false;
}
if (this.xmlHandler)
{
this.xmlHandler.importXML(this.lastResponse);
}
this.onSuccess(this);
} else {
switch(this.requestor.status)
{
case 12029:
case 12030:
case 12031:
case 12152:
case 12159:
// OK: It's the IE SSL bug. Create a tiemout to call <me> again...
//alert('reloading');
var loader = this;
setTimeout( function() { loader.execute.call(loader); }, 10);
break;

default:
this.onError(this);
}
}
this.busy = false;
}
}
ajaxRequestor.prototype.__postParams = function()
{
var out = "";
var varNames = '';
for (var i=0; i<this.postNames.length; i++)
{
if (i > 0) { varNames += '|'; }
varNames += this.postNames[i];
if (i > 0) { out += '&'; }
out += this.postNames[i] + '=' + this.__encodeString(this.postValues[i]);
}
if (out) { out += '&' + 'ajax_var_names=' + varNames; }
return out;
}
ajaxRequestor.prototype.abort = function()
{
if (this.busy)
{
// clear timeout as well
this.requestor.abort();
clearTimeout(this.timeoutHandle);
this.timeoutHandle = false;
this.busy = false;
}
}

ajaxRequestor.prototype.clear = function()
{
this.methodPost = true;
this.__transStatus = 0;
this.__transBusy = false;
    this.lastResponse = new String();
this.selfReference = null;
    this.newRequest();
this.timeoutHandle = false;
this.timeoutMS = 8000;
}
ajaxRequestor.prototype.clearAll = function()
{
    this.xmlHandler = null;
    this.masterStatus = null;
    this.onUnrecognized = new String();

    this.onError = this.__defaultError;
    this.onSuccess = this.__defaultSuccess;
   
    this.clear();
}
ajaxRequestor.prototype.execute = function(timeoutVal)
{
if (this.busy)
{
// clear timeout as well
this.requestor.abort();
this.busy = false;
}

var thisTimeoutVal = this.timeoutMS;
if (timeoutVal != undefined) { thisTimeoutVal = timeoutVal; }

this.__getRequestor();

if (!this.requestor) {
alert("You cannot dispatch a request on this machine (no viable XMLHTTPRequestor)");
return "";
}
if (!this.url) {
alert("You must supply a URL to ajaxRequestor to process a request");
return "";
}

this.busy = true;
var httpMethod = (this.methodPost) ? 'POST' : 'GET';

var theURL = this.url;
theURL += this.__getParams();
this.lastRequest = theURL;

var loader = this;
this.requestor.onreadystatechange = function() { loader.__onRTS.call(loader); }
if (this.masterStatus) { this.masterStatus.handleChange(true); }

// Set a callback to <me> in case the request takes to long...
this.timeoutHandle = setTimeout( function() { loader.__handleTimeout.call(loader); }, this.timeoutMS);

    this.requestor.open('POST', theURL, true);
    this.requestor.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");   

    this.requestor.send(this.__postParams());

}
ajaxRequestor.prototype.__handleAbort = function()
{
if (this.masterStatus) { this.masterStatus.handleChange(false); }
this.requestor.onreadystatechange = null;
this.requestor.abort();
}
ajaxRequestor.prototype.__handleTimeout = function()
{
this.__handleAbort();
var loader = this;
setTimeout(function() { loader.execute.call(loader); }, 100);
}
ajaxRequestor.prototype.getParam = function(key, value)
{
var ptr = this.getNames.length;
for (var i=0; i<this.getNames.length; i++)
{
if (this.getNames[i] == key) { ptr = i; }
}
this.getNames[ptr] = key;
this.getValues[ptr] = value;
}
ajaxRequestor.prototype.method = function(doPost)
{
this.methodPost = (doPost);
}
ajaxRequestor.prototype.newRequest = function()
{
this.getNames = new Array();
this.getValues = new Array();
this.postNames = new Array();
this.postValues = new Array();
this.url = '';
}
ajaxRequestor.prototype.postParam = function(key, value)
{
var ptr = this.postNames.length;
for (var i=0; i<this.postNames.length; i++)
{
if (this.postNames[i] == key) { ptr = i; }
}
this.postNames[ptr] = key;
this.postValues[ptr] = value;
}
« Last Edit: April 18, 2007, 06:56:52 PM by perkiset » Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 9792



View Profile
« Reply #2 on: April 18, 2007, 07:02:48 PM »

Use it like this:

< script >
ajax1 = new ajaxRequestor();
ajax1.url = '/myAjaxURL.php';
ajax1.onSuccess = handleAjax;
ajax1.postParam('paramName', 'paramValue');
ajax1.postParam('anotherParam', 'anotherValue);
ajax1.execute();

function handleAjax(sender)
{
   alert(sender.lastResponse);
}
< / script >
That's about it. You can instantiate as many as you want and the messaging will stay true to the object that sent it. You do not need to pass any params, I just put that here to show you how I do it. I typically have a param, 'request' and a value of "loaditems" or "refreshdata" and such - then I have a single handling page at the server that takes all ajax requests and switch/cases between them.

/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #3 on: April 18, 2007, 07:49:41 PM »

my suggestions.
(hot as shit brain is fried) Smiley
biggest problem with JS is cross browser.

Protype JS lib handles all the ajax shit, plus other funky things, it wieghts in at like 20k,
It is the defacto standard of JS on ruby on rails so have big following.
now days with gzip on sever, that is nothing.

http://www.prototypejs.org/ lib itself
http://www.prototypejs.org/learn/introduction-to-ajax that is how to use it
simplest case stolen from example sheet above

Suppose you have this code in your HTML document:
<h2>Our fantastic products</h2>
<div id="products">(fetching product list ...)</div>

The 'products' container is empty and you want to fill it with HTML returned from an Ajax response. No problem:
new Ajax.Updater('products', '/some_url', { method: 'get' });
some_url returns html whic gets shoved in the products div

this is overview of lib
http://blogs.ebusiness-apps.com/jordan/pages/Prototype%20Library%20Info.htm
It ads to JS useful DOM,string stuff etc, and more importantly make them cross browser.

Anyway my 2 cents Smiley
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 9792



View Profile
« Reply #4 on: April 18, 2007, 09:08:45 PM »

Hey Nop -

we're working through the remains of a concept NB posted @ syndk8 but we wanted to do more privately. The Ajax components is actually very small - he simply needs to be able to reliably throw a single request so that he can corroborate with an image beacon that the user is a for-reals, non-bot surfer. I'm gonna post the code to drop the cookies and check it all in a little bit as well.

All that being said - I'm gonna look at that lib to see if it might make some of my issues smoother - thanks!

/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 9792



View Profile
« Reply #5 on: April 18, 2007, 09:14:23 PM »

Here is a storage class that I use for pushing cookies onto the local site. It is a little heavy for this application, because I use it to store lotsamany cookies in one cookie... but it will do the trick. You can also lighten it up severely (as you can with the ajaxRequestor) to do more single-minded tricks.

// ----------------------------------------------------------- //
//                       localStorage                          //
// ----------------------------------------------------------- //
function localStorage() { this.clear(); }
localStorage.prototype.clear = function()
{
   this.fileName = new String();
}
localStorage.prototype._getRaw = function()
{
   var rawBuff = document.cookie;
   var cookieRegExp = new RegExp("\\b" + this.fileName + "=([^;]*)");
   theValue = cookieRegExp.exec(rawBuff);
   if (theValue != null) { theValue = theValue[1]; }
   return theValue;
}
localStorage.prototype.asArray = function()
{
   var outArr = new Object();
   var rawBuff = this._getRaw(this.fileName);
   if (rawBuff == undefined) { return false; }
   var tempArr = rawBuff.match(/([^&]+)/g);
   for (var i=0; i<tempArr.length; i++)
   {
      var parts = tempArr.match(/([^=]+)=(.*$)/);
      var varName = parts[1];
      var varValue = parts[2];
      outArr[varName] = unescape(varValue);
   }
   return outArr;
}
localStorage.prototype.dropFile = function()
{
   if (this.fileName)
   {
      var expiredDate = new Date();
      expiredDate.SetMonth(-1);
      var writeBuff = this.fileName + "=";
      writeBuff += "expires=" + expiredDate.toGMTString();
      document.cookie = writeBuff;
   }
}
localStorage.prototype.dropItem = function(theName)
{
   var rawBuff = readUnEscapedCookie(this.fileName);
   if (rawBuff)
   {
      var stripAttributeRegExp = new RegExp("(^|/&)" + theName + "=[^&]*&?");
      rawBuff = rawBuff.replace(stripAttributeRegExp, "$1");
      if (rawBuff.length != 0)
      {
         var newBuff = this.fileName + "=" + rawBuff;
         document.cookie = newBuff
      } else { this.dropFile(); }
   }
}
localStorage.prototype.enabled = function()
{
   var cookiesEnabled = window.navigator.cookieEnabled;
   if (!cookiesEnabled)
   {
      document.cookie = "cookiesEnabled=True";
      cookiesEnabled = new Boolean(document.cookie).valueOf();
   }
   return cookiesEnabled;
}
localStorage.prototype.retrieveItem = function(theName)
{
   var rawBuff = this._getRaw(this.fileName);
   var extractMultiValueCookieRegExp = new RegExp("\\b" + theName + "=([^;&]*)");
   resValue = extractMultiValueCookieRegExp.exec(rawBuff);
   if (resValue != null) { resValue = unescape(resValue[1]); }
   return resValue;
}
localStorage.prototype.storeItem = function(theName, theValue)
{
   var rawBuff = this._getRaw(this.fileName);
   if (rawBuff)
   {
      var stripAttributeRegExp = new RegExp("(^|&)" + theName + "=[^&]*&?");
      rawBuff = rawBuff.replace(stripAttributeRegExp, "$1");
      if (rawBuff.length != 0) { rawBuff += "&"; }
   } else rawBuff = "";
   
   rawBuff += theName + "=" + escape(theValue);
   document.cookie = this.fileName + "=" + rawBuff;
}
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 9792



View Profile
« Reply #6 on: April 18, 2007, 09:15:44 PM »

Usage:

storage = new localStorage();
storage.fileName = 'aNameThatIsMeaningfulToYouOrTheApplication';
storage.storeItem('anItemName', 'anItemValue');
var newVal = storage.retrieveItem('anItemName');

Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
thedarkness
Lifer
*****
Offline Offline

Posts: 585



View Profile
« Reply #7 on: May 18, 2007, 04:44:57 AM »

I hear people saying IP delivery is the better method of cloaking......

Advantages/disadvantages over this method?

Cheers,
td
Logged

"I want to be the guy my dog thinks I am."
 - Unknown
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5604


Back in my day we had 9 planets


View Profile
« Reply #8 on: May 18, 2007, 09:25:06 AM »

i still havent gotten around to this, but plan on it.

IP cloaking doesnt catch spiders on new IPs that are specifically out to get you, such as cloak busters.

the advantage with this is that you require enough things that a real surfer would have enabled, and you can protect your final destination even when the IPs fail. Although this is still cloaking, i would actually call it Human Traffic Direction. I dont want to cloak to the spider, i want to direct the humans.

the scenario is very similar to a normal doorway bot detection cloak. you have a content site and a sales site. you dont care if the spiders find either site, you just dont want them to make a connection between the two. doorways would be an example. When a user or a bot land directly on the sales site, great, whatever, who cares, thats what you want anyway and it was a freebee. But when a user lands on a doorway, you want them directed to the sales site, per normal. When a bot lands on the doorway, you just keep them there.

Not really any different than doorway cloaking, but instead of checking to see if its a bot, flip the paradigm around, and instead, check to see if the surfer is human. Captchas use the same concept, since they cant reliably tell if you are an automation anymore, they now make you-the-human do something to prove it.

My thought was to make your system prove your human.
can i cookie you?
can you request an image from within the same usersession?
can you do JS?
can you do AJAX?

no bot does that all.
make sense?

i still would do IP cloaking as well, for a while. the thing is, if something like that became mainstream, the bots would start looking for it you would think right? so you can still test IPs to catch "smart bots" and now you know your human director is now pooched and it was fun while it lasted.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
thedarkness
Lifer
*****
Offline Offline

Posts: 585



View Profile
« Reply #9 on: May 18, 2007, 04:47:34 PM »

OK, so both, of course nothing will save you from a Google employee with a browser on an unknown IP but that's the risk we take I guess (no way around that).

Cheers,
td
Logged

"I want to be the guy my dog thinks I am."
 - Unknown
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #10 on: May 18, 2007, 04:51:18 PM »

In a nutshell simplicity.
If you are going to get nailed IP cloaking will not save your ass, nor will it fool the savy internet user.

JS Cloaking on the other hand is simple, plus it does not require you have control over the host.
I personally use a version of full iframe cloaking that i stole off sndk8
Logged
thedarkness
Lifer
*****
Offline Offline

Posts: 585



View Profile
« Reply #11 on: May 18, 2007, 11:50:12 PM »

So if a humans looking to bust you, they're going to bust you.

Cheers,
td
Logged

"I want to be the guy my dog thinks I am."
 - Unknown
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #12 on: May 19, 2007, 12:03:05 AM »

So if a humans looking to bust you, they're going to bust you.
That is the way i see it.
If you get busted does not matter as long as u have made a profit Smiley.

Logged
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5604


Back in my day we had 9 planets


View Profile
« Reply #13 on: May 19, 2007, 12:36:51 AM »

i agree as well.

for me, this is more a matter of stats control and traffic control. the usage I have planned for this is both the cloaking aspect to hide the destination sites from engines, but also for legitimate redirectionification of users.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 9792



View Profile
« Reply #14 on: May 19, 2007, 12:50:09 AM »

@redirectionification  ROFLMAO

Hey... what are we still doing up and @ our machines?

Losers!  ROFLMAO

G'Night,
/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1] 2
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!