Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.
Open
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
60 changes: 43 additions & 17 deletions src/Milky/Checker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private async Task StartCpmCounterAsync()

private void OutputCombo(Combo combo, CheckResult checkResult)
{
if (checkResult.ComboResult == ComboResult.Invalid && !_outputSettings.OutputInvalids)
if ((checkResult.ComboResult == ComboResult.Invalid && !_outputSettings.OutputInvalids) || checkResult.ComboResult == ComboResult.Banned)
{
return;
}
Expand Down Expand Up @@ -239,31 +239,57 @@ private void OutputCombo(Combo combo, CheckResult checkResult)

File.AppendAllText(globalOutputPath, outputString + Environment.NewLine);
}
}

Console.ForegroundColor = checkResult.ComboResult switch
{
ComboResult.Hit => _outputSettings.HitColor,
ComboResult.Free => _outputSettings.FreeColor,
ComboResult.Invalid => _outputSettings.InvalidColor
};

if (_outputSettings.CustomColors.Count > 0 && checkResult.Captures != null)
Console.ForegroundColor = checkResult.ComboResult switch
{
ComboResult.Hit => _outputSettings.HitColor,
ComboResult.Free => _outputSettings.FreeColor,
ComboResult.Invalid => _outputSettings.InvalidColor,
ComboResult.Banned => _outputSettings.BannedColor,
ComboResult.Unknown => _outputSettings.UnknownColor
};

if (_outputSettings.CustomColors.Count > 0 && checkResult.Captures != null)
{
foreach (var customColor in _outputSettings.CustomColors)
{
foreach (var customColor in _outputSettings.CustomColors)
if (checkResult.Captures.TryGetValue(customColor.Value.Key, out var capturedObject))
{
if (checkResult.Captures.TryGetValue(customColor.Value.Key, out var capturedObject))
if (customColor.Value.Value(capturedObject))
{
if (customColor.Value.Value(capturedObject))
{
Console.ForegroundColor = customColor.Key;
break;
}
Console.ForegroundColor = customColor.Key;
break;
}
}
}
}

Console.WriteLine(outputString);
switch (checkResult.ComboResult)
{
case ComboResult.Free:
if (_outputSettings.DisplayFrees)
Console.WriteLine(outputString);
break;
case ComboResult.Unknown:
if (_outputSettings.DisplayUnknowns)
Console.WriteLine(outputString);
break;
case ComboResult.Banned:
if (_outputSettings.DisplayBanneds)
Console.WriteLine(outputString);
break;
case ComboResult.Invalid:
if (_outputSettings.OutputInvalids)
Console.WriteLine(outputString);
break;
case ComboResult.Hit:
default:
Console.WriteLine(outputString);
break;
}


Info.LastHit = DateTime.Now;
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/Milky/CheckerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public CheckerBuilder WithProxies(IEnumerable<Proxy> proxies)
{
foreach (var proxy in proxies.Where(p => p.Valid))
{
_httpClientLibrary.Add(proxy.GetHttpClient());
_httpClientLibrary.Add(proxy.GetHttpClient(_checkerSettings));
}

return this;
Expand Down Expand Up @@ -112,7 +112,9 @@ private void SetUpHttpClientLibrary()

_httpClientLibrary.Add(new HttpClient(new HttpClientHandler()
{
UseCookies = false // Using cookies would suck with shared HttpClients, especially for credential stuffing
AllowAutoRedirect = _checkerSettings.AllowAutoRedirect,
MaxAutomaticRedirections = _checkerSettings.MaxAutomaticRedirections,
UseCookies = _checkerSettings.UseCookies // Using cookies would suck with shared HttpClients, especially for credential stuffing
}));
}
else if (_httpClientLibrary.Items.Count == 0)
Expand Down Expand Up @@ -140,4 +142,4 @@ private void SetUpMiscellaneous(int extraThreads = 10)
Directory.CreateDirectory(_outputSettings.OutputDirectory);
}
}
}
}
4 changes: 3 additions & 1 deletion src/Milky/Enums/ComboResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public enum ComboResult
Retry,
Invalid,
Free,
Hit
Hit,
Banned,
Unknown
}
}
14 changes: 11 additions & 3 deletions src/Milky/Models/CheckerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ public class CheckerSettings
{
/// <param name="maxThreads">Maximum combos to check concurrently</param>
/// <param name="useProxies">Whether proxies should be used or not</param>
public CheckerSettings(int maxThreads, bool useProxies)
/// <param name="useCookies">Whether or not to use/save/keep cookies, usually not recommended for credential stuffing but who knows</param>
/// <param name="AllowAutoRedirect">Whether or not to follow redirections</param>
/// <param name="MaxAutomaticRedirections">Max automatic request redirections</param>
public CheckerSettings(int maxThreads, bool useProxies, bool useCookies = false, bool allowAutoRedirect = true, int maxAutomaticRedirections = 50)
{
MaxThreads = maxThreads;
UseProxies = useProxies;
UseCookies = useCookies;
AllowAutoRedirect = allowAutoRedirect;
MaxAutomaticRedirections = maxAutomaticRedirections;
}

public int MaxThreads { get; }

public bool UseProxies { get; }
public bool UseCookies { get; }
public bool AllowAutoRedirect { get; set; }
public int MaxAutomaticRedirections { get; set; }
}
}
}
25 changes: 25 additions & 0 deletions src/Milky/Models/OutputSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ public class OutputSettings
/// </summary>
public bool OutputInvalids { get; set; } = false;

/// <summary>
/// Whether to display free's in console
/// </summary>
public bool DisplayFrees { get; set; } = true;

/// <summary>
/// Whether to display unknown's in console
/// </summary>
public bool DisplayUnknowns { get; set; } = false;

/// <summary>
/// Whether to display banned's in console
/// </summary>
public bool DisplayBanneds { get; set; } = false;

/// <summary>
/// Separator that's going to be used to separate the combo and the capture, as well as each capture
/// </summary>
Expand All @@ -34,6 +49,16 @@ public class OutputSettings
/// </summary>
public ConsoleColor FreeColor { get; set; } = ConsoleColor.Cyan;

/// <summary>
/// Console output color for <see cref="ComboResult.Unknown"/>
/// </summary>
public ConsoleColor UnknownColor { get; set; } = ConsoleColor.DarkRed;

/// <summary>
/// Console output color for <see cref="ComboResult.Banned"/>
/// </summary>
public ConsoleColor BannedColor { get; set; } = ConsoleColor.Yellow;

/// <summary>
/// Console output color for <see cref="ComboResult.Invalid"/>
/// </summary>
Expand Down
37 changes: 20 additions & 17 deletions src/Milky/Models/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public Proxy(string proxy, ProxySettings settings)

internal NetworkCredential Credentials { get; }

public HttpClient GetHttpClient(CookieContainer cookieContainer = null)
public HttpClient GetHttpClient(CheckerSettings checkerSettings, CookieContainer cookieContainer = null)
{
var httpMessageHandler = GetHttpMessageHandler(cookieContainer);
var httpMessageHandler = GetHttpMessageHandler(checkerSettings, cookieContainer);

var httpClient = new HttpClient(httpMessageHandler)
{
Expand All @@ -63,50 +63,53 @@ public HttpClient GetHttpClient(CookieContainer cookieContainer = null)
return httpClient;
}

public HttpMessageHandler GetHttpMessageHandler(CookieContainer cookieContainer = null)
public HttpMessageHandler GetHttpMessageHandler(CheckerSettings checkerSettings, CookieContainer cookieContainer = null)
{
if (Settings.Protocol == ProxyProtocol.HTTP)
{
return new HttpClientHandler()
{
Proxy = new WebProxy(Host, Port) { Credentials = Credentials },
AllowAutoRedirect = Settings.AllowAutoRedirect,
UseCookies = Settings.UseCookies,
CookieContainer = cookieContainer ?? new CookieContainer()
AllowAutoRedirect = checkerSettings.AllowAutoRedirect,
UseCookies = checkerSettings.UseCookies,
CookieContainer = cookieContainer ?? new CookieContainer(),
MaxAutomaticRedirections = checkerSettings.MaxAutomaticRedirections
};
}

var timeoutMilliseconds = (int)Settings.Timeout.TotalMilliseconds;

var proxySettings = new SocksSharp.Proxy.ProxySettings()
{
Host = Host, Port = Port,
Host = Host,
Port = Port,
Credentials = Credentials,
ConnectTimeout = timeoutMilliseconds,
ReadWriteTimeOut = timeoutMilliseconds
};

// Note: MaxAutomaticRedirections not supported by SocksSharp
return Settings.Protocol switch
{
ProxyProtocol.SOCKS4 => new ProxyClientHandler<Socks4>(proxySettings)
{
AllowAutoRedirect = Settings.AllowAutoRedirect,
UseCookies = Settings.UseCookies,
CookieContainer = cookieContainer
AllowAutoRedirect = checkerSettings.AllowAutoRedirect,
UseCookies = checkerSettings.UseCookies,
CookieContainer = cookieContainer ?? new CookieContainer(),
},
ProxyProtocol.SOCKS4A => new ProxyClientHandler<Socks4a>(proxySettings)
{
AllowAutoRedirect = Settings.AllowAutoRedirect,
UseCookies = Settings.UseCookies,
CookieContainer = cookieContainer
AllowAutoRedirect = checkerSettings.AllowAutoRedirect,
UseCookies = checkerSettings.UseCookies,
CookieContainer = cookieContainer ?? new CookieContainer(),
},
ProxyProtocol.SOCKS5 => new ProxyClientHandler<Socks5>(proxySettings)
{
AllowAutoRedirect = Settings.AllowAutoRedirect,
UseCookies = Settings.UseCookies,
CookieContainer = cookieContainer
AllowAutoRedirect = checkerSettings.AllowAutoRedirect,
UseCookies = checkerSettings.UseCookies,
CookieContainer = cookieContainer ?? new CookieContainer(),
}
};
}
}
}
}
13 changes: 1 addition & 12 deletions src/Milky/Models/ProxySettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Milky.Enums;
using System;
using System.Net;

namespace Milky.Models
{
Expand All @@ -19,15 +18,5 @@ public ProxySettings(ProxyProtocol protocol)
public bool Rotating { get; set; } = false;

public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(10);

/// <summary>
/// Whether or not to follow redirections
/// </summary>
public bool AllowAutoRedirect { get; set; } = true;

/// <summary>
/// Whether or not to use/save/keep cookies, usually not recommended for credential stuffing but who knows
/// </summary>
public bool UseCookies { get; set; } = false;
}
}
}