mirror of
https://github.com/Stone-Red-Code/FraudCapturer.git
synced 2026-09-04 00:56:05 +02:00
Code cleanup
This commit is contained in:
@@ -22,7 +22,7 @@ internal class BlockConfig
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckIfBlockSet(IpInfo ipInfo, BlockConfigSet blockConfigSet)
|
||||
public static bool CheckIfBlockSet(IpInfo ipInfo, BlockConfigSet blockConfigSet)
|
||||
{
|
||||
if (ipInfo.Type == "VPN" && blockConfigSet.BlockIfVpn)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
namespace FraudCapturer.Configuration;
|
||||
|
||||
internal class Configurator
|
||||
internal static class Configurator
|
||||
{
|
||||
public BlockConfig GetConfig()
|
||||
public static BlockConfig GetConfig()
|
||||
{
|
||||
BlockConfig blockConfig = new BlockConfig();
|
||||
|
||||
@@ -24,7 +24,7 @@ internal class Configurator
|
||||
return blockConfig;
|
||||
}
|
||||
|
||||
private BlockConfigSet GetBlockConfigSetFromConsole(bool ifNotProxyDefault, bool ifproxyDefault, bool ifVpnDeault)
|
||||
private static BlockConfigSet GetBlockConfigSetFromConsole(bool ifNotProxyDefault, bool ifproxyDefault, bool ifVpnDeault)
|
||||
{
|
||||
BlockConfigSet blockConfigSet = new BlockConfigSet();
|
||||
Console.WriteLine($"Block if no Proxy detected {GetDefaultHintString(ifNotProxyDefault)}:");
|
||||
@@ -39,7 +39,7 @@ internal class Configurator
|
||||
return blockConfigSet;
|
||||
}
|
||||
|
||||
private bool GetBoolValueFromConsole(bool defaultValue)
|
||||
private static bool GetBoolValueFromConsole(bool defaultValue)
|
||||
{
|
||||
string input = Console.ReadLine() ?? string.Empty;
|
||||
|
||||
@@ -48,7 +48,7 @@ internal class Configurator
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
while (input.ToLower() != "y" && input.ToLower() != "n")
|
||||
while (input.ToLower() is not "y" and not "n")
|
||||
{
|
||||
input = Console.ReadLine() ?? string.Empty;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ internal class Configurator
|
||||
return input.ToLower() == "y";
|
||||
}
|
||||
|
||||
private string GetDefaultHintString(bool defaultValue)
|
||||
private static string GetDefaultHintString(bool defaultValue)
|
||||
{
|
||||
return defaultValue ? "[Y/n]" : "[y/N]";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// This file is used by Code Analysis to maintain SuppressMessage
|
||||
// attributes that are applied to this project.
|
||||
// Project-level suppressions either have no target or are given
|
||||
// a specific target and scoped to a namespace, type, member, etc.
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
[assembly: SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "<Pending>", Scope = "member", Target = "~F:FraudCapturer.Program.AppUrl")]
|
||||
@@ -15,12 +15,8 @@ internal class DomainHelper
|
||||
{
|
||||
public static string[] GetDomainsFromDnsReqest(TransportPacket transportPacket)
|
||||
{
|
||||
List<string> domains = new();
|
||||
MatchCollection matchCollection = Regex.Matches(transportPacket.GetPayloadAsString().ToLower(), @"(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]");
|
||||
foreach (Match match in matchCollection)
|
||||
{
|
||||
domains.Add(match.Value);
|
||||
}
|
||||
List<string> domains = matchCollection.Select(match => match.Value).ToList();
|
||||
return domains.Distinct().ToArray();
|
||||
}
|
||||
|
||||
@@ -79,13 +75,13 @@ internal class DomainHelper
|
||||
}
|
||||
}
|
||||
|
||||
private class AntiFishReqestBody
|
||||
private sealed class AntiFishReqestBody
|
||||
{
|
||||
[JsonPropertyName("message")]
|
||||
public string? Message { get; set; }
|
||||
}
|
||||
|
||||
private class AntiFishResult
|
||||
private sealed class AntiFishResult
|
||||
{
|
||||
[JsonPropertyName("followed")]
|
||||
public bool Followed { get; set; }
|
||||
@@ -103,7 +99,7 @@ internal class DomainHelper
|
||||
public double TrustRating { get; set; }
|
||||
}
|
||||
|
||||
private class AntiFishResultBody
|
||||
private sealed class AntiFishResultBody
|
||||
{
|
||||
[JsonPropertyName("match")]
|
||||
public bool Match { get; set; }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace FraudCapturer.Helpers;
|
||||
|
||||
internal class FirewallHelper
|
||||
internal static class FirewallHelper
|
||||
{
|
||||
public static void BlockIp(IPAddress? ipAddress)
|
||||
{
|
||||
@@ -41,7 +41,7 @@ internal class FirewallHelper
|
||||
lock (Program.IpStorePath)
|
||||
{
|
||||
List<string> iPs = File.ReadAllLines(Program.IpStorePath).ToList();
|
||||
iPs.Remove(ipAddress.ToString());
|
||||
_ = iPs.Remove(ipAddress.ToString());
|
||||
|
||||
File.WriteAllLines(Program.IpStorePath, iPs);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Text.Json;
|
||||
|
||||
namespace FraudCapturer.Helpers;
|
||||
|
||||
internal class IpHelper
|
||||
internal static class IpHelper
|
||||
{
|
||||
public static string? ProxycheckApiKey { get; set; }
|
||||
|
||||
@@ -101,7 +101,7 @@ internal class IpHelper
|
||||
return ip[0] switch
|
||||
{
|
||||
10 or 127 => true,
|
||||
172 => ip[1] >= 16 && ip[1] < 32,
|
||||
172 => ip[1] is >= 16 and < 32,
|
||||
192 => ip[1] == 168,
|
||||
_ => false,
|
||||
};
|
||||
@@ -124,16 +124,14 @@ internal class IpHelper
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (IPAddress localIP in localIPs)
|
||||
return localIPs.Any(i => i.Equals(hostIP));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (hostIP.Equals(localIP))
|
||||
{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -9,24 +9,24 @@ internal static class PackageHelper
|
||||
public static string GetPayloadAsString(this TransportPacket transportPacket)
|
||||
{
|
||||
byte[] data = transportPacket.PayloadData;
|
||||
string bytes = "";
|
||||
string ascii = "";
|
||||
StringBuilder bytes = new StringBuilder();
|
||||
StringBuilder ascii = new StringBuilder();
|
||||
|
||||
for (int i = 1; i <= data.Length; i++)
|
||||
{
|
||||
// add the current byte to the bytes hex string
|
||||
bytes += data[i - 1].ToString("x").PadLeft(2, '0') + " ";
|
||||
_ = bytes.Append(data[i - 1].ToString("x").PadLeft(2, '0') + " ");
|
||||
|
||||
// add the current byte to the asciiBytes array for later processing
|
||||
if (data[i - 1] < 0x21 || data[i - 1] > 0x7e)
|
||||
if (data[i - 1] is < 0x21 or > 0x7e)
|
||||
{
|
||||
ascii += ".";
|
||||
_ = ascii.Append('.');
|
||||
}
|
||||
else
|
||||
{
|
||||
ascii += Encoding.ASCII.GetString(new[] { data[i - 1] });
|
||||
_ = ascii.Append(Encoding.ASCII.GetString(new[] { data[i - 1] }));
|
||||
}
|
||||
}
|
||||
return ascii.Trim('.');
|
||||
return ascii.ToString().Trim('.');
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ using System.Text.Json;
|
||||
|
||||
namespace FraudCapturer;
|
||||
|
||||
public class Program
|
||||
public static class Program
|
||||
{
|
||||
public const string AppName = "FraudCapturer";
|
||||
public const string AppUrl = "https://github.com/Stone-Red-Code/FraudCapturer";
|
||||
@@ -43,7 +43,7 @@ public class Program
|
||||
|
||||
if (args.FirstOrDefault() == "config")
|
||||
{
|
||||
blockConfig = new Configurator().GetConfig();
|
||||
blockConfig = Configurator.GetConfig();
|
||||
string jsonConfig = JsonSerializer.Serialize(blockConfig);
|
||||
File.WriteAllText(ConfigStorePath, jsonConfig);
|
||||
|
||||
@@ -119,10 +119,10 @@ public class Program
|
||||
private static void Device_OnPacketArrival(object sender, PacketCapture e)
|
||||
{
|
||||
RawCapture rawPacket = e.GetPacket();
|
||||
ProcessRawPacket(rawPacket);
|
||||
_ = ProcessRawPacket(rawPacket);
|
||||
}
|
||||
|
||||
private static async void ProcessRawPacket(RawCapture rawPacket)
|
||||
private static async Task ProcessRawPacket(RawCapture rawPacket)
|
||||
{
|
||||
Packet packet = Packet.ParsePacket(rawPacket.LinkLayerType, rawPacket.Data);
|
||||
if (packet is EthernetPacket)
|
||||
@@ -191,19 +191,19 @@ public class Program
|
||||
bool block = false;
|
||||
ConsoleColor consoleColor;
|
||||
|
||||
if (ipInfo.Risk >= 67 && blockConfig.CheckIfBlockSet(ipInfo, blockConfig.HighRiskSet))
|
||||
if (ipInfo.Risk >= 67 && BlockConfig.CheckIfBlockSet(ipInfo, blockConfig.HighRiskSet))
|
||||
{
|
||||
FirewallHelper.BlockIp(remoteIpAddress);
|
||||
consoleColor = ConsoleColor.Red;
|
||||
block = true;
|
||||
}
|
||||
else if (ipInfo.Risk <= 33 && blockConfig.CheckIfBlockSet(ipInfo, blockConfig.LowRiskSet))
|
||||
else if (ipInfo.Risk <= 33 && BlockConfig.CheckIfBlockSet(ipInfo, blockConfig.LowRiskSet))
|
||||
{
|
||||
FirewallHelper.BlockIp(remoteIpAddress);
|
||||
consoleColor = ConsoleColor.Yellow;
|
||||
block = true;
|
||||
}
|
||||
else if (blockConfig.CheckIfBlockSet(ipInfo, blockConfig.MeduimRiskSet))
|
||||
else if (BlockConfig.CheckIfBlockSet(ipInfo, blockConfig.MeduimRiskSet))
|
||||
{
|
||||
FirewallHelper.BlockIp(remoteIpAddress);
|
||||
consoleColor = ConsoleColor.DarkYellow;
|
||||
@@ -255,7 +255,7 @@ public class Program
|
||||
continue;
|
||||
}
|
||||
|
||||
if (domainInfo.IsMatch == false)
|
||||
if (!domainInfo.IsMatch)
|
||||
{
|
||||
if (lastDomain != domain)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user