Compare commits
4
Commits
v0.4.0
..
7d3e6f8842
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d3e6f8842 | ||
|
|
aeafaa71a8 | ||
|
|
13468bbdf9 | ||
|
|
e48b6bb832 |
No files matched your search
@@ -6,6 +6,24 @@ All notable changes to Flypaper are documented in this file. The format follows
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Narrow or tiny countries that are drawn as a polygon but barely visible (Israel, Lebanon,
|
||||
Palestine, Kuwait, Qatar, Netherlands, Belgium, Switzerland and others) now also get a
|
||||
marker on the world map once they have catches.
|
||||
|
||||
### Added
|
||||
|
||||
- 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`
|
||||
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
|
||||
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
|
||||
`head <n>B` suffix (none when off).
|
||||
|
||||
## [0.4.0] - 2026-11-15
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -23,6 +23,8 @@ All optional. Read at startup; list entries need an index (`__0`, `__1`, ...).
|
||||
| `Flypaper__Drip__Content` | Hold method: `Html`, `Text` or `Alternating` | `Html` |
|
||||
| `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__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`, `/SDK/…`, `/ISAPI/…`, `wp-login.php`) | `true` |
|
||||
| `TZ` | Time zone for the dashboard | UTC |
|
||||
|
||||
The defaults of the runtime settings below can also be set this way, e.g.
|
||||
@@ -38,6 +40,8 @@ general reset button removes all saved values; the hold method section has its o
|
||||
| Hold method: content (HTML filler text, random plain text, or alternating per catch) | HTML filler text |
|
||||
| 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: 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` |
|
||||
| Maximum connections overall | `1000` |
|
||||
| Maximum connections per IP | `10` |
|
||||
|
||||
@@ -5,6 +5,7 @@ using Flypaper.Core.Strategies;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Flypaper.Core;
|
||||
|
||||
@@ -20,6 +21,15 @@ public static class FlypaperCoreExtensions
|
||||
services.TryAddSingleton<IRandomSource, SystemRandomSource>();
|
||||
services.TryAddEnumerable(ServiceDescriptor.Singleton<ITarpitStrategy, HtmlDripStrategy>());
|
||||
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<TrapRunner>();
|
||||
services.TryAddSingleton<IIpEnricher, NullIpEnricher>();
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
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)
|
||||
{
|
||||
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
|
||||
{
|
||||
DripContent.Text => [TextDripStrategy.StrategyName],
|
||||
|
||||
@@ -9,6 +9,8 @@ public sealed record HoldMethodSettings(
|
||||
TimeSpan MaxDelay,
|
||||
int MinChunkSize,
|
||||
int MaxChunkSize,
|
||||
int HeadStartSize,
|
||||
bool MatchPath,
|
||||
TimeSpan MaxHoldDuration)
|
||||
{
|
||||
public double BytesPerSecond => AverageBytesPerSecond(MinDelay, MaxDelay, MinChunkSize, MaxChunkSize);
|
||||
@@ -20,6 +22,8 @@ public sealed record HoldMethodSettings(
|
||||
[SettingKeys.DripMaxDelay] = MaxDelay.ToString("c", CultureInfo.InvariantCulture),
|
||||
[SettingKeys.DripMinChunkSize] = MinChunkSize.ToString(CultureInfo.InvariantCulture),
|
||||
[SettingKeys.DripMaxChunkSize] = MaxChunkSize.ToString(CultureInfo.InvariantCulture),
|
||||
[SettingKeys.DripHeadStartSize] = HeadStartSize.ToString(CultureInfo.InvariantCulture),
|
||||
[SettingKeys.DripMatchPath] = MatchPath ? "true" : "false",
|
||||
[SettingKeys.MaxHoldDuration] = MaxHoldDuration.ToString("c", CultureInfo.InvariantCulture)
|
||||
};
|
||||
|
||||
@@ -36,6 +40,8 @@ public sealed record HoldMethodInput(
|
||||
string? MaxDelayMs,
|
||||
string? MinChunkSize,
|
||||
string? MaxChunkSize,
|
||||
string? HeadStartSize,
|
||||
bool MatchPath,
|
||||
string? MaxHoldDuration);
|
||||
|
||||
public sealed record HoldMethodParseResult(HoldMethodSettings? Settings, IReadOnlyDictionary<string, string> Errors);
|
||||
@@ -13,6 +13,7 @@ public static class RuntimeSettingsParser
|
||||
private const int MinDelayMs = 10;
|
||||
private const int MaxDelayMs = 30_000;
|
||||
private const int MaxChunkSize = 4096;
|
||||
private const int MaxHeadStartSize = 65_536;
|
||||
|
||||
public static RuntimeSettingsParseResult Parse(RuntimeSettingsInput input)
|
||||
{
|
||||
@@ -57,6 +58,7 @@ public static class RuntimeSettingsParser
|
||||
var maxDelay = ParseInt(input.MaxDelayMs, nameof(input.MaxDelayMs), MinDelayMs, MaxDelayMs, errors);
|
||||
var minChunk = ParseInt(input.MinChunkSize, nameof(input.MinChunkSize), 1, MaxChunkSize, errors);
|
||||
var maxChunk = ParseInt(input.MaxChunkSize, nameof(input.MaxChunkSize), 1, MaxChunkSize, errors);
|
||||
var headStart = ParseInt(input.HeadStartSize, nameof(input.HeadStartSize), 0, MaxHeadStartSize, errors);
|
||||
var hold = ParseTimeSpan(input.MaxHoldDuration, nameof(input.MaxHoldDuration), MinHold, MaxHold, errors);
|
||||
|
||||
if (minDelay > maxDelay)
|
||||
@@ -81,6 +83,8 @@ public static class RuntimeSettingsParser
|
||||
TimeSpan.FromMilliseconds(maxDelay!.Value),
|
||||
minChunk!.Value,
|
||||
maxChunk!.Value,
|
||||
headStart!.Value,
|
||||
input.MatchPath,
|
||||
hold!.Value),
|
||||
errors);
|
||||
}
|
||||
|
||||
@@ -12,12 +12,14 @@ public static class SettingKeys
|
||||
public const string DripMaxDelay = "Flypaper:Drip:MaxDelay";
|
||||
public const string DripMinChunkSize = "Flypaper:Drip:MinChunkSize";
|
||||
public const string DripMaxChunkSize = "Flypaper:Drip:MaxChunkSize";
|
||||
public const string DripHeadStartSize = "Flypaper:Drip:HeadStartSize";
|
||||
public const string DripMatchPath = "Flypaper:Drip:MatchPath";
|
||||
|
||||
public static readonly IReadOnlyList<string> General =
|
||||
[MaxConnections, MaxConnectionsPerIp, IgnorePrivateNetworks, RetentionDays];
|
||||
|
||||
public static readonly IReadOnlyList<string> HoldMethod =
|
||||
[DripContent, DripMinDelay, DripMaxDelay, DripMinChunkSize, DripMaxChunkSize, MaxHoldDuration];
|
||||
[DripContent, DripMinDelay, DripMaxDelay, DripMinChunkSize, DripMaxChunkSize, DripHeadStartSize, DripMatchPath, MaxHoldDuration];
|
||||
|
||||
public static readonly IReadOnlySet<string> All =
|
||||
new HashSet<string>(General.Concat(HoldMethod), StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
@@ -13,4 +13,8 @@ public sealed class DripOptions
|
||||
public int MinChunkSize { get; set; } = 1;
|
||||
|
||||
public int MaxChunkSize { get; set; } = 64;
|
||||
|
||||
public int HeadStartSize { get; set; } = 1024;
|
||||
|
||||
public bool MatchPath { get; set; } = true;
|
||||
}
|
||||
@@ -5,6 +5,25 @@ namespace Flypaper.Core.Strategies;
|
||||
|
||||
public static class DripSchedule
|
||||
{
|
||||
public static ReadOnlyMemory<byte> TakeHead(IEnumerator<string> fragments, int minBytes)
|
||||
{
|
||||
var head = new List<byte>();
|
||||
while (head.Count < minBytes && fragments.MoveNext())
|
||||
{
|
||||
head.AddRange(Encoding.UTF8.GetBytes(fragments.Current));
|
||||
}
|
||||
|
||||
return head.ToArray();
|
||||
}
|
||||
|
||||
public static IEnumerable<string> Remaining(IEnumerator<string> fragments)
|
||||
{
|
||||
while (fragments.MoveNext())
|
||||
{
|
||||
yield return fragments.Current;
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<DripStep> Create(IEnumerable<string> content, IRandomSource random, DripOptions options)
|
||||
{
|
||||
var minChunk = Math.Max(1, options.MinChunkSize);
|
||||
|
||||
@@ -19,14 +19,24 @@ public abstract class DripStrategy(
|
||||
public string Describe()
|
||||
{
|
||||
var current = options.CurrentValue;
|
||||
var head = current.HeadStartSize > 0 ? $" head {current.HeadStartSize}B" : "";
|
||||
return string.Create(
|
||||
CultureInfo.InvariantCulture,
|
||||
$"{Name} {current.MinDelay.TotalMilliseconds:0}-{current.MaxDelay.TotalMilliseconds:0}ms {current.MinChunkSize}-{current.MaxChunkSize}B");
|
||||
$"{Name} {current.MinDelay.TotalMilliseconds:0}-{current.MaxDelay.TotalMilliseconds:0}ms {current.MinChunkSize}-{current.MaxChunkSize}B{head}");
|
||||
}
|
||||
|
||||
public async Task RunAsync(ITrapChannel channel, CancellationToken ct)
|
||||
{
|
||||
foreach (var step in DripSchedule.Create(Content(random), random, options.CurrentValue))
|
||||
var current = options.CurrentValue;
|
||||
using var fragments = Content(random).GetEnumerator();
|
||||
|
||||
var head = DripSchedule.TakeHead(fragments, current.HeadStartSize);
|
||||
if (head.Length > 0)
|
||||
{
|
||||
await channel.WriteAsync(head, ct);
|
||||
}
|
||||
|
||||
foreach (var step in DripSchedule.Create(DripSchedule.Remaining(fragments), random, current))
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
await channel.WriteAsync(step.Chunk, ct);
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
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("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),
|
||||
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> WordPressLogin(IRandomSource random)
|
||||
{
|
||||
yield return """
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-US">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<title>Log In ‹ Portal — WordPress</title>
|
||||
<meta name='robots' content='max-image-preview:large, noindex, noarchive' />
|
||||
<link rel='stylesheet' id='login-css' href='/wp-admin/css/login.min.css?ver=6.4.3' media='all' />
|
||||
<meta name='viewport' content='width=device-width' />
|
||||
</head>
|
||||
<body class="login no-js login-action-login wp-core-ui locale-en-us">
|
||||
<div id="login">
|
||||
<h1><a href="https://wordpress.org/">Powered by WordPress</a></h1>
|
||||
<form name="loginform" id="loginform" action="/wp-login.php" method="post">
|
||||
<p>
|
||||
<label for="user_login">Username or Email Address</label>
|
||||
<input type="text" name="log" id="user_login" class="input" value="" size="20" autocapitalize="off" autocomplete="username" required="required" />
|
||||
</p>
|
||||
<div class="user-pass-wrap">
|
||||
<label for="user_pass">Password</label>
|
||||
<input type="password" name="pwd" id="user_pass" class="input password-input" value="" size="20" autocomplete="current-password" required="required" />
|
||||
</div>
|
||||
<p class="submit">
|
||||
<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Log In" />
|
||||
<input type="hidden" name="redirect_to" value="/wp-admin/" />
|
||||
<input type="hidden" name="testcookie" value="1" />
|
||||
</p>
|
||||
</form>
|
||||
<p id="nav"><a href="/wp-login.php?action=lostpassword">Lost your password?</a></p>
|
||||
<p id="backtoblog"><a href="/">← Go to Portal</a></p>
|
||||
</div>
|
||||
|
||||
""";
|
||||
|
||||
while (true)
|
||||
{
|
||||
yield return $"<!-- {Hex(random, 32)} -->\n";
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<string> Hikvision(IRandomSource random)
|
||||
{
|
||||
yield return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<LanguageList version=\"2.0\" xmlns=\"http://www.hikvision.com/ver20/XMLSchema\">\n";
|
||||
|
||||
var id = 1;
|
||||
while (true)
|
||||
{
|
||||
yield return $" <Language>\n <id>{id++}</id>\n <name>{LoremText.Word(random)}</name>\n <enabled>{(random.Next(0, 2) == 0 ? "true" : "false")}</enabled>\n </Language>\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(
|
||||
session,
|
||||
$"{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(
|
||||
trapContext,
|
||||
@@ -73,6 +74,7 @@ internal sealed class FlypaperMiddleware(
|
||||
var response = context.Response;
|
||||
response.StatusCode = StatusCodes.Status200OK;
|
||||
response.ContentType = strategy is IStrategyDetails details ? details.MediaType : "text/html; charset=utf-8";
|
||||
response.Headers.Server = "nginx";
|
||||
response.Headers.CacheControl = "no-store";
|
||||
response.Headers["X-Accel-Buffering"] = "no";
|
||||
await response.StartAsync(ct);
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"width":1000.0,"height":439.1,"countries":[{"code":"AF","name":"Afghanistan","path":"M669.6,108.7L671,108.7L673.1,109.4L674,109.9L675.5,108.8L676.6,109.4L677,107.9L678.5,108L678.7,107.5L678.6,106.1L679.3,104.9L680.9,105.7L681,106.7L681.8,106.9L682.4,109.7L683.8,110.8L684.5,110.1L685.5,109.8L686.6,108.3L688.4,108.5L691.1,108.5L691.8,109.5L690.5,109.9L689.4,110.5L686.6,110.9L684,111.6L683,113.1L684,114.5L684.8,116.2L683.9,117.6L684.4,119L684.1,120.2L681.6,120.1L683.2,122.4L681.8,123.3L681.2,125.4L681.9,127.5L681.1,128.4L680.1,128.1L678.2,128.6L678.1,129.5L676.2,129.5L675.2,131.5L675.8,134.5L672.6,136L670.7,135.7L670.4,136.5L668.7,136L666.1,136.5L661.3,134.7L663,131.5L662.3,129.3L660.2,128.7L659.5,126.5L658,123.7L658.7,121.8L657.4,121.3L657.6,118.8L657.5,114.5L660.5,115.8L662.3,115.4L662.5,113.8L664.4,113.3L665.5,112.3L665.3,109.6L667.2,108.9L667.3,107.7L668.8,108.6L669.6,108.7Z"},{"code":"AL","name":"Albanien","path":"M552.5,97.2L552.5,98L551.7,98.5L551.7,99.6L550.7,101.2L550.2,100.9L550.1,100.2L548.6,99.1L548.2,97.5L548.2,95.3L548.5,94.3L548,93.8L547.8,92.8L548.7,91.2L548.9,91.8L549.5,91.5L550.1,92.4L550.8,92.7L551,93.9L550.8,95L551.3,96.4L552.5,97.2Z"},{"code":"DZ","name":"Algerien","path":"M476.7,143.4L476.8,142.7L476.8,142.5L476.9,138.2L481.3,135.6L483.9,135.1L486.1,134.1L487.2,132.4L490.3,131L490.4,128.4L491.9,128.1L493.1,126.8L496.6,126.2L497.1,124.8L496.4,124.1L495.5,120.4L495.4,118.4L494.4,116.2L496.9,114.3L499.7,113.7L501.3,112.3L503.8,111.3L508.1,110.7L512.3,110.4L513.6,110.9L516,109.6L518.7,109.5L519.8,110.3L521.5,110.1L521.1,111.9L521.6,115.1L521.1,117.9L519.5,119.8L519.8,122.4L522,124.5L522.1,125.3L523.7,126.7L525.1,133L526,136.2L526.2,137.8L525.9,140.7L526.1,142.3L525.8,144.3L526.1,146.6L525.1,148.1L526.8,150.7L526.9,152.2L527.9,154.3L529.2,153.6L531.4,155.3L532.6,157.6L523.5,164.5L515.6,171.8L511.8,173.4L508.7,173.8L508.7,171.4L507.4,170.8L505.7,169.8L505,168L495.8,160L486.7,152.1L476.7,143.4Z"},{"code":"AO","name":"Angola","path":"M536.7,264L535.7,264.8L535.2,265.8L535.1,267.4L534.4,267.8L533.7,265L534.8,263.3L535.7,262.7L536.7,264ZM534.8,269L536,268.5L536.8,268.6L537.8,268.1L546.1,268.1L546.8,271L547.5,273.3L548.2,274.5L549.2,276.5L551.1,276.2L552,275.6L553.6,276.2L554,275.2L554.8,273L556.5,272.9L556.7,272.2L558.1,272.2L557.8,273.6L561.3,273.5L561.3,275.9L561.8,277.4L561.4,279.7L561.5,282L562.4,283.4L562.2,287.9L562.9,287.5L564.1,287.6L565.8,287.1L567.1,287.3L567.4,288.5L567,290.3L567.4,292.1L567,293.5L567.2,294.8L561.3,294.7L560.8,306.7L562.5,309.7L564.3,312L559.1,313.5L552.4,313L550.6,311.2L539.3,311.4L538.9,311.7L537.3,310L535.5,309.9L533.8,310.5L532.5,311.2L532.3,308.9L532.7,305.6L533.8,302.2L533.9,300.6L534.9,297.2L535.6,295.6L537.3,293.2L538.2,291.5L538.5,288.7L538.4,286.6L537.6,285.2L536.9,282.9L536.2,280.6L536.4,279.8L537.3,278.3L536.5,274.7L535.9,272.1L534.5,269.7L534.8,269Z"},{"code":"AR","name":"Argentinien","path":"M343.2,430.7L344.7,432L346.9,434.2L350.6,435.8L354.1,436.5L353.8,437.9L351.7,438.1L350.1,437.1L348.7,437L346.3,437L343.2,430.7ZM347.6,358.1L347.5,361L347.5,364.6L348.3,368L347.9,368.8L348.2,371L348.5,372.8L352.4,375.8L352.6,378.1L354.6,379.6L354.9,381.2L353.5,385.5L350.2,387.3L345.3,388L342.5,387.7L343.6,389.7L343.8,392.1L344.7,393.8L343.6,395L341.2,395.4L338.4,394.2L337.7,395.1L339.1,398.3L341.1,399.3L342.1,398.3L343.4,399.9L341.5,400.9L340.2,402.9L340.9,406.1L341,407.8L338.7,407.8L337.4,409.4L337.6,411.8L340.8,414L343.4,414.6L343.6,417.4L341.5,419.1L341.5,422.6L339.9,423.8L339.5,425.2L341.7,428.2L344,429.9L342.9,429.7L340.6,429.3L334.9,428.9L333.1,427.2L332.1,425L330.6,425.2L329.3,424.1L327.6,421L328.8,419.6L328.7,417.7L327.8,416.2L327.9,413.6L327.1,409.5L326.1,407.6L326.9,407L326.2,405.8L324.8,405.2L325.1,403.9L323.6,402.6L321.6,398.9L322.4,398.3L320.5,394.3L319.9,390.9L319.6,388L320.7,386.8L318.9,383.5L318,380.4L319.2,378.2L318.4,375.4L318.9,372L318,368.8L317.2,368.2L314.4,362.2L315.2,358.6L314.1,355.1L314.3,351.9L315.3,348.6L316.7,346.3L315.7,344.9L316,343.8L314.7,337.7L317.3,336L317.6,332.2L317.1,331.3L318.9,328L322.6,328.8L324.6,331.5L325.2,328.5L328.3,328.7L328.9,329.5L334.8,335.4L337.2,336L340.9,338.7L343.9,340.1L344.6,341.7L342.9,347.1L345.7,348.1L348.8,348.7L350.9,348.1L352.8,345.3L352.8,342.2L354,341.5L355.7,343.6L356.1,346.4L354.1,348.4L352.6,349.9L350.2,353.3L347.6,358.1Z"},{"code":"AM","name":"Armenien","path":"M617.6,104L616.7,104.1L615.2,102.2L615.1,101.7L614,101.7L613.1,100.8L612.6,100.9L611.4,99.9L609.4,99.1L609.3,97.5L608.6,96.3L611.9,95.8L612.6,96.7L613.7,97.3L613.4,98.1L615,99.2L614.5,100.3L615.8,101.2L617,101.7L617.6,104Z"},{"code":"AZ","name":"Aserbaidschan","path":"M615,93.8L615.8,94L617.9,95.9L619.1,96.2L619.3,95.3L620.5,94L622.2,95.7L624,98L625.2,98.2L626.2,99.1L624.2,99.3L624.4,101.9L624.2,103.1L623.5,103.9L623.9,105.5L623.3,105.7L621.4,103.9L621.9,102.3L620.9,101.3L620,101.6L617.6,104L617,101.7L615.8,101.2L614.5,100.3L615,99.2L613.4,98.1L613.7,97.3L612.6,96.7L611.9,95.8L612.4,95.3L614.5,96.2L615.9,96.4L616.1,96.1L614.5,94.3L615,93.8ZM616.7Line truncated
|
||||
{"width":1000.0,"height":439.1,"countries":[{"code":"AF","name":"Afghanistan","path":"M669.6,108.7L671,108.7L673.1,109.4L674,109.9L675.5,108.8L676.6,109.4L677,107.9L678.5,108L678.7,107.5L678.6,106.1L679.3,104.9L680.9,105.7L681,106.7L681.8,106.9L682.4,109.7L683.8,110.8L684.5,110.1L685.5,109.8L686.6,108.3L688.4,108.5L691.1,108.5L691.8,109.5L690.5,109.9L689.4,110.5L686.6,110.9L684,111.6L683,113.1L684,114.5L684.8,116.2L683.9,117.6L684.4,119L684.1,120.2L681.6,120.1L683.2,122.4L681.8,123.3L681.2,125.4L681.9,127.5L681.1,128.4L680.1,128.1L678.2,128.6L678.1,129.5L676.2,129.5L675.2,131.5L675.8,134.5L672.6,136L670.7,135.7L670.4,136.5L668.7,136L666.1,136.5L661.3,134.7L663,131.5L662.3,129.3L660.2,128.7L659.5,126.5L658,123.7L658.7,121.8L657.4,121.3L657.6,118.8L657.5,114.5L660.5,115.8L662.3,115.4L662.5,113.8L664.4,113.3L665.5,112.3L665.3,109.6L667.2,108.9L667.3,107.7L668.8,108.6L669.6,108.7Z"},{"code":"AL","name":"Albanien","path":"M552.5,97.2L552.5,98L551.7,98.5L551.7,99.6L550.7,101.2L550.2,100.9L550.1,100.2L548.6,99.1L548.2,97.5L548.2,95.3L548.5,94.3L548,93.8L547.8,92.8L548.7,91.2L548.9,91.8L549.5,91.5L550.1,92.4L550.8,92.7L551,93.9L550.8,95L551.3,96.4L552.5,97.2Z"},{"code":"DZ","name":"Algerien","path":"M476.7,143.4L476.8,142.7L476.8,142.5L476.9,138.2L481.3,135.6L483.9,135.1L486.1,134.1L487.2,132.4L490.3,131L490.4,128.4L491.9,128.1L493.1,126.8L496.6,126.2L497.1,124.8L496.4,124.1L495.5,120.4L495.4,118.4L494.4,116.2L496.9,114.3L499.7,113.7L501.3,112.3L503.8,111.3L508.1,110.7L512.3,110.4L513.6,110.9L516,109.6L518.7,109.5L519.8,110.3L521.5,110.1L521.1,111.9L521.6,115.1L521.1,117.9L519.5,119.8L519.8,122.4L522,124.5L522.1,125.3L523.7,126.7L525.1,133L526,136.2L526.2,137.8L525.9,140.7L526.1,142.3L525.8,144.3L526.1,146.6L525.1,148.1L526.8,150.7L526.9,152.2L527.9,154.3L529.2,153.6L531.4,155.3L532.6,157.6L523.5,164.5L515.6,171.8L511.8,173.4L508.7,173.8L508.7,171.4L507.4,170.8L505.7,169.8L505,168L495.8,160L486.7,152.1L476.7,143.4Z"},{"code":"AO","name":"Angola","path":"M536.7,264L535.7,264.8L535.2,265.8L535.1,267.4L534.4,267.8L533.7,265L534.8,263.3L535.7,262.7L536.7,264ZM534.8,269L536,268.5L536.8,268.6L537.8,268.1L546.1,268.1L546.8,271L547.5,273.3L548.2,274.5L549.2,276.5L551.1,276.2L552,275.6L553.6,276.2L554,275.2L554.8,273L556.5,272.9L556.7,272.2L558.1,272.2L557.8,273.6L561.3,273.5L561.3,275.9L561.8,277.4L561.4,279.7L561.5,282L562.4,283.4L562.2,287.9L562.9,287.5L564.1,287.6L565.8,287.1L567.1,287.3L567.4,288.5L567,290.3L567.4,292.1L567,293.5L567.2,294.8L561.3,294.7L560.8,306.7L562.5,309.7L564.3,312L559.1,313.5L552.4,313L550.6,311.2L539.3,311.4L538.9,311.7L537.3,310L535.5,309.9L533.8,310.5L532.5,311.2L532.3,308.9L532.7,305.6L533.8,302.2L533.9,300.6L534.9,297.2L535.6,295.6L537.3,293.2L538.2,291.5L538.5,288.7L538.4,286.6L537.6,285.2L536.9,282.9L536.2,280.6L536.4,279.8L537.3,278.3L536.5,274.7L535.9,272.1L534.5,269.7L534.8,269Z"},{"code":"AR","name":"Argentinien","path":"M343.2,430.7L344.7,432L346.9,434.2L350.6,435.8L354.1,436.5L353.8,437.9L351.7,438.1L350.1,437.1L348.7,437L346.3,437L343.2,430.7ZM347.6,358.1L347.5,361L347.5,364.6L348.3,368L347.9,368.8L348.2,371L348.5,372.8L352.4,375.8L352.6,378.1L354.6,379.6L354.9,381.2L353.5,385.5L350.2,387.3L345.3,388L342.5,387.7L343.6,389.7L343.8,392.1L344.7,393.8L343.6,395L341.2,395.4L338.4,394.2L337.7,395.1L339.1,398.3L341.1,399.3L342.1,398.3L343.4,399.9L341.5,400.9L340.2,402.9L340.9,406.1L341,407.8L338.7,407.8L337.4,409.4L337.6,411.8L340.8,414L343.4,414.6L343.6,417.4L341.5,419.1L341.5,422.6L339.9,423.8L339.5,425.2L341.7,428.2L344,429.9L342.9,429.7L340.6,429.3L334.9,428.9L333.1,427.2L332.1,425L330.6,425.2L329.3,424.1L327.6,421L328.8,419.6L328.7,417.7L327.8,416.2L327.9,413.6L327.1,409.5L326.1,407.6L326.9,407L326.2,405.8L324.8,405.2L325.1,403.9L323.6,402.6L321.6,398.9L322.4,398.3L320.5,394.3L319.9,390.9L319.6,388L320.7,386.8L318.9,383.5L318,380.4L319.2,378.2L318.4,375.4L318.9,372L318,368.8L317.2,368.2L314.4,362.2L315.2,358.6L314.1,355.1L314.3,351.9L315.3,348.6L316.7,346.3L315.7,344.9L316,343.8L314.7,337.7L317.3,336L317.6,332.2L317.1,331.3L318.9,328L322.6,328.8L324.6,331.5L325.2,328.5L328.3,328.7L328.9,329.5L334.8,335.4L337.2,336L340.9,338.7L343.9,340.1L344.6,341.7L342.9,347.1L345.7,348.1L348.8,348.7L350.9,348.1L352.8,345.3L352.8,342.2L354,341.5L355.7,343.6L356.1,346.4L354.1,348.4L352.6,349.9L350.2,353.3L347.6,358.1Z"},{"code":"AM","name":"Armenien","path":"M617.6,104L616.7,104.1L615.2,102.2L615.1,101.7L614,101.7L613.1,100.8L612.6,100.9L611.4,99.9L609.4,99.1L609.3,97.5L608.6,96.3L611.9,95.8L612.6,96.7L613.7,97.3L613.4,98.1L615,99.2L614.5,100.3L615.8,101.2L617,101.7L617.6,104Z"},{"code":"AZ","name":"Aserbaidschan","path":"M615,93.8L615.8,94L617.9,95.9L619.1,96.2L619.3,95.3L620.5,94L622.2,95.7L624,98L625.2,98.2L626.2,99.1L624.2,99.3L624.4,101.9L624.2,103.1L623.5,103.9L623.9,105.5L623.3,105.7L621.4,103.9L621.9,102.3L620.9,101.3L620,101.6L617.6,104L617,101.7L615.8,101.2L614.5,100.3L615,99.2L613.4,98.1L613.7,97.3L612.6,96.7L611.9,95.8L612.4,95.3L614.5,96.2L615.9,96.4L616.1,96.1L614.5,94.3L615,93.8ZM616.7Line truncated
|
||||
@@ -12,5 +12,9 @@ public sealed class HoldMethodModel
|
||||
|
||||
public string? MaxChunkSize { get; set; }
|
||||
|
||||
public string? HeadStartSize { get; set; }
|
||||
|
||||
public bool MatchPath { get; set; }
|
||||
|
||||
public string? MaxHoldDuration { get; set; }
|
||||
}
|
||||
@@ -56,11 +56,22 @@
|
||||
<SettingsField Label="Paket max." For="drip-max-chunk" Unit="Bytes" Hint="Zufällig zwischen min. und max." Errors="_errors" Key="@nameof(HoldMethodModel.MaxChunkSize)">
|
||||
<InputText id="drip-max-chunk" @bind-Value="Model!.MaxChunkSize" inputmode="numeric" data-bandwidth-input />
|
||||
</SettingsField>
|
||||
<SettingsField Label="Schneller Start" For="drip-head-start" Unit="Bytes" Hint="0 bis 65536, sofort ohne Pause gesendet" Errors="_errors" Key="@nameof(HoldMethodModel.HeadStartSize)">
|
||||
<InputText id="drip-head-start" @bind-Value="Model!.HeadStartSize" inputmode="numeric" />
|
||||
</SettingsField>
|
||||
<SettingsField Label="Maximale Haltedauer" For="hold" Hint="hh:mm:ss, höchstens 7 Tage" Errors="_errors" Key="@nameof(HoldMethodModel.MaxHoldDuration)">
|
||||
<InputText id="hold" @bind-Value="Model!.MaxHoldDuration" />
|
||||
</SettingsField>
|
||||
</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">
|
||||
<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>
|
||||
@@ -125,6 +136,8 @@
|
||||
Model.MaxDelayMs,
|
||||
Model.MinChunkSize,
|
||||
Model.MaxChunkSize,
|
||||
Model.HeadStartSize,
|
||||
Model.MatchPath,
|
||||
Model.MaxHoldDuration));
|
||||
|
||||
if (result.Settings is null)
|
||||
@@ -153,6 +166,8 @@
|
||||
MaxDelayMs = ((int)drip.MaxDelay.TotalMilliseconds).ToString(CultureInfo.InvariantCulture),
|
||||
MinChunkSize = drip.MinChunkSize.ToString(CultureInfo.InvariantCulture),
|
||||
MaxChunkSize = drip.MaxChunkSize.ToString(CultureInfo.InvariantCulture),
|
||||
HeadStartSize = drip.HeadStartSize.ToString(CultureInfo.InvariantCulture),
|
||||
MatchPath = drip.MatchPath,
|
||||
MaxHoldDuration = Core.CurrentValue.MaxHoldDuration.ToString("c", CultureInfo.InvariantCulture)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
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")]
|
||||
[InlineData("/SDK/webLanguage", "hikvision-drip")]
|
||||
[InlineData("/ISAPI/System/deviceInfo", "hikvision-drip")]
|
||||
[InlineData("/wp-login.php", "wordpress-drip")]
|
||||
[InlineData("/blog/WP-Login.php", "wordpress-drip")]
|
||||
public void Matches_known_paths(string path, string expected) =>
|
||||
FileContent.Match(path).ShouldNotBeNull().Name.ShouldBe(expected);
|
||||
|
||||
[Theory]
|
||||
[InlineData("/")]
|
||||
[InlineData("/index.php")]
|
||||
[InlineData("/sdkfoo")]
|
||||
[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:")]
|
||||
[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)
|
||||
{
|
||||
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
|
||||
{
|
||||
private static readonly HoldMethodInput Valid = new("Alternating", "50", "1000", "1", "64", "01:00:00");
|
||||
private static readonly HoldMethodInput Valid = new("Alternating", "50", "1000", "1", "64", "2048", true, "01:00:00");
|
||||
|
||||
[Fact]
|
||||
public void Parses_valid_input()
|
||||
@@ -18,6 +18,8 @@ public sealed class HoldMethodParserTests
|
||||
settings.MaxDelay.ShouldBe(TimeSpan.FromSeconds(1));
|
||||
settings.MinChunkSize.ShouldBe(1);
|
||||
settings.MaxChunkSize.ShouldBe(64);
|
||||
settings.HeadStartSize.ShouldBe(2048);
|
||||
settings.MatchPath.ShouldBeTrue();
|
||||
settings.MaxHoldDuration.ShouldBe(TimeSpan.FromHours(1));
|
||||
settings.ToConfiguration().Keys.ShouldBe(SettingKeys.HoldMethod, ignoreOrder: true);
|
||||
}
|
||||
@@ -56,6 +58,19 @@ public sealed class HoldMethodParserTests
|
||||
errors.Keys.ShouldBe([nameof(HoldMethodInput.MaxDelayMs), nameof(HoldMethodInput.MaxChunkSize)], ignoreOrder: true);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("0")]
|
||||
[InlineData("65536")]
|
||||
public void Accepts_head_start_bounds(string value) =>
|
||||
RuntimeSettingsParser.ParseHoldMethod(Valid with { HeadStartSize = value }).Settings.ShouldNotBeNull();
|
||||
|
||||
[Theory]
|
||||
[InlineData("-1")]
|
||||
[InlineData("65537")]
|
||||
[InlineData("")]
|
||||
public void Rejects_head_start_out_of_range(string value) =>
|
||||
RuntimeSettingsParser.ParseHoldMethod(Valid with { HeadStartSize = value }).Errors.Keys.ShouldBe([nameof(HoldMethodInput.HeadStartSize)]);
|
||||
|
||||
[Theory]
|
||||
[InlineData("10")]
|
||||
[InlineData("00:00:00")]
|
||||
|
||||
@@ -22,6 +22,46 @@ public sealed class HtmlDripStrategyTests
|
||||
Encoding.UTF8.GetString(channel.Writes.SelectMany(write => write).ToArray()).ShouldStartWith("<!doctype html>");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Sends_head_start_without_delay_before_dripping()
|
||||
{
|
||||
var options = new DripOptions { MinDelay = TimeSpan.FromSeconds(30), MaxDelay = TimeSpan.FromSeconds(30), HeadStartSize = 1024 };
|
||||
var strategy = new HtmlDripStrategy(TestOptions.Monitor(options), new SeededRandomSource(21), TimeProvider.System);
|
||||
var channel = new FakeTrapChannel();
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(200));
|
||||
|
||||
await Should.ThrowAsync<OperationCanceledException>(() => strategy.RunAsync(channel, cts.Token));
|
||||
|
||||
channel.Writes.Count.ShouldBe(2);
|
||||
var head = channel.Writes.First();
|
||||
head.Length.ShouldBeGreaterThanOrEqualTo(1024);
|
||||
Encoding.UTF8.GetString(head).ShouldStartWith("<!doctype html>");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Skips_head_start_when_disabled()
|
||||
{
|
||||
var options = new DripOptions { MinDelay = TimeSpan.FromSeconds(30), MaxDelay = TimeSpan.FromSeconds(30), HeadStartSize = 0 };
|
||||
var strategy = new HtmlDripStrategy(TestOptions.Monitor(options), new SeededRandomSource(21), TimeProvider.System);
|
||||
var channel = new FakeTrapChannel();
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(200));
|
||||
|
||||
await Should.ThrowAsync<OperationCanceledException>(() => strategy.RunAsync(channel, cts.Token));
|
||||
|
||||
channel.Writes.Count.ShouldBe(1);
|
||||
channel.Writes.First().Length.ShouldBeLessThanOrEqualTo(64);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1024, "html-drip 5-10ms 1-64B head 1024B")]
|
||||
[InlineData(0, "html-drip 5-10ms 1-64B")]
|
||||
public void Describe_marks_the_head_start_variant(int headStart, string expected)
|
||||
{
|
||||
var options = new DripOptions { MinDelay = TimeSpan.FromMilliseconds(5), MaxDelay = TimeSpan.FromMilliseconds(10), HeadStartSize = headStart };
|
||||
|
||||
new HtmlDripStrategy(TestOptions.Monitor(options), new SeededRandomSource(1), TimeProvider.System).Describe().ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(TrapProtocol.Http, true)]
|
||||
[InlineData(TrapProtocol.Ssh, false)]
|
||||
@@ -29,7 +69,7 @@ public sealed class HtmlDripStrategyTests
|
||||
CreateStrategy().Supports(protocol).ShouldBe(expected);
|
||||
|
||||
private static HtmlDripStrategy CreateStrategy() => new(
|
||||
TestOptions.Monitor(new DripOptions { MinDelay = TimeSpan.FromMilliseconds(1), MaxDelay = TimeSpan.FromMilliseconds(5) }),
|
||||
TestOptions.Monitor(new DripOptions { MinDelay = TimeSpan.FromMilliseconds(1), MaxDelay = TimeSpan.FromMilliseconds(5), HeadStartSize = 0 }),
|
||||
new SeededRandomSource(21),
|
||||
TimeProvider.System);
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public sealed class StrategySelectionTests
|
||||
var options = TestOptions.Monitor(new DripOptions { MinDelay = TimeSpan.FromMilliseconds(100), MaxDelay = TimeSpan.FromMilliseconds(250), MinChunkSize = 2, MaxChunkSize = 8 });
|
||||
var text = new TextDripStrategy(options, new SeededRandomSource(1), TimeProvider.System);
|
||||
|
||||
text.Describe().ShouldBe("text-drip 100-250ms 2-8B");
|
||||
text.Describe().ShouldBe("text-drip 100-250ms 2-8B head 1024B");
|
||||
text.MediaType.ShouldStartWith("text/plain");
|
||||
new HtmlDripStrategy(options, new SeededRandomSource(1), TimeProvider.System).MediaType.ShouldStartWith("text/html");
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public sealed class TrapRunnerTests
|
||||
var outcome = await CreateRunner(TimeSpan.FromMinutes(1)).RunAsync(Context(), Open, cts.Token);
|
||||
|
||||
outcome.ShouldBe(TrapOutcome.ClientAborted);
|
||||
_sink.Received(1).Publish(Arg.Is<TrapEvent>(e => e.Outcome == TrapOutcome.ClientAborted && e.Strategy == "html-drip 5-20ms 1-64B"));
|
||||
_sink.Received(1).Publish(Arg.Is<TrapEvent>(e => e.Outcome == TrapOutcome.ClientAborted && e.Strategy == "html-drip 5-20ms 1-64B head 1024B"));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
||||
@@ -14,9 +14,14 @@ namespace Flypaper.Tests.Http;
|
||||
public sealed class ContentTypeTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("Html", "text/html; 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", "/", "text/html; charset=utf-8")]
|
||||
[InlineData("Text", "/", "text/plain; charset=utf-8")]
|
||||
[InlineData("Html", "/config.json", "application/json")]
|
||||
[InlineData("Html", "/.env", "text/plain; charset=utf-8")]
|
||||
[InlineData("Html", "/sitemap.xml", "application/xml")]
|
||||
[InlineData("Html", "/SDK/webLanguage", "application/xml")]
|
||||
[InlineData("Html", "/wp-login.php", "text/html; charset=UTF-8")]
|
||||
public async Task Trap_answers_with_the_media_type_of_the_selected_strategy(string content, string path, string expected)
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(new Dictionary<string, string?>
|
||||
@@ -39,11 +44,13 @@ public sealed class ContentTypeTests
|
||||
var context = new DefaultHttpContext { RequestServices = services };
|
||||
context.Connection.RemoteIpAddress = IPAddress.Parse("203.0.113.9");
|
||||
context.Connection.LocalPort = 8080;
|
||||
context.Request.Path = "/";
|
||||
context.Request.Path = path;
|
||||
|
||||
await app.Build()(context);
|
||||
|
||||
context.Response.StatusCode.ShouldBe(StatusCodes.Status200OK);
|
||||
context.Response.ContentType.ShouldBe(expected);
|
||||
context.Response.Headers.Server.ToString().ShouldBe("nginx");
|
||||
context.Response.ContentLength.ShouldBeNull();
|
||||
}
|
||||
}
|
||||
@@ -89,12 +89,14 @@ public sealed class SettingsOverrideTests : IDisposable
|
||||
var store = host.Services.GetRequiredService<RuntimeSettingsStore>();
|
||||
string[] holdKeys = [.. SettingKeys.HoldMethod];
|
||||
|
||||
await store.SaveAsync(new HoldMethodSettings(DripContent.Text, TimeSpan.FromMilliseconds(200), TimeSpan.FromSeconds(2), 8, 16, 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));
|
||||
|
||||
drip.CurrentValue.Content.ShouldBe(DripContent.Text);
|
||||
drip.CurrentValue.MinDelay.ShouldBe(TimeSpan.FromMilliseconds(200));
|
||||
drip.CurrentValue.MaxChunkSize.ShouldBe(16);
|
||||
drip.CurrentValue.HeadStartSize.ShouldBe(256);
|
||||
drip.CurrentValue.MatchPath.ShouldBeFalse();
|
||||
core.CurrentValue.MaxHoldDuration.ShouldBe(TimeSpan.FromMinutes(5));
|
||||
core.CurrentValue.MaxConnections.ShouldBe(50);
|
||||
(await store.HasOverridesAsync(holdKeys)).ShouldBeTrue();
|
||||
|
||||
@@ -38,14 +38,23 @@ public sealed class WorldMapDataTests
|
||||
public void Small_bot_heavy_countries_have_markers(string code) =>
|
||||
_map.Markers.ShouldContain(m => m.Code == code);
|
||||
|
||||
[Fact]
|
||||
public void No_country_has_both_a_polygon_and_a_marker()
|
||||
[Theory]
|
||||
[InlineData("IL")]
|
||||
[InlineData("LB")]
|
||||
[InlineData("PS")]
|
||||
[InlineData("KW")]
|
||||
[InlineData("QA")]
|
||||
[InlineData("NL")]
|
||||
public void Tiny_countries_with_a_polygon_also_have_a_marker(string code)
|
||||
{
|
||||
var polygons = _map.Countries.Select(c => c.Code).OfType<string>().ToHashSet();
|
||||
|
||||
_map.Markers.Where(m => polygons.Contains(m.Code)).ShouldBeEmpty();
|
||||
_map.Countries.ShouldContain(c => c.Code == code);
|
||||
_map.Markers.ShouldContain(m => m.Code == code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Markers_are_unique_per_country() =>
|
||||
_map.Markers.Select(m => m.Code).ShouldBeUnique();
|
||||
|
||||
[Fact]
|
||||
public void Markers_lie_inside_the_map() =>
|
||||
_map.Markers.ShouldAllBe(m => m.X >= 0 && m.X <= _map.Width && m.Y >= 0 && m.Y <= _map.Height);
|
||||
|
||||
Reference in new issue
Block a user