Pick tarpit content by request path
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e48b6bb832
commit
13468bbdf9
18 files changed
+307
-9
No files matched your search
@@ -8,6 +8,10 @@ All notable changes to Flypaper are documented in this file. The format follows
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- Content matches the requested path: `.env`, `*.json`, `*.xml` (sitemaps), `*.yml`, `*.sql`,
|
||||||
|
`/.git/…` and `robots.txt` get an endless, matching file with the right `Content-Type`
|
||||||
|
instead of an HTML page (strategy names `env-drip`, `json-drip`, …). Switchable on the
|
||||||
|
settings page (`Flypaper__Drip__MatchPath`).
|
||||||
- Head start: the first bytes of the page (at least `HeadStartSize`, default 1024) are sent
|
- Head start: the first bytes of the page (at least `HeadStartSize`, default 1024) are sent
|
||||||
immediately after the `200` headers, with a `Server` header, so scanners see a real response
|
immediately after the `200` headers, with a `Server` header, so scanners see a real response
|
||||||
before the drip begins. Adjustable on the settings page; the stored strategy name gets a
|
before the drip begins. Adjustable on the settings page; the stored strategy name gets a
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ All optional. Read at startup; list entries need an index (`__0`, `__1`, ...).
|
|||||||
| `Flypaper__Drip__MinDelay` / `MaxDelay` | Pause between chunks | `00:00:00.05` / `00:00:01` |
|
| `Flypaper__Drip__MinDelay` / `MaxDelay` | Pause between chunks | `00:00:00.05` / `00:00:01` |
|
||||||
| `Flypaper__Drip__MinChunkSize` / `MaxChunkSize` | Bytes per chunk | `1` / `64` |
|
| `Flypaper__Drip__MinChunkSize` / `MaxChunkSize` | Bytes per chunk | `1` / `64` |
|
||||||
| `Flypaper__Drip__HeadStartSize` | Bytes sent immediately before dripping starts (`0` = off) | `1024` |
|
| `Flypaper__Drip__HeadStartSize` | Bytes sent immediately before dripping starts (`0` = off) | `1024` |
|
||||||
|
| `Flypaper__Drip__MatchPath` | Pick content by request path (`/.env`, `*.json`, `*.xml`, `*.yml`, `*.sql`, `/.git/…`, `robots.txt`) | `true` |
|
||||||
| `TZ` | Time zone for the dashboard | UTC |
|
| `TZ` | Time zone for the dashboard | UTC |
|
||||||
|
|
||||||
The defaults of the runtime settings below can also be set this way, e.g.
|
The defaults of the runtime settings below can also be set this way, e.g.
|
||||||
@@ -40,6 +41,7 @@ general reset button removes all saved values; the hold method section has its o
|
|||||||
| Hold method: pause between chunks, min and max (10 ms to 30 s) | 50 ms / 1000 ms |
|
| Hold method: pause between chunks, min and max (10 ms to 30 s) | 50 ms / 1000 ms |
|
||||||
| Hold method: chunk size, min and max (1 to 4096 bytes) | 1 / 64 bytes |
|
| Hold method: chunk size, min and max (1 to 4096 bytes) | 1 / 64 bytes |
|
||||||
| Hold method: head start, sent without delay before the drip (0 to 65536 bytes) | 1024 bytes |
|
| Hold method: head start, sent without delay before the drip (0 to 65536 bytes) | 1024 bytes |
|
||||||
|
| Hold method: content matching the request path (e.g. `/.env`, `/config.json`) | on |
|
||||||
| Hold method: maximum hold time per catch | `01:00:00` |
|
| Hold method: maximum hold time per catch | `01:00:00` |
|
||||||
| Maximum connections overall | `1000` |
|
| Maximum connections overall | `1000` |
|
||||||
| Maximum connections per IP | `10` |
|
| Maximum connections per IP | `10` |
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Flypaper.Core.Strategies;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Flypaper.Core;
|
namespace Flypaper.Core;
|
||||||
|
|
||||||
@@ -20,6 +21,15 @@ public static class FlypaperCoreExtensions
|
|||||||
services.TryAddSingleton<IRandomSource, SystemRandomSource>();
|
services.TryAddSingleton<IRandomSource, SystemRandomSource>();
|
||||||
services.TryAddEnumerable(ServiceDescriptor.Singleton<ITarpitStrategy, HtmlDripStrategy>());
|
services.TryAddEnumerable(ServiceDescriptor.Singleton<ITarpitStrategy, HtmlDripStrategy>());
|
||||||
services.TryAddEnumerable(ServiceDescriptor.Singleton<ITarpitStrategy, TextDripStrategy>());
|
services.TryAddEnumerable(ServiceDescriptor.Singleton<ITarpitStrategy, TextDripStrategy>());
|
||||||
|
foreach (var profile in FileContent.Profiles)
|
||||||
|
{
|
||||||
|
services.AddSingleton<ITarpitStrategy>(provider => new FileDripStrategy(
|
||||||
|
profile,
|
||||||
|
provider.GetRequiredService<IOptionsMonitor<DripOptions>>(),
|
||||||
|
provider.GetRequiredService<IRandomSource>(),
|
||||||
|
provider.GetRequiredService<TimeProvider>()));
|
||||||
|
}
|
||||||
|
|
||||||
services.TryAddSingleton<ITrapStrategySelector, ConfiguredStrategySelector>();
|
services.TryAddSingleton<ITrapStrategySelector, ConfiguredStrategySelector>();
|
||||||
services.TryAddSingleton<TrapRunner>();
|
services.TryAddSingleton<TrapRunner>();
|
||||||
services.TryAddSingleton<IIpEnricher, NullIpEnricher>();
|
services.TryAddSingleton<IIpEnricher, NullIpEnricher>();
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
namespace Flypaper.Core.Models;
|
namespace Flypaper.Core.Models;
|
||||||
|
|
||||||
public sealed record TrapContext(TrapSession Session, string? Target = null, string? ClientInfo = null);
|
public sealed record TrapContext(TrapSession Session, string? Target = null, string? ClientInfo = null, string? Path = null);
|
||||||
@@ -13,6 +13,12 @@ public sealed class ConfiguredStrategySelector(
|
|||||||
public ITarpitStrategy? Select(TrapContext context)
|
public ITarpitStrategy? Select(TrapContext context)
|
||||||
{
|
{
|
||||||
var candidates = strategies.Where(strategy => strategy.Supports(context.Session.Protocol)).ToList();
|
var candidates = strategies.Where(strategy => strategy.Supports(context.Session.Protocol)).ToList();
|
||||||
|
if (options.CurrentValue.MatchPath && FileContent.Match(context.Path) is { } profile
|
||||||
|
&& candidates.FirstOrDefault(strategy => strategy.Name == profile.Name) is { } fileStrategy)
|
||||||
|
{
|
||||||
|
return fileStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
string[] wanted = options.CurrentValue.Content switch
|
string[] wanted = options.CurrentValue.Content switch
|
||||||
{
|
{
|
||||||
DripContent.Text => [TextDripStrategy.StrategyName],
|
DripContent.Text => [TextDripStrategy.StrategyName],
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ public sealed record HoldMethodSettings(
|
|||||||
int MinChunkSize,
|
int MinChunkSize,
|
||||||
int MaxChunkSize,
|
int MaxChunkSize,
|
||||||
int HeadStartSize,
|
int HeadStartSize,
|
||||||
|
bool MatchPath,
|
||||||
TimeSpan MaxHoldDuration)
|
TimeSpan MaxHoldDuration)
|
||||||
{
|
{
|
||||||
public double BytesPerSecond => AverageBytesPerSecond(MinDelay, MaxDelay, MinChunkSize, MaxChunkSize);
|
public double BytesPerSecond => AverageBytesPerSecond(MinDelay, MaxDelay, MinChunkSize, MaxChunkSize);
|
||||||
@@ -22,6 +23,7 @@ public sealed record HoldMethodSettings(
|
|||||||
[SettingKeys.DripMinChunkSize] = MinChunkSize.ToString(CultureInfo.InvariantCulture),
|
[SettingKeys.DripMinChunkSize] = MinChunkSize.ToString(CultureInfo.InvariantCulture),
|
||||||
[SettingKeys.DripMaxChunkSize] = MaxChunkSize.ToString(CultureInfo.InvariantCulture),
|
[SettingKeys.DripMaxChunkSize] = MaxChunkSize.ToString(CultureInfo.InvariantCulture),
|
||||||
[SettingKeys.DripHeadStartSize] = HeadStartSize.ToString(CultureInfo.InvariantCulture),
|
[SettingKeys.DripHeadStartSize] = HeadStartSize.ToString(CultureInfo.InvariantCulture),
|
||||||
|
[SettingKeys.DripMatchPath] = MatchPath ? "true" : "false",
|
||||||
[SettingKeys.MaxHoldDuration] = MaxHoldDuration.ToString("c", CultureInfo.InvariantCulture)
|
[SettingKeys.MaxHoldDuration] = MaxHoldDuration.ToString("c", CultureInfo.InvariantCulture)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -39,6 +41,7 @@ public sealed record HoldMethodInput(
|
|||||||
string? MinChunkSize,
|
string? MinChunkSize,
|
||||||
string? MaxChunkSize,
|
string? MaxChunkSize,
|
||||||
string? HeadStartSize,
|
string? HeadStartSize,
|
||||||
|
bool MatchPath,
|
||||||
string? MaxHoldDuration);
|
string? MaxHoldDuration);
|
||||||
|
|
||||||
public sealed record HoldMethodParseResult(HoldMethodSettings? Settings, IReadOnlyDictionary<string, string> Errors);
|
public sealed record HoldMethodParseResult(HoldMethodSettings? Settings, IReadOnlyDictionary<string, string> Errors);
|
||||||
@@ -84,6 +84,7 @@ public static class RuntimeSettingsParser
|
|||||||
minChunk!.Value,
|
minChunk!.Value,
|
||||||
maxChunk!.Value,
|
maxChunk!.Value,
|
||||||
headStart!.Value,
|
headStart!.Value,
|
||||||
|
input.MatchPath,
|
||||||
hold!.Value),
|
hold!.Value),
|
||||||
errors);
|
errors);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,13 @@ public static class SettingKeys
|
|||||||
public const string DripMinChunkSize = "Flypaper:Drip:MinChunkSize";
|
public const string DripMinChunkSize = "Flypaper:Drip:MinChunkSize";
|
||||||
public const string DripMaxChunkSize = "Flypaper:Drip:MaxChunkSize";
|
public const string DripMaxChunkSize = "Flypaper:Drip:MaxChunkSize";
|
||||||
public const string DripHeadStartSize = "Flypaper:Drip:HeadStartSize";
|
public const string DripHeadStartSize = "Flypaper:Drip:HeadStartSize";
|
||||||
|
public const string DripMatchPath = "Flypaper:Drip:MatchPath";
|
||||||
|
|
||||||
public static readonly IReadOnlyList<string> General =
|
public static readonly IReadOnlyList<string> General =
|
||||||
[MaxConnections, MaxConnectionsPerIp, IgnorePrivateNetworks, RetentionDays];
|
[MaxConnections, MaxConnectionsPerIp, IgnorePrivateNetworks, RetentionDays];
|
||||||
|
|
||||||
public static readonly IReadOnlyList<string> HoldMethod =
|
public static readonly IReadOnlyList<string> HoldMethod =
|
||||||
[DripContent, DripMinDelay, DripMaxDelay, DripMinChunkSize, DripMaxChunkSize, DripHeadStartSize, MaxHoldDuration];
|
[DripContent, DripMinDelay, DripMaxDelay, DripMinChunkSize, DripMaxChunkSize, DripHeadStartSize, DripMatchPath, MaxHoldDuration];
|
||||||
|
|
||||||
public static readonly IReadOnlySet<string> All =
|
public static readonly IReadOnlySet<string> All =
|
||||||
new HashSet<string>(General.Concat(HoldMethod), StringComparer.OrdinalIgnoreCase);
|
new HashSet<string>(General.Concat(HoldMethod), StringComparer.OrdinalIgnoreCase);
|
||||||
|
|||||||
@@ -15,4 +15,6 @@ public sealed class DripOptions
|
|||||||
public int MaxChunkSize { get; set; } = 64;
|
public int MaxChunkSize { get; set; } = 64;
|
||||||
|
|
||||||
public int HeadStartSize { get; set; } = 1024;
|
public int HeadStartSize { get; set; } = 1024;
|
||||||
|
|
||||||
|
public bool MatchPath { get; set; } = true;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using Flypaper.Core.Abstractions;
|
||||||
|
|
||||||
|
namespace Flypaper.Core.Strategies;
|
||||||
|
|
||||||
|
public sealed record FileProfile(
|
||||||
|
string Name,
|
||||||
|
string MediaType,
|
||||||
|
Func<string, bool> Matches,
|
||||||
|
Func<IRandomSource, IEnumerable<string>> Generate);
|
||||||
|
|
||||||
|
public static class FileContent
|
||||||
|
{
|
||||||
|
private static readonly string[] Sections = ["docs", "blog", "wiki", "support", "products", "archive", "news", "help", "files"];
|
||||||
|
|
||||||
|
public static readonly IReadOnlyList<FileProfile> Profiles =
|
||||||
|
[
|
||||||
|
new("git-drip", "text/plain; charset=utf-8", path => path.Contains("/.git/", StringComparison.Ordinal), GitConfig),
|
||||||
|
new("robots-drip", "text/plain; charset=utf-8", path => LastSegment(path) == "robots.txt", Robots),
|
||||||
|
new("env-drip", "text/plain; charset=utf-8", path => IsEnv(LastSegment(path)), Env),
|
||||||
|
new("json-drip", "application/json", path => path.EndsWith(".json", StringComparison.Ordinal), Json),
|
||||||
|
new("xml-drip", "application/xml", path => path.EndsWith(".xml", StringComparison.Ordinal), Xml),
|
||||||
|
new("yaml-drip", "text/plain; charset=utf-8", path => path.EndsWith(".yml", StringComparison.Ordinal) || path.EndsWith(".yaml", StringComparison.Ordinal), Yaml),
|
||||||
|
new("sql-drip", "text/plain; charset=utf-8", path => path.EndsWith(".sql", StringComparison.Ordinal), Sql)
|
||||||
|
];
|
||||||
|
|
||||||
|
public static FileProfile? Match(string? path)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(path))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var normalized = path.ToLowerInvariant();
|
||||||
|
return Profiles.FirstOrDefault(profile => profile.Matches(normalized));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string LastSegment(string path) => path[(path.LastIndexOf('/') + 1)..];
|
||||||
|
|
||||||
|
private static bool IsEnv(string name) =>
|
||||||
|
name.StartsWith(".env", StringComparison.Ordinal) || name.EndsWith(".env", StringComparison.Ordinal) || name == "env";
|
||||||
|
|
||||||
|
private static IEnumerable<string> Env(IRandomSource random)
|
||||||
|
{
|
||||||
|
yield return $"APP_NAME=Portal\nAPP_ENV=production\nAPP_DEBUG=false\nAPP_URL=https://example.com\nAPP_KEY=base64:{Hex(random, 32)}\n\n"
|
||||||
|
+ $"DB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=app\nDB_USERNAME=app\nDB_PASSWORD={Hex(random, 16)}\n\n";
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var key = $"{Upper(random)}_{Upper(random)}";
|
||||||
|
yield return random.Next(0, 4) switch
|
||||||
|
{
|
||||||
|
0 => $"{key}=true\n",
|
||||||
|
1 => $"{key}={random.Next(1, 65536)}\n",
|
||||||
|
2 => $"{key}=https://{LoremText.Word(random)}.internal/\n",
|
||||||
|
_ => $"{key}={Hex(random, 24)}\n"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<string> Json(IRandomSource random)
|
||||||
|
{
|
||||||
|
yield return "{\n \"name\": \"portal\",\n \"version\": \"1.4.2\",\n \"private\": true,\n \"entries\": [\n";
|
||||||
|
|
||||||
|
var id = 1;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
yield return $" {{\"id\": {id++}, \"name\": \"{LoremText.Word(random)}\", \"token\": \"{Hex(random, 16)}\", \"enabled\": {(random.Next(0, 2) == 0 ? "true" : "false")}}},\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<string> Xml(IRandomSource random)
|
||||||
|
{
|
||||||
|
yield return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var date = string.Create(CultureInfo.InvariantCulture, $"2026-{random.Next(1, 13):00}-{random.Next(1, 29):00}");
|
||||||
|
yield return $" <url>\n <loc>https://example.com/{Pick(random, Sections)}/{LoremText.Phrase(random, 2).Replace(' ', '-')}</loc>\n <lastmod>{date}</lastmod>\n </url>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<string> Yaml(IRandomSource random)
|
||||||
|
{
|
||||||
|
yield return "version: \"3.8\"\nservices:\n";
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
yield return $" {LoremText.Word(random)}:\n image: {LoremText.Word(random)}:{random.Next(1, 10)}.{random.Next(0, 20)}\n restart: unless-stopped\n environment:\n - SECRET={Hex(random, 12)}\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<string> Sql(IRandomSource random)
|
||||||
|
{
|
||||||
|
yield return "-- MySQL dump 10.13 Distrib 8.0.36, for Linux (x86_64)\n--\n-- Host: localhost Database: app\n-- ------------------------------------------------------\n\n"
|
||||||
|
+ "DROP TABLE IF EXISTS `users`;\nCREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `name` varchar(64) NOT NULL,\n `token` varchar(64) NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n\n"
|
||||||
|
+ "LOCK TABLES `users` WRITE;\n";
|
||||||
|
|
||||||
|
var id = 1;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
yield return $"INSERT INTO `users` VALUES ({id++},'{LoremText.Word(random)}','{Hex(random, 32)}');\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<string> GitConfig(IRandomSource random)
|
||||||
|
{
|
||||||
|
yield return "[core]\n\trepositoryformatversion = 0\n\tfilemode = true\n\tbare = false\n\tlogallrefupdates = true\n"
|
||||||
|
+ "[remote \"origin\"]\n\turl = https://example.com/portal.git\n\tfetch = +refs/heads/*:refs/remotes/origin/*\n";
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var branch = $"{LoremText.Word(random)}-{LoremText.Word(random)}";
|
||||||
|
yield return $"[branch \"{branch}\"]\n\tremote = origin\n\tmerge = refs/heads/{branch}\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<string> Robots(IRandomSource random)
|
||||||
|
{
|
||||||
|
yield return "User-agent: *\nCrawl-delay: 2\nSitemap: https://example.com/sitemap.xml\n";
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
yield return $"Disallow: /{Pick(random, Sections)}/{LoremText.Word(random)}/\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string Hex(IRandomSource random, int length)
|
||||||
|
{
|
||||||
|
var chars = new char[length];
|
||||||
|
for (var i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
chars[i] = "0123456789abcdef"[random.Next(0, 16)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return new string(chars);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string Upper(IRandomSource random) => LoremText.Word(random).ToUpperInvariant();
|
||||||
|
|
||||||
|
private static string Pick(IRandomSource random, string[] values) => values[random.Next(0, values.Length)];
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using Flypaper.Core.Abstractions;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
namespace Flypaper.Core.Strategies;
|
||||||
|
|
||||||
|
public sealed class FileDripStrategy(
|
||||||
|
FileProfile profile,
|
||||||
|
IOptionsMonitor<DripOptions> options,
|
||||||
|
IRandomSource random,
|
||||||
|
TimeProvider timeProvider) : DripStrategy(options, random, timeProvider)
|
||||||
|
{
|
||||||
|
public override string Name => profile.Name;
|
||||||
|
|
||||||
|
public override string MediaType => profile.MediaType;
|
||||||
|
|
||||||
|
protected override IEnumerable<string> Content(IRandomSource random) => profile.Generate(random);
|
||||||
|
}
|
||||||
@@ -35,7 +35,8 @@ internal sealed class FlypaperMiddleware(
|
|||||||
var trapContext = new TrapContext(
|
var trapContext = new TrapContext(
|
||||||
session,
|
session,
|
||||||
$"{request.Method} {StoredHost(request.Host)}{request.Path}{request.QueryString}",
|
$"{request.Method} {StoredHost(request.Host)}{request.Path}{request.QueryString}",
|
||||||
request.Headers.UserAgent.ToString());
|
request.Headers.UserAgent.ToString(),
|
||||||
|
request.Path.Value);
|
||||||
|
|
||||||
var outcome = await runner.RunAsync(
|
var outcome = await runner.RunAsync(
|
||||||
trapContext,
|
trapContext,
|
||||||
|
|||||||
@@ -14,5 +14,7 @@ public sealed class HoldMethodModel
|
|||||||
|
|
||||||
public string? HeadStartSize { get; set; }
|
public string? HeadStartSize { get; set; }
|
||||||
|
|
||||||
|
public bool MatchPath { get; set; }
|
||||||
|
|
||||||
public string? MaxHoldDuration { get; set; }
|
public string? MaxHoldDuration { get; set; }
|
||||||
}
|
}
|
||||||
@@ -64,6 +64,14 @@
|
|||||||
</SettingsField>
|
</SettingsField>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<label class="switch-row">
|
||||||
|
<InputCheckbox class="switch" @bind-Value="Model!.MatchPath" />
|
||||||
|
<span>
|
||||||
|
<strong>Inhalt zum Pfad passend wählen</strong>
|
||||||
|
<span class="muted">Anfragen wie /.env, /config.json, /sitemap.xml oder /backup.sql bekommen passend aussehenden Inhalt statt einer Webseite.</span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
<div class="estimate">
|
<div class="estimate">
|
||||||
<span class="estimate-value">Ø <strong id="drip-bandwidth">@Bandwidth</strong> Bytes/s</span>
|
<span class="estimate-value">Ø <strong id="drip-bandwidth">@Bandwidth</strong> Bytes/s</span>
|
||||||
<span class="muted">pro gefangener Verbindung, berechnet aus Pausen und Paketgrößen</span>
|
<span class="muted">pro gefangener Verbindung, berechnet aus Pausen und Paketgrößen</span>
|
||||||
@@ -129,6 +137,7 @@
|
|||||||
Model.MinChunkSize,
|
Model.MinChunkSize,
|
||||||
Model.MaxChunkSize,
|
Model.MaxChunkSize,
|
||||||
Model.HeadStartSize,
|
Model.HeadStartSize,
|
||||||
|
Model.MatchPath,
|
||||||
Model.MaxHoldDuration));
|
Model.MaxHoldDuration));
|
||||||
|
|
||||||
if (result.Settings is null)
|
if (result.Settings is null)
|
||||||
@@ -158,6 +167,7 @@
|
|||||||
MinChunkSize = drip.MinChunkSize.ToString(CultureInfo.InvariantCulture),
|
MinChunkSize = drip.MinChunkSize.ToString(CultureInfo.InvariantCulture),
|
||||||
MaxChunkSize = drip.MaxChunkSize.ToString(CultureInfo.InvariantCulture),
|
MaxChunkSize = drip.MaxChunkSize.ToString(CultureInfo.InvariantCulture),
|
||||||
HeadStartSize = drip.HeadStartSize.ToString(CultureInfo.InvariantCulture),
|
HeadStartSize = drip.HeadStartSize.ToString(CultureInfo.InvariantCulture),
|
||||||
|
MatchPath = drip.MatchPath,
|
||||||
MaxHoldDuration = Core.CurrentValue.MaxHoldDuration.ToString("c", CultureInfo.InvariantCulture)
|
MaxHoldDuration = Core.CurrentValue.MaxHoldDuration.ToString("c", CultureInfo.InvariantCulture)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using Flypaper.Core.Models;
|
||||||
|
using Flypaper.Core.Runtime;
|
||||||
|
using Flypaper.Core.Strategies;
|
||||||
|
using Flypaper.Tests.Fakes;
|
||||||
|
using Shouldly;
|
||||||
|
|
||||||
|
namespace Flypaper.Tests.Core;
|
||||||
|
|
||||||
|
public sealed class FileContentTests
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData("/.env", "env-drip")]
|
||||||
|
[InlineData("/app/.ENV.production", "env-drip")]
|
||||||
|
[InlineData("/config.json", "json-drip")]
|
||||||
|
[InlineData("/sitemap.xml", "xml-drip")]
|
||||||
|
[InlineData("/docker-compose.yml", "yaml-drip")]
|
||||||
|
[InlineData("/backup/db.sql", "sql-drip")]
|
||||||
|
[InlineData("/.git/config", "git-drip")]
|
||||||
|
[InlineData("/robots.txt", "robots-drip")]
|
||||||
|
public void Matches_known_paths(string path, string expected) =>
|
||||||
|
FileContent.Match(path).ShouldNotBeNull().Name.ShouldBe(expected);
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("/")]
|
||||||
|
[InlineData("/index.php")]
|
||||||
|
[InlineData("/wp-login.php")]
|
||||||
|
[InlineData("/environment")]
|
||||||
|
[InlineData("")]
|
||||||
|
[InlineData(null)]
|
||||||
|
public void Ignores_other_paths(string? path) => FileContent.Match(path).ShouldBeNull();
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("/.env", "APP_NAME=")]
|
||||||
|
[InlineData("/config.json", "{")]
|
||||||
|
[InlineData("/sitemap.xml", "<?xml")]
|
||||||
|
[InlineData("/docker-compose.yml", "version:")]
|
||||||
|
[InlineData("/dump.sql", "-- MySQL dump")]
|
||||||
|
[InlineData("/.git/config", "[core]")]
|
||||||
|
[InlineData("/robots.txt", "User-agent:")]
|
||||||
|
public void Generates_an_endless_file_that_starts_like_the_real_thing(string path, string start)
|
||||||
|
{
|
||||||
|
var profile = FileContent.Match(path).ShouldNotBeNull();
|
||||||
|
|
||||||
|
var text = string.Concat(profile.Generate(new SeededRandomSource(5)).Take(200));
|
||||||
|
|
||||||
|
text.ShouldStartWith(start);
|
||||||
|
text.Length.ShouldBeGreaterThan(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Selector_prefers_the_path_profile_and_can_be_switched_off()
|
||||||
|
{
|
||||||
|
var session = new TrapSession(Guid.NewGuid(), TrapProtocol.Http, IPAddress.Parse("203.0.113.9"), DateTimeOffset.UtcNow);
|
||||||
|
var context = new TrapContext(session, "GET /.env", Path: "/.env");
|
||||||
|
|
||||||
|
Selector(matchPath: true).Select(context).ShouldNotBeNull().Name.ShouldBe("env-drip");
|
||||||
|
Selector(matchPath: true).Select(context with { Path = "/" }).ShouldNotBeNull().Name.ShouldBe("html-drip");
|
||||||
|
Selector(matchPath: false).Select(context).ShouldNotBeNull().Name.ShouldBe("html-drip");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task File_strategy_sends_the_head_start_and_names_itself()
|
||||||
|
{
|
||||||
|
var options = TestOptions.Monitor(new DripOptions { MinDelay = TimeSpan.FromSeconds(30), MaxDelay = TimeSpan.FromSeconds(30), HeadStartSize = 300 });
|
||||||
|
var strategy = new FileDripStrategy(FileContent.Match("/.env")!, options, new SeededRandomSource(1), TimeProvider.System);
|
||||||
|
var channel = new FakeTrapChannel();
|
||||||
|
using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(200));
|
||||||
|
|
||||||
|
await Should.ThrowAsync<OperationCanceledException>(() => strategy.RunAsync(channel, cts.Token));
|
||||||
|
|
||||||
|
Encoding.UTF8.GetString(channel.Writes.First()).ShouldStartWith("APP_NAME=");
|
||||||
|
channel.Writes.First().Length.ShouldBeGreaterThanOrEqualTo(300);
|
||||||
|
strategy.Describe().ShouldBe("env-drip 30000-30000ms 1-64B head 300B");
|
||||||
|
strategy.MediaType.ShouldStartWith("text/plain");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ConfiguredStrategySelector Selector(bool matchPath)
|
||||||
|
{
|
||||||
|
var options = TestOptions.Monitor(new DripOptions { MatchPath = matchPath });
|
||||||
|
var random = new SeededRandomSource(11);
|
||||||
|
return new ConfiguredStrategySelector(
|
||||||
|
[
|
||||||
|
new HtmlDripStrategy(options, random, TimeProvider.System),
|
||||||
|
new TextDripStrategy(options, random, TimeProvider.System),
|
||||||
|
.. FileContent.Profiles.Select(profile => new FileDripStrategy(profile, options, random, TimeProvider.System))
|
||||||
|
],
|
||||||
|
options,
|
||||||
|
random);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ namespace Flypaper.Tests.Core;
|
|||||||
|
|
||||||
public sealed class HoldMethodParserTests
|
public sealed class HoldMethodParserTests
|
||||||
{
|
{
|
||||||
private static readonly HoldMethodInput Valid = new("Alternating", "50", "1000", "1", "64", "2048", "01:00:00");
|
private static readonly HoldMethodInput Valid = new("Alternating", "50", "1000", "1", "64", "2048", true, "01:00:00");
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Parses_valid_input()
|
public void Parses_valid_input()
|
||||||
@@ -19,6 +19,7 @@ public sealed class HoldMethodParserTests
|
|||||||
settings.MinChunkSize.ShouldBe(1);
|
settings.MinChunkSize.ShouldBe(1);
|
||||||
settings.MaxChunkSize.ShouldBe(64);
|
settings.MaxChunkSize.ShouldBe(64);
|
||||||
settings.HeadStartSize.ShouldBe(2048);
|
settings.HeadStartSize.ShouldBe(2048);
|
||||||
|
settings.MatchPath.ShouldBeTrue();
|
||||||
settings.MaxHoldDuration.ShouldBe(TimeSpan.FromHours(1));
|
settings.MaxHoldDuration.ShouldBe(TimeSpan.FromHours(1));
|
||||||
settings.ToConfiguration().Keys.ShouldBe(SettingKeys.HoldMethod, ignoreOrder: true);
|
settings.ToConfiguration().Keys.ShouldBe(SettingKeys.HoldMethod, ignoreOrder: true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,12 @@ namespace Flypaper.Tests.Http;
|
|||||||
public sealed class ContentTypeTests
|
public sealed class ContentTypeTests
|
||||||
{
|
{
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("Html", "text/html; charset=utf-8")]
|
[InlineData("Html", "/", "text/html; charset=utf-8")]
|
||||||
[InlineData("Text", "text/plain; charset=utf-8")]
|
[InlineData("Text", "/", "text/plain; charset=utf-8")]
|
||||||
public async Task Trap_answers_with_the_media_type_of_the_selected_strategy(string content, string expected)
|
[InlineData("Html", "/config.json", "application/json")]
|
||||||
|
[InlineData("Html", "/.env", "text/plain; charset=utf-8")]
|
||||||
|
[InlineData("Html", "/sitemap.xml", "application/xml")]
|
||||||
|
public async Task Trap_answers_with_the_media_type_of_the_selected_strategy(string content, string path, string expected)
|
||||||
{
|
{
|
||||||
var configuration = new ConfigurationBuilder()
|
var configuration = new ConfigurationBuilder()
|
||||||
.AddInMemoryCollection(new Dictionary<string, string?>
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
||||||
@@ -39,7 +42,7 @@ public sealed class ContentTypeTests
|
|||||||
var context = new DefaultHttpContext { RequestServices = services };
|
var context = new DefaultHttpContext { RequestServices = services };
|
||||||
context.Connection.RemoteIpAddress = IPAddress.Parse("203.0.113.9");
|
context.Connection.RemoteIpAddress = IPAddress.Parse("203.0.113.9");
|
||||||
context.Connection.LocalPort = 8080;
|
context.Connection.LocalPort = 8080;
|
||||||
context.Request.Path = "/";
|
context.Request.Path = path;
|
||||||
|
|
||||||
await app.Build()(context);
|
await app.Build()(context);
|
||||||
|
|
||||||
|
|||||||
@@ -89,13 +89,14 @@ public sealed class SettingsOverrideTests : IDisposable
|
|||||||
var store = host.Services.GetRequiredService<RuntimeSettingsStore>();
|
var store = host.Services.GetRequiredService<RuntimeSettingsStore>();
|
||||||
string[] holdKeys = [.. SettingKeys.HoldMethod];
|
string[] holdKeys = [.. SettingKeys.HoldMethod];
|
||||||
|
|
||||||
await store.SaveAsync(new HoldMethodSettings(DripContent.Text, TimeSpan.FromMilliseconds(200), TimeSpan.FromSeconds(2), 8, 16, 256, TimeSpan.FromMinutes(5)));
|
await store.SaveAsync(new HoldMethodSettings(DripContent.Text, TimeSpan.FromMilliseconds(200), TimeSpan.FromSeconds(2), 8, 16, 256, false, TimeSpan.FromMinutes(5)));
|
||||||
await store.SaveAsync(new RuntimeSettings(50, 4, 90, true));
|
await store.SaveAsync(new RuntimeSettings(50, 4, 90, true));
|
||||||
|
|
||||||
drip.CurrentValue.Content.ShouldBe(DripContent.Text);
|
drip.CurrentValue.Content.ShouldBe(DripContent.Text);
|
||||||
drip.CurrentValue.MinDelay.ShouldBe(TimeSpan.FromMilliseconds(200));
|
drip.CurrentValue.MinDelay.ShouldBe(TimeSpan.FromMilliseconds(200));
|
||||||
drip.CurrentValue.MaxChunkSize.ShouldBe(16);
|
drip.CurrentValue.MaxChunkSize.ShouldBe(16);
|
||||||
drip.CurrentValue.HeadStartSize.ShouldBe(256);
|
drip.CurrentValue.HeadStartSize.ShouldBe(256);
|
||||||
|
drip.CurrentValue.MatchPath.ShouldBeFalse();
|
||||||
core.CurrentValue.MaxHoldDuration.ShouldBe(TimeSpan.FromMinutes(5));
|
core.CurrentValue.MaxHoldDuration.ShouldBe(TimeSpan.FromMinutes(5));
|
||||||
core.CurrentValue.MaxConnections.ShouldBe(50);
|
core.CurrentValue.MaxConnections.ShouldBe(50);
|
||||||
(await store.HasOverridesAsync(holdKeys)).ShouldBeTrue();
|
(await store.HasOverridesAsync(holdKeys)).ShouldBeTrue();
|
||||||
|
|||||||
Reference in new issue
Block a user