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

[pull] main from msasanmh:main #10

Merged
merged 3 commits into from
Jun 10, 2024
Merged
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
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