mirror of
https://github.com/Stone-Red-Code/FraudCapturer.git
synced 2026-09-04 09:06:06 +02:00
- Fix messed up output colors
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using PacketDotNet;
|
||||
|
||||
using Stone_Red_Utilities.ConsoleExtentions;
|
||||
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
@@ -49,7 +51,7 @@ internal class DomainHelper
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
Console.WriteLine($"error: {ex.Message}");
|
||||
ConsoleExt.WriteLine($"error: {ex.Message}", ConsoleColor.Gray);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -72,7 +74,7 @@ internal class DomainHelper
|
||||
}
|
||||
catch (SocketException ex)
|
||||
{
|
||||
Console.WriteLine($"error: {ex.Message} ({domain})");
|
||||
ConsoleExt.WriteLine($"error: {ex.Message} ({domain})", ConsoleColor.Gray);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SharpPcap" Version="6.1.0" />
|
||||
<PackageReference Include="Stone_Red-C-Sharp-Utilities" Version="1.0.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
+12
-18
@@ -1,4 +1,6 @@
|
||||
using System.Net;
|
||||
using Stone_Red_Utilities.ConsoleExtentions;
|
||||
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace FraudCapturer;
|
||||
@@ -18,7 +20,7 @@ internal class IpHelper
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
Console.WriteLine($"error: {ex.Message}");
|
||||
ConsoleExt.WriteLine($"error: {ex.Message}", ConsoleColor.Gray);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -31,10 +33,10 @@ internal class IpHelper
|
||||
|
||||
if (statusValue.GetString() != "ok")
|
||||
{
|
||||
Console.Write(statusValue.GetString());
|
||||
ConsoleExt.Write(statusValue.GetString(), ConsoleColor.Gray);
|
||||
if (responseData.RootElement.TryGetProperty("message", out JsonElement messageValue))
|
||||
{
|
||||
Console.WriteLine($": {messageValue.GetString()}");
|
||||
ConsoleExt.WriteLine($": {messageValue.GetString()}", ConsoleColor.Gray);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -96,21 +98,13 @@ internal class IpHelper
|
||||
}
|
||||
|
||||
byte[] ip = IPAddress.Parse(ipAdress).GetAddressBytes();
|
||||
switch (ip[0])
|
||||
return ip[0] switch
|
||||
{
|
||||
case 10:
|
||||
case 127:
|
||||
return true;
|
||||
|
||||
case 172:
|
||||
return ip[1] >= 16 && ip[1] < 32;
|
||||
|
||||
case 192:
|
||||
return ip[1] == 168;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
10 or 127 => true,
|
||||
172 => ip[1] >= 16 && ip[1] < 32,
|
||||
192 => ip[1] == 168,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
public static bool IsLocalIpAddress(string host)
|
||||
|
||||
+23
-26
@@ -3,6 +3,8 @@ using PacketDotNet;
|
||||
|
||||
using SharpPcap;
|
||||
|
||||
using Stone_Red_Utilities.ConsoleExtentions;
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net;
|
||||
|
||||
@@ -38,10 +40,8 @@ public class Program
|
||||
|
||||
if (string.IsNullOrWhiteSpace(args.FirstOrDefault()))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("No proxycheck api key provided! You are limited to 100 IP checks per day. Get one for free at proxycheck.io.");
|
||||
ConsoleExt.WriteLine("No proxycheck api key provided! You are limited to 100 IP checks per day. Get one for free at proxycheck.io.", ConsoleColor.Red);
|
||||
Console.WriteLine();
|
||||
Console.ResetColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -93,7 +93,7 @@ public class Program
|
||||
device.Open();
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("-- Listening on {0}, hit 'Ctrl-C' to exit...", device.Description);
|
||||
Console.WriteLine($"-- Listening on {device.Description}, hit 'Ctrl-C' to exit...");
|
||||
|
||||
// Start capture of packets
|
||||
device.Capture();
|
||||
@@ -139,7 +139,7 @@ public class Program
|
||||
capturedIpsCache.Clear();
|
||||
capturedDomainsCache.Clear();
|
||||
File.WriteAllText(IpStorePath, string.Empty);
|
||||
Console.WriteLine("Cleared cache");
|
||||
ConsoleExt.WriteLine("Cleared cache", ConsoleColor.Gray);
|
||||
}
|
||||
|
||||
//Check if a DNS packet contains a "dangerous" domain.
|
||||
@@ -156,7 +156,7 @@ public class Program
|
||||
await CheckIpAddress(remoteIpAddress, direction);
|
||||
|
||||
TimeSpan timeRemainingUntilCacheReset = new TimeSpan(0, 10, 0) - (DateTime.Now - lastCacheClear);
|
||||
Console.WriteLine($"Next cache reset in {timeRemainingUntilCacheReset.Minutes} minute(s) and {timeRemainingUntilCacheReset.Seconds} second(s)");
|
||||
ConsoleExt.WriteLine($"Next cache reset in {timeRemainingUntilCacheReset.Minutes} minute(s) and {timeRemainingUntilCacheReset.Seconds} second(s)", ConsoleColor.Gray);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,43 +167,42 @@ public class Program
|
||||
|
||||
if (IpHelper.IsInternalIpAddress(remoteIpAddress.ToString()))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||
Console.WriteLine($"[{direction}] [Internal] {remoteIpAddress}");
|
||||
ConsoleExt.WriteLine($"[{direction}] [Internal] {remoteIpAddress}", ConsoleColor.Cyan);
|
||||
}
|
||||
else if (ipInfo is not null)
|
||||
{
|
||||
bool block = false;
|
||||
ConsoleColor consoleColor;
|
||||
|
||||
if (ipInfo.Risk >= 67)
|
||||
{
|
||||
FirewallHelper.BlockIp(remoteIpAddress);
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
consoleColor = ConsoleColor.Red;
|
||||
block = true;
|
||||
}
|
||||
else if (ipInfo.Risk >= 34 && ipInfo.IsProxy)
|
||||
{
|
||||
FirewallHelper.BlockIp(remoteIpAddress);
|
||||
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
||||
consoleColor = ConsoleColor.DarkYellow;
|
||||
block = true;
|
||||
}
|
||||
else if (ipInfo.IsProxy && ipInfo.Type != "VPN")
|
||||
{
|
||||
FirewallHelper.BlockIp(remoteIpAddress);
|
||||
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
||||
consoleColor = ConsoleColor.DarkYellow;
|
||||
block = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
consoleColor = ConsoleColor.Green;
|
||||
}
|
||||
|
||||
Console.WriteLine($"[{direction}] [Provider: {ipInfo.Provider}] [Risk: {ipInfo.Risk}] [Proxy: {ipInfo.IsProxy}] [Type: {ipInfo.Type}] [Block: {block}] {remoteIpAddress}");
|
||||
ConsoleExt.WriteLine($"[{direction}] [Provider: {ipInfo.Provider}] [Risk: {ipInfo.Risk}] [Proxy: {ipInfo.IsProxy}] [Type: {ipInfo.Type}] [Block: {block}] {remoteIpAddress}", consoleColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Magenta;
|
||||
Console.WriteLine($"[{direction}] [Invalid] {remoteIpAddress}");
|
||||
ConsoleExt.WriteLine($"[{direction}] [Invalid] {remoteIpAddress}", ConsoleColor.Magenta);
|
||||
}
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
private static async Task CheckDns(Packet packet, IPAddress remoteIpAddress, string direction)
|
||||
@@ -231,49 +230,47 @@ public class Program
|
||||
|
||||
if (domainInfo is null)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Magenta;
|
||||
if (lastDomain != domain)
|
||||
{
|
||||
lastDomain = domain;
|
||||
Console.WriteLine($"[{direction}] [Dns] [Invalid] [Domain: {domain}] {remoteIpAddress}");
|
||||
ConsoleExt.WriteLine($"[{direction}] [Dns] [Invalid] [Domain: {domain}] {remoteIpAddress}", ConsoleColor.Magenta);
|
||||
}
|
||||
Console.ResetColor();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (domainInfo.IsMatch == false)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
if (lastDomain != domain)
|
||||
{
|
||||
lastDomain = domain;
|
||||
Console.WriteLine($"[{direction}] [Dns] [Domain: {domain}] [Type: Undetected] [Block: {block}] {remoteIpAddress}");
|
||||
ConsoleExt.WriteLine($"[{direction}] [Dns] [Domain: {domain}] [Type: Undetected] [Block: {block}] {remoteIpAddress}", ConsoleColor.Green);
|
||||
}
|
||||
Console.ResetColor();
|
||||
continue;
|
||||
}
|
||||
|
||||
ConsoleColor consoleColor;
|
||||
|
||||
if (domainInfo.TrustRating >= 0.9)
|
||||
{
|
||||
FirewallHelper.BlockIp(domainInfo.IpAddress);
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
consoleColor = ConsoleColor.Red;
|
||||
block = true;
|
||||
}
|
||||
else if (domainInfo.TrustRating >= 0.5)
|
||||
{
|
||||
FirewallHelper.BlockIp(domainInfo.IpAddress);
|
||||
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
||||
consoleColor = ConsoleColor.DarkYellow;
|
||||
block = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
consoleColor = ConsoleColor.Green;
|
||||
}
|
||||
|
||||
if (lastDomain != domain)
|
||||
{
|
||||
lastDomain = domain;
|
||||
Console.WriteLine($"[{direction}] [Dns] [Domain: {domain}] [Type: {domainInfo.Type}] [Source: {domainInfo.Source}] [Source Trust: {domainInfo.TrustRating * 100d}] [Block: {block}] {remoteIpAddress}");
|
||||
ConsoleExt.WriteLine($"[{direction}] [Dns] [Domain: {domain}] [Type: {domainInfo.Type}] [Source: {domainInfo.Source}] [Source Trust: {domainInfo.TrustRating * 100d}] [Block: {block}] {remoteIpAddress}", consoleColor);
|
||||
}
|
||||
|
||||
Console.ResetColor();
|
||||
|
||||
Reference in New Issue
Block a user