Show the strategy of each catch in the dashboard
Build and deploy / build (push) Successful in 1m31s
Build and deploy / deploy (push) Successful in 30s

Add a Strategie column to the catch list (searchable, filterable) and a
Strategien tab to the Top 10 card. The MCP top tool accepts strategies.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
TomandClaude Sonnet 5.5 committed 2026-11-16 23:34:10 +01:00
1 parent 7d3e6f8842
commit b7027e2a72
15 files changed
+83 -24

No files matched your search

+4
View File
@@ -14,6 +14,10 @@ All notable changes to Flypaper are documented in this file. The format follows
### Added
- Dashboard: the catch list has a new „Strategie“ column (hidden on narrower screens, shown in
the expanded row) and the search covers it. A new „Strategien“ tab in the Top 10 card shows
catches and hold time per strategy and filters the list on click. The MCP `top` tool accepts
`strategies` as a dimension.
- Content matches the requested path: `.env`, `*.json`, `*.xml` (sitemaps), `*.yml`, `*.sql`,
`/.git/…`, `robots.txt`, Hikvision `/SDK/…` and `/ISAPI/…` (XML) and `wp-login.php`
(WordPress login page) get an endless, matching file with the right `Content-Type`
@@ -10,6 +10,7 @@ public sealed record DashboardData(
TimeSpan TotalHoldTime,
IReadOnlyList<TopEntry> TopIps,
IReadOnlyList<TopEntry> TopTargets,
IReadOnlyList<TopEntry> TopStrategies,
IReadOnlyList<TopEntry> TopCountries,
IReadOnlyList<TopEntry> TopProviders,
IReadOnlyDictionary<string, int> CatchesByCountry);
@@ -42,6 +42,7 @@ public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbCont
TimeSpan.FromMilliseconds(await catches.SumAsync(e => e.DurationMs, ct)),
await TopAsync(catches.GroupBy(e => e.RemoteIp), ct),
await TopAsync(catches.Where(e => e.Target != null).GroupBy(e => e.Target!), ct),
await TopAsync(catches.GroupBy(e => e.Strategy), ct),
countries
.Take(TopCount)
.Select(x => new TopEntry(x.Key, x.Count, TimeSpan.FromMilliseconds(x.DurationMs), x.Name))
@@ -104,6 +105,11 @@ public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbCont
events = events.Where(e => e.Target == target);
}
if (filter.Strategy is { } strategy)
{
events = events.Where(e => e.Strategy == strategy);
}
if (!string.IsNullOrWhiteSpace(filter.Search))
{
var pattern = $"%{filter.Search.Trim().Replace("\\", "\\\\").Replace("%", "\\%").Replace("_", "\\_")}%";
@@ -111,6 +117,7 @@ public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbCont
EF.Functions.Like(e.RemoteIp, pattern, "\\")
|| EF.Functions.Like(e.Provider!, pattern, "\\")
|| EF.Functions.Like(e.Target!, pattern, "\\")
|| EF.Functions.Like(e.Strategy, pattern, "\\")
|| EF.Functions.Like(e.ClientInfo!, pattern, "\\"));
}
@@ -10,6 +10,7 @@ public sealed record RecentFilter(
long? Asn = null,
string? Ip = null,
string? Target = null,
string? Strategy = null,
string? Search = null,
int Limit = RecentFilter.DefaultLimit)
{
@@ -93,6 +93,8 @@ public sealed class CatchQueries(IDbContextFactory<FlypaperDbContext> dbContextF
.Select(g => new TopRow { Key = "AS" + g.Key.ToString(), Label = g.Max(e => e.Provider), Count = g.Count(), DurationMs = g.Sum(e => e.DurationMs) }),
TopDimension.Targets => catches.Where(e => e.Target != null).GroupBy(e => e.Target!)
.Select(g => new TopRow { Key = g.Key, Count = g.Count(), DurationMs = g.Sum(e => e.DurationMs) }),
TopDimension.Strategies => catches.GroupBy(e => e.Strategy)
.Select(g => new TopRow { Key = g.Key, Count = g.Count(), DurationMs = g.Sum(e => e.DurationMs) }),
TopDimension.UserAgents => catches.Where(e => e.ClientInfo != null).GroupBy(e => e.ClientInfo!)
.Select(g => new TopRow { Key = g.Key, Count = g.Count(), DurationMs = g.Sum(e => e.DurationMs) }),
_ => throw new ArgumentOutOfRangeException(nameof(dimension))
@@ -42,6 +42,7 @@ public enum TopDimension
Countries,
Providers,
Targets,
Strategies,
UserAgents
}
@@ -12,6 +12,7 @@ public sealed record DashboardFilter(
string? Provider = null,
string? Ip = null,
string? Ziel = null,
string? Strategie = null,
string? Q = null,
int Limit = RecentFilter.DefaultLimit)
{
@@ -31,6 +32,7 @@ public sealed record DashboardFilter(
string? provider,
string? ip,
string? ziel,
string? strategie,
string? q,
string? limit)
{
@@ -45,6 +47,7 @@ public sealed record DashboardFilter(
Asn(provider) is { } asn ? $"AS{asn.ToString(CultureInfo.InvariantCulture)}" : null,
IPAddress.TryParse(Clean(ip), out var address) ? address.ToString() : null,
Clean(ziel),
Clean(strategie),
Clean(q),
parsedLimit);
}
@@ -67,6 +70,7 @@ public sealed record DashboardFilter(
Asn(Provider),
Ip,
Ziel,
Strategie,
Q,
Limit);
@@ -81,6 +85,7 @@ public sealed record DashboardFilter(
Add(parts, "provider", Provider);
Add(parts, "ip", Ip);
Add(parts, "ziel", Ziel);
Add(parts, "strategie", Strategie);
Add(parts, "q", Q);
if (Limit != RecentFilter.DefaultLimit)
{
@@ -127,9 +127,9 @@
</label>
<label class="filter-search">
<span>Suche</span>
<input type="search" name="q" value="@_filter.Q" placeholder="IP, Provider, Ziel, User-Agent" />
<input type="search" name="q" value="@_filter.Q" placeholder="IP, Provider, Ziel, Strategie, User-Agent" />
</label>
@foreach (var (name, value) in new[] { ("provider", _filter.Provider), ("ip", _filter.Ip), ("ziel", _filter.Ziel) })
@foreach (var (name, value) in new[] { ("provider", _filter.Provider), ("ip", _filter.Ip), ("ziel", _filter.Ziel), ("strategie", _filter.Strategie) })
{
if (value is not null)
{
@@ -163,6 +163,7 @@
<th class="c-origin">Herkunft</th>
<th class="c-provider">Provider</th>
<th class="c-target">Ziel</th>
<th class="c-strategy">Strategie</th>
<th class="c-agent">User-Agent</th>
<th class="c-duration num">Dauer</th>
<th class="c-bytes num">Bytes</th>
@@ -194,11 +195,13 @@
<td class="c-target mono" title="@target">
@target
<div class="extra extra-md">Provider: @(provider ?? "–")</div>
<div class="extra extra-md">Strategie: @trapEvent.Strategy</div>
<div class="extra extra-md">User-Agent: @(trapEvent.ClientInfo ?? "–")</div>
<div class="extra extra-all">Herkunft: @(trapEvent.CountryCode is { } code ? $"{Formatting.Flag(code)} {code} · {Origin(trapEvent)}" : "–")</div>
<div class="extra extra-sm">Dauer: @duration · Bytes: @bytes</div>
<div class="extra extra-xs">Datum: @started.ToString("dd.MM.yyyy") · Ausgang: @OutcomeLabel(trapEvent.Outcome)</div>
</td>
<td class="c-strategy mono" title="@trapEvent.Strategy">@trapEvent.Strategy</td>
<td class="c-agent" title="@trapEvent.ClientInfo">@trapEvent.ClientInfo</td>
<td class="c-duration num">@duration</td>
<td class="c-bytes num">@bytes</td>
@@ -247,13 +250,15 @@
[SupplyParameterFromQuery(Name = "ziel")] public string? Ziel { get; set; }
[SupplyParameterFromQuery(Name = "strategie")] public string? Strategie { get; set; }
[SupplyParameterFromQuery(Name = "q")] public string? Q { get; set; }
[SupplyParameterFromQuery(Name = "limit")] public string? Limit { get; set; }
protected override async Task OnInitializedAsync()
{
_filter = DashboardFilter.Parse(Zeit, Ausgang, Land, Provider, Ip, Ziel, Q, Limit);
_filter = DashboardFilter.Parse(Zeit, Ausgang, Land, Provider, Ip, Ziel, Strategie, Q, Limit);
_data = await Queries.GetAsync();
_recent = await Queries.GetRecentAsync(_filter.ToRecentFilter());
_loadedAt = DateTime.Now;
@@ -264,7 +269,8 @@
new("countries", "Länder", "Land", data.TopCountries, f => f.Land, (f, key) => f with { Land = key }, ShowFlags: true, LabelFormatter: CountryNames.Display),
new("providers", "Provider", "Provider", data.TopProviders, f => f.Provider, (f, key) => f with { Provider = key }),
new("ips", "IPs", "IP", data.TopIps, f => f.Ip, (f, key) => f with { Ip = key }),
new("targets", "Ziele", "Ziel", data.TopTargets, f => f.Ziel, (f, key) => f with { Ziel = key }, KeyFormatter: Formatting.Target)
new("targets", "Ziele", "Ziel", data.TopTargets, f => f.Ziel, (f, key) => f with { Ziel = key }, KeyFormatter: Formatting.Target),
new("strategies", "Strategien", "Strategie", data.TopStrategies, f => f.Strategie, (f, key) => f with { Strategie = key })
];
private DashboardFilter TopFilter(TopTab tab, TopEntry entry) =>
@@ -306,6 +312,11 @@
yield return ($"Ziel: {Formatting.Target(ziel)}", reset with { Ziel = null });
}
if (_filter.Strategie is { } strategie)
{
yield return ($"Strategie: {strategie}", reset with { Strategie = null });
}
if (_filter.Q is { } q)
{
yield return ($"Suche: „{q}“", reset with { Q = null });
+4 -3
View File
@@ -62,8 +62,8 @@ public sealed class FlypaperTools(CatchQueries queries, IConnectionGovernor gove
[McpServerTool(Name = "top", Title = "Top values", ReadOnly = true, Destructive = false, Idempotent = true, OpenWorld = false, UseStructuredContent = true)]
[Description("Most frequent values among the catches of a time window, by number of catches. Rejected connections are not counted.")]
public async Task<TopResult> Top(
[Description("What to rank by: ips, countries, providers, targets or user_agents.")]
[AllowedValues("ips", "countries", "providers", "targets", "user_agents")]
[Description("What to rank by: ips, countries, providers, targets, strategies or user_agents.")]
[AllowedValues("ips", "countries", "providers", "targets", "strategies", "user_agents")]
string dimension,
[Description(PeriodDescription)] string period = "24h",
[Description("Number of entries, 1 to 500.")] int limit = 10,
@@ -75,8 +75,9 @@ public sealed class FlypaperTools(CatchQueries queries, IConnectionGovernor gove
"countries" => TopDimension.Countries,
"providers" => TopDimension.Providers,
"targets" => TopDimension.Targets,
"strategies" => TopDimension.Strategies,
"user_agents" => TopDimension.UserAgents,
_ => throw new McpException("dimension must be one of ips, countries, providers, targets, user_agents.")
_ => throw new McpException("dimension must be one of ips, countries, providers, targets, strategies, user_agents.")
};
var items = await queries.TopAsync(parsed, Since(period), limit, ct);
+5
View File
@@ -464,6 +464,10 @@ a.button:hover {
width: 116px;
}
.recent-table .c-strategy {
width: 190px;
}
.recent-table .extra {
display: none;
margin-top: 4px;
@@ -474,6 +478,7 @@ a.button:hover {
@media (max-width: 1199px) {
.recent-table .c-provider,
.recent-table .c-strategy,
.recent-table .c-agent {
display: none;
}
@@ -98,6 +98,7 @@ public sealed class FlypaperToolsTests : IDisposable
[InlineData("countries", "CN", 2)]
[InlineData("providers", "AS4134", 2)]
[InlineData("targets", "GET /.env", 1)]
[InlineData("strategies", "html-drip", 4)]
[InlineData("user_agents", "zgrab/0.x", 2)]
public async Task Top_ranks_each_dimension(string dimension, string firstKey, int firstCount)
{
+2 -2
View File
@@ -119,8 +119,8 @@ public sealed class McpEndpointTests : IDisposable
}
[Theory]
[InlineData("top", """{"by":"countries","period":"all"}""", "unknown parameter 'by'; expected 'dimension' (ips|countries|providers|targets|user_agents)")]
[InlineData("top", """{"period":"all"}""", "missing required parameter 'dimension' (ips|countries|providers|targets|user_agents)")]
[InlineData("top", """{"by":"countries","period":"all"}""", "unknown parameter 'by'; expected 'dimension' (ips|countries|providers|targets|strategies|user_agents)")]
[InlineData("top", """{"period":"all"}""", "missing required parameter 'dimension' (ips|countries|providers|targets|strategies|user_agents)")]
[InlineData("list_catches", """{"countryCode":"GB"}""", "unknown parameter 'countryCode'")]
public async Task Invalid_arguments_return_a_readable_tool_error(string tool, string arguments, string expected)
{
+5 -4
View File
@@ -19,11 +19,11 @@ internal sealed class McpTestData : IDisposable
using var db = Factory.CreateDbContext();
db.Database.Migrate();
Add(db, "203.0.113.9", hoursAgo: 1, seconds: 3600, "CN", "Volksrepublik China", "Beijing", 4134, "Chinanet", "GET /.env", "zgrab/0.x");
Add(db, "203.0.113.9", hoursAgo: 1, seconds: 3600, "CN", "Volksrepublik China", "Beijing", 4134, "Chinanet", "GET /.env", "zgrab/0.x", strategy: "env-drip");
Add(db, "203.0.113.9", hoursAgo: 2, seconds: 120, "CN", "Volksrepublik China", "Beijing", 4134, "Chinanet", "GET example.com/wp-login.php", "zgrab/0.x");
Add(db, "198.51.100.7", hoursAgo: 3, seconds: 30, "TW", "Republik China", "Taipeh", 3462, "Data Communication Business Group", "GET /.git/config", "curl/8.5.0");
Add(db, "2001:db8::1", hoursAgo: 30, seconds: 900, "US", "Vereinigte Staaten von Amerika", "Mountain View", 15169, "Google LLC", "POST /xmlrpc.php", "python-requests/2.31");
Add(db, "198.51.100.7", hoursAgo: 4, seconds: 0, "TW", "Republik China", "Taipeh", 3462, "Data Communication Business Group", "GET /.env", "curl/8.5.0", TrapOutcome.Rejected);
Add(db, "198.51.100.7", hoursAgo: 4, seconds: 0, "TW", "Republik China", "Taipeh", 3462, "Data Communication Business Group", "GET /.env", "curl/8.5.0", TrapOutcome.Rejected, "env-drip");
Add(db, "192.0.2.50", hoursAgo: 200, seconds: 5, null, null, null, null, null, "GET /", null);
db.SaveChanges();
}
@@ -44,14 +44,15 @@ internal sealed class McpTestData : IDisposable
string? provider,
string target,
string? userAgent,
TrapOutcome outcome = TrapOutcome.ClientAborted)
TrapOutcome outcome = TrapOutcome.ClientAborted,
string strategy = "html-drip")
{
var started = Now.AddHours(-hoursAgo);
var entity = TrapEventEntity.From(new TrapEvent(
Guid.NewGuid(),
TrapProtocol.Http,
IPAddress.Parse(ip),
"html-drip",
strategy,
started,
started.AddSeconds(seconds),
seconds * 10,
@@ -44,13 +44,32 @@ public sealed class RecentCatchesTests : IDisposable
recent.Total.ShouldBe(expected);
}
[Fact]
public async Task Matches_strategy_exactly()
{
var recent = await _queries.GetRecentAsync(new RecentFilter(Strategy: "env-drip"));
recent.Total.ShouldBe(2);
recent.Items.ShouldAllBe(e => e.Strategy == "env-drip");
}
[Fact]
public async Task Dashboard_ranks_strategies_among_catches()
{
var data = await _queries.GetAsync();
data.TopStrategies.Select(s => (s.Key, s.Count)).ShouldBe([("html-drip", 4), ("env-drip", 1)]);
data.TopStrategies[1].HoldTime.ShouldBe(TimeSpan.FromHours(1));
}
[Theory]
[InlineData("chinanet", 2)]
[InlineData("env-drip", 2)]
[InlineData("CURL", 2)]
[InlineData("198.51", 2)]
[InlineData("wp-login", 1)]
[InlineData("100%", 0)]
public async Task Search_is_case_insensitive_over_ip_provider_target_and_user_agent(string search, int expected)
public async Task Search_is_case_insensitive_over_ip_provider_target_strategy_and_user_agent(string search, int expected)
{
var recent = await _queries.GetRecentAsync(new RecentFilter(Search: search));
+10 -10
View File
@@ -10,10 +10,10 @@ public sealed class DashboardFilterTests
[Fact]
public void Parses_all_parameters()
{
var filter = DashboardFilter.Parse("24h", "Abgelehnt", "hk", "as4134", " 203.0.113.9 ", "GET /.env", " wp ", "100");
var filter = DashboardFilter.Parse("24h", "Abgelehnt", "hk", "as4134", " 203.0.113.9 ", "GET /.env", " env-drip ", " wp ", "100");
filter.ShouldBe(new DashboardFilter("24h", "abgelehnt", "HK", "AS4134", "203.0.113.9", "GET /.env", "wp", 100));
filter.ToRecentFilter().ShouldBe(new RecentFilter(TimeSpan.FromHours(24), TrapOutcome.Rejected, "HK", 4134, "203.0.113.9", "GET /.env", "wp", 100));
filter.ShouldBe(new DashboardFilter("24h", "abgelehnt", "HK", "AS4134", "203.0.113.9", "GET /.env", "env-drip", "wp", 100));
filter.ToRecentFilter().ShouldBe(new RecentFilter(TimeSpan.FromHours(24), TrapOutcome.Rejected, "HK", 4134, "203.0.113.9", "GET /.env", "env-drip", "wp", 100));
}
[Theory]
@@ -21,12 +21,12 @@ public sealed class DashboardFilterTests
[InlineData("zeitlimit", TrapOutcome.Timeout)]
[InlineData("abgelehnt", TrapOutcome.Rejected)]
public void Maps_outcomes(string value, TrapOutcome expected) =>
DashboardFilter.Parse(null, value, null, null, null, null, null, null).ToRecentFilter().Outcome.ShouldBe(expected);
DashboardFilter.Parse(null, value, null, null, null, null, null, null, null).ToRecentFilter().Outcome.ShouldBe(expected);
[Fact]
public void Ignores_invalid_values()
{
var filter = DashboardFilter.Parse("gestern", "kaputt", "Hongkong", "Chinanet", "not-an-ip", " ", "", "viele");
var filter = DashboardFilter.Parse("gestern", "kaputt", "Hongkong", "Chinanet", "not-an-ip", " ", " ", "", "viele");
filter.ShouldBe(new DashboardFilter());
filter.IsEmpty.ShouldBeTrue();
@@ -38,23 +38,23 @@ public sealed class DashboardFilterTests
[InlineData("100000", RecentFilter.MaxLimit)]
[InlineData(null, RecentFilter.DefaultLimit)]
public void Clamps_the_limit(string? limit, int expected) =>
DashboardFilter.Parse(null, null, null, null, null, null, null, limit).Limit.ShouldBe(expected);
DashboardFilter.Parse(null, null, null, null, null, null, null, null, limit).Limit.ShouldBe(expected);
[Fact]
public void Builds_links_without_defaults_and_with_escaping()
{
new DashboardFilter().Href().ShouldBe("/#faenge");
new DashboardFilter(Land: "CN", Ziel: "GET example.com/a&b", Limit: 100).Href("f50")
.ShouldBe("/?land=CN&ziel=GET%20example.com%2Fa%26b&limit=100#f50");
new DashboardFilter(Land: "CN", Ziel: "GET example.com/a&b", Strategie: "html-drip 50-500ms 1-1024B", Limit: 100).Href("f50")
.ShouldBe("/?land=CN&ziel=GET%20example.com%2Fa%26b&strategie=html-drip%2050-500ms%201-1024B&limit=100#f50");
}
[Fact]
public void Links_round_trip()
{
var filter = new DashboardFilter("7d", "zeitlimit", "TW", "AS3462", "2001:db8::1", "POST /xmlrpc.php", "curl", 200);
var filter = new DashboardFilter("7d", "zeitlimit", "TW", "AS3462", "2001:db8::1", "POST /xmlrpc.php", "hikvision-drip", "curl", 200);
var query = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(new Uri("http://x" + filter.Href()).Query);
DashboardFilter.Parse(query["zeit"], query["ausgang"], query["land"], query["provider"], query["ip"], query["ziel"], query["q"], query["limit"])
DashboardFilter.Parse(query["zeit"], query["ausgang"], query["land"], query["provider"], query["ip"], query["ziel"], query["strategie"], query["q"], query["limit"])
.ShouldBe(filter);
}