diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fa8a93..ee2a442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ All notable changes to Flypaper are documented in this file. The format follows ### 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` + `/.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 diff --git a/docs/configuration.md b/docs/configuration.md index 46abc86..7c1fd01 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -24,7 +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__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`) | `true` | +| `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. diff --git a/src/Flypaper.Core/Strategies/FileContent.cs b/src/Flypaper.Core/Strategies/FileContent.cs index 7b56517..43d4cac 100644 --- a/src/Flypaper.Core/Strategies/FileContent.cs +++ b/src/Flypaper.Core/Strategies/FileContent.cs @@ -17,6 +17,8 @@ public static class FileContent [ 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), @@ -58,6 +60,59 @@ public static class FileContent } } + private static IEnumerable WordPressLogin(IRandomSource random) + { + yield return """ + + + + + Log In ‹ Portal — WordPress + + + + + +
+

Powered by WordPress

+
+

+ + +

+
+ + +
+

+ + + +

+
+ +

← Go to Portal

+
+ + """; + + while (true) + { + yield return $"\n"; + } + } + + private static IEnumerable Hikvision(IRandomSource random) + { + yield return "\n\n"; + + var id = 1; + while (true) + { + yield return $" \n {id++}\n {LoremText.Word(random)}\n {(random.Next(0, 2) == 0 ? "true" : "false")}\n \n"; + } + } + private static IEnumerable Json(IRandomSource random) { yield return "{\n \"name\": \"portal\",\n \"version\": \"1.4.2\",\n \"private\": true,\n \"entries\": [\n"; diff --git a/test/Flypaper.Tests/Core/FileContentTests.cs b/test/Flypaper.Tests/Core/FileContentTests.cs index 7ade7fb..05c7000 100644 --- a/test/Flypaper.Tests/Core/FileContentTests.cs +++ b/test/Flypaper.Tests/Core/FileContentTests.cs @@ -19,13 +19,17 @@ public sealed class FileContentTests [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("/wp-login.php")] + [InlineData("/sdkfoo")] [InlineData("/environment")] [InlineData("")] [InlineData(null)] @@ -39,6 +43,8 @@ public sealed class FileContentTests [InlineData("/dump.sql", "-- MySQL dump")] [InlineData("/.git/config", "[core]")] [InlineData("/robots.txt", "User-agent:")] + [InlineData("/SDK/webLanguage", "")] public void Generates_an_endless_file_that_starts_like_the_real_thing(string path, string start) { var profile = FileContent.Match(path).ShouldNotBeNull(); diff --git a/test/Flypaper.Tests/Http/ContentTypeTests.cs b/test/Flypaper.Tests/Http/ContentTypeTests.cs index 206fe6c..1363823 100644 --- a/test/Flypaper.Tests/Http/ContentTypeTests.cs +++ b/test/Flypaper.Tests/Http/ContentTypeTests.cs @@ -19,6 +19,8 @@ public sealed class ContentTypeTests [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()