Skip to content

Commit

Permalink
v3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
msasanmh committed Jun 8, 2024
1 parent 13ced43 commit 854535d
Show file tree
Hide file tree
Showing 123 changed files with 7,837 additions and 3,306 deletions.
33 changes: 18 additions & 15 deletions ConsoleAppTest/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MsmhToolsClass;
using MsmhToolsClass.MsmhAgnosticServer;
using System.Diagnostics;
using System.Net;

namespace ConsoleAppTest;
Expand All @@ -25,7 +26,7 @@ static async Task Main(string[] args)
// Set ProxyRules Content (Apply Fake DNS and White List Program)
string proxyRulesContent = $"{dohHost}|{dohCleanIP};";
proxyRulesContent += $"\n{dohCleanIP}|+;";
proxyRulesContent += $"\n*|-;"; // Block Other Requests
//proxyRulesContent += $"\n*|-;"; // Block Other Requests

List<string> dnsServers1 = new()
{
Expand All @@ -34,9 +35,9 @@ static async Task Main(string[] args)
//"https://free.shecan.ir/dns-query",
//"tls://dns.google",
//"https://notworking.com/dns-query",
//"tcp://8.8.8.8:53",
"tcp://8.8.8.8:53",
//"udp://8.8.8.8:53",
//"tcp://1.1.1.1:53",
"tcp://1.1.1.1:53",
//"https://every1dns.com/dns-query",
//"https://dns.cloudflare.com/dns-query",
//"https://dns.google/dns-query",
Expand All @@ -49,18 +50,18 @@ static async Task Main(string[] args)
AgnosticSettings settings1 = new()
{
Working_Mode = AgnosticSettings.WorkingMode.DnsAndProxy,
ListenerPort = 53,
ListenerPort = 8080,
DnsTimeoutSec = 10,
ProxyTimeoutSec = 40,
ProxyTimeoutSec = 60,
MaxRequests = 1000000,
KillOnCpuUsage = 40,
DNSs = dnsServers1,
BootstrapIpAddress = IPAddress.Loopback,
BootstrapPort = 53,
BootstrapPort = 8080,
AllowInsecure = false,
BlockPort80 = true,
CloudflareCleanIP = cfClenIP,
UpstreamProxyScheme = $"socks5://{IPAddress.Loopback}:53",
UpstreamProxyScheme = $"socks5://{IPAddress.Loopback}:8080",
//ApplyUpstreamOnlyToBlockedIps = true
};

Expand All @@ -79,7 +80,7 @@ static async Task Main(string[] args)

List<string> dnsServers2 = new()
{
$"udp://{IPAddress.Loopback}:53"
$"udp://{IPAddress.Loopback}:8080"
};

AgnosticSettings settings2 = new()
Expand All @@ -90,7 +91,7 @@ static async Task Main(string[] args)
DNSs = dnsServers2,
MaxRequests = 1000000,
BootstrapIpAddress = IPAddress.Loopback,
BootstrapPort = 53,
BootstrapPort = 8080,
AllowInsecure = false,
//UpstreamProxyScheme = "socks5://192.168.1.120:10808",
//ApplyUpstreamOnlyToBlockedIps = true
Expand All @@ -105,19 +106,21 @@ static async Task Main(string[] args)

await server2.EnableSSL(settingsSSL);


AgnosticProgram.DnsLimit dnsLimit = new();
dnsLimit.Set(true, false, AgnosticProgram.DnsLimit.LimitDoHPathsMode.Text, "msasanmhX");
server2.EnableDnsLimit(dnsLimit);

server1.Start(settings1);
server2.Start(settings2);



DnsMessage dmQ1 = DnsMessage.CreateQuery(DnsEnums.DnsProtocol.UDP, "youtube.com", DnsEnums.RRType.A, DnsEnums.CLASS.IN);
DnsMessage.TryWrite(dmQ1, out byte[] dmQBytes1);
DnsMessage dmQ2 = DnsMessage.CreateQuery(DnsEnums.DnsProtocol.DoH, "mail.yahoo.com", DnsEnums.RRType.A, DnsEnums.CLASS.IN);
DnsMessage.TryWrite(dmQ2, out byte[] dmQBytes2);
string dns = "udp://127.0.0.1:53";
string doh = "https://127.0.0.1:443/dns-query";
string dns = "udp://127.0.0.1:8080";
string doh = "https://127.0.0.1:443/msasanmhX/dns-query";
//doh = "https://dns-cloudflare.com/dns-query";

IPAddress bootIP = IPAddress.Parse("8.8.8.8");
Expand All @@ -136,10 +139,10 @@ static async Task Main(string[] args)
int n = 0;


tt1();
//tt1();
//tt1();
tt2();
//tt1();
//tt2();
//tt2();
//tt2();

Expand Down
135 changes: 135 additions & 0 deletions CypherRSA/CypherRSA.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
using System.Diagnostics;
using System.Security.Cryptography;
using System.Text;

namespace CypherRSA;

// Max Lengh Support 379 Characters
public static class CypherRSA
{
public static void GenerateKeys(out byte[] publicKey, out byte[] privateKey)
{
try
{
using RSA rsaKey = RSA.Create(4096);
publicKey = rsaKey.ExportRSAPublicKey();
privateKey = rsaKey.ExportRSAPrivateKey();
rsaKey.Clear();
}
catch (Exception ex)
{
publicKey = Array.Empty<byte>();
privateKey = Array.Empty<byte>();
Debug.WriteLine("CypherTool GenerateKeys: " + ex.Message);
}
}

public static bool TryEncrypt(byte[] input, byte[] publicKey, out byte[] encryptedBytes, out string encryptedHex)
{
try
{
using RSA rsaKey = RSA.Create(4096);
rsaKey.ImportRSAPublicKey(publicKey, out _);
encryptedBytes = rsaKey.Encrypt(input, RSAEncryptionPadding.OaepSHA512);
encryptedHex = Convert.ToHexString(encryptedBytes);

rsaKey.Clear();
return true;
}
catch (Exception ex)
{
encryptedBytes = Array.Empty<byte>();
encryptedHex = string.Empty;
Debug.WriteLine("CypherTool TryEncrypt 1: " + ex.Message);
return false;
}
}

public static bool TryEncrypt(string inputText, byte[] publicKey, out byte[] encryptedBytes, out string encryptedHex)
{
try
{
byte[] inputBytes = Encoding.UTF8.GetBytes(inputText);
return TryEncrypt(inputBytes, publicKey, out encryptedBytes, out encryptedHex);
}
catch (Exception ex)
{
encryptedBytes = Array.Empty<byte>();
encryptedHex = string.Empty;
Debug.WriteLine("CypherTool TryEncrypt 2: " + ex.Message);
return false;
}
}

public static bool TryDecrypt(byte[] encryptedBytes, byte[] privateKey, out byte[] decryptedBytes)
{
try
{
using RSA rsaKey = RSA.Create(4096);
rsaKey.ImportRSAPrivateKey(privateKey, out _);
decryptedBytes = rsaKey.Decrypt(encryptedBytes, RSAEncryptionPadding.OaepSHA512);
rsaKey.Clear();
return true;
}
catch (Exception ex)
{
decryptedBytes = Array.Empty<byte>();
Debug.WriteLine("CypherTool TryDecrypt 1: " + ex.Message);
return false;
}
}

public static bool TryDecrypt(string encryptedHex, byte[] privateKey, out byte[] decryptedBytes)
{
try
{
byte[] encryptedBytes = Convert.FromHexString(encryptedHex);
return TryDecrypt(encryptedBytes, privateKey, out decryptedBytes);
}
catch (Exception ex)
{
decryptedBytes = Array.Empty<byte>();
Debug.WriteLine("CypherTool TryDecrypt 2: " + ex.Message);
return false;
}
}

public static bool TryDecrypt(byte[] encryptedBytes, byte[] privateKey, out string decryptedText)
{
bool isDecryptionSuccess = TryDecrypt(encryptedBytes, privateKey, out byte[] decryptedBytes);
if (isDecryptionSuccess)
{
try
{
decryptedText = Encoding.UTF8.GetString(decryptedBytes);
return true;
}
catch (Exception ex)
{
decryptedText = string.Empty;
Debug.WriteLine("CypherTool TryDecrypt 3: " + ex.Message);
return false;
}
}
else
{
decryptedText = string.Empty;
return false;
}
}

public static bool TryDecrypt(string encryptedHex, byte[] privateKey, out string decryptedText)
{
try
{
byte[] encryptedBytes = Convert.FromHexString(encryptedHex);
return TryDecrypt(encryptedBytes, privateKey, out decryptedText);
}
catch (Exception ex)
{
decryptedText = string.Empty;
Debug.WriteLine("CypherTool TryDecrypt 4: " + ex.Message);
return false;
}
}
}
28 changes: 28 additions & 0 deletions CypherRSA/CypherRSA.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Title>Cypher RSA Tool</Title>
<Version>$(VersionPrefix)1.0.0</Version>
<Copyright>MSasanMH</Copyright>
<PackageIcon>SecureDNSClient.png</PackageIcon>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<Platforms>AnyCPU;x64;x86</Platforms>
<ApplicationIcon>SecureDNSClientMulti.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<Content Include="SecureDNSClientMulti.ico" />
</ItemGroup>

<ItemGroup>
<None Include="..\SecureDNSClient.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions CypherRSA/CypherRSA.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>D:\PPWin\SecureDNSClient\CypherRSA\Properties\PublishProfiles\X64.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>
Loading

0 comments on commit 854535d

Please sign in to comment.