├── .gitignore
├── README.md
├── hashtopolis.sln
└── hashtopolis
├── .gitignore
├── 7zClass.cs
├── App.config
├── Program.cs
├── Properties
└── AssemblyInfo.cs
├── binary
└── hashtopolis.exe
├── downloadClass.cs
├── hashcatClass.cs
├── hashcatUpdateClass.cs
├── hashtopolis.csproj
├── hashtopolis.csproj.user
├── jsonClass.cs
├── registerClass.cs
├── small.ico
├── taskClass.cs
└── updateClass.cs
/.gitignore:
--------------------------------------------------------------------------------
1 | hashtopolis/bin/
2 | hashtopolis/obj/
3 | *.suo
4 | .vs/
5 | .suo
6 |
7 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Hashtopolis C# Agent
2 |
3 | [](https://github.com/hashtopolis/agent-csharp)
4 |
5 | **Note: This agent was used in old Hashtopolis versions and is not supported anymore by Hashtopolis!**
6 |
7 | This agent is used with [Hashtopolis](https://github.com/hashtopolis/hashtopolis), read the wiki or create issues there, visit the [Forum](https://hashtopolis.org).
8 |
--------------------------------------------------------------------------------
/hashtopolis.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26730.12
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hashtopolis", "hashtopolis\hashtopolis.csproj", "{199AD37B-3000-4CC0-992C-87738F84C768}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Debug|x64 = Debug|x64
12 | Release|Any CPU = Release|Any CPU
13 | Release|x64 = Release|x64
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {199AD37B-3000-4CC0-992C-87738F84C768}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {199AD37B-3000-4CC0-992C-87738F84C768}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {199AD37B-3000-4CC0-992C-87738F84C768}.Debug|x64.ActiveCfg = Debug|x64
19 | {199AD37B-3000-4CC0-992C-87738F84C768}.Debug|x64.Build.0 = Debug|x64
20 | {199AD37B-3000-4CC0-992C-87738F84C768}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {199AD37B-3000-4CC0-992C-87738F84C768}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {199AD37B-3000-4CC0-992C-87738F84C768}.Release|x64.ActiveCfg = Release|x64
23 | {199AD37B-3000-4CC0-992C-87738F84C768}.Release|x64.Build.0 = Release|x64
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {6AF2D704-CD70-4421-8080-269C7AD78ABA}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/hashtopolis/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hashtopolis/agent-csharp/f5980387abc18203407d803d55bb84ac95f8b7b5/hashtopolis/.gitignore
--------------------------------------------------------------------------------
/hashtopolis/7zClass.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Diagnostics;
4 |
5 |
6 | namespace hashtopolis
7 | {
8 |
9 | class _7zClass
10 | {
11 |
12 | public class dlProps
13 | {
14 | public string action = "downloadBinary";
15 | public string type = "7zr";
16 | public string token { get; set; }
17 | }
18 |
19 | public int osID { get; set; }
20 | public string tokenID { get; set; }
21 | public string appPath { get; set; }
22 | public string connectURL { get; set; }
23 |
24 | string binPath = "";
25 |
26 | public Boolean init7z()
27 | {
28 |
29 | binPath = Path.Combine(appPath, "7zr");
30 | if (osID == 1)
31 | {
32 | binPath += ".exe";
33 | }
34 |
35 | FileInfo f = new FileInfo(binPath);
36 |
37 | if (!File.Exists(binPath) || f.Length == 0)
38 | {
39 | Console.WriteLine("Downloading 7zip binary");
40 | jsonClass jsC = new jsonClass { debugFlag = true, connectURL = connectURL };
41 |
42 | dlProps dlzip = new dlProps
43 | {
44 | token = tokenID
45 | };
46 |
47 |
48 | string jsonString = jsC.toJson(dlzip);
49 | string ret = jsC.jsonSend(jsonString);
50 | if (jsC.isJsonSuccess(ret))
51 |
52 | {
53 | string dlLocation = jsC.getRetVar(ret,"executable");
54 | downloadClass dlClass = new downloadClass();
55 |
56 | if (!dlClass.DownloadFile(dlLocation, binPath))
57 | {
58 | Console.WriteLine("Unable to download requested file");
59 | }
60 | else
61 | {
62 | Console.WriteLine("Finished downloading file");
63 | }
64 |
65 | }
66 | if (osID != 1) //If OS is not windows, we need to set the permissions
67 | {
68 | try
69 | {
70 | Console.WriteLine("Applying execution permissions to 7zr binary");
71 | Process.Start("chmod", "+x \"" + binPath + "\"");
72 | }
73 | catch (Exception e)
74 | {
75 | Console.Write(e.Data);
76 | Console.WriteLine("Unable to change access permissions of 7zr, execution permissions required");
77 | }
78 | }
79 |
80 | }
81 |
82 | if (File.Exists(binPath))
83 | {
84 | return true;
85 | }
86 |
87 | return false;
88 |
89 | }
90 |
91 | //Code from hashtopus
92 | public Boolean xtract(string archivePath, string outDir, string files = "")
93 | {
94 | ProcessStartInfo pinfo = new ProcessStartInfo();
95 | pinfo.FileName = binPath;
96 | pinfo.WorkingDirectory = appPath;
97 | pinfo.UseShellExecute = false;
98 | pinfo.RedirectStandardError = true;
99 | pinfo.RedirectStandardOutput = true;
100 | pinfo.Arguments = " x -y -o\"" + outDir + "\" \"" + archivePath + "\"";
101 | string stdOutSingle = "";
102 | Boolean unpackFailed = false;
103 | Process unpak = new Process();
104 | unpak.StartInfo = pinfo;
105 |
106 | if (files != "") unpak.StartInfo.Arguments += " " + files;
107 |
108 | Console.WriteLine(pinfo.FileName + pinfo.Arguments);
109 | Console.WriteLine("Extracting archive " + archivePath + "...");
110 |
111 | FileInfo f = new FileInfo(archivePath);
112 |
113 | if (f.Length == 0)
114 | {
115 | Console.WriteLine("File is 0 bytes");
116 | return false;
117 | }
118 |
119 | try
120 | {
121 | if (!unpak.Start()) return false;
122 | while (!unpak.HasExited)
123 | {
124 | while (!unpak.StandardOutput.EndOfStream)
125 | {
126 | stdOutSingle = unpak.StandardOutput.ReadLine().TrimEnd();
127 | if (stdOutSingle == "Error: Can not open file as archive")
128 | {
129 | unpackFailed = true;
130 | }
131 | }
132 | }
133 | unpak.StandardOutput.Close();
134 | }
135 | catch
136 | {
137 | Console.WriteLine("Could not start 7zr.");
138 | return false;
139 | }
140 | finally
141 | {
142 | unpak.WaitForExit();
143 | }
144 |
145 | if (unpackFailed == true)
146 | {
147 | Console.WriteLine("Failed to extract " + archivePath);
148 | Console.WriteLine("WARNING:Some needed files may be missing and the tasks may not start correctly");
149 | return false;
150 | }
151 | return true;
152 |
153 | }
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/hashtopolis/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/hashtopolis/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Threading;
5 | using System.Web.Script.Serialization;
6 | using System.Diagnostics;
7 | namespace hashtopolis
8 | {
9 |
10 |
11 |
12 | public struct Packets
13 | {
14 | public Dictionary statusPackets;
15 | public List crackedPackets;
16 | }
17 |
18 | public class testProp
19 | {
20 | public string action = "testConnection";
21 | }
22 |
23 | public class config_data
24 | {
25 | public string url { get; set; }
26 | public string uuid { get; set; }
27 | public string voucher { get; set; }
28 | public string token { get; set; }
29 | }
30 |
31 |
32 | class Program
33 | {
34 |
35 |
36 | public static string AppPath = AppDomain.CurrentDomain.BaseDirectory;
37 |
38 | //Read the settings file here
39 |
40 | private static string urlPath = Path.Combine(AppPath, "URL");
41 | private static string serverURL = "";
42 |
43 | static void initDirs()
44 | {
45 |
46 | string[] createDirs = new String[] { "files", "hashlists", "tasks", "hashcat" };
47 |
48 | foreach (string dir in createDirs)
49 | {
50 | string enumDir = Path.Combine(AppPath, dir);
51 | try
52 | {
53 | if (!Directory.Exists(enumDir))
54 | {
55 | Console.WriteLine("Creating {0} directory", dir);
56 | Directory.CreateDirectory(enumDir);
57 | }
58 | }
59 | catch (Exception e)
60 | {
61 | Console.WriteLine(e.Data);
62 | Console.WriteLine("Unable to create dir {0}", dir);
63 | Console.WriteLine("Client now terminating");
64 | Environment.Exit(0);
65 | }
66 |
67 | }
68 |
69 | }
70 |
71 |
72 |
73 | public static bool loadURL()
74 | {
75 | if (serverURL == "")
76 | {
77 | if (File.Exists(urlPath))
78 | {
79 | serverURL = File.ReadAllText(urlPath);
80 | if (serverURL == "")
81 | {
82 | File.Delete(urlPath);
83 | return false;
84 | }
85 | }
86 | else
87 | {
88 | return false;
89 | }
90 | }
91 | return true;
92 |
93 | }
94 |
95 |
96 | public static void writeSettings(config_data config)
97 | {
98 | string jsonPath = Path.Combine(AppPath, "config.json");
99 | jsonClass jsonProcessor = new jsonClass();
100 | string saveSettings = jsonProcessor.toJson(config);
101 |
102 | File.WriteAllText(jsonPath, saveSettings);
103 | }
104 |
105 | public static void getSettings(config_data config)
106 | {
107 | JavaScriptSerializer jss = new JavaScriptSerializer();
108 | string jsonPath = Path.Combine(AppPath, "config.json");
109 | config.url = "";
110 | config.uuid = "";
111 | config.token = "";
112 | config.voucher = "";
113 |
114 | if (File.Exists(jsonPath))
115 | {
116 | string jsonContent = File.ReadAllText(jsonPath);
117 | Dictionary dict = jss.Deserialize>(jsonContent);
118 | if (dict.ContainsKey("url"))
119 | {
120 | config.url = dict["url"];
121 | }
122 | if (dict.ContainsKey("voucher"))
123 | {
124 | config.voucher = dict["voucher"];
125 | }
126 | if (dict.ContainsKey("uuid"))
127 | {
128 | config.uuid = dict["uuid"];
129 | }
130 | if (dict.ContainsKey("token"))
131 | {
132 | config.token = dict["token"];
133 | }
134 |
135 | }
136 | else
137 | {
138 | Console.WriteLine("Not found");
139 | }
140 | }
141 |
142 | public static Boolean initConnect(config_data config)
143 | {
144 | jsonClass testConnect = new jsonClass { debugFlag = DebugMode };
145 | testProp tProp = new testProp();
146 | string urlMsg = "Please enter server connect URL (https will be used unless specified):";
147 | Console.WriteLine(config.url);
148 | while (config.url == "")
149 | {
150 | Console.WriteLine(urlMsg);
151 | string url = Console.ReadLine();
152 | if (!url.StartsWith("http", StringComparison.OrdinalIgnoreCase))
153 | {
154 | url = "https://" + url;
155 | }
156 | Console.WriteLine("Testing connection to " + url);
157 | testConnect.connectURL = url;
158 | string jsonString = testConnect.toJson(tProp);
159 | string ret = testConnect.jsonSendOnce(jsonString);
160 | if (ret != null)
161 | {
162 | if (testConnect.isJsonSuccess(ret))
163 | {
164 | //File.WriteAllText(urlPath, url);
165 | Console.WriteLine("Connecction successful");
166 | config.url = url;
167 | writeSettings(config);
168 | }
169 | }
170 | else
171 | {
172 | urlMsg = "Test connect failed, please enter server connect URL:";
173 | }
174 |
175 | }
176 |
177 | Console.WriteLine("Connecting to server {0}",serverURL);
178 | return true;
179 | }
180 |
181 | public static Boolean DebugMode;
182 |
183 | static void Main(string[] args)
184 | {
185 |
186 |
187 | if (Console.LargestWindowWidth > 94 && Console.LargestWindowHeight > 24)
188 | {
189 | Console.SetWindowSize(95, 25);
190 | }
191 |
192 |
193 |
194 | System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
195 | customCulture.NumberFormat.NumberDecimalSeparator = ".";
196 | System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
197 |
198 | string tokenSwitch = "";
199 |
200 | foreach (string arg in args)
201 | {
202 | switch (arg.Substring(0, 2))
203 | {
204 |
205 | case "-t":
206 | tokenSwitch = arg.Substring(3);
207 | break;
208 | case "-u":
209 | serverURL = arg.Substring(3);
210 | break;
211 | case "-d":
212 | DebugMode = true;
213 | break;
214 | }
215 | }
216 |
217 |
218 | string AppVersion = "0.52.6";
219 | Console.WriteLine("Client Version " + AppVersion);
220 |
221 | config_data config = new config_data();
222 |
223 | getSettings(config);
224 | Console.Write(config.url);
225 | initConnect(config);
226 | initDirs();
227 |
228 | registerClass client = new registerClass { connectURL = serverURL, debugFlag = DebugMode,tokenID = tokenSwitch};
229 | Boolean legacy = false; //Defaults to legacy STATUS codes
230 | client.setPath( AppPath);
231 | if (client.loginAgent())
232 | {
233 | Console.WriteLine("Logged in to server");
234 | }
235 |
236 | updateClass updater = new updateClass
237 | {
238 | htpVersion = AppVersion,
239 | parentPath = AppPath,
240 | arguments = args,
241 | connectURL = serverURL,
242 | debugFlag = DebugMode,
243 | tokenID = client.tokenID
244 |
245 | };
246 | updater.runUpdate();
247 | //Run code to self-update
248 |
249 | _7zClass zipper = new _7zClass
250 | {
251 | tokenID = client.tokenID,
252 | osID = client.osID,
253 | appPath = AppPath,
254 | connectURL = serverURL
255 | };
256 |
257 | if (!zipper.init7z())
258 | {
259 | Console.WriteLine("Failed to initialize 7zip, proceeding without. \n The client may not be able to extract compressed files");
260 | }
261 |
262 | taskClass tasks = new taskClass
263 | {
264 | sevenZip = zipper,
265 | debugFlag = DebugMode,
266 | client = client,
267 | legacy = legacy
268 |
269 | };
270 |
271 | tasks.setOffset(); //Set offset for STATUS changes in hashcat 3.6.0
272 | tasks.setDirs(AppPath);
273 |
274 | int backDown = 5;
275 | while(true) //Keep waiting for 5 seconds and checking for tasks
276 | {
277 | Thread.Sleep(backDown * 1000);
278 |
279 | if (tasks.getTask())
280 | {
281 | backDown = 5;
282 | }
283 | if (backDown <30)
284 | {
285 | backDown++;
286 | }
287 | }
288 |
289 | }
290 | }
291 | }
292 |
--------------------------------------------------------------------------------
/hashtopolis/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("hashtopolis")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("hashtopolis")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("199ad37b-3000-4cc0-992c-87738f84c768")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/hashtopolis/binary/hashtopolis.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hashtopolis/agent-csharp/f5980387abc18203407d803d55bb84ac95f8b7b5/hashtopolis/binary/hashtopolis.exe
--------------------------------------------------------------------------------
/hashtopolis/downloadClass.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.Net;
4 | using System.Threading;
5 | using System.IO;
6 | using System.ComponentModel;
7 |
8 | namespace hashtopolis
9 | {
10 | class downloadClass
11 | {
12 |
13 |
14 | Stopwatch sw = new Stopwatch();
15 | private bool completedFlag = false;
16 |
17 | public bool DownloadFileCurl(string urlAddress, string location)
18 | {
19 | string AppPath = AppDomain.CurrentDomain.BaseDirectory;
20 | ProcessStartInfo pinfo = new ProcessStartInfo();
21 | pinfo.FileName = "curl";
22 | pinfo.UseShellExecute = false;
23 | pinfo.RedirectStandardOutput = true;
24 |
25 |
26 | pinfo.WorkingDirectory = AppPath;
27 |
28 | pinfo.Arguments = " " + urlAddress + " -o" + "\"" + location + "\"";
29 |
30 | Process unpak = new Process();
31 | unpak.StartInfo = pinfo;
32 | unpak.Start();
33 | unpak.WaitForExit();
34 | return true;
35 |
36 | }
37 |
38 |
39 |
40 | public bool DownloadFile(string urlAddress, string location)
41 | {
42 |
43 | completedFlag = false;
44 | WebClient webClient;
45 | try
46 | {
47 | System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 |
48 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
49 | }
50 | catch
51 | {
52 | Console.WriteLine("Skipping TLS settings (consider upgrading to the latest .NET framework for better TLS support");
53 | }
54 |
55 | using (webClient = new WebClient())
56 | {
57 | webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
58 | webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(dlFinished);
59 | if (!urlAddress.StartsWith("http", StringComparison.OrdinalIgnoreCase))
60 | {
61 | urlAddress = "https://" + urlAddress;
62 | }
63 | Uri URL = null;
64 | try
65 | {
66 | Console.WriteLine("Downloading from " + urlAddress);
67 | URL = new Uri(urlAddress);
68 | }
69 | catch
70 | {
71 | Console.WriteLine("Invalid url for downloading");
72 | return false;
73 | }
74 |
75 | //webClient.DownloadFile(URL, location);
76 | // Start the stopwatch which we will be using to calculate the download speed
77 | sw.Start();
78 |
79 | try
80 | {
81 | // Start downloading the file
82 | webClient.DownloadFileAsync(URL, location);
83 |
84 | }
85 | catch (Exception ex)
86 | {
87 | Console.WriteLine(ex.Message);
88 | return false;
89 | }
90 | while (!completedFlag) Thread.Sleep(500);
91 |
92 | if (File.Exists(location))
93 | {
94 | FileInfo f = new FileInfo(location);
95 | long size = f.Length;
96 | Console.WriteLine();
97 | return true;
98 | }
99 | else
100 | {
101 | return false;
102 | }
103 |
104 | }
105 | }
106 |
107 | //This will fire upon filedownload completion
108 | void dlFinished(object sender, AsyncCompletedEventArgs e)
109 | {
110 | completedFlag = true;
111 | }
112 |
113 | // The event that will fire whenever the progress of the WebClient is changed
114 | private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
115 | {
116 |
117 | double speed = e.BytesReceived / 1024d / sw.Elapsed.TotalSeconds;
118 | int divCount = 0;
119 | while (speed > 1000)
120 | {
121 | speed = speed / 1000;
122 | divCount += 1;
123 | }
124 |
125 | string speedMetric = "?/s";
126 | switch (divCount)
127 | {
128 | case 0:
129 | speedMetric = "KB/s";
130 | break;
131 | case 1:
132 | speedMetric = "MB/s";
133 | break;
134 | case 2:
135 | speedMetric = "GB/s";
136 | break;
137 | case 3:
138 | speedMetric = "TB/s";
139 | break;
140 |
141 | }
142 |
143 | Console.Write("\r{0} {1}% @ {2} {3}", "Downloading",e.ProgressPercentage, speed.ToString("0.00"), speedMetric);
144 |
145 | }
146 |
147 |
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/hashtopolis/hashcatClass.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Diagnostics;
7 | using System.Text.RegularExpressions;
8 | using System.Globalization;
9 |
10 | namespace hashtopolis
11 | {
12 | class hashcatClass : IDisposable
13 | {
14 | public Boolean debugFlag { get; set; }
15 |
16 | public List hashlist = new List { }; //New collection to store cracks
17 | public Process hcProc;
18 |
19 | private string workingDir = "";
20 | private string filesDir = "";
21 | private string hcDir = "hashcat";
22 | private string hcBin = "hashcat64.exe";
23 | public string hcDirectory { get; set; }
24 | public string hcBinary { get; set; }
25 |
26 | private string hcArgs = "";
27 |
28 | private object packetLock;
29 | private object crackedLock;
30 | private object statusLock;
31 |
32 | List passedPackets;
33 |
34 | public void Dispose()
35 | {
36 | Dispose(true);
37 | GC.SuppressFinalize(this);
38 | }
39 |
40 | protected virtual void Dispose(bool disposing)
41 | {
42 | if (disposing)
43 | {
44 | if (!hcProc.HasExited )
45 | {
46 | hcProc.Kill();
47 | hcProc.Dispose();
48 | }
49 | }
50 | }
51 |
52 | public void setPassthrough(ref List refPacketlist, ref object objpacketLock, Boolean debugging)
53 | {
54 | passedPackets = refPacketlist;
55 | packetLock = objpacketLock;
56 |
57 | crackedLock = new object();
58 | statusLock = new object();
59 | debugFlag = debugging;
60 |
61 | }
62 |
63 | public void setArgs(string args)
64 | {
65 |
66 | hcArgs = args;
67 | }
68 |
69 | public void setDirs(string fpath)
70 | {
71 | hcDir = Path.Combine(fpath, hcDirectory);
72 | workingDir = Path.Combine(fpath, "tasks").TrimEnd();
73 | filesDir = Path.Combine(fpath, "files"," ").TrimEnd();
74 |
75 | hcBin = hcBinary;
76 |
77 | }
78 |
79 | public void runUpdate()
80 | {
81 | if (!Directory.Exists(hcDir))
82 | {
83 | //forceUpdate = true;
84 | }
85 | }
86 |
87 |
88 |
89 | private void parseStatus1(string line,ref Dictionary collection)
90 | {
91 |
92 | System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
93 | customCulture.NumberFormat.NumberDecimalSeparator = ".";
94 | System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
95 |
96 | //Console.WriteLine(line);
97 |
98 | string[] items = line.Split('\t');
99 | double speedData = 0;
100 | double countStep = 0;
101 | double execRuntime = 0;
102 |
103 | int max = items.Count();
104 | int i = 0;
105 |
106 | if (debugFlag)
107 | {
108 | Console.WriteLine(line);
109 | }
110 |
111 |
112 | while(i < max)
113 | {
114 | countStep = 0;
115 | switch (items[i])
116 | {
117 | case "STATUS":
118 | collection.Add("STATUS", Convert.ToInt64(items[i + 1]));
119 | i =+ 1;
120 | break;
121 | case "SPEED":
122 | while (items[i+1] != "EXEC_RUNTIME") //Due to multiple cards, perform micro-loop
123 | {
124 | collection.Add("SPEED" + countStep, Convert.ToDouble(items[i + 1]));
125 | speedData += (Convert.ToDouble(items[i + 1]) * 1000) / Convert.ToDouble(items[i + 2]); //For hashcat 3.7 compatability
126 | countStep++;
127 | i += 2;
128 | }
129 | collection.Add("SPEED_TOTAL", speedData);
130 | collection.Add("SPEED_COUNT", countStep);
131 | break;
132 | case "EXEC_RUNTIME":
133 | while (items[i+1] != "CURKU") //Due to multiple cards, perform micro-loop
134 | {
135 | collection.Add("EXEC_RUNTIME" + countStep, Math.Round(Convert.ToDouble(Decimal.Parse(items[i + 1]), CultureInfo.InvariantCulture),2));
136 | execRuntime += Convert.ToDouble(Decimal.Parse(items[i + 1]), CultureInfo.InvariantCulture);
137 | countStep++;
138 | i += 1;
139 | }
140 | collection.Add("EXEC_RUNTIME_AVG", Math.Round(execRuntime/ countStep,2)); //Calculate the average kernel run-time
141 | collection.Add("EXEC_TIME_COUNT", countStep);
142 |
143 | break;
144 | case "CURKU":
145 | collection.Add("CURKU", Convert.ToDouble(items[i + 1]));
146 | i += 1;
147 | break;
148 | case "PROGRESS":
149 | collection.Add("PROGRESS1", Convert.ToDouble(items[i + 1])); //First progress value
150 | collection.Add("PROGRESS2", Convert.ToDouble(items[i + 2])); //Total progress value
151 | collection.Add("PROGRESS_DIV", Math.Round(Convert.ToDouble(items[i + 1])/Convert.ToInt64(items[i + 2]),15)); //Total progress value
152 | i += 2;
153 | break;
154 | case "RECHASH":
155 | collection.Add("RECHASH1", Convert.ToDouble(items[i + 1])); //First RECHASH value
156 | collection.Add("RECHASH2", Convert.ToDouble(items[i + 2])); //Second RECHASH value
157 | i += 2;
158 | break;
159 | case "RECSALT":
160 | collection.Add("RECSALT1", Convert.ToDouble(items[i + 1])); //First RECSALT value
161 | collection.Add("RECSALT2", Convert.ToDouble(items[i + 2])); //Second RECSALT value
162 | i += 2;
163 | break;
164 | case "REJECTED":
165 | collection.Add("REJECTED", Convert.ToDouble(items[i + 1]));
166 | collection.Add("PROGRESS_REJ", Math.Round((collection["PROGRESS1"]-collection["REJECTED"]) / collection["PROGRESS2"], 15)); //Total progress value
167 | i += 1;
168 | break;
169 | case "UTIL":
170 | while (items[i + 1] != "") //Due to multiple cards, perform micro-loop
171 | {
172 | collection.Add("UTIL" + countStep, Convert.ToDouble(items[i + 1]));
173 | countStep++;
174 | i += 2;
175 | }
176 | break;
177 | case "TEMP":
178 | while (items[i + 1] != "REJECTED") //Due to multiple cards, perform micro-loop
179 | {
180 | collection.Add("TEMP" + countStep, Convert.ToDouble(items[i + 1]));
181 | countStep++;
182 | i += 2;
183 | }
184 | break;
185 |
186 | }
187 | i += 1;
188 | }
189 |
190 | string[] Vars = new String[] { "STATUS", "SPEED_TOTAL", "EXEC_RUNTIME_AVG", "CURKU", "PROGRESS1","RECHASH1","RECSALT1" };
191 | foreach (string variable in Vars)
192 | {
193 | if (!collection.ContainsKey(variable))
194 | {
195 | Console.WriteLine("Failed to parse {0} variable, something went wrong", variable);
196 | }
197 | }
198 | }
199 |
200 |
201 | private void parseStatus2(string statusLine, ref Dictionary collection)
202 | {
203 |
204 | CultureInfo customCulture = (CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
205 | customCulture.NumberFormat.NumberDecimalSeparator = ".";
206 | System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
207 |
208 | Match match = Regex.Match(statusLine, ":[0-9]{1,}:[0-9.]{1,}(\n|\r|\r\n)", RegexOptions.IgnoreCase); //Match only the progress line using regex
209 | long counter = 0;
210 | double leftT = 0;
211 | double rightT = 0;
212 |
213 | while (match.Success)
214 | {
215 |
216 | string[] items = match.ToString().TrimEnd().Split(':');
217 |
218 |
219 | collection.Add("LEFT" + counter, Convert.ToDouble(Decimal.Parse(items[1],CultureInfo.InvariantCulture)));
220 | collection.Add("RIGHT" + counter, Convert.ToDouble(Decimal.Parse(items[2], CultureInfo.InvariantCulture)));
221 | leftT += Convert.ToDouble(Decimal.Parse(items[1], CultureInfo.InvariantCulture));
222 | rightT += Convert.ToDouble(Decimal.Parse(items[2], CultureInfo.InvariantCulture));
223 | counter++;
224 | match = match.NextMatch();
225 | }
226 | collection.Add("LEFT_TOTAL" ,leftT);
227 | collection.Add("RIGHT_TOTAL", rightT);
228 |
229 | }
230 |
231 | public Boolean runBenchmark(int benchMethod, int benchSecs, ref Dictionary collection,Boolean legacy)
232 | {
233 |
234 | StringBuilder stdOutBuild = new StringBuilder();
235 |
236 | string suffixArgs = " --restore-disable --potfile-disable --machine-readable --session=hashtopolis";
237 | string suffixExtra = "";
238 |
239 | if (benchMethod == 1)
240 | {
241 | suffixExtra = " --runtime=" + benchSecs;
242 | }
243 | else if (benchMethod == 2)
244 | {
245 | suffixExtra = " --progress-only";
246 | }
247 |
248 | if (legacy) //--weak was removed post HC 3.6, don't issue this command
249 | {
250 | suffixArgs = suffixArgs + "--weak=0" + suffixExtra;
251 | }
252 | else
253 | {
254 | suffixArgs = suffixArgs + suffixExtra;
255 | }
256 |
257 | ProcessStartInfo pInfo = new ProcessStartInfo();
258 | pInfo.FileName = Path.Combine(hcDirectory, hcBinary);
259 |
260 | if (!File.Exists(pInfo.FileName))
261 | {
262 | Console.WriteLine("Could not locate " + pInfo.FileName);
263 | return false;
264 | }
265 |
266 | pInfo.WorkingDirectory = hcDirectory;
267 | pInfo.Arguments = hcArgs + suffixArgs;
268 | pInfo.UseShellExecute = false;
269 | pInfo.RedirectStandardError = true;
270 | pInfo.RedirectStandardOutput = true;
271 |
272 |
273 | if (debugFlag)
274 | {
275 | Console.WriteLine("Using {0} as working directory", filesDir);
276 | Console.WriteLine(pInfo.FileName + pInfo.Arguments);
277 | }
278 |
279 |
280 | Process hcProcBenchmark = new Process();
281 | hcProcBenchmark.StartInfo = pInfo;
282 |
283 | hcProcBenchmark.ErrorDataReceived += (sender, argu) => outputError(argu.Data);
284 |
285 | if (benchMethod == 1)
286 | {
287 | Console.WriteLine("Server requested the client benchmark this task for {0} seconds", benchSecs);
288 |
289 | }
290 | else
291 | {
292 | Console.WriteLine("Server has requested the client perform a speed benchmark");
293 |
294 | }
295 | try
296 | {
297 | hcProcBenchmark.Start();
298 | hcProcBenchmark.BeginErrorReadLine();
299 |
300 | while (!hcProcBenchmark.HasExited)
301 | {
302 | while (!hcProcBenchmark.StandardOutput.EndOfStream)
303 | {
304 |
305 | string stdOut = hcProcBenchmark.StandardOutput.ReadLine().TrimEnd();
306 | stdOutBuild.AppendLine(stdOut);
307 | if (stdOut.Contains("STATUS\t") && benchMethod !=2)
308 | {
309 |
310 | {
311 | parseStatus1(stdOut, ref collection);
312 | }
313 |
314 | break;
315 | }
316 | }
317 | }
318 | hcProcBenchmark.StandardOutput.Close();
319 |
320 | }
321 | finally
322 | {
323 | hcProcBenchmark.Close();
324 | }
325 |
326 | if (stdOutBuild.ToString().Contains("Parsing Hashes: 0/")) //Can read from stderr for no hashes loaded, but this also works.
327 | {
328 | return false;
329 | }
330 | else
331 | {
332 | Console.WriteLine(stdOutBuild.ToString());
333 | }
334 |
335 | if (benchMethod == 2)
336 | {
337 | parseStatus2(stdOutBuild.ToString(),ref collection);
338 | }
339 |
340 | return true;
341 | }
342 |
343 | private static void parseKeyspace(string line, ref long keySpace)
344 | {
345 | line = line.TrimEnd();
346 |
347 | if (!long.TryParse(line, out keySpace))
348 | {
349 | Console.WriteLine("There was an error parsing the keyspace, setting keyspace to 0. Please review attack cmd");
350 | keySpace = 0; //Return 0 which will throw error
351 | }
352 |
353 | }
354 |
355 | public string getVersion2(ref string[] versionNum)
356 | {
357 | ProcessStartInfo pInfo = new ProcessStartInfo();
358 | pInfo.FileName = Path.Combine(hcDir, hcBin);
359 | pInfo.WorkingDirectory = filesDir;
360 | pInfo.Arguments = "--version";
361 | pInfo.UseShellExecute = false;
362 | pInfo.RedirectStandardError = true;
363 | pInfo.RedirectStandardOutput = true;
364 | Process hcGetVersion = new Process();
365 |
366 | hcGetVersion.StartInfo = pInfo;
367 | string versionString = "";
368 |
369 | try
370 | {
371 | hcGetVersion.Start();
372 | versionString = hcGetVersion.StandardOutput.ReadToEnd().TrimEnd();
373 | hcGetVersion.WaitForExit();
374 |
375 | Regex regex = new Regex("v(?[^-]*)");
376 |
377 | Match match = regex.Match(versionString);
378 |
379 | if (match.Success)
380 | {
381 | versionNum = match.Groups["version"].Value.Split('.');
382 |
383 | }
384 | else
385 | {
386 | versionNum = versionString.Split('.'); //Hashcat changed the output after 3.6 to exclude the version string
387 | }
388 | }
389 | catch
390 | {
391 | Console.WriteLine("Something went wrong when trying to get HC version");
392 | }
393 | finally
394 | {
395 | if (hcGetVersion.ExitCode != 0)
396 | {
397 | Console.WriteLine("Something went when trying to get HC version");
398 | }
399 |
400 | hcGetVersion.Close();
401 | }
402 |
403 | return versionString;
404 | }
405 | public string getVersion()
406 | {
407 |
408 | string stdOutSingle = "";
409 | ProcessStartInfo pInfo = new ProcessStartInfo();
410 | pInfo.FileName = Path.Combine(hcDir, hcBin);
411 | pInfo.WorkingDirectory = filesDir;
412 | pInfo.Arguments = "--version";
413 | pInfo.UseShellExecute = false;
414 | pInfo.RedirectStandardError = true;
415 | pInfo.RedirectStandardOutput = true;
416 | Process hcGetVersion = new Process();
417 | hcGetVersion.StartInfo = pInfo;
418 | hcGetVersion.ErrorDataReceived += (sender, argu) => outputError(argu.Data);
419 |
420 | try
421 | {
422 |
423 | hcGetVersion.Start();
424 | while (!hcGetVersion.HasExited)
425 | {
426 | while (!hcGetVersion.StandardOutput.EndOfStream)
427 | {
428 |
429 | string stdOut = hcGetVersion.StandardOutput.ReadLine().TrimEnd();
430 | stdOutSingle = stdOut; //We just want the last line
431 | }
432 | }
433 | hcGetVersion.StandardOutput.Close();
434 |
435 | }
436 | catch
437 | {
438 | Console.WriteLine("Something went wrong when trying to get HC version");
439 | }
440 | finally
441 | {
442 |
443 | hcGetVersion.Close();
444 | }
445 |
446 | return stdOutSingle;
447 |
448 |
449 | }
450 |
451 | public Boolean runKeyspace(ref long keySpace)
452 | {
453 |
454 | Console.WriteLine("Server has requested the client measure the keyspace for this task");
455 |
456 | string stdOutSingle = "";
457 | string suffixArgs = " --session=hashtopolis --keyspace --quiet";
458 | ProcessStartInfo pInfo = new ProcessStartInfo();
459 | pInfo.FileName = Path.Combine(hcDirectory, hcBinary);
460 |
461 | if (!File.Exists(pInfo.FileName))
462 | {
463 | Console.WriteLine("Could not locate " + pInfo.FileName);
464 | return false;
465 | }
466 |
467 | pInfo.WorkingDirectory = hcDirectory;
468 |
469 |
470 | pInfo.Arguments = hcArgs + suffixArgs;
471 | pInfo.UseShellExecute = false;
472 | pInfo.RedirectStandardError = true;
473 | pInfo.RedirectStandardOutput = true;
474 | if (debugFlag)
475 | {
476 | Console.WriteLine("Using {0} as working directory", pInfo.WorkingDirectory);
477 | Console.WriteLine(pInfo.FileName + " " + pInfo.Arguments);
478 | }
479 |
480 | Process hcProcKeyspace = new Process();
481 | hcProcKeyspace.StartInfo = pInfo;
482 | hcProcKeyspace.ErrorDataReceived += (sender, argu) => outputError(argu.Data);
483 |
484 | try
485 | {
486 | hcProcKeyspace.Start();
487 | hcProcKeyspace.BeginErrorReadLine();
488 |
489 | while (!hcProcKeyspace.HasExited)
490 | {
491 | while (!hcProcKeyspace.StandardOutput.EndOfStream)
492 | {
493 | string stdOut = hcProcKeyspace.StandardOutput.ReadLine().TrimEnd();
494 | stdOutSingle = stdOut; //We just want the last line
495 | }
496 | }
497 | hcProcKeyspace.StandardOutput.Close();
498 |
499 | }
500 | catch
501 | {
502 | Console.WriteLine("Something went wrong with keyspace measuring");
503 | }
504 | finally
505 | {
506 | if (hcProcKeyspace.ExitCode != 0)
507 | {
508 | Console.WriteLine("Something went wrong with keyspace measuring");
509 | }
510 |
511 | hcProcKeyspace.Close();
512 | }
513 |
514 | parseKeyspace(stdOutSingle,ref keySpace);
515 |
516 | return true;
517 | }
518 |
519 | public static void outputError(string stdError)
520 | {
521 | if (!string.IsNullOrEmpty(stdError))
522 | {
523 | Console.WriteLine(stdError.Trim());
524 | }
525 |
526 | }
527 |
528 |
529 | //There is very little discruption to the attack as a very quick lock/unlock is performed on the packet list to pop the job off the queue
530 | public void threadReadOutfile(ref List uploadPackets, ref object objPacketlock)
531 | {
532 | System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
533 | customCulture.NumberFormat.NumberDecimalSeparator = ".";
534 | System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
535 |
536 | }
537 |
538 | public void stdOutTrigger(string stdOut)
539 | {
540 |
541 | if (!string.IsNullOrEmpty(stdOut))
542 | {
543 |
544 | if ((!stdOut.Contains("STATUS\t") && (!stdOut.Contains("EXEC_RUNTIME\t")) && (!stdOut.Contains("CURKU\t"))))
545 | {
546 | if (stdOut.StartsWith("Hashfile"))
547 | {
548 | if (!stdOut.Contains("Line-length exception"))
549 | {
550 | lock (crackedLock)
551 | {
552 | hashlist.Add(stdOut);
553 | }
554 | }
555 | else
556 | {
557 | lock (crackedLock)
558 | {
559 | hashlist.Add(stdOut);
560 | }
561 | }
562 | }
563 | else
564 | {
565 | lock (crackedLock)
566 | {
567 | hashlist.Add(stdOut);
568 | }
569 | }
570 | }
571 |
572 | else
573 |
574 | {
575 | lock (statusLock)
576 | {
577 | Dictionary dStats = new Dictionary();
578 |
579 | parseStatus1(stdOut, ref dStats);
580 |
581 |
582 | lock (packetLock)
583 | {
584 | lock (crackedLock)
585 | {
586 | passedPackets.Add(new Packets { statusPackets = new Dictionary(dStats), crackedPackets = new List(hashlist) });
587 | dStats.Clear();
588 | hashlist.Clear();
589 | }
590 | }
591 | }
592 | }
593 |
594 | }
595 | }
596 |
597 |
598 |
599 | public Boolean startAttack(long chunk, long taskID, long skip, long size, long interval, string taskPath)
600 | {
601 |
602 | string oPath = Path.Combine(taskPath, taskID + "_" + chunk + ".txt"); // Path to write th -o file
603 | if (File.Exists(oPath))
604 | {
605 | File.Delete(oPath); // We need to wipe the outfile if it exists since we want to start at pos 0
606 | }
607 |
608 | ProcessStartInfo pInfo = new ProcessStartInfo();
609 |
610 | pInfo.FileName = Path.Combine(hcDir, hcBin);
611 |
612 | if (!File.Exists(pInfo.FileName))
613 | {
614 | Console.WriteLine("Could not locate " + pInfo.FileName);
615 | return false;
616 | }
617 |
618 | pInfo.Arguments = hcArgs + " --potfile-disable --quiet --restore-disable --session=hashtopolis --status --machine-readable --status-timer=" + interval + " --outfile-check-timer=" + interval + " --remove --remove-timer=" + interval + " -s " + skip + " -l " + size;
619 | pInfo.WorkingDirectory = hcDirectory;
620 | pInfo.UseShellExecute = false;
621 | pInfo.RedirectStandardError = true;
622 | pInfo.RedirectStandardOutput = true;
623 |
624 | if (debugFlag)
625 | {
626 | Console.WriteLine(pInfo.FileName + " " + pInfo.Arguments);
627 | }
628 |
629 | hcProc = new Process { };
630 | hcProc.StartInfo = pInfo;
631 | // create event handlers for normal and error output
632 |
633 | hcProc.OutputDataReceived += (sender, argu) => stdOutTrigger(argu.Data);
634 | hcProc.ErrorDataReceived += (sender, argu) => outputError(argu.Data);
635 | hcProc.EnableRaisingEvents = true;
636 | hcProc.Start();
637 | hcProc.BeginOutputReadLine();
638 | hcProc.BeginErrorReadLine();
639 |
640 | hcProc.WaitForExit();
641 | hcProc.CancelErrorRead();
642 | hcProc.CancelOutputRead();
643 | if (debugFlag)
644 | {
645 | Console.WriteLine("Attack finished");
646 | }
647 |
648 |
649 | hcProc.Dispose();
650 |
651 | return true;
652 |
653 | }
654 | }
655 | }
656 |
--------------------------------------------------------------------------------
/hashtopolis/hashcatUpdateClass.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Diagnostics;
8 |
9 | namespace hashtopolis
10 | {
11 |
12 | class hashcatUpdateClass
13 | {
14 |
15 | public class hcUpdateProper
16 | {
17 | public string action = "downloadBinary";
18 | public string type = "cracker";
19 | public string token = "";
20 | public int binaryVersionId = 0;
21 | public int force { set; get; }
22 |
23 | }
24 |
25 | public Boolean debugFlag { get; set; }
26 | public string AppPath { get; set; }
27 | public _7zClass sevenZip { get; set; }
28 | public registerClass client { get; set; }
29 | public int binaryVersionId { get; set; }
30 |
31 |
32 | public bool updateCracker()
33 | {
34 | hcUpdateProper hcUpd = new hcUpdateProper();
35 | jsonClass jsonUpd = new jsonClass { debugFlag = debugFlag, connectURL = client.connectURL };
36 | hcUpd.token = client.tokenID;
37 | hcUpd.binaryVersionId = binaryVersionId;
38 |
39 | string jsonString = jsonUpd.toJson(hcUpd);
40 | string ret = jsonUpd.jsonSend(jsonString);
41 |
42 | if (jsonUpd.isJsonSuccess(ret))
43 | {
44 | string crackerName = jsonUpd.getRetVar(ret, "name");
45 | string fullSubDir = Path.Combine(AppPath, crackerName.ToLower(), binaryVersionId.ToString());
46 | if (!Directory.Exists(fullSubDir)) //We need to download
47 | {
48 | Console.WriteLine("Client doesn't have required cracker...");
49 | downloadClass dlClass = new downloadClass();
50 | if (client.osID != 1)
51 | {
52 | dlClass.DownloadFileCurl(jsonUpd.getRetVar(ret, "url"), Path.Combine(AppPath, "crackerClient.7z"));
53 | }
54 | else
55 | {
56 | dlClass.DownloadFile(jsonUpd.getRetVar(ret, "url"), Path.Combine(AppPath, "crackerClient.7z"));
57 | }
58 |
59 | if (Directory.Exists(Path.Combine(AppPath, "tmp")))
60 | {
61 | Directory.Delete(Path.Combine(AppPath, "tmp"), true);
62 | }
63 |
64 | sevenZip.xtract(Path.Combine(AppPath, "crackerClient.7z"), Path.Combine(AppPath, "tmp"));
65 |
66 | //check if files present
67 |
68 | string[] files = Directory.GetFiles(Path.Combine(AppPath, "tmp"));
69 | if (files.Length != 0)
70 | {
71 | Directory.Move(Path.Combine(AppPath, "tmp"), fullSubDir);
72 | }
73 | else
74 | {
75 | string[] dirs = Directory.GetDirectories(Path.Combine(AppPath, "tmp"));
76 | Directory.Move(dirs[0], fullSubDir);
77 | }
78 |
79 | Directory.Delete(Path.Combine(AppPath, "tmp"));
80 | string binLocation = Path.Combine(fullSubDir, jsonUpd.getRetVar(ret, "executable"));
81 |
82 | if (client.osID != 1) //Chmod for non windows
83 | {
84 | Console.WriteLine("Applying execution permissions to cracker binary");
85 | Process.Start("chmod", "+x \"" + binLocation + "\"");
86 | }
87 |
88 | //May need to inplement legacy checks if cracker is hashcat
89 | }
90 | else
91 | {
92 | Console.WriteLine("Client already exists, skipping download");
93 | }
94 | client.crackerBinary = jsonUpd.getRetVar(ret, "executable");
95 |
96 |
97 | if (client.is64Bit)
98 | {
99 | client.crackerBinary = client.crackerBinary.Replace(".", "64.");
100 | }
101 | else
102 | {
103 | client.crackerBinary = client.crackerBinary.Replace(".", "32.");
104 | }
105 |
106 |
107 |
108 | client.crackerPath = Path.Combine(AppPath, crackerName.ToLower(), binaryVersionId.ToString());
109 | }
110 |
111 |
112 | if (Directory.Exists(client.crackerPath))
113 | {
114 | return true;
115 | }
116 | else
117 | {
118 | Console.WriteLine("Could not locate cracker, perhaps manually delete cracker " + binaryVersionId.ToString());
119 | return false;
120 | }
121 | }
122 |
123 |
124 | public bool updateHashcat()
125 | {
126 | hcUpdateProper hcUpd = new hcUpdateProper();
127 | jsonClass jsonUpd = new jsonClass { debugFlag = debugFlag, connectURL = client.connectURL };
128 | hcUpd.token = client.tokenID;
129 | string hcBinName = "hashcat";
130 | if (client.osID == 0)
131 | {
132 | hcBinName = hcBinName + "64.bin";
133 | }
134 | else if (client.osID == 1)
135 | {
136 | hcBinName = hcBinName + "64.exe";
137 | }
138 |
139 | string hcBinLoc = Path.Combine(AppPath, "hashcat", hcBinName);
140 |
141 | if (File.Exists(hcBinLoc))
142 | {
143 | hcUpd.force = 0; //HC exists, we don't need to force
144 | }
145 | else
146 | {
147 | hcUpd.force = 1; //HC doesn't exist, we need to force
148 | }
149 |
150 | string jsonString = jsonUpd.toJson(hcUpd);
151 | string ret = jsonUpd.jsonSend(jsonString);
152 |
153 | if (jsonUpd.getRetVar(ret, "version") == "NEW")
154 | {
155 | downloadClass dlClass = new downloadClass();
156 |
157 | if (client.osID != 1)
158 | {
159 | dlClass.DownloadFileCurl(jsonUpd.getRetVar(ret, "url"), Path.Combine(AppPath, "hcClient.7z"));
160 | }
161 | else
162 | {
163 | dlClass.DownloadFile(jsonUpd.getRetVar(ret, "url"), Path.Combine(AppPath, "hcClient.7z"));
164 | }
165 |
166 | sevenZip.xtract(Path.Combine(AppPath, "hcClient.7z"), Path.Combine(AppPath, "hcClient"));
167 | if (Directory.Exists(Path.Combine(AppPath, "hashcat")))
168 | {
169 | Directory.Delete(Path.Combine(AppPath, "hashcat"), true);
170 | }
171 | Directory.Move(Path.Combine(AppPath, "hcClient", jsonUpd.getRetVar(ret, "rootdir")), Path.Combine(AppPath, "hashcat"));
172 | Directory.Delete(Path.Combine(AppPath, "hcClient"));
173 |
174 |
175 | if (client.osID != 1) //Chmod for non windows
176 | {
177 | Console.WriteLine("Applying execution permissions to 7zr binary");
178 | Process.Start("chmod", "+x \"" + hcBinLoc + "\"");
179 | }
180 | }
181 |
182 | if (File.Exists(hcBinLoc))
183 | {
184 | return true;
185 | }
186 |
187 | return false;
188 |
189 | }
190 |
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/hashtopolis/hashtopolis.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {199AD37B-3000-4CC0-992C-87738F84C768}
8 | Exe
9 | Properties
10 | hashtopolis
11 | hashtopolis
12 | v4.5
13 | 512
14 | true
15 |
16 |
17 |
18 | AnyCPU
19 | true
20 | full
21 | false
22 | bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 | false
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 | false
37 |
38 |
39 | true
40 | bin\x64\Debug\
41 | DEBUG;TRACE
42 | full
43 | x64
44 | prompt
45 | MinimumRecommendedRules.ruleset
46 | false
47 |
48 |
49 | bin\x64\Release\
50 | TRACE
51 | true
52 | pdbonly
53 | x64
54 | prompt
55 | MinimumRecommendedRules.ruleset
56 | false
57 |
58 |
59 | small.ico
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
99 |
--------------------------------------------------------------------------------
/hashtopolis/hashtopolis.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/hashtopolis/jsonClass.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Net;
5 | using System.Collections;
6 | using System.Web.Script.Serialization;
7 | using System.Linq;
8 | using System.Threading;
9 |
10 | public class jsonClass
11 | {
12 |
13 | public Boolean debugFlag { get; set; }
14 | public string connectURL { get; set; }
15 | Random rnd = new Random(Guid.NewGuid().GetHashCode()); //init and seed the random generator for use in re-try backdown
16 | JavaScriptSerializer jss = new JavaScriptSerializer();
17 | //Checks if json string has success response
18 | //Will print the error messages on fail
19 | public Boolean isJsonSuccess(string jsonString)
20 | {
21 | jss.MaxJsonLength = 2147483647;
22 |
23 | if (debugFlag)
24 | Console.WriteLine(jsonString);
25 |
26 | try
27 | {
28 | Dictionary dict = jss.Deserialize>(jsonString);
29 |
30 | if (dict.ContainsKey("response"))
31 | {
32 | if (dict["response"] == "SUCCESS")
33 | {
34 | return true;
35 | }
36 | else
37 | {
38 | Console.WriteLine(dict["response"]);
39 | if (dict.ContainsKey("message"))
40 | {
41 | Console.WriteLine(dict["message"]);
42 | }
43 | }
44 | }
45 | return false;
46 | }
47 | catch (Exception e)
48 | {
49 | Console.WriteLine(e.Data);
50 | Console.WriteLine("Empty string for success check");
51 | return false;
52 | }
53 |
54 | }
55 |
56 |
57 | //Returns variable from json string, values are casted to string
58 | public string getRetVar(string jsonString, string itemVar)
59 | {
60 | jss.MaxJsonLength = 2147483647;
61 |
62 | try
63 | {
64 | var dict = jss.Deserialize>(jsonString);
65 | if (dict.ContainsKey(itemVar))
66 | {
67 | return Convert.ToString(dict[itemVar]);
68 | }
69 | }
70 | catch(Exception e)
71 | {
72 | Console.WriteLine(e);
73 | Console.WriteLine("Error while trying to get {0} from jaon string", itemVar);
74 | }
75 |
76 |
77 | return null;
78 | }
79 |
80 | //Returns json string array to arraylist
81 | //This is probably redundant as we can use the below function gerRetList to return a better typed array
82 | public ArrayList getRetArray(string jsonString, string itemVar)
83 | {
84 | jss.MaxJsonLength = 2147483647;
85 |
86 | var dict = jss.Deserialize>(jsonString);
87 | if (dict.ContainsKey(itemVar))
88 | {
89 | return dict[itemVar];
90 | }
91 |
92 | return null;
93 | }
94 |
95 | //Return json string array to list with type string
96 | public List getRetList(string jsonString, string itemVar)
97 | {
98 | jss.MaxJsonLength = 2147483647;
99 |
100 | var dict = jss.Deserialize>(jsonString);
101 | if (dict.ContainsKey(itemVar))
102 | {
103 | List newList = new List(dict[itemVar].ToArray(typeof(string))); //Convert Array to List
104 | return newList;
105 | }
106 |
107 | return dict[itemVar];
108 | }
109 |
110 | //Converts array=>key to jason string format
111 | public string toJson(object obj)
112 | {
113 | jss.MaxJsonLength = 2147483647;
114 |
115 | var json = jss.Serialize(obj);
116 | if (debugFlag)
117 | Console.WriteLine(json);
118 | return json;
119 | }
120 |
121 |
122 | public string jsonSendOnce(string json)
123 | {
124 | var request = (HttpWebRequest)WebRequest.Create(connectURL);
125 | request.ContentType = "application/json";
126 | request.Method = "POST";
127 | request.KeepAlive = false;
128 |
129 | int randomTime = 0;
130 |
131 | HttpWebResponse response = null;
132 | int tries = 0;
133 | {
134 | Thread.Sleep(tries * 1000 + randomTime * 1000);
135 | try
136 | {
137 | using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream()))
138 | {
139 | streamWriter.Write(json);
140 | }
141 |
142 | }
143 | catch (WebException ex)
144 | {
145 | Console.WriteLine(ex.Message);
146 | return null ;
147 | }
148 | catch (Exception ex)
149 | {
150 | Console.WriteLine(ex.Message);
151 | return null;
152 | }
153 |
154 | try
155 | {
156 | response = (HttpWebResponse)request.GetResponse();
157 | string result;
158 | using (var streamReader = new StreamReader(response.GetResponseStream()))
159 | {
160 | result = streamReader.ReadToEnd();
161 | }
162 |
163 | return result;
164 | }
165 | catch(WebException ex)
166 | {
167 | Console.WriteLine(ex.Message);
168 | }
169 |
170 |
171 | return null;
172 |
173 | }
174 | }
175 |
176 | //On fail, the client will use a backdown algorithm and retry 30 times
177 | public string jsonSend(string json, int timeOutSecs = 30)
178 | {
179 |
180 | int tries = 0;
181 | int randomTime = 0;
182 | string result = null;
183 |
184 | do
185 | {
186 | Thread.Sleep(tries * 1000 + randomTime * 1000);
187 |
188 | try
189 | {
190 |
191 | var request = (HttpWebRequest)WebRequest.Create(connectURL);
192 | request.ContentType = "application/json";
193 | request.Method = "POST";
194 | request.Timeout = timeOutSecs * 1000;
195 | request.KeepAlive = true;
196 |
197 | HttpWebResponse response = null;
198 |
199 | using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream()))
200 | {
201 | streamWriter.Write(json);
202 | }
203 |
204 |
205 | response = (HttpWebResponse)request.GetResponse();
206 | if (response.StatusCode != HttpStatusCode.OK)
207 | {
208 | Console.WriteLine("Invalid HTTP response");
209 | Console.WriteLine("terminating");
210 | Environment.Exit(0);
211 | }
212 |
213 |
214 | using (var streamReader = new StreamReader(response.GetResponseStream()))
215 | {
216 | result = streamReader.ReadToEnd();
217 | }
218 | if (string.IsNullOrEmpty(result))
219 | {
220 | Console.WriteLine("server is not responding to requests");
221 | Console.WriteLine("terminating");
222 | Environment.Exit(0);
223 | }
224 | break;
225 | }
226 |
227 | catch (WebException ex)
228 | {
229 | if (ex.Status == WebExceptionStatus.Timeout)
230 | {
231 | Console.WriteLine("Server timed out");
232 | Console.WriteLine(ex.Message);
233 | tries++;
234 | randomTime = rnd.Next(1, tries);
235 | Console.WriteLine("Attempting to re-connect in {0} seconds", tries + randomTime);
236 | }
237 | }
238 | catch (Exception)
239 | {
240 | Console.WriteLine("Could not connect to specified server, exiting");
241 | tries++;
242 | randomTime = rnd.Next(1, tries);
243 | Console.WriteLine("Attempting to re-connect in {0} seconds", tries + randomTime);
244 | }
245 |
246 | } while (tries <= 10);
247 |
248 |
249 | return result; //Return json string
250 |
251 | }
252 |
253 |
254 | }
--------------------------------------------------------------------------------
/hashtopolis/registerClass.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Management;
5 | using System.Diagnostics;
6 | using System.Runtime.InteropServices;
7 |
8 | public class registerClass
9 | {
10 | private string tokenPath;
11 | public string tokenID { get; set; }
12 | public int osID { get; set; }
13 | public Boolean is64Bit { get; set; }
14 | public string connectURL { get; set; }
15 | public Boolean debugFlag { set; get; }
16 | public string crackerPath { set; get; }
17 | public string crackerBinary { set; get; }
18 |
19 | //Suppress P/Invoke warning my using NativeMethods
20 | internal static class NativeMethods
21 | {
22 | [DllImport("libc")]
23 | public static extern int uname(IntPtr buf);
24 | }
25 |
26 | //Code from Pinta Core Project
27 | private bool IsRunningOnMac()
28 | {
29 |
30 | IntPtr buf = IntPtr.Zero;
31 | try
32 | {
33 | buf = Marshal.AllocHGlobal(8192);
34 | // This is a hacktastic way of getting sysname from uname ()
35 | if (NativeMethods.uname(buf) == 0)
36 | {
37 | string os = Marshal.PtrToStringAnsi(buf);
38 | if (os == "Darwin")
39 | return true;
40 | }
41 | }
42 | catch
43 | {
44 | }
45 | finally
46 | {
47 | if (buf != IntPtr.Zero)
48 | Marshal.FreeHGlobal(buf);
49 | }
50 | return false;
51 | }
52 |
53 | //Code to run commands
54 | private static string ReadProcessOutput(string procName, string args)
55 | {
56 | try
57 | {
58 | Process p = new Process();
59 | p.StartInfo.UseShellExecute = false;
60 | p.StartInfo.RedirectStandardOutput = true;
61 | if (args != null && args != "") p.StartInfo.Arguments = " " + args;
62 | p.StartInfo.FileName = procName;
63 | p.Start();
64 | string output = p.StandardOutput.ReadToEnd();
65 | p.WaitForExit();
66 | if (output == null) output = "";
67 | output = output.Trim();
68 | return output;
69 | }
70 | catch
71 | {
72 | return "";
73 | }
74 | }
75 |
76 | //Detect whether we are running under mono
77 | private void setOS()
78 | {
79 | is64Bit = false; //Default to 32bit unless 64bit detected
80 | if (Type.GetType("Mono.Runtime") != null)
81 | {
82 |
83 | string machine = ReadProcessOutput("uname", "-m");
84 | if (machine.Contains("x86_64"))
85 | {
86 | is64Bit = true;
87 | }
88 |
89 | if (!IsRunningOnMac())
90 | {
91 |
92 | if (is64Bit)
93 | {
94 | Console.WriteLine("System is Linux 64-bit");
95 | }
96 | else
97 | {
98 | Console.WriteLine("System is Linux 32-bit");
99 | }
100 | osID = 0;
101 | }
102 | else
103 | {
104 | if (is64Bit)
105 | {
106 | Console.WriteLine("System is MAC 64-bit");
107 | }
108 | else
109 | {
110 | Console.WriteLine("System is MAC 32-bit");
111 | };
112 | osID = 2;
113 | }
114 |
115 |
116 |
117 | }
118 | else
119 | {
120 |
121 | if (Environment.Is64BitProcess)
122 | {
123 | Console.WriteLine("System is Windows 64-bit");
124 | is64Bit = true;
125 | }
126 | else
127 | {
128 | Console.WriteLine("System is Windows 32-bit");
129 | }
130 | osID = 1;
131 | }
132 |
133 | }
134 |
135 | public void setPath(string path)
136 | {
137 | tokenPath = Path.Combine(path,"token");
138 | }
139 |
140 | private class Register
141 | {
142 | public string action { get; set; }
143 | public string voucher { get; set; }
144 | public string name { get; set; }
145 | }
146 |
147 | private class UpdateClient
148 | {
149 | public string action { get; set; }
150 | public string token { get; set; }
151 | public string uid { get; set; }
152 | public int os { get; set; }
153 | public IList devices { get; set; }
154 | }
155 |
156 |
157 | private bool registerAgent(string iVoucher)
158 | {
159 | jsonClass jsC = new jsonClass { debugFlag = debugFlag, connectURL = connectURL };
160 | string machineName = "default";
161 | setOS();
162 |
163 | if (osID == 1) //Windows
164 | {
165 | machineName = System.Environment.MachineName;
166 | }
167 | else if (osID == 0) //Linux
168 | {
169 | ProcessStartInfo pinfo = new ProcessStartInfo();
170 | pinfo = new ProcessStartInfo();
171 | pinfo.FileName = "uname";
172 | pinfo.Arguments = "-n";
173 | pinfo.UseShellExecute = false;
174 | pinfo.RedirectStandardOutput = true;
175 | Process uname = new Process();
176 | uname.StartInfo = pinfo;
177 | uname.Start();
178 | while (!uname.HasExited)
179 | {
180 | while (!uname.StandardOutput.EndOfStream)
181 | {
182 | string stdOut = uname.StandardOutput.ReadLine();
183 | machineName = stdOut;
184 | }
185 | }
186 | }
187 | else if (osID == 2) //Mac
188 | {
189 | //Get Machine Name (Mac)
190 | ProcessStartInfo pinfo = new ProcessStartInfo();
191 | pinfo.FileName = "scutil";
192 | pinfo.Arguments = " --get ComputerName";
193 | pinfo.UseShellExecute = false;
194 | pinfo.RedirectStandardError = true;
195 | pinfo.RedirectStandardOutput = true;
196 |
197 | Process getMachineName = new Process();
198 | getMachineName.StartInfo = pinfo;
199 | getMachineName.Start();
200 | while (!getMachineName.HasExited)
201 | {
202 | while (!getMachineName.StandardOutput.EndOfStream)
203 | {
204 | string stdOut = getMachineName.StandardOutput.ReadLine();
205 | machineName = stdOut;
206 | }
207 | }
208 |
209 | }
210 |
211 | Register regist = new Register
212 | {
213 | action = "register",
214 | voucher = iVoucher,
215 | name = machineName,
216 | };
217 |
218 | string jsonString = jsC.toJson(regist);
219 | string ret = jsC.jsonSend(jsonString);
220 |
221 | String guid = Guid.NewGuid().ToString(); //Generate GUID
222 |
223 | if (jsC.isJsonSuccess(ret))
224 | {
225 | tokenID = jsC.getRetVar(ret, "token");
226 | File.WriteAllText(tokenPath, tokenID);
227 |
228 | updateAgentInformation();
229 |
230 | return true;
231 | }
232 | return false;
233 |
234 | }
235 |
236 |
237 |
238 | private bool updateAgentInformation()
239 | {
240 | Console.WriteLine("Sending server client information");
241 | jsonClass jsC = new jsonClass { debugFlag = debugFlag, connectURL = connectURL };
242 |
243 | setOS();
244 |
245 |
246 | List deviceList;
247 | string CPUModel = "";
248 |
249 | deviceList = new List { };
250 |
251 | if (osID == 1)
252 | {
253 | ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Description FROM Win32_VideoController"); //Prep object to query windows GPUs
254 |
255 | //Get Devices (Windows)
256 | foreach (ManagementObject mo in searcher.Get())
257 | {
258 | deviceList.Add(mo.Properties["Description"].Value.ToString().Trim());
259 | }
260 |
261 | //Get CPU (Windows)
262 | searcher = new ManagementObjectSearcher("SELECT Name from Win32_Processor"); //Prep object to query windows CPUs
263 | foreach (ManagementObject mo in searcher.Get())
264 | {
265 | deviceList.Add(mo.Properties["Name"].Value.ToString().Trim());
266 | }
267 |
268 | }
269 | else if(osID == 0)
270 | {
271 |
272 | //Get GPU Devices (Linux) use lspci to query GPU
273 | ProcessStartInfo pinfo = new ProcessStartInfo();
274 | pinfo.FileName = "lspci";
275 | pinfo.UseShellExecute = false;
276 | pinfo.RedirectStandardOutput = true;
277 | Process lspci = new Process();
278 | lspci.StartInfo = pinfo;
279 | lspci.Start();
280 | List searchList = new List(new string[] { "VGA compatible controller: ", "3D controller: "});
281 |
282 |
283 | while (!lspci.HasExited)
284 | {
285 | while (!lspci.StandardOutput.EndOfStream)
286 | {
287 | string stdOut = lspci.StandardOutput.ReadLine();
288 | foreach (string searchItem in searchList)
289 | {
290 | int pozi = stdOut.IndexOf(searchItem);
291 | if (pozi != -1)
292 | {
293 | deviceList.Add(stdOut.Substring(pozi + searchItem.Length));
294 | }
295 | }
296 |
297 | }
298 | }
299 |
300 | //Get CPU (Linux) use lscpu to query CPU
301 | pinfo.FileName = "lscpu";
302 | pinfo.UseShellExecute = false;
303 | pinfo.RedirectStandardOutput = true;
304 | lspci.StartInfo = pinfo;
305 | lspci.Start();
306 | string searchString = "Model Name: ";
307 | while (!lspci.HasExited)
308 | {
309 | while (!lspci.StandardOutput.EndOfStream)
310 | {
311 | string stdOut = lspci.StandardOutput.ReadLine();
312 | int pos = stdOut.IndexOf(searchString);
313 | if (pos != -1)
314 | {
315 | deviceList.Add(stdOut.Substring(pos + searchString.Length));
316 | }
317 | }
318 | }
319 | }
320 | else if(osID == 2)
321 | {
322 | //Get Machine Name (Mac)
323 | ProcessStartInfo pinfo = new ProcessStartInfo();
324 | pinfo.FileName = "scutil";
325 | pinfo.Arguments = " --get ComputerName";
326 | pinfo.UseShellExecute = false;
327 | pinfo.RedirectStandardError = true;
328 | pinfo.RedirectStandardOutput = true;
329 |
330 |
331 | //Get Devices (Mac)
332 | pinfo.FileName = "system_profiler";
333 | pinfo.Arguments = " -detaillevel mini";
334 | Process getDevices = new Process();
335 | getDevices.StartInfo = pinfo;
336 |
337 | Console.WriteLine("Please wait while devices are being enumerated...");
338 | getDevices.Start();
339 | Boolean triggerRead = false;
340 |
341 | string searchID = "Chipset Model: ";
342 |
343 | while (!getDevices.StandardOutput.EndOfStream)
344 | {
345 |
346 | string stdOut = getDevices.StandardOutput.ReadLine().TrimEnd();
347 |
348 | if (triggerRead == true)
349 | {
350 | if (stdOut.Contains("Total Number of Cores:")) //Just incase we go past
351 | {
352 | break;
353 | }
354 | if (stdOut.Contains("Hardware:"))
355 | {
356 | searchID = "Processor Name: ";
357 | }
358 | int pos = stdOut.IndexOf(searchID);
359 |
360 | if (pos != -1)
361 | {
362 | if (searchID == "Chipset Model: ")
363 | {
364 |
365 | deviceList.Add(stdOut.Substring(pos + searchID.Length));
366 |
367 | }
368 | else if (searchID == "Processor Name: ")
369 | {
370 | CPUModel = stdOut.Substring(pos + searchID.Length);
371 | searchID = "Processor Speed: ";
372 | }
373 | else if (searchID == "Processor Speed: ")
374 | {
375 | CPUModel = CPUModel + " @ " + stdOut.Substring(pos + searchID.Length);
376 | deviceList.Add(CPUModel);
377 | break;
378 | }
379 | }
380 | }
381 | else if (triggerRead == false)
382 | {
383 | if (stdOut.Contains("Graphics/Displays:"))
384 | {
385 | triggerRead = true;
386 | }
387 | }
388 |
389 |
390 | }
391 | }
392 |
393 | String guid = Guid.NewGuid().ToString(); //Generate GUID
394 |
395 | UpdateClient update = new UpdateClient
396 | {
397 | action = "updateInformation",
398 | token = tokenID,
399 | uid = guid,
400 | os = osID,
401 | devices = deviceList
402 | };
403 |
404 | string jsonString = jsC.toJson(update);
405 | string ret = jsC.jsonSend(jsonString);
406 |
407 | if (jsC.isJsonSuccess(ret))
408 | {
409 | return true;
410 | }
411 | return false;
412 |
413 | }
414 | public bool loginAgent()
415 | {
416 | if (!loadToken())
417 | {
418 | Console.WriteLine("Unable to find existing token, please enter voucher");
419 | while (registerAgent(Console.ReadLine()) == false)
420 | {
421 | Console.WriteLine("Invalid voucher, please try again");
422 | }
423 |
424 | }
425 | else
426 | {
427 | Console.WriteLine("Existing token found");
428 | jsonClass jsC = new jsonClass { connectURL = connectURL, debugFlag = debugFlag };
429 |
430 | var arrayKey = new Dictionary
431 | {
432 | { "action", "login" },
433 | { "clientSignature", "generic-csharp"},
434 | { "token",tokenID},
435 | };
436 |
437 | string jsonString = jsC.toJson(arrayKey);
438 | string ret = jsC.jsonSend(jsonString);
439 |
440 | if (jsC.isJsonSuccess(ret))
441 | {
442 | updateAgentInformation();
443 | return true;
444 | }
445 | else
446 | {
447 | Console.WriteLine("Existing token is invalid, please enter voucher");
448 | while (registerAgent(Console.ReadLine()) == false)
449 | {
450 | Console.WriteLine("Invalid voucher, please try again");
451 | }
452 | }
453 | return false;
454 | }
455 | return true;
456 |
457 | }
458 |
459 | public bool loadToken()
460 | {
461 |
462 | if (tokenID == "")
463 | {
464 | if (File.Exists(tokenPath))
465 | {
466 | tokenID = File.ReadAllText(tokenPath);
467 | if (tokenID == "")
468 | {
469 | File.Delete(tokenPath);
470 | return false;
471 | }
472 | }
473 | else
474 | {
475 | return false;
476 | }
477 | setOS();
478 | }
479 |
480 | return true;
481 | }
482 |
483 | }
484 |
--------------------------------------------------------------------------------
/hashtopolis/small.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hashtopolis/agent-csharp/f5980387abc18203407d803d55bb84ac95f8b7b5/hashtopolis/small.ico
--------------------------------------------------------------------------------
/hashtopolis/taskClass.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.IO;
4 | using System.Collections.Generic;
5 | using System.Threading;
6 |
7 | namespace hashtopolis
8 | {
9 | class taskClass
10 | {
11 |
12 | hashcatClass hcClass = new hashcatClass();
13 |
14 | private string attackcmd;
15 | private string cmdpars;
16 | private Boolean stipPath;
17 | private string actualHLpath;
18 | private int benchTime, hashlistID, taskID, statusTimer, benchMethod, crackerId;
19 | private ArrayList files;
20 | private string hashlistAlias = "#HL#";
21 |
22 | private string prefixServerdl = "";
23 |
24 | private long chunkNo, skip, length;
25 | private string filepath, hashpath, appPath, zapPath, tasksPath;
26 |
27 | public Boolean debugFlag { get; set; }
28 | public _7zClass sevenZip { get; set; }
29 | public registerClass client { get; set; }
30 | public Boolean legacy { get; set; }
31 | private int offset = 0;
32 |
33 | public void setOffset()
34 | {
35 | if (!legacy)
36 | {
37 | offset = 1;
38 | Console.WriteLine("Using new STATUS codes");
39 | }
40 | else
41 | {
42 | Console.WriteLine("Using legacy STATUS codes");
43 | }
44 | }
45 |
46 |
47 | private List primaryCracked; //Stores the cracked hashes as they come
48 | private object packetLock = new object(); //Lock to prevent the packetList from being edited as it's passed between the periodicUpload thread and the stdOut reader in hashcatClass
49 |
50 | public void setDirs(string fpath)
51 | {
52 | appPath = fpath;
53 | filepath = Path.Combine(fpath, "files");
54 | hashpath = Path.Combine(fpath, "hashlists");
55 | zapPath = Path.Combine(fpath, "hashlists", "zaps");
56 | tasksPath = Path.Combine(fpath, "tasks");
57 | prefixServerdl = client.connectURL.Substring(0, client.connectURL.IndexOf("/api/")) + "/";
58 |
59 | }
60 |
61 | private class Task
62 | {
63 | public string action { get; set; }
64 | public string token { get; set; }
65 | }
66 |
67 | private class FileProps
68 | {
69 | public string action { get; set; }
70 | public string token { get; set; }
71 | public int taskId { get; set; }
72 | public string file { get; set; }
73 | }
74 |
75 |
76 | private class chunkProps
77 | {
78 | public string action = "getChunk";
79 | public string token { get; set; }
80 | public int taskId { get; set; }
81 | }
82 |
83 | private class hashlistProps
84 | {
85 | public string action = "getHashlist";
86 | public string token { get; set; }
87 | public int hashlistId { get; set; }
88 | }
89 |
90 | private class keyspaceProps
91 | {
92 | public string action = "sendKeyspace";
93 | public string token { get; set; }
94 | public int taskId { get; set; }
95 | public long keyspace { get; set; }
96 | }
97 |
98 | private class benchProps
99 | {
100 | public string action = "sendBenchmark";
101 | public string token { get; set; }
102 | public int taskId { get; set; }
103 | public string type { get; set; }
104 | public string result { get; set; }
105 | }
106 |
107 | private class errorProps
108 | {
109 | public string action = "clientError";
110 | public string token { get; set; }
111 | public int taskId { get; set; }
112 | public string message { get; set; }
113 | }
114 |
115 | private class solveProps
116 | {
117 | public string action = "sendProgress";
118 | public string token { get; set; }
119 | public long chunkId { get; set; }
120 | public double keyspaceProgress { get; set; }
121 | public double relativeProgress { get; set; }
122 | //public double total { get; set; }
123 | public double speed { get; set; }
124 | public double state { get; set; }
125 | public List cracks { get; set; }
126 | }
127 |
128 | public Boolean getHashes(int inTask)
129 | {
130 |
131 | actualHLpath = Path.Combine(hashpath, Path.GetFileName(inTask.ToString()));
132 |
133 | Console.WriteLine("Downloading hashlist for this task, please wait...");
134 |
135 | hashlistProps hProps = new hashlistProps
136 | {
137 | token = client.tokenID,
138 | hashlistId = inTask
139 | };
140 | jsonClass jsC = new jsonClass { debugFlag = debugFlag, connectURL = client.connectURL };
141 | string jsonString = jsC.toJson(hProps);
142 | string ret = jsC.jsonSend(jsonString,300); //300 second timeout
143 |
144 | if (jsC.isJsonSuccess(ret))
145 | {
146 |
147 | getURLtoFile(jsC.getRetVar(ret, "url"), actualHLpath);
148 | }
149 |
150 |
151 | /*
152 | //Check if is json string, a nasty workaround copies from the javaclient to detect whether the return string is json vs hl. Should probably use a proper detector
153 | if (ret[0] != '{' && ret[ret.Length - 1] != '}')
154 | {
155 | File.WriteAllText(actualHLpath, ret);
156 | Directory.CreateDirectory(Path.Combine(hashpath, "zaps" + inTask.ToString()));
157 | }
158 | else
159 | {
160 | if (jsC.isJsonSuccess(ret))
161 | {
162 | string b64data = jsC.getRetVar(ret,"data");
163 | byte[] binArray = System.Convert.FromBase64String(b64data);
164 | File.WriteAllBytes(actualHLpath, binArray);
165 | stipPath = true; //Strip path for all HL recieved binary hashlsits
166 |
167 | }
168 | else
169 | {
170 | return false;
171 | }
172 |
173 | }
174 | */
175 |
176 | return true;
177 | }
178 |
179 | public string speedCalc(double speed)
180 | {
181 | int count = 0;
182 | while (speed > 1000)
183 | {
184 | speed = speed / 1000;
185 | count++;
186 | }
187 |
188 | speed = Math.Round(speed, 2);
189 |
190 | if (count == 0)
191 | {
192 | return speed.ToString("F") + "H/s";
193 | }
194 | else if (count == 1)
195 | {
196 | return speed.ToString("F") + "KH/s";
197 | }
198 | else if (count == 2)
199 | {
200 | return speed.ToString("F") + "MH/s";
201 | }
202 | else if (count == 3)
203 | {
204 | return speed.ToString("F") + "GH/s";
205 | }
206 | else if (count == 4)
207 | {
208 | return speed.ToString("F") + "TH/s";
209 | }
210 | return speed.ToString("F");
211 | }
212 |
213 |
214 | //This runs as an independant thread and uploads the STATUS generated from the hcAttack
215 | //This thread is run on a dynamic timer based on the size of the queue and will range from a base 2500ms down to 200ms
216 | //There is very little discruption to the attack as a very quick lock/unlock is performed on the packet list to pop the job off the queue
217 | public void threadPeriodicUpdate(ref List uploadPackets, ref object objPacketlock)
218 | {
219 | System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
220 | customCulture.NumberFormat.NumberDecimalSeparator = ".";
221 | System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
222 |
223 | jsonClass jsC = new jsonClass {debugFlag = debugFlag, connectURL = client.connectURL };//Initis the json class
224 | solveProps sProps = new solveProps(); //Init the properties to build our json string
225 | List receivedZaps = new List { }; //List to store incoming zaps for writing
226 | string ret =""; //Return string from json post
227 | string jsonString ="";
228 | string zapfilePath = zapPath + hashlistID.ToString();
229 | long zapCount = 0;
230 | List batchList = new List { };
231 | double chunkPercent = 0;
232 | double chunkStart = 0;
233 | Boolean run = true;
234 | List singlePacket = new List { };
235 | int sleepTime = 2500;
236 | long ulQueue = 0;
237 | hcClass.debugFlag = debugFlag;
238 | Boolean firstRun = true;
239 |
240 | string oPath = Path.Combine(tasksPath, taskID + "_" + chunkNo + ".txt"); // Path to write th -o file
241 |
242 | while (run)
243 | {
244 | Thread.Sleep(sleepTime); //Delay this thread for 2.5 seconds, if this falls behind it will batch the jobs
245 | lock (objPacketlock)
246 | {
247 | if (uploadPackets.Count > 0)
248 | {
249 | singlePacket.Add(uploadPackets[0]);
250 | ulQueue = uploadPackets.Count;
251 | uploadPackets.RemoveAt(0);
252 | if (uploadPackets.Count > 3)
253 |
254 | sleepTime = 200; //Decrese the time we process the queue
255 | }
256 | else
257 | {
258 | sleepTime = 5000; //Decrese the time we process the queue
259 | }
260 | firstRun = false;
261 | }
262 |
263 | if (firstRun == true) //This is a work around to send a server a dummy stat to prevent timeouts on the initial start
264 | {
265 |
266 | sProps.token = client.tokenID;
267 | sProps.chunkId = chunkNo;
268 | sProps.keyspaceProgress = skip;
269 |
270 | sProps.relativeProgress = 0;
271 |
272 | sProps.speed = 0;
273 | sProps.state = 3; //Can't find the status code list lets try 3
274 | sProps.cracks = new List();
275 |
276 | jsonString = jsC.toJson(sProps);
277 | ret = jsC.jsonSend(jsonString);
278 |
279 | if (!jsC.isJsonSuccess(ret)) //If we received error, eg task was removed just break
280 | {
281 | break;
282 | }
283 | }
284 |
285 | if (singlePacket.Count == 0)
286 | {
287 | firstRun = false;
288 | continue;
289 | }
290 |
291 | try
292 | {
293 | {
294 | //Special override as there is a possible race condition in HC, where STATUS4 doesn't give 100%
295 | if (singlePacket[0].statusPackets["STATUS"] == 4 + offset)
296 | {
297 | singlePacket[0].statusPackets["PROGRESS1"] = singlePacket[0].statusPackets["PROGRESS2"];
298 | }
299 |
300 | sProps.token = client.tokenID;
301 | sProps.chunkId = chunkNo;
302 | sProps.keyspaceProgress = singlePacket[0].statusPackets["CURKU"];
303 |
304 |
305 | chunkStart = Math.Floor(singlePacket[0].statusPackets["PROGRESS2"]) / (skip + length) * skip;
306 | chunkPercent = Math.Round((Convert.ToDouble(singlePacket[0].statusPackets["PROGRESS1"]) - chunkStart) / Convert.ToDouble(singlePacket[0].statusPackets["PROGRESS2"] - chunkStart), 4) * 10000;
307 |
308 | sProps.relativeProgress = chunkPercent;
309 |
310 | //sProps.total = singlePacket[0].statusPackets["PROGRESS2"];
311 | sProps.speed = singlePacket[0].statusPackets["SPEED_TOTAL"];
312 | sProps.state = singlePacket[0].statusPackets["STATUS"] - offset; //Client-side workaround for old STATUS on server
313 |
314 | if (singlePacket[0].crackedPackets.Count > 200)
315 | {
316 | int max = 200;
317 |
318 | //Process the requests in batches of 1000
319 | while (singlePacket[0].crackedPackets.Count != 0)
320 | {
321 | List subChunk = new List(singlePacket[0].crackedPackets.GetRange(0, max));
322 | singlePacket[0].crackedPackets.RemoveRange(0, max);
323 | if (singlePacket[0].crackedPackets.Count < max)
324 | {
325 | max = singlePacket[0].crackedPackets.Count;
326 | }
327 |
328 | if (stipPath == true)
329 | {
330 | for (int i = 0; i <= subChunk.Count-1; i++)
331 | {
332 | subChunk[i] = subChunk[i].Replace(actualHLpath + ":", "");
333 | }
334 | }
335 |
336 | sProps.cracks = subChunk;
337 | jsonString = jsC.toJson(sProps);
338 | ret = jsC.jsonSend(jsonString);
339 |
340 | if (!jsC.isJsonSuccess(ret)) //If we received error, eg task was removed just break
341 | {
342 | break;
343 | }
344 | }
345 |
346 | }
347 | else
348 | {
349 | if (stipPath == true)
350 | {
351 | for (int i =0; i<= singlePacket[0].crackedPackets.Count-1; i++)
352 | {
353 | singlePacket[0].crackedPackets[i] = singlePacket[0].crackedPackets[i].Replace(actualHLpath + ":", "");
354 | }
355 | }
356 | sProps.cracks = singlePacket[0].crackedPackets;
357 |
358 | jsonString = jsC.toJson(sProps);
359 | ret = jsC.jsonSend(jsonString);
360 | }
361 | }
362 |
363 |
364 | if (jsC.isJsonSuccess(ret))
365 | {
366 |
367 | if (jsC.getRetVar(ret, "agent") == "stop") //Special command sent by server, possibly undocumented
368 | {
369 | hcClass.hcProc.CancelOutputRead();
370 | hcClass.hcProc.CancelErrorRead();
371 | hcClass.hcProc.Kill();
372 | run = false;
373 | Console.WriteLine("Server has instructed the client terminate the task via stop");
374 | }
375 |
376 |
377 | chunkPercent = chunkPercent / 100; //We already calculated with * 10000 earlier
378 |
379 | receivedZaps = jsC.getRetList(ret, "zaps"); //Check whether the server sent out hashes to zap
380 | if (receivedZaps.Count > 0)
381 | {
382 | zapCount++;
383 | File.WriteAllLines(Path.Combine(zapfilePath,zapCount.ToString()), receivedZaps); //Write hashes for zapping
384 |
385 | }
386 | Console.WriteLine("Progress:{0,7} | Speed:{1,-4} | Cracks:{2,-4} | Accepted:{3,-4} | Zapped:{4,-4} | Queue:{5,-2}", chunkPercent.ToString("F") + "%", speedCalc(singlePacket[0].statusPackets["SPEED_TOTAL"]), singlePacket[0].crackedPackets.Count, jsC.getRetVar(ret, "cracked"), receivedZaps.Count,ulQueue);
387 | receivedZaps.Clear();
388 |
389 |
390 | }
391 |
392 |
393 | else //We received an error from the server, terminate the run
394 | {
395 |
396 | string writeCracked = Path.Combine(hashpath, Path.GetFileName(hashlistID.ToString())) + ".cracked";
397 | Console.WriteLine("Writing any cracks in queue to file " + writeCracked);
398 | File.AppendAllLines(writeCracked, singlePacket[0].crackedPackets);
399 | lock (objPacketlock)
400 | {
401 | if (uploadPackets.Count > 0)
402 | {
403 | for (int i = 0; i < uploadPackets.Count; i++)
404 | {
405 | if (uploadPackets[i].crackedPackets.Count > 0)
406 | {
407 | File.AppendAllLines(writeCracked, uploadPackets[i].crackedPackets);
408 | }
409 | }
410 | }
411 | }
412 |
413 | run = false; //Potentially we can change this so keep submitting the rest of the cracked queue instead of terminating
414 |
415 | if (!hcClass.hcProc.HasExited)
416 | {
417 | hcClass.hcProc.CancelOutputRead();
418 | hcClass.hcProc.CancelErrorRead();
419 | hcClass.hcProc.Kill();
420 | //The server would need to accept the chunk but return an error
421 | }
422 | break;
423 | }
424 |
425 |
426 | {
427 | if (singlePacket[0].statusPackets["STATUS"] >= 4 + offset) //We are the last upload task
428 | //if (singlePacket[0].statusPackets["STATUS"] >= 5) //Uncomment this line, and comment above line for upcoming HC > 3.6
429 | {
430 | Console.WriteLine("Finished processing chunk");
431 | singlePacket.Clear();
432 | run = false;
433 | }
434 | else
435 | {
436 | singlePacket.RemoveAt(0);
437 | }
438 |
439 | }
440 |
441 | }
442 |
443 |
444 | catch (Exception e)
445 | {
446 | Console.WriteLine(e.Message);
447 | Console.WriteLine("Error processing packet for upload");
448 | }
449 |
450 |
451 | }
452 |
453 | }
454 |
455 | private jsonClass jsC = new jsonClass { };
456 |
457 | public int getChunk(int inTask)
458 | {
459 | Console.WriteLine("Getting chunk...");
460 | chunkProps cProps = new chunkProps
461 | {
462 | action = "getChunk",
463 | token = client.tokenID,
464 | taskId = inTask
465 | };
466 |
467 | jsC.debugFlag = debugFlag;
468 | jsC.connectURL = client.connectURL;
469 | primaryCracked = new List { };
470 | hcClass.debugFlag = debugFlag;
471 |
472 | string jsonString = jsC.toJson(cProps);
473 | string ret = jsC.jsonSend(jsonString);
474 |
475 |
476 | if (jsC.isJsonSuccess(ret))
477 | {
478 | string status = jsC.getRetVar(ret, "status");
479 |
480 |
481 | string argBuilder = attackcmd;
482 | string attackcmdMod = " " + cmdpars + " ";
483 | string actualHLpath = Path.Combine(hashpath, hashlistID.ToString());
484 | switch (status)
485 | {
486 | case "OK":
487 | attackcmdMod = " " + cmdpars + " "; //Reset the argument string
488 | attackcmdMod += attackcmd.Replace(hashlistAlias, "\"" + actualHLpath + "\" "); //Add the path to Hashlist
489 |
490 | attackcmdMod = convertToRelative(attackcmdMod);
491 |
492 | attackcmdMod += " --outfile-check-dir=\"" + zapPath + hashlistID.ToString() + "\" "; //Add the zap path to the commands
493 |
494 | hcClass.setArgs(attackcmdMod);
495 |
496 | chunkNo = Convert.ToInt64(jsC.getRetVar(ret, "chunkId"));
497 | skip = Convert.ToInt64(jsC.getRetVar(ret, "skip"));
498 | length = Convert.ToInt64(jsC.getRetVar(ret, "length"));
499 |
500 | List uploadPackets = new List();
501 |
502 | hcClass.setDirs(appPath);
503 | hcClass.setPassthrough(ref uploadPackets, ref packetLock, debugFlag);
504 |
505 | Thread thread = new Thread(() => threadPeriodicUpdate(ref uploadPackets, ref packetLock));
506 | thread.Start(); //Start our thread to monitor the upload queue
507 |
508 | //Start the monitor thread here
509 |
510 |
511 | hcClass.startAttack(chunkNo, taskID, skip, length, statusTimer, tasksPath); //Start the hashcat binary
512 | thread.Join();
513 |
514 | return 1;
515 |
516 | case "keyspace_required":
517 | hcClass.setDirs(appPath);
518 | attackcmdMod = " " + cmdpars + " "; //Reset the argument string
519 | attackcmdMod += attackcmd.Replace(hashlistAlias, ""); //Remove out the #HL#
520 |
521 | attackcmdMod = convertToRelative(attackcmdMod);
522 |
523 | hcClass.setArgs(attackcmdMod);
524 | long calcKeyspace = 0;
525 |
526 | if (!hcClass.runKeyspace(ref calcKeyspace))
527 | {
528 | Console.WriteLine("Keyspace measuring was unsuccessful, check all files are present");
529 | return 0;
530 | }
531 |
532 |
533 | if (calcKeyspace == 0)
534 | {
535 | errorProps eProps = new errorProps
536 | {
537 | token = client.tokenID,
538 | taskId = taskID,
539 | message = "Invalid keyspace, keyspace probably too small for this hashtype"
540 | };
541 | jsonString = jsC.toJson(eProps);
542 | ret = jsC.jsonSend(jsonString);
543 | return 0;
544 | }
545 | else
546 | {
547 | keyspaceProps kProps = new keyspaceProps
548 | {
549 | token = client.tokenID,
550 | taskId = taskID,
551 | keyspace = calcKeyspace
552 | };
553 | jsonString = jsC.toJson(kProps);
554 | ret = jsC.jsonSend(jsonString);
555 |
556 | }
557 |
558 | return 2;
559 |
560 | case "fully_dispatched":
561 | return 0;
562 |
563 | case "benchmark":
564 | hcClass.setDirs(appPath);
565 | attackcmdMod = " " + cmdpars + " "; //Reset the argument string
566 | attackcmdMod += attackcmd.Replace(hashlistAlias, "\"" + actualHLpath + "\""); //Add the path to Hashlist
567 |
568 | attackcmdMod = convertToRelative(attackcmdMod);
569 |
570 | hcClass.setArgs(attackcmdMod);
571 |
572 | Dictionary collection = new Dictionary(); //Holds all the returned benchmark values1
573 |
574 | if(!hcClass.runBenchmark(benchMethod, benchTime, ref collection, legacy))
575 | {
576 | Console.WriteLine("Benchmark error, perhaps hashlist is empty");
577 | errorProps eProps = new errorProps
578 | {
579 | token = client.tokenID,
580 | taskId = taskID,
581 | message = "Client received an invalid hashlist for benchmark"
582 | };
583 | jsonString = jsC.toJson(eProps);
584 | ret = jsC.jsonSend(jsonString);
585 |
586 | return 0;
587 |
588 | }
589 |
590 | benchProps bProps = new benchProps
591 | {
592 | token = client.tokenID,
593 | taskId = taskID,
594 | };
595 |
596 | try
597 | {
598 | if (benchMethod == 1) //Old benchmark method using actual run
599 | {
600 | bProps.type = "run";
601 | bProps.result = collection["PROGRESS_REJ"].ToString("0." + new string('#', 100));
602 |
603 | }
604 | else //New benchmark method using --speed param
605 | {
606 | bProps.type = "speed";
607 | bProps.result = collection["LEFT_TOTAL"].ToString() + ":" + collection["RIGHT_TOTAL"].ToString();
608 | }
609 | }
610 | catch
611 | {
612 | Console.WriteLine("Benchmark was unsuccessful, check all files are present");
613 | return 0;
614 | }
615 |
616 |
617 |
618 | jsonString = jsC.toJson(bProps);
619 | ret = jsC.jsonSend(jsonString);
620 | if (!jsC.isJsonSuccess(ret))
621 | {
622 | Console.WriteLine("Server rejected benchmark");
623 | Console.WriteLine("Check the hashlist was downloaded correctly");
624 | return 0;
625 | }
626 | return 3;
627 |
628 | }
629 |
630 | }
631 | return 0;
632 | }
633 |
634 | private string convertToRelative(string input)
635 | {
636 | string[] filename = input.Split(' '); //Split by spaces
637 | string final = "";
638 |
639 |
640 | foreach (var file in filename)
641 | {
642 | if (File.Exists("files\\" + file))
643 | {
644 | final += "..\\..\\files\\" + file + " ";
645 | }
646 | else
647 | {
648 | final += file + " ";
649 | }
650 | }
651 |
652 | if (client.osID != 1)
653 | {
654 | final = final.Replace("\\", "/");
655 | }
656 |
657 | return final;
658 |
659 | }
660 | private Boolean getFile(string fileName)
661 | {
662 | FileProps get = new FileProps
663 | {
664 | action = "getFile",
665 | token = client.tokenID,
666 | taskId = taskID,
667 | file = fileName
668 | };
669 |
670 | jsonClass jsC = new jsonClass { debugFlag = debugFlag, connectURL = client.connectURL };
671 | string jsonString = jsC.toJson(get);
672 | string ret = jsC.jsonSend(jsonString);
673 |
674 | if (jsC.isJsonSuccess(ret))
675 | {
676 | string fileDl = jsC.getRetVar(ret, "url");
677 | {
678 | downloadClass dlHdl = new downloadClass();
679 | string dlFrom = Path.Combine(prefixServerdl, jsC.getRetVar(ret, "url"));
680 | string dlTo = Path.Combine(filepath,fileName);
681 | dlHdl.DownloadFile(dlFrom, dlTo);
682 | Console.WriteLine("Finished downloading file");
683 | //Check if file exists. check if return success
684 | return true;
685 | }
686 |
687 | }
688 | return false;
689 | }
690 |
691 | private Boolean getURLtoFile(string url, string dst)
692 | {
693 | {
694 | downloadClass dlHdl = new downloadClass();
695 | string dlFrom = Path.Combine(prefixServerdl, url);
696 | string dlTo = Path.Combine(filepath, dst);
697 | dlHdl.DownloadFile(dlFrom, dlTo);
698 | Console.WriteLine("Finished downloading file");
699 | //Check if file exists. check if return success
700 | if (File.Exists(dlTo))
701 | {
702 | return true;
703 | }
704 | }
705 |
706 | return false;
707 | }
708 |
709 |
710 | private Int64 fileSize(string filePath)
711 | {
712 | Int64 fSize = new FileInfo(Path.Combine(hashpath , Path.GetFileName(hashlistID.ToString()))).Length;
713 | return fSize;
714 | }
715 |
716 |
717 | public Boolean getTask()
718 | {
719 |
720 | Console.WriteLine("Getting task");
721 | Task get = new Task
722 | {
723 | action = "getTask",
724 | token = client.tokenID
725 | };
726 |
727 | jsonClass jsC = new jsonClass { debugFlag = debugFlag, connectURL = client.connectURL };
728 | string jsonString = jsC.toJson(get);
729 | string ret = jsC.jsonSend(jsonString);
730 |
731 | if (jsC.isJsonSuccess(ret))
732 | {
733 | if (jsC.getRetVar(ret, "taskId") != null)
734 | {
735 | taskID = Int32.Parse(jsC.getRetVar(ret, "taskId"));
736 | attackcmd = (jsC.getRetVar(ret, "attackcmd"));
737 | cmdpars = (jsC.getRetVar(ret, "cmdpars"));
738 | hashlistID = Int32.Parse(jsC.getRetVar(ret, "hashlistId"));
739 | benchTime = Int32.Parse(jsC.getRetVar(ret, "bench"));
740 | crackerId = Int32.Parse(jsC.getRetVar(ret, "crackerId"));
741 |
742 | Console.WriteLine("Server has assigned client with Task:{0}, Cracker:{2} and Hashlist:{1}",taskID,hashlistID,crackerId);
743 | if (jsC.getRetVar(ret, "benchType") == "run")
744 | {
745 | benchMethod = 1;
746 | }
747 | else
748 | {
749 | benchMethod = 2;
750 | }
751 | statusTimer = Int32.Parse(jsC.getRetVar(ret, "statustimer"));
752 | hashlistAlias = jsC.getRetVar(ret, "hashlistAlias");
753 | files = jsC.getRetArray(ret, "files");
754 | int gotChunk = 1;
755 |
756 | foreach (string fileItem in files)
757 | {
758 | string actualFile = Path.Combine(filepath, fileItem);
759 | if (!File.Exists(actualFile))
760 | {
761 | getFile(fileItem);
762 |
763 | if (fileItem.ToLower().EndsWith(".7z"))
764 | {
765 | if (sevenZip.xtract(actualFile, filepath))
766 | {
767 | File.WriteAllText(actualFile, "UNPACKED");
768 | }
769 | else
770 | {
771 | return false;
772 | }
773 | }
774 | }
775 | }
776 |
777 | //Convert implied relative paths to absolute paths only applies to Mac OSX / Linux
778 | //We, break up the attack command by space and check whether the file for the full path exists, we it does we replace
779 | //Could potentially cause issues if the file names are attack numbers eg 1 2 3 4 5 6 7
780 | //File names cannot contain spaces
781 | //Altnerative method is to perform find replace on the attackcmd based on the files array
782 | if (client.osID != 1)
783 | {
784 | string[] explode = new string[] { };
785 | explode = attackcmd.Split(' ');
786 |
787 | for (int i = 0; i