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

Feat/random user agent on browser helper #66

Open
wants to merge 15 commits into
base: StealthImprovements
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions PuppeteerExtraSharp/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void CustomizeUa(Func<string, string> uaAction)
_customAction = uaAction;
}

public override async Task OnPageCreated(Page page)
public override async Task OnPageCreated(IPage page)
{
var ua = await page.Browser.GetUserAgentAsync();
ua = ua.Replace("HeadlessChrome", "Chrome");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public BlockResourcesPlugin RemoveRule(BlockRule rule)
}


public override async Task OnPageCreated(Page page)
public override async Task OnPageCreated(IPage page)
{
await page.SetRequestInterceptionAsync(true);
page.Request += (sender, args) => OnPageRequest(page, args);

}


private async void OnPageRequest(Page sender, RequestEventArgs e)
private async void OnPageRequest(IPage sender, RequestEventArgs e)
{
if (BlockResources.Any(rule => rule.IsRequestBlocked(sender, e.Request)))
{
Expand Down
8 changes: 4 additions & 4 deletions PuppeteerExtraSharp/Plugins/BlockResources/BlockRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace PuppeteerExtraSharp.Plugins.BlockResources
public class BlockRule
{
public string SitePattern;
public Page Page;
public IPage IPage;
public HashSet<ResourceType> ResourceType = new HashSet<ResourceType>();

internal BlockRule()
{

}

public bool IsRequestBlocked(Page fromPage, Request request)
public bool IsRequestBlocked(IPage fromPage, IRequest request)
{
if (!IsResourcesBlocked(request.ResourceType))
return false;
Expand All @@ -24,9 +24,9 @@ public bool IsRequestBlocked(Page fromPage, Request request)
}


public bool IsPageBlocked(Page page)
public bool IsPageBlocked(IPage page)
{
return Page != null && page.Equals(Page);
return IPage != null && page.Equals(IPage);
}

public bool IsSiteBlocked(string siteUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public ResourcesBlockBuilder BlockedResources(params ResourceType[] resources)
return this;
}

public ResourcesBlockBuilder OnlyForPage(Page page)
public ResourcesBlockBuilder OnlyForPage(IPage page)
{
Rule.Page = page;
Rule.IPage = page;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
[assembly: InternalsVisibleTo("Extra.Tests")]
namespace PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions
{
internal class ChromeApp : PuppeteerExtraPlugin
public class ChromeApp : PuppeteerExtraPlugin
{
public ChromeApp(): base("stealth-chromeApp") { }

public override Task OnPageCreated(Page page)
public override Task OnPageCreated(IPage page)
{
var script = Utils.GetScript("ChromeApp.js");
return Utils.EvaluateOnNewPageWithUtilsScript(page, script);
return Utils.EvaluateOnNewPage(page, script);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

namespace PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions
{
internal class ChromeRuntime: PuppeteerExtraPlugin
public class ChromeRuntime: PuppeteerExtraPlugin
{
public ChromeRuntime(): base("stealth-runtime") { }

public override Task OnPageCreated(Page page)
public override Task OnPageCreated(IPage page)
{
var script = Utils.GetScript("Runtime.js");
return Utils.EvaluateOnNewPageWithUtilsScript(page, script);
return Utils.EvaluateOnNewPage(page, script);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

namespace PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions
{
internal class ChromeSci: PuppeteerExtraPlugin
public class ChromeSci: PuppeteerExtraPlugin
{
public ChromeSci(): base("stealth_sci") { }

public override Task OnPageCreated(Page page)
public override Task OnPageCreated(IPage page)
{
var script = Utils.GetScript("SCI.js");
return Utils.EvaluateOnNewPageWithUtilsScript(page, script);
return Utils.EvaluateOnNewPage(page, script);
}
}
}
6 changes: 3 additions & 3 deletions PuppeteerExtraSharp/Plugins/ExtraStealth/Evasions/Codec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

namespace PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions
{
internal class Codec : PuppeteerExtraPlugin
public class Codec : PuppeteerExtraPlugin
{
public Codec() : base("stealth-codec") { }

public override Task OnPageCreated(Page page)
public override Task OnPageCreated(IPage page)
{
var script = Utils.GetScript("Codec.js");
return Utils.EvaluateOnNewPageWithUtilsScript(page, script);
return Utils.EvaluateOnNewPage(page, script);
}
}
}
22 changes: 22 additions & 0 deletions PuppeteerExtraSharp/Plugins/ExtraStealth/Evasions/ContentWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using PuppeteerSharp;

namespace PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions
{
public class ContentWindow : PuppeteerExtraPlugin
{
public ContentWindow() : base("Iframe.ContentWindow") { }

public override List<PluginRequirements> Requirements { get; set; } = new()
{
PluginRequirements.RunLast
};

public override Task OnPageCreated(IPage page)
{
var script = Utils.GetScript("ContentWindow.js");
return Utils.EvaluateOnNewPage(page, script);
}
}
}
22 changes: 0 additions & 22 deletions PuppeteerExtraSharp/Plugins/ExtraStealth/Evasions/Frame.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions
{
internal class HardwareConcurrency : PuppeteerExtraPlugin
public class HardwareConcurrency : PuppeteerExtraPlugin
{
public StealthHardwareConcurrencyOptions Options { get; }

Expand All @@ -12,10 +12,10 @@ public HardwareConcurrency(StealthHardwareConcurrencyOptions options = null) : b
Options = options ?? new StealthHardwareConcurrencyOptions(4);
}

public override Task OnPageCreated(Page page)
public override Task OnPageCreated(IPage page)
{
var script = Utils.GetScript("HardwareConcurrency.js");
return Utils.EvaluateOnNewPageWithUtilsScript(page, script, Options.Concurrency);
return Utils.EvaluateOnNewPage(page, script, Options.Concurrency);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions
{
internal class Languages : PuppeteerExtraPlugin
public class Languages : PuppeteerExtraPlugin
{
public StealthLanguagesOptions Options { get; }

Expand All @@ -13,10 +13,10 @@ public Languages(StealthLanguagesOptions options = null) : base("stealth-languag
Options = options ?? new StealthLanguagesOptions("en-US", "en");
}

public override Task OnPageCreated(Page page)
public override Task OnPageCreated(IPage page)
{
var script = Utils.GetScript("Language.js");
return Utils.EvaluateOnNewPageWithUtilsScript(page,script, Options.Languages);
return Utils.EvaluateOnNewPage(page,script, Options.Languages);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ public class LoadTimes : PuppeteerExtraPlugin
{
public LoadTimes() : base("stealth-loadTimes") { }

public override Task OnPageCreated(Page page)
public override Task OnPageCreated(IPage page)
{
var script = Utils.GetScript("LoadTimes.js");
return Utils.EvaluateOnNewPageWithUtilsScript(page, script);
return Utils.EvaluateOnNewPage(page, script);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using PuppeteerSharp;

namespace PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions
{
internal class OutDimensions : PuppeteerExtraPlugin
public class OutDimensions : PuppeteerExtraPlugin
{
public OutDimensions() : base("stealth-dimensions") { }

public override async Task OnPageCreated(Page page)
public override async Task OnPageCreated(IPage page)
{
var script = Utils.GetScript("Outdimensions.js");
await page.EvaluateFunctionOnNewDocumentAsync(script);
}

public override void BeforeLaunch(LaunchOptions options)
{
options.DefaultViewport = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

namespace PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions
{
internal class Permissions: PuppeteerExtraPlugin
public class Permissions: PuppeteerExtraPlugin
{
public Permissions() : base("stealth-permissions") { }

public override Task OnPageCreated(Page page)
public override Task OnPageCreated(IPage page)
{
var script = Utils.GetScript("Permissions.js");
return Utils.EvaluateOnNewPageWithUtilsScript(page, script);
return Utils.EvaluateOnNewPage(page, script);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@

namespace PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions
{
internal class PluginEvasion: PuppeteerExtraPlugin
public class PluginEvasion : PuppeteerExtraPlugin
{
public PluginEvasion():base("stealth-pluginEvasion") { }
public PluginEvasion() : base("stealth-pluginEvasion")
{
}

public override async Task OnPageCreated(Page page)
public override async Task OnPageCreated(IPage page)
{
var scipt = Utils.GetScript("Plugin.js");
await page.EvaluateFunctionOnNewDocumentAsync(scipt);
await Utils.EvaluateOnNewPage(page, scipt);
}
}
}
}
36 changes: 36 additions & 0 deletions PuppeteerExtraSharp/Plugins/ExtraStealth/Evasions/SourceUrl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Threading.Tasks;
using PuppeteerSharp;

namespace PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions
{
public class SourceUrl : PuppeteerExtraPlugin
{
public SourceUrl() : base("SourceUrl")
{
}

public override async Task OnPageCreated(IPage page)
{
var mainWordProperty =
page.MainFrame.GetType().GetProperty("MainWorld", BindingFlags.NonPublic
| BindingFlags.Public | BindingFlags.Instance);
var mainWordGetters = mainWordProperty.GetGetMethod(true);

page.Load += async (_, _) =>
{
var mainWord = mainWordGetters.Invoke(page.MainFrame, null);
var contextField = mainWord.GetType()
.GetField("_contextResolveTaskWrapper", BindingFlags.NonPublic | BindingFlags.Instance);
if (contextField is not null)
{
var context = (TaskCompletionSource<ExecutionContext>) contextField.GetValue(mainWord);
var execution = await context.Task;
var suffixField = execution.GetType()
.GetField("_evaluationScriptSuffix", BindingFlags.NonPublic | BindingFlags.Instance);
suffixField?.SetValue(execution, "//# sourceURL=''");
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

namespace PuppeteerExtraSharp.Plugins.ExtraStealth.Evasions
{
internal class StackTrace : PuppeteerExtraPlugin
public class StackTrace : PuppeteerExtraPlugin
{
public StackTrace() : base("stealth-stackTrace") { }

public override async Task OnPageCreated(Page page)
public override async Task OnPageCreated(IPage page)
{
var script = Utils.GetScript("Stacktrace.js");
await page.EvaluateFunctionOnNewDocumentAsync(script);
Expand Down
Loading