using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { // "hackim19{Get_Hard_In_Dynamic_Reversing_ASAP_brace_me_then_you_trace_me}"; private static string TheString =""; static void Main(string[] args) { //test(); //return; TheString = args[0]; while (true) { Console.WriteLine("TheString:"+ TheString); string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789{}_.,-!?"; //string letters = "abcdefghijklmnopqrstuvwxyz0123456789_}"; StringBuilder sb = new StringBuilder(); sb.Append("#!/bin/sh\n"); sb.Append("rm test.txt\n"); for (int i = 0; i < letters.Length; i++) sb.Append("python3 fri.py " + TheString + letters[i] + "\n"); File.WriteAllText(@"/work/do.sh", sb.ToString()); /* do.sh looks like this: #!/bin/sh rm test.txt python3 fri.py hackim19{Get_Hard_In_Dynamic_Reversing_AAA python3 fri.py hackim19{Get_Hard_In_Dynamic_Reversing_AAB python3 fri.py hackim19{Get_Hard_In_Dynamic_Reversing_AAC */ ExecuteBashCommand(@"/work/do.sh"); /* test.txt looks like this 139036 hackim19{Get_Hard_In_Dynamic_Reversing_AAA 139143 hackim19{Get_Hard_In_Dynamic_Reversing_AAB 139134 hackim19{Get_Hard_In_Dynamic_Reversing_AAC */ var lines = File.ReadAllLines("/work/test.txt").OrderBy(i=>i).ToArray(); List> arr = new List>(); foreach (string line in lines) { string[] s = line.Split(" ".ToArray()); if (s.Length == 2 && s[0].Length > 0) { Console.WriteLine(":" + s[0] + ":" + s[1]); arr.Add(new Tuple(int.Parse(s[0]), s[1])); } } var best = arr.OrderBy(i => i.Item1).First(); //Sort and take best foreach (var i in arr) File.AppendAllText("Paths.txt",i.Item1 + i.Item2+"\n"); //Some trace for later TheString += best.Item2.Substring(best.Item2.Length - 1); } } static void test() { for (int i = 8; i < TheString.Length - 1; i++) { for (int ch = 32; ch < 128; ch++) { if (ch == 39) continue; string str = TheString.Substring(0, i) + Encoding.ASCII.GetString(new byte[] { (byte)ch }) + TheString.Substring(i + 1); string result = ExecuteBashCommand("echo '" + str + "' | /work/dist"); Console.WriteLine(str + ":" + result); if (!result.Contains("0")) return; } } } /* static void test() { for (int i = 9; i < TheString.Length-1; i++) { for (int ch = 32; ch < 128; ch++) { if(ch==39) continue; for (int i2 = 9; i2 < TheString.Length-1; i2++) { Console.WriteLine(i+":"+i2); for (int ch2 = 32; ch2 < 128; ch2++) { if (ch2 == 39) continue; string str = TheString.Substring(0, i) + Encoding.ASCII.GetString(new byte[] {(byte) ch}) + TheString.Substring(i + 1); str = str.Substring(0, i2) + Encoding.ASCII.GetString(new byte[] { (byte)ch2 }) + str.Substring(i2 + 1); string result = ExecuteBashCommand("echo '" + str + "' | /work/dist"); if (!result.Contains("0")) { Console.WriteLine(str + ":" + result); return; } } } } } } */ static string ExecuteBashCommand(string command) { // according to: https://stackoverflow.com/a/15262019/637142 // thans to this we will pass everything as one command command = command.Replace("\"", "\"\""); var proc = new Process { StartInfo = new ProcessStartInfo { FileName = "/bin/bash", Arguments = "-c \"" + command + "\"", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, } }; //Console.WriteLine("/bin/bash "+ "-c \"" + command + "\""); proc.Start(); proc.WaitForExit(); return proc.StandardOutput.ReadToEnd(); } static string ExecuteBashCommandStream(string command,string txt) { // according to: https://stackoverflow.com/a/15262019/637142 // thans to this we will pass everything as one command command = command.Replace("\"", "\"\""); var proc = new Process { StartInfo = new ProcessStartInfo { FileName = "/bin/bash", Arguments = "-c \"" + command + "\"", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, RedirectStandardInput = true } }; proc.Start(); System.Threading.Thread.Sleep(10); proc.StandardInput.Write(txt + "\n\x0004"); proc.WaitForExit(); return proc.StandardOutput.ReadToEnd(); } } }