diff --git a/.gitignore b/.gitignore index b6afb91..b6cf559 100644 --- a/.gitignore +++ b/.gitignore @@ -1,61 +1,59 @@ -################# -## Eclipse -################# - -*.pydevproject -.project -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.classpath -.settings/ -.loadpath - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# PDT-specific -.buildpath - - -################# -## Visual Studio -################# - ## 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/master/VisualStudio.gitignore # User-specific files *.suo *.user +*.userosscache *.sln.docstates -# Build results +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs +# Build results [Dd]ebug/ +[Dd]ebugPublic/ [Rr]elease/ +[Rr]eleases/ x64/ -build/ +x86/ +bld/ [Bb]in/ [Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* +# NUNIT +*.VisualState.xml +TestResult.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/ +**/Properties/launchSettings.json + *_i.c *_p.c +*_i.h *.ilk *.meta *.obj @@ -75,21 +73,34 @@ build/ *.vssscc .builds *.pidb -*.log +*.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 @@ -97,6 +108,10 @@ ipch/ # ReSharper is a .NET coding add-in _ReSharper*/ *.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode # TeamCity is a build add-in _TeamCity* @@ -104,9 +119,25 @@ _TeamCity* # DotCover is a Code Coverage Tool *.dotCover +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + # NCrunch -*.ncrunch* +_NCrunch_* .*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ # Installshield output folder [Ee]xpress/ @@ -125,97 +156,150 @@ DocProject/Help/html publish/ # Publish Web Output -*.Publish.xml +*.[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 - -# NuGet Packages Directory -## TODO: If you have NuGet Package Restore enabled, uncomment the next line -#packages/ - -# Windows Azure Build Output -csx +*.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 +# 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 -# Windows Store app package directory +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ # Others -sql/ -*.Cache ClientBin/ -[Ss]tyle[Cc]op.* ~$* *~ *.dbmdl -*.[Pp]ublish.xml +*.dbproj.schemaview +*.jfm *.pfx *.publishsettings +orleans.codegen.cs + +# 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 ;-) +# 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 # SQL Server files -App_Data/*.mdf -App_Data/*.ldf +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ -############# -## Windows detritus -############# +# Typescript v1 declaration files +typings/ -# Windows image file caches -Thumbs.db -ehthumbs.db +# Visual Studio 6 build log +*.plg -# Folder config file -Desktop.ini +# Visual Studio 6 workspace options file +*.opt -# Recycle Bin used on file shares -$RECYCLE.BIN/ +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw -# Mac crap -.DS_Store +# 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/ -############# -## Python -############# +# FAKE - F# Make +.fake/ -*.py[co] +# JetBrains Rider +.idea/ +*.sln.iml -# Packages -*.egg -*.egg-info -dist/ -build/ -eggs/ -parts/ -var/ -sdist/ -develop-eggs/ -.installed.cfg +# CodeRush +.cr/ -# Installer logs -pip-log.txt +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc -# Unit test / coverage reports -.coverage -.tox +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config -#Translations -*.mo +# Tabs Studio +*.tss -#Mr Developer -.mr.developer.cfg +# Telerik's JustMock configuration file +*.jmconfig -############# -## Nuget -############# +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs -*.nupkg \ No newline at end of file +# OpenCover UI analysis results +OpenCover/ \ No newline at end of file diff --git a/Org.Mentalis/Org.Mentalis.csproj b/Org.Mentalis/Org.Mentalis.csproj index d5afb17..c8691cf 100644 --- a/Org.Mentalis/Org.Mentalis.csproj +++ b/Org.Mentalis/Org.Mentalis.csproj @@ -1,65 +1,7 @@ - - - + + - Debug - AnyCPU - {4C3F4F57-A121-44BA-97CE-B5F30ED6A735} - Library - Properties - Org.Mentalis - Org.Mentalis - v4.5.1 - 512 + netstandard2.0;net40 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/Org.Mentalis/Proxy/Client.cs b/Org.Mentalis/Proxy/Client.cs index 12c562c..5be0aab 100644 --- a/Org.Mentalis/Proxy/Client.cs +++ b/Org.Mentalis/Proxy/Client.cs @@ -100,22 +100,42 @@ protected byte[] RemoteBuffer { ///Closes the connections with the local client and the remote host. Once Dispose has been called, this object should not be used anymore. /// public void Dispose() { + try { ClientSocket.Shutdown(SocketShutdown.Both); } catch {} + try { DestinationSocket.Shutdown(SocketShutdown.Both); } catch {} + //Close the sockets - if (ClientSocket != null) - ClientSocket.Close(); - if (DestinationSocket != null) - DestinationSocket.Close(); - //Clean up + if (ClientSocket != null) + { + try + { + ClientSocket.Close(); + } catch {} + } + if (DestinationSocket != null) + { + try + { + DestinationSocket.Close(); + } catch { } + } + + //Clean up ClientSocket = null; DestinationSocket = null; - if (Destroyer != null) - Destroyer(this); + + if (Destroyer != null) + { + try + { + Destroyer(this); + } catch { } + } } ///Returns text information about this Client object. ///A string representing this Client object. diff --git a/Org.Mentalis/Proxy/Http/HttpClient.cs b/Org.Mentalis/Proxy/Http/HttpClient.cs index 93283c2..7b38cc8 100644 --- a/Org.Mentalis/Proxy/Http/HttpClient.cs +++ b/Org.Mentalis/Proxy/Http/HttpClient.cs @@ -128,11 +128,11 @@ protected bool IsValidQuery(string Query) int index = Query.IndexOf("\r\n\r\n"); if (index == -1) return false; - HeaderFields = ParseQuery(Query); + HeaderFields = ParseQuery(Query.Substring(0, index)); if (HttpRequestType.ToUpper().Equals("POST")) { try { int length = int.Parse((string)HeaderFields["Content-Length"]); - return Query.Length >= index + 6 + length; + return Query.Length >= index + 4 + length; } catch { SendBadRequest(); return true; diff --git a/Org.Mentalis/Proxy/Listener.cs b/Org.Mentalis/Proxy/Listener.cs index c29cabb..26de788 100644 --- a/Org.Mentalis/Proxy/Listener.cs +++ b/Org.Mentalis/Proxy/Listener.cs @@ -91,7 +91,7 @@ protected Socket ListenSocket { } ///Gets the list of connected clients. ///An instance of the ArrayList class that's used to store all the connections. - protected ArrayList Clients { + private ArrayList Clients { get { return m_Clients; } @@ -130,13 +130,19 @@ protected void Restart() { ///A client will never be added twice to the list. ///The client to add to the client list. protected void AddClient(Client client) { - if (Clients.IndexOf(client) == -1) - Clients.Add(client); + lock (Clients) + { + if (Clients.IndexOf(client) == -1) + Clients.Add(client); + } } ///Removes the specified Client from the client list. ///The client to remove from the client list. protected void RemoveClient(Client client) { - Clients.Remove(client); + lock (Clients) + { + Clients.Remove(client); + } } ///Returns the number of clients in the client list. ///The number of connected clients. @@ -148,9 +154,12 @@ public int GetClientCount() { ///The requested client. ///If the specified index is invalid, the GetClientAt method returns null. public Client GetClientAt(int Index) { - if (Index < 0 || Index >= GetClientCount()) - return null; - return (Client)Clients[Index]; + lock (Clients) + { + if (Index < 0 || Index >= GetClientCount()) + return null; + return (Client)Clients[Index]; + } } ///Gets a value indicating whether the Listener is currently listening or not. ///A boolean that indicates whether the Listener is currently listening or not. diff --git a/README.md b/README.md index 8e21300..e37c721 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,11 @@ If you are not familiar with C# then you will want to have a look at these free #####Windows -Visual Studio 2012 Express +Visual Studio 2017 Community #####Mac & Linux +Visual Studio Code MonoDevelop ##Before You Build diff --git a/SocksWebProxy.sln b/SocksWebProxy.sln index 028e5ef..3c9d0e0 100644 --- a/SocksWebProxy.sln +++ b/SocksWebProxy.sln @@ -1,13 +1,15 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.27004.2006 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocksWebProxy", "SocksWebProxy\SocksWebProxy.csproj", "{EF64B71A-6512-460E-8F0A-BCD456FF9461}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Org.Mentalis", "Org.Mentalis\Org.Mentalis.csproj", "{B3F3E904-3540-449B-80B0-250645D1B0AE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Org.Mentalis", "Org.Mentalis\Org.Mentalis.csproj", "{4C3F4F57-A121-44BA-97CE-B5F30ED6A735}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestNETCore", "TestNETCore\TestNETCore.csproj", "{63D1D0A2-5681-4FA3-8BDC-C625185D711B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{46C1DAFB-8B4B-4F77-9B43-964BF2DEC92C}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestNETFramework", "TestNETFramework\TestNETFramework.csproj", "{648CA705-0F53-4997-8501-9414BDA890C2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocksWebProxy", "SocksWebProxy\SocksWebProxy.csproj", "{0D5599D1-A672-49D1-ACA1-64ABB7E3EDBF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,20 +17,27 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {EF64B71A-6512-460E-8F0A-BCD456FF9461}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EF64B71A-6512-460E-8F0A-BCD456FF9461}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EF64B71A-6512-460E-8F0A-BCD456FF9461}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EF64B71A-6512-460E-8F0A-BCD456FF9461}.Release|Any CPU.Build.0 = Release|Any CPU - {4C3F4F57-A121-44BA-97CE-B5F30ED6A735}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4C3F4F57-A121-44BA-97CE-B5F30ED6A735}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4C3F4F57-A121-44BA-97CE-B5F30ED6A735}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4C3F4F57-A121-44BA-97CE-B5F30ED6A735}.Release|Any CPU.Build.0 = Release|Any CPU - {46C1DAFB-8B4B-4F77-9B43-964BF2DEC92C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {46C1DAFB-8B4B-4F77-9B43-964BF2DEC92C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {46C1DAFB-8B4B-4F77-9B43-964BF2DEC92C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {46C1DAFB-8B4B-4F77-9B43-964BF2DEC92C}.Release|Any CPU.Build.0 = Release|Any CPU + {B3F3E904-3540-449B-80B0-250645D1B0AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B3F3E904-3540-449B-80B0-250645D1B0AE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B3F3E904-3540-449B-80B0-250645D1B0AE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B3F3E904-3540-449B-80B0-250645D1B0AE}.Release|Any CPU.Build.0 = Release|Any CPU + {63D1D0A2-5681-4FA3-8BDC-C625185D711B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {63D1D0A2-5681-4FA3-8BDC-C625185D711B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {63D1D0A2-5681-4FA3-8BDC-C625185D711B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {63D1D0A2-5681-4FA3-8BDC-C625185D711B}.Release|Any CPU.Build.0 = Release|Any CPU + {648CA705-0F53-4997-8501-9414BDA890C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {648CA705-0F53-4997-8501-9414BDA890C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {648CA705-0F53-4997-8501-9414BDA890C2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {648CA705-0F53-4997-8501-9414BDA890C2}.Release|Any CPU.Build.0 = Release|Any CPU + {0D5599D1-A672-49D1-ACA1-64ABB7E3EDBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0D5599D1-A672-49D1-ACA1-64ABB7E3EDBF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0D5599D1-A672-49D1-ACA1-64ABB7E3EDBF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0D5599D1-A672-49D1-ACA1-64ABB7E3EDBF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3A25D89A-D925-49D2-90D5-2F6FB904EAF5} + EndGlobalSection EndGlobal diff --git a/SocksWebProxy/Properties/AssemblyInfo.cs b/SocksWebProxy/Properties/AssemblyInfo.cs deleted file mode 100644 index f98f8c2..0000000 --- a/SocksWebProxy/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -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("SocksWebProxy")] -[assembly: AssemblyDescription("SocksWebProxy")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Landon Key")] -[assembly: AssemblyProduct("SocksWebProxy")] -[assembly: AssemblyCopyright("Copyright © 2014")] -[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("200b960c-daa9-46c2-82dc-712e0a12d82a")] - -// 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/SocksWebProxy/Proxy/ProxyClient.cs b/SocksWebProxy/Proxy/ProxyClient.cs index eec666e..8819b09 100644 --- a/SocksWebProxy/Proxy/ProxyClient.cs +++ b/SocksWebProxy/Proxy/ProxyClient.cs @@ -64,6 +64,7 @@ protected override void ProcessQuery(string Query) if (HttpRequestType.ToUpper().Equals("POST")) { int index = Query.IndexOf("\r\n\r\n"); + HeaderFields = ParseQuery(Query.Substring(0, index)); m_HttpPost = Query.Substring(index + 4); } } @@ -72,8 +73,8 @@ protected override void ProcessQuery(string Query) DestinationSocket = new ProxySocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); ((ProxySocket)DestinationSocket).ProxyEndPoint = new IPEndPoint(Config.SocksAddress, Config.SocksPort); - ((ProxySocket)DestinationSocket).ProxyUser = "username"; - ((ProxySocket)DestinationSocket).ProxyPass = "password"; + ((ProxySocket)DestinationSocket).ProxyUser = Config.Username; + ((ProxySocket)DestinationSocket).ProxyPass = Config.Password; ((ProxySocket)DestinationSocket).ProxyType = Config.ProxyType; if (HeaderFields.ContainsKey("Proxy-Connection") && HeaderFields["Proxy-Connection"].ToLower().Equals("keep-alive")) diff --git a/SocksWebProxy/Proxy/ProxyConfig.cs b/SocksWebProxy/Proxy/ProxyConfig.cs index 475a1d3..497a4f0 100644 --- a/SocksWebProxy/Proxy/ProxyConfig.cs +++ b/SocksWebProxy/Proxy/ProxyConfig.cs @@ -20,6 +20,8 @@ public enum SocksVersion public int SocksPort { get; set; } public IPAddress SocksAddress { get; set; } public SocksVersion Version { get; set; } + public string Username { get; set; } + public string Password { get; set; } public ProxyTypes ProxyType { @@ -36,6 +38,8 @@ public ProxyConfig() SocksAddress = IPAddress.Parse("127.0.0.1"); SocksPort = 9150; Version = SocksVersion.Five; + Username = ""; + Password = ""; } public ProxyConfig(IPAddress httpIP, int httpPort,IPAddress socksIP,int socksPort,SocksVersion version) { @@ -44,6 +48,18 @@ public ProxyConfig(IPAddress httpIP, int httpPort,IPAddress socksIP,int socksPor SocksAddress = socksIP; SocksPort = socksPort; Version = version; + Username = ""; + Password = ""; + } + public ProxyConfig(IPAddress httpIP, int httpPort, IPAddress socksIP, int socksPort, SocksVersion version, string username, string password) + { + HttpAddress = httpIP; + HttpPort = httpPort; + SocksAddress = socksIP; + SocksPort = socksPort; + Version = version; + Username = username; + Password = password; } } } diff --git a/SocksWebProxy/SocksWebProxy.cs b/SocksWebProxy/SocksWebProxy.cs index c27607f..8735d01 100644 --- a/SocksWebProxy/SocksWebProxy.cs +++ b/SocksWebProxy/SocksWebProxy.cs @@ -10,35 +10,24 @@ namespace com.LandonKey.SocksWebProxy { - public class SocksWebProxy:IWebProxy + public class SocksWebProxy:IWebProxy, IDisposable { - private static object locker = new object(); - private static List listeners; - private static bool allowBypass; - - + private ProxyListener listener; + private bool allowBypass; private ProxyListener GetListener(ProxyConfig config, bool allowBypass = true) { - lock(locker) - { - SocksWebProxy.allowBypass = allowBypass; - if (listeners == null) - listeners = new List(); - - var listener = listeners.Where(x => x.Port == config.HttpPort).FirstOrDefault(); + this.allowBypass = allowBypass; - if(listener == null) - { - listener = new ProxyListener(config); - listener.Start(); - listeners.Add(listener); - } + if(listener == null) + { + listener = new ProxyListener(config); + listener.Start(); + } - if (listener.Version != config.Version) - throw new Exception("Socks Version Mismatch for Port " + config.HttpPort); + if (listener.Version != config.Version) + throw new Exception("Socks Version Mismatch for Port " + config.HttpPort); - return listener; - } + return listener; } private ProxyConfig Config { get; set; } @@ -93,5 +82,23 @@ public bool IsActive() var isSocksPortListening = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().Any(x => x.Port == Config.SocksPort); return isSocksPortListening; } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + ~SocksWebProxy() { + Dispose(); + } + + public void Dispose() + { + if (!disposedValue) + { + listener?.Dispose(); + disposedValue = true; + } + GC.SuppressFinalize(this); + } + #endregion } } diff --git a/SocksWebProxy/SocksWebProxy.csproj b/SocksWebProxy/SocksWebProxy.csproj index 725fb55..64c007d 100644 --- a/SocksWebProxy/SocksWebProxy.csproj +++ b/SocksWebProxy/SocksWebProxy.csproj @@ -1,62 +1,33 @@ - - - + + - Debug - AnyCPU - {EF64B71A-6512-460E-8F0A-BCD456FF9461} - Library - Properties - com.LandonKey.SocksWebProxy - SocksWebProxy - v4.5.1 - 512 + netstandard2.0;net40 + $(TargetsForTfmSpecificBuildOutput);IncludeP2POutput + NET Standard Support + + https://github.com/lloydsparkes/SocksWebProxy + https://github.com/lloydsparkes/SocksWebProxy/README.md + https://github.com/lloydsparkes/SocksWebProxy/ + Copyright 2016 + Net4 SocksWebProxy NetStandard + Landon Key + https://github.com/lloydsparkes/SocksWebProxy/graphs/contributors + 1.4.0.1 + true + DotNet4.SocksProxy - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - + - {4c3f4f57-a121-44ba-97ce-b5f30ed6a735} - Org.Mentalis + true + all - - - \ No newline at end of file + + diff --git a/TestNETCore/Program.cs b/TestNETCore/Program.cs new file mode 100644 index 0000000..d88dff5 --- /dev/null +++ b/TestNETCore/Program.cs @@ -0,0 +1,305 @@ +using com.LandonKey.SocksWebProxy; +using com.LandonKey.SocksWebProxy.Proxy; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Linq.Expressions; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Tests +{ + class Program + { + private static IPAddress oldIp; + static void Main(string[] args) + { + //Start tor + //System.Diagnostics.Process process = new System.Diagnostics.Process(); + //System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); + //startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; + //startInfo.FileName = "cmd.exe"; + //startInfo.Arguments = @""/C "C:\Users\Oscar\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe"" -f ""C:\Users\Oscar\Desktop\Tor Browser\Browser\TorBrowser\Tor\torrc-defaults"""; + //process.StartInfo = startInfo; + //process.Start(); + //process.WaitForExit(); + + //var strCmdText = @"""C:\Users\Oscar\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe"" -f ""C:\Users\Oscar\Desktop\Tor Browser\Browser\TorBrowser\Tor\torrc-defaults"" | more"; + //var strCmdText = "echo Oscar"; + //System.Diagnostics.Process.Start("cmd.exe", strCmdText); + + //Could not start Tor any other way. + //Process cmd = new Process(); + //cmd.StartInfo.FileName = "cmd.exe"; + //cmd.StartInfo.RedirectStandardInput = true; + //cmd.StartInfo.RedirectStandardOutput = true; + //cmd.StartInfo.CreateNoWindow = true; + //cmd.StartInfo.UseShellExecute = false; + //cmd.Start(); + + ////cmd.StandardInput.WriteLine("echo Oscar"); + + //cmd.StandardInput.WriteLine(@"""D:\Tools\Tor\Browser\TorBrowser\Tor\tor.exe"" -f ""D:\Tools\Tor\Browser\TorBrowser\Tor\torrc-defaults"""); + //cmd.StandardInput.Flush(); + //cmd.StandardInput.Close(); + //cmd.WaitForExit(); + //Console.WriteLine(cmd.StandardOutput.ReadToEnd()); + + //Waiting for Tor to start up + //Thread.Sleep(30000); + RunParallel(10, "https://check.torproject.org/"); + + + // wait until the user presses enter + Console.WriteLine(""); + Console.WriteLine("Press enter to continue..."); + Console.ReadLine(); + } + + private static int GetNextFreePort() + { + var listener = new TcpListener(IPAddress.Loopback, 0); + listener.Start(); + var port = ((IPEndPoint)listener.LocalEndpoint).Port; + listener.Stop(); + + return port; + } + + private static void RunParallel(int count, string url) + { + var locker = new object(); + + for (int a = 0; a < count; a++) + { + //if (a != 0) + //{ + // Thread.Sleep(2000); + //} + + var proxy = new SocksWebProxy(new ProxyConfig( + //This is an internal http->socks proxy that runs in process + IPAddress.Parse("127.0.0.1"), + //This is the port your in process http->socks proxy will run on + GetNextFreePort(), + //This could be an address to a local socks proxy (ex: Tor / Tor Browser, If Tor is running it will be on 127.0.0.1) + IPAddress.Parse("127.0.0.1"), + //This is the port that the socks proxy lives on (ex: Tor / Tor Browser, Tor is 9150) + 9150, + //This Can be Socks4 or Socks5 + ProxyConfig.SocksVersion.Five + )); + + proxy = null; + GC.Collect(); + + int counter = 0; + WebClient client = new WebClient(); + client.Headers.Add("Cache-Control", "no-cache"); + client.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache); + //client.Proxy = proxy.IsActive() ? proxy : null; + client.Proxy = proxy; + var doc = new HtmlAgilityPack.HtmlDocument(); + var html = client.DownloadString(url); + doc.LoadHtml(html); + var nodes = doc.DocumentNode.SelectNodes("//p/strong"); + IPAddress ip; + foreach (var node in nodes) + { + try + { + if (IPAddress.TryParse(node.InnerText, out ip)) + { + //lock (locker) + //{ + if (oldIp != null) + { + { + while (oldIp.ToString() != ip.ToString()) + { + counter++; + html = client.DownloadString(url + "?random=" + counter); + doc.LoadHtml(html); + nodes = doc.DocumentNode.SelectNodes("//p/strong"); + int index = nodes.FirstOrDefault().InnerText.IndexOf("<"); + if (index != -1) + IPAddress.TryParse(nodes.FirstOrDefault().InnerText.Substring(0, index), + out ip); + else + { + IPAddress.TryParse(nodes.FirstOrDefault().InnerText, out ip); + } + } + } + + } + oldIp = ip; + Console.WriteLine(a + ":::::::::::::::::::::"); + Console.WriteLine(""); + if (html.Contains("Congratulations. This browser is configured to use Tor.")) + { + Console.WriteLine("Connected through Tor with IP: " + ip.ToString()); + // Connect to tor, get a new identity and drop existing circuits + Socket server = null; + try + { + //Authenticate using control password + IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9151); + server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + server.Connect(endPoint); + server.Send( + Encoding.ASCII.GetBytes("AUTHENTICATE \"password\"" + Environment.NewLine)); + byte[] data = new byte[1024]; + int receivedDataLength = server.Receive(data); + string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); + + //Request a new Identity + server.Send(Encoding.ASCII.GetBytes("SIGNAL NEWNYM" + Environment.NewLine)); + data = new byte[1024]; + receivedDataLength = server.Receive(data); + stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); + if (!stringData.Contains("250")) + { + Console.WriteLine("Unable to signal new user to server."); + server.Shutdown(SocketShutdown.Both); + server.Close(); + } + else + { + Console.WriteLine("SIGNAL NEWNYM sent successfully"); + } + + //Enable circuit events to enable console output + server.Send(Encoding.ASCII.GetBytes("setevents circ" + Environment.NewLine)); + data = new byte[1024]; + receivedDataLength = server.Receive(data); + stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); + + //Get circuit information + server.Send(Encoding.ASCII.GetBytes("getinfo circuit-status" + Environment.NewLine)); + data = new byte[16384]; + receivedDataLength = server.Receive(data); + stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); + stringData = stringData.Substring(stringData.IndexOf("250+circuit-status"), + stringData.IndexOf("250 OK") - stringData.IndexOf("250+circuit-status")); + var stringArray = stringData.Split(new[] {"\r\n"}, StringSplitOptions.None); + foreach (var s in stringArray) + { + if (s.Contains("BUILT")) + { + //Close any existing circuit in order to get a new IP + var circuit = s.Substring(0, s.IndexOf("BUILT")).Trim(); + server.Send( + Encoding.ASCII.GetBytes($"closecircuit {circuit}" + Environment.NewLine)); + data = new byte[1024]; + receivedDataLength = server.Receive(data); + stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); + } + } + } + finally + { + server.Shutdown(SocketShutdown.Both); + server.Close(); + } + } + else + { + Console.Write("Not connected through Tor with IP: " + ip.ToString()); + } + Console.WriteLine(""); + Console.WriteLine(a + ":::::::::::::::::::::"); + } + //} + else + { + //lock (locker) + //{ + Console.WriteLine(a + ":::::::::::::::::::::"); + Console.WriteLine(""); + Console.Write("IP not found"); + Console.WriteLine(""); + Console.WriteLine(a + ":::::::::::::::::::::"); + //} + } + } catch { } + } + } + } + } +} + + +//Enumerable.Range(0, count).ToList().ForEach(new Action(x => +//{ +// if (x != 0) Thread.Sleep(6000); +// WebClient client = new WebClient(); +// //client.Proxy = proxy.IsActive() ? proxy : null; +// client.Proxy = proxy; +// var doc = new HtmlAgilityPack.HtmlDocument(); +// var html = client.DownloadString(url); +// doc.LoadHtml(html); +// var nodes = doc.DocumentNode.SelectNodes("//p/strong"); +// IPAddress ip; +// foreach(var node in nodes) +// { +// if(IPAddress.TryParse(node.InnerText, out ip)) +// { + +// lock (locker) +// { +// Console.WriteLine(x + ":::::::::::::::::::::"); +// Console.WriteLine(""); +// if (html.Contains("Congratulations. This browser is configured to use Tor.")) +// { +// Console.WriteLine("Connected through Tor with IP: " + ip.ToString()); +// Socket server = null; +// try +// { +// IPEndPoint ip2 = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9151); +// server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); +// server.Connect(ip2); +// server.Send(Encoding.ASCII.GetBytes("AUTHENTICATE \"password\"" + Environment.NewLine)); +// byte[] data = new byte[1024]; +// int receivedDataLength = server.Receive(data); +// string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); +// server.Send(Encoding.ASCII.GetBytes("SIGNAL NEWNYM" + Environment.NewLine)); +// data = new byte[1024]; +// receivedDataLength = server.Receive(data); +// stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); +// if (!stringData.Contains("250")) +// { +// Console.WriteLine("Unable to signal new user to server."); +// server.Shutdown(SocketShutdown.Both); +// server.Close(); +// } +// } +// finally +// { +// server.Close(); +// } +// } +// else +// Console.Write("Not connected through Tor with IP: " + ip.ToString()); +// Console.WriteLine(""); +// Console.WriteLine(x + ":::::::::::::::::::::"); +// } +// return; +// } +// } + +// lock (locker) +// { +// Console.WriteLine(x + ":::::::::::::::::::::"); +// Console.WriteLine(""); +// Console.Write("IP not found"); +// Console.WriteLine(""); +// Console.WriteLine(x + ":::::::::::::::::::::"); +// } + +//})); diff --git a/TestNETCore/TestNETCore.csproj b/TestNETCore/TestNETCore.csproj new file mode 100644 index 0000000..0d64181 --- /dev/null +++ b/TestNETCore/TestNETCore.csproj @@ -0,0 +1,17 @@ + + + + Exe + netcoreapp2.0 + + + + + + + + + + + + diff --git a/Tests/App.config b/TestNETFramework/App.config similarity index 59% rename from Tests/App.config rename to TestNETFramework/App.config index 9c05822..74ade9d 100644 --- a/Tests/App.config +++ b/TestNETFramework/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/TestNETFramework/Program.cs b/TestNETFramework/Program.cs new file mode 100644 index 0000000..7e0908f --- /dev/null +++ b/TestNETFramework/Program.cs @@ -0,0 +1,204 @@ +using com.LandonKey.SocksWebProxy; +using com.LandonKey.SocksWebProxy.Proxy; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Linq.Expressions; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Tests +{ + class Program + { + private static IPAddress oldIp; + static void Main(string[] args) + { + RunParallel(10, "https://check.torproject.org/"); + + + // wait until the user presses enter + Console.WriteLine(""); + Console.WriteLine("Press enter to continue..."); + Console.ReadLine(); + } + + private static int GetNextFreePort() + { + var listener = new TcpListener(IPAddress.Loopback, 0); + listener.Start(); + var port = ((IPEndPoint)listener.LocalEndpoint).Port; + listener.Stop(); + + return port; + } + + private static void RunParallel(int count, string url) + { + var locker = new object(); + + for (int a = 0; a < count; a++) + { + //if (a != 0) + //{ + // Thread.Sleep(2000); + //} + + var proxy = new SocksWebProxy(new ProxyConfig( + //This is an internal http->socks proxy that runs in process + IPAddress.Parse("127.0.0.1"), + //This is the port your in process http->socks proxy will run on + GetNextFreePort(), + //This could be an address to a local socks proxy (ex: Tor / Tor Browser, If Tor is running it will be on 127.0.0.1) + IPAddress.Parse("127.0.0.1"), + //This is the port that the socks proxy lives on (ex: Tor / Tor Browser, Tor is 9150) + 9150, + //This Can be Socks4 or Socks5 + ProxyConfig.SocksVersion.Five + )); + + proxy = null; + GC.Collect(); + + int counter = 0; + WebClient client = new WebClient(); + client.Headers.Add("Cache-Control", "no-cache"); + client.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache); + //client.Proxy = proxy.IsActive() ? proxy : null; + client.Proxy = proxy; + var doc = new HtmlAgilityPack.HtmlDocument(); + var html = client.DownloadString(url); + doc.LoadHtml(html); + var nodes = doc.DocumentNode.SelectNodes("//p/strong"); + IPAddress ip; + foreach (var node in nodes) + { + try + { + if (IPAddress.TryParse(node.InnerText, out ip)) + { + //lock (locker) + //{ + if (oldIp != null) + { + { + while (oldIp.ToString() != ip.ToString()) + { + counter++; + html = client.DownloadString(url + "?random=" + counter); + doc.LoadHtml(html); + nodes = doc.DocumentNode.SelectNodes("//p/strong"); + int index = nodes.FirstOrDefault().InnerText.IndexOf("<"); + if (index != -1) + IPAddress.TryParse(nodes.FirstOrDefault().InnerText.Substring(0, index), + out ip); + else + { + IPAddress.TryParse(nodes.FirstOrDefault().InnerText, out ip); + } + } + } + + } + oldIp = ip; + Console.WriteLine(a + ":::::::::::::::::::::"); + Console.WriteLine(""); + if (html.Contains("Congratulations. This browser is configured to use Tor.")) + { + Console.WriteLine("Connected through Tor with IP: " + ip.ToString()); + // Connect to tor, get a new identity and drop existing circuits + Socket server = null; + try + { + //Authenticate using control password + IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9151); + server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + server.Connect(endPoint); + server.Send( + Encoding.ASCII.GetBytes("AUTHENTICATE \"password\"" + Environment.NewLine)); + byte[] data = new byte[1024]; + int receivedDataLength = server.Receive(data); + string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); + + //Request a new Identity + server.Send(Encoding.ASCII.GetBytes("SIGNAL NEWNYM" + Environment.NewLine)); + data = new byte[1024]; + receivedDataLength = server.Receive(data); + stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); + if (!stringData.Contains("250")) + { + Console.WriteLine("Unable to signal new user to server."); + server.Shutdown(SocketShutdown.Both); + server.Close(); + } + else + { + Console.WriteLine("SIGNAL NEWNYM sent successfully"); + } + + //Enable circuit events to enable console output + server.Send(Encoding.ASCII.GetBytes("setevents circ" + Environment.NewLine)); + data = new byte[1024]; + receivedDataLength = server.Receive(data); + stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); + + //Get circuit information + server.Send(Encoding.ASCII.GetBytes("getinfo circuit-status" + Environment.NewLine)); + data = new byte[16384]; + receivedDataLength = server.Receive(data); + stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); + stringData = stringData.Substring(stringData.IndexOf("250+circuit-status"), + stringData.IndexOf("250 OK") - stringData.IndexOf("250+circuit-status")); + var stringArray = stringData.Split(new[] { "\r\n" }, StringSplitOptions.None); + foreach (var s in stringArray) + { + if (s.Contains("BUILT")) + { + //Close any existing circuit in order to get a new IP + var circuit = s.Substring(0, s.IndexOf("BUILT")).Trim(); + server.Send( + Encoding.ASCII.GetBytes($"closecircuit {circuit}" + Environment.NewLine)); + data = new byte[1024]; + receivedDataLength = server.Receive(data); + stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); + } + } + } + finally + { + server.Shutdown(SocketShutdown.Both); + server.Close(); + } + } + else + { + Console.Write("Not connected through Tor with IP: " + ip.ToString()); + } + Console.WriteLine(""); + Console.WriteLine(a + ":::::::::::::::::::::"); + } + //} + else + { + //lock (locker) + //{ + Console.WriteLine(a + ":::::::::::::::::::::"); + Console.WriteLine(""); + Console.Write("IP not found"); + Console.WriteLine(""); + Console.WriteLine(a + ":::::::::::::::::::::"); + //} + } + } + catch { } + } + } + } + } +} + diff --git a/Org.Mentalis/Properties/AssemblyInfo.cs b/TestNETFramework/Properties/AssemblyInfo.cs similarity index 74% rename from Org.Mentalis/Properties/AssemblyInfo.cs rename to TestNETFramework/Properties/AssemblyInfo.cs index c4edb2b..dc01e85 100644 --- a/Org.Mentalis/Properties/AssemblyInfo.cs +++ b/TestNETFramework/Properties/AssemblyInfo.cs @@ -2,35 +2,35 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following +// 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("Org.Mentalis")] +[assembly: AssemblyTitle("TestNETFramework")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Org.Mentalis")] -[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyProduct("TestNETFramework")] +[assembly: AssemblyCopyright("Copyright © 2017")] [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 +// 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("2b884cd0-e92e-477c-b81e-4e553144ed93")] +[assembly: Guid("648ca705-0f53-4997-8501-9414bda890c2")] // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // -// You can specify all the values or you can default the Build and Revision Numbers +// 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")] +[assembly: AssemblyVersion("1.0.0.1")] +[assembly: AssemblyFileVersion("1.0.0.1")] diff --git a/Tests/Tests.csproj b/TestNETFramework/TestNETFramework.csproj similarity index 75% rename from Tests/Tests.csproj rename to TestNETFramework/TestNETFramework.csproj index 4e24a40..f771c18 100644 --- a/Tests/Tests.csproj +++ b/TestNETFramework/TestNETFramework.csproj @@ -1,17 +1,21 @@  - + Debug AnyCPU - {46C1DAFB-8B4B-4F77-9B43-964BF2DEC92C} + {648CA705-0F53-4997-8501-9414BDA890C2} Exe Properties Tests Tests v4.5.1 + TestNETFramework + TestNETFramework + v4.0 512 true + AnyCPU @@ -33,9 +37,6 @@ 4 - - ..\packages\HtmlAgilityPack.1.4.6\lib\Net45\HtmlAgilityPack.dll - @@ -50,20 +51,21 @@ - + + {b3f3e904-3540-449b-80b0-250645d1b0ae} + Org.Mentalis + - {ef64b71a-6512-460e-8f0a-bcd456ff9461} + {0d5599d1-a672-49d1-aca1-64abb7e3edbf} SocksWebProxy + + + 1.6.3 + + - \ No newline at end of file diff --git a/Tests/Program.cs b/Tests/Program.cs deleted file mode 100644 index f142c39..0000000 --- a/Tests/Program.cs +++ /dev/null @@ -1,284 +0,0 @@ -using com.LandonKey.SocksWebProxy; -using com.LandonKey.SocksWebProxy.Proxy; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Net; -using System.Net.Sockets; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace Tests -{ - class Program - { - private static IPAddress oldIp; - static void Main(string[] args) - { - //Start tor - //System.Diagnostics.Process process = new System.Diagnostics.Process(); - //System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); - //startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; - //startInfo.FileName = "cmd.exe"; - //startInfo.Arguments = @""/C "C:\Users\Oscar\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe"" -f ""C:\Users\Oscar\Desktop\Tor Browser\Browser\TorBrowser\Tor\torrc-defaults"""; - //process.StartInfo = startInfo; - //process.Start(); - //process.WaitForExit(); - - //var strCmdText = @"""C:\Users\Oscar\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe"" -f ""C:\Users\Oscar\Desktop\Tor Browser\Browser\TorBrowser\Tor\torrc-defaults"" | more"; - //var strCmdText = "echo Oscar"; - //System.Diagnostics.Process.Start("cmd.exe", strCmdText); - - //Could not start Tor any other way. - Process cmd = new Process(); - cmd.StartInfo.FileName = "cmd.exe"; - cmd.StartInfo.RedirectStandardInput = true; - cmd.StartInfo.RedirectStandardOutput = true; - cmd.StartInfo.CreateNoWindow = true; - cmd.StartInfo.UseShellExecute = false; - cmd.Start(); - - //cmd.StandardInput.WriteLine("echo Oscar"); - - cmd.StandardInput.WriteLine(@"""C:\Users\Oscar\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe"" -f ""C:\Users\Oscar\Desktop\Tor Browser\Browser\TorBrowser\Tor\torrc-defaults"""); - cmd.StandardInput.Flush(); - cmd.StandardInput.Close(); - cmd.WaitForExit(); - //Console.WriteLine(cmd.StandardOutput.ReadToEnd()); - - //Waiting for Tor to start up - Thread.Sleep(1000); - RunParallel(10, "https://check.torproject.org/"); - - - // wait until the user presses enter - Console.WriteLine(""); - Console.WriteLine("Press enter to continue..."); - Console.ReadLine(); - } - - private static void RunParallel(int count, string url) - { - var locker = new object(); - - for (int a = 0; a < count; a++) - { - //if (a != 0) - //{ - // Thread.Sleep(2000); - //} - - var proxy = new SocksWebProxy(new ProxyConfig( - //This is an internal http->socks proxy that runs in process - IPAddress.Parse("127.0.0.1"), - //This is the port your in process http->socks proxy will run on - 12345, - //This could be an address to a local socks proxy (ex: Tor / Tor Browser, If Tor is running it will be on 127.0.0.1) - IPAddress.Parse("127.0.0.1"), - //This is the port that the socks proxy lives on (ex: Tor / Tor Browser, Tor is 9150) - 9150, - //This Can be Socks4 or Socks5 - ProxyConfig.SocksVersion.Five - )); - int counter = 0; - WebClient client = new WebClient(); - client.Headers.Add("Cache-Control", "no-cache"); - client.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache); - //client.Proxy = proxy.IsActive() ? proxy : null; - client.Proxy = proxy; - var doc = new HtmlAgilityPack.HtmlDocument(); - var html = client.DownloadString(url); - doc.LoadHtml(html); - var nodes = doc.DocumentNode.SelectNodes("//p/strong"); - IPAddress ip; - foreach (var node in nodes) - { - if (IPAddress.TryParse(node.InnerText, out ip)) - { - //lock (locker) - //{ - if (oldIp != null) - { - { - while (oldIp.ToString() == ip.ToString()) - { - counter++; - html = client.DownloadString(url + "?random=" + counter); - doc.LoadHtml(html); - nodes = doc.DocumentNode.SelectNodes("//p/strong"); - int index = nodes.FirstOrDefault().InnerText.IndexOf("<"); - if (index != -1) - IPAddress.TryParse(nodes.FirstOrDefault().InnerText.Substring(0, index), out ip); - else - { - IPAddress.TryParse(nodes.FirstOrDefault().InnerText, out ip); - } - } - } - - } - oldIp = ip; - Console.WriteLine(a + ":::::::::::::::::::::"); - Console.WriteLine(""); - if (html.Contains("Congratulations. This browser is configured to use Tor.")) - { - Console.WriteLine("Connected through Tor with IP: " + ip.ToString()); - // Connect to tor, get a new identity and drop existing circuits - Socket server = null; - try - { - //Authenticate using control password - IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9151); - server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - server.Connect(endPoint); - server.Send(Encoding.ASCII.GetBytes("AUTHENTICATE \"password\"" + Environment.NewLine)); - byte[] data = new byte[1024]; - int receivedDataLength = server.Receive(data); - string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); - - //Request a new Identity - server.Send(Encoding.ASCII.GetBytes("SIGNAL NEWNYM" + Environment.NewLine)); - data = new byte[1024]; - receivedDataLength = server.Receive(data); - stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); - if (!stringData.Contains("250")) - { - Console.WriteLine("Unable to signal new user to server."); - server.Shutdown(SocketShutdown.Both); - server.Close(); - } - else - { - Console.WriteLine("SIGNAL NEWNYM sent successfully"); - } - - //Enable circuit events to enable console output - server.Send(Encoding.ASCII.GetBytes("setevents circ" + Environment.NewLine)); - data = new byte[1024]; - receivedDataLength = server.Receive(data); - stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); - - //Get circuit information - server.Send(Encoding.ASCII.GetBytes("getinfo circuit-status" + Environment.NewLine)); - data = new byte[16384]; - receivedDataLength = server.Receive(data); - stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); - stringData = stringData.Substring(stringData.IndexOf("250+circuit-status"), - stringData.IndexOf("250 OK") - stringData.IndexOf("250+circuit-status")); - var stringArray = stringData.Split(new[] { "\r\n" }, StringSplitOptions.None); - foreach (var s in stringArray) - { - if (s.Contains("BUILT")) - { - //Close any existing circuit in order to get a new IP - var circuit = s.Substring(0, s.IndexOf("BUILT")).Trim(); - server.Send(Encoding.ASCII.GetBytes($"closecircuit {circuit}" + Environment.NewLine)); - data = new byte[1024]; - receivedDataLength = server.Receive(data); - stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); - } - } - } - finally - { - server.Shutdown(SocketShutdown.Both); - server.Close(); - } - } - else - { - Console.Write("Not connected through Tor with IP: " + ip.ToString()); - } - Console.WriteLine(""); - Console.WriteLine(a + ":::::::::::::::::::::"); - } - //} - else - { - //lock (locker) - //{ - Console.WriteLine(a + ":::::::::::::::::::::"); - Console.WriteLine(""); - Console.Write("IP not found"); - Console.WriteLine(""); - Console.WriteLine(a + ":::::::::::::::::::::"); - //} - } - } - } - } - } -} - - -//Enumerable.Range(0, count).ToList().ForEach(new Action(x => -//{ -// if (x != 0) Thread.Sleep(6000); -// WebClient client = new WebClient(); -// //client.Proxy = proxy.IsActive() ? proxy : null; -// client.Proxy = proxy; -// var doc = new HtmlAgilityPack.HtmlDocument(); -// var html = client.DownloadString(url); -// doc.LoadHtml(html); -// var nodes = doc.DocumentNode.SelectNodes("//p/strong"); -// IPAddress ip; -// foreach(var node in nodes) -// { -// if(IPAddress.TryParse(node.InnerText, out ip)) -// { - -// lock (locker) -// { -// Console.WriteLine(x + ":::::::::::::::::::::"); -// Console.WriteLine(""); -// if (html.Contains("Congratulations. This browser is configured to use Tor.")) -// { -// Console.WriteLine("Connected through Tor with IP: " + ip.ToString()); -// Socket server = null; -// try -// { -// IPEndPoint ip2 = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9151); -// server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); -// server.Connect(ip2); -// server.Send(Encoding.ASCII.GetBytes("AUTHENTICATE \"password\"" + Environment.NewLine)); -// byte[] data = new byte[1024]; -// int receivedDataLength = server.Receive(data); -// string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); -// server.Send(Encoding.ASCII.GetBytes("SIGNAL NEWNYM" + Environment.NewLine)); -// data = new byte[1024]; -// receivedDataLength = server.Receive(data); -// stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); -// if (!stringData.Contains("250")) -// { -// Console.WriteLine("Unable to signal new user to server."); -// server.Shutdown(SocketShutdown.Both); -// server.Close(); -// } -// } -// finally -// { -// server.Close(); -// } -// } -// else -// Console.Write("Not connected through Tor with IP: " + ip.ToString()); -// Console.WriteLine(""); -// Console.WriteLine(x + ":::::::::::::::::::::"); -// } -// return; -// } -// } - -// lock (locker) -// { -// Console.WriteLine(x + ":::::::::::::::::::::"); -// Console.WriteLine(""); -// Console.Write("IP not found"); -// Console.WriteLine(""); -// Console.WriteLine(x + ":::::::::::::::::::::"); -// } - -//})); diff --git a/Tests/Properties/AssemblyInfo.cs b/Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index dd1864f..0000000 --- a/Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -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("Tests")] -[assembly: AssemblyDescription("Tests the SocksWebProxy")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Landon Key")] -[assembly: AssemblyProduct("SocksWebProxy")] -[assembly: AssemblyCopyright("Copyright © 2014")] -[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("46b9733c-f56d-4cb1-8b43-7bc8e7784cf3")] - -// 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/Tests/packages.config b/Tests/packages.config deleted file mode 100644 index 4292629..0000000 --- a/Tests/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file