Add research page with MCP write tools, longer hold for repeat offenders and svn/hg decoys
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a25072e6fb
commit
e88dc415f9
48 files changed
+1983
-57
No files matched your search
@@ -18,6 +18,19 @@ public sealed class FileContentTests
|
||||
[InlineData("/docker-compose.yml", "yaml-drip")]
|
||||
[InlineData("/backup/db.sql", "sql-drip")]
|
||||
[InlineData("/.git/config", "git-drip")]
|
||||
[InlineData("/.git/HEAD", "git-drip")]
|
||||
[InlineData("/app/.git/logs/HEAD", "git-drip")]
|
||||
[InlineData("/.git", "git-drip")]
|
||||
[InlineData("/.gitconfig", "git-drip")]
|
||||
[InlineData("/.git-credentials", "git-drip")]
|
||||
[InlineData("/home/.GITCONFIG", "git-drip")]
|
||||
[InlineData("/.svn/format", "svn-drip")]
|
||||
[InlineData("/.svn/wc.db", "svn-drip")]
|
||||
[InlineData("/.svn/entries", "svn-drip")]
|
||||
[InlineData("/site/.svn", "svn-drip")]
|
||||
[InlineData("/.hg/requires", "hg-drip")]
|
||||
[InlineData("/.hg/store/requires", "hg-drip")]
|
||||
[InlineData("/.hg", "hg-drip")]
|
||||
[InlineData("/SDK/webLanguage", "hikvision-drip")]
|
||||
[InlineData("/ISAPI/System/deviceInfo", "hikvision-drip")]
|
||||
[InlineData("/wp-login.php", "wordpress-drip")]
|
||||
@@ -29,6 +42,9 @@ public sealed class FileContentTests
|
||||
[InlineData("/")]
|
||||
[InlineData("/index.php")]
|
||||
[InlineData("/sdkfoo")]
|
||||
[InlineData("/.svnfoo")]
|
||||
[InlineData("/.hgrc-not")]
|
||||
[InlineData("/legit.git/x")]
|
||||
[InlineData("/environment")]
|
||||
[InlineData("")]
|
||||
[InlineData(null)]
|
||||
@@ -41,6 +57,11 @@ public sealed class FileContentTests
|
||||
[InlineData("/docker-compose.yml", "version:")]
|
||||
[InlineData("/dump.sql", "-- MySQL dump")]
|
||||
[InlineData("/.git/config", "[core]")]
|
||||
[InlineData("/.git-credentials", "[core]")]
|
||||
[InlineData("/.svn/entries", "12\n")]
|
||||
[InlineData("/.svn/wc.db", "12\n")]
|
||||
[InlineData("/.hg/requires", "dotencode\n")]
|
||||
[InlineData("/.hg/store/requires", "dotencode\n")]
|
||||
[InlineData("/SDK/webLanguage", "<?xml")]
|
||||
[InlineData("/wp-login.php", "<!DOCTYPE html>")]
|
||||
public void Generates_an_endless_file_that_starts_like_the_real_thing(string path, string start)
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Flypaper.Tests.Core;
|
||||
|
||||
public sealed class HoldMethodParserTests
|
||||
{
|
||||
private static readonly HoldMethodInput Valid = new("Alternating", "50", "1000", "1", "64", "2048", true, "80", "/Backup-2024, /admin-old/x", "01:00:00");
|
||||
private static readonly HoldMethodInput Valid = new("Alternating", "50", "1000", "1", "64", "2048", true, "80", "/Backup-2024, /admin-old/x", "01:00:00", "7", "1.00:00:00");
|
||||
|
||||
[Fact]
|
||||
public void Parses_valid_input()
|
||||
@@ -108,6 +108,37 @@ public sealed class HoldMethodParserTests
|
||||
public void Rejects_invalid_hold_durations(string value) =>
|
||||
RuntimeSettingsParser.ParseHoldMethod(Valid with { MaxHoldDuration = value }).Errors.Keys.ShouldBe([nameof(HoldMethodInput.MaxHoldDuration)]);
|
||||
|
||||
[Theory]
|
||||
[InlineData("0")]
|
||||
[InlineData("365")]
|
||||
public void Accepts_repeat_window(string value) =>
|
||||
RuntimeSettingsParser.ParseHoldMethod(Valid with { RepeatWindowDays = value }).Settings.ShouldNotBeNull().RepeatWindowDays.ShouldBe(int.Parse(value));
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData("-1")]
|
||||
[InlineData("366")]
|
||||
[InlineData("abc")]
|
||||
public void Rejects_invalid_repeat_window(string value) =>
|
||||
RuntimeSettingsParser.ParseHoldMethod(Valid with { RepeatWindowDays = value }).Errors.Keys.ShouldBe([nameof(HoldMethodInput.RepeatWindowDays)]);
|
||||
|
||||
[Theory]
|
||||
[InlineData("10")]
|
||||
[InlineData("00:00:00")]
|
||||
[InlineData("24:00:00")]
|
||||
[InlineData("8.00:00:00")]
|
||||
public void Rejects_invalid_repeat_hold_durations(string value) =>
|
||||
RuntimeSettingsParser.ParseHoldMethod(Valid with { RepeatHoldDuration = value }).Errors.Keys.ShouldBe([nameof(HoldMethodInput.RepeatHoldDuration)]);
|
||||
|
||||
[Fact]
|
||||
public void Parses_repeat_settings()
|
||||
{
|
||||
var settings = RuntimeSettingsParser.ParseHoldMethod(Valid).Settings.ShouldNotBeNull();
|
||||
|
||||
settings.RepeatWindowDays.ShouldBe(7);
|
||||
settings.RepeatHoldDuration.ShouldBe(TimeSpan.FromHours(24));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Computes_average_bandwidth()
|
||||
{
|
||||
|
||||
@@ -99,6 +99,58 @@ public sealed class TrapRunnerTests
|
||||
_sink.Received(1).Publish(Arg.Is<TrapEvent>(e => e.RemoteIp.Equals(IPAddress.Parse("192.168.1.20"))));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Holds_ips_with_an_earlier_timeout_longer_and_marks_the_strategy()
|
||||
{
|
||||
AllowAcquire();
|
||||
var lookup = Substitute.For<IRepeatOffenderLookup>();
|
||||
lookup.HasTimedOutSinceAsync(Arg.Any<IPAddress>(), Arg.Any<DateTime>(), Arg.Any<CancellationToken>()).Returns(true);
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(500));
|
||||
|
||||
var outcome = await CreateRunner(TimeSpan.FromMilliseconds(100), repeatOffenders: lookup, repeatWindowDays: 7, repeatHoldDuration: TimeSpan.FromMinutes(1))
|
||||
.RunAsync(Context(), Open, cts.Token);
|
||||
|
||||
outcome.ShouldBe(TrapOutcome.ClientAborted);
|
||||
await lookup.Received(1).HasTimedOutSinceAsync(
|
||||
IPAddress.Parse("203.0.113.9"),
|
||||
Arg.Is<DateTime>(since => Math.Abs((DateTime.UtcNow.AddDays(-7) - since).TotalSeconds) < 30),
|
||||
Arg.Any<CancellationToken>());
|
||||
_sink.Received(1).Publish(Arg.Is<TrapEvent>(e => e.Strategy.EndsWith(" repeat")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Keeps_the_normal_limit_for_new_ips()
|
||||
{
|
||||
AllowAcquire();
|
||||
var lookup = Substitute.For<IRepeatOffenderLookup>();
|
||||
lookup.HasTimedOutSinceAsync(Arg.Any<IPAddress>(), Arg.Any<DateTime>(), Arg.Any<CancellationToken>()).Returns(false);
|
||||
|
||||
var outcome = await CreateRunner(TimeSpan.FromMilliseconds(100), repeatOffenders: lookup, repeatWindowDays: 7)
|
||||
.RunAsync(Context(), Open, CancellationToken.None);
|
||||
|
||||
outcome.ShouldBe(TrapOutcome.Timeout);
|
||||
_sink.Received(1).Publish(Arg.Is<TrapEvent>(e => !e.Strategy.EndsWith(" repeat")));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, "00:00:00.100")]
|
||||
[InlineData(7, "00:00:00.050")]
|
||||
public async Task Does_not_ask_when_the_feature_is_off_or_would_not_extend_the_hold(int windowDays, string repeatHold)
|
||||
{
|
||||
AllowAcquire();
|
||||
var lookup = Substitute.For<IRepeatOffenderLookup>();
|
||||
|
||||
await CreateRunner(TimeSpan.FromMilliseconds(100), repeatOffenders: lookup, repeatWindowDays: windowDays, repeatHoldDuration: TimeSpan.Parse(repeatHold))
|
||||
.RunAsync(Context(), Open, CancellationToken.None);
|
||||
|
||||
await lookup.DidNotReceiveWithAnyArgs().HasTimedOutSinceAsync(default!, default, default);
|
||||
}
|
||||
|
||||
private sealed class NullRepeatLookup : IRepeatOffenderLookup
|
||||
{
|
||||
public ValueTask<bool> HasTimedOutSinceAsync(IPAddress address, DateTime since, CancellationToken ct) => ValueTask.FromResult(false);
|
||||
}
|
||||
|
||||
private IDisposable AllowAcquire()
|
||||
{
|
||||
var lease = Substitute.For<IDisposable>();
|
||||
@@ -113,7 +165,12 @@ public sealed class TrapRunnerTests
|
||||
|
||||
private ValueTask<ITrapChannel> Open(ITarpitStrategy strategy, CancellationToken ct) => ValueTask.FromResult<ITrapChannel>(_channel);
|
||||
|
||||
private TrapRunner CreateRunner(TimeSpan maxHoldDuration, bool ignorePrivateNetworks = true)
|
||||
private TrapRunner CreateRunner(
|
||||
TimeSpan maxHoldDuration,
|
||||
bool ignorePrivateNetworks = true,
|
||||
IRepeatOffenderLookup? repeatOffenders = null,
|
||||
int repeatWindowDays = 0,
|
||||
TimeSpan? repeatHoldDuration = null)
|
||||
{
|
||||
var dripOptions = TestOptions.Monitor(new DripOptions { MinDelay = TimeSpan.FromMilliseconds(5), MaxDelay = TimeSpan.FromMilliseconds(20) });
|
||||
var random = new SeededRandomSource(7);
|
||||
@@ -122,7 +179,14 @@ public sealed class TrapRunnerTests
|
||||
_governor,
|
||||
new ConfiguredStrategySelector([drip], dripOptions, random),
|
||||
_sink,
|
||||
TestOptions.Monitor(new FlypaperOptions { MaxHoldDuration = maxHoldDuration, IgnorePrivateNetworks = ignorePrivateNetworks }),
|
||||
repeatOffenders ?? new NullRepeatLookup(),
|
||||
TestOptions.Monitor(new FlypaperOptions
|
||||
{
|
||||
MaxHoldDuration = maxHoldDuration,
|
||||
IgnorePrivateNetworks = ignorePrivateNetworks,
|
||||
RepeatWindowDays = repeatWindowDays,
|
||||
RepeatHoldDuration = repeatHoldDuration ?? TimeSpan.FromHours(24)
|
||||
}),
|
||||
TimeProvider.System,
|
||||
NullLogger<TrapRunner>.Instance);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user