diff --git a/.gitignore b/.gitignore
index 1981af8..97c5696 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,10 @@
-
-.idea/
*.iml
-java/
\ No newline at end of file
+*.exe
+*.log
+*.json
+crackers
+prince
+files
+hashlists
+__pycache__
+*.zip
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..ce013be
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,9 @@
+language: python
+python:
+ - "3.5"
+ - "3.6"
+install:
+ - pip install -r requirements.txt
+script:
+ - ./build.sh
+ - python hashtopolis.zip --version
diff --git a/README.md b/README.md
index a54d362..3795c91 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,98 @@
-# Hashtopolis Agents
+# Hashtopolis Python Agent
-Official agents for using the distributed hashcracker [Hashtopolis](https://github.com/s3inlc/hashtopolis).
+[](https://www.codefactor.io/repository/github/s3inlc/hashtopolis-agent-python)
+[](https://github.com/s3inlc/Hashtopolis-Agent-Python)
+[](https://travis-ci.org/s3inlc/hashtopolis-agent-python)
-Currently available agents:
-- [C#](csharp)
-- [Python](python)
+This agent is used with [Hashtopolis](https://github.com/s3inlc/hashtopolis), read the wiki or create issues there, visit the [Forum](https://hashtopolis.org).
+This Hashtopolis agent is only compatible with Hashtopolis versions 0.5.0 and higher.
-## Protocol Documentation
+## Prerequisites
-A documentation to the protocol which is used to communicate between the agent and the server can be found here: [Protocol.pdf](https://github.com/s3inlc/hashtopolis/blob/master/doc/protocol.pdf)
+You need python3 installed on your agent system.
+Following python packages are required:
+
+* requests
+
+## Manual
+
+You can either download the agent from the Hashtopolis new agent page or you can use the url shown there to download the agent with
+wget/curl.
+
+### Run
+
+To run the agent you simply need to call `python3 hashtopolis.zip`. There are no command line options accepted, all
+settings/configurations are done via the config file, described in the following section.
+
+Please note that the client does not correctly recognize the OS when you are running in Cygwin or similar on Windows. You need to run it in Windows command line.
+
+### Config
+
+When you run the client for the first time it will ask automatically for all the requirement settings and then saves it automatically to a config file called `config.json`. This could for example look like this:
+
+```
+{
+ "url": "https://example.org/hashtopolis/api/server.php",
+ "token": "ABCDEFGHIJ",
+ "uuid": "49dcd31c-3637-4f2a-8df1-b545202df5b3"
+}
+```
+
+### Overview
+
+| field | type | default | description |
+|-----------------------|---------|---------|----------------------------------------------------------------------------|
+| voucher | string | | Used for agent registration (will be prompted on first start) |
+| url | string | | The hashtopolis API endpoint (will be prompted on first start) |
+| token | string | | The access token for the API (sent by server on registration) |
+| uuid | string | | Unique identifier of the agent (generated on registration) |
+| debug | boolean | false | Enables debug output |
+| allow-piping | boolean | false | Allows hashcat to read password candidates from stdin |
+| piping-threshold | integer | 95 | Restarts chunk in piping mode when GPU UTIL is below this value |
+| rsync | boolean | false | Enables download of wordlists and rules via rsync |
+| rsync-path | string | | Remote path to hashtopolis files directory |
+| multicast-device | string | eth0 | Device which is used to retrieve UDP multicast file distribution |
+| file-deletion-disable | boolean | false | Disable requesting the server for files to delete |
+| file-deletion-interval| integer | 600 | Interval time in seconds in which the agent should check for deleted files |
+| proxies | object | | Specify proxies e.g. `"proxies": {"https": "localhost:8433"}` |
+| auth-user | string | | HTTP Basic Auth user |
+| auth-password | string | | HTTP Basic AUth password |
+
+### Debug example
+
+```
+{
+ "url": "https://coray.org/htp-test/src/api/server.php",
+ "token": "7RNDqtnPxm",
+ "uuid": "49dcd31c-3637-4f2a-8df1-b545202df5b3",
+ "debug": true
+}
+```
+
+### rsync
+
+You need a user on the server which can automatically login (e.g. SSH keys) and has read access to the files directory of hashtopolis. On the client side you need rsync installed and set the following lines in your agent config.
+
+```
+ "rsync": true,
+ "rsync-path": "user@yourserver:/path/to/hashtopolis/files"
+```
+
+### Multicast
+
+In order to use the multicast distribution for files, please make sure that the agents and server are prepared according to this:https://github.com/s3inlc/hashtopolis-runner
+
+## Hashcat Compatibility
+
+The list contains all Hashcat versions with which the client was tested and is able to work with (other versions might work):
+
+* 5.0.0
+* 4.2.1
+* 4.2.0
+* 4.1.0
+* 4.0.1
+* 4.0.0
+
+## Generic Crackers
+
+This client is able to run generic Hashtopolis cracker binaries which fulfill the minimal functionality requirements, described [here](https://github.com/s3inlc/hashtopolis/tree/master/doc/README.md). An example implementation can be found [here](https://github.com/s3inlc/hashtopolis-generic-cracker)
diff --git a/python/__main__.py b/__main__.py
similarity index 51%
rename from python/__main__.py
rename to __main__.py
index db043cf..30def6b 100644
--- a/python/__main__.py
+++ b/__main__.py
@@ -1,3 +1,5 @@
+import sys
+import time
from time import sleep
from htpclient.binarydownload import BinaryDownload
@@ -6,7 +8,7 @@
from htpclient.generic_cracker import GenericCracker
from htpclient.hashcat_cracker import HashcatCracker
from htpclient.hashlist import Hashlist
-from htpclient.helpers import start_uftpd
+from htpclient.helpers import start_uftpd, file_get_contents
from htpclient.initialize import Initialize
from htpclient.jsonRequest import *
from htpclient.dicts import *
@@ -16,26 +18,99 @@
CONFIG = None
binaryDownload = None
+current_cracker = None
+
+
+def run_health_check():
+ global CONFIG, binaryDownload
+ logging.info("Health check requested by server!")
+ logging.info("Retrieving health check settings...")
+ query = copy_and_set_token(dict_getHealthCheck, CONFIG.get_value('token'))
+ req = JsonRequest(query)
+ ans = req.execute()
+ if ans is None:
+ logging.error("Failed to get health check!")
+ sleep(5)
+ return
+ elif ans['response'] != 'SUCCESS':
+ logging.error("Error on getting health check: " + str(ans))
+ sleep(5)
+ return
+ binaryDownload.check_version(ans['crackerBinaryId'])
+ check_id = ans['checkId']
+ logging.info("Starting check ID " + str(check_id))
+
+ # write hashes to file
+ hash_file = open("hashlists/health_check.txt", "w")
+ hash_file.write("\n".join(ans['hashes']))
+ hash_file.close()
+
+ # delete old file if necessary
+ if os.path.exists("hashlists/health_check.out"):
+ os.unlink("hashlists/health_check.out")
+
+ # run task
+ cracker = HashcatCracker(ans['crackerBinaryId'], binaryDownload)
+ start = int(time.time())
+ [states, errors] = cracker.run_health_check(ans['attack'], ans['hashlistAlias'])
+ end = int(time.time())
+
+ # read results
+ if os.path.exists("hashlists/health_check.out"):
+ founds = file_get_contents("hashlists/health_check.out").replace("\r\n", "\n").split("\n")
+ else:
+ founds = []
+ num_gpus = len(states[0].get_temps())
+ query = copy_and_set_token(dict_sendHealthCheck, CONFIG.get_value('token'))
+ query['checkId'] = check_id
+ query['start'] = start
+ query['end'] = end
+ query['numGpus'] = num_gpus
+ query['numCracked'] = len(founds) - 1
+ query['errors'] = errors
+ req = JsonRequest(query)
+ ans = req.execute()
+ if ans is None:
+ logging.error("Failed to send health check results!")
+ sleep(5)
+ return
+ elif ans['response'] != 'OK':
+ logging.error("Error on sending health check results: " + str(ans))
+ sleep(5)
+ return
+ logging.info("Health check completed successfully!")
def init():
global CONFIG, binaryDownload
- logformat = '[%(asctime)s] [%(levelname)-5s] %(message)s'
- dateformat = '%Y-%m-%d %H:%M:%S'
- logfile = 'client.log'
- loglevel = logging.INFO
+ log_format = '[%(asctime)s] [%(levelname)-5s] %(message)s'
+ print_format = '%(message)s'
+ date_format = '%Y-%m-%d %H:%M:%S'
+ log_level = logging.INFO
+ logfile = open('client.log', "a", encoding="utf-8")
logging.getLogger("requests").setLevel(logging.WARNING)
CONFIG = Config()
if CONFIG.get_value('debug'):
- loglevel = logging.DEBUG
+ log_level = logging.DEBUG
logging.getLogger("requests").setLevel(logging.DEBUG)
- logging.basicConfig(filename=logfile, level=loglevel, format=logformat, datefmt=dateformat)
- logging.getLogger().addHandler(logging.StreamHandler())
+ logging.basicConfig(level=log_level, format=print_format, datefmt=date_format)
+ file_handler = logging.StreamHandler(logfile)
+ file_handler.setFormatter(logging.Formatter(log_format))
+ logging.getLogger().addHandler(file_handler)
logging.info("Starting client '" + Initialize.get_version() + "'...")
+ session = Session(requests.Session()).s
+ session.headers.update({'User-Agent': Initialize.get_version()})
+
+ if CONFIG.get_value('proxies'):
+ session.proxies = CONFIG.get_value('proxies')
+
+ if CONFIG.get_value('auth-user') and CONFIG.get_value('auth-password'):
+ session.auth = (CONFIG.get_value('auth-user'), CONFIG.get_value('auth-password'))
+
# connection initialization
Initialize().run()
# download and updates
@@ -46,7 +121,7 @@ def init():
def loop():
- global binaryDownload, CONFIG
+ global binaryDownload, CONFIG, current_cracker
logging.debug("Entering loop...")
task = Task()
@@ -62,7 +137,11 @@ def loop():
if task.get_task() is not None:
last_task_id = task.get_task()['taskId']
task.load_task()
- if task.get_task() is None:
+ if task.get_task_id() == -1:
+ run_health_check()
+ task.reset_task()
+ continue
+ elif task.get_task() is None:
task_change = True
continue
else:
@@ -85,8 +164,10 @@ def loop():
logging.info("Got cracker binary type " + binaryDownload.get_version()['name'])
if binaryDownload.get_version()['name'].lower() == 'hashcat':
cracker = HashcatCracker(task.get_task()['crackerId'], binaryDownload)
+ current_cracker = cracker
else:
cracker = GenericCracker(task.get_task()['crackerId'], binaryDownload)
+ current_cracker = cracker
task_change = False
chunk_resp = chunk.get_chunk(task.get_task()['taskId'])
if chunk_resp == 0:
@@ -94,7 +175,12 @@ def loop():
continue
elif chunk_resp == -1:
# measure keyspace
- cracker.measure_keyspace(task.get_task(), chunk)
+ if not cracker.measure_keyspace(task.get_task(), chunk): # failure case
+ task.reset_task()
+ continue
+ elif chunk_resp == -3:
+ run_health_check()
+ task.reset_task()
continue
elif chunk_resp == -2:
# measure benchmark
@@ -126,6 +212,12 @@ def loop():
logging.info("Server accepted benchmark!")
continue
+ # check if we have an invalid chunk
+ if chunk.chunk_data() is not None and chunk.chunk_data()['length'] == 0:
+ logging.error("Invalid chunk size (0) retrieved! Retrying...")
+ task.reset_task()
+ continue
+
# run chunk
logging.info("Start chunk...")
cracker.run_chunk(task.get_task(), chunk.chunk_data())
@@ -137,8 +229,11 @@ def loop():
if __name__ == "__main__":
try:
+ if len(sys.argv) > 1 and sys.argv[1] == '--version':
+ print(Initialize.get_version())
+ sys.exit()
init()
loop()
except KeyboardInterrupt:
logging.info("Exiting...")
- exit()
+ sys.exit()
diff --git a/python/build.sh b/build.sh
similarity index 60%
rename from python/build.sh
rename to build.sh
index d8e8c94..0c7fcb2 100755
--- a/python/build.sh
+++ b/build.sh
@@ -1,4 +1,6 @@
#!/usr/bin/env bash
-rm hashtopolis.zip
+if [ -f hashtopolis.zip ]; then
+ rm hashtopolis.zip
+fi
zip -r hashtopolis.zip __main__.py htpclient -x "*__pycache__*"
diff --git a/python/changelog.md b/changelog.md
similarity index 82%
rename from python/changelog.md
rename to changelog.md
index 54a8d4d..9e52767 100644
--- a/python/changelog.md
+++ b/changelog.md
@@ -1,3 +1,19 @@
+## 0.2.0 -> 0.x.x
+
+### Features
+
+* Agents can run health checks requested from the server.
+
+### Bugfixes
+
+* Fixed benchmark results when having many GPUs in one agent.
+
+### Enhancements
+
+* Added check for chunk length 0 sent from the server to avoid full agent crash on running.
+* Using requests session
+* Added option for using proxies
+* Added HTTP Basic Auth support
## 0.1.8 -> 0.2.0
diff --git a/csharp/.gitignore b/csharp/.gitignore
deleted file mode 100644
index 9d725e2..0000000
--- a/csharp/.gitignore
+++ /dev/null
@@ -1,7 +0,0 @@
-hashtopolis/bin/
-hashtopolis/obj/
-*.suo
-.vs/
-.suo
-
-
diff --git a/csharp/.gitkeep b/csharp/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/csharp/hashtopolis.sln b/csharp/hashtopolis.sln
deleted file mode 100644
index eb1e016..0000000
--- a/csharp/hashtopolis.sln
+++ /dev/null
@@ -1,31 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.26730.12
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hashtopolis", "hashtopolis\hashtopolis.csproj", "{199AD37B-3000-4CC0-992C-87738F84C768}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Debug|x64 = Debug|x64
- Release|Any CPU = Release|Any CPU
- Release|x64 = Release|x64
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {199AD37B-3000-4CC0-992C-87738F84C768}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {199AD37B-3000-4CC0-992C-87738F84C768}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {199AD37B-3000-4CC0-992C-87738F84C768}.Debug|x64.ActiveCfg = Debug|x64
- {199AD37B-3000-4CC0-992C-87738F84C768}.Debug|x64.Build.0 = Debug|x64
- {199AD37B-3000-4CC0-992C-87738F84C768}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {199AD37B-3000-4CC0-992C-87738F84C768}.Release|Any CPU.Build.0 = Release|Any CPU
- {199AD37B-3000-4CC0-992C-87738F84C768}.Release|x64.ActiveCfg = Release|x64
- {199AD37B-3000-4CC0-992C-87738F84C768}.Release|x64.Build.0 = Release|x64
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {6AF2D704-CD70-4421-8080-269C7AD78ABA}
- EndGlobalSection
-EndGlobal
diff --git a/csharp/hashtopolis/.gitignore b/csharp/hashtopolis/.gitignore
deleted file mode 100644
index e69de29..0000000
diff --git a/csharp/hashtopolis/7zClass.cs b/csharp/hashtopolis/7zClass.cs
deleted file mode 100644
index d0fc6e1..0000000
--- a/csharp/hashtopolis/7zClass.cs
+++ /dev/null
@@ -1,155 +0,0 @@
-using System;
-using System.IO;
-using System.Diagnostics;
-
-
-namespace hashtopolis
-{
-
- class _7zClass
- {
-
- public class dlProps
- {
- public string action = "downloadBinary";
- public string type = "7zr";
- public string token { get; set; }
- }
-
- public int osID { get; set; }
- public string tokenID { get; set; }
- public string appPath { get; set; }
- public string connectURL { get; set; }
-
- string binPath = "";
-
- 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;
-
- }
-
- //Code from hashtopus
- public Boolean xtract(string archivePath, string outDir, string files = "")
- {
- ProcessStartInfo pinfo = new ProcessStartInfo();
- pinfo.FileName = binPath;
- pinfo.WorkingDirectory = appPath;
- pinfo.UseShellExecute = false;
- pinfo.RedirectStandardError = true;
- pinfo.RedirectStandardOutput = true;
- pinfo.Arguments = " x -y -o\"" + outDir + "\" \"" + archivePath + "\"";
- string stdOutSingle = "";
- Boolean unpackFailed = false;
- Process unpak = new Process();
- unpak.StartInfo = pinfo;
-
- if (files != "") unpak.StartInfo.Arguments += " " + files;
-
- Console.WriteLine(pinfo.FileName + pinfo.Arguments);
- Console.WriteLine("Extracting archive " + archivePath + "...");
-
- FileInfo f = new FileInfo(archivePath);
-
- if (f.Length == 0)
- {
- Console.WriteLine("File is 0 bytes");
- return false;
- }
-
- try
- {
- if (!unpak.Start()) return false;
- while (!unpak.HasExited)
- {
- while (!unpak.StandardOutput.EndOfStream)
- {
- stdOutSingle = unpak.StandardOutput.ReadLine().TrimEnd();
- if (stdOutSingle == "Error: Can not open file as archive")
- {
- unpackFailed = true;
- }
- }
- }
- unpak.StandardOutput.Close();
- }
- catch
- {
- Console.WriteLine("Could not start 7zr.");
- return false;
- }
- finally
- {
- unpak.WaitForExit();
- }
-
- if (unpackFailed == true)
- {
- Console.WriteLine("Failed to extract " + archivePath);
- Console.WriteLine("WARNING:Some needed files may be missing and the tasks may not start correctly");
- return false;
- }
- return true;
-
- }
- }
-}
diff --git a/csharp/hashtopolis/App.config b/csharp/hashtopolis/App.config
deleted file mode 100644
index e707b32..0000000
--- a/csharp/hashtopolis/App.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/csharp/hashtopolis/Program.cs b/csharp/hashtopolis/Program.cs
deleted file mode 100644
index b99f205..0000000
--- a/csharp/hashtopolis/Program.cs
+++ /dev/null
@@ -1,223 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Threading;
-using System.Diagnostics;
-namespace hashtopolis
-{
-
-
-
- public struct Packets
- {
- public Dictionary statusPackets;
- public List crackedPackets;
- }
-
- public class testProp
- {
- public string action = "testConnection";
- }
-
-
-
- class Program
- {
-
- public static string AppPath = AppDomain.CurrentDomain.BaseDirectory;
- private static string urlPath = Path.Combine(AppPath, "URL");
- private static string serverURL = "";
-
- static void initDirs()
- {
-
- string[] createDirs = new String[] { "files", "hashlists", "tasks", "hashcat" };
-
- foreach (string dir in createDirs)
- {
- string enumDir = Path.Combine(AppPath, dir);
- try
- {
- if (!Directory.Exists(enumDir))
- {
- Console.WriteLine("Creating {0} directory", dir);
- Directory.CreateDirectory(enumDir);
- }
- }
- catch(Exception e)
- {
- Console.WriteLine(e.Data);
- Console.WriteLine("Unable to create dir {0}", dir);
- Console.WriteLine("Client now terminating");
- Environment.Exit(0);
- }
-
- }
-
- }
-
-
- public static bool loadURL()
- {
- if (serverURL == "")
- {
- if (File.Exists(urlPath))
- {
- serverURL = File.ReadAllText(urlPath);
- if (serverURL == "")
- {
- File.Delete(urlPath);
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- return true;
-
- }
-
-
- public static Boolean initConnect()
- {
- jsonClass testConnect = new jsonClass { debugFlag = DebugMode };
- testProp tProp = new testProp();
- string urlMsg = "Please enter server connect URL (https will be used unless specified):";
- while (!loadURL())
- {
- Console.WriteLine(urlMsg);
- string url = Console.ReadLine();
- if (!url.StartsWith("http", StringComparison.OrdinalIgnoreCase))
- {
- url = "https://" + url;
- }
- Console.WriteLine("Testing connection to " + url);
- testConnect.connectURL = url;
- string jsonString = testConnect.toJson(tProp);
- string ret = testConnect.jsonSendOnce(jsonString);
- if (ret != null)
- {
- if (testConnect.isJsonSuccess(ret))
- {
- File.WriteAllText(urlPath, url);
- }
- }
- else
- {
- urlMsg = "Test connect failed, please enter server connect URL:";
- }
-
- }
-
- Console.WriteLine("Connecting to server {0}",serverURL);
- return true;
- }
-
- public static Boolean DebugMode;
-
- static void Main(string[] args)
- {
-
-
- if (Console.LargestWindowWidth > 94 && Console.LargestWindowHeight > 24)
- {
- Console.SetWindowSize(95, 25);
- }
-
-
-
- System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
- customCulture.NumberFormat.NumberDecimalSeparator = ".";
- System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
-
- string tokenSwitch = "";
-
- foreach (string arg in args)
- {
- switch (arg.Substring(0, 2))
- {
-
- case "-t":
- tokenSwitch = arg.Substring(3);
- break;
- case "-u":
- serverURL = arg.Substring(3);
- break;
- case "-d":
- DebugMode = true;
- break;
- }
- }
-
- string AppVersion = "0.52.6";
- Console.WriteLine("Client Version " + AppVersion);
-
- initConnect();
- initDirs();
-
- registerClass client = new registerClass { connectURL = serverURL, debugFlag = DebugMode,tokenID = tokenSwitch};
- Boolean legacy = false; //Defaults to legacy STATUS codes
- client.setPath( AppPath);
- if (client.loginAgent())
- {
- Console.WriteLine("Logged in to server");
- }
-
- updateClass updater = new updateClass
- {
- htpVersion = AppVersion,
- parentPath = AppPath,
- arguments = args,
- connectURL = serverURL,
- debugFlag = DebugMode,
- tokenID = client.tokenID
-
- };
- updater.runUpdate();
- //Run code to self-update
-
- _7zClass zipper = new _7zClass
- {
- tokenID = client.tokenID,
- osID = client.osID,
- appPath = AppPath,
- connectURL = serverURL
- };
-
- if (!zipper.init7z())
- {
- Console.WriteLine("Failed to initialize 7zip, proceeding without. \n The client may not be able to extract compressed files");
- }
-
- taskClass tasks = new taskClass
- {
- sevenZip = zipper,
- debugFlag = DebugMode,
- client = client,
- legacy = legacy
-
- };
-
- tasks.setOffset(); //Set offset for STATUS changes in hashcat 3.6.0
- tasks.setDirs(AppPath);
-
- int backDown = 5;
- while(true) //Keep waiting for 5 seconds and checking for tasks
- {
- Thread.Sleep(backDown * 1000);
-
- if (tasks.getTask())
- {
- backDown = 5;
- }
- if (backDown <30)
- {
- backDown++;
- }
- }
-
- }
- }
-}
diff --git a/csharp/hashtopolis/Properties/AssemblyInfo.cs b/csharp/hashtopolis/Properties/AssemblyInfo.cs
deleted file mode 100644
index 867088f..0000000
--- a/csharp/hashtopolis/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("hashtopolis")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("hashtopolis")]
-[assembly: AssemblyCopyright("Copyright © 2016")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("199ad37b-3000-4cc0-992c-87738f84c768")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/csharp/hashtopolis/binary/hashtopolis.exe b/csharp/hashtopolis/binary/hashtopolis.exe
deleted file mode 100644
index 1bf8228..0000000
Binary files a/csharp/hashtopolis/binary/hashtopolis.exe and /dev/null differ
diff --git a/csharp/hashtopolis/downloadClass.cs b/csharp/hashtopolis/downloadClass.cs
deleted file mode 100644
index 8030e4b..0000000
--- a/csharp/hashtopolis/downloadClass.cs
+++ /dev/null
@@ -1,149 +0,0 @@
-using System;
-using System.Diagnostics;
-using System.Net;
-using System.Threading;
-using System.IO;
-using System.ComponentModel;
-
-namespace hashtopolis
-{
- class downloadClass
- {
-
-
- Stopwatch sw = new Stopwatch();
- private bool completedFlag = false;
-
- public bool DownloadFileCurl(string urlAddress, string location)
- {
- string AppPath = AppDomain.CurrentDomain.BaseDirectory;
- ProcessStartInfo pinfo = new ProcessStartInfo();
- pinfo.FileName = "curl";
- pinfo.UseShellExecute = false;
- pinfo.RedirectStandardOutput = true;
-
-
- pinfo.WorkingDirectory = AppPath;
-
- pinfo.Arguments = " " + urlAddress + " -o" + "\"" + location + "\"";
-
- Process unpak = new Process();
- unpak.StartInfo = pinfo;
- unpak.Start();
- unpak.WaitForExit();
- return true;
-
- }
-
-
-
- public bool DownloadFile(string urlAddress, string location)
- {
-
- completedFlag = false;
- WebClient webClient;
- try
- {
- System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 |
- SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
- }
- catch
- {
- Console.WriteLine("Skipping TLS settings (consider upgrading to the latest .NET framework for better TLS support");
- }
-
- using (webClient = new WebClient())
- {
- webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
- webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(dlFinished);
- if (!urlAddress.StartsWith("http", StringComparison.OrdinalIgnoreCase))
- {
- urlAddress = "https://" + urlAddress;
- }
- Uri URL = null;
- try
- {
- Console.WriteLine("Downloading from " + urlAddress);
- URL = new Uri(urlAddress);
- }
- catch
- {
- Console.WriteLine("Invalid url for downloading");
- return false;
- }
-
- //webClient.DownloadFile(URL, location);
- // Start the stopwatch which we will be using to calculate the download speed
- sw.Start();
-
- try
- {
- // Start downloading the file
- webClient.DownloadFileAsync(URL, location);
-
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- return false;
- }
- while (!completedFlag) Thread.Sleep(500);
-
- if (File.Exists(location))
- {
- FileInfo f = new FileInfo(location);
- long size = f.Length;
- Console.WriteLine();
- return true;
- }
- else
- {
- return false;
- }
-
- }
- }
-
- //This will fire upon filedownload completion
- void dlFinished(object sender, AsyncCompletedEventArgs e)
- {
- completedFlag = true;
- }
-
- // The event that will fire whenever the progress of the WebClient is changed
- private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
- {
-
- double speed = e.BytesReceived / 1024d / sw.Elapsed.TotalSeconds;
- int divCount = 0;
- while (speed > 1000)
- {
- speed = speed / 1000;
- divCount += 1;
- }
-
- string speedMetric = "?/s";
- switch (divCount)
- {
- case 0:
- speedMetric = "KB/s";
- break;
- case 1:
- speedMetric = "MB/s";
- break;
- case 2:
- speedMetric = "GB/s";
- break;
- case 3:
- speedMetric = "TB/s";
- break;
-
- }
-
- Console.Write("\r{0} {1}% @ {2} {3}", "Downloading",e.ProgressPercentage, speed.ToString("0.00"), speedMetric);
-
- }
-
-
- }
-}
diff --git a/csharp/hashtopolis/hashcatClass.cs b/csharp/hashtopolis/hashcatClass.cs
deleted file mode 100644
index d6040cc..0000000
--- a/csharp/hashtopolis/hashcatClass.cs
+++ /dev/null
@@ -1,630 +0,0 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Diagnostics;
-using System.Text.RegularExpressions;
-using System.Globalization;
-
-namespace hashtopolis
-{
- class hashcatClass : IDisposable
- {
- public Boolean debugFlag { get; set; }
-
- public List hashlist = new List { }; //New collection to store cracks
- public Process hcProc;
-
- private string workingDir = "";
- private string filesDir = "";
- private string hcDir = "hashcat";
- private string hcBin = "hashcat64.exe";
- public string hcDirectory { get; set; }
- public string hcBinary { get; set; }
-
- private string hcArgs = "";
-
- private object packetLock;
- private object crackedLock;
- private object statusLock;
-
- List passedPackets;
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (!hcProc.HasExited )
- {
- hcProc.Kill();
- hcProc.Dispose();
- }
- }
- }
-
- public void setPassthrough(ref List refPacketlist, ref object objpacketLock, Boolean debugging)
- {
- passedPackets = refPacketlist;
- packetLock = objpacketLock;
-
- crackedLock = new object();
- statusLock = new object();
- debugFlag = debugging;
-
- }
-
- public void setArgs(string args)
- {
-
- hcArgs = args;
- }
-
- public void setDirs(string fpath)
- {
- hcDir = Path.Combine(fpath, hcDirectory);
- workingDir = Path.Combine(fpath, "tasks").TrimEnd();
- filesDir = Path.Combine(fpath, "files"," ").TrimEnd();
-
- hcBin = hcBinary;
-
- }
-
- public void runUpdate()
- {
- if (!Directory.Exists(hcDir))
- {
- //forceUpdate = true;
- }
- }
-
-
-
- private void parseStatus1(string line,ref Dictionary collection)
- {
-
- System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
- customCulture.NumberFormat.NumberDecimalSeparator = ".";
- System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
-
- //Console.WriteLine(line);
-
- string[] items = line.Split('\t');
- double speedData = 0;
- double countStep = 0;
- double execRuntime = 0;
-
- int max = items.Count();
- int i = 0;
-
- if (debugFlag)
- {
- Console.WriteLine(line);
- }
-
-
- while(i < max)
- {
- countStep = 0;
- switch (items[i])
- {
- case "STATUS":
- collection.Add("STATUS", Convert.ToInt64(items[i + 1]));
- i =+ 1;
- break;
- case "SPEED":
- while (items[i+1] != "EXEC_RUNTIME") //Due to multiple cards, perform micro-loop
- {
- collection.Add("SPEED" + countStep, Convert.ToDouble(items[i + 1]));
- speedData += (Convert.ToDouble(items[i + 1]) * 1000) / Convert.ToDouble(items[i + 2]); //For hashcat 3.7 compatability
- countStep++;
- i += 2;
- }
- collection.Add("SPEED_TOTAL", speedData);
- collection.Add("SPEED_COUNT", countStep);
- break;
- case "EXEC_RUNTIME":
- while (items[i+1] != "CURKU") //Due to multiple cards, perform micro-loop
- {
- collection.Add("EXEC_RUNTIME" + countStep, Math.Round(Convert.ToDouble(Decimal.Parse(items[i + 1]), CultureInfo.InvariantCulture),2));
- execRuntime += Convert.ToDouble(Decimal.Parse(items[i + 1]), CultureInfo.InvariantCulture);
- countStep++;
- i += 1;
- }
- collection.Add("EXEC_RUNTIME_AVG", Math.Round(execRuntime/ countStep,2)); //Calculate the average kernel run-time
- collection.Add("EXEC_TIME_COUNT", countStep);
-
- break;
- case "CURKU":
- collection.Add("CURKU", Convert.ToDouble(items[i + 1]));
- i += 1;
- break;
- case "PROGRESS":
- collection.Add("PROGRESS1", Convert.ToDouble(items[i + 1])); //First progress value
- collection.Add("PROGRESS2", Convert.ToDouble(items[i + 2])); //Total progress value
- collection.Add("PROGRESS_DIV", Math.Round(Convert.ToDouble(items[i + 1])/Convert.ToInt64(items[i + 2]),15)); //Total progress value
- i += 2;
- break;
- case "RECHASH":
- collection.Add("RECHASH1", Convert.ToDouble(items[i + 1])); //First RECHASH value
- collection.Add("RECHASH2", Convert.ToDouble(items[i + 2])); //Second RECHASH value
- i += 2;
- break;
- case "RECSALT":
- collection.Add("RECSALT1", Convert.ToDouble(items[i + 1])); //First RECSALT value
- collection.Add("RECSALT2", Convert.ToDouble(items[i + 2])); //Second RECSALT value
- i += 2;
- break;
- case "REJECTED":
- collection.Add("REJECTED", Convert.ToDouble(items[i + 1]));
- collection.Add("PROGRESS_REJ", Math.Round((collection["PROGRESS1"]-collection["REJECTED"]) / collection["PROGRESS2"], 15)); //Total progress value
- i += 1;
- break;
-
- }
- i += 1;
- }
-
- string[] Vars = new String[] { "STATUS", "SPEED_TOTAL", "EXEC_RUNTIME_AVG", "CURKU", "PROGRESS1","RECHASH1","RECSALT1" };
- foreach (string variable in Vars)
- {
- if (!collection.ContainsKey(variable))
- {
- Console.WriteLine("Failed to parse {0} variable, something went wrong", variable);
- }
- }
- }
-
-
- private void parseStatus2(string statusLine, ref Dictionary collection)
- {
-
- CultureInfo customCulture = (CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
- customCulture.NumberFormat.NumberDecimalSeparator = ".";
- System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
-
- Match match = Regex.Match(statusLine, ":[0-9]{1,}:[0-9.]{1,}(\n|\r|\r\n)", RegexOptions.IgnoreCase); //Match only the progress line using regex
- long counter = 0;
- double leftT = 0;
- double rightT = 0;
-
- while (match.Success)
- {
-
- string[] items = match.ToString().TrimEnd().Split(':');
-
-
- collection.Add("LEFT" + counter, Convert.ToDouble(Decimal.Parse(items[1],CultureInfo.InvariantCulture)));
- collection.Add("RIGHT" + counter, Convert.ToDouble(Decimal.Parse(items[2], CultureInfo.InvariantCulture)));
- leftT += Convert.ToDouble(Decimal.Parse(items[1], CultureInfo.InvariantCulture));
- rightT += Convert.ToDouble(Decimal.Parse(items[2], CultureInfo.InvariantCulture));
- counter++;
- match = match.NextMatch();
- }
- collection.Add("LEFT_TOTAL" ,leftT);
- collection.Add("RIGHT_TOTAL", rightT);
-
- }
-
- public Boolean runBenchmark(int benchMethod, int benchSecs, ref Dictionary collection,Boolean legacy)
- {
-
- StringBuilder stdOutBuild = new StringBuilder();
-
- string suffixArgs = " --restore-disable --potfile-disable --machine-readable --session=hashtopolis";
- string suffixExtra = "";
-
- if (benchMethod == 1)
- {
- suffixExtra = " --runtime=" + benchSecs;
- }
- else if (benchMethod == 2)
- {
- suffixExtra = " --progress-only";
- }
-
- if (legacy) //--weak was removed post HC 3.6, don't issue this command
- {
- suffixArgs = suffixArgs + "--weak=0" + suffixExtra;
- }
- else
- {
- suffixArgs = suffixArgs + suffixExtra;
- }
-
- ProcessStartInfo pInfo = new ProcessStartInfo();
- pInfo.FileName = Path.Combine(hcDirectory, hcBinary);
-
- if (!File.Exists(pInfo.FileName))
- {
- Console.WriteLine("Could not locate " + pInfo.FileName);
- return false;
- }
-
- pInfo.WorkingDirectory = hcDirectory;
- pInfo.Arguments = hcArgs + suffixArgs;
- pInfo.UseShellExecute = false;
- pInfo.RedirectStandardError = true;
- pInfo.RedirectStandardOutput = true;
-
-
- if (debugFlag)
- {
- Console.WriteLine("Using {0} as working directory", filesDir);
- Console.WriteLine(pInfo.FileName + pInfo.Arguments);
- }
-
-
- Process hcProcBenchmark = new Process();
- hcProcBenchmark.StartInfo = pInfo;
-
- hcProcBenchmark.ErrorDataReceived += (sender, argu) => outputError(argu.Data);
-
- if (benchMethod == 1)
- {
- Console.WriteLine("Server requested the client benchmark this task for {0} seconds", benchSecs);
-
- }
- else
- {
- Console.WriteLine("Server has requested the client perform a speed benchmark");
-
- }
- try
- {
- hcProcBenchmark.Start();
- hcProcBenchmark.BeginErrorReadLine();
-
- while (!hcProcBenchmark.HasExited)
- {
- while (!hcProcBenchmark.StandardOutput.EndOfStream)
- {
-
- string stdOut = hcProcBenchmark.StandardOutput.ReadLine().TrimEnd();
- stdOutBuild.AppendLine(stdOut);
- if (stdOut.Contains("STATUS\t") && benchMethod !=2)
- {
-
- {
- parseStatus1(stdOut, ref collection);
- }
-
- break;
- }
- }
- }
- hcProcBenchmark.StandardOutput.Close();
-
- }
- finally
- {
- hcProcBenchmark.Close();
- }
-
- if (stdOutBuild.ToString().Contains("Parsing Hashes: 0/")) //Can read from stderr for no hashes loaded, but this also works.
- {
- return false;
- }
- else
- {
- Console.WriteLine(stdOutBuild.ToString());
- }
-
- if (benchMethod == 2)
- {
- parseStatus2(stdOutBuild.ToString(),ref collection);
- }
-
- return true;
- }
-
- private static void parseKeyspace(string line, ref long keySpace)
- {
- line = line.TrimEnd();
-
- if (!long.TryParse(line, out keySpace))
- {
- Console.WriteLine("There was an error parsing the keyspace, setting keyspace to 0. Please review attack cmd");
- keySpace = 0; //Return 0 which will throw error
- }
-
- }
-
- public string getVersion2(ref string[] versionNum)
- {
- ProcessStartInfo pInfo = new ProcessStartInfo();
- pInfo.FileName = Path.Combine(hcDir, hcBin);
- pInfo.WorkingDirectory = filesDir;
- pInfo.Arguments = "--version";
- pInfo.UseShellExecute = false;
- pInfo.RedirectStandardError = true;
- pInfo.RedirectStandardOutput = true;
- Process hcGetVersion = new Process();
-
- hcGetVersion.StartInfo = pInfo;
- string versionString = "";
-
- try
- {
- hcGetVersion.Start();
- versionString = hcGetVersion.StandardOutput.ReadToEnd().TrimEnd();
- hcGetVersion.WaitForExit();
-
- Regex regex = new Regex("v(?[^-]*)");
-
- Match match = regex.Match(versionString);
-
- if (match.Success)
- {
- versionNum = match.Groups["version"].Value.Split('.');
-
- }
- else
- {
- versionNum = versionString.Split('.'); //Hashcat changed the output after 3.6 to exclude the version string
- }
- }
- catch
- {
- Console.WriteLine("Something went wrong when trying to get HC version");
- }
- finally
- {
- if (hcGetVersion.ExitCode != 0)
- {
- Console.WriteLine("Something went when trying to get HC version");
- }
-
- hcGetVersion.Close();
- }
-
- return versionString;
- }
- public string getVersion()
- {
-
- string stdOutSingle = "";
- ProcessStartInfo pInfo = new ProcessStartInfo();
- pInfo.FileName = Path.Combine(hcDir, hcBin);
- pInfo.WorkingDirectory = filesDir;
- pInfo.Arguments = "--version";
- pInfo.UseShellExecute = false;
- pInfo.RedirectStandardError = true;
- pInfo.RedirectStandardOutput = true;
- Process hcGetVersion = new Process();
- hcGetVersion.StartInfo = pInfo;
- hcGetVersion.ErrorDataReceived += (sender, argu) => outputError(argu.Data);
-
- try
- {
-
- hcGetVersion.Start();
- while (!hcGetVersion.HasExited)
- {
- while (!hcGetVersion.StandardOutput.EndOfStream)
- {
-
- string stdOut = hcGetVersion.StandardOutput.ReadLine().TrimEnd();
- stdOutSingle = stdOut; //We just want the last line
- }
- }
- hcGetVersion.StandardOutput.Close();
-
- }
- catch
- {
- Console.WriteLine("Something went wrong when trying to get HC version");
- }
- finally
- {
-
- hcGetVersion.Close();
- }
-
- return stdOutSingle;
-
-
- }
-
- public Boolean runKeyspace(ref long keySpace)
- {
-
- Console.WriteLine("Server has requested the client measure the keyspace for this task");
-
- string stdOutSingle = "";
- string suffixArgs = " --session=hashtopolis --keyspace --quiet";
- ProcessStartInfo pInfo = new ProcessStartInfo();
- pInfo.FileName = Path.Combine(hcDirectory, hcBinary);
-
- if (!File.Exists(pInfo.FileName))
- {
- Console.WriteLine("Could not locate " + pInfo.FileName);
- return false;
- }
-
- pInfo.WorkingDirectory = hcDirectory;
-
-
- pInfo.Arguments = hcArgs + suffixArgs;
- pInfo.UseShellExecute = false;
- pInfo.RedirectStandardError = true;
- pInfo.RedirectStandardOutput = true;
- if (debugFlag)
- {
- Console.WriteLine("Using {0} as working directory", pInfo.WorkingDirectory);
- Console.WriteLine(pInfo.FileName + " " + pInfo.Arguments);
- }
-
- Process hcProcKeyspace = new Process();
- hcProcKeyspace.StartInfo = pInfo;
- hcProcKeyspace.ErrorDataReceived += (sender, argu) => outputError(argu.Data);
-
- try
- {
- hcProcKeyspace.Start();
- hcProcKeyspace.BeginErrorReadLine();
-
- while (!hcProcKeyspace.HasExited)
- {
- while (!hcProcKeyspace.StandardOutput.EndOfStream)
- {
- string stdOut = hcProcKeyspace.StandardOutput.ReadLine().TrimEnd();
- stdOutSingle = stdOut; //We just want the last line
- }
- }
- hcProcKeyspace.StandardOutput.Close();
-
- }
- catch
- {
- Console.WriteLine("Something went wrong with keyspace measuring");
- }
- finally
- {
- if (hcProcKeyspace.ExitCode != 0)
- {
- Console.WriteLine("Something went wrong with keyspace measuring");
- }
-
- hcProcKeyspace.Close();
- }
-
- parseKeyspace(stdOutSingle,ref keySpace);
-
- return true;
- }
-
- public static void outputError(string stdError)
- {
- if (!string.IsNullOrEmpty(stdError))
- {
- Console.WriteLine(stdError.Trim());
- }
-
- }
-
- public void stdOutTrigger(string stdOut)
- {
-
- if (!string.IsNullOrEmpty(stdOut))
- {
-
- if ((!stdOut.Contains("STATUS\t") && (!stdOut.Contains("EXEC_RUNTIME\t")) && (!stdOut.Contains("CURKU\t"))))
- {
- if (stdOut.StartsWith("Hashfile"))
- {
- if (!stdOut.Contains("Line-length exception"))
- {
- lock (crackedLock)
- {
- hashlist.Add(stdOut);
- }
- }
- else
- {
- lock (crackedLock)
- {
- hashlist.Add(stdOut);
- }
- }
- }
- else
- {
- lock (crackedLock)
- {
- hashlist.Add(stdOut);
- }
- }
- }
-
- else
-
- {
- lock (statusLock)
- {
- Dictionary dStats = new Dictionary();
-
- parseStatus1(stdOut, ref dStats);
-
-
- lock (packetLock)
- {
- lock (crackedLock)
- {
- passedPackets.Add(new Packets { statusPackets = new Dictionary(dStats), crackedPackets = new List(hashlist) });
- dStats.Clear();
- hashlist.Clear();
-
- }
- }
- }
- }
-
- }
- }
-
-
-
- public Boolean startAttack(long chunk, long taskID, long skip, long size, long interval, string taskPath)
- {
-
- string oPath = Path.Combine(taskPath, taskID + "_" + chunk + ".txt"); // Path to write th -o file
- if (File.Exists(oPath))
- {
- File.Delete(oPath); // We need to wipe the outfile if it exists since we want to start at pos 0
- }
-
- ProcessStartInfo pInfo = new ProcessStartInfo();
-
- pInfo.FileName = Path.Combine(hcDir, hcBin);
-
- if (!File.Exists(pInfo.FileName))
- {
- Console.WriteLine("Could not locate " + pInfo.FileName);
- return false;
- }
-
- 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;
- pInfo.WorkingDirectory = hcDirectory;
- pInfo.UseShellExecute = false;
- pInfo.RedirectStandardError = true;
- pInfo.RedirectStandardOutput = true;
-
- if (debugFlag)
- {
- Console.WriteLine(pInfo.FileName + " " + pInfo.Arguments);
- }
-
- hcProc = new Process { };
- hcProc.StartInfo = pInfo;
- // create event handlers for normal and error output
-
- hcProc.OutputDataReceived += (sender, argu) => stdOutTrigger(argu.Data);
- hcProc.ErrorDataReceived += (sender, argu) => outputError(argu.Data);
- hcProc.EnableRaisingEvents = true;
- hcProc.Start();
- hcProc.BeginOutputReadLine();
- hcProc.BeginErrorReadLine();
-
- hcProc.WaitForExit();
- hcProc.CancelErrorRead();
- hcProc.CancelOutputRead();
- if (debugFlag)
- {
- Console.WriteLine("Attack finished");
- }
-
-
- hcProc.Dispose();
-
- return true;
-
- }
- }
-}
diff --git a/csharp/hashtopolis/hashcatUpdateClass.cs b/csharp/hashtopolis/hashcatUpdateClass.cs
deleted file mode 100644
index e14c700..0000000
--- a/csharp/hashtopolis/hashcatUpdateClass.cs
+++ /dev/null
@@ -1,192 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Diagnostics;
-
-namespace hashtopolis
-{
-
- class hashcatUpdateClass
- {
-
- public class hcUpdateProper
- {
- public string action = "downloadBinary";
- public string type = "cracker";
- public string token = "";
- public int binaryVersionId = 0;
- public int force { set; get; }
-
- }
-
- public Boolean debugFlag { get; set; }
- public string AppPath { get; set; }
- public _7zClass sevenZip { get; set; }
- public registerClass client { get; set; }
- public int binaryVersionId { get; set; }
-
-
- 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;
- }
- }
-
-
- 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;
-
- }
-
- }
-}
diff --git a/csharp/hashtopolis/hashtopolis.csproj b/csharp/hashtopolis/hashtopolis.csproj
deleted file mode 100644
index 489c60e..0000000
--- a/csharp/hashtopolis/hashtopolis.csproj
+++ /dev/null
@@ -1,99 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- {199AD37B-3000-4CC0-992C-87738F84C768}
- Exe
- Properties
- hashtopolis
- hashtopolis
- v4.5
- 512
- true
-
-
-
- AnyCPU
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- AnyCPU
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- false
-
-
- true
- bin\x64\Debug\
- DEBUG;TRACE
- full
- x64
- prompt
- MinimumRecommendedRules.ruleset
- false
-
-
- bin\x64\Release\
- TRACE
- true
- pdbonly
- x64
- prompt
- MinimumRecommendedRules.ruleset
- false
-
-
- small.ico
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/csharp/hashtopolis/hashtopolis.csproj.user b/csharp/hashtopolis/hashtopolis.csproj.user
deleted file mode 100644
index 9fcb30c..0000000
--- a/csharp/hashtopolis/hashtopolis.csproj.user
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
\ No newline at end of file
diff --git a/csharp/hashtopolis/jsonClass.cs b/csharp/hashtopolis/jsonClass.cs
deleted file mode 100644
index 8d18b23..0000000
--- a/csharp/hashtopolis/jsonClass.cs
+++ /dev/null
@@ -1,254 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Net;
-using System.Collections;
-using System.Web.Script.Serialization;
-using System.Linq;
-using System.Threading;
-
-public class jsonClass
-{
-
- public Boolean debugFlag { get; set; }
- public string connectURL { get; set; }
- Random rnd = new Random(Guid.NewGuid().GetHashCode()); //init and seed the random generator for use in re-try backdown
- JavaScriptSerializer jss = new JavaScriptSerializer();
- //Checks if json string has success response
- //Will print the error messages on fail
- public Boolean isJsonSuccess(string jsonString)
- {
- jss.MaxJsonLength = 2147483647;
-
- if (debugFlag)
- Console.WriteLine(jsonString);
-
- try
- {
- Dictionary dict = jss.Deserialize>(jsonString);
-
- if (dict.ContainsKey("response"))
- {
- if (dict["response"] == "SUCCESS")
- {
- return true;
- }
- else
- {
- Console.WriteLine(dict["response"]);
- if (dict.ContainsKey("message"))
- {
- Console.WriteLine(dict["message"]);
- }
- }
- }
- return false;
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Data);
- Console.WriteLine("Empty string for success check");
- return false;
- }
-
- }
-
-
- //Returns variable from json string, values are casted to string
- public string getRetVar(string jsonString, string itemVar)
- {
- jss.MaxJsonLength = 2147483647;
-
- try
- {
- var dict = jss.Deserialize>(jsonString);
- if (dict.ContainsKey(itemVar))
- {
- return Convert.ToString(dict[itemVar]);
- }
- }
- catch(Exception e)
- {
- Console.WriteLine(e);
- Console.WriteLine("Error while trying to get {0} from jaon string", itemVar);
- }
-
-
- return null;
- }
-
- //Returns json string array to arraylist
- //This is probably redundant as we can use the below function gerRetList to return a better typed array
- public ArrayList getRetArray(string jsonString, string itemVar)
- {
- jss.MaxJsonLength = 2147483647;
-
- var dict = jss.Deserialize>(jsonString);
- if (dict.ContainsKey(itemVar))
- {
- return dict[itemVar];
- }
-
- return null;
- }
-
- //Return json string array to list with type string
- public List getRetList(string jsonString, string itemVar)
- {
- jss.MaxJsonLength = 2147483647;
-
- var dict = jss.Deserialize>(jsonString);
- if (dict.ContainsKey(itemVar))
- {
- List newList = new List(dict[itemVar].ToArray(typeof(string))); //Convert Array to List
- return newList;
- }
-
- return dict[itemVar];
- }
-
- //Converts array=>key to jason string format
- public string toJson(object obj)
- {
- jss.MaxJsonLength = 2147483647;
-
- var json = jss.Serialize(obj);
- if (debugFlag)
- Console.WriteLine(json);
- return json;
- }
-
-
- public string jsonSendOnce(string json)
- {
- var request = (HttpWebRequest)WebRequest.Create(connectURL);
- request.ContentType = "application/json";
- request.Method = "POST";
- request.KeepAlive = false;
-
- int randomTime = 0;
-
- HttpWebResponse response = null;
- int tries = 0;
- {
- Thread.Sleep(tries * 1000 + randomTime * 1000);
- try
- {
- using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream()))
- {
- streamWriter.Write(json);
- }
-
- }
- catch (WebException ex)
- {
- Console.WriteLine(ex.Message);
- return null ;
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- return null;
- }
-
- try
- {
- response = (HttpWebResponse)request.GetResponse();
- string result;
- using (var streamReader = new StreamReader(response.GetResponseStream()))
- {
- result = streamReader.ReadToEnd();
- }
-
- return result;
- }
- catch(WebException ex)
- {
- Console.WriteLine(ex.Message);
- }
-
-
- return null;
-
- }
- }
-
- //On fail, the client will use a backdown algorithm and retry 30 times
- public string jsonSend(string json, int timeOutSecs = 30)
- {
-
- int tries = 0;
- int randomTime = 0;
- string result = null;
-
- do
- {
- Thread.Sleep(tries * 1000 + randomTime * 1000);
-
- try
- {
-
- var request = (HttpWebRequest)WebRequest.Create(connectURL);
- request.ContentType = "application/json";
- request.Method = "POST";
- request.Timeout = timeOutSecs * 1000;
- request.KeepAlive = true;
-
- HttpWebResponse response = null;
-
- using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream()))
- {
- streamWriter.Write(json);
- }
-
-
- response = (HttpWebResponse)request.GetResponse();
- if (response.StatusCode != HttpStatusCode.OK)
- {
- Console.WriteLine("Invalid HTTP response");
- Console.WriteLine("terminating");
- Environment.Exit(0);
- }
-
-
- using (var streamReader = new StreamReader(response.GetResponseStream()))
- {
- result = streamReader.ReadToEnd();
- }
- if (string.IsNullOrEmpty(result))
- {
- Console.WriteLine("server is not responding to requests");
- Console.WriteLine("terminating");
- Environment.Exit(0);
- }
- break;
- }
-
- catch (WebException ex)
- {
- if (ex.Status == WebExceptionStatus.Timeout)
- {
- Console.WriteLine("Server timed out");
- Console.WriteLine(ex.Message);
- tries++;
- randomTime = rnd.Next(1, tries);
- Console.WriteLine("Attempting to re-connect in {0} seconds", tries + randomTime);
- }
- }
- catch (Exception)
- {
- Console.WriteLine("Could not connect to specified server, exiting");
- tries++;
- randomTime = rnd.Next(1, tries);
- Console.WriteLine("Attempting to re-connect in {0} seconds", tries + randomTime);
- }
-
- } while (tries <= 10);
-
-
- return result; //Return json string
-
- }
-
-
-}
\ No newline at end of file
diff --git a/csharp/hashtopolis/registerClass.cs b/csharp/hashtopolis/registerClass.cs
deleted file mode 100644
index cfef1a0..0000000
--- a/csharp/hashtopolis/registerClass.cs
+++ /dev/null
@@ -1,485 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Management;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-public class registerClass
-{
- private string tokenPath;
- public string tokenID { get; set; }
- public int osID { get; set; }
- public Boolean is64Bit { get; set; }
- public string connectURL { get; set; }
- public Boolean debugFlag { set; get; }
- public string crackerPath { set; get; }
- public string crackerBinary { set; get; }
-
- //Suppress P/Invoke warning my using NativeMethods
- internal static class NativeMethods
- {
- [DllImport("libc")]
- public static extern int uname(IntPtr buf);
- }
-
- //Code from Pinta Core Project
- private bool IsRunningOnMac()
- {
-
- IntPtr buf = IntPtr.Zero;
- try
- {
- buf = Marshal.AllocHGlobal(8192);
- // This is a hacktastic way of getting sysname from uname ()
- if (NativeMethods.uname(buf) == 0)
- {
- string os = Marshal.PtrToStringAnsi(buf);
- if (os == "Darwin")
- return true;
- }
- }
- catch
- {
- }
- finally
- {
- if (buf != IntPtr.Zero)
- Marshal.FreeHGlobal(buf);
- }
- return false;
- }
-
- //Code to run commands
- private static string ReadProcessOutput(string procName, string args)
- {
- try
- {
- Process p = new Process();
- p.StartInfo.UseShellExecute = false;
- p.StartInfo.RedirectStandardOutput = true;
- if (args != null && args != "") p.StartInfo.Arguments = " " + args;
- p.StartInfo.FileName = procName;
- p.Start();
- string output = p.StandardOutput.ReadToEnd();
- p.WaitForExit();
- if (output == null) output = "";
- output = output.Trim();
- return output;
- }
- catch
- {
- return "";
- }
- }
-
- //Detect whether we are running under mono
- private void setOS()
- {
- is64Bit = false; //Default to 32bit unless 64bit detected
- if (Type.GetType("Mono.Runtime") != null)
- {
-
- string machine = ReadProcessOutput("uname", "-m");
- if (machine.Contains("x86_64"))
- {
- is64Bit = true;
- }
-
- if (!IsRunningOnMac())
- {
-
- if (is64Bit)
- {
- Console.WriteLine("System is Linux 64-bit");
- }
- else
- {
- Console.WriteLine("System is Linux 32-bit");
- }
- osID = 0;
- }
- else
- {
- if (is64Bit)
- {
- Console.WriteLine("System is MAC 64-bit");
- }
- else
- {
- Console.WriteLine("System is MAC 32-bit");
- };
- osID = 2;
- }
-
-
-
- }
- else
- {
-
- if (Environment.Is64BitProcess)
- {
- Console.WriteLine("System is Windows 64-bit");
- is64Bit = true;
- }
- else
- {
- Console.WriteLine("System is Windows 32-bit");
- }
- osID = 1;
- }
-
- }
-
- public void setPath(string path)
- {
- tokenPath = Path.Combine(path,"token");
- }
-
- private class Register
- {
- public string action { get; set; }
- public string voucher { get; set; }
- public string name { get; set; }
- }
-
- private class UpdateClient
- {
- public string action { get; set; }
- public string token { get; set; }
- public string uid { get; set; }
- public int os { get; set; }
- public IList devices { get; set; }
- }
-
-
- private bool registerAgent(string iVoucher)
- {
- jsonClass jsC = new jsonClass { debugFlag = debugFlag, connectURL = connectURL };
- string machineName = "default";
- setOS();
-
- if (osID == 1) //Windows
- {
- machineName = System.Environment.MachineName;
- }
- else if (osID == 0) //Linux
- {
- ProcessStartInfo pinfo = new ProcessStartInfo();
- pinfo = new ProcessStartInfo();
- pinfo.FileName = "uname";
- pinfo.Arguments = "-n";
- pinfo.UseShellExecute = false;
- pinfo.RedirectStandardOutput = true;
- Process uname = new Process();
- uname.StartInfo = pinfo;
- uname.Start();
- while (!uname.HasExited)
- {
- while (!uname.StandardOutput.EndOfStream)
- {
- string stdOut = uname.StandardOutput.ReadLine();
- machineName = stdOut;
- }
- }
- }
- else if (osID == 2) //Mac
- {
- //Get Machine Name (Mac)
- ProcessStartInfo pinfo = new ProcessStartInfo();
- pinfo.FileName = "scutil";
- pinfo.Arguments = " --get ComputerName";
- pinfo.UseShellExecute = false;
- pinfo.RedirectStandardError = true;
- pinfo.RedirectStandardOutput = true;
-
- Process getMachineName = new Process();
- getMachineName.StartInfo = pinfo;
- getMachineName.Start();
- while (!getMachineName.HasExited)
- {
- while (!getMachineName.StandardOutput.EndOfStream)
- {
- string stdOut = getMachineName.StandardOutput.ReadLine();
- machineName = stdOut;
- }
- }
-
- }
-
- Register regist = new Register
- {
- action = "register",
- voucher = iVoucher,
- name = machineName,
- };
-
- string jsonString = jsC.toJson(regist);
- string ret = jsC.jsonSend(jsonString);
-
- String guid = Guid.NewGuid().ToString(); //Generate GUID
-
- if (jsC.isJsonSuccess(ret))
- {
- tokenID = jsC.getRetVar(ret, "token");
- File.WriteAllText(tokenPath, tokenID);
-
- updateAgentInformation();
-
- return true;
- }
- return false;
-
- }
-
-
-
- private bool updateAgentInformation()
- {
- Console.WriteLine("Sending server client information");
- jsonClass jsC = new jsonClass { debugFlag = debugFlag, connectURL = connectURL };
-
- setOS();
-
-
- List deviceList;
- string CPUModel = "";
-
- deviceList = new List { };
-
- if (osID == 1)
- {
- ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Description FROM Win32_VideoController"); //Prep object to query windows GPUs
-
- //Get Devices (Windows)
- foreach (ManagementObject mo in searcher.Get())
- {
- deviceList.Add(mo.Properties["Description"].Value.ToString().Trim());
- }
-
- //Get CPU (Windows)
- searcher = new ManagementObjectSearcher("SELECT Name from Win32_Processor"); //Prep object to query windows CPUs
- foreach (ManagementObject mo in searcher.Get())
- {
- deviceList.Add(mo.Properties["Name"].Value.ToString().Trim());
- }
-
- }
- else if(osID == 0)
- {
-
- //Get GPU Devices (Linux) use lspci to query GPU
- ProcessStartInfo pinfo = new ProcessStartInfo();
- pinfo.FileName = "lspci";
- pinfo.UseShellExecute = false;
- pinfo.RedirectStandardOutput = true;
- Process lspci = new Process();
- lspci.StartInfo = pinfo;
- lspci.Start();
- List searchList = new List(new string[] { "VGA compatible controller: ", "3D controller: "});
-
-
- while (!lspci.HasExited)
- {
- while (!lspci.StandardOutput.EndOfStream)
- {
- string stdOut = lspci.StandardOutput.ReadLine();
- foreach (string searchItem in searchList)
- {
- int pozi = stdOut.IndexOf(searchItem);
- if (pozi != -1)
- {
- deviceList.Add(stdOut.Substring(pozi + searchItem.Length));
- }
- }
-
- }
- }
-
- //Get CPU (Linux) use lscpu to query CPU
- pinfo.FileName = "lscpu";
- pinfo.UseShellExecute = false;
- pinfo.RedirectStandardOutput = true;
- lspci.StartInfo = pinfo;
- lspci.Start();
- string searchString = "Model Name: ";
- while (!lspci.HasExited)
- {
- while (!lspci.StandardOutput.EndOfStream)
- {
- string stdOut = lspci.StandardOutput.ReadLine();
- int pos = stdOut.IndexOf(searchString);
- if (pos != -1)
- {
- deviceList.Add(stdOut.Substring(pos + searchString.Length));
- }
- }
- }
- }
- else if(osID == 2)
- {
- //Get Machine Name (Mac)
- ProcessStartInfo pinfo = new ProcessStartInfo();
- pinfo.FileName = "scutil";
- pinfo.Arguments = " --get ComputerName";
- pinfo.UseShellExecute = false;
- pinfo.RedirectStandardError = true;
- pinfo.RedirectStandardOutput = true;
-
-
- //Get Devices (Mac)
- pinfo.FileName = "system_profiler";
- pinfo.Arguments = " -detaillevel mini";
- Process getDevices = new Process();
- getDevices.StartInfo = pinfo;
-
- Console.WriteLine("Please wait while devices are being enumerated...");
- getDevices.Start();
- Boolean triggerRead = false;
-
- string searchID = "Chipset Model: ";
-
- while (!getDevices.StandardOutput.EndOfStream)
- {
-
- string stdOut = getDevices.StandardOutput.ReadLine().TrimEnd();
-
- if (triggerRead == true)
- {
- if (stdOut.Contains("Total Number of Cores:")) //Just incase we go past
- {
- break;
- }
- if (stdOut.Contains("Hardware:"))
- {
- searchID = "Processor Name: ";
- }
- int pos = stdOut.IndexOf(searchID);
-
- if (pos != -1)
- {
- if (searchID == "Chipset Model: ")
- {
-
- deviceList.Add(stdOut.Substring(pos + searchID.Length));
-
- }
- else if (searchID == "Processor Name: ")
- {
- CPUModel = stdOut.Substring(pos + searchID.Length);
- searchID = "Processor Speed: ";
- }
- else if (searchID == "Processor Speed: ")
- {
- CPUModel = CPUModel + " @ " + stdOut.Substring(pos + searchID.Length);
- deviceList.Add(CPUModel);
- break;
- }
- }
- }
- else if (triggerRead == false)
- {
- if (stdOut.Contains("Graphics/Displays:"))
- {
- triggerRead = true;
- }
- }
-
-
- }
- }
-
- String guid = Guid.NewGuid().ToString(); //Generate GUID
-
- UpdateClient update = new UpdateClient
- {
- action = "updateInformation",
- token = tokenID,
- uid = guid,
- os = osID,
- devices = deviceList
- };
-
- string jsonString = jsC.toJson(update);
- string ret = jsC.jsonSend(jsonString);
-
- if (jsC.isJsonSuccess(ret))
- {
- return true;
- }
- return false;
-
- }
- public bool loginAgent()
- {
- if (!loadToken())
- {
- Console.WriteLine("Unable to find existing token, please enter voucher");
- while (registerAgent(Console.ReadLine()) == false)
- {
- Console.WriteLine("Invalid voucher, please try again");
- }
-
-
- }
- else
- {
- Console.WriteLine("Existing token found");
- jsonClass jsC = new jsonClass { connectURL = connectURL, debugFlag = debugFlag };
-
- var arrayKey = new Dictionary
- {
- { "action", "login" },
- { "clientSignature", "generic-csharp"},
- { "token",tokenID},
- };
-
- string jsonString = jsC.toJson(arrayKey);
- string ret = jsC.jsonSend(jsonString);
-
- if (jsC.isJsonSuccess(ret))
- {
-
- updateAgentInformation();
- return true;
- }
- else
- {
- Console.WriteLine("Existing token is invalid, please enter voucher");
- while (registerAgent(Console.ReadLine()) == false)
- {
- Console.WriteLine("Invalid voucher, please try again");
- }
- }
- return false;
- }
- return true;
-
- }
-
- public bool loadToken()
- {
-
- if (tokenID == "")
- {
- if (File.Exists(tokenPath))
- {
- tokenID = File.ReadAllText(tokenPath);
- if (tokenID == "")
- {
- File.Delete(tokenPath);
- return false;
- }
- }
- else
- {
- return false;
- }
- setOS();
- }
-
- return true;
- }
-
-}
diff --git a/csharp/hashtopolis/small.ico b/csharp/hashtopolis/small.ico
deleted file mode 100644
index 1eb93a9..0000000
Binary files a/csharp/hashtopolis/small.ico and /dev/null differ
diff --git a/csharp/hashtopolis/taskClass.cs b/csharp/hashtopolis/taskClass.cs
deleted file mode 100644
index a5fa585..0000000
--- a/csharp/hashtopolis/taskClass.cs
+++ /dev/null
@@ -1,854 +0,0 @@
-using System;
-using System.Collections;
-using System.IO;
-using System.Collections.Generic;
-using System.Threading;
-
-namespace hashtopolis
-{
- class taskClass
- {
-
- hashcatClass hcClass = new hashcatClass();
-
- private string attackcmd;
- private string cmdpars;
- private Boolean stipPath;
- private string actualHLpath;
- private int benchTime, hashlistID, taskID, statusTimer, benchMethod, crackerId;
- private ArrayList files;
- private string hashlistAlias = "#HL#";
-
- private string prefixServerdl = "";
-
- private long chunkNo, skip, length;
- private string filepath, hashpath, appPath, zapPath, tasksPath;
-
- public Boolean debugFlag { get; set; }
- public _7zClass sevenZip { get; set; }
- public registerClass client { get; set; }
- public Boolean legacy { get; set; }
- private int offset = 0;
-
- public void setOffset()
- {
- if (!legacy)
- {
- offset = 1;
- Console.WriteLine("Using new STATUS codes");
- }
- else
- {
- Console.WriteLine("Using legacy STATUS codes");
- }
- }
-
-
- private List primaryCracked; //Stores the cracked hashes as they come
- 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
-
- public void setDirs(string fpath)
- {
- appPath = fpath;
- filepath = Path.Combine(fpath, "files");
- hashpath = Path.Combine(fpath, "hashlists");
- zapPath = Path.Combine(fpath, "hashlists", "zaps");
- tasksPath = Path.Combine(fpath, "tasks");
- prefixServerdl = client.connectURL.Substring(0, client.connectURL.IndexOf("/api/")) + "/";
-
- }
-
- private class Task
- {
- public string action { get; set; }
- public string token { get; set; }
- }
-
- private class FileProps
- {
- public string action { get; set; }
- public string token { get; set; }
- public int taskId { get; set; }
- public string file { get; set; }
- }
-
-
- private class chunkProps
- {
- public string action = "getChunk";
- public string token { get; set; }
- public int taskId { get; set; }
- }
-
- private class hashlistProps
- {
- public string action = "getHashlist";
- public string token { get; set; }
- public int hashlistId { get; set; }
- }
-
- private class keyspaceProps
- {
- public string action = "sendKeyspace";
- public string token { get; set; }
- public int taskId { get; set; }
- public long keyspace { get; set; }
- }
-
- private class benchProps
- {
- public string action = "sendBenchmark";
- public string token { get; set; }
- public int taskId { get; set; }
- public string type { get; set; }
- public string result { get; set; }
- }
-
- private class errorProps
- {
- public string action = "clientError";
- public string token { get; set; }
- public int taskId { get; set; }
- public string message { get; set; }
- }
-
- private class solveProps
- {
- public string action = "sendProgress";
- public string token { get; set; }
- public long chunkId { get; set; }
- public double keyspaceProgress { get; set; }
- public double relativeProgress { get; set; }
- //public double total { get; set; }
- public double speed { get; set; }
- public double state { get; set; }
- public List cracks { get; set; }
- }
-
- public Boolean getHashes(int inTask)
- {
-
- actualHLpath = Path.Combine(hashpath, Path.GetFileName(inTask.ToString()));
-
- Console.WriteLine("Downloading hashlist for this task, please wait...");
-
- hashlistProps hProps = new hashlistProps
- {
- token = client.tokenID,
- hashlistId = inTask
- };
- jsonClass jsC = new jsonClass { debugFlag = debugFlag, connectURL = client.connectURL };
- string jsonString = jsC.toJson(hProps);
- string ret = jsC.jsonSend(jsonString,300); //300 second timeout
-
- if (jsC.isJsonSuccess(ret))
- {
-
- getURLtoFile(jsC.getRetVar(ret, "url"), actualHLpath);
- }
-
-
- /*
- //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
- if (ret[0] != '{' && ret[ret.Length - 1] != '}')
- {
- File.WriteAllText(actualHLpath, ret);
- Directory.CreateDirectory(Path.Combine(hashpath, "zaps" + inTask.ToString()));
- }
- else
- {
- if (jsC.isJsonSuccess(ret))
- {
- string b64data = jsC.getRetVar(ret,"data");
- byte[] binArray = System.Convert.FromBase64String(b64data);
- File.WriteAllBytes(actualHLpath, binArray);
- stipPath = true; //Strip path for all HL recieved binary hashlsits
-
- }
- else
- {
- return false;
- }
-
- }
- */
-
- return true;
- }
-
- public string speedCalc(double speed)
- {
- int count = 0;
- while (speed > 1000)
- {
- speed = speed / 1000;
- count++;
- }
-
- speed = Math.Round(speed, 2);
-
- if (count == 0)
- {
- return speed.ToString("F") + "H/s";
- }
- else if (count == 1)
- {
- return speed.ToString("F") + "KH/s";
- }
- else if (count == 2)
- {
- return speed.ToString("F") + "MH/s";
- }
- else if (count == 3)
- {
- return speed.ToString("F") + "GH/s";
- }
- else if (count == 4)
- {
- return speed.ToString("F") + "TH/s";
- }
- return speed.ToString("F");
- }
-
-
- //This runs as an independant thread and uploads the STATUS generated from the hcAttack
- //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
- //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
- public void threadPeriodicUpdate(ref List uploadPackets, ref object objPacketlock)
- {
- System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
- customCulture.NumberFormat.NumberDecimalSeparator = ".";
- System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
-
- jsonClass jsC = new jsonClass {debugFlag = debugFlag, connectURL = client.connectURL };//Initis the json class
- solveProps sProps = new solveProps(); //Init the properties to build our json string
- List receivedZaps = new List { }; //List to store incoming zaps for writing
- string ret =""; //Return string from json post
- string jsonString ="";
- string zapfilePath = zapPath + hashlistID.ToString();
- long zapCount = 0;
- List batchList = new List { };
- double chunkPercent = 0;
- double chunkStart = 0;
- Boolean run = true;
- List singlePacket = new List { };
- int sleepTime = 2500;
- long ulQueue = 0;
- hcClass.debugFlag = debugFlag;
- Boolean firstRun = true;
-
-
-
- string oPath = Path.Combine(tasksPath, taskID + "_" + chunkNo + ".txt"); // Path to write th -o file
-
- while (run)
- {
- Thread.Sleep(sleepTime); //Delay this thread for 2.5 seconds, if this falls behind it will batch the jobs
- lock (objPacketlock)
- {
- if (uploadPackets.Count > 0)
- {
-
- singlePacket.Add(uploadPackets[0]);
- ulQueue = uploadPackets.Count;
- uploadPackets.RemoveAt(0);
- if (uploadPackets.Count > 3)
-
- sleepTime = 200; //Decrese the time we process the queue
- }
- else
- {
- sleepTime = 2500; //Decrese the time we process the queue
- }
- }
-
- if (firstRun == true) //This is a work around to send a server a dummy stat to prevent timeouts on the initial start
- {
- sProps.token = client.tokenID;
- sProps.chunkId = chunkNo;
- sProps.keyspaceProgress = skip;
-
- sProps.relativeProgress = 0;
-
- sProps.speed = 0;
- sProps.state = 3; //Can't find the status code list lets try 3
-
- sProps.cracks = new List();
-
- jsonString = jsC.toJson(sProps);
- ret = jsC.jsonSend(jsonString);
-
- if (!jsC.isJsonSuccess(ret)) //If we received error, eg task was removed just break
- {
- break;
- }
- firstRun = false;
- }
-
- if (singlePacket.Count == 0)
- {
- continue;
- }
-
- try
- {
- {
- //Special override as there is a possible race condition in HC, where STATUS4 doesn't give 100%
- if (singlePacket[0].statusPackets["STATUS"] == 4 + offset)
- {
- singlePacket[0].statusPackets["PROGRESS1"] = singlePacket[0].statusPackets["PROGRESS2"];
- }
-
- sProps.token = client.tokenID;
- sProps.chunkId = chunkNo;
- sProps.keyspaceProgress = singlePacket[0].statusPackets["CURKU"];
-
-
- chunkStart = Math.Floor(singlePacket[0].statusPackets["PROGRESS2"]) / (skip + length) * skip;
- chunkPercent = Math.Round((Convert.ToDouble(singlePacket[0].statusPackets["PROGRESS1"]) - chunkStart) / Convert.ToDouble(singlePacket[0].statusPackets["PROGRESS2"] - chunkStart), 4) * 10000;
-
- sProps.relativeProgress = chunkPercent;
-
- //sProps.total = singlePacket[0].statusPackets["PROGRESS2"];
- sProps.speed = singlePacket[0].statusPackets["SPEED_TOTAL"];
- sProps.state = singlePacket[0].statusPackets["STATUS"] - offset; //Client-side workaround for old STATUS on server
-
- if (singlePacket[0].crackedPackets.Count > 200)
- {
- int max = 200;
-
- //Process the requests in batches of 1000
- while (singlePacket[0].crackedPackets.Count != 0)
- {
- List subChunk = new List(singlePacket[0].crackedPackets.GetRange(0, max));
- singlePacket[0].crackedPackets.RemoveRange(0, max);
- if (singlePacket[0].crackedPackets.Count < max)
- {
- max = singlePacket[0].crackedPackets.Count;
- }
-
- if (stipPath == true)
- {
- for (int i = 0; i <= subChunk.Count-1; i++)
- {
- subChunk[i] = subChunk[i].Replace(actualHLpath + ":", "");
- }
- }
-
- sProps.cracks = subChunk;
- jsonString = jsC.toJson(sProps);
- ret = jsC.jsonSend(jsonString);
-
- if (!jsC.isJsonSuccess(ret)) //If we received error, eg task was removed just break
- {
- break;
- }
- }
-
- }
- else
- {
- if (stipPath == true)
- {
- for (int i =0; i<= singlePacket[0].crackedPackets.Count-1; i++)
- {
- singlePacket[0].crackedPackets[i] = singlePacket[0].crackedPackets[i].Replace(actualHLpath + ":", "");
- }
- }
- sProps.cracks = singlePacket[0].crackedPackets;
-
- jsonString = jsC.toJson(sProps);
- ret = jsC.jsonSend(jsonString);
- }
- }
-
-
- if (jsC.isJsonSuccess(ret))
- {
-
- if (jsC.getRetVar(ret, "agent") == "stop") //Special command sent by server, possibly undocumented
- {
- hcClass.hcProc.CancelOutputRead();
- hcClass.hcProc.CancelErrorRead();
- hcClass.hcProc.Kill();
- run = false;
- Console.WriteLine("Server has instructed the client terminate the task via stop");
- }
-
-
- chunkPercent = chunkPercent / 100; //We already calculated with * 10000 earlier
-
- receivedZaps = jsC.getRetList(ret, "zaps"); //Check whether the server sent out hashes to zap
- if (receivedZaps.Count > 0)
- {
- zapCount++;
- File.WriteAllLines(Path.Combine(zapfilePath,zapCount.ToString()), receivedZaps); //Write hashes for zapping
-
- }
- 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);
- receivedZaps.Clear();
-
-
- }
-
-
- else //We received an error from the server, terminate the run
- {
-
- string writeCracked = Path.Combine(hashpath, Path.GetFileName(hashlistID.ToString())) + ".cracked";
- Console.WriteLine("Writing any cracks in queue to file " + writeCracked);
- File.AppendAllLines(writeCracked, singlePacket[0].crackedPackets);
- lock (objPacketlock)
- {
- if (uploadPackets.Count > 0)
- {
- for (int i = 0; i < uploadPackets.Count; i++)
- {
- if (uploadPackets[i].crackedPackets.Count > 0)
- {
- File.AppendAllLines(writeCracked, uploadPackets[i].crackedPackets);
- }
- }
- }
- }
-
- run = false; //Potentially we can change this so keep submitting the rest of the cracked queue instead of terminating
-
- if (!hcClass.hcProc.HasExited)
- {
- hcClass.hcProc.CancelOutputRead();
- hcClass.hcProc.CancelErrorRead();
- hcClass.hcProc.Kill();
- //The server would need to accept the chunk but return an error
- }
- break;
- }
-
-
- {
- if (singlePacket[0].statusPackets["STATUS"] >= 4 + offset) //We are the last upload task
- //if (singlePacket[0].statusPackets["STATUS"] >= 5) //Uncomment this line, and comment above line for upcoming HC > 3.6
- {
- Console.WriteLine("Finished processing chunk");
- singlePacket.Clear();
- run = false;
- }
- else
- {
- singlePacket.RemoveAt(0);
- }
-
- }
-
- }
-
-
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- Console.WriteLine("Error processing packet for upload");
- }
-
-
- }
-
- }
-
- private jsonClass jsC = new jsonClass { };
-
- public int getChunk(int inTask)
- {
- Console.WriteLine("Getting chunk...");
- chunkProps cProps = new chunkProps
- {
- action = "getChunk",
- token = client.tokenID,
- taskId = inTask
- };
-
- jsC.debugFlag = debugFlag;
- jsC.connectURL = client.connectURL;
- primaryCracked = new List { };
- hcClass.debugFlag = debugFlag;
-
- string jsonString = jsC.toJson(cProps);
- string ret = jsC.jsonSend(jsonString);
-
-
- if (jsC.isJsonSuccess(ret))
- {
- string status = jsC.getRetVar(ret, "status");
-
-
- string argBuilder = attackcmd;
- string attackcmdMod = " " + cmdpars + " ";
- string actualHLpath = Path.Combine(hashpath, hashlistID.ToString());
- switch (status)
- {
- case "OK":
- attackcmdMod = " " + cmdpars + " "; //Reset the argument string
- attackcmdMod += attackcmd.Replace(hashlistAlias, "\"" + actualHLpath + "\" "); //Add the path to Hashlist
-
- attackcmdMod = convertToRelative(attackcmdMod);
-
- attackcmdMod += " --outfile-check-dir=\"" + zapPath + hashlistID.ToString() + "\" "; //Add the zap path to the commands
-
- hcClass.setArgs(attackcmdMod);
-
- chunkNo = Convert.ToInt64(jsC.getRetVar(ret, "chunkId"));
- skip = Convert.ToInt64(jsC.getRetVar(ret, "skip"));
- length = Convert.ToInt64(jsC.getRetVar(ret, "length"));
-
- List uploadPackets = new List();
-
- hcClass.setDirs(appPath);
- hcClass.setPassthrough(ref uploadPackets, ref packetLock, debugFlag);
-
- Thread thread = new Thread(() => threadPeriodicUpdate(ref uploadPackets, ref packetLock));
- thread.Start(); //Start our thread to monitor the upload queue
-
- hcClass.startAttack(chunkNo, taskID, skip, length, statusTimer, tasksPath); //Start the hashcat binary
- thread.Join();
-
- return 1;
-
- case "keyspace_required":
- hcClass.setDirs(appPath);
- attackcmdMod = " " + cmdpars + " "; //Reset the argument string
- attackcmdMod += attackcmd.Replace(hashlistAlias, ""); //Remove out the #HL#
-
- attackcmdMod = convertToRelative(attackcmdMod);
-
- hcClass.setArgs(attackcmdMod);
- long calcKeyspace = 0;
-
- if (!hcClass.runKeyspace(ref calcKeyspace))
- {
- Console.WriteLine("Keyspace measuring was unsuccessful, check all files are present");
- return 0;
- }
-
-
- if (calcKeyspace == 0)
- {
- errorProps eProps = new errorProps
- {
- token = client.tokenID,
- taskId = taskID,
- message = "Invalid keyspace, keyspace probably too small for this hashtype"
- };
- jsonString = jsC.toJson(eProps);
- ret = jsC.jsonSend(jsonString);
- return 0;
- }
- else
- {
- keyspaceProps kProps = new keyspaceProps
- {
- token = client.tokenID,
- taskId = taskID,
- keyspace = calcKeyspace
- };
- jsonString = jsC.toJson(kProps);
- ret = jsC.jsonSend(jsonString);
-
- }
-
- return 2;
-
- case "fully_dispatched":
- return 0;
-
- case "benchmark":
- hcClass.setDirs(appPath);
- attackcmdMod = " " + cmdpars + " "; //Reset the argument string
- attackcmdMod += attackcmd.Replace(hashlistAlias, "\"" + actualHLpath + "\""); //Add the path to Hashlist
-
- attackcmdMod = convertToRelative(attackcmdMod);
-
- hcClass.setArgs(attackcmdMod);
-
- Dictionary collection = new Dictionary(); //Holds all the returned benchmark values1
-
- if(!hcClass.runBenchmark(benchMethod, benchTime, ref collection, legacy))
- {
- Console.WriteLine("Benchmark error, perhaps hashlist is empty");
- errorProps eProps = new errorProps
- {
- token = client.tokenID,
- taskId = taskID,
- message = "Client received an invalid hashlist for benchmark"
- };
- jsonString = jsC.toJson(eProps);
- ret = jsC.jsonSend(jsonString);
-
- return 0;
-
- }
-
- benchProps bProps = new benchProps
- {
- token = client.tokenID,
- taskId = taskID,
- };
-
- try
- {
- if (benchMethod == 1) //Old benchmark method using actual run
- {
- bProps.type = "run";
- bProps.result = collection["PROGRESS_REJ"].ToString("0." + new string('#', 100));
-
- }
- else //New benchmark method using --speed param
- {
- bProps.type = "speed";
- bProps.result = collection["LEFT_TOTAL"].ToString() + ":" + collection["RIGHT_TOTAL"].ToString();
- }
- }
- catch
- {
- Console.WriteLine("Benchmark was unsuccessful, check all files are present");
- return 0;
- }
-
-
-
- jsonString = jsC.toJson(bProps);
- ret = jsC.jsonSend(jsonString);
- if (!jsC.isJsonSuccess(ret))
- {
- Console.WriteLine("Server rejected benchmark");
- Console.WriteLine("Check the hashlist was downloaded correctly");
- return 0;
- }
- return 3;
-
- }
-
- }
- return 0;
- }
-
- private string convertToRelative(string input)
- {
- string[] filename = input.Split(' '); //Split by spaces
- string final = "";
-
-
- foreach (var file in filename)
- {
- if (File.Exists("files\\" + file))
- {
- final += "..\\..\\files\\" + file + " ";
- }
- else
- {
- final += file + " ";
- }
- }
-
- if (client.osID != 1)
- {
- final = final.Replace("\\", "/");
- }
-
- return final;
-
- }
- 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;
- }
-
- 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;
- }
-
-
- private Int64 fileSize(string filePath)
- {
- Int64 fSize = new FileInfo(Path.Combine(hashpath , Path.GetFileName(hashlistID.ToString()))).Length;
- return fSize;
- }
-
-
- public Boolean getTask()
- {
-
- Console.WriteLine("Getting task");
- Task get = new Task
- {
- action = "getTask",
- token = client.tokenID
- };
-
- jsonClass jsC = new jsonClass { debugFlag = debugFlag, connectURL = client.connectURL };
- string jsonString = jsC.toJson(get);
- string ret = jsC.jsonSend(jsonString);
-
- if (jsC.isJsonSuccess(ret))
- {
- if (jsC.getRetVar(ret, "taskId") != null)
- {
- taskID = Int32.Parse(jsC.getRetVar(ret, "taskId"));
- attackcmd = (jsC.getRetVar(ret, "attackcmd"));
- cmdpars = (jsC.getRetVar(ret, "cmdpars"));
- hashlistID = Int32.Parse(jsC.getRetVar(ret, "hashlistId"));
- benchTime = Int32.Parse(jsC.getRetVar(ret, "bench"));
- crackerId = Int32.Parse(jsC.getRetVar(ret, "crackerId"));
-
- Console.WriteLine("Server has assigned client with Task:{0}, Cracker:{2} and Hashlist:{1}",taskID,hashlistID,crackerId);
- if (jsC.getRetVar(ret, "benchType") == "run")
- {
- benchMethod = 1;
- }
- else
- {
- benchMethod = 2;
- }
- statusTimer = Int32.Parse(jsC.getRetVar(ret, "statustimer"));
- hashlistAlias = jsC.getRetVar(ret, "hashlistAlias");
- files = jsC.getRetArray(ret, "files");
- int gotChunk = 1;
-
- foreach (string fileItem in files)
- {
- string actualFile = Path.Combine(filepath, fileItem);
- if (!File.Exists(actualFile))
- {
- getFile(fileItem);
-
- if (fileItem.ToLower().EndsWith(".7z"))
- {
- if (sevenZip.xtract(actualFile, filepath))
- {
- File.WriteAllText(actualFile, "UNPACKED");
- }
- else
- {
- return false;
- }
- }
- }
- }
-
- //Convert implied relative paths to absolute paths only applies to Mac OSX / Linux
- //We, break up the attack command by space and check whether the file for the full path exists, we it does we replace
- //Could potentially cause issues if the file names are attack numbers eg 1 2 3 4 5 6 7
- //File names cannot contain spaces
- //Altnerative method is to perform find replace on the attackcmd based on the files array
- if (client.osID != 1)
- {
- string[] explode = new string[] { };
- explode = attackcmd.Split(' ');
-
- for (int i = 0; i kill the process and then wait for issuing the chunk again
- self.usePipe = True
- chunk_start = int(status.get_progress_total() / (chunk['skip'] + chunk['length']) * chunk['skip'])
- self.progressVal = status.get_progress_total() - chunk_start
- logging.info("Detected low UTIL value, restart chunk with piping...")
- try:
- kill_hashcat(proc.pid, Initialize.get_os())
- except ProcessLookupError:
- pass
- return
+ if enable_piping and 'slowHash' in task and task['slowHash'] and not self.usePipe:
+ if task['files'] and not task['usePrince'] and 1 < self.statusCount < 10 and status.get_util() != -1 and status.get_util() < piping_threshold:
+ # we need to try piping -> kill the process and then wait for issuing the chunk again
+ self.usePipe = True
+ chunk_start = int(status.get_progress_total() / (chunk['skip'] + chunk['length']) * chunk['skip'])
+ self.progressVal = status.get_progress_total() - chunk_start
+ logging.info("Detected low UTIL value, restart chunk with piping...")
+ try:
+ kill_hashcat(proc.pid, Initialize.get_os())
+ except ProcessLookupError:
+ pass
+ return
self.first_status = True
# send update to server
@@ -216,7 +218,11 @@ def run_loop(self, proc, chunk, task):
query['relativeProgress'] = relative_progress
query['speed'] = speed
query['state'] = status.get_state()
- query['cracks'] = self.cracks
+ # crack format: hash[:salt]:plain:hex_plain:crack_pos
+ prepared = []
+ for crack in self.cracks:
+ prepared.append(crack.split("\t"))
+ query['cracks'] = prepared
if status.get_temps():
query['gpuTemp'] = status.get_temps()
if status.get_all_util():
@@ -228,6 +234,7 @@ def run_loop(self, proc, chunk, task):
if ans is None:
logging.error("Failed to send solve!")
elif ans['response'] != 'SUCCESS':
+ self.wasStopped = True
logging.error("Error from server on solve: " + str(ans))
try:
kill_hashcat(proc.pid, Initialize.get_os())
@@ -243,6 +250,7 @@ def run_loop(self, proc, chunk, task):
kill_hashcat(proc.pid, Initialize.get_os())
except ProcessLookupError:
pass
+ sleep(5)
return
else:
cracks_count = len(self.cracks)
@@ -250,7 +258,7 @@ def run_loop(self, proc, chunk, task):
zaps = ans['zaps']
if zaps:
logging.debug("Writing zaps")
- zap_output = ":FF\n".join(zaps) + ':FF\n'
+ zap_output = "\tFF\n".join(zaps) + '\tFF\n'
f = open("hashlist_" + str(task['hashlistId']) + "/" + str(time.time()), 'a')
f.write(zap_output)
f.close()
@@ -266,33 +274,34 @@ def run_loop(self, proc, chunk, task):
else:
pass
# logging.warning("HCOUT: " + line.strip())
- else:
+ elif identifier == 'ERR':
msg = escape_ansi(line.replace(b"\r\n", b"\n").decode('utf-8')).strip()
- if msg:
+ if msg and str(msg) != '^C': # this is maybe not the fanciest way, but as ctrl+c is sent to the underlying process it reports it to stderr
logging.error("HC error: " + msg)
send_error(msg, self.config.get_value('token'), task['taskId'])
- sleep(5)
+ sleep(0.1)
def measure_keyspace(self, task, chunk):
if task['usePrince']:
- self.prince_keyspace(task, chunk)
- return
+ return self.prince_keyspace(task, chunk)
full_cmd = self.callPath + " --keyspace --quiet " + update_files(task['attackcmd']).replace(task['hashlistAlias'] + " ", "") + ' ' + task['cmdpars']
if Initialize.get_os() == 1:
full_cmd = full_cmd.replace("/", '\\')
try:
+ logging.debug("CALL: " + full_cmd)
output = subprocess.check_output(full_cmd, shell=True, cwd=self.cracker_path)
- except subprocess.CalledProcessError:
- logging.error("Error during keyspace measure")
+ except subprocess.CalledProcessError as e:
+ logging.error("Error during keyspace measure: " + str(e))
send_error("Keyspace measure failed!", self.config.get_value('token'), task['taskId'])
- return
+ sleep(5)
+ return False
output = output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n")
keyspace = "0"
for line in output:
if not line:
continue
keyspace = line
- chunk.send_keyspace(int(keyspace), task['taskId'])
+ return chunk.send_keyspace(int(keyspace), task['taskId'])
def prince_keyspace(self, task, chunk):
binary = "pp64."
@@ -309,7 +318,8 @@ def prince_keyspace(self, task, chunk):
except subprocess.CalledProcessError:
logging.error("Error during PRINCE keyspace measure")
send_error("PRINCE keyspace measure failed!", self.config.get_value('token'), task['taskId'])
- return
+ sleep(5)
+ return False
output = output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n")
keyspace = "0"
for line in output:
@@ -317,9 +327,9 @@ def prince_keyspace(self, task, chunk):
continue
keyspace = line
if int(keyspace) > 9000000000000000000: # max size of a long long int
- chunk.send_keyspace(-1, task['taskId'])
+ return chunk.send_keyspace(-1, task['taskId'])
else:
- chunk.send_keyspace(int(keyspace), task['taskId'])
+ return chunk.send_keyspace(int(keyspace), task['taskId'])
def run_benchmark(self, task):
if task['benchType'] == 'speed':
@@ -390,8 +400,8 @@ def run_speed_benchmark(self, task):
logging.debug("CALL: " + full_cmd)
output = subprocess.check_output(full_cmd, shell=True, cwd=self.cracker_path)
except subprocess.CalledProcessError as e:
- logging.error("Error during keyspace measure, return code: " + str(e.returncode))
- send_error("Keyspace measure failed!", self.config.get_value('token'), task['taskId'])
+ logging.error("Error during speed benchmark, return code: " + str(e.returncode))
+ send_error("Speed benchmark failed!", self.config.get_value('token'), task['taskId'])
return 0
output = output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n")
benchmark_sum = [0, 0]
@@ -402,15 +412,15 @@ def run_speed_benchmark(self, task):
if len(line) != 3:
continue
benchmark_sum[0] += int(line[1])
- benchmark_sum[1] += float(line[2])
- return str(benchmark_sum[0]) + ":" + str(benchmark_sum[1])
+ benchmark_sum[1] += float(line[2])*int(line[1])
+ return str(benchmark_sum[0]) + ":" + str(float(benchmark_sum[1]) / benchmark_sum[0])
def output_watcher(self, file_path, process):
while not os.path.exists(file_path):
time.sleep(1)
if process.poll() is not None:
return
- file_handle = open(file_path)
+ file_handle = open(file_path, encoding="utf-8")
end_count = 0
while 1:
where = file_handle.tell()
@@ -432,3 +442,37 @@ def output_watcher(self, file_path, process):
def agent_stopped(self):
return self.wasStopped
+
+ def run_health_check(self, attack, hashlist_alias):
+ args = " --machine-readable --quiet"
+ args += " --restore-disable --potfile-disable --session=health "
+ args += update_files(attack).replace(hashlist_alias, "../../hashlists/health_check.txt")
+ args += " -o ../../hashlists/health_check.out"
+ full_cmd = self.callPath + args
+ if Initialize.get_os() == 1:
+ full_cmd = full_cmd.replace("/", '\\')
+ logging.debug("CALL: " + full_cmd)
+ proc = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.cracker_path)
+ output, error = proc.communicate()
+ logging.debug("Started health check attack")
+ proc.wait() # wait until done
+ errors = []
+ states = []
+ if error:
+ error = escape_ansi(error.replace(b"\r\n", b"\n").decode('utf-8'))
+ error = error.split('\n')
+ for line in error:
+ if not line:
+ continue
+ errors.append(line)
+ if output:
+ output = escape_ansi(output.replace(b"\r\n", b"\n").decode('utf-8'))
+ output = output.split('\n')
+ for line in output:
+ if not line:
+ continue
+ logging.debug(line)
+ status = HashcatStatus(line)
+ if status.is_valid():
+ states.append(status)
+ return [states, errors]
diff --git a/python/htpclient/hashcat_status.py b/htpclient/hashcat_status.py
similarity index 100%
rename from python/htpclient/hashcat_status.py
rename to htpclient/hashcat_status.py
diff --git a/python/htpclient/hashlist.py b/htpclient/hashlist.py
similarity index 100%
rename from python/htpclient/hashlist.py
rename to htpclient/hashlist.py
diff --git a/python/htpclient/helpers.py b/htpclient/helpers.py
similarity index 97%
rename from python/htpclient/helpers.py
rename to htpclient/helpers.py
index 7c81038..d2ce0a7 100644
--- a/python/htpclient/helpers.py
+++ b/htpclient/helpers.py
@@ -53,6 +53,11 @@ def send_error(error, token, task_id):
req.execute()
+def file_get_contents(filename):
+ with open(filename) as f:
+ return f.read()
+
+
def start_uftpd(os_extension, config):
try:
subprocess.check_output("killall -s 9 uftpd", shell=True) # stop running service to make sure we can start it again
diff --git a/python/htpclient/initialize.py b/htpclient/initialize.py
similarity index 98%
rename from python/htpclient/initialize.py
rename to htpclient/initialize.py
index 81be616..9ed0ba0 100644
--- a/python/htpclient/initialize.py
+++ b/htpclient/initialize.py
@@ -54,6 +54,8 @@ def __login(self):
self.__login()
else:
logging.info("Login successful!")
+ if 'server-version' in ans:
+ logging.info("Hashtopolis Server version: " + ans['server-version'])
if 'multicastEnabled' in ans and ans['multicastEnabled'] and self.get_os() == 0: # currently only allow linux
logging.info("Multicast enabled!")
self.config.set_value('multicast', True)
diff --git a/python/htpclient/jsonRequest.py b/htpclient/jsonRequest.py
similarity index 76%
rename from python/htpclient/jsonRequest.py
rename to htpclient/jsonRequest.py
index 755c5e3..8b3bc57 100644
--- a/python/htpclient/jsonRequest.py
+++ b/htpclient/jsonRequest.py
@@ -1,18 +1,19 @@
import logging
-import requests
from htpclient.config import *
+from htpclient.session import *
class JsonRequest:
def __init__(self, data):
self.data = data
self.config = Config()
+ self.session = Session().s
def execute(self):
try:
logging.debug(self.data)
- r = requests.post(self.config.get_value('url'), json=self.data)
+ r = self.session.post(self.config.get_value('url'), json=self.data)
if r.status_code != 200:
logging.error("Status code from server: " + str(r.status_code))
return None
diff --git a/htpclient/session.py b/htpclient/session.py
new file mode 100644
index 0000000..5552125
--- /dev/null
+++ b/htpclient/session.py
@@ -0,0 +1,11 @@
+import requests
+
+
+class Session:
+ __instance = None
+
+ def __new__(cls, s=None):
+ if Session.__instance is None:
+ Session.__instance = object.__new__(cls)
+ Session.__instance.s = s
+ return Session.__instance
diff --git a/python/htpclient/task.py b/htpclient/task.py
similarity index 85%
rename from python/htpclient/task.py
rename to htpclient/task.py
index ff5a0c1..7ad22af 100644
--- a/python/htpclient/task.py
+++ b/htpclient/task.py
@@ -34,9 +34,15 @@ def load_task(self):
logging.info("No task available!")
sleep(5)
return
+ elif ans['taskId'] == -1:
+ self.taskId = -1
+ return
self.task = ans
self.taskId = ans['taskId']
logging.info("Got task with id: " + str(ans['taskId']))
def get_task(self):
return self.task
+
+ def get_task_id(self):
+ return self.taskId
diff --git a/python/.gitignore b/python/.gitignore
deleted file mode 100644
index 0c14901..0000000
--- a/python/.gitignore
+++ /dev/null
@@ -1,9 +0,0 @@
-*.iml
-*.exe
-*.log
-*.json
-crackers
-prince
-files
-hashlists
-__pycache__
diff --git a/python/README.md b/python/README.md
deleted file mode 100644
index 144d7f3..0000000
--- a/python/README.md
+++ /dev/null
@@ -1,92 +0,0 @@
-# Hashtopolis Python Agent
-
-[](https://www.codefactor.io/repository/github/s3inlc/hashtopolis-agent)
-[](https://github.com/s3inlc/Hashtopolis-Agent)
-
-This Hashtopolis agent is only compatible with Hashtopolis versions 0.5.0 and higher.
-
-## Prerequisites
-
-You need python3 installed on your agent system.
-Following python packages are required:
-
-* requests
-
-## Manual
-
-You can either download the agent from the Hashtopolis new agent page or you can use the url shown there to download the agent with
-wget/curl.
-
-### Run
-
-To run the agent you simply need to call `python3 hashtopolis.zip`. There are no command line options accepted, all
-settings/configurations are done via the config file, described in the following section.
-
-Please note that the client does not correctly recognize the OS when you are running in Cygwin or similar on Windows. You need to run it in Windows command line.
-
-### Config
-
-When you run the client for the first time it will ask automatically for all the requirement settings and then saves it automatically to a config file called `config.json`. This could for example look like this:
-
-```
-{
- "url": "https://coray.org/htp-test/src/api/server.php",
- "token": "7RNDqtnPxm",
- "uuid": "49dcd31c-3637-4f2a-8df1-b545202df5b3"
-}
-```
-
-### Overview
-
-| field | type | default | description |
-|-----------------------|---------|---------|----------------------------------------------------------------------------|
-| voucher | string | | Used for agent registration (will be prompted on first start) |
-| url | string | | The hashtopolis API endpoint (will be prompted on first start) |
-| token | string | | The access token for the API (sent by server on registration) |
-| uuid | string | | Unique identifier of the agent (generated on registration) |
-| debug | boolean | false | Enables debug output |
-| allow-piping | boolean | false | Allows hashcat to read password candidates from stdin |
-| piping-threshold | integer | 95 | Restarts chunk in piping mode when GPU UTIL is below this value |
-| rsync | boolean | false | Enables download of wordlists and rules via rsync |
-| rsync-path | string | | Remote path to hashtopolis files directory |
-| multicast-device | string | eth0 | Device which is used to retrieve UDP multicast file distribution |
-| file-deletion-disable | boolean | false | Disable requesting the server for files to delete |
-| file-deletion-interval| integer | 600 | Interval time in seconds in which the agent should check for deleted files |
-
-### Debug example
-
-```
-{
- "url": "https://coray.org/htp-test/src/api/server.php",
- "token": "7RNDqtnPxm",
- "uuid": "49dcd31c-3637-4f2a-8df1-b545202df5b3",
- "debug": true
-}
-```
-
-### rsync
-
-You need a user on the server which can automatically login (e.g. SSH keys) and has read access to the files directory of hashtopolis. On the client side you need rsync installed and set the following lines in your agent config.
-
-```
- "rsync": true,
- "rsync-path": "user@yourserver:/path/to/hashtopolis/files"
-```
-
-### Multicast
-
-In order to use the multicast distribution for files, please make sure that the agents and server are prepared according to this:https://github.com/s3inlc/hashtopolis-runner
-
-## Hashcat Compatibility
-
-The list contains all Hashcat versions with which the client was tested and is able to work with (other versions might work):
-
-* 4.2.1
-* 4.2.0
-* 4.1.0
-* 4.0.1
-* 4.0.0
-
-## Generic Crackers
-
-This client is able to run generic Hashtopolis cracker binaries which fulfill the minimal functionality requirements, described [here](https://github.com/s3inlc/hashtopolis/tree/master/doc/README.md). An example implementation can be found [here](https://github.com/s3inlc/hashtopolis-generic-cracker)
diff --git a/python/requirements.txt b/requirements.txt
similarity index 100%
rename from python/requirements.txt
rename to requirements.txt