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
@@ -0,0 +1,8 @@
|
||||
using System.Net;
|
||||
|
||||
namespace Flypaper.Core.Abstractions;
|
||||
|
||||
public interface IRepeatOffenderLookup
|
||||
{
|
||||
ValueTask<bool> HasTimedOutSinceAsync(IPAddress address, DateTime since, CancellationToken ct);
|
||||
}
|
||||
@@ -43,6 +43,7 @@ public static class FlypaperCoreExtensions
|
||||
services.TryAddSingleton<ITrapStrategySelector, ConfiguredStrategySelector>();
|
||||
services.TryAddSingleton<TrapRunner>();
|
||||
services.TryAddSingleton<IIpEnricher, NullIpEnricher>();
|
||||
services.TryAddSingleton<IRepeatOffenderLookup, NullRepeatOffenderLookup>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -10,5 +10,9 @@ public sealed class FlypaperOptions
|
||||
|
||||
public TimeSpan MaxHoldDuration { get; set; } = TimeSpan.FromHours(1);
|
||||
|
||||
public int RepeatWindowDays { get; set; } = 7;
|
||||
|
||||
public TimeSpan RepeatHoldDuration { get; set; } = TimeSpan.FromHours(24);
|
||||
|
||||
public bool IgnorePrivateNetworks { get; set; } = true;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Net;
|
||||
using Flypaper.Core.Abstractions;
|
||||
|
||||
namespace Flypaper.Core.Networking;
|
||||
|
||||
internal sealed class NullRepeatOffenderLookup : IRepeatOffenderLookup
|
||||
{
|
||||
public ValueTask<bool> HasTimedOutSinceAsync(IPAddress address, DateTime since, CancellationToken ct) => ValueTask.FromResult(false);
|
||||
}
|
||||
@@ -11,6 +11,7 @@ public sealed partial class TrapRunner(
|
||||
IConnectionGovernor governor,
|
||||
ITrapStrategySelector strategies,
|
||||
ITrapEventSink sink,
|
||||
IRepeatOffenderLookup repeatOffenders,
|
||||
IOptionsMonitor<FlypaperOptions> options,
|
||||
TimeProvider timeProvider,
|
||||
ILogger<TrapRunner> logger)
|
||||
@@ -37,6 +38,14 @@ public sealed partial class TrapRunner(
|
||||
holdDuration = extension.MinimumHold;
|
||||
}
|
||||
|
||||
if (options.CurrentValue is { RepeatWindowDays: > 0 } current
|
||||
&& current.RepeatHoldDuration > holdDuration
|
||||
&& await repeatOffenders.HasTimedOutSinceAsync(session.RemoteIp, timeProvider.GetUtcNow().UtcDateTime.AddDays(-current.RepeatWindowDays), ct))
|
||||
{
|
||||
holdDuration = current.RepeatHoldDuration;
|
||||
description += " repeat";
|
||||
}
|
||||
|
||||
using var hold = new CancellationTokenSource(holdDuration, timeProvider);
|
||||
using var linked = CancellationTokenSource.CreateLinkedTokenSource(ct, hold.Token);
|
||||
|
||||
|
||||
@@ -13,7 +13,9 @@ public sealed record HoldMethodSettings(
|
||||
bool MatchPath,
|
||||
int LinkSpacing,
|
||||
string BaitPaths,
|
||||
TimeSpan MaxHoldDuration)
|
||||
TimeSpan MaxHoldDuration,
|
||||
int RepeatWindowDays,
|
||||
TimeSpan RepeatHoldDuration)
|
||||
{
|
||||
public double BytesPerSecond => AverageBytesPerSecond(MinDelay, MaxDelay, MinChunkSize, MaxChunkSize);
|
||||
|
||||
@@ -28,7 +30,9 @@ public sealed record HoldMethodSettings(
|
||||
[SettingKeys.DripMatchPath] = MatchPath ? "true" : "false",
|
||||
[SettingKeys.DripLinkSpacing] = LinkSpacing.ToString(CultureInfo.InvariantCulture),
|
||||
[SettingKeys.DripBaitPaths] = BaitPaths,
|
||||
[SettingKeys.MaxHoldDuration] = MaxHoldDuration.ToString("c", CultureInfo.InvariantCulture)
|
||||
[SettingKeys.MaxHoldDuration] = MaxHoldDuration.ToString("c", CultureInfo.InvariantCulture),
|
||||
[SettingKeys.RepeatWindowDays] = RepeatWindowDays.ToString(CultureInfo.InvariantCulture),
|
||||
[SettingKeys.RepeatHoldDuration] = RepeatHoldDuration.ToString("c", CultureInfo.InvariantCulture)
|
||||
};
|
||||
|
||||
public static double AverageBytesPerSecond(TimeSpan minDelay, TimeSpan maxDelay, int minChunkSize, int maxChunkSize)
|
||||
@@ -48,6 +52,8 @@ public sealed record HoldMethodInput(
|
||||
bool MatchPath,
|
||||
string? LinkSpacing,
|
||||
string? BaitPaths,
|
||||
string? MaxHoldDuration);
|
||||
string? MaxHoldDuration,
|
||||
string? RepeatWindowDays,
|
||||
string? RepeatHoldDuration);
|
||||
|
||||
public sealed record HoldMethodParseResult(HoldMethodSettings? Settings, IReadOnlyDictionary<string, string> Errors);
|
||||
@@ -15,6 +15,7 @@ public static class RuntimeSettingsParser
|
||||
private const int MaxChunkSize = 4096;
|
||||
private const int MaxHeadStartSize = 65_536;
|
||||
private const int MaxLinkSpacing = 4096;
|
||||
private const int MaxRepeatWindowDays = 365;
|
||||
|
||||
public static RuntimeSettingsParseResult Parse(RuntimeSettingsInput input)
|
||||
{
|
||||
@@ -63,6 +64,8 @@ public static class RuntimeSettingsParser
|
||||
var linkSpacing = ParseInt(input.LinkSpacing, nameof(input.LinkSpacing), 0, MaxLinkSpacing, errors);
|
||||
var baits = ParseBaitPaths(input.BaitPaths, nameof(input.BaitPaths), errors);
|
||||
var hold = ParseTimeSpan(input.MaxHoldDuration, nameof(input.MaxHoldDuration), MinHold, MaxHold, errors);
|
||||
var repeatWindow = ParseInt(input.RepeatWindowDays, nameof(input.RepeatWindowDays), 0, MaxRepeatWindowDays, errors);
|
||||
var repeatHold = ParseTimeSpan(input.RepeatHoldDuration, nameof(input.RepeatHoldDuration), MinHold, MaxHold, errors);
|
||||
|
||||
if (minDelay > maxDelay)
|
||||
{
|
||||
@@ -90,7 +93,9 @@ public static class RuntimeSettingsParser
|
||||
input.MatchPath,
|
||||
linkSpacing!.Value,
|
||||
baits!,
|
||||
hold!.Value),
|
||||
hold!.Value,
|
||||
repeatWindow!.Value,
|
||||
repeatHold!.Value),
|
||||
errors);
|
||||
}
|
||||
|
||||
@@ -130,7 +135,7 @@ public static class RuntimeSettingsParser
|
||||
|
||||
if (!text.Contains(':') || !TimeSpan.TryParse(text, CultureInfo.InvariantCulture, out var value))
|
||||
{
|
||||
errors[field] = "Format hh:mm:ss, zum Beispiel 00:00:10.";
|
||||
errors[field] = "Format hh:mm:ss (ab einem Tag d.hh:mm:ss), zum Beispiel 00:00:10.";
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ public static class SettingKeys
|
||||
public const string MaxConnections = "Flypaper:MaxConnections";
|
||||
public const string MaxConnectionsPerIp = "Flypaper:MaxConnectionsPerIp";
|
||||
public const string MaxHoldDuration = "Flypaper:MaxHoldDuration";
|
||||
public const string RepeatWindowDays = "Flypaper:RepeatWindowDays";
|
||||
public const string RepeatHoldDuration = "Flypaper:RepeatHoldDuration";
|
||||
public const string IgnorePrivateNetworks = "Flypaper:IgnorePrivateNetworks";
|
||||
public const string RetentionDays = "Flypaper:Retention:Days";
|
||||
public const string DripContent = "Flypaper:Drip:Content";
|
||||
@@ -21,7 +23,7 @@ public static class SettingKeys
|
||||
[MaxConnections, MaxConnectionsPerIp, IgnorePrivateNetworks, RetentionDays];
|
||||
|
||||
public static readonly IReadOnlyList<string> HoldMethod =
|
||||
[DripContent, DripMinDelay, DripMaxDelay, DripMinChunkSize, DripMaxChunkSize, DripHeadStartSize, DripMatchPath, DripLinkSpacing, DripBaitPaths, MaxHoldDuration];
|
||||
[DripContent, DripMinDelay, DripMaxDelay, DripMinChunkSize, DripMaxChunkSize, DripHeadStartSize, DripMatchPath, DripLinkSpacing, DripBaitPaths, MaxHoldDuration, RepeatWindowDays, RepeatHoldDuration];
|
||||
|
||||
public static readonly IReadOnlySet<string> All =
|
||||
new HashSet<string>(General.Concat(HoldMethod), StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
@@ -13,7 +13,9 @@ public static class FileContent
|
||||
{
|
||||
public static readonly IReadOnlyList<FileProfile> Profiles =
|
||||
[
|
||||
new("git-drip", "text/plain; charset=utf-8", path => path.Contains("/.git/", StringComparison.Ordinal), GitConfig),
|
||||
new("git-drip", "text/plain; charset=utf-8", IsGit, GitConfig),
|
||||
new("svn-drip", "text/plain; charset=utf-8", path => IsInside(path, "/.svn"), Svn),
|
||||
new("hg-drip", "text/plain; charset=utf-8", path => IsInside(path, "/.hg"), Mercurial),
|
||||
new("wordpress-drip", "text/html; charset=UTF-8", path => LastSegment(path) == "wp-login.php", WordPressLogin),
|
||||
new("hikvision-drip", "application/xml", path => path.StartsWith("/sdk/", StringComparison.Ordinal) || path.StartsWith("/isapi/", StringComparison.Ordinal), Hikvision),
|
||||
new("env-drip", "text/plain; charset=utf-8", path => IsEnv(LastSegment(path)), Env),
|
||||
@@ -34,6 +36,11 @@ public static class FileContent
|
||||
return Profiles.FirstOrDefault(profile => profile.Matches(normalized));
|
||||
}
|
||||
|
||||
private static bool IsInside(string path, string directory) =>
|
||||
path.Contains(directory + "/", StringComparison.Ordinal) || path.EndsWith(directory, StringComparison.Ordinal);
|
||||
|
||||
private static bool IsGit(string path) => IsInside(path, "/.git") || LastSegment(path).StartsWith(".git", StringComparison.Ordinal);
|
||||
|
||||
private static string LastSegment(string path) => path[(path.LastIndexOf('/') + 1)..];
|
||||
|
||||
private static bool IsEnv(string name) =>
|
||||
@@ -167,6 +174,27 @@ public static class FileContent
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<string> Svn(IRandomSource random)
|
||||
{
|
||||
yield return "12\n\ndir\n4821\nhttps://svn.example.com/repos/portal/trunk\nhttps://svn.example.com/repos/portal\n2026-03-14T09:21:07.512340Z\n4821\ndeploy\n\n\n\n\n\n\n\n";
|
||||
|
||||
while (true)
|
||||
{
|
||||
var date = string.Create(CultureInfo.InvariantCulture, $"2026-{random.Next(1, 13):00}-{random.Next(1, 29):00}T{random.Next(0, 24):00}:{random.Next(0, 60):00}:{random.Next(0, 60):00}.{random.Next(0, 1_000_000):000000}Z");
|
||||
yield return $"{LoremText.Word(random)}-{LoremText.Word(random)}.php\nfile\n\n\n{date}\n{Hex(random, 32)}\n{date}\ndeploy\n{random.Next(200, 90_000)}\n\n\n\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<string> Mercurial(IRandomSource random)
|
||||
{
|
||||
yield return "dotencode\nfncache\ngeneraldelta\nrevlogv1\nsparserevlog\nstore\n";
|
||||
|
||||
while (true)
|
||||
{
|
||||
yield return $"data/{Pick(random, MazeContent.Roots)}/{LoremText.Word(random)}-{LoremText.Word(random)}.php.i\n";
|
||||
}
|
||||
}
|
||||
|
||||
private static string Hex(IRandomSource random, int length)
|
||||
{
|
||||
var chars = new char[length];
|
||||
|
||||
Reference in new issue
Block a user