Exemplo n.º 1
0
        private Boolean getFile(string fileName)
        {
            FileProps get = new FileProps
            {
                action = "getFile",
                token  = client.tokenID,
                taskId = taskID,
                file   = fileName
            };

            jsonClass jsC = new jsonClass {
                debugFlag = debugFlag, connectURL = client.connectURL
            };
            string jsonString = jsC.toJson(get);
            string ret        = jsC.jsonSend(jsonString);

            if (jsC.isJsonSuccess(ret))
            {
                string fileDl = jsC.getRetVar(ret, "url");
                {
                    downloadClass dlHdl  = new downloadClass();
                    string        dlFrom = Path.Combine(prefixServerdl, jsC.getRetVar(ret, "url"));
                    string        dlTo   = Path.Combine(filepath, fileName);
                    dlHdl.DownloadFile(dlFrom, dlTo);
                    Console.WriteLine("Finished downloading file");
                    //Check if file exists. check if return success
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        private Boolean getURLtoFile(string url, string dst)
        {
            {
                downloadClass dlHdl  = new downloadClass();
                string        dlFrom = Path.Combine(prefixServerdl, url);
                string        dlTo   = Path.Combine(filepath, dst);
                dlHdl.DownloadFile(dlFrom, dlTo);
                Console.WriteLine("Finished downloading file");
                //Check if file exists. check if return success
                if (File.Exists(dlTo))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        public bool updateCracker()
        {
            hcUpdateProper hcUpd   = new hcUpdateProper();
            jsonClass      jsonUpd = new jsonClass {
                debugFlag = debugFlag, connectURL = client.connectURL
            };

            hcUpd.token           = client.tokenID;
            hcUpd.binaryVersionId = binaryVersionId;

            string jsonString = jsonUpd.toJson(hcUpd);
            string ret        = jsonUpd.jsonSend(jsonString);

            if (jsonUpd.isJsonSuccess(ret))
            {
                string crackerName = jsonUpd.getRetVar(ret, "name");
                string fullSubDir  = Path.Combine(AppPath, crackerName.ToLower(), binaryVersionId.ToString());
                if (!Directory.Exists(fullSubDir)) //We need to download
                {
                    Console.WriteLine("Client doesn't have required cracker...");
                    downloadClass dlClass = new downloadClass();
                    if (client.osID != 1)
                    {
                        dlClass.DownloadFileCurl(jsonUpd.getRetVar(ret, "url"), Path.Combine(AppPath, "crackerClient.7z"));
                    }
                    else
                    {
                        dlClass.DownloadFile(jsonUpd.getRetVar(ret, "url"), Path.Combine(AppPath, "crackerClient.7z"));
                    }

                    if (Directory.Exists(Path.Combine(AppPath, "tmp")))
                    {
                        Directory.Delete(Path.Combine(AppPath, "tmp"), true);
                    }

                    sevenZip.xtract(Path.Combine(AppPath, "crackerClient.7z"), Path.Combine(AppPath, "tmp"));

                    //check if files present

                    string[] files = Directory.GetFiles(Path.Combine(AppPath, "tmp"));
                    if (files.Length != 0)
                    {
                        Directory.Move(Path.Combine(AppPath, "tmp"), fullSubDir);
                    }
                    else
                    {
                        string[] dirs = Directory.GetDirectories(Path.Combine(AppPath, "tmp"));
                        Directory.Move(dirs[0], fullSubDir);
                    }

                    Directory.Delete(Path.Combine(AppPath, "tmp"));
                    string binLocation = Path.Combine(fullSubDir, jsonUpd.getRetVar(ret, "executable"));

                    if (client.osID != 1) //Chmod for non windows
                    {
                        Console.WriteLine("Applying execution permissions to cracker binary");
                        Process.Start("chmod", "+x \"" + binLocation + "\"");
                    }

                    //May need to inplement legacy checks if cracker is hashcat
                }
                else
                {
                    Console.WriteLine("Client already exists, skipping download");
                }
                client.crackerBinary = jsonUpd.getRetVar(ret, "executable");


                if (client.is64Bit)
                {
                    client.crackerBinary = client.crackerBinary.Replace(".", "64.");
                }
                else
                {
                    client.crackerBinary = client.crackerBinary.Replace(".", "32.");
                }



                client.crackerPath = Path.Combine(AppPath, crackerName.ToLower(), binaryVersionId.ToString());
            }


            if (Directory.Exists(client.crackerPath))
            {
                return(true);
            }
            else
            {
                Console.WriteLine("Could not locate cracker, perhaps manually delete cracker " + binaryVersionId.ToString());
                return(false);
            }
        }
Exemplo n.º 4
0
        public bool updateHashcat()
        {
            hcUpdateProper hcUpd   = new hcUpdateProper();
            jsonClass      jsonUpd = new jsonClass {
                debugFlag = debugFlag, connectURL = client.connectURL
            };

            hcUpd.token = client.tokenID;
            string hcBinName = "hashcat";

            if (client.osID == 0)
            {
                hcBinName = hcBinName + "64.bin";
            }
            else if (client.osID == 1)
            {
                hcBinName = hcBinName + "64.exe";
            }

            string hcBinLoc = Path.Combine(AppPath, "hashcat", hcBinName);

            if (File.Exists(hcBinLoc))
            {
                hcUpd.force = 0; //HC exists, we don't need to force
            }
            else
            {
                hcUpd.force = 1; //HC doesn't exist, we need to force
            }

            string jsonString = jsonUpd.toJson(hcUpd);
            string ret        = jsonUpd.jsonSend(jsonString);

            if (jsonUpd.getRetVar(ret, "version") == "NEW")
            {
                downloadClass dlClass = new downloadClass();

                if (client.osID != 1)
                {
                    dlClass.DownloadFileCurl(jsonUpd.getRetVar(ret, "url"), Path.Combine(AppPath, "hcClient.7z"));
                }
                else
                {
                    dlClass.DownloadFile(jsonUpd.getRetVar(ret, "url"), Path.Combine(AppPath, "hcClient.7z"));
                }

                sevenZip.xtract(Path.Combine(AppPath, "hcClient.7z"), Path.Combine(AppPath, "hcClient"));
                if (Directory.Exists(Path.Combine(AppPath, "hashcat")))
                {
                    Directory.Delete(Path.Combine(AppPath, "hashcat"), true);
                }
                Directory.Move(Path.Combine(AppPath, "hcClient", jsonUpd.getRetVar(ret, "rootdir")), Path.Combine(AppPath, "hashcat"));
                Directory.Delete(Path.Combine(AppPath, "hcClient"));


                if (client.osID != 1) //Chmod for non windows
                {
                    Console.WriteLine("Applying execution permissions to 7zr binary");
                    Process.Start("chmod", "+x \"" + hcBinLoc + "\"");
                }
            }

            if (File.Exists(hcBinLoc))
            {
                return(true);
            }

            return(false);
        }
        public void runUpdate()
        {
            string currentBin = Environment.GetCommandLineArgs()[0]; //Grab current bin name

            if (System.AppDomain.CurrentDomain.FriendlyName == launcherProcName)
            {
                for (int i = 0; i < arguments.Length; i++)
                {
                    if (arguments[i] != "debug")
                    {
                        parentProc = (arguments[i]);
                        break;
                    }
                }

                //Looks like user isn't using custom name, use the default one
                if (string.IsNullOrEmpty(parentProc))
                {
                    parentProc = "hashtopolis.exe";
                }

                waitForProcess(parentProc);
                File.Copy(launcherProcName, parentProc, true);


                if (Type.GetType("Mono.Runtime") != null)
                {
                    Console.WriteLine("Client has now been updated, please re-launch the agent");
                }
                else
                {
                    Process reSpawn = new Process();
                    reSpawn.StartInfo.FileName = parentProc;
                    reSpawn.Start();
                }
                Environment.Exit(0);
            }
            else //We are either user-run bin or spanwed bin
            {
                waitForProcess(launcherProcName);
                if (File.Exists(launcherProcName))
                {
                    Console.WriteLine("Cleaning up files post update");
                    File.Delete(launcherProcName);
                }

                Console.WriteLine("Checking for client updates");
                updProps uProps = new updProps
                {
                    version = htpVersion,
                    token   = tokenID
                };

                jsonClass jsC = new jsonClass {
                    debugFlag = debugFlag, connectURL = connectURL
                };
                string jsonString = jsC.toJson(uProps);
                string ret        = jsC.jsonSend(jsonString);

                if (jsC.isJsonSuccess(ret))
                {
                    if (jsC.getRetVar(ret, "version") == "OK")
                    {
                        Console.WriteLine("You are using the latest client version");
                        return;
                    }
                    else
                    {
                        downloadClass dl     = new downloadClass();
                        string        dlFrom = Path.Combine(jsC.getRetVar(ret, "url"));
                        string        dlTo   = Path.Combine(parentPath, launcherProcName);
                        dl.DownloadFile(dlFrom, dlTo);
                        Console.WriteLine("Finished downloading latest client");
                        Console.WriteLine("Client will now relaunch");
                        Process Spawn = new Process();
                        Spawn.StartInfo.WorkingDirectory = parentPath;
                        if (Type.GetType("Mono.Runtime") != null)
                        {
                            Spawn.StartInfo.FileName  = "mono";
                            Spawn.StartInfo.Arguments = launcherProcName + " " + parentProc;
                        }
                        else
                        {
                            Spawn.StartInfo.FileName  = launcherProcName;
                            Spawn.StartInfo.Arguments = parentProc;
                        }

                        Spawn.Start();
                        Environment.Exit(0);
                    }
                }
                else
                {
                    Console.WriteLine("Exiting agnet");
                    Environment.Exit(0);
                }
            }
        }
        public Boolean init7z()
        {
            binPath = Path.Combine(appPath, "7zr");
            if (osID == 1)
            {
                binPath += ".exe";
            }

            FileInfo f = new FileInfo(binPath);

            if (!File.Exists(binPath) || f.Length == 0)
            {
                Console.WriteLine("Downloading 7zip binary");
                jsonClass jsC = new jsonClass {
                    debugFlag = true, connectURL = connectURL
                };

                dlProps dlzip = new dlProps
                {
                    token = tokenID
                };


                string jsonString = jsC.toJson(dlzip);
                string ret        = jsC.jsonSend(jsonString);
                if (jsC.isJsonSuccess(ret))

                {
                    string        dlLocation = jsC.getRetVar(ret, "executable");
                    downloadClass dlClass    = new downloadClass();

                    if (!dlClass.DownloadFile(dlLocation, binPath))
                    {
                        Console.WriteLine("Unable to download requested file");
                    }
                    else
                    {
                        Console.WriteLine("Finished downloading file");
                    }
                }
                if (osID != 1) //If OS is not windows, we need to set the permissions
                {
                    try
                    {
                        Console.WriteLine("Applying execution permissions to 7zr binary");
                        Process.Start("chmod", "+x \"" + binPath + "\"");
                    }
                    catch (Exception e)
                    {
                        Console.Write(e.Data);
                        Console.WriteLine("Unable to change access permissions of 7zr, execution permissions required");
                    }
                }
            }

            if (File.Exists(binPath))
            {
                return(true);
            }

            return(false);
        }