Skip to content

Instantly share code, notes, and snippets.

@key-moon
Created April 10, 2019 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save key-moon/3b0bc54e3ec66b9b8fb5f5a1a50d7256 to your computer and use it in GitHub Desktop.
Save key-moon/3b0bc54e3ec66b9b8fb5f5a1a50d7256 to your computer and use it in GitHub Desktop.
static void Main()
{
var first = "/4b043a01-a4b7-4141-8a99-fc94fe7e3778.html";
Dictionary<string, int> ids = new Dictionary<string, int>();
Queue<string> queue = new Queue<string>();
ids.Add(first, 0);
queue.Enqueue(first);
while (queue.Count > 0)
{
var item = queue.Dequeue();
var id = ids[item];
HttpClient client = new HttpClient();
var res = client.SendAsync(new HttpRequestMessage(HttpMethod.Get, $"https://moar_horse_2.tjctf.org{item}")).Result;
var content = res.Content.ReadAsStringAsync().Result;
if (!Validate(content))
{
Console.WriteLine(content);
}
var links = Regex.Matches(content, "<a.*/a>").Cast<Match>().Select(x => x.Value.Split('"')[1]).ToArray();
foreach (var link in links)
{
if (!ids.ContainsKey(link))
{
ids.Add(link, ids.Count);
queue.Enqueue(link);
}
Console.WriteLine($"{id}->{ids[link]};");
}
}
}
static bool Validate(string content)
{
const string pattern = "^<html><head><linkhref=\"/style\\.css\"rel=\"stylesheet\"></head><body><divclass=\"jumbotrontext-center\"><divclass=\"container\"><h1>WelcometoFlagFinding!</h1></div></div><divclass=\"container\"><divclass=\"row\"><divclass=\"col-xs-6\"><ahref=\"/.{36}\\.html\"class=\"btnbtn-smanimated-buttongibson-one\">Backward</a></div><divclass=\"col-xs-6\"><ahref=\"/.{36}\\.html\"class=\"btnbtn-smanimated-buttongibson-two\">Forward</a></div></div></div></body></html>$";
return Regex.IsMatch(content.Replace(" ", "").Replace("\n", ""), pattern);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment