-
-
Save key-moon/3b0bc54e3ec66b9b8fb5f5a1a50d7256 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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