Skip to content

A DNS And Proxy Server in C# - Supports: UDP, TCP, DNS-Over-HTTPS (DoH), HTTP, HTTPS, SOCKS4, SOCKS4A, SOCKS5.

License

Notifications You must be signed in to change notification settings

msasanmh/MsmhAgnosticServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A DNS and Proxy Server in C# (Class Library .NET 6)

I'm just sharing this library for developers due to recieved requests. It's a multi platform DNS and Proxy Server. Target Platform: Windows. Tested once on Android. You can make it fully compatible with your own target platform.

Library Directory Address.

Nuget Package:
https://www.nuget.org/packages/MsmhAgnosticServer/

DNS Servers: DNS-Over-UDP, DNS-Over-TCP, DNS-Over-HTTPS (DoH)
DNS Clients: DNS-Over-UDP, DNS-Over-TCP, DNS-Over-HTTPS (DoH), DNS-Over-TLS (DoT), DNSCrypt.
Proxy Servers:
HTTP (Domain, IPv4, IPv6) (Get, Post, etc)
HTTPS (Domain, IPv4, IPv6) (Post, etc)
SOCKS4 (IPv4) (Connect, Bind)
SOCKS4A (Domain, IPv4) (Connect, Bind)
SOCKS5 (Domain, IPv4, IPv6) (Connect, Bind, UDP)

DNS Server Features: DNS Records modification, Upstream Proxy, Text based DNS Rules (Block, Fake DNS, Upstream Proxy per domain)
Proxy Server Features: Upstream Proxy, Fragment, Fake SNI, Text based Proxy Rules (Block, Fake DNS, Fake SNI, Custom DNS, Upstream Proxy per domain)

Smart DNS Server: Supported - You can create an Smart DNS Server using DNS Rules (Just modify all A Records and AAAA Records To Your Proxy Server IP).

Running a DNS and Proxy Server on port 8080 example:

// Create Agnostic Server
MsmhAgnosticServer server = new();

// Request Received Event
server.OnRequestReceived += Server_OnRequestReceived;

// A List Of DNS Servers To Connect To
List<string> dnsServers = new()
{
    "sdns://AQMAAAAAAAAAEjEwMy44Ny42OC4xOTQ6ODQ0MyAxXDKkdrOao8ZeLyu7vTnVrT0C7YlPNNf6trdMkje7QR8yLmRuc2NyeXB0LWNlcnQuZG5zLmJlYmFzaWQuY29t",
    "tcp://8.8.8.8:53",
    "tcp://1.1.1.1:53",
    "https://max.rethinkdns.com/dns-query",
    "https://45.90.29.204:443/dns-query",
    "udp://208.67.222.222:5353"
};

// Create Settings For Server
AgnosticSettings settings = new()
{
    Working_Mode = AgnosticSettings.WorkingMode.DnsAndProxy, // Working Mode - Only DNS Or DNS And Proxy
    ListenerPort = 8080, // Server Listning Port
    DnsTimeoutSec = 10, // DNS Request Timeout In Seconds
    ProxyTimeoutSec = 40, // Proxy Request Timeout In Seconds
    MaxRequests = 1000000, // Set Number Of Requests To Handle Per Second
    KillOnCpuUsage = 40, // Kill All Proxy Requests If CPU Usage Goes Above 40%
    DNSs = dnsServers, // Set Our DNS Servers List
    BootstrapIpAddress = IPAddress.Parse("8.8.8.8"), // Set Bootstrap IP Address
    BootstrapPort = 53, // Set Bootstrap Port
    AllowInsecure = false, // Allow Insecure
    BlockPort80 = false, // Block Port 80 On Proxy Requests
    // CloudflareCleanIP = cfClenIP, // You Can Redirect All Cloudflare IPs To A Clean IP (IPv4 Only)
    // UpstreamProxyScheme = $"socks5://{IPAddress.Loopback}:53", // You Can Set Your Upstream Proxy Here
    // ApplyUpstreamOnlyToBlockedIps = true // Apply Upstream Proxy Only To Blocked IPs
};

// Enable Fragment For Proxy Requests
AgnosticProgram.Fragment fragment = new();
fragment.Set(AgnosticProgram.Fragment.Mode.Program, 50, AgnosticProgram.Fragment.ChunkMode.SNI, 5, 2, 1);
server.EnableFragment(fragment);

//// Enable DNS Rules
//AgnosticProgram.DnsRules dnsRules = new();
//dnsRules.Set(AgnosticProgram.DnsRules.Mode.File, "File_Path");
//server.EnableDnsRules(dnsRules);

//// Enable Proxy Rules
//AgnosticProgram.ProxyRules proxyRules = new();
//proxyRules.Set(AgnosticProgram.ProxyRules.Mode.File, "File_Path");
//server.EnableProxyRules(proxyRules);

// Create SSL Settings For Activating DoH And HTTPS Server, Also You Can Change SNI Here (Fake SNI)
AgnosticSettingsSSL settingsSSL = new(true)
{
    EnableSSL = true,
    //ChangeSni = true,
    //DefaultSni = "speedtest.net",
};

await server.EnableSSL(settingsSSL);

// Start Server
server.Start(settings);

// Write To Console
Console.WriteLine($"Msmh Agnostic Server Started On: {settings.ListenerIP}:{settings.ListenerPort}");

About

A DNS And Proxy Server in C# - Supports: UDP, TCP, DNS-Over-HTTPS (DoH), HTTP, HTTPS, SOCKS4, SOCKS4A, SOCKS5.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages