Put signposts back into the trap into the fake files
.env, JSON, YAML, SQL and Git config carry URLs marked with the serving catch, so a later request shows where the address came from. MCP exposes the marker. Switch: Flypaper__Drip__Signposts. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7c11bf211e
commit
302b40c172
14 files changed
+199
-27
No files matched your search
@@ -18,6 +18,8 @@ public sealed class DripOptions
|
||||
|
||||
public int LinkSpacing { get; set; } = 160;
|
||||
|
||||
public bool Signposts { get; set; } = true;
|
||||
|
||||
public bool Lure { get; set; } = true;
|
||||
|
||||
public string BaitPaths { get; set; } = Strategies.BaitPaths.Default;
|
||||
|
||||
@@ -7,20 +7,20 @@ public sealed record FileProfile(
|
||||
string Name,
|
||||
string MediaType,
|
||||
Func<string, bool> Matches,
|
||||
Func<IRandomSource, IEnumerable<string>> Generate);
|
||||
Func<IRandomSource, SignpostLinks?, IEnumerable<string>> Generate);
|
||||
|
||||
public static class FileContent
|
||||
{
|
||||
public static readonly IReadOnlyList<FileProfile> Profiles =
|
||||
[
|
||||
new("git-drip", "text/plain; charset=utf-8", IsGit, GitConfig),
|
||||
new("svn-drip", "text/plain; charset=utf-8", path => IsInside(path, "/.svn"), Svn),
|
||||
new("hg-drip", "text/plain; charset=utf-8", path => IsInside(path, "/.hg"), Mercurial),
|
||||
new("wordpress-drip", "text/html; charset=UTF-8", path => LastSegment(path) == "wp-login.php", WordPressLogin),
|
||||
new("hikvision-drip", "application/xml", path => path.StartsWith("/sdk/", StringComparison.Ordinal) || path.StartsWith("/isapi/", StringComparison.Ordinal), Hikvision),
|
||||
new("svn-drip", "text/plain; charset=utf-8", path => IsInside(path, "/.svn"), (random, _) => Svn(random)),
|
||||
new("hg-drip", "text/plain; charset=utf-8", path => IsInside(path, "/.hg"), (random, _) => Mercurial(random)),
|
||||
new("wordpress-drip", "text/html; charset=UTF-8", path => LastSegment(path) == "wp-login.php", (random, _) => WordPressLogin(random)),
|
||||
new("hikvision-drip", "application/xml", path => path.StartsWith("/sdk/", StringComparison.Ordinal) || path.StartsWith("/isapi/", StringComparison.Ordinal), (random, _) => Hikvision(random)),
|
||||
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("xml-drip", "application/xml", path => path.EndsWith(".xml", StringComparison.Ordinal), (random, _) => Xml(random)),
|
||||
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)
|
||||
];
|
||||
@@ -46,10 +46,13 @@ public static class FileContent
|
||||
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)
|
||||
private static IEnumerable<string> Env(IRandomSource random, SignpostLinks? links)
|
||||
{
|
||||
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";
|
||||
var appUrl = links is { BaseUrl.Length: > 0 } ? links.BaseUrl : "https://example.com";
|
||||
var signposts = links is null ? "" : $"BACKUP_URL={links.Backup}\nADMIN_URL={links.Admin}\nCONFIG_URL={links.Settings}\n\n";
|
||||
yield return $"APP_NAME=Portal\nAPP_ENV=production\nAPP_DEBUG=false\nAPP_URL={appUrl}\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"
|
||||
+ signposts;
|
||||
|
||||
while (true)
|
||||
{
|
||||
@@ -117,9 +120,10 @@ public static class FileContent
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<string> Json(IRandomSource random)
|
||||
private static IEnumerable<string> Json(IRandomSource random, SignpostLinks? links)
|
||||
{
|
||||
yield return "{\n \"name\": \"portal\",\n \"version\": \"1.4.2\",\n \"private\": true,\n \"entries\": [\n";
|
||||
var signposts = links is null ? "" : $" \"backup_url\": \"{links.Backup}\",\n \"api_base\": \"{links.Settings}\",\n";
|
||||
yield return "{\n \"name\": \"portal\",\n \"version\": \"1.4.2\",\n \"private\": true,\n" + signposts + " \"entries\": [\n";
|
||||
|
||||
var id = 1;
|
||||
while (true)
|
||||
@@ -139,9 +143,10 @@ public static class FileContent
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<string> Yaml(IRandomSource random)
|
||||
private static IEnumerable<string> Yaml(IRandomSource random, SignpostLinks? links)
|
||||
{
|
||||
yield return "version: \"3.8\"\nservices:\n";
|
||||
var signposts = links is null ? "" : $"x-backup:\n backup_url: {links.Backup}\n api_base: {links.Settings}\n";
|
||||
yield return "version: \"3.8\"\n" + signposts + "services:\n";
|
||||
|
||||
while (true)
|
||||
{
|
||||
@@ -149,9 +154,10 @@ public static class FileContent
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<string> Sql(IRandomSource random)
|
||||
private static IEnumerable<string> Sql(IRandomSource random, SignpostLinks? links)
|
||||
{
|
||||
yield return "-- MySQL dump 10.13 Distrib 8.0.36, for Linux (x86_64)\n--\n-- Host: localhost Database: app\n-- ------------------------------------------------------\n\n"
|
||||
var signpost = links is null ? "" : $"-- Previous full dump: {links.Backup}\n";
|
||||
yield return "-- MySQL dump 10.13 Distrib 8.0.36, for Linux (x86_64)\n--\n-- Host: localhost Database: app\n" + signpost + "-- ------------------------------------------------------\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";
|
||||
|
||||
@@ -162,10 +168,11 @@ public static class FileContent
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GitConfig(IRandomSource random)
|
||||
private static IEnumerable<string> GitConfig(IRandomSource random, SignpostLinks? links)
|
||||
{
|
||||
var remote = links?.Repository ?? "https://example.com/portal.git";
|
||||
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";
|
||||
+ $"[remote \"origin\"]\n\turl = {remote}\n\tfetch = +refs/heads/*:refs/remotes/origin/*\n";
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
||||
@@ -13,5 +13,6 @@ public sealed class FileDripStrategy(
|
||||
|
||||
public override string MediaType => profile.MediaType;
|
||||
|
||||
protected override IEnumerable<string> Content(IRandomSource random, ITrapChannel channel, DripOptions options) => profile.Generate(random);
|
||||
protected override IEnumerable<string> Content(IRandomSource random, ITrapChannel channel, DripOptions options) =>
|
||||
profile.Generate(random, options.Signposts ? SignpostLinks.For(channel) : null);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Flypaper.Core.Abstractions;
|
||||
|
||||
namespace Flypaper.Core.Strategies;
|
||||
|
||||
public sealed partial record SignpostLinks(string BaseUrl, string Marker)
|
||||
{
|
||||
public const int MarkerLength = 12;
|
||||
|
||||
public string Backup => $"{BaseUrl}/backup/db-{Marker}.sql";
|
||||
|
||||
public string Admin => $"{BaseUrl}/admin-{Marker}/";
|
||||
|
||||
public string Settings => $"{BaseUrl}/storage/settings-{Marker}.json";
|
||||
|
||||
public string Repository => $"{BaseUrl}/git-{Marker}/portal.git";
|
||||
|
||||
public static string MarkerOf(Guid sessionId) => sessionId.ToString("N")[..MarkerLength];
|
||||
|
||||
public static SignpostLinks For(ITrapChannel channel)
|
||||
{
|
||||
var baseUrl = channel.Host is { } host && HostPattern().IsMatch(host) ? $"http://{host}" : "";
|
||||
return new SignpostLinks(baseUrl, MarkerOf(channel.Session.Id));
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"^[A-Za-z0-9.-]{1,253}\z")]
|
||||
private static partial Regex HostPattern();
|
||||
}
|
||||
Reference in new issue
Block a user