Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] -> detect JS tampering #9

Open
unixfox opened this issue Nov 24, 2024 · 8 comments
Open

[feature request] -> detect JS tampering #9

unixfox opened this issue Nov 24, 2024 · 8 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed Lies Related to lied fingerprints

Comments

@unixfox
Copy link

unixfox commented Nov 24, 2024

Hero: https://github.com/ulixee/hero

Seems to claim that it is better than puppeteer, playwright when it comes to scraping: https://ulixee.org/docs/hero/overview/basic-concepts

For now, it doesn't get detected by brotector:

out


I tried to see if there were some things obvious by using https://deviceandbrowserinfo.com/info_device but couldn't find anything.

But creepjs detects it: https://abrahamjuliot.github.io/creepjs/ as "smart enemy".


Example code:

const Hero = require('@ulixee/hero-playground');

(async () => {
  const hero = new Hero();
  await hero.goto('https://kaliiiiiiiiii.github.io/brotector/');
  await new Promise(resolve => setTimeout(resolve, 5000));
  const tab = hero.activeTab;
  const screenshot = await tab.takeScreenshot();
  require("fs").writeFile("out.png", screenshot, 'base64', function(err) {
    console.log(err);
  });
  await hero.close();
})();
@kaliiiiiiiiii
Copy link
Owner

Thanks!

@kaliiiiiiiiii
Copy link
Owner

@unixfox Though, you've forgot to click the button at brotector. Does that cause detection?

@kaliiiiiiiiii kaliiiiiiiiii added the question Further information is requested label Nov 24, 2024
@unixfox
Copy link
Author

unixfox commented Nov 24, 2024

Thank you for your reply!

Indeed I clicked on the button using the documentation: https://ulixee.org/docs/hero/basic-client/interactions

const Hero = require('@ulixee/hero-playground');

(async () => {
  const hero = new Hero();
  await hero.goto('https://kaliiiiiiiiii.github.io/brotector/');
  const tab = hero.activeTab;
  await new Promise(resolve => setTimeout(resolve, 1000));
  const aElem = hero.document.querySelector('button');
  await hero.interact({ click: { element: aElem } })
  await new Promise(resolve => setTimeout(resolve, 3000));
  const screenshot = await tab.takeScreenshot({fullPage: true});
  require("fs").writeFile("out.png", screenshot, 'base64', function(err) {
    console.log(err);
  });
  await hero.close();
})();

And brotector found some interesting things.

out

But maybe we can detect it earlier like creepjs is doing?

@kaliiiiiiiiii
Copy link
Owner

kaliiiiiiiiii commented Nov 24, 2024

But maybe we can detect it earlier like creepjs is doing?

Well, hero injects javascript into the main world which patches stuff.
Detection of JS patching is a cat-and-mouse game, unfortunately.

Usually smth specific to the framework, and code signature-based detection.
Example for reference: #6

const chromedriverSourceMatches = [
"WebDriver", "W3C", "Execute-Script", "cdc_adoQpoasnfa76pfcZLmcfl", "Chromium", "shadow-6066-11e4-a52e-4f735466cecf",
"element-6066-11e4-a52e-4f735466cecf", "STALE_ELEMENT_REFERENCE", "crbug.com/40229283",
"shadow root is detached from the current frame","stale element not found in the current frame"]

brotector/brotector.js

Lines 370 to 389 in a39efef

hook_SeleniumScriptInjection(){
this.hookFunc("Function", "apply", this.SeleniumScriptInjectionHandler.bind(this))
}
SeleniumScriptInjectionHandler(target, thisArg, argumentsList){
let code = thisArg.toString()
let matches = {}
let testStr = undefined
for (testStr of chromedriverSourceMatches){
if(code.indexOf(testStr) !== -1){
if (matches[testStr] == undefined){matches[testStr] = 0}
matches[testStr] += 1
}
}
const len = Object.keys(matches).length
if (len > 0){
this.log({"detection":"SeleniumScriptInjection", "score":0.9, data:{args:argumentsList,matches:matches}})
if(this.crash){throw Error(brotectorBanner)}
}
}
}

@kaliiiiiiiiii kaliiiiiiiiii added help wanted Extra attention is needed good first issue Good for newcomers enhancement New feature or request and removed question Further information is requested labels Nov 24, 2024
@unixfox
Copy link
Author

unixfox commented Nov 24, 2024

Thank you for pointing in the right direction! That's indeed a good idea.

I think creepjs recognize that something is fishy pretty easily thanks to its good prediction mechanism.

Here is a portion of a screenshot taken with hero on creepjs:

image

Hero advertise itself as an Apple device:

image

Hard giveaway when it is ran on a Linux machine.

Lies reported by creepjs:
image

@kaliiiiiiiiii
Copy link
Owner

Lies reported by creepjs: image

Uh yeah could definitely start implementing validation tests for:

  1. Object.defineProperty
  2. Function.prototype.toString
  3. Proxy detection

each on the critical functions and properties

@kaliiiiiiiiii
Copy link
Owner

have added 49eba09#diff-5fcd26e1643bfe21d1ba6b43eff683cf5b09c8340adf89d61261ead09b8e01a0 for now

@kaliiiiiiiiii
Copy link
Owner

kaliiiiiiiiii commented Dec 4, 2024

Lies reported by creepjs: image

Uh yeah could definitely start implementing validation tests for:

  1. Object.defineProperty
  2. Function.prototype.toString
  3. Proxy detection

each on the critical functions and properties

resources for that

Maybe I should start implementing a proper framework with TS... don't really have the time tho

@kaliiiiiiiiii kaliiiiiiiiii changed the title [feature request] detect hero [feature request] -> detect lies Dec 4, 2024
@kaliiiiiiiiii kaliiiiiiiiii added the Lies Related to lied fingerprints label Dec 4, 2024
@kaliiiiiiiiii kaliiiiiiiiii changed the title [feature request] -> detect lies [feature request] -> detect JS tampering Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed Lies Related to lied fingerprints
Projects
None yet
Development

No branches or pull requests

2 participants