- Add Block config class

This commit is contained in:
Stone_Red
2022-01-11 23:30:54 +01:00
parent 48304bb030
commit e9147ff2b7
8 changed files with 81 additions and 12 deletions
@@ -0,0 +1,42 @@
namespace FraudCapturer.Configuration;
internal class BlockConfig
{
public BlockConfigSet LowRiskSet { get; set; } = new BlockConfigSet(false, true, false);
public BlockConfigSet MeduimRiskSet { get; set; } = new BlockConfigSet(false, true, true);
public BlockConfigSet HighRiskSet { get; set; } = new BlockConfigSet(true, true, true);
public bool CheckIfBlock(IpInfo ipInfo)
{
if (ipInfo.Risk <= 33)
{
return CheckIfBlockSet(ipInfo, LowRiskSet);
}
else if (ipInfo.Risk >= 67)
{
return CheckIfBlockSet(ipInfo, HighRiskSet);
}
else
{
return CheckIfBlockSet(ipInfo, MeduimRiskSet);
}
}
public bool CheckIfBlockSet(IpInfo ipInfo, BlockConfigSet blockConfigSet)
{
if (ipInfo.Type == "VPN" && blockConfigSet.BlockIfVpn)
{
return true;
}
else if (ipInfo.IsProxy && blockConfigSet.BlockIfProxy)
{
return true;
}
else if (!ipInfo.IsProxy && blockConfigSet.BlockIfNotProxy)
{
return true;
}
return false;
}
}
@@ -0,0 +1,15 @@
namespace FraudCapturer.Configuration;
internal class BlockConfigSet
{
public BlockConfigSet(bool blockIfNotProxy, bool blockIfProxy, bool blockIfVpn)
{
BlockIfNotProxy = blockIfNotProxy;
BlockIfProxy = blockIfProxy;
BlockIfVpn = blockIfVpn;
}
public bool BlockIfNotProxy { get; }
public bool BlockIfProxy { get; }
public bool BlockIfVpn { get; }
}
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FraudCapturer.Configuration;
internal class Configurator
{
}
@@ -9,7 +9,7 @@ using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
namespace FraudCapturer;
namespace FraudCapturer.Helpers;
internal class DomainHelper
{
@@ -1,6 +1,6 @@
using System.Net;
namespace FraudCapturer;
namespace FraudCapturer.Helpers;
internal class FirewallHelper
{
@@ -3,7 +3,7 @@
using System.Net;
using System.Text.Json;
namespace FraudCapturer;
namespace FraudCapturer.Helpers;
internal class IpHelper
{
@@ -2,7 +2,7 @@
using System.Text;
namespace FraudCapturer;
namespace FraudCapturer.Helpers;
internal static class PackageHelper
{
+9 -8
View File
@@ -1,4 +1,6 @@
using FraudCapturer.Configuration;
using FraudCapturer.Helpers;
using PacketDotNet;
using SharpPcap;
@@ -10,9 +12,6 @@ using System.Net;
namespace FraudCapturer;
/// <summary>
/// Example showing packet manipulation
/// </summary>
public class Program
{
public const string AppName = "FraudCapturer";
@@ -25,6 +24,8 @@ public class Program
private static readonly ConcurrentBag<string> capturedIpsCache = new();
private static readonly ConcurrentDictionary<string, DomainInfo?> capturedDomainsCache = new();
private static BlockConfig blockConfig = new BlockConfig();
/// <summary>
/// The main entry point for the application.
/// </summary>
@@ -174,19 +175,19 @@ public class Program
bool block = false;
ConsoleColor consoleColor;
if (ipInfo.Risk >= 67)
if (ipInfo.Risk >= 67 && blockConfig.CheckIfBlockSet(ipInfo, blockConfig.HighRiskSet))
{
FirewallHelper.BlockIp(remoteIpAddress);
consoleColor = ConsoleColor.Red;
block = true;
}
else if (ipInfo.Risk >= 34 && ipInfo.IsProxy)
else if (ipInfo.Risk <= 33 && blockConfig.CheckIfBlockSet(ipInfo, blockConfig.LowRiskSet))
{
FirewallHelper.BlockIp(remoteIpAddress);
consoleColor = ConsoleColor.DarkYellow;
consoleColor = ConsoleColor.Yellow;
block = true;
}
else if (ipInfo.IsProxy && ipInfo.Type != "VPN")
else if (blockConfig.CheckIfBlockSet(ipInfo, blockConfig.MeduimRiskSet))
{
FirewallHelper.BlockIp(remoteIpAddress);
consoleColor = ConsoleColor.DarkYellow;