Skip to content

Commit c97138c

Browse files
authored
Add files via upload
1 parent 285c582 commit c97138c

File tree

4 files changed

+234
-0
lines changed

4 files changed

+234
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.32112.339
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicChromeDriverDetectionPatch", "BasicChromeDriverDetectionPatch\BasicChromeDriverDetectionPatch.csproj", "{F248F80C-4F89-4BFF-AD5B-5094E712C1BA}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{F248F80C-4F89-4BFF-AD5B-5094E712C1BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{F248F80C-4F89-4BFF-AD5B-5094E712C1BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{F248F80C-4F89-4BFF-AD5B-5094E712C1BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{F248F80C-4F89-4BFF-AD5B-5094E712C1BA}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {2DAE7423-1720-4CA5-8221-DE10E977E833}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0-windows</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<DebugType>none</DebugType>
9+
<BaseOutputPath>..\.build\bin\</BaseOutputPath>
10+
<BaseIntermediateOutputPath>..\.build\obj\</BaseIntermediateOutputPath>
11+
<ErrorReport>none</ErrorReport>
12+
<NeutralLanguage>en-US</NeutralLanguage>
13+
<StartupObject>BasicChromeDriverDetectionPatch.Program</StartupObject>
14+
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
15+
<Authors>Plot</Authors>
16+
<RepositoryType>git</RepositoryType>
17+
<Description>A tool that patches the ChromeDriver binary to avert a "basic" bot detection method used by most anti-automation services.</Description>
18+
<PackageProjectUrl>https://github.com/Plot1337/BasicChromeDriverDetectionPatch</PackageProjectUrl>
19+
<RepositoryUrl>https://github.com/Plot1337/BasicChromeDriverDetectionPatch</RepositoryUrl>
20+
<PackageLicenseFile>..\LICENSE</PackageLicenseFile>
21+
<PackageTags>bot; chrome; automation; csharp; dotnet; selenium; chromedriver; patch; selenium-webdriver; undetected; undetectable</PackageTags>
22+
</PropertyGroup>
23+
24+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
25+
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
26+
</PropertyGroup>
27+
28+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
29+
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
30+
</PropertyGroup>
31+
32+
</Project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
namespace BasicChromeDriverDetectionPatch
2+
{
3+
internal class BinHelper
4+
{
5+
public static List<int> FindOffsets(byte[]? source, byte[] find)
6+
{
7+
if (source == null)
8+
throw new ArgumentNullException(nameof(source));
9+
10+
var result = new List<int>();
11+
int matchIndex = 0;
12+
13+
for (int i = 0; i < source.Length; i++)
14+
{
15+
if (source[i] == find[matchIndex])
16+
{
17+
if (matchIndex == (find.Length - 1))
18+
{
19+
result.Add(i - matchIndex);
20+
continue;
21+
}
22+
23+
matchIndex++;
24+
}
25+
else if (source[i] == find[0]) matchIndex = 1;
26+
else matchIndex = 0;
27+
}
28+
29+
return result;
30+
}
31+
32+
public static byte[] Replace(byte[] source, byte[] search, byte[] replace)
33+
{
34+
byte[]? dst = null;
35+
byte[]? temp = null;
36+
37+
var offsets = FindOffsets(source, search);
38+
39+
foreach (var index in offsets)
40+
{
41+
temp = temp == null ? source : (dst ?? source);
42+
dst = new byte[temp.Length - search.Length + replace.Length];
43+
44+
Buffer.BlockCopy(temp, 0, dst, 0, index);
45+
Buffer.BlockCopy(replace, 0, dst, index, replace.Length);
46+
47+
Buffer.BlockCopy(
48+
temp,
49+
index + search.Length,
50+
dst,
51+
index + replace.Length,
52+
temp.Length - (index + search.Length));
53+
}
54+
55+
return dst ?? source;
56+
}
57+
}
58+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using System.Text;
2+
3+
namespace BasicChromeDriverDetectionPatch
4+
{
5+
internal class Program
6+
{
7+
static byte[]? Data;
8+
9+
static void Main(string[] args)
10+
{
11+
Console.Title =
12+
"Basic ChromeDriver Detection Patch - Plot <github.com/Plot1337>";
13+
14+
if (args.Length == 0)
15+
ErrorExit(
16+
"Usage: [current exe] [path to chromedriver.exe]"
17+
);
18+
19+
string path = args[0];
20+
21+
try
22+
{
23+
Console.WriteLine($"Attempting to load... ({path})");
24+
Data = File.ReadAllBytes(path);
25+
26+
Console.WriteLine("Loaded EXE bin into memory!");
27+
28+
var ids = GetCdcIds();
29+
30+
if (ids.Count == 0)
31+
ErrorExit("No IDs found! Perhaps the EXE is already patched?");
32+
33+
Console.WriteLine($"Found {ids.Count} IDs! Replacing with alts...");
34+
35+
byte[] AsciiStr(string str) =>
36+
Encoding.ASCII.GetBytes(str);
37+
38+
foreach (var id in ids)
39+
{
40+
string alt = RandomString();
41+
42+
Data = BinHelper.Replace(
43+
Data,
44+
AsciiStr(id),
45+
AsciiStr(alt)
46+
);
47+
48+
Console.WriteLine($"{id} -> {alt}");
49+
}
50+
51+
string patchedFilePath = path.Replace(".exe", "_patched.exe");
52+
53+
File.WriteAllBytes(patchedFilePath, Data);
54+
Console.WriteLine("Saved to: " + patchedFilePath);
55+
}
56+
catch (FileNotFoundException) { ErrorExit("Chromedriver EXE not found!"); }
57+
catch (Exception ex) { ErrorExit(ex.ToString()); }
58+
59+
Exit();
60+
}
61+
62+
static List<string> GetCdcIds()
63+
{
64+
Console.WriteLine("Finding CDC ids...");
65+
66+
if (Data == null)
67+
throw new ArgumentNullException(nameof(Data));
68+
69+
int idLen = 26;
70+
var result = new List<string>();
71+
72+
// "cdc_" as bytes
73+
byte[] searchArr = {
74+
0x63, 0x64, 0x63, 0x5F
75+
};
76+
77+
var offsets = BinHelper.FindOffsets(Data, searchArr);
78+
79+
foreach (var offset in offsets)
80+
{
81+
var idBytes = Data.Skip(offset).Take(idLen).ToArray();
82+
string id = Encoding.UTF8.GetString(idBytes);
83+
84+
result.Add(id);
85+
Console.WriteLine($"{offset}: {id}");
86+
}
87+
88+
return result.Distinct().ToList();
89+
}
90+
91+
static string RandomString(int length = 26)
92+
{
93+
var random = new Random();
94+
string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
95+
96+
return new string(
97+
Enumerable.Repeat(chars, length).Select(
98+
i => i[random.Next(i.Length)]
99+
).ToArray()
100+
);
101+
}
102+
103+
static void ErrorExit(string message)
104+
{
105+
Console.ForegroundColor = ConsoleColor.Red;
106+
Console.WriteLine(message);
107+
Console.ForegroundColor = ConsoleColor.White;
108+
109+
Exit();
110+
}
111+
112+
static void Exit()
113+
{
114+
Console.WriteLine("Press any key to exit...");
115+
Console.ReadKey(true);
116+
Environment.Exit(0);
117+
}
118+
}
119+
}

0 commit comments

Comments
 (0)