public int getChunk(int inTask) { Console.WriteLine("Getting chunk..."); chunkProps cProps = new chunkProps { action = "chunk", token = client.tokenID, taskId = inTask }; jsC.debugFlag = debugFlag; jsC.connectURL = client.connectURL; primaryCracked = new List <string> { }; hcClass.debugFlag = debugFlag; string jsonString = jsC.toJson(cProps); string ret = jsC.jsonSend(jsonString); if (jsC.isJsonSuccess(ret)) { string status = jsC.getRetVar(ret, "status"); string argBuilder = attackcmd; string attackcmdMod = " " + cmdpars + " "; string actualHLpath = Path.Combine(hashpath, hashlistID.ToString()); switch (status) { case "OK": attackcmdMod = " " + cmdpars + " "; //Reset the argument string attackcmdMod += attackcmd.Replace(hashlistAlias, "\"" + actualHLpath + "\" "); //Add the path to Hashlist attackcmdMod += " --outfile-check-dir=\"" + zapPath + hashlistID.ToString() + "\" "; //Add the zap path to the commands hcClass.setArgs(attackcmdMod); chunkNo = Convert.ToInt64(jsC.getRetVar(ret, "chunk")); skip = Convert.ToInt64(jsC.getRetVar(ret, "skip")); length = Convert.ToInt64(jsC.getRetVar(ret, "length")); List <Packets> uploadPackets = new List <Packets>(); hcClass.setDirs(appPath, client.osID); hcClass.setPassthrough(ref uploadPackets, ref packetLock, separator.ToString(), debugFlag); Thread thread = new Thread(() => threadPeriodicUpdate(ref uploadPackets, ref packetLock)); thread.Start(); //Start our thread to monitor the upload queue hcClass.startAttack(chunkNo, taskID, skip, length, separator.ToString(), statusTimer, tasksPath); //Start the hashcat binary thread.Join(); return(1); case "keyspace_required": hcClass.setDirs(appPath, client.osID); attackcmdMod = " " + cmdpars + " "; //Reset the argument string attackcmdMod += attackcmd.Replace(hashlistAlias, ""); //Remove out the #HL# hcClass.setArgs(attackcmdMod); long calcKeyspace = 0; hcClass.runKeyspace(ref calcKeyspace); if (calcKeyspace == 0) { errorProps eProps = new errorProps { token = client.tokenID, task = taskID, message = "Invalid keyspace, keyspace probably too small for this hashtype" }; jsonString = jsC.toJson(eProps); ret = jsC.jsonSend(jsonString); return(0); } else { keyspaceProps kProps = new keyspaceProps { token = client.tokenID, taskId = taskID, keyspace = calcKeyspace }; jsonString = jsC.toJson(kProps); ret = jsC.jsonSend(jsonString); } return(2); case "fully_dispatched": return(0); case "benchmark": hcClass.setDirs(appPath, client.osID); attackcmdMod = " " + cmdpars + " "; //Reset the argument string attackcmdMod += attackcmd.Replace(hashlistAlias, "\"" + actualHLpath + "\""); //Add the path to Hashlist hcClass.setArgs(attackcmdMod); Dictionary <string, double> collection = new Dictionary <string, double>(); //Holds all the returned benchmark values1 hcClass.runBenchmark(benchMethod, benchTime, ref collection, legacy); benchProps bProps = new benchProps { token = client.tokenID, taskId = taskID, }; if (benchMethod == 1) //Old benchmark method using actual run { bProps.type = "run"; if (collection.ContainsKey("PROGRESS_REJ")) { bProps.result = collection["PROGRESS_REJ"].ToString("0." + new string('#', 100)); } else { bProps.result = collection["PROGRESS_DIV"].ToString("0." + new string('#', 100)); } } else //New benchmark method using --speed param { bProps.type = "speed"; bProps.result = collection["LEFT_TOTAL"].ToString() + ":" + collection["RIGHT_TOTAL"].ToString(); } jsonString = jsC.toJson(bProps); ret = jsC.jsonSend(jsonString); if (!jsC.isJsonSuccess(ret)) { Console.WriteLine("Server rejected benchmark"); Console.WriteLine("Check the hashlist was downloaded correctly"); return(0); } return(3); case "hashcat_update": Console.WriteLine("A new version of hashcat was found, updating..."); hashcatUpdateClass hcUpdater = new hashcatUpdateClass { debugFlag = debugFlag, client = client, AppPath = appPath, sevenZip = sevenZip }; if (hcUpdater.updateHashcat()) { hashcatClass hcClass = new hashcatClass { debugFlag = debugFlag }; hcClass.setDirs(appPath, client.osID); string[] versionInts = { }; string hcVersion = hcClass.getVersion2(ref versionInts); Console.WriteLine("Hashcat version {0} found", hcVersion); if (hcVersion.Length != 0) { if (Convert.ToInt32(versionInts[0]) == 3 && Convert.ToInt32(versionInts[1]) == 6) { if (hcVersion.Contains("-")) { legacy = false; //This is most likely a beta/custom build with commits ahead of 3.6.0 release branch } } else if (Convert.ToInt32(versionInts[0]) == 3) { if (Convert.ToInt32(versionInts[1].Substring(0, 1)) >= 6) { legacy = false; //This is a release build above 3.6.0 } } else if (Convert.ToInt32(versionInts[0]) >= 4) { legacy = false; //This is a release build above 4.0.0 } } else { //For some reason we couldn't read the version, lets just assume we are on non legacy legacy = false; } setOffset(); } else { Console.WriteLine("Update failed"); } return(4); } } return(0); }
static void Main(string[] args) { if (Console.LargestWindowWidth > 94 && Console.LargestWindowHeight > 24) { Console.SetWindowSize(95, 25); } System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; System.Threading.Thread.CurrentThread.CurrentCulture = customCulture; for (int i = 0; i < args.Length; i++) { if (args[i] == "debug") { DebugMode = true; break; } } string AppVersion = "0.45.9"; Console.WriteLine("Client Version " + AppVersion); initConnect(); updateClass updater = new updateClass { htpVersion = AppVersion, parentPath = AppPath, arguments = args, connectURL = serverURL, debugFlag = DebugMode }; updater.runUpdate(); initDirs(); registerClass client = new registerClass { connectURL = serverURL, debugFlag = DebugMode }; Boolean legacy = true; //Defaults to legacy STATUS codes client.setPath(AppPath); if (client.loginAgent()) { Console.WriteLine("Logged in to server"); } //Run code to self-update _7zClass zipper = new _7zClass { tokenID = client.tokenID, osID = client.osID, appPath = AppPath, connectURL = serverURL }; if (!zipper.init7z()) { Console.WriteLine("Failed to initialize 7zip, proceeding without. \n The client may not be able to extract compressed files"); } else //We have 7zip, lets check for HC update since that is zipped { hashcatUpdateClass hcUpdater = new hashcatUpdateClass { debugFlag = DebugMode, client = client, AppPath = AppPath, sevenZip = zipper }; if (hcUpdater.updateHashcat()) { hashcatClass hcClass = new hashcatClass { }; hcClass.setDirs(AppPath, client.osID); string[] versionInts = {}; string hcVersion = hcClass.getVersion2(ref versionInts); Console.WriteLine("Hashcat version {0} found", hcVersion); if (Convert.ToInt32(versionInts[0]) == 3 && Convert.ToInt32(versionInts[1]) == 6) { if (hcVersion.Contains("-")) { legacy = false; //This is most likely a beta/custom build with commits ahead of 3.6.0 release branch } } else if (Convert.ToInt32(versionInts[0]) >= 3 && Convert.ToInt32(versionInts[1]) >= 6) { legacy = false; //This is a release build above 3.6.0 } } else { Console.WriteLine("Could not locate hashcat binary"); Console.WriteLine("You can manually download and extract hashcat"); Console.WriteLine("Client will now terminate"); { Environment.Exit(0); } } } taskClass tasks = new taskClass { sevenZip = zipper, debugFlag = DebugMode, client = client, legacy = legacy }; tasks.setOffset(); //Set offset for STATUS changes in hashcat 3.6.0 tasks.setDirs(AppPath); int backDown = 5; while (true) //Keep waiting for 5 seconds and checking for tasks { Thread.Sleep(backDown * 1000); if (tasks.getTask()) { backDown = 5; } if (backDown < 30) { backDown++; } } }