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

Is it correct for me to call stealth like this? I want the entire browser to pass detection effectively, not a single page. Code: #1039

Closed
cplasfwst opened this issue Apr 15, 2024 · 2 comments
Labels
question Questions related to rod

Comments

@cplasfwst
Copy link

Rod Version: v0.114.8

The code to demonstrate your question

  1. Clone Rod to your local and cd to the repository:

    git clone https://github.com/go-rod/rod
    cd rod
  2. Use your code to replace the content of function TestRod in file rod_test.go.

  3. Test your code with: go test -run TestRod, make sure it fails as expected.

  4. Replace ALL THE CONTENT under "The code to demonstrate your question" with your TestRod function, like below:

func TestRod(t *testing.T) {
    g := setup(t)
    g.Eq(1, 2) // the test should fail, here 1 doesn't equal 2
}

What you got

Such as what error you see.

What you expect to see

Such as what you want to do.

What have you tried to solve the question

Such as after modifying some source code of Rod you are able to get rid of the problem.


Is it correct for me to call stealth like this? I want the entire browser to pass detection effectively, not a single page. Code:
`package main

import (
"fmt"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/devices"
"github.com/go-rod/rod/lib/launcher"
"path/filepath"
"time"
)

var MyDevice = devices.Device{
Title: "Chrome computer",
Capabilities: []string{"touch", "mobile"},
UserAgent: "Mozilla/5.0 (Windows NT 18.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
AcceptLanguage: "cn",
Screen: devices.Screen{
DevicePixelRatio: 2,
Horizontal: devices.ScreenSize{
Width: 1920,
Height: 1080,
},
Vertical: devices.ScreenSize{
Width: 1920,
Height: 1080,
},
},
}

func main() {
//path, _ := launcher.LookPath()
extPath, err := filepath.Abs("fixtures/chrome-extension")
if err != nil {
fmt.Println("出错了:", err)
}
u := launcher.New().Set("--disable-blink-features", "AutomationControlled").Set("no-first-run").Set("disable-default-apps").
Set("load-extension", extPath).
Headless(false).MustLaunch()

browser := rod.New().ControlURL(u).MustConnect()

browser.DefaultDevice(MyDevice)
page := browser.MustPage("https://bot.sannysoft.com/")

time.Sleep(time.Hour * 10)
fmt.Println(page)

}
`

The following is the manifest.json file under the chrome-extension directory under my fixtures directory code:
`{
"manifest_version": 2,

"name": "test",
"description": "Test extension",
"version": "1.0",
"content_scripts": [
{
"js": ["main2.js"],
"matches": ["<all_urls>"]
}
]
}`

main2.js:This file was generated by the npx extract-stealth-evasions command.
code:(({_utilsFns:_utilsFns,_mainFunction:_mainFunction,_args:_args})=>{const utils=Object.fromEntries(Object.entries(_utilsFns).map((([key,value])=>[key,eval(value)])));utils.init(),eval(_mainFunction)(utils,..._args)})({_utilsFns:{init:"() => {\n utils.preloadCache()\n}",stripProxyFromErrors:"(handler = {}) => {\n const newHandler = {\n setPrototypeOf: function (target, proto) {\n if (proto === null)\n throw new TypeError('Cannot convert object to primitive value')\n if (Object.getPrototypeOf(target) === Object.getPrototypeOf(proto)) {\n throw new TypeError('Cyclic __proto__ value')\n }\n return Reflect.setPrototypeOf(target, proto)\n }\n }\n // We wrap each trap in the handler in a try/catch and modify the error stack if they throw\n const traps = Object.getOwnPropertyNames(handler)\n traps.forEach(trap => {\n newHandler[trap] = function () {\n try {\n // Forward the call to the defined proxy handler\n return handler[trap].apply(this, arguments || [])\n } catch (err) {\n // Stack traces differ per browser, we only support chromium based ones currently\n if (!err || !err.stack || !err.stack.includes(at )) {\n throw err\n }\n\n // When something throws within one of our traps the Proxy will show up in error stacks\n // An earlier implementation of this code would simply strip lines with a blacklist,\n // but it makes sense to be more surgical here and only remove lines related to our Proxy.\n // We try to use a known \"anchor\" line for that and strip it with everything above it.\n // If the anchor line cannot be found for some reason we fall back to our blacklist approach.\n\n const stripWithBlacklist = (stack, stripFirstLine = true) => {\n const blacklist = [\n at Reflect.${trap} , // e.g. Reflect.get or Reflect.apply\n at Object.${trap} , // e.g. Object.get or Object.apply\n at Object.newHandler. [as ${trap}] // caused by this very wrapper :-)\n ]\n return (\n err.stack\n .split('\\n')\n // Always remove the first (file) line in the stack (guaranteed to be our proxy)\n .filter((line, index) => !(index === 1 && stripFirstLine))\n // Check if the line starts with one of our blacklisted strings\n ...-----------------------Omit------------------------------省略----------Omit......_srcdoc\n })\n _iframe.srcdoc = newValue\n }\n })\n return iframe\n }\n\n // Adds a hook to intercept iframe creation events\n const addIframeCreationSniffer = () => {\n /* global document */\n const createElementHandler = {\n // Make toString() native\n get(target, key) {\n return Reflect.get(target, key)\n },\n apply: function(target, thisArg, args) {\n const isIframe =\n args && args.length &&${args[0]}.toLowerCase() === 'iframe'\n if (!isIframe) {\n // Everything as usual\n return target.apply(thisArg, args)\n } else {\n return handleIframeCreation(target, thisArg, args)\n }\n }\n }\n // All this just due to iframes with srcdoc bug\n utils.replaceWithProxy(\n document,\n 'createElement',\n createElementHandler\n )\n }\n\n // Let's go\n addIframeCreationSniffer()\n } catch (err) {\n // console.warn(err)\n }\n }",_args:[]});

Ultimately it is how do I call this main2.js file correctly to effectively insert stealth related robot monitoring?

@cplasfwst cplasfwst added the question Questions related to rod label Apr 15, 2024
Copy link

Please fix the format of your markdown:

79 MD046/code-block-style Code block style [Expected: fenced; Actual: indented]
105:2027 MD033/no-inline-html Inline HTML [Element: computed]
105:1212 MD038/no-space-in-code Spaces inside code span elements [Context: "...t blacklist = [\n            `"]

generated by check-issue

@ysmood
Copy link
Collaborator

ysmood commented Apr 15, 2024

#322

@ysmood ysmood closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions related to rod
Projects
None yet
Development

No branches or pull requests

2 participants