Skip to content

Instantly share code, notes, and snippets.

@key-moon
Created October 3, 2018 18:24
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/32e9e440652384135897e8d8a11cc967 to your computer and use it in GitHub Desktop.
Save key-moon/32e9e440652384135897e8d8a11cc967 to your computer and use it in GitHub Desktop.
static void Main()
{
string flagCand = "_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ{}. !\"#$%&()=~`+*<>?-^\\@[;:],./";
Console.WriteLine(GetFlagHash(0));
string placeHolder = "ifying code is: ";
string flag = "picoCTF{@g3nt6_1$_th3_c00l3$t_8220250}";
for (int i = flag.Length + 1; i < 41; i++)
{
Console.WriteLine($"{i}番目の文字を取得します");
string hash = GetFlagHash(i);
Debug.WriteLine($"{i} : {hash}");
foreach (var c in flagCand)
{
string plane = (placeHolder + flag + c.ToString()).Substring((placeHolder + flag).Length - 16 + 1);
Console.WriteLine($"GetHash({plane})");
string h = GetHash(plane);
Debug.WriteLine($"{plane} : {h}");
if (h == hash)
{
Console.WriteLine($"{i}番目の文字は : {c}");
flag += c;
goto end;
}
}
Console.WriteLine("対応する文字が一つも見つかりませんでした。");
end:;
}
}
static string GetFlagHash(int end)
{
return GetAESString("".PadLeft(44 - end, '_'))[7];
}
static string GetHash(string s)
{
if (s.Length != 16) throw new ArgumentException();
return GetAESString($"___________{s}_")[4];
}
static string[] GetAESString(string s)
{
var stream = new TCPStream("2018shell2.picoctf.com", 30399, Encoding.ASCII);
stream.ReadToEnd();
stream.ReadToEnd();
stream.WriteLine(s);
string res = stream.ReadToEnd();
List<string> spl = new List<string>();
for (int i = 0; i < res.Length; i += 32)
{
spl.Add(res.Substring(i, 16));
}
return spl.ToArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment