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);
        }
示例#2
0
        public int getChunk(int inTask)
        {
            Console.WriteLine("Getting chunk...");
            chunkProps cProps = new chunkProps
            {
                action = "getChunk",
                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 = convertToRelative(attackcmdMod);

                    attackcmdMod += " --outfile-check-dir=\"" + zapPath + hashlistID.ToString() + "\" ";     //Add the zap path to the commands

                    hcClass.setArgs(attackcmdMod);

                    chunkNo = Convert.ToInt64(jsC.getRetVar(ret, "chunkId"));
                    skip    = Convert.ToInt64(jsC.getRetVar(ret, "skip"));
                    length  = Convert.ToInt64(jsC.getRetVar(ret, "length"));

                    List <Packets> uploadPackets = new List <Packets>();

                    hcClass.setDirs(appPath);
                    hcClass.setPassthrough(ref uploadPackets, ref packetLock, 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, statusTimer, tasksPath); //Start the hashcat binary
                    thread.Join();

                    return(1);

                case "keyspace_required":
                    hcClass.setDirs(appPath);
                    attackcmdMod  = " " + cmdpars + " ";                  //Reset the argument string
                    attackcmdMod += attackcmd.Replace(hashlistAlias, ""); //Remove out the #HL#

                    attackcmdMod = convertToRelative(attackcmdMod);

                    hcClass.setArgs(attackcmdMod);
                    long calcKeyspace = 0;

                    if (!hcClass.runKeyspace(ref calcKeyspace))
                    {
                        Console.WriteLine("Keyspace measuring was unsuccessful, check all files are present");
                        return(0);
                    }


                    if (calcKeyspace == 0)
                    {
                        errorProps eProps = new errorProps
                        {
                            token   = client.tokenID,
                            taskId  = 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);
                    attackcmdMod  = " " + cmdpars + " ";                                          //Reset the argument string
                    attackcmdMod += attackcmd.Replace(hashlistAlias, "\"" + actualHLpath + "\""); //Add the path to Hashlist

                    attackcmdMod = convertToRelative(attackcmdMod);

                    hcClass.setArgs(attackcmdMod);

                    Dictionary <string, double> collection = new Dictionary <string, double>();   //Holds all the returned benchmark values1

                    if (!hcClass.runBenchmark(benchMethod, benchTime, ref collection, legacy))
                    {
                        Console.WriteLine("Benchmark error, perhaps hashlist is empty");
                        errorProps eProps = new errorProps
                        {
                            token   = client.tokenID,
                            taskId  = taskID,
                            message = "Client received an invalid hashlist for benchmark"
                        };
                        jsonString = jsC.toJson(eProps);
                        ret        = jsC.jsonSend(jsonString);

                        return(0);
                    }

                    benchProps bProps = new benchProps
                    {
                        token  = client.tokenID,
                        taskId = taskID,
                    };

                    try
                    {
                        if (benchMethod == 1)     //Old benchmark method using actual run
                        {
                            bProps.type   = "run";
                            bProps.result = collection["PROGRESS_REJ"].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();
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Benchmark was unsuccessful, check all files are present");
                        return(0);
                    }



                    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);
                }
            }
            return(0);
        }