Skip to content

Commit b06f05a

Browse files
authored
version 2.1.2 (Release: June 2021) (#43)
* turning up version numbers * fixing a small issue in the license * classify messages about found ips as verbose #44 * a small readability thing * added_start_menu #42 * some beauty fixes for the console (icon..) (#51) * removed dead code * set icon for the app * ability to remove temp bans (#47) * service gets ability to remove temp bans * forgetting IPS needs to ignore re-supplied events * console feature to remove temporary bans * tested and tweaked the server feature to remove temp ban #45 * fixed a bug with forgetting ips fixed a bug where a task will not forget an ip it has already forgotten earlier * replaced "middle finger" with safe for work image (#62) * releasing 2.1.2
1 parent b43e80b commit b06f05a

20 files changed

Lines changed: 193 additions & 98 deletions

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Michael Schönbauer
3+
Copyright (c) 2019 Michael Schoenbauer
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

NEWS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
## NEWS
22

3+
### 2021-06-03 release of v.2. was completed
4+
- a small typo in the license was fixed
5+
- severity of some messages was adjusted (moved from info to verbose) to keep a cleaner event log
6+
- it contains minor bugfixes and corrections, but nothing interesting apart from that its signed now.
7+
- the console app now has a start menu entry
8+
- the console app had some beauty fixes
9+
- added ability to remove temp bans
10+
- fixes a bug with forgetting ips
11+
- replaces te old 'middle finger' with a more safe for work image
12+
313
### 2020-12-28 preparing the release of v2.1
414
- first, i want to say THANK YOU, to everyone who donated
515
- finally, we have received enough donations, so we can sign the next release. (and afford 3 beers on top of that)

Source/EvlWatcher/EvlWatcher.WCF/IEvlWatcherService.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,9 @@ public interface IEvlWatcherService
4242
[OperationContract]
4343
[FaultContract(typeof(ServiceFaultDTO))]
4444
void SaveGlobalConfig(SeverityLevelDTO logLevel, int consoleBackLog, int checkInterval);
45+
46+
[OperationContract]
47+
[FaultContract(typeof(ServiceFaultDTO))]
48+
void RemoveTemporaryBan(IPAddress address);
4549
}
4650
}

Source/EvlWatcher/EvlWatcher/EvlWatcher.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ private void Run()
394394
}
395395
}
396396

397-
398397
//start monitoring the logs
399398
while (true)
400399
{
@@ -469,7 +468,6 @@ private void Run()
469468

470469
_logger.Dump($"Scanning finished in {DateTime.Now.Subtract(scanStart).TotalMilliseconds}[ms] ", SeverityLevel.Debug);
471470

472-
473471
//then supply the events to the requesting tasks
474472
foreach (string key in requiredEventTypesToLogTasks.Keys)
475473
{
@@ -514,7 +512,6 @@ private void Run()
514512

515513
List<IPAddress> blockedIPs = ipTask.GetTempBanVictims();
516514

517-
518515
_logger.Dump($"Polled {t.Name} and got {blockedIPs.Count} temporary and {_serviceconfiguration.BlacklistAddresses.Count()} permanent ban(s)", SeverityLevel.Verbose);
519516

520517
foreach (IPAddress blockedIP in blockedIPs)
@@ -611,6 +608,22 @@ public void SaveGlobalConfig(SeverityLevelDTO logLevel, int consoleBackLog, int
611608
_serviceconfiguration.EventLogInterval = checkInterval;
612609
}
613610

611+
public void RemoveTemporaryBan(IPAddress address)
612+
{
613+
EnsureClientPrivileges();
614+
615+
lock (_syncObject)
616+
{
617+
_logger.Dump($"Removing IP {address} from temporary ban list", SeverityLevel.Info);
618+
foreach (var ipBlockingTask in _logTasks.Where(t => t is IPBlockingLogTask).Select(t => t as IPBlockingLogTask))
619+
{
620+
ipBlockingTask.Forget(address);
621+
}
622+
_lastPolledTempBans.Remove(address);
623+
PushBanList();
624+
}
625+
}
626+
614627
#endregion
615628
}
616629
}

Source/EvlWatcher/EvlWatcher/NSIS/make.nsi

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Name "EvlWatcher"
22

33
; The file to write
44
Icon EvlWatcher.ico
5-
OutFile "EvlWatcher-v2.0 setup.exe"
5+
OutFile "EvlWatcher-v2.1.2-setup.exe"
66

77
; The default installation directory
88
InstallDir $PROGRAMFILES\EvlWatcher
@@ -43,20 +43,12 @@ Section "EvlWatcher Service"
4343

4444
;;;;;;;;MODULES HERE;;;;;;;;;;
4545

46-
Delete $INSTDIR\BlockRDPBruters.dll
47-
Delete $INSTDIR\BlockFTPBruters.dll
48-
Delete $INSTDIR\BlockFTPBruters.cfg
49-
5046
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5147

52-
Delete $INSTDIR\Interop.NetFwTypeLib.dll
5348
Delete $INSTDIR\EvlWatcher.exe
54-
Delete $INSTDIR\gpl-3.0.txt
5549
Delete $INSTDIR\license.txt
56-
Delete $INSTDIR\source.zip
5750
Delete $INSTDIR\config.xml
5851
Delete $INSTDIR\EvlWatcherConsole.exe
59-
Delete $INSTDIR\EvlWatcher.ico
6052
Delete $INSTDIR\EvlWatcher.WCF.dll
6153

6254
; Set output path to the installation directory.
@@ -91,6 +83,13 @@ Section "EvlWatcher Service"
9183

9284
SectionEnd
9385

86+
Section "Start Menu Entry"
87+
88+
CreateDirectory "$SMPROGRAMS\EvlWatcher"
89+
CreateShortCut "$SMPROGRAMS\EvlWatcher\EvlWatcherConsole.lnk" "$INSTDIR\EvlWatcherConsole.exe"
90+
91+
SectionEnd
92+
9493
;;;;;;;MODULES HERE;;;;;;;;;;
9594

9695

@@ -108,6 +107,9 @@ Section "Uninstall"
108107

109108
Sleep 5000
110109

110+
Delete "$SMPROGRAMS\EvlWatcher\EvlWatcherConsole.lnk"
111+
rmDir "$SMPROGRAMS\EvlWatcher"
112+
111113
; Remove registry keys
112114
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EvlWatcher"
113115
DeleteRegKey HKLM SOFTWARE\EvlWatcher
@@ -116,36 +118,14 @@ Section "Uninstall"
116118

117119
;;;;;;;;MODULES HERE;;;;;;;;;;;
118120

119-
Delete $INSTDIR\BlockRDPBruters.dll
120-
Delete $INSTDIR\BlockFTPBruters.dll
121-
Delete $INSTDIR\BlockFTPBruters.cfg
122-
123121
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
124122

125-
Delete $INSTDIR\Interop.NetFwTypeLib.dll
126123
Delete $INSTDIR\EvlWatcher.exe
127-
Delete $INSTDIR\gpl-3.0.txt
128124
Delete $INSTDIR\license.txt
129125
Delete $INSTDIR\config.xml
130126
Delete $INSTDIR\EvlWatcherConsole.exe
131-
Delete $INSTDIR\source.zip
132-
Delete $INSTDIR\EvlWatcher.ico
133127
Delete $INSTDIR\EvlWatcher.WCF.dll
134-
135-
Delete $INSTDIR\Source\Constants.cs
136-
Delete $INSTDIR\Source\FirewallAPI.cs
137-
Delete $INSTDIR\Source\Installer.cs
138-
Delete $INSTDIR\Source\IPBlockingLogTask.cs
139-
Delete $INSTDIR\Source\EvlWatcher.cs
140-
Delete $INSTDIR\Source\LogTask.cs
141128

142-
;;;;;;;;;MODULES HERE;;;;;;;;;;;;;;;;
143-
144-
Delete $INSTDIR\Source\LogTaskBlockRDPBruters.cs
145-
Delete $INSTDIR\Source\LogTaskBlockFTPBruters.cs
146-
Delete $INSTDIR\Source\BlockFTPBruters.cfg
147-
148-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
149129

150130
Delete $INSTDIR\uninstall.exe
151131

Source/EvlWatcher/EvlWatcher/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
// Build Number
2929
// Revision
3030
//
31-
[assembly: AssemblyVersion("2.0.0.0")]
32-
[assembly: AssemblyFileVersion("2.0.0.0")]
31+
[assembly: AssemblyVersion("2.1.2.0")]
32+
[assembly: AssemblyFileVersion("2.1.2.0")]

Source/EvlWatcher/EvlWatcher/license.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Michael Schönbauer
3+
Copyright (c) 2020 Michael Schoenbauer
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Source/EvlWatcher/EvlWatcher/systemapi/FirewallAPI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private INetFwRule GetOrCreateEvlWatcherRule(bool create)
6464
rule.EdgeTraversal = false;
6565
rule.LocalAddresses = "*";
6666
rule.Name = "EvlWatcher";
67-
rule.Profiles = 2147483647; // = means all Profiles
67+
rule.Profiles = int.MaxValue;// = means all Profiles
6868
rule.Protocol = 256;
6969
policies.Rules.Add(rule);
7070
}

Source/EvlWatcher/EvlWatcher/tasks/GenericIPBlockingTask.cs

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ internal static GenericIPBlockingTask FromConfiguration(IPersistentTaskConfigura
3636

3737
#region private members
3838

39+
private readonly object _syncObject = new object();
3940
private readonly Dictionary<IPAddress, DateTime> _blockedIPsToDate = new Dictionary<IPAddress, DateTime>();
41+
private readonly Dictionary<IPAddress, DateTime> _forgetIPsToDate = new Dictionary<IPAddress, DateTime>();
4042
private readonly Dictionary<IPAddress, int> _bannedCount = new Dictionary<IPAddress, int>();
4143
private readonly ILogger _logger;
4244

@@ -64,40 +66,51 @@ internal GenericIPBlockingTask(ILogger logger)
6466
#region public operations
6567
public override List<IPAddress> GetTempBanVictims()
6668
{
67-
List<IPAddress> ipsToRemove = new List<IPAddress>();
68-
List<IPAddress> ipsToBlock = new List<IPAddress>();
69-
70-
//also remove IPS from ban list when they have been blocked "long enough"
71-
foreach (KeyValuePair<IPAddress, DateTime> kvp in _blockedIPsToDate)
69+
lock (_syncObject)
7270
{
73-
if (kvp.Value.Add(new TimeSpan(0, 0, LockTime)) < System.DateTime.Now)
74-
{
75-
ipsToRemove.Add(kvp.Key);
76-
}
77-
else
71+
List<IPAddress> ipsToRemove = new List<IPAddress>();
72+
List<IPAddress> ipsToBlock = new List<IPAddress>();
73+
74+
//also remove IPS from ban list when they have been blocked "long enough"
75+
foreach (KeyValuePair<IPAddress, DateTime> kvp in _blockedIPsToDate)
7876
{
79-
ipsToBlock.Add(kvp.Key);
77+
if (kvp.Value.Add(new TimeSpan(0, 0, LockTime)) < DateTime.Now)
78+
{
79+
ipsToRemove.Add(kvp.Key);
80+
}
81+
else
82+
{
83+
ipsToBlock.Add(kvp.Key);
84+
}
8085
}
81-
}
8286

83-
foreach (IPAddress ipToRemove in ipsToRemove)
84-
_blockedIPsToDate.Remove(ipToRemove);
87+
//also remove forgotten IPs when its been a while
88+
List<IPAddress> removeFromForgottenList = _forgetIPsToDate.Where(p => DateTime.Now.AddHours(-1) > p.Value).Select(p=>p.Key).ToList();
89+
foreach (var ip in removeFromForgottenList)
90+
removeFromForgottenList.Remove(ip);
91+
92+
foreach (IPAddress ipToRemove in ipsToRemove)
93+
_blockedIPsToDate.Remove(ipToRemove);
8594

86-
return ipsToBlock;
95+
return ipsToBlock;
96+
}
8797
}
8898

8999
public override List<IPAddress> GetPermaBanVictims()
90100
{
91-
List<IPAddress> permaList = new List<IPAddress>();
92-
foreach (KeyValuePair<IPAddress, int> kvp in _bannedCount.Where(p=>p.Value>=PermaBanCount))
101+
lock (_syncObject)
93102
{
94-
permaList.Add(kvp.Key);
95-
_logger.Dump($"Permanently banned {kvp.Value} (strike count was over {PermaBanCount}) ", SeverityLevel.Info);
96-
}
97-
foreach (IPAddress ip in permaList)
98-
_bannedCount.Remove(ip);
103+
List<IPAddress> permaList = new List<IPAddress>();
104+
foreach (KeyValuePair<IPAddress, int> kvp in _bannedCount.Where(p => p.Value >= PermaBanCount))
105+
{
106+
permaList.Add(kvp.Key);
107+
_logger.Dump($"Permanently banned {kvp.Value} (strike count was over {PermaBanCount}) ", SeverityLevel.Info);
108+
}
109+
foreach (IPAddress ip in permaList)
110+
_bannedCount.Remove(ip);
99111

100-
return permaList;
112+
return permaList;
113+
}
101114
}
102115

103116
protected override void OnComputeEvents(List<ExtractedEventRecord> events)
@@ -133,32 +146,55 @@ protected override void OnComputeEvents(List<ExtractedEventRecord> events)
133146
{
134147
if (m.Groups.Count == 2 && IPAddress.TryParse(m.Groups[1].Value, out IPAddress ipAddress))
135148
{
149+
if (_forgetIPsToDate.ContainsKey(ipAddress) && _forgetIPsToDate[ipAddress] > e.TimeCreated )
150+
{
151+
_logger.Dump($"{Name}: found {ipAddress} but ignored it (was recently removed from autoban list)", SeverityLevel.Info);
152+
continue;
153+
}
136154

137155
if (!sourceToCount.ContainsKey(ipAddress))
138156
sourceToCount.Add(ipAddress, 1);
139157
else
140158
sourceToCount[ipAddress]++;
141159

142-
_logger.Dump($"{Name}: found {ipAddress}, trigger count is {sourceToCount[ipAddress]}", SeverityLevel.Info);
160+
_logger.Dump($"{Name}: found {ipAddress}, trigger count is {sourceToCount[ipAddress]}", SeverityLevel.Verbose);
143161
}
144162
}
145163
}
146164

147-
foreach (KeyValuePair<IPAddress, int> kvp in sourceToCount)
165+
lock (_syncObject)
148166
{
149-
if (kvp.Value >= TriggerCount && !_blockedIPsToDate.ContainsKey(kvp.Key))
167+
foreach (KeyValuePair<IPAddress, int> kvp in sourceToCount)
150168
{
151-
_blockedIPsToDate.Add(kvp.Key, DateTime.Now);
152-
if (!_bannedCount.ContainsKey(kvp.Key))
153-
_bannedCount[kvp.Key] = 1;
154-
else
155-
_bannedCount[kvp.Key] += 1;
169+
if (kvp.Value >= TriggerCount && !_blockedIPsToDate.ContainsKey(kvp.Key))
170+
{
171+
_blockedIPsToDate.Add(kvp.Key, DateTime.Now);
172+
if (!_bannedCount.ContainsKey(kvp.Key))
173+
_bannedCount[kvp.Key] = 1;
174+
else
175+
_bannedCount[kvp.Key] += 1;
156176

157-
_logger.Dump($"Temporarily banning {kvp.Key}, this is strike {_bannedCount[kvp.Key]}", SeverityLevel.Info);
177+
_logger.Dump($"Temporarily banning {kvp.Key}, this is strike {_bannedCount[kvp.Key]}", SeverityLevel.Info);
178+
}
158179
}
159180
}
160181
}
161182

183+
public override void Forget(IPAddress address)
184+
{
185+
lock (_syncObject)
186+
{
187+
_blockedIPsToDate.Remove(address);
188+
189+
if (!_forgetIPsToDate.ContainsKey(address))
190+
_forgetIPsToDate.Add(address, DateTime.Now);
191+
else
192+
_forgetIPsToDate[address] = DateTime.Now;
193+
194+
_bannedCount.Remove(address);
195+
}
196+
}
197+
162198
#endregion
163199
}
164200
}

Source/EvlWatcher/EvlWatcher/tasks/IPBlockingLogTask.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ public abstract class IPBlockingLogTask : LogTask
1010
{
1111
public abstract List<IPAddress> GetTempBanVictims();
1212
public abstract List<IPAddress> GetPermaBanVictims();
13+
14+
public abstract void Forget(IPAddress address);
1315
}
1416
}

0 commit comments

Comments
 (0)