commit f328ed86799ea2cd3896df1025749dff20ea3ad5 Author: maxluli Date: Sat Feb 25 10:22:30 2023 +0100 First working version diff --git a/.Gitignore b/.Gitignore new file mode 100644 index 0000000..4507fc7 --- /dev/null +++ b/.Gitignore @@ -0,0 +1,402 @@ +# Created by https://www.toptal.com/developers/gitignore/api/csharp +# Edit at https://www.toptal.com/developers/gitignore?templates=csharp + +### Csharp ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + +# End of https://www.toptal.com/developers/gitignore/api/csharp \ No newline at end of file diff --git a/CookiePython.sln b/CookiePython.sln new file mode 100644 index 0000000..6779dd2 --- /dev/null +++ b/CookiePython.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32526.322 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookiePython", "CookiePython\CookiePython.csproj", "{08A0D7C0-64DA-47AF-BB0C-4342D12FBC8C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {08A0D7C0-64DA-47AF-BB0C-4342D12FBC8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {08A0D7C0-64DA-47AF-BB0C-4342D12FBC8C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {08A0D7C0-64DA-47AF-BB0C-4342D12FBC8C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {08A0D7C0-64DA-47AF-BB0C-4342D12FBC8C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {52C1C305-D77D-45FB-8AFF-CD4836B6A551} + EndGlobalSection +EndGlobal diff --git a/CookiePython/App.config b/CookiePython/App.config new file mode 100644 index 0000000..dfa6665 --- /dev/null +++ b/CookiePython/App.config @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CookiePython/CookiePython.csproj b/CookiePython/CookiePython.csproj new file mode 100644 index 0000000..6cccb33 --- /dev/null +++ b/CookiePython/CookiePython.csproj @@ -0,0 +1,187 @@ + + + + + + Debug + AnyCPU + {08A0D7C0-64DA-47AF-BB0C-4342D12FBC8C} + Exe + CookiePython + CookiePython + v4.7.2 + 512 + true + true + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\BenchmarkDotNet.0.13.5\lib\netstandard2.0\BenchmarkDotNet.dll + + + ..\packages\BenchmarkDotNet.Annotations.0.13.5\lib\netstandard2.0\BenchmarkDotNet.Annotations.dll + + + ..\packages\CommandLineParser.2.4.3\lib\netstandard2.0\CommandLine.dll + + + ..\packages\Microsoft.Diagnostics.Tracing.TraceEvent.3.0.2\lib\net462\Dia2Lib.dll + True + + + ..\packages\Gee.External.Capstone.2.3.0\lib\netstandard2.0\Gee.External.Capstone.dll + + + ..\packages\Iced.1.17.0\lib\net45\Iced.dll + + + ..\packages\Microsoft.Bcl.AsyncInterfaces.1.1.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll + + + ..\packages\Microsoft.CodeAnalysis.Common.3.0.0\lib\netstandard2.0\Microsoft.CodeAnalysis.dll + + + ..\packages\Microsoft.CodeAnalysis.CSharp.3.0.0\lib\netstandard2.0\Microsoft.CodeAnalysis.CSharp.dll + + + ..\packages\Microsoft.Diagnostics.Tracing.TraceEvent.3.0.2\lib\net462\Microsoft.Diagnostics.FastSerialization.dll + + + ..\packages\Microsoft.Diagnostics.NETCore.Client.0.2.251802\lib\netstandard2.0\Microsoft.Diagnostics.NETCore.Client.dll + + + ..\packages\Microsoft.Diagnostics.Runtime.2.2.332302\lib\netstandard2.0\Microsoft.Diagnostics.Runtime.dll + + + ..\packages\Microsoft.Diagnostics.Tracing.TraceEvent.3.0.2\lib\net462\Microsoft.Diagnostics.Tracing.TraceEvent.dll + + + ..\packages\Microsoft.DotNet.PlatformAbstractions.3.1.6\lib\net45\Microsoft.DotNet.PlatformAbstractions.dll + + + ..\packages\Microsoft.Extensions.Configuration.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll + + + ..\packages\Microsoft.Extensions.Configuration.Abstractions.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll + + + ..\packages\Microsoft.Extensions.Configuration.Binder.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Configuration.Binder.dll + + + ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.1.1\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + + ..\packages\Microsoft.Extensions.Logging.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Logging.dll + + + ..\packages\Microsoft.Extensions.Logging.Abstractions.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll + + + ..\packages\Microsoft.Extensions.Options.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Options.dll + + + ..\packages\Microsoft.Extensions.Primitives.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll + + + ..\packages\Microsoft.Win32.Registry.5.0.0\lib\net461\Microsoft.Win32.Registry.dll + + + ..\packages\Microsoft.Diagnostics.Tracing.TraceEvent.3.0.2\lib\net462\OSExtensions.dll + + + ..\packages\Perfolizer.0.2.1\lib\netstandard2.0\Perfolizer.dll + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.CodeDom.6.0.0\lib\net461\System.CodeDom.dll + + + ..\packages\System.Collections.Immutable.5.0.0\lib\net461\System.Collections.Immutable.dll + + + + + ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Reflection.Metadata.1.6.0\lib\netstandard2.0\System.Reflection.Metadata.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.0.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + True + + + ..\packages\System.Security.AccessControl.5.0.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Principal.Windows.5.0.0\lib\net461\System.Security.Principal.Windows.dll + + + ..\packages\System.Text.Encoding.CodePages.4.5.0\lib\net461\System.Text.Encoding.CodePages.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + + + + + + + + ..\packages\Microsoft.Diagnostics.Tracing.TraceEvent.3.0.2\lib\net462\TraceReloggerLib.dll + True + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/CookiePython/Program.cs b/CookiePython/Program.cs new file mode 100644 index 0000000..816a4b2 --- /dev/null +++ b/CookiePython/Program.cs @@ -0,0 +1,87 @@ +using System.Diagnostics; +using System.IO; +using System.Collections.Generic; +using System.Globalization; +using System; +using System.Reflection; + +namespace CookiePython +{ + internal class Program + { + static void Main(string[] args) + { + List cookies = GetChromeCookies(); + + foreach (Cookie c in cookies) + { + Console.WriteLine(c.HostKey); + Console.WriteLine(c.Name); + Console.WriteLine(c.Value); + } + + Console.ReadLine(); + } + public class Cookie + { + public string HostKey { get; set; } + public string Name { get; set; } + public string Value { get; set; } + public string Path { get; set; } + public DateTime ExpiresUtc { get; set; } + public bool IsSecure { get; set; } + public bool IsHttpOnly { get; set; } + } + + public static List GetChromeCookies() + { + string scriptPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "recoverCookiesCSV.py"); + //string scriptPath = "C:/users/Moi/Desktop/recoverCookiesCSV.py"; + ProcessStartInfo start = new ProcessStartInfo(); + start.FileName = "python.exe"; + start.Arguments = scriptPath; + start.UseShellExecute = false; + start.RedirectStandardOutput = true; + Process process = Process.Start(start); + string output = process.StandardOutput.ReadToEnd(); + process.WaitForExit(); + + List cookies = new List(); + + using (var reader = new StreamReader("cookies.csv")) + { + // Read the header row and validate column order + string header = reader.ReadLine(); + string[] expectedColumns = { "host_key", "name", "value", "path", "expires_utc", "is_secure", "is_httponly" }; + string[] actualColumns = header.Split(','); + for (int i = 0; i < expectedColumns.Length; i++) + { + if (expectedColumns[i] != actualColumns[i]) + { + throw new InvalidOperationException($"Expected column '{expectedColumns[i]}' at index {i} but found '{actualColumns[i]}'"); + } + } + + // Read each data row and parse values into a Cookie object + while (!reader.EndOfStream) + { + string line = reader.ReadLine(); + string[] fields = line.Split(','); + Cookie cookie = new Cookie(); + cookie.HostKey = fields[0]; + cookie.Name = fields[1]; + cookie.Value = fields[2]; + cookie.Path = fields[3]; + + cookie.ExpiresUtc = new DateTime(); + if (long.TryParse(fields[4], out long expiresUtcTicks)) + cookie.ExpiresUtc = new DateTime(expiresUtcTicks, DateTimeKind.Utc); + + cookies.Add(cookie); + } + } + + return cookies; + } + } +} diff --git a/CookiePython/Properties/AssemblyInfo.cs b/CookiePython/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..000195d --- /dev/null +++ b/CookiePython/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CookiePython")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CookiePython")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("08a0d7c0-64da-47af-bb0c-4342d12fbc8c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CookiePython/packages.config b/CookiePython/packages.config new file mode 100644 index 0000000..e70064b --- /dev/null +++ b/CookiePython/packages.config @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CookiePython/recoverCookies.py b/CookiePython/recoverCookies.py new file mode 100644 index 0000000..62a973e --- /dev/null +++ b/CookiePython/recoverCookies.py @@ -0,0 +1,62 @@ +import os +import json +import base64 +import sqlite3 +import win32crypt +from Cryptodome.Cipher import AES +from pathlib import Path + + +def get_master_key(): + with open( + os.getenv("localappdata") + "\\Google\\Chrome\\User Data\\Local State", "r" + ) as f: + local_state = f.read() + local_state = json.loads(local_state) + master_key = base64.b64decode(local_state["os_crypt"]["encrypted_key"]) + master_key = master_key[5:] # removing DPAPI + master_key = win32crypt.CryptUnprotectData(master_key, None, None, None, 0)[1] + print("MASTER KEY :") + print(master_key) + print(len(master_key)) + return master_key + + +def decrypt_payload(cipher, payload): + return cipher.decrypt(payload) + + +def generate_cipher(aes_key, iv): + return AES.new(aes_key, AES.MODE_GCM, iv) + + +def decrypt_password(buff, master_key): + try: + iv = buff[3:15] + payload = buff[15:] + cipher = generate_cipher(master_key, iv) + decrypted_pass = decrypt_payload(cipher, payload) + decrypted_pass = decrypted_pass[:-16].decode() # remove suffix bytes + return decrypted_pass + except Exception: + # print("Probably saved password from Chrome version older than v80\n") + # print(str(e)) + return "Chrome < 80" + + +master_key = get_master_key() + +cookies_path = Path( + os.getenv("localappdata") + "\\Google\\Chrome\\User Data\\Default\\Network\\Cookies" +) + +if not cookies_path.exists(): + raise ValueError("Cookies file not found") + +with sqlite3.connect(cookies_path) as connection: + connection.row_factory = sqlite3.Row + cursor = connection.cursor() + cursor.execute("SELECT * FROM cookies") + for row in cursor.fetchall(): + decrypted_value = decrypt_password(row["encrypted_value"], master_key) + print(row["host_key"], row["name"], decrypted_value) diff --git a/ReadMe.md b/ReadMe.md new file mode 100644 index 0000000..d296c3a --- /dev/null +++ b/ReadMe.md @@ -0,0 +1 @@ +# :D \ No newline at end of file