From 323b1132f361a6fee2d0133f9d99fa5af2644782 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Thu, 27 Apr 2023 12:55:51 -0400 Subject: [PATCH 01/55] changed database structure for benchmarks. Added a Benchmark table and hardwareGroup --- ci/files/db_0.13.0.sql | 1256 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1256 insertions(+) create mode 100644 ci/files/db_0.13.0.sql diff --git a/ci/files/db_0.13.0.sql b/ci/files/db_0.13.0.sql new file mode 100644 index 000000000..5e484cb69 --- /dev/null +++ b/ci/files/db_0.13.0.sql @@ -0,0 +1,1256 @@ +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT = @@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS = @@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION = @@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- Create tables and insert default entries +CREATE TABLE `AccessGroup` ( + `accessGroupId` INT(11) NOT NULL, + `groupName` VARCHAR(50) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `AccessGroupAgent` ( + `accessGroupAgentId` INT(11) NOT NULL, + `accessGroupId` INT(11) NOT NULL, + `agentId` INT(11) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `AccessGroupUser` ( + `accessGroupUserId` INT(11) NOT NULL, + `accessGroupId` INT(11) NOT NULL, + `userId` INT(11) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `Agent` ( + `agentId` INT(11) NOT NULL, + `agentName` VARCHAR(100) NOT NULL, + `uid` VARCHAR(100) NOT NULL, + `os` INT(11) NOT NULL, + `devices` TEXT NOT NULL, + `cmdPars` VARCHAR(256) NOT NULL, + `ignoreErrors` TINYINT(4) NOT NULL, + `isActive` TINYINT(4) NOT NULL, + `isTrusted` TINYINT(4) NOT NULL, + `token` VARCHAR(30) NOT NULL, + `lastAct` VARCHAR(50) NOT NULL, + `lastTime` BIGINT NOT NULL, + `lastIp` VARCHAR(50) NOT NULL, + `userId` INT(11) DEFAULT NULL, + `cpuOnly` TINYINT(4) NOT NULL, + `clientSignature` VARCHAR(50) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `AgentBinary` ( + `agentBinaryId` INT(11) NOT NULL, + `type` VARCHAR(20) NOT NULL, + `version` VARCHAR(20) NOT NULL, + `operatingSystems` VARCHAR(50) NOT NULL, + `filename` VARCHAR(50) NOT NULL, + `updateTrack` VARCHAR(20) NOT NULL, + `updateAvailable` VARCHAR(20) NOT NULL +) ENGINE = InnoDB; + +INSERT INTO `AgentBinary` (`agentBinaryId`, `type`, `version`, `operatingSystems`, `filename`, `updateTrack`, `updateAvailable`) VALUES + (1, 'python', '0.5.0', 'Windows, Linux, OS X', 'hashtopolis.zip', 'stable', ''); + +CREATE TABLE `AgentError` ( + `agentErrorId` INT(11) NOT NULL, + `agentId` INT(11) NOT NULL, + `taskId` INT(11) DEFAULT NULL, + `time` BIGINT NOT NULL, + `error` TEXT NOT NULL, + `chunkId` INT(11) NULL +) ENGINE = InnoDB; + +CREATE TABLE `AgentStat` ( + `agentStatId` INT(11) NOT NULL, + `agentId` INT(11) NOT NULL, + `statType` INT(11) NOT NULL, + `time` BIGINT NOT NULL, + `value` VARCHAR(64) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `AgentZap` ( + `agentZapId` INT(11) NOT NULL, + `agentId` INT(11) NOT NULL, + `lastZapId` INT(11) NULL +) ENGINE = InnoDB; + +CREATE TABLE `Assignment` ( + `assignmentId` INT(11) NOT NULL, + `taskId` INT(11) NOT NULL, + `agentId` INT(11) NOT NULL, + `benchmark` VARCHAR(50) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `Chunk` ( + `chunkId` INT(11) NOT NULL, + `taskId` INT(11) NOT NULL, + `skip` BIGINT(20) NOT NULL, + `length` BIGINT(20) NOT NULL, + `agentId` INT(11) NULL, + `dispatchTime` BIGINT NOT NULL, + `solveTime` BIGINT NOT NULL, + `checkpoint` BIGINT(20) NOT NULL, + `progress` INT(11) NULL, + `state` INT(11) NOT NULL, + `cracked` INT(11) NOT NULL, + `speed` BIGINT(20) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `Config` ( + `configId` INT(11) NOT NULL, + `configSectionId` INT(11) NOT NULL, + `item` VARCHAR(80) NOT NULL, + `value` TEXT NOT NULL +) ENGINE = InnoDB; + +INSERT INTO `Config` (`configId`, `configSectionId`, `item`, `value`) VALUES + (1, 1, 'agenttimeout', '30'), + (2, 1, 'benchtime', '30'), + (3, 1, 'chunktime', '600'), + (4, 1, 'chunktimeout', '30'), + (9, 1, 'fieldseparator', ':'), + (10, 1, 'hashlistAlias', '#HL#'), + (11, 1, 'statustimer', '5'), + (12, 4, 'timefmt', 'd.m.Y, H:i:s'), + (13, 1, 'blacklistChars', '&|`\"\'{}()[]$<>;'), + (14, 3, 'numLogEntries', '5000'), + (15, 1, 'disptolerance', '20'), + (16, 3, 'batchSize', '50000'), + (18, 2, 'yubikey_id', ''), + (19, 2, 'yubikey_key', ''), + (20, 2, 'yubikey_url', 'http://api.yubico.com/wsapi/2.0/verify'), + (21, 4, 'donateOff', '0'), + (22, 3, 'pagingSize', '5000'), + (23, 3, 'plainTextMaxLength', '200'), + (24, 3, 'hashMaxLength', '1024'), + (25, 5, 'emailSender', 'hashtopolis@example.org'), + (26, 5, 'emailSenderName', 'Hashtopolis'), + (27, 5, 'baseHost', ''), + (28, 3, 'maxHashlistSize', '5000000'), + (29, 4, 'hideImportMasks', '1'), + (30, 7, 'telegramBotToken', ''), + (31, 5, 'contactEmail', ''), + (32, 5, 'voucherDeletion', '0'), + (33, 4, 'hashesPerPage', '1000'), + (34, 4, 'hideIpInfo', '0'), + (35, 1, 'defaultBenchmark', '1'), + (36, 4, 'showTaskPerformance', '0'), + (37, 1, 'ruleSplitSmallTasks', '0'), + (38, 1, 'ruleSplitAlways', '0'), + (39, 1, 'ruleSplitDisable', '0'), + (41, 4, 'agentStatLimit', '100'), + (42, 1, 'agentDataLifetime', '3600'), + (43, 4, 'agentStatTension', '0'), + (44, 6, 'multicastEnable', '0'), + (45, 6, 'multicastDevice', 'eth0'), + (46, 6, 'multicastTransferRateEnable', '0'), + (47, 6, 'multicastTranserRate', '500000'), + (48, 1, 'disableTrimming', '0'), + (49, 5, 'serverLogLevel', '20'), + (50, 7, 'notificationsProxyEnable', '0'), + (60, 7, 'notificationsProxyServer', ''), + (61, 7, 'notificationsProxyPort', '8080'), + (62, 7, 'notificationsProxyType', 'HTTP'), + (63, 1, 'priority0Start', '0'), + (64, 5, 'baseUrl', ''), + (65, 4, 'maxSessionLength', '48'), + (66, 1, 'hashcatBrainEnable', '0'), + (67, 1, 'hashcatBrainHost', ''), + (68, 1, 'hashcatBrainPort', '0'), + (69, 1, 'hashcatBrainPass', ''), + (70, 1, 'hashlistImportCheck', '0'), + (71, 5, 'allowDeregister', '0'), + (72, 4, 'agentTempThreshold1', '70'), + (73, 4, 'agentTempThreshold2', '80'), + (74, 4, 'agentUtilThreshold1', '90'), + (75, 4, 'agentUtilThreshold2', '75'), + (76, 3, 'uApiSendTaskIsComplete', '0'), + (77, 1, 'hcErrorIgnore', 'DeviceGetFanSpeed'); + +CREATE TABLE `ConfigSection` ( + `configSectionId` INT(11) NOT NULL, + `sectionName` VARCHAR(100) NOT NULL +) ENGINE = InnoDB; + +INSERT INTO `ConfigSection` (`configSectionId`, `sectionName`) VALUES + (1, 'Cracking/Tasks'), + (2, 'Yubikey'), + (3, 'Finetuning'), + (4, 'UI'), + (5, 'Server'), + (6, 'Multicast'), + (7, 'Notifications'); + +CREATE TABLE `CrackerBinary` ( + `crackerBinaryId` INT(11) NOT NULL, + `crackerBinaryTypeId` INT(11) NOT NULL, + `version` VARCHAR(20) NOT NULL, + `downloadUrl` VARCHAR(150) NOT NULL, + `binaryName` VARCHAR(50) NOT NULL +) ENGINE = InnoDB; + +INSERT INTO `CrackerBinary` (`crackerBinaryId`, `crackerBinaryTypeId`, `version`, `downloadUrl`, `binaryName`) VALUES + (1, 1, '5.1.0', 'https://hashcat.net/files/hashcat-5.1.0.7z', 'hashcat'); + +CREATE TABLE `CrackerBinaryType` ( + `crackerBinaryTypeId` INT(11) NOT NULL, + `typeName` VARCHAR(30) NOT NULL, + `isChunkingAvailable` TINYINT(4) NOT NULL +) ENGINE = InnoDB; + +INSERT INTO `CrackerBinaryType` (`crackerBinaryTypeId`, `typeName`, `isChunkingAvailable`) VALUES + (1, 'hashcat', 1); + +CREATE TABLE `File` ( + `fileId` INT(11) NOT NULL, + `filename` VARCHAR(100) NOT NULL, + `size` BIGINT(20) NOT NULL, + `isSecret` TINYINT(4) NOT NULL, + `fileType` INT(11) NOT NULL, + `accessGroupId` INT(11) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `FilePretask` ( + `filePretaskId` INT(11) NOT NULL, + `fileId` INT(11) NOT NULL, + `pretaskId` INT(11) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `FileTask` ( + `fileTaskId` INT(11) NOT NULL, + `fileId` INT(11) NOT NULL, + `taskId` INT(11) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `FileDelete` ( + `fileDeleteId` INT(11) NOT NULL, + `filename` VARCHAR(256) NOT NULL, + `time` BIGINT NOT NULL +) ENGINE=InnoDB; + +CREATE TABLE `Hash` ( + `hashId` INT(11) NOT NULL, + `hashlistId` INT(11) NOT NULL, + `hash` TEXT NOT NULL, + `salt` VARCHAR(256) DEFAULT NULL, + `plaintext` VARCHAR(256) DEFAULT NULL, + `timeCracked` BIGINT DEFAULT NULL, + `chunkId` INT(11) DEFAULT NULL, + `isCracked` TINYINT(4) NOT NULL, + `crackPos` BIGINT NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `HashBinary` ( + `hashBinaryId` INT(11) NOT NULL, + `hashlistId` INT(11) NOT NULL, + `essid` VARCHAR(100) NOT NULL, + `hash` MEDIUMTEXT NOT NULL, + `plaintext` VARCHAR(1024) DEFAULT NULL, + `timeCracked` BIGINT DEFAULT NULL, + `chunkId` INT(11) DEFAULT NULL, + `isCracked` TINYINT(4) NOT NULL, + `crackPos` BIGINT NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `Hashlist` ( + `hashlistId` INT(11) NOT NULL, + `hashlistName` VARCHAR(100) NOT NULL, + `format` INT(11) NOT NULL, + `hashTypeId` INT(11) NOT NULL, + `hashCount` INT(11) NOT NULL, + `saltSeparator` VARCHAR(10) DEFAULT NULL, + `cracked` INT(11) NOT NULL, + `isSecret` TINYINT(4) NOT NULL, + `hexSalt` TINYINT(4) NOT NULL, + `isSalted` TINYINT(4) NOT NULL, + `accessGroupId` INT(11) NOT NULL, + `notes` TEXT NOT NULL, + `brainId` INT(11) NOT NULL, + `brainFeatures` TINYINT(4) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `HashlistHashlist` ( + `hashlistHashlistId` INT(11) NOT NULL, + `parentHashlistId` INT(11) NOT NULL, + `hashlistId` INT(11) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `HashType` ( + `hashTypeId` INT(11) NOT NULL, + `description` VARCHAR(256) NOT NULL, + `isSalted` TINYINT(4) NOT NULL, + `isSlowHash` TINYINT(4) NOT NULL +) ENGINE = InnoDB; + +INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) VALUES + (0, 'MD5', 0, 0), + (10, 'md5($pass.$salt)', 1, 0), + (11, 'Joomla < 2.5.18', 1, 0), + (12, 'PostgreSQL', 1, 0), + (20, 'md5($salt.$pass)', 1, 0), + (21, 'osCommerce, xt:Commerce', 1, 0), + (22, 'Juniper Netscreen/SSG (ScreenOS)', 1, 0), + (23, 'Skype', 1, 0), + (30, 'md5(unicode($pass).$salt)', 1, 0), + (40, 'md5($salt.unicode($pass))', 1, 0), + (50, 'HMAC-MD5 (key = $pass)', 1, 0), + (60, 'HMAC-MD5 (key = $salt)', 1, 0), + (100, 'SHA1', 0, 0), + (101, 'nsldap, SHA-1(Base64), Netscape LDAP SHA', 0, 0), + (110, 'sha1($pass.$salt)', 1, 0), + (111, 'nsldaps, SSHA-1(Base64), Netscape LDAP SSHA', 0, 0), + (112, 'Oracle S: Type (Oracle 11+)', 1, 0), + (120, 'sha1($salt.$pass)', 1, 0), + (121, 'SMF >= v1.1', 1, 0), + (122, 'OS X v10.4, v10.5, v10.6', 0, 0), + (123, 'EPi', 0, 0), + (124, 'Django (SHA-1)', 0, 0), + (125, 'ArubaOS', 0, 0), + (130, 'sha1(unicode($pass).$salt)', 1, 0), + (131, 'MSSQL(2000)', 0, 0), + (132, 'MSSQL(2005)', 0, 0), + (133, 'PeopleSoft', 0, 0), + (140, 'sha1($salt.unicode($pass))', 1, 0), + (141, 'EPiServer 6.x < v4', 0, 0), + (150, 'HMAC-SHA1 (key = $pass)', 1, 0), + (160, 'HMAC-SHA1 (key = $salt)', 1, 0), + (200, 'MySQL323', 0, 0), + (300, 'MySQL4.1/MySQL5+', 0, 0), + (400, 'phpass, MD5(Wordpress), MD5(Joomla), MD5(phpBB3)', 0, 0), + (500, 'md5crypt, MD5(Unix), FreeBSD MD5, Cisco-IOS MD5 2', 0, 0), + (501, 'Juniper IVE', 0, 0), + (600, 'BLAKE2b-512', 0, 0), + (900, 'MD4', 0, 0), + (1000, 'NTLM', 0, 0), + (1100, 'Domain Cached Credentials (DCC), MS Cache', 1, 0), + (1300, 'SHA-224', 0, 0), + (1400, 'SHA256', 0, 0), + (1410, 'sha256($pass.$salt)', 1, 0), + (1411, 'SSHA-256(Base64), LDAP {SSHA256}', 0, 0), + (1420, 'sha256($salt.$pass)', 1, 0), + (1421, 'hMailServer', 0, 0), + (1430, 'sha256(unicode($pass).$salt)', 1, 0), + (1440, 'sha256($salt.unicode($pass))', 1, 0), + (1441, 'EPiServer 6.x >= v4', 0, 0), + (1450, 'HMAC-SHA256 (key = $pass)', 1, 0), + (1460, 'HMAC-SHA256 (key = $salt)', 1, 0), + (1500, 'descrypt, DES(Unix), Traditional DES', 0, 0), + (1600, 'md5apr1, MD5(APR), Apache MD5', 0, 0), + (1700, 'SHA512', 0, 0), + (1710, 'sha512($pass.$salt)', 1, 0), + (1711, 'SSHA-512(Base64), LDAP {SSHA512}', 0, 0), + (1720, 'sha512($salt.$pass)', 1, 0), + (1722, 'OS X v10.7', 0, 0), + (1730, 'sha512(unicode($pass).$salt)', 1, 0), + (1731, 'MSSQL(2012), MSSQL(2014)', 0, 0), + (1740, 'sha512($salt.unicode($pass))', 1, 0), + (1750, 'HMAC-SHA512 (key = $pass)', 1, 0), + (1760, 'HMAC-SHA512 (key = $salt)', 1, 0), + (1800, 'sha512crypt, SHA512(Unix)', 0, 0), + (2100, 'Domain Cached Credentials 2 (DCC2), MS Cache', 0, 1), + (2400, 'Cisco-PIX MD5', 0, 0), + (2410, 'Cisco-ASA MD5', 1, 0), + (2500, 'WPA/WPA2', 0, 1), + (2600, 'md5(md5($pass))', 0, 0), + (2611, 'vBulletin < v3.8.5', 1, 0), + (2612, 'PHPS', 0, 0), + (2711, 'vBulletin >= v3.8.5', 1, 0), + (2811, 'IPB2+, MyBB1.2+', 1, 0), + (3000, 'LM', 0, 0), + (3100, 'Oracle H: Type (Oracle 7+), DES(Oracle)', 1, 0), + (3200, 'bcrypt, Blowfish(OpenBSD)', 0, 0), + (3710, 'md5($salt.md5($pass))', 1, 0), + (3711, 'Mediawiki B type', 0, 0), + (3800, 'md5($salt.$pass.$salt)', 1, 0), + (3910, 'md5(md5($pass).md5($salt))', 1, 0), + (4010, 'md5($salt.md5($salt.$pass))', 1, 0), + (4110, 'md5($salt.md5($pass.$salt))', 1, 0), + (4300, 'md5(strtoupper(md5($pass)))', 0, 0), + (4400, 'md5(sha1($pass))', 0, 0), + (4500, 'sha1(sha1($pass))', 0, 0), + (4520, 'sha1($salt.sha1($pass))', 1, 0), + (4521, 'Redmine Project Management Web App', 0, 0), + (4522, 'PunBB', 0, 0), + (4700, 'sha1(md5($pass))', 0, 0), + (4800, 'MD5(Chap), iSCSI CHAP authentication', 1, 0), + (4900, 'sha1($salt.$pass.$salt)', 1, 0), + (5000, 'SHA-3(Keccak)', 0, 0), + (5100, 'Half MD5', 0, 0), + (5200, 'Password Safe v3', 0, 1), + (5300, 'IKE-PSK MD5', 0, 0), + (5400, 'IKE-PSK SHA1', 0, 0), + (5500, 'NetNTLMv1-VANILLA / NetNTLMv1+ESS', 0, 0), + (5600, 'NetNTLMv2', 0, 0), + (5700, 'Cisco-IOS SHA256', 0, 0), + (5800, 'Samsung Android Password/PIN', 1, 0), + (6000, 'RipeMD160', 0, 0), + (6100, 'Whirlpool', 0, 0), + (6211, 'TrueCrypt 5.0+ PBKDF2-HMAC-RipeMD160 + AES/Serpent/Twofish', 0, 1), + (6212, 'TrueCrypt 5.0+ PBKDF2-HMAC-RipeMD160 + AES-Twofish/Serpent-AES/Twofish-Serpent', 0, 1), + (6213, 'TrueCrypt 5.0+ PBKDF2-HMAC-RipeMD160 + AES-Twofish-Serpent/Serpent-Twofish-AES', 0, 1), + (6221, 'TrueCrypt 5.0+ SHA512 + AES/Serpent/Twofish', 0, 1), + (6222, 'TrueCrypt 5.0+ SHA512 + AES-Twofish/Serpent-AES/Twofish-Serpent', 0, 1), + (6223, 'TrueCrypt 5.0+ SHA512 + AES-Twofish-Serpent/Serpent-Twofish-AES', 0, 1), + (6231, 'TrueCrypt 5.0+ Whirlpool + AES/Serpent/Twofish', 0, 1), + (6232, 'TrueCrypt 5.0+ Whirlpool + AES-Twofish/Serpent-AES/Twofish-Serpent', 0, 1), + (6233, 'TrueCrypt 5.0+ Whirlpool + AES-Twofish-Serpent/Serpent-Twofish-AES', 0, 1), + (6241, 'TrueCrypt 5.0+ PBKDF2-HMAC-RipeMD160 + AES/Serpent/Twofish + boot', 0, 1), + (6242, 'TrueCrypt 5.0+ PBKDF2-HMAC-RipeMD160 + AES-Twofish/Serpent-AES/Twofish-Serpent + boot', 0, 1), + (6243, 'TrueCrypt 5.0+ PBKDF2-HMAC-RipeMD160 + AES-Twofish-Serpent/Serpent-Twofish-AES + boot', 0, 1), + (6300, 'AIX {smd5}', 0, 0), + (6400, 'AIX {ssha256}', 0, 1), + (6500, 'AIX {ssha512}', 0, 1), + (6600, '1Password, Agile Keychain', 0, 1), + (6700, 'AIX {ssha1}', 0, 1), + (6800, 'Lastpass', 1, 1), + (6900, 'GOST R 34.11-94', 0, 0), + (7000, 'Fortigate (FortiOS)', 0, 0), + (7100, 'OS X v10.8 / v10.9', 0, 1), + (7200, 'GRUB 2', 0, 1), + (7300, 'IPMI2 RAKP HMAC-SHA1', 1, 0), + (7400, 'sha256crypt, SHA256(Unix)', 0, 0), + (7500, 'Kerberos 5 AS-REQ Pre-Auth', 0, 0), + (7700, 'SAP CODVN B (BCODE)', 0, 0), + (7800, 'SAP CODVN F/G (PASSCODE)', 0, 0), + (7900, 'Drupal7', 0, 0), + (8000, 'Sybase ASE', 0, 0), + (8100, 'Citrix Netscaler', 0, 0), + (8200, '1Password, Cloud Keychain', 0, 1), + (8300, 'DNSSEC (NSEC3)', 1, 0), + (8400, 'WBB3, Woltlab Burning Board 3', 1, 0), + (8500, 'RACF', 0, 0), + (8600, 'Lotus Notes/Domino 5', 0, 0), + (8700, 'Lotus Notes/Domino 6', 0, 0), + (8800, 'Android FDE <= 4.3', 0, 1), + (8900, 'scrypt', 1, 0), + (9000, 'Password Safe v2', 0, 0), + (9100, 'Lotus Notes/Domino', 0, 1), + (9200, 'Cisco $8$', 0, 1), + (9300, 'Cisco $9$', 0, 0), + (9400, 'Office 2007', 0, 1), + (9500, 'Office 2010', 0, 1), + (9600, 'Office 2013', 0, 1), + (9700, 'MS Office ⇐ 2003 MD5 + RC4, oldoffice$0, oldoffice$1', 0, 0), + (9710, 'MS Office <= 2003 $0/$1, MD5 + RC4, collider #1', 0, 0), + (9720, 'MS Office <= 2003 $0/$1, MD5 + RC4, collider #2', 0, 0), + (9800, 'MS Office ⇐ 2003 SHA1 + RC4, oldoffice$3, oldoffice$4', 0, 0), + (9810, 'MS Office <= 2003 $3, SHA1 + RC4, collider #1', 0, 0), + (9820, 'MS Office <= 2003 $3, SHA1 + RC4, collider #2', 0, 0), + (9900, 'Radmin2', 0, 0), + (10000, 'Django (PBKDF2-SHA256)', 0, 1), + (10100, 'SipHash', 1, 0), + (10200, 'Cram MD5', 0, 0), + (10300, 'SAP CODVN H (PWDSALTEDHASH) iSSHA-1', 0, 0), + (10400, 'PDF 1.1 - 1.3 (Acrobat 2 - 4)', 0, 0), + (10410, 'PDF 1.1 - 1.3 (Acrobat 2 - 4), collider #1', 0, 0), + (10420, 'PDF 1.1 - 1.3 (Acrobat 2 - 4), collider #2', 0, 0), + (10500, 'PDF 1.4 - 1.6 (Acrobat 5 - 8)', 0, 0), + (10600, 'PDF 1.7 Level 3 (Acrobat 9)', 0, 0), + (10700, 'PDF 1.7 Level 8 (Acrobat 10 - 11)', 0, 0), + (10800, 'SHA384', 0, 0), + (10900, 'PBKDF2-HMAC-SHA256', 0, 1), + (11000, 'PrestaShop', 1, 0), + (11100, 'PostgreSQL Challenge-Response Authentication (MD5)', 0, 0), + (11200, 'MySQL Challenge-Response Authentication (SHA1)', 0, 0), + (11300, 'Bitcoin/Litecoin wallet.dat', 0, 1), + (11400, 'SIP digest authentication (MD5)', 0, 0), + (11500, 'CRC32', 1, 0), + (11600, '7-Zip', 0, 0), + (11700, 'GOST R 34.11-2012 (Streebog) 256-bit', 0, 0), + (11800, 'GOST R 34.11-2012 (Streebog) 512-bit', 0, 0), + (11900, 'PBKDF2-HMAC-MD5', 0, 1), + (12000, 'PBKDF2-HMAC-SHA1', 0, 1), + (12001, 'Atlassian (PBKDF2-HMAC-SHA1)', 0, 1), + (12100, 'PBKDF2-HMAC-SHA512', 0, 1), + (12200, 'eCryptfs', 0, 1), + (12300, 'Oracle T: Type (Oracle 12+)', 0, 1), + (12400, 'BSDiCrypt, Extended DES', 0, 0), + (12500, 'RAR3-hp', 0, 0), + (12600, 'ColdFusion 10+', 1, 0), + (12700, 'Blockchain, My Wallet', 0, 1), + (12800, 'MS-AzureSync PBKDF2-HMAC-SHA256', 0, 1), + (12900, 'Android FDE (Samsung DEK)', 0, 1), + (13000, 'RAR5', 0, 1), + (13100, 'Kerberos 5 TGS-REP etype 23', 0, 0), + (13200, 'AxCrypt', 0, 0), + (13300, 'AxCrypt in memory SHA1', 0, 0), + (13400, 'Keepass 1/2 AES/Twofish with/without keyfile', 0, 0), + (13500, 'PeopleSoft PS_TOKEN', 1, 0), + (13600, 'WinZip', 0, 1), + (13711, 'VeraCrypt PBKDF2-HMAC-RIPEMD160 + AES, Serpent, Twofish', 0, 1), + (13712, 'VeraCrypt PBKDF2-HMAC-RIPEMD160 + AES-Twofish, Serpent-AES, Twofish-Serpent', 0, 1), + (13713, 'VeraCrypt PBKDF2-HMAC-RIPEMD160 + Serpent-Twofish-AES', 0, 1), + (13721, 'VeraCrypt PBKDF2-HMAC-SHA512 + AES, Serpent, Twofish', 0, 1), + (13722, 'VeraCrypt PBKDF2-HMAC-SHA512 + AES-Twofish, Serpent-AES, Twofish-Serpent', 0, 1), + (13723, 'VeraCrypt PBKDF2-HMAC-SHA512 + Serpent-Twofish-AES', 0, 1), + (13731, 'VeraCrypt PBKDF2-HMAC-Whirlpool + AES, Serpent, Twofish', 0, 1), + (13732, 'VeraCrypt PBKDF2-HMAC-Whirlpool + AES-Twofish, Serpent-AES, Twofish-Serpent', 0, 1), + (13733, 'VeraCrypt PBKDF2-HMAC-Whirlpool + Serpent-Twofish-AES', 0, 1), + (13751, 'VeraCrypt PBKDF2-HMAC-SHA256 + AES, Serpent, Twofish', 0, 1), + (13752, 'VeraCrypt PBKDF2-HMAC-SHA256 + AES-Twofish, Serpent-AES, Twofish-Serpent', 0, 1), + (13753, 'VeraCrypt PBKDF2-HMAC-SHA256 + Serpent-Twofish-AES', 0, 1), + (13800, 'Windows 8+ phone PIN/Password', 1, 0), + (13900, 'OpenCart', 1, 0), + (14000, 'DES (PT = $salt, key = $pass)', 1, 0), + (14100, '3DES (PT = $salt, key = $pass)', 1, 0), + (14400, 'sha1(CX)', 1, 0), + (14600, 'LUKS 10', 0, 1), + (14700, 'iTunes Backup < 10.0 11', 0, 1), + (14800, 'iTunes Backup >= 10.0 11', 0, 1), + (14900, 'Skip32 12', 1, 0), + (15000, 'FileZilla Server >= 0.9.55', 1, 0), + (15100, 'Juniper/NetBSD sha1crypt', 0, 1), + (15200, 'Blockchain, My Wallet, V2', 0, 0), + (15300, 'DPAPI masterkey file v1 and v2', 0, 1), + (15400, 'ChaCha20', 0, 0), + (15500, 'JKS Java Key Store Private Keys (SHA1)', 0, 0), + (15600, 'Ethereum Wallet, PBKDF2-HMAC-SHA256', 0, 1), + (15700, 'Ethereum Wallet, SCRYPT', 0, 0), + (15900, 'DPAPI master key file version 2 + Active Directory domain context', 0, 1), + (16000, 'Tripcode', 0, 0), + (16100, 'TACACS+', 0, 0), + (16200, 'Apple Secure Notes', 0, 1), + (16300, 'Ethereum Pre-Sale Wallet, PBKDF2-HMAC-SHA256', 0, 1), + (16400, 'CRAM-MD5 Dovecot', 0, 0), + (16500, 'JWT (JSON Web Token)', 0, 0), + (16600, 'Electrum Wallet (Salt-Type 1-3)', 0, 0), + (16700, 'FileVault 2', 0, 1), + (16800, 'WPA-PMKID-PBKDF2', 0, 1), + (16801, 'WPA-PMKID-PMK', 0, 1), + (16900, 'Ansible Vault', 0, 1), + (17200, 'PKZIP (Compressed)', 0, 0), + (17210, 'PKZIP (Uncompressed)', 0, 0), + (17220, 'PKZIP (Compressed Multi-File)', 0, 0), + (17225, 'PKZIP (Mixed Multi-File)', 0, 0), + (17230, 'PKZIP (Compressed Multi-File Checksum-Only)', 0, 0), + (17300, 'SHA3-224', 0, 0), + (17400, 'SHA3-256', 0, 0), + (17500, 'SHA3-384', 0, 0), + (17600, 'SHA3-512', 0, 0), + (17700, 'Keccak-224', 0, 0), + (17800, 'Keccak-256', 0, 0), + (17900, 'Keccak-384', 0, 0), + (18000, 'Keccak-512', 0, 0), + (18100, 'TOTP (HMAC-SHA1)', 1, 0), + (18200, 'Kerberos 5 AS-REP etype 23', 0, 1), + (18300, 'Apple File System (APFS)', 0, 1), + (18400, 'Open Document Format (ODF) 1.2 (SHA-256, AES)', 0, 1), + (18500, 'sha1(md5(md5($pass)))', 0, 0), + (18600, 'Open Document Format (ODF) 1.1 (SHA-1, Blowfish)', 0, 1), + (18700, 'Java Object hashCode()', 0, 1), + (18800, 'Blockchain, My Wallet, Second Password (SHA256)', 0, 1), + (18900, 'Android Backup', 0, 1), + (19000, 'QNX /etc/shadow (MD5)', 0, 1), + (19100, 'QNX /etc/shadow (SHA256)', 0, 1), + (19200, 'QNX /etc/shadow (SHA512)', 0, 1), + (19300, 'sha1($salt1.$pass.$salt2)', 0, 0), + (19500, 'Ruby on Rails Restful-Authentication', 0, 0), + (19600, 'Kerberos 5 TGS-REP etype 17 (AES128-CTS-HMAC-SHA1-96)', 0, 1), + (19700, 'Kerberos 5 TGS-REP etype 18 (AES256-CTS-HMAC-SHA1-96)', 0, 1), + (19800, 'Kerberos 5, etype 17, Pre-Auth', 0, 1), + (19900, 'Kerberos 5, etype 18, Pre-Auth', 0, 1), + (20011, 'DiskCryptor SHA512 + XTS 512 bit (AES) / DiskCryptor SHA512 + XTS 512 bit (Twofish) / DiskCryptor SHA512 + XTS 512 bit (Serpent)', 0, 1), + (20012, 'DiskCryptor SHA512 + XTS 1024 bit (AES-Twofish) / DiskCryptor SHA512 + XTS 1024 bit (Twofish-Serpent) / DiskCryptor SHA512 + XTS 1024 bit (Serpent-AES)', 0, 1), + (20013, 'DiskCryptor SHA512 + XTS 1536 bit (AES-Twofish-Serpent)', 0, 1), + (20200, 'Python passlib pbkdf2-sha512', 0, 1), + (20300, 'Python passlib pbkdf2-sha256', 0, 1), + (20400, 'Python passlib pbkdf2-sha1', 0, 0), + (20500, 'PKZIP Master Key', 0, 0), + (20510, 'PKZIP Master Key (6 byte optimization)', 0, 0), + (20600, 'Oracle Transportation Management (SHA256)', 0, 0), + (20710, 'sha256(sha256($pass).$salt)', 1, 0), + (20711, 'AuthMe sha256', 0, 0), + (20800, 'sha256(md5($pass))', 0, 0), + (20900, 'md5(sha1($pass).md5($pass).sha1($pass))', 0, 0), + (21000, 'BitShares v0.x - sha512(sha512_bin(pass))', 0, 0), + (21100, 'sha1(md5($pass.$salt))', 1, 0), + (21200, 'md5(sha1($salt).md5($pass))', 1, 0), + (21300, 'md5($salt.sha1($salt.$pass))', 1, 0), + (21400, 'sha256(sha256_bin(pass))', 0, 0), + (21500, 'SolarWinds Orion', 0, 0), + (21600, 'Web2py pbkdf2-sha512', 0, 0), + (21700, 'Electrum Wallet (Salt-Type 4)', 0, 0), + (21800, 'Electrum Wallet (Salt-Type 5)', 0, 0), + (22000, 'WPA-PBKDF2-PMKID+EAPOL', 0, 0), + (22001, 'WPA-PMK-PMKID+EAPOL', 0, 0), + (22100, 'BitLocker', 0, 0), + (22200, 'Citrix NetScaler (SHA512)', 0, 0), + (22300, 'sha256($salt.$pass.$salt)', 1, 0), + (22400, 'AES Crypt (SHA256)', 0, 0), + (99999, 'Plaintext', 0, 0); + +CREATE TABLE `LogEntry` ( + `logEntryId` INT(11) NOT NULL, + `issuer` VARCHAR(50) NOT NULL, + `issuerId` VARCHAR(50) NOT NULL, + `level` VARCHAR(50) NOT NULL, + `message` TEXT NOT NULL, + `time` BIGINT NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `NotificationSetting` ( + `notificationSettingId` INT(11) NOT NULL, + `action` VARCHAR(50) NOT NULL, + `objectId` INT(11) NULL, + `notification` VARCHAR(50) NOT NULL, + `userId` INT(11) NOT NULL, + `receiver` VARCHAR(256) NOT NULL, + `isActive` TINYINT(4) NOT NULL +)ENGINE = InnoDB; + +CREATE TABLE `Pretask` ( + `pretaskId` INT(11) NOT NULL, + `taskName` VARCHAR(100) NOT NULL, + `attackCmd` VARCHAR(256) NOT NULL, + `chunkTime` INT(11) NOT NULL, + `statusTimer` INT(11) NOT NULL, + `color` VARCHAR(20) NULL, + `isSmall` TINYINT(4) NOT NULL, + `isCpuTask` TINYINT(4) NOT NULL, + `useNewBench` TINYINT(4) NOT NULL, + `priority` INT(11) NOT NULL, + `isMaskImport` TINYINT(4) NOT NULL, + `crackerBinaryTypeId` INT(11) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `RegVoucher` ( + `regVoucherId` INT(11) NOT NULL, + `voucher` VARCHAR(100) NOT NULL, + `time` BIGINT NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `RightGroup` ( + `rightGroupId` INT(11) NOT NULL, + `groupName` VARCHAR(50) NOT NULL, + `permissions` TEXT NOT NULL +) ENGINE = InnoDB; + +INSERT INTO `RightGroup` (`rightGroupId`, `groupName`, `permissions`) VALUES + (1, 'Administrator', 'ALL'); + +CREATE TABLE `Session` ( + `sessionId` INT(11) NOT NULL, + `userId` INT(11) NOT NULL, + `sessionStartDate` BIGINT NOT NULL, + `lastActionDate` BIGINT NOT NULL, + `isOpen` TINYINT(4) NOT NULL, + `sessionLifetime` INT(11) NOT NULL, + `sessionKey` VARCHAR(256) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `Speed` ( + `speedId` INT(11) NOT NULL, + `agentId` INT(11) NOT NULL, + `taskId` INT(11) NOT NULL, + `speed` BIGINT(20) NOT NULL, + `time` BIGINT(20) NOT NULL +) ENGINE=InnoDB; + +CREATE TABLE `StoredValue` ( + `storedValueId` VARCHAR(50) NOT NULL, + `val` VARCHAR(256) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `Supertask` ( + `supertaskId` INT(11) NOT NULL, + `supertaskName` VARCHAR(50) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `SupertaskPretask` ( + `supertaskPretaskId` INT(11) NOT NULL, + `supertaskId` INT(11) NOT NULL, + `pretaskId` INT(11) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `Task` ( + `taskId` INT(11) NOT NULL, + `taskName` VARCHAR(256) NOT NULL, + `attackCmd` VARCHAR(256) NOT NULL, + `chunkTime` INT(11) NOT NULL, + `statusTimer` INT(11) NOT NULL, + `keyspace` BIGINT(20) NOT NULL, + `keyspaceProgress` BIGINT(20) NOT NULL, + `priority` INT(11) NOT NULL, + `color` VARCHAR(20) NULL, + `isSmall` TINYINT(4) NOT NULL, + `isCpuTask` TINYINT(4) NOT NULL, + `useNewBench` TINYINT(4) NOT NULL, + `skipKeyspace` BIGINT(20) NOT NULL, + `crackerBinaryId` INT(11) DEFAULT NULL, + `crackerBinaryTypeId` INT(11) NULL, + `taskWrapperId` INT(11) NOT NULL, + `isArchived` TINYINT(4) NOT NULL, + `notes` TEXT NOT NULL, + `staticChunks` INT(11) NOT NULL, + `chunkSize` BIGINT(20) NOT NULL, + `forcePipe` TINYINT(4) NOT NULL, + `usePreprocessor` TINYINT(4) NOT NULL, + `preprocessorCommand` VARCHAR(256) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `TaskDebugOutput` ( + `taskDebugOutputId` INT(11) NOT NULL, + `taskId` INT(11) NOT NULL, + `output` VARCHAR(256) NOT NULL +) ENGINE=InnoDB; + +CREATE TABLE `TaskWrapper` ( + `taskWrapperId` INT(11) NOT NULL, + `priority` INT(11) NOT NULL, + `taskType` INT(11) NOT NULL, + `hashlistId` INT(11) NOT NULL, + `accessGroupId` INT(11) DEFAULT NULL, + `taskWrapperName` VARCHAR(100) NOT NULL, + `isArchived` TINYINT(4) NOT NULL, + `cracked` INT(11) NOT NULL +)ENGINE = InnoDB; + +CREATE TABLE `User` ( + `userId` INT(11) NOT NULL, + `username` VARCHAR(100) NOT NULL, + `email` VARCHAR(150) NOT NULL, + `passwordHash` VARCHAR(256) NOT NULL, + `passwordSalt` VARCHAR(256) NOT NULL, + `isValid` TINYINT(4) NOT NULL, + `isComputedPassword` TINYINT(4) NOT NULL, + `lastLoginDate` BIGINT NOT NULL, + `registeredSince` BIGINT NOT NULL, + `sessionLifetime` INT(11) NOT NULL, + `rightGroupId` INT(11) NOT NULL, + `yubikey` VARCHAR(256) DEFAULT NULL, + `otp1` VARCHAR(256) DEFAULT NULL, + `otp2` VARCHAR(256) DEFAULT NULL, + `otp3` VARCHAR(256) DEFAULT NULL, + `otp4` VARCHAR(256) DEFAULT NULL +) ENGINE = InnoDB; + +CREATE TABLE `Benchmark` ( + `benchmarkId` INT(11) NOT NULL, + `benchmarkValue` VARCHAR(256) NOT NULL, + `hardwareGroupId` int(11) NOT NULL, + `attackParameters` VARCHAR(256) NOT NULL, + `ttl` int(11) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `HardwareGroup` ( + `hardwareGroupId` INT(11) NOT NULL, + `devices` VARCHAR(256) NOT NULL, +) ENGINE = InnoDB; + +CREATE TABLE `Zap` ( + `zapId` INT(11) NOT NULL, + `hash` TEXT NOT NULL, + `solveTime` BIGINT NOT NULL, + `agentId` INT(11) NULL, + `hashlistId` INT(11) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `ApiKey` ( + `apiKeyId` INT(11) NOT NULL, + `startValid` BIGINT(20) NOT NULL, + `endValid` BIGINT(20) NOT NULL, + `accessKey` VARCHAR(256) NOT NULL, + `accessCount` INT(11) NOT NULL, + `userId` INT(11) NOT NULL, + `apiGroupId` INT(11) NOT NULL +) ENGINE=InnoDB; + +CREATE TABLE `ApiGroup` ( + `apiGroupId` INT(11) NOT NULL, + `name` VARCHAR(100) NOT NULL, + `permissions` TEXT NOT NULL +) ENGINE=InnoDB; + +CREATE TABLE `FileDownload` ( + `fileDownloadId` INT(11) NOT NULL, + `time` BIGINT NOT NULL, + `fileId` INT(11) NOT NULL, + `status` INT(11) NOT NULL +) ENGINE=InnoDB; + +INSERT INTO `ApiGroup` ( `apiGroupId`, `name`, `permissions`) VALUES + (1, 'Administrators', 'ALL'); + +CREATE TABLE `HealthCheck` ( + `healthCheckId` INT(11) NOT NULL, + `time` BIGINT(20) NOT NULL, + `status` INT(11) NOT NULL, + `checkType` INT(11) NOT NULL, + `hashtypeId` INT(11) NOT NULL, + `crackerBinaryId` INT(11) NOT NULL, + `expectedCracks` INT(11) NOT NULL, + `attackCmd` VARCHAR(256) NOT NULL +) ENGINE=InnoDB; + +CREATE TABLE `HealthCheckAgent` ( + `healthCheckAgentId` INT(11) NOT NULL, + `healthCheckId` INT(11) NOT NULL, + `agentId` INT(11) NOT NULL, + `status` INT(11) NOT NULL, + `cracked` INT(11) NOT NULL, + `numGpus` INT(11) NOT NULL, + `start` BIGINT(20) NOT NULL, + `end` BIGINT(20) NOT NULL, + `errors` TEXT NOT NULL +) ENGINE=InnoDB; + +CREATE TABLE `Preprocessor` ( + `preprocessorId` INT(11) NOT NULL, + `name` VARCHAR(256) NOT NULL, + `url` VARCHAR(512) NOT NULL, + `binaryName` VARCHAR(256) NOT NULL, + `keyspaceCommand` VARCHAR(256) NULL, + `skipCommand` VARCHAR(256) NULL, + `limitCommand` VARCHAR(256) NULL +) ENGINE=InnoDB; + +INSERT INTO `Preprocessor` ( `preprocessorId`, `name`, `url`, `binaryName`, `keyspaceCommand`, `skipCommand`, `limitCommand`) VALUES + (1, 'Prince', 'https://github.com/hashcat/princeprocessor/releases/download/v0.22/princeprocessor-0.22.7z', 'pp', '--keyspace', '--skip', '--limit'); + +-- Add Indexes +ALTER TABLE `AccessGroup` + ADD PRIMARY KEY (`accessGroupId`); + +ALTER TABLE `AccessGroupAgent` + ADD PRIMARY KEY (`accessGroupAgentId`), + ADD KEY `accessGroupId` (`accessGroupId`), + ADD KEY `agentId` (`agentId`); + +ALTER TABLE `AccessGroupUser` + ADD PRIMARY KEY (`accessGroupUserId`), + ADD KEY `accessGroupId` (`accessGroupId`), + ADD KEY `userId` (`userId`); + +ALTER TABLE `Agent` + ADD PRIMARY KEY (`agentId`), + ADD KEY `userId` (`userId`); + +ALTER TABLE `Benchmark` + ADD PRIMARY KEY (`benchmarkId`), + ADD KEY `agentId` (`agentId`); + +ALTER TABLE `HardwareGroup` + ADD PRIMARY KEY (`hardwareGroupId`); + +ALTER TABLE `AgentBinary` + ADD PRIMARY KEY (`agentBinaryId`); + +ALTER TABLE `AgentError` + ADD PRIMARY KEY (`agentErrorId`), + ADD KEY `agentId` (`agentId`), + ADD KEY `taskId` (`taskId`); + +ALTER TABLE `AgentStat` + ADD PRIMARY KEY (`agentStatId`), + ADD KEY `agentId` (`agentId`); + +ALTER TABLE `AgentZap` + ADD PRIMARY KEY (`agentZapId`), + ADD KEY `agentId` (`agentId`), + ADD KEY `lastZapId` (`lastZapId`); + +ALTER TABLE `ApiKey` + ADD PRIMARY KEY (`apiKeyId`); + +ALTER TABLE `ApiGroup` + ADD PRIMARY KEY (`apiGroupId`); + +ALTER TABLE `Assignment` + ADD PRIMARY KEY (`assignmentId`), + ADD KEY `taskId` (`taskId`), + ADD KEY `agentId` (`agentId`); + +ALTER TABLE `Chunk` + ADD PRIMARY KEY (`chunkId`), + ADD KEY `taskId` (`taskId`), + ADD KEY `agentId` (`agentId`); + +ALTER TABLE `Config` + ADD PRIMARY KEY (`configId`), + ADD KEY `configSectionId` (`configSectionId`); + +ALTER TABLE `ConfigSection` + ADD PRIMARY KEY (`configSectionId`); + +ALTER TABLE `CrackerBinary` + ADD PRIMARY KEY (`crackerBinaryId`), + ADD KEY `crackerBinaryTypeId` (`crackerBinaryTypeId`); + +ALTER TABLE `CrackerBinaryType` + ADD PRIMARY KEY (`crackerBinaryTypeId`); + +ALTER TABLE `File` + ADD PRIMARY KEY (`fileId`); + +ALTER TABLE `FileDownload` + ADD PRIMARY KEY (`fileDownloadId`); + +ALTER TABLE `FileDelete` + ADD PRIMARY KEY (`fileDeleteId`); + +ALTER TABLE `FilePretask` + ADD PRIMARY KEY (`filePretaskId`), + ADD KEY `fileId` (`fileId`), + ADD KEY `pretaskId` (`pretaskId`); + +ALTER TABLE `FileTask` + ADD PRIMARY KEY (`fileTaskId`), + ADD KEY `fileId` (`fileId`), + ADD KEY `taskId` (`taskId`); + +ALTER TABLE `Hash` + ADD PRIMARY KEY (`hashId`), + ADD KEY `hashlistId` (`hashlistId`), + ADD KEY `chunkId` (`chunkId`), + ADD KEY `isCracked` (`isCracked`), + ADD KEY `hash` (`hash`(500)); + +ALTER TABLE `HashBinary` + ADD PRIMARY KEY (`hashBinaryId`), + ADD KEY `hashlistId` (`hashlistId`), + ADD KEY `chunkId` (`chunkId`); + +ALTER TABLE `Hashlist` + ADD PRIMARY KEY (`hashlistId`), + ADD KEY `hashTypeId` (`hashTypeId`); + +ALTER TABLE `HashlistHashlist` + ADD PRIMARY KEY (`hashlistHashlistId`), + ADD KEY `parentHashlistId` (`parentHashlistId`), + ADD KEY `hashlistId` (`hashlistId`); + +ALTER TABLE `HashType` + ADD PRIMARY KEY (`hashTypeId`); + +ALTER TABLE `HealthCheck` + ADD PRIMARY KEY (`healthCheckId`); + +ALTER TABLE `HealthCheckAgent` + ADD PRIMARY KEY (`healthCheckAgentId`); + +ALTER TABLE `LogEntry` + ADD PRIMARY KEY (`logEntryId`); + +ALTER TABLE `NotificationSetting` + ADD PRIMARY KEY (`notificationSettingId`), + ADD KEY `userId` (`userId`); + +ALTER TABLE `Pretask` + ADD PRIMARY KEY (`pretaskId`); + +ALTER TABLE `RegVoucher` + ADD PRIMARY KEY (`regVoucherId`); + +ALTER TABLE `RightGroup` + ADD PRIMARY KEY (`rightGroupId`); + +ALTER TABLE `Session` + ADD PRIMARY KEY (`sessionId`), + ADD KEY `userId` (`userId`); + +ALTER TABLE `Speed` + ADD PRIMARY KEY (`speedId`), + ADD KEY `agentId` (`agentId`), + ADD KEY `taskId` (`taskId`); + +ALTER TABLE `StoredValue` + ADD PRIMARY KEY (`storedValueId`); + +ALTER TABLE `Supertask` + ADD PRIMARY KEY (`supertaskId`); + +ALTER TABLE `SupertaskPretask` + ADD PRIMARY KEY (`supertaskPretaskId`), + ADD KEY `supertaskId` (`supertaskId`), + ADD KEY `pretaskId` (`pretaskId`); + +ALTER TABLE `Task` + ADD PRIMARY KEY (`taskId`), + ADD KEY `crackerBinaryId` (`crackerBinaryId`); + +ALTER TABLE `TaskDebugOutput` + ADD PRIMARY KEY (`taskDebugOutputId`); + +ALTER TABLE `TaskWrapper` + ADD PRIMARY KEY (`taskWrapperId`), + ADD KEY `hashlistId` (`hashlistId`), + ADD KEY `accessGroupId` (`accessGroupId`); + +ALTER TABLE `User` + ADD PRIMARY KEY (`userId`), + ADD UNIQUE KEY `username` (`username`), + ADD KEY `rightGroupId` (`rightGroupId`); + +ALTER TABLE `Zap` + ADD PRIMARY KEY (`zapId`), + ADD KEY `agentId` (`agentId`), + ADD KEY `hashlistId` (`hashlistId`); + +ALTER TABLE `Preprocessor` + ADD PRIMARY KEY (`preprocessorId`); + +-- Add AUTO_INCREMENT for tables +ALTER TABLE `AccessGroup` + MODIFY `accessGroupId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `AccessGroupAgent` + MODIFY `accessGroupAgentId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `AccessGroupUser` + MODIFY `accessGroupUserId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `Agent` + MODIFY `agentId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `AgentBinary` + MODIFY `agentBinaryId` INT(11) NOT NULL AUTO_INCREMENT, + AUTO_INCREMENT = 2; + +ALTER TABLE `AgentError` + MODIFY `agentErrorId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `AgentStat` + MODIFY `agentStatId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `AgentZap` + MODIFY `agentZapId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `ApiKey` + MODIFY `apiKeyId` int(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `ApiGroup` + MODIFY `apiGroupId` int(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `Assignment` + MODIFY `assignmentId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `Chunk` + MODIFY `chunkId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `Config` + MODIFY `configId` INT(11) NOT NULL AUTO_INCREMENT, + AUTO_INCREMENT = 72; + +ALTER TABLE `ConfigSection` + MODIFY `configSectionId` INT(11) NOT NULL AUTO_INCREMENT, + AUTO_INCREMENT = 8; + +ALTER TABLE `CrackerBinary` + MODIFY `crackerBinaryId` INT(11) NOT NULL AUTO_INCREMENT, + AUTO_INCREMENT = 2; + +ALTER TABLE `CrackerBinaryType` + MODIFY `crackerBinaryTypeId` INT(11) NOT NULL AUTO_INCREMENT, + AUTO_INCREMENT = 2; + +ALTER TABLE `File` + MODIFY `fileId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `FileDownload` + MODIFY `fileDownloadId` int(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `FileDelete` + MODIFY `fileDeleteId` int(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `FilePretask` + MODIFY `filePretaskId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `FileTask` + MODIFY `fileTaskId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `Hash` + MODIFY `hashId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `HashBinary` + MODIFY `hashBinaryId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `Hashlist` + MODIFY `hashlistId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `HashlistHashlist` + MODIFY `hashlistHashlistId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `HealthCheck` + MODIFY `healthCheckId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `HealthCheckAgent` + MODIFY `healthCheckAgentId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `LogEntry` + MODIFY `logEntryId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `NotificationSetting` + MODIFY `notificationSettingId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `Pretask` + MODIFY `pretaskId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `RegVoucher` + MODIFY `regVoucherId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `RightGroup` + MODIFY `rightGroupId` INT(11) NOT NULL AUTO_INCREMENT, + AUTO_INCREMENT = 2; + +ALTER TABLE `Session` + MODIFY `sessionId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `Speed` + MODIFY `speedId` int(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `Supertask` + MODIFY `supertaskId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `SupertaskPretask` + MODIFY `supertaskPretaskId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `Task` + MODIFY `taskId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `TaskDebugOutput` + MODIFY `taskDebugOutputId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `TaskWrapper` + MODIFY `taskWrapperId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `User` + MODIFY `userId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `Benchmark` + MODIFY `benchmarkId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `HardwareGroup` + MODIFY `hardwareGroupId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `Zap` + MODIFY `zapId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `Preprocessor` + MODIFY `preprocessorId` INT(11) NOT NULL AUTO_INCREMENT; + +-- Add Constraints +ALTER TABLE `AccessGroupAgent` + ADD CONSTRAINT `AccessGroupAgent_ibfk_1` FOREIGN KEY (`accessGroupId`) REFERENCES `AccessGroup` (`accessGroupId`), + ADD CONSTRAINT `AccessGroupAgent_ibfk_2` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`); + +ALTER TABLE `AccessGroupUser` + ADD CONSTRAINT `AccessGroupUser_ibfk_1` FOREIGN KEY (`accessGroupId`) REFERENCES `AccessGroup` (`accessGroupId`), + ADD CONSTRAINT `AccessGroupUser_ibfk_2` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`); + +ALTER TABLE `Agent` + ADD CONSTRAINT `Agent_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`); + +ALTER TABLE `AgentError` + ADD CONSTRAINT `AgentError_ibfk_1` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`), + ADD CONSTRAINT `AgentError_ibfk_2` FOREIGN KEY (`taskId`) REFERENCES `Task` (`taskId`); + +ALTER TABLE `AgentStat` + ADD CONSTRAINT `AgentStat_ibfk_1` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`); + +ALTER TABLE `AgentZap` + ADD CONSTRAINT `AgentZap_ibfk_1` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`), + ADD CONSTRAINT `AgentZap_ibfk_2` FOREIGN KEY (`lastZapId`) REFERENCES `Zap` (`zapId`); + +ALTER TABLE `ApiKey` + ADD CONSTRAINT `ApiKey_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`), + ADD CONSTRAINT `ApiKey_ibfk_2` FOREIGN KEY (`apiGroupId`) REFERENCES `ApiGroup` (`apiGroupId`); + +ALTER TABLE `Assignment` + ADD CONSTRAINT `Assignment_ibfk_1` FOREIGN KEY (`taskId`) REFERENCES `Task` (`taskId`), + ADD CONSTRAINT `Assignment_ibfk_2` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`); + +ALTER TABLE `Chunk` + ADD CONSTRAINT `Chunk_ibfk_1` FOREIGN KEY (`taskId`) REFERENCES `Task` (`taskId`), + ADD CONSTRAINT `Chunk_ibfk_2` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`); + +ALTER TABLE `Config` + ADD CONSTRAINT `Config_ibfk_1` FOREIGN KEY (`configSectionId`) REFERENCES `ConfigSection` (`configSectionId`); + +ALTER TABLE `CrackerBinary` + ADD CONSTRAINT `CrackerBinary_ibfk_1` FOREIGN KEY (`crackerBinaryTypeId`) REFERENCES `CrackerBinaryType` (`crackerBinaryTypeId`); + +ALTER TABLE `File` + ADD CONSTRAINT `File_ibfk_1` FOREIGN KEY (`accessGroupId`) REFERENCES `AccessGroup` (`accessGroupId`); + +ALTER TABLE `FileDownload` + ADD CONSTRAINT `FileDownload_ibkf_1` FOREIGN KEY (`fileId`) REFERENCES `File`(`fileId`); + +ALTER TABLE `FilePretask` + ADD CONSTRAINT `FilePretask_ibfk_1` FOREIGN KEY (`fileId`) REFERENCES `File` (`fileId`), + ADD CONSTRAINT `FilePretask_ibfk_2` FOREIGN KEY (`pretaskId`) REFERENCES `Pretask` (`pretaskId`); + +ALTER TABLE `FileTask` + ADD CONSTRAINT `FileTask_ibfk_1` FOREIGN KEY (`fileId`) REFERENCES `File` (`fileId`), + ADD CONSTRAINT `FileTask_ibfk_2` FOREIGN KEY (`taskId`) REFERENCES `Task` (`taskId`); + +ALTER TABLE `Hash` + ADD CONSTRAINT `Hash_ibfk_1` FOREIGN KEY (`hashlistId`) REFERENCES `Hashlist` (`hashlistId`), + ADD CONSTRAINT `Hash_ibfk_2` FOREIGN KEY (`chunkId`) REFERENCES `Chunk` (`chunkId`); + +ALTER TABLE `HashBinary` + ADD CONSTRAINT `HashBinary_ibfk_1` FOREIGN KEY (`hashlistId`) REFERENCES `Hashlist` (`hashlistId`), + ADD CONSTRAINT `HashBinary_ibfk_2` FOREIGN KEY (`chunkId`) REFERENCES `Chunk` (`chunkId`); + +ALTER TABLE `Hashlist` + ADD CONSTRAINT `Hashlist_ibfk_1` FOREIGN KEY (`hashTypeId`) REFERENCES `HashType` (`hashTypeId`), + ADD CONSTRAINT `Hashlist_ibfk_2` FOREIGN KEY (`accessGroupId`) REFERENCES `AccessGroup` (`accessGroupId`); + +ALTER TABLE `HashlistHashlist` + ADD CONSTRAINT `HashlistHashlist_ibfk_1` FOREIGN KEY (`parentHashlistId`) REFERENCES `Hashlist` (`hashlistId`), + ADD CONSTRAINT `HashlistHashlist_ibfk_2` FOREIGN KEY (`hashlistId`) REFERENCES `Hashlist` (`hashlistId`); + +ALTER TABLE `HealthCheck` + ADD CONSTRAINT `HealthCheck_ibfk_1` FOREIGN KEY (`crackerBinaryId`) REFERENCES `CrackerBinary` (`crackerBinaryId`); + +ALTER TABLE `HealthCheckAgent` + ADD CONSTRAINT `HealthCheckAgent_ibfk_1` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`), + ADD CONSTRAINT `HealthCheckAgent_ibfk_2` FOREIGN KEY (`healthCheckId`) REFERENCES `HealthCheck` (`healthCheckId`); + +ALTER TABLE `NotificationSetting` + ADD CONSTRAINT `NotificationSetting_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`); + +ALTER TABLE `Pretask` + ADD CONSTRAINT `Pretask_ibfk_1` FOREIGN KEY (`crackerBinaryTypeId`) REFERENCES `CrackerBinaryType` (`crackerBinaryTypeId`); + +ALTER TABLE `Session` + ADD CONSTRAINT `Session_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`); + +ALTER TABLE `Speed` + ADD CONSTRAINT `Speed_ibfk_1` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`), + ADD CONSTRAINT `Speed_ibfk_2` FOREIGN KEY (`taskId`) REFERENCES `Task` (`taskId`); + +ALTER TABLE `SupertaskPretask` + ADD CONSTRAINT `SupertaskPretask_ibfk_1` FOREIGN KEY (`supertaskId`) REFERENCES `Supertask` (`supertaskId`), + ADD CONSTRAINT `SupertaskPretask_ibfk_2` FOREIGN KEY (`pretaskId`) REFERENCES `Pretask` (`pretaskId`); + +ALTER TABLE `Task` + ADD CONSTRAINT `Task_ibfk_1` FOREIGN KEY (`crackerBinaryId`) REFERENCES `CrackerBinary` (`crackerBinaryId`), + ADD CONSTRAINT `Task_ibfk_2` FOREIGN KEY (`crackerBinaryTypeId`) REFERENCES `CrackerBinaryType` (`crackerBinaryTypeId`), + ADD CONSTRAINT `Task_ibfk_3` FOREIGN KEY (`taskWrapperId`) REFERENCES `TaskWrapper` (`taskWrapperId`); + +ALTER TABLE `TaskDebugOutput` + ADD CONSTRAINT `TaskDebugOutput_ibfk_1` FOREIGN KEY (`taskId`) REFERENCES `Task` (`taskId`); + +ALTER TABLE `TaskWrapper` + ADD CONSTRAINT `TaskWrapper_ibfk_1` FOREIGN KEY (`hashlistId`) REFERENCES `Hashlist` (`hashlistId`), + ADD CONSTRAINT `TaskWrapper_ibfk_2` FOREIGN KEY (`accessGroupId`) REFERENCES `AccessGroup` (`accessGroupId`); + +ALTER TABLE `User` + ADD CONSTRAINT `User_ibfk_1` FOREIGN KEY (`rightGroupId`) REFERENCES `RightGroup` (`rightGroupId`); + +ALTER TABLE `Benchmark` + ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`HardwareGroupId`) REFERENCES `Agent` (`hardwareGroupId`); + +ALTER TABLE `Zap` + ADD CONSTRAINT `Zap_ibfk_1` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`), + ADD CONSTRAINT `Zap_ibfk_2` FOREIGN KEY (`hashlistId`) REFERENCES `Hashlist` (`hashlistId`); + +/*!40101 SET CHARACTER_SET_CLIENT = @OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS = @OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION = @OLD_COLLATION_CONNECTION */; From 2f5cd16c68b9b4310620476cc519a4f80148c08e Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Thu, 27 Apr 2023 13:20:57 -0400 Subject: [PATCH 02/55] Added the models for benchmark caching --- src/dba/Factory.class.php | 23 +++++ src/dba/models/Agent.class.php | 18 ++-- src/dba/models/AgentFactory.class.php | 2 +- src/dba/models/Benchmark.class.php | 92 +++++++++++++++++++ src/dba/models/BenchmarkFactory.class.php | 82 +++++++++++++++++ src/dba/models/HardwareGroup.class.php | 65 +++++++++++++ src/dba/models/HardwareGroupFactory.class.php | 82 +++++++++++++++++ src/dba/models/generator.php | 12 +++ 8 files changed, 366 insertions(+), 10 deletions(-) create mode 100644 src/dba/models/Benchmark.class.php create mode 100644 src/dba/models/BenchmarkFactory.class.php create mode 100644 src/dba/models/HardwareGroup.class.php create mode 100644 src/dba/models/HardwareGroupFactory.class.php diff --git a/src/dba/Factory.class.php b/src/dba/Factory.class.php index aaa44afc7..d586dde00 100644 --- a/src/dba/Factory.class.php +++ b/src/dba/Factory.class.php @@ -18,6 +18,8 @@ class Factory { private static $fileFactory = null; private static $hashFactory = null; private static $hashBinaryFactory = null; + private static $benchmarkFactory = null; + private static $hardwareGroupFactory = null; private static $hashlistFactory = null; private static $hashTypeFactory = null; private static $logEntryFactory = null; @@ -137,6 +139,27 @@ public static function getConfigFactory() { return self::$configFactory; } } + + public static function getBenchmarkFactory() { + if (self::$benchmarkFactory == null) { + $f = new BenchmarkFactory(); + self::$benchmarkFactory = $f; + return $f; + } else { + return self::$benchmarkFactory; + } + } + + public static function getHardwareGroupFactory() { + if (self::$hardwareGroupFactory == null) { + $f = new HardwareGroupFactory(); + self::$hardwareGroupFactory = $f; + return $f; + } else { + return self::$hardwareGroupFactory; + } + } + public static function getConfigSectionFactory() { if (self::$configSectionFactory == null) { diff --git a/src/dba/models/Agent.class.php b/src/dba/models/Agent.class.php index ecd0c5b9d..eb72b0f00 100644 --- a/src/dba/models/Agent.class.php +++ b/src/dba/models/Agent.class.php @@ -7,7 +7,7 @@ class Agent extends AbstractModel { private $agentName; private $uid; private $os; - private $devices; + private $hardwareGroupId; private $cmdPars; private $ignoreErrors; private $isActive; @@ -20,12 +20,12 @@ class Agent extends AbstractModel { private $cpuOnly; private $clientSignature; - function __construct($agentId, $agentName, $uid, $os, $devices, $cmdPars, $ignoreErrors, $isActive, $isTrusted, $token, $lastAct, $lastTime, $lastIp, $userId, $cpuOnly, $clientSignature) { + function __construct($agentId, $agentName, $uid, $os, $hardwareGroupId, $cmdPars, $ignoreErrors, $isActive, $isTrusted, $token, $lastAct, $lastTime, $lastIp, $userId, $cpuOnly, $clientSignature) { $this->agentId = $agentId; $this->agentName = $agentName; $this->uid = $uid; $this->os = $os; - $this->devices = $devices; + $this->hardwareGroupId = $hardwareGroupId; $this->cmdPars = $cmdPars; $this->ignoreErrors = $ignoreErrors; $this->isActive = $isActive; @@ -45,7 +45,7 @@ function getKeyValueDict() { $dict['agentName'] = $this->agentName; $dict['uid'] = $this->uid; $dict['os'] = $this->os; - $dict['devices'] = $this->devices; + $dict['hardwareGroupId'] = $this->hardwareGroupId; $dict['cmdPars'] = $this->cmdPars; $dict['ignoreErrors'] = $this->ignoreErrors; $dict['isActive'] = $this->isActive; @@ -109,12 +109,12 @@ function setOs($os) { $this->os = $os; } - function getDevices() { - return $this->devices; + function getHardwareGroupId() { + return $this->hardwareGroupId; } - function setDevices($devices) { - $this->devices = $devices; + function setHardwareGroupId($hardwareGroupId) { + $this->hardwareGroupId = $hardwareGroupId; } function getCmdPars() { @@ -209,7 +209,7 @@ function setClientSignature($clientSignature) { const AGENT_NAME = "agentName"; const UID = "uid"; const OS = "os"; - const DEVICES = "devices"; + const HARDWARE_GROUP_ID = "hardwareGroupId"; const CMD_PARS = "cmdPars"; const IGNORE_ERRORS = "ignoreErrors"; const IS_ACTIVE = "isActive"; diff --git a/src/dba/models/AgentFactory.class.php b/src/dba/models/AgentFactory.class.php index 3363c2a6a..6a66bd420 100644 --- a/src/dba/models/AgentFactory.class.php +++ b/src/dba/models/AgentFactory.class.php @@ -33,7 +33,7 @@ function getNullObject() { * @return Agent */ function createObjectFromDict($pk, $dict) { - $o = new Agent($dict['agentId'], $dict['agentName'], $dict['uid'], $dict['os'], $dict['devices'], $dict['cmdPars'], $dict['ignoreErrors'], $dict['isActive'], $dict['isTrusted'], $dict['token'], $dict['lastAct'], $dict['lastTime'], $dict['lastIp'], $dict['userId'], $dict['cpuOnly'], $dict['clientSignature']); + $o = new Agent($dict['agentId'], $dict['agentName'], $dict['uid'], $dict['os'], $dict['hardwareGroupId'], $dict['cmdPars'], $dict['ignoreErrors'], $dict['isActive'], $dict['isTrusted'], $dict['token'], $dict['lastAct'], $dict['lastTime'], $dict['lastIp'], $dict['userId'], $dict['cpuOnly'], $dict['clientSignature']); return $o; } diff --git a/src/dba/models/Benchmark.class.php b/src/dba/models/Benchmark.class.php new file mode 100644 index 000000000..74b5f5b01 --- /dev/null +++ b/src/dba/models/Benchmark.class.php @@ -0,0 +1,92 @@ +benchmarkId = $benchmarkId; + $this->benchmarkValue = $benchmarkValue; + $this->attackParameters = $attackParameters; + $this->hardwareGroupId = $hardwareGroupId; + $this->ttl = $ttl; + } + + function getKeyValueDict() { + $dict = array(); + $dict['benchmarkId'] = $this->benchmarkId; + $dict['benchmarkValue'] = $this->benchmarkValue; + $dict['attackParameters'] = $this->attackParameters; + $dict['hardwareGroupId'] = $this->hardwareGroupId; + $dict['ttl'] = $this->ttl; + + return $dict; + } + + function getPrimaryKey() { + return "benchmarkId"; + } + + function getPrimaryKeyValue() { + return $this->benchmarkId; + } + + function getId() { + return $this->benchmarkId; + } + + function setId($benchmarkId) { + $this->benchmarkId = $benchmarkId; + } + + /** + * Used to serialize the data contained in the model + * @return array + */ + public function expose() { + return get_object_vars($this); + } + + function getBenchmarkValue() { + return $this->benchmarkValue; + } + + function setBenchmarkValue($benchmarkValue) { + $this->benchmarkValue = $benchmarkValue; + } + + function getAttackParameters() { + return $this->attackParameters; + } + + function setAttackParameters($attackParameters) { + $this->attackParameters = $attackParameters; + } + + function getHardwareGroupId() { + return $this->hardwareGroupId; + } + + function setHardwareGroupId($hardwareGroupId) { + $this->hardwareGroupId = $hardwareGroupId; + } + + function getTtl() { + return $this->ttl; + } + + function setTtl($ttl) { + $this->ttl = $ttl; + } + + const benchmarkId = "benchmarkId"; + const BENCHMARK_VALUE = "benchmarkValue"; + const ATTACK_PARAMETERS = "attackParameters"; + const HARDWARE_GROUP_benchmarkId = "hardwareGroupId"; + const TTL = "ttl"; +} diff --git a/src/dba/models/BenchmarkFactory.class.php b/src/dba/models/BenchmarkFactory.class.php new file mode 100644 index 000000000..ec8a2b4de --- /dev/null +++ b/src/dba/models/BenchmarkFactory.class.php @@ -0,0 +1,82 @@ +hardwareGroupId = $hardwareGroupId; + $this->devices = $devices; + } + + function getKeyValueDict() { + $dict = array(); + $dict['hardwareGroupId'] = $this->hardwareGroupId; + $dict['devices'] = $this->devices; + + return $dict; + } + + function getPrimaryKey() { + return "hardwareGroupId"; + } + + function getPrimaryKeyValue() { + return $this->hardwareGroupId; + } + + function getId() { + return $this->hardwareGroupId; + } + + function setId($id) { + $this->hardwareGroupId = $id; + } + + /** + * Used to serialize the data contained in the model + * @return array + */ + public function expose() { + return get_object_vars($this); + } + + function getDevices() { + return $this->devices; + } + + function setDevices($devices) { + $this->devices = $devices; + } + + // function getBenchmarkId() { + // return $this->benchmarkId; + // } + + // function setBenchmarkId($benchmarkId) { + // $this->benchmarkId = $benchmarkId; + // } + + const HARDWARE_GROUP_ID = "hardwareGroupId"; + const DEVICES = "devices"; + // const BENCHMARK_ID = "benchmarkId"; +} diff --git a/src/dba/models/HardwareGroupFactory.class.php b/src/dba/models/HardwareGroupFactory.class.php new file mode 100644 index 000000000..3a7370117 --- /dev/null +++ b/src/dba/models/HardwareGroupFactory.class.php @@ -0,0 +1,82 @@ + Date: Thu, 27 Apr 2023 13:27:20 -0400 Subject: [PATCH 03/55] Changed getchunk, sendbenchmark and updateclientinformation API to make use of benchmark caching --- src/inc/api/APIGetChunk.class.php | 12 +++++++++++- src/inc/api/APISendBenchmark.class.php | 10 ++++++++-- src/inc/api/APIUpdateClientInformation.class.php | 7 +++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/inc/api/APIGetChunk.class.php b/src/inc/api/APIGetChunk.class.php index 79af89730..734a7e63e 100644 --- a/src/inc/api/APIGetChunk.class.php +++ b/src/inc/api/APIGetChunk.class.php @@ -40,6 +40,7 @@ public function execute($QUERY = array()) { $qF1 = new QueryFilter(Assignment::AGENT_ID, $this->agent->getId(), "="); $qF2 = new QueryFilter(Assignment::TASK_ID, $task->getId(), "="); $assignment = Factory::getAssignmentFactory()->filter([Factory::FILTER => [$qF1, $qF2]], true); + if ($assignment == null) { DServerLog::log(DServerLog::WARNING, "Requested chunk on task it is not assigned to!", [$this->agent]); $this->sendErrorResponse(PActions::GET_CHUNK, "You are not assigned to this task!"); @@ -54,13 +55,22 @@ public function execute($QUERY = array()) { ); } else if ($assignment->getBenchmark() == 0 && $task->getIsSmall() == 0 && $task->getStaticChunks() == DTaskStaticChunking::NORMAL) { // benchmark only required on non-small tasks and on non-special chunk tasks - DServerLog::log(DServerLog::TRACE, "Need to run a benchmark!", [$this->agent, $task]); + //toegevoegde code voor cache + + $benchmark = BenchmarkUtils::getBenchmarkByValue($task->getAttackCmd(), $this->agent->getHardwareGroupId()); + if ($benchmark === NULL) { + DServerLog::log(DServerLog::INFO, "Need to run a benchmark!", [$this->agent, $task]); $this->sendResponse(array( PResponseGetChunk::ACTION => PActions::GET_CHUNK, PResponseGetChunk::RESPONSE => PValues::SUCCESS, PResponseGetChunk::CHUNK_STATUS => PValuesChunkType::BENCHMARK_REQUIRED ) ); + } else { + DServerLog::log(DServerLog::INFO, "Found benchmark in cache", [$this->agent, $task]); + $assignment->setBenchmark($benchmark->getBenchmarkValue()); + Factory::getAssignmentFactory()->update($assignment); + } } else if ($this->agent->getIsActive() == 0) { DServerLog::log(DServerLog::TRACE, "Agent is inactive!", [$this->agent]); diff --git a/src/inc/api/APISendBenchmark.class.php b/src/inc/api/APISendBenchmark.class.php index f038395f1..7d512bf06 100644 --- a/src/inc/api/APISendBenchmark.class.php +++ b/src/inc/api/APISendBenchmark.class.php @@ -4,7 +4,6 @@ use DBA\Assignment; use DBA\QueryFilter; use DBA\Factory; -use DBA\File; class APISendBenchmark extends APIBasic { public function execute($QUERY = array()) { @@ -75,9 +74,16 @@ public function execute($QUERY = array()) { Factory::getAgentFactory()->set($this->agent, Agent::IS_ACTIVE, 0); $this->sendErrorResponse(PActions::SEND_BENCHMARK, "Invalid benchmark type!"); } - + $assignment->setBenchmark($benchmark); Factory::getAssignmentFactory()->update($assignment); + + //save benchmark in cache + // BenchmarkUtils::saveBenchmarkInCache($task->getAttackCmd() ,$this->agent->getId(), $benchmark); //todo + $hardwareGroup = Factory::getHardwareGroupFactory()->get($this->agent->getHardwareGroupId()); + + BenchmarkUtils::saveBenchmarkInCache($task->getAttackCmd(), $hardwareGroup, $benchmark); //todo + DServerLog::log(DServerLog::DEBUG, "Saved agent benchmark", [$this->agent, $task, $assignment]); $this->sendResponse(array( PResponseSendBenchmark::ACTION => PActions::SEND_BENCHMARK, diff --git a/src/inc/api/APIUpdateClientInformation.class.php b/src/inc/api/APIUpdateClientInformation.class.php index ab1309622..b11580fca 100644 --- a/src/inc/api/APIUpdateClientInformation.class.php +++ b/src/inc/api/APIUpdateClientInformation.class.php @@ -29,13 +29,16 @@ public function execute($QUERY = array()) { // we only update this variable on the first time, otherwise we would overwrite manual changes Factory::getAgentFactory()->set($this->agent, Agent::CPU_ONLY, $cpuOnly); } + Factory::getAgentFactory()->mset($this->agent, [ - Agent::DEVICES => htmlentities(implode("\n", $devices), ENT_QUOTES, "UTF-8"), + //change to hardware group + // Agent::DEVICES => htmlentities(implode("\n", $devices), ENT_QUOTES, "UTF-8"), Agent::UID => $uid, Agent::OS => $os ] ); - + HardwareGroupUtils::updateHardwareOfAgent(htmlentities(implode("\n", $devices), ENT_QUOTES, "UTF-8"), $this->agent); + $this->updateAgent(PActions::UPDATE_CLIENT_INFORMATION); DServerLog::log(DServerLog::DEBUG, "Agent sent updated client information", [$this->agent]); From 174e791484730adf4ea84bece1a9df85d1abca28 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Thu, 27 Apr 2023 13:35:14 -0400 Subject: [PATCH 04/55] Added benchmarkUtils and HardwareGroupUtils --- src/inc/utils/BenchmarkUtils.class.php | 231 +++++++++++++++++++++ src/inc/utils/HardwareGroupUtils.class.php | 37 ++++ 2 files changed, 268 insertions(+) create mode 100644 src/inc/utils/BenchmarkUtils.class.php create mode 100644 src/inc/utils/HardwareGroupUtils.class.php diff --git a/src/inc/utils/BenchmarkUtils.class.php b/src/inc/utils/BenchmarkUtils.class.php new file mode 100644 index 000000000..d04afd8cf --- /dev/null +++ b/src/inc/utils/BenchmarkUtils.class.php @@ -0,0 +1,231 @@ +get($benchmarkId); + if ($benchmark == null) { + throw new HTException("Invalid benchmark ID!"); + } + return $benchmark; + } + + public static function delete($benchmarkId) { + $benchmark = BenchmarkUtils::getBenchmark($benchmarkId); + Factory::getBenchmarkFactory()->delete($benchmark); + } + + static function cleanupAttackParameters2($attackCmd) { + if (strlen($attackCmd) == 0) { + throw new HTException("Attack command cannot be empty!"); + } else if (strlen($attackCmd) > 256) { + throw new HTException("Attack command is too long (max 256 characters)!"); + } + + $parameterParseMap = array(); + $parameterParseMap["-m"] = "--hash-type"; + $parameterParseMap["-a"] = "--attack-mode"; + $parameterParseMap["-S"] = "--slow-candidates"; + $parameterParseMap["-i"] = "--increment"; + + $parts_cmd = preg_split('/\s+/', $attackCmd); + + //arguments will be added in a associative array so that the value of the arguments can be easily extracted + //and the array can be sorted on the keys to get 1 format + $arguments = array(); + + $hashlist = SConfig::getInstance()->getVal(DConfig::HASHLIST_ALIAS); + // $hashlist = "#HL#"; + $attackValue = ""; //this is the dictionary or attack mask + + $i = 0; + $size = sizeof($parts_cmd); + + for ($i = 0;$i < count($parts_cmd);$i++) { + $arg = $parts_cmd[$i]; + if ($arg == $hashlist) { //the hashlist is always #HL# so it doesnt have to be parsed + continue; + } + + if (!str_starts_with($arg, "-")) { //if the argument doesnt start with '-', its the attackvalue which is gonna be appended on the end + $attackValue = $arg; + continue; + } + + if (array_key_exists($arg, $parameterParseMap)) { + $arg = $parameterParseMap[$arg]; + } + + //parse longparameter in style: --remove-timer=30 + if (str_contains($arg, '=')) { + $longParameterSplit = explode('=', $arg); + $arguments[$longParameterSplit[0]] = $longParameterSplit[1]; + continue; + } else if($i <= ($size - 2)) { //if the next character doesnt start with '-' it means that its the value of the parameter + if (!str_starts_with($parts_cmd[$i+1], "-")) { + $arguments[$arg] = $parts_cmd[$i+1]; + $i++; + continue; + } + } + $arguments[$arg] = null; + } + + if (!array_key_exists("--hash-type", $arguments)) { //if --hash-type not in arguments that means hashtype 0 is in use + $arguments["--hash-type"] = "0"; + } + if (!array_key_exists("--attack-mode", $arguments)) { //if --hash-type not in arguments that means hashtype 0 is in use + $arguments["--attack-mode"] = "0"; + } + + ksort($arguments); //sort the arguments by key + + $cleanAttackCmd = ""; + + foreach ($arguments as $key => $value) { + $cleanAttackCmd = $cleanAttackCmd . " " . $key; + if ($value != null) { + $cleanAttackCmd = $cleanAttackCmd . " " . $value; + } + } + + $cleanAttackCmd = $hashlist . $cleanAttackCmd . " " . $attackValue; + + return $cleanAttackCmd; + } + + + static function cleanupAttackParameters($attackCmd) { + + //TODO + if (strlen($attackCmd) == 0) { + throw new HTException("Attack command cannot be empty!"); + } + // else if (strpos($attackCmd, SConfig::getInstance()->getVal(DConfig::HASHLIST_ALIAS)) === false) { + // throw new HTException("Attack command must contain the hashlist alias!"); + // } + // else if (Util::containsBlacklistedChars($attackCmd)) { + // throw new HTException("The attack command must contain no blacklisted characters!");} + else if (strlen($attackCmd) > 256) { + throw new HTException("Attack command is too long (max 256 characters)!"); + } + + $parameterParseMap = array(); + $parameterParseMap["-m"] = "--hash-type"; + $parameterParseMap["-a"] = "--attack-mode"; + $parameterParseMap["-S"] = "--slow-candidates"; + $parameterParseMap["-i"] = "--increment"; + + $parts_cmd = explode(" ", $attackCmd); + + $arguments = array(); + + $i = 0; + $size = sizeof($parts_cmd); + + for ($i = 0;$i < count($parts_cmd);$i++) { + $arg = $parts_cmd[$i]; + if (array_key_exists($arg, $parameterParseMap)) { + $arg = $parameterParseMap[$arg]; + } + + if($i <= ($size - 2)) { //if the next character doesnt start with '-' it means that its the value of the parameter + if (str_starts_with($parts_cmd[$i+1], "-")) { + $arguments[$arg] = $parts_cmd[$i+1]; + $i++; + continue; + } + + array_push($arguments, $arg); + } + + return $attackCmd; + } +} + + public static function getBenchmarkByValue($attackParameters, $hardwareGroupId) { + $hardwareGroup = Factory::getHardwareGroupFactory()->get($hardwareGroupId); + + if (!isset($hardwareGroup)) { + return null; + } + + $cleanAttackParameter = self::cleanupAttackParameters($attackParameters); + + $qF = new QueryFilter("attackParameters", $cleanAttackParameter, "="); + $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroup->getId(), "="); + + $res = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2]], true); + + if(isset($res)){ + if ($res->getTtl() < time()) { // if ttl has been exceeded, remove value and return null + + Factory::getBenchmarkFactory()->delete($res); + return null; + } + } + + return $res; + } + + public static function deleteBenchmark($benchmark) { + Factory::getBenchmarkFactory()->delete($benchmark); + return true; + } + + public static function saveBenchmarkInCache($attackParameters, $hardwareGroup, $benchmarkValue) { + $cleanAttackParameters = self::cleanupAttackParameters2($attackParameters); + + $qF = new QueryFilter("attackParameters", $cleanAttackParameters, "="); + $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroup->getId(), "="); + + $foundBenchmark = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2],Factory::getHardwareGroupFactory()], true); + + if (isset($foundBenchmark)) { //if benchmark already in cache, update the value + $foundBenchmark->setTtl(time() + ttl); + $foundBenchmark->setBenchmarkValue($benchmarkValue); + $benchmark = Factory::getBenchmarkFactory()->update($foundBenchmark); + } else { + $newBenchmark = new Benchmark(null, $benchmarkValue, $cleanAttackParameters, $hardwareGroup->getID(), time() + ttl); + $benchmark = Factory::getBenchmarkFactory()->save($newBenchmark); + } + + return $benchmark; + + } + +//removes all values where the time to live has been exceeded +public static function refreshCache() { + $qF = new QueryFilter("ttl", time(), "<"); + Factory::getFileTaskFactory()->massDeletion([Factory::FILTER => $qF]); + +} + +//removes all values in cache +public static function deleteCache() { + Factory::getBenchmarkFactory()->massDeletion([]); +} + +public static function getCacheOfAgent($agentID) { + $qF = new QueryFilter("agentID", $agentID, "="); + $oF = new OrderFilter(ttl, "DESC"); + + $benchmarks = Factory::getBenchmarkFactory()->filter([Factory::FILTER => $qF, Factory::ORDER => $oF]); + return $benchmarks; +} +} + +?> \ No newline at end of file diff --git a/src/inc/utils/HardwareGroupUtils.class.php b/src/inc/utils/HardwareGroupUtils.class.php new file mode 100644 index 000000000..258f6ef2b --- /dev/null +++ b/src/inc/utils/HardwareGroupUtils.class.php @@ -0,0 +1,37 @@ +filter([Factory::FILTER => [$qF]], true); + + if(isset($res)) { + Factory::getAgentFactory()->set($agent, Agent::HARDWARE_GROUP_ID, $res->getId()); + } else { + //nieuwe hardware group maken en id bij agent zetten + $newHardwareGroup = new HardwareGroup(null, $devices); + $savedHardwareGroup = Factory::getHardwareGroupFactory()->save($newHardwareGroup); + + Factory::getAgentFactory()->set($agent, Agent::HARDWARE_GROUP_ID, $savedHardwareGroup->getId()); + } +} + +public static function getDevicesFromBenchmark($benchmark) { + $qF = new QueryFilter("HardwareGroupId", $benchmark->getHardwareGroupId(), "="); + $res = Factory::getHardwareGroupFactory()->filter([Factory::FILTER => [$qF]], true); + return $res->getDevices(); +} + +public static function getHardwareGroupByDevices($devices) { + $qF = new QueryFilter("devices", $devices, "="); + $res = Factory::getHardwareGroupFactory()->filter([Factory::FILTER => [$qF]], true); + + return $res; +} +} \ No newline at end of file From 57483afd4ab3fe111a303e2d324403aa3b731680 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Thu, 27 Apr 2023 13:39:34 -0400 Subject: [PATCH 05/55] Changed Agent templates to use hardwareGroups --- src/agents.php | 11 +++++++---- src/templates/agents/detail.template.html | 2 +- src/templates/agents/index.template.html | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/agents.php b/src/agents.php index c501b4605..7e9a1e452 100755 --- a/src/agents.php +++ b/src/agents.php @@ -56,6 +56,7 @@ //show agent detail Template::loadInstance("agents/detail"); $agent = Factory::getAgentFactory()->get($_GET['id']); + $hardwareGroup = Factory::getHardwareGroupFactory()->get($agent->getHardwareGroupId()); if (!$agent) { UI::printError("ERROR", "Agent not found!"); } @@ -64,12 +65,12 @@ } else { // uniq devices lines and prepend with count - $tmp_devices_tuple = array_count_values(explode("\n", $agent->getDevices())); + $tmp_devices_tuple = array_count_values(explode("\n", $hardwareGroup->getDevices())); $devices_tuple = array(); foreach ($tmp_devices_tuple as $key => $value) { $devices_tuple[] = str_replace("*", "  ", sprintf("%'*2d× ", $value) . $key); } - $agent->setDevices(implode("\n", $devices_tuple)); + $hardwareGroup->setDevices(implode("\n", $devices_tuple)); UI::add('agent', $agent); UI::add('users', Factory::getUserFactory()->filter([])); @@ -158,12 +159,14 @@ $joined = Factory::getAccessGroupFactory()->filter([Factory::FILTER => $qF, Factory::JOIN => $jF]); $accessGroupAgents->addValue($agent->getId(), $joined[Factory::getAccessGroupFactory()->getModelName()]); // uniq devices lines and prepend with count - $tmp_devices_tuple = array_count_values(explode("\n", $agent->getDevices())); + $hardwareGroup = Factory::getHardwareGroupFactory()->get($agent->getHardwareGroupId()); + + $tmp_devices_tuple = array_count_values(explode("\n", $hardwareGroup->getDevices())); $devices_tuple = array(); foreach ($tmp_devices_tuple as $key => $value) { $devices_tuple[] = str_replace("*", "  ", sprintf("%'*2d× ", $value) . $key); } - $agent->setDevices(implode("\n", $devices_tuple)); + $agent->setHardwareGroupId(implode("\n", $devices_tuple)); } UI::add('accessGroupAgents', $accessGroupAgents); diff --git a/src/templates/agents/detail.template.html b/src/templates/agents/detail.template.html index c37c39728..ba036d301 100644 --- a/src/templates/agents/detail.template.html +++ b/src/templates/agents/detail.template.html @@ -126,7 +126,7 @@

Agent details

Graphic cards: - [[str_replace("\n","
",[[agent.getDevices()]])]] + [[str_replace("\n","
",[[hardwareGroup.getDevices()]])]] Member of access groups: diff --git a/src/templates/agents/index.template.html b/src/templates/agents/index.template.html index a82933a0a..0c8ac84eb 100755 --- a/src/templates/agents/index.template.html +++ b/src/templates/agents/index.template.html @@ -50,7 +50,7 @@

Agents ([[numAgents]])

{{ENDIF}} - [[str_replace("\n","
",[[agent.getDevices()]])]] + [[str_replace("\n","
",[[agent.getHardwareGroupId()]])]] {{IF [[agent.getCpuOnly()]] == 0}} From 6f5374789091dac6575682c6dbb07ebd92e4182b Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Thu, 27 Apr 2023 13:51:43 -0400 Subject: [PATCH 06/55] Added frontend to view the cached benchmarks --- src/benchmark.php | 49 ++++++++++++++++ src/inc/defines/accessControl.php | 7 +++ src/inc/defines/benchmarks.php | 8 +++ src/inc/handlers/BenchmarkHandler.class.php | 37 ++++++++++++ src/templates/benchmarks/detail.template.html | 56 +++++++++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 src/benchmark.php create mode 100644 src/inc/defines/benchmarks.php create mode 100644 src/inc/handlers/BenchmarkHandler.class.php create mode 100644 src/templates/benchmarks/detail.template.html diff --git a/src/benchmark.php b/src/benchmark.php new file mode 100644 index 000000000..d3826b4f0 --- /dev/null +++ b/src/benchmark.php @@ -0,0 +1,49 @@ +isLoggedin()) { + header("Location: index.php?err=4" . time() . "&fw=" . urlencode($_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'])); + die(); +} + +Template::loadInstance("benchmarks/index"); + +AccessControl::getInstance()->checkPermission(DViewControl::AGENTS_VIEW_PERM); + +if (isset($_POST['action']) && CSRF::check($_POST['csrf'])) { + $benchmarkHandler = new BenchmarkHandler(); + $benchmarkHandler->handle($_POST['action']); + if (UI::getNumMessages() == 0) { + Util::refresh(); + } +} + +if (isset($_GET['id'])) { + //go to detail page + // Template::loadInstance("benchmark/detail"); + $agent = Factory::getAgentFactory()->get($_GET['id']); + if (!$agent) { + UI::printError("ERROR", "Agent not found!"); + } else { + $qF = new QueryFilter("agentId", $agent->getId(), "="); + $benchmarks = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF]]); + } +} else { + $benchmarks = Factory::getBenchmarkFactory()->filter([]); +} + +foreach ($benchmarks as $benchmark) { + $devices = HardwareGroupUtils::getDevicesFromBenchmark($benchmark); + $benchmark->setHardwareGroupId($devices); +} + + +UI::add('benchmarks', $benchmarks); +UI::add('numBenchmarks', sizeof($benchmarks)); + +echo Template::getInstance()->render(UI::getObjects()); + +?> \ No newline at end of file diff --git a/src/inc/defines/accessControl.php b/src/inc/defines/accessControl.php index f910e7a6a..c4ebe0445 100644 --- a/src/inc/defines/accessControl.php +++ b/src/inc/defines/accessControl.php @@ -26,6 +26,8 @@ class DAccessControl { const SERVER_CONFIG_ACCESS = "serverConfigAccess"; const USER_CONFIG_ACCESS = "userConfigAccess"; const MANAGE_ACCESS_GROUP_ACCESS = "manageAccessGroupAccess"; + const VIEW_BENCHMARK_ACCESS = "ViewBenchmarkAccess"; + const DELETE_BENCHMARK_ACCESS = "DeleteBenchmarkAccess"; // special access definitions for public access pages and pages which are viewable if logged in const PUBLIC_ACCESS = "publicAccess"; @@ -102,6 +104,11 @@ public static function getDescription($access) { return "Can manage preconfigured supertasks."; case DAccessControl::MANAGE_ACCESS_GROUP_ACCESS: return "Can manage access groups."; + case DAccessControl::VIEW_BENCHMARK_ACCESS: + return "Can view the cached benchmarks"; + case DAccessControl::DELETE_BENCHMARK_ACCESS: + return "Can delete the cached benchmarks"; + } return "__" . $access . "__"; } diff --git a/src/inc/defines/benchmarks.php b/src/inc/defines/benchmarks.php new file mode 100644 index 000000000..ff95953dd --- /dev/null +++ b/src/inc/defines/benchmarks.php @@ -0,0 +1,8 @@ +agent = null; + return; + } + + $this->agent = Factory::getAgentFactory()->get($agentId); + if ($this->agent == null) { + UI::printError("FATAL", "Agent with ID $agentId not found!"); + } + } + + public function handle($action) { + try { + switch ($action) { + case DBenchmarkAction::DELETE_BENCHMARK: + AccessControl::getInstance()->checkPermission(DBenchmarkAction::DELETE_BENCHMARK); + $benchId = $_POST['benchmarkId']; + BenchmarkUtils::delete($_POST['benchmarkId']); + break; + default: + UI::addMessage(UI::ERROR, "Invalid action!"); + break; + } + } + catch (HTException $e) { + UI::addMessage(UI::ERROR, $e->getMessage()); + } + } +} \ No newline at end of file diff --git a/src/templates/benchmarks/detail.template.html b/src/templates/benchmarks/detail.template.html new file mode 100644 index 000000000..9791bed27 --- /dev/null +++ b/src/templates/benchmarks/detail.template.html @@ -0,0 +1,56 @@ +{%TEMPLATE->struct/head%} +{%TEMPLATE->struct/menu%} +

Benchmarks ([[numBenchmarks]])

+{%TEMPLATE->struct/messages%} +
+
+ + + + + + + + + + + + + {{FOREACH benchmark;[[benchmarks]]}} + + + + + + + {{IF [[accessControl.hasPermission([[$DAccessControl::DELETE_BENCHMARK_ACCESS]])]]}} + + {{ELSE}} + + {{ENDIF}} + + {{ENDFOREACH}} + +
Benchmark idBenchmark CmdCPU/GPUBenchmark valuettlaction
[[benchmark.getId()]][[benchmark.getAttackParameters()]][[str_replace("\n","
",[[benchmark.getHardwareGroupId()]])]]
[[benchmark.getBenchmarkValue()]][[date([[config.getVal(DConfig::TIME_FORMAT)]], [[benchmark.getTtl()]])]] +
+ + + + +
+
 
+ +
+
+{%TEMPLATE->struct/foot%} \ No newline at end of file From 75cedf48cf0bbe805fd9883e772022511097e122 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Wed, 3 May 2023 08:43:12 -0400 Subject: [PATCH 07/55] fixed bug in benchmarkUtils --- src/inc/utils/BenchmarkUtils.class.php | 55 ++------------------------ 1 file changed, 4 insertions(+), 51 deletions(-) diff --git a/src/inc/utils/BenchmarkUtils.class.php b/src/inc/utils/BenchmarkUtils.class.php index d04afd8cf..be05c761b 100644 --- a/src/inc/utils/BenchmarkUtils.class.php +++ b/src/inc/utils/BenchmarkUtils.class.php @@ -29,6 +29,8 @@ public static function delete($benchmarkId) { } static function cleanupAttackParameters2($attackCmd) { + $attackCmd = trim($attackCmd); + if (strlen($attackCmd) == 0) { throw new HTException("Attack command cannot be empty!"); } else if (strlen($attackCmd) > 256) { @@ -107,55 +109,6 @@ static function cleanupAttackParameters2($attackCmd) { return $cleanAttackCmd; } - - static function cleanupAttackParameters($attackCmd) { - - //TODO - if (strlen($attackCmd) == 0) { - throw new HTException("Attack command cannot be empty!"); - } - // else if (strpos($attackCmd, SConfig::getInstance()->getVal(DConfig::HASHLIST_ALIAS)) === false) { - // throw new HTException("Attack command must contain the hashlist alias!"); - // } - // else if (Util::containsBlacklistedChars($attackCmd)) { - // throw new HTException("The attack command must contain no blacklisted characters!");} - else if (strlen($attackCmd) > 256) { - throw new HTException("Attack command is too long (max 256 characters)!"); - } - - $parameterParseMap = array(); - $parameterParseMap["-m"] = "--hash-type"; - $parameterParseMap["-a"] = "--attack-mode"; - $parameterParseMap["-S"] = "--slow-candidates"; - $parameterParseMap["-i"] = "--increment"; - - $parts_cmd = explode(" ", $attackCmd); - - $arguments = array(); - - $i = 0; - $size = sizeof($parts_cmd); - - for ($i = 0;$i < count($parts_cmd);$i++) { - $arg = $parts_cmd[$i]; - if (array_key_exists($arg, $parameterParseMap)) { - $arg = $parameterParseMap[$arg]; - } - - if($i <= ($size - 2)) { //if the next character doesnt start with '-' it means that its the value of the parameter - if (str_starts_with($parts_cmd[$i+1], "-")) { - $arguments[$arg] = $parts_cmd[$i+1]; - $i++; - continue; - } - - array_push($arguments, $arg); - } - - return $attackCmd; - } -} - public static function getBenchmarkByValue($attackParameters, $hardwareGroupId) { $hardwareGroup = Factory::getHardwareGroupFactory()->get($hardwareGroupId); @@ -163,7 +116,7 @@ public static function getBenchmarkByValue($attackParameters, $hardwareGroupId) return null; } - $cleanAttackParameter = self::cleanupAttackParameters($attackParameters); + $cleanAttackParameter = self::cleanupAttackParameters2($attackParameters); $qF = new QueryFilter("attackParameters", $cleanAttackParameter, "="); $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroup->getId(), "="); @@ -192,7 +145,7 @@ public static function saveBenchmarkInCache($attackParameters, $hardwareGroup, $ $qF = new QueryFilter("attackParameters", $cleanAttackParameters, "="); $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroup->getId(), "="); - $foundBenchmark = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2],Factory::getHardwareGroupFactory()], true); + $foundBenchmark = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2]], true); if (isset($foundBenchmark)) { //if benchmark already in cache, update the value $foundBenchmark->setTtl(time() + ttl); From a5cf43033f7efe58a424de28c19e93e0b23abded Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Mon, 8 May 2023 06:04:45 -0400 Subject: [PATCH 08/55] fixed bug in registerAgent, wasnt updated to hardwaregroup --- src/inc/api/APIRegisterAgent.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inc/api/APIRegisterAgent.class.php b/src/inc/api/APIRegisterAgent.class.php index bd2a1098a..084a66ca9 100644 --- a/src/inc/api/APIRegisterAgent.class.php +++ b/src/inc/api/APIRegisterAgent.class.php @@ -28,7 +28,7 @@ public function execute($QUERY = array()) { //create access token & save agent details $token = Util::randomString(10); - $agent = new Agent(null, $name, "", -1, "", "", 0, 1, 0, $token, PActions::REGISTER, time(), Util::getIP(), null, $cpuOnly, ""); + $agent = new Agent(null, $name, "", -1, 0, "", 0, 1, 0, $token, PActions::REGISTER, time(), Util::getIP(), null, $cpuOnly, ""); if (SConfig::getInstance()->getVal(DConfig::VOUCHER_DELETION) == 0) { Factory::getRegVoucherFactory()->delete($voucher); From 0c3f5613b6943df616b1b180c497bc21207b252b Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Wed, 5 Jul 2023 06:39:57 -0400 Subject: [PATCH 09/55] updated install/hashtopolis.sql for benchmark cache --- src/install/hashtopolis.sql | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index a2d1dacdb..0981d5ac5 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -911,6 +911,19 @@ CREATE TABLE `User` ( `otp4` VARCHAR(256) DEFAULT NULL ) ENGINE = InnoDB; +CREATE TABLE `Benchmark` ( + `benchmarkId` INT(11) NOT NULL, + `benchmarkValue` VARCHAR(256) NOT NULL, + `hardwareGroupId` int(11) NOT NULL, + `attackParameters` VARCHAR(256) NOT NULL, + `ttl` int(11) NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE `HardwareGroup` ( + `hardwareGroupId` INT(11) NOT NULL, + `devices` VARCHAR(256) NOT NULL, +) ENGINE = InnoDB; + CREATE TABLE `Zap` ( `zapId` INT(11) NOT NULL, `hash` MEDIUMTEXT NOT NULL, @@ -1156,6 +1169,13 @@ ALTER TABLE `Zap` ALTER TABLE `Preprocessor` ADD PRIMARY KEY (`preprocessorId`); +ALTER TABLE `Benchmark` + ADD PRIMARY KEY (`benchmarkId`), + ADD KEY `agentId` (`agentId`); + +ALTER TABLE `HardwareGroup` + ADD PRIMARY KEY (`hardwareGroupId`); + -- Add AUTO_INCREMENT for tables ALTER TABLE `AccessGroup` MODIFY `accessGroupId` INT(11) NOT NULL AUTO_INCREMENT; @@ -1289,6 +1309,12 @@ ALTER TABLE `Zap` ALTER TABLE `Preprocessor` MODIFY `preprocessorId` INT(11) NOT NULL AUTO_INCREMENT; +ALTER TABLE `Benchmark` + MODIFY `benchmarkId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `HardwareGroup` + MODIFY `hardwareGroupId` INT(11) NOT NULL AUTO_INCREMENT; + -- Add Constraints ALTER TABLE `AccessGroupAgent` ADD CONSTRAINT `AccessGroupAgent_ibfk_1` FOREIGN KEY (`accessGroupId`) REFERENCES `AccessGroup` (`accessGroupId`), @@ -1399,6 +1425,9 @@ ALTER TABLE `TaskWrapper` ALTER TABLE `User` ADD CONSTRAINT `User_ibfk_1` FOREIGN KEY (`rightGroupId`) REFERENCES `RightGroup` (`rightGroupId`); +ALTER TABLE `Benchmark` + ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`HardwareGroupId`) REFERENCES `Agent` (`hardwareGroupId`); + ALTER TABLE `Zap` ADD CONSTRAINT `Zap_ibfk_1` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`), ADD CONSTRAINT `Zap_ibfk_2` FOREIGN KEY (`hashlistId`) REFERENCES `Hashlist` (`hashlistId`); From 0c2509b4095e398d8d8125a18b3b149015472477 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Wed, 5 Jul 2023 07:27:47 -0400 Subject: [PATCH 10/55] Added update script for database update --- .../updates/update_v0.14.x_v0.14.0.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/install/updates/update_v0.14.x_v0.14.0.php diff --git a/src/install/updates/update_v0.14.x_v0.14.0.php b/src/install/updates/update_v0.14.x_v0.14.0.php new file mode 100644 index 000000000..93da769dd --- /dev/null +++ b/src/install/updates/update_v0.14.x_v0.14.0.php @@ -0,0 +1,38 @@ +getDB()->query("CREATE TABLE `HardwareGroup` ( + `hardwareGroupId` INT(11) NOT NULL, + `devices` VARCHAR(65000) NOT NULL, + ) ENGINE=InnoDB;" + ); + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` MODIFY `hardwareGroupId` int(11) NOT NULL AUTO_INCREMENT"); +} + +//change Agent table +Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` + DROP COLUMN devices; +"); +Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` + ADD COLUMN hardwareGroupId INT(11); +"); +Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); + + +if (!Util::databaseTableExists("Benchmark")) { + Factory::getAgentFactory()->getDB()->query("CREATE TABLE `Benchmark` ( + `benchmarkId` INT(11) NOT NULL, + `benchmarkValue` VARCHAR(256) NOT NULL, + `hardwareGroupId` INT(11) NOT NULL, + `attackParameters` VARCHAR(256) NOT NULL, + `ttl` INT(11) NULL, + `hashMode` INT(11) NULL, + `benchmarkType` VARCHAR(10) NULL, + ) ENGINE=InnoDB;" + ); + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` MODIFY `benchmarkId` int(11) NOT NULL AUTO_INCREMENT"); +} +Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` ADD CONSTRAINT FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); + +?> \ No newline at end of file From e06fb1ffaeb4fe4d8a170dda60f300b00fd84b94 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Wed, 5 Jul 2023 11:09:23 -0400 Subject: [PATCH 11/55] Fixed errors in hashtopolis.sql file --- src/install/hashtopolis.sql | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index 0981d5ac5..ae25a5309 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -30,7 +30,7 @@ CREATE TABLE `Agent` ( `agentName` VARCHAR(100) NOT NULL, `uid` VARCHAR(100) NOT NULL, `os` INT(11) NOT NULL, - `devices` TEXT NOT NULL, + `hardwareGroupId` INT(11) NOT NULL, `cmdPars` VARCHAR(256) NOT NULL, `ignoreErrors` TINYINT(4) NOT NULL, `isActive` TINYINT(4) NOT NULL, @@ -914,7 +914,7 @@ CREATE TABLE `User` ( CREATE TABLE `Benchmark` ( `benchmarkId` INT(11) NOT NULL, `benchmarkValue` VARCHAR(256) NOT NULL, - `hardwareGroupId` int(11) NOT NULL, + `hardwareGroupId` INT(11) NOT NULL, `attackParameters` VARCHAR(256) NOT NULL, `ttl` int(11) NOT NULL ) ENGINE = InnoDB; @@ -1011,6 +1011,7 @@ ALTER TABLE `AccessGroupUser` ALTER TABLE `Agent` ADD PRIMARY KEY (`agentId`), ADD KEY `userId` (`userId`); + ADD KEY `hardwareGroupId` (`hardwareGroupId`); ALTER TABLE `AgentBinary` ADD PRIMARY KEY (`agentBinaryId`); @@ -1172,6 +1173,7 @@ ALTER TABLE `Preprocessor` ALTER TABLE `Benchmark` ADD PRIMARY KEY (`benchmarkId`), ADD KEY `agentId` (`agentId`); + ADD KEY `hardwareGroupId` (`hardwareGroupId`); ALTER TABLE `HardwareGroup` ADD PRIMARY KEY (`hardwareGroupId`); @@ -1326,6 +1328,8 @@ ALTER TABLE `AccessGroupUser` ALTER TABLE `Agent` ADD CONSTRAINT `Agent_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`); + ADD CONSTRAINT `Agent_ibfk_2` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`); + ALTER TABLE `AgentError` ADD CONSTRAINT `AgentError_ibfk_1` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`), @@ -1426,7 +1430,7 @@ ALTER TABLE `User` ADD CONSTRAINT `User_ibfk_1` FOREIGN KEY (`rightGroupId`) REFERENCES `RightGroup` (`rightGroupId`); ALTER TABLE `Benchmark` - ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`HardwareGroupId`) REFERENCES `Agent` (`hardwareGroupId`); + ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`); ALTER TABLE `Zap` ADD CONSTRAINT `Zap_ibfk_1` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`), From f01d7902c86e6fd2334acdeb6f6fbc12c8ddcb1f Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Fri, 7 Jul 2023 07:41:51 -0400 Subject: [PATCH 12/55] fixed bug in hashtopolis.sql --- src/install/hashtopolis.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index ae25a5309..bf30fa05a 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -921,7 +921,7 @@ CREATE TABLE `Benchmark` ( CREATE TABLE `HardwareGroup` ( `hardwareGroupId` INT(11) NOT NULL, - `devices` VARCHAR(256) NOT NULL, + `devices` VARCHAR(256) NOT NULL ) ENGINE = InnoDB; CREATE TABLE `Zap` ( From 3a2d0db3358fc9d465800dec9e912a3ff9aa849b Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Fri, 7 Jul 2023 08:04:12 -0400 Subject: [PATCH 13/55] fixed bug in hashtopolis.sql again --- src/install/hashtopolis.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index bf30fa05a..110821348 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -915,13 +915,13 @@ CREATE TABLE `Benchmark` ( `benchmarkId` INT(11) NOT NULL, `benchmarkValue` VARCHAR(256) NOT NULL, `hardwareGroupId` INT(11) NOT NULL, - `attackParameters` VARCHAR(256) NOT NULL, + `attackParameters` VARCHAR(512) NOT NULL, `ttl` int(11) NOT NULL ) ENGINE = InnoDB; CREATE TABLE `HardwareGroup` ( `hardwareGroupId` INT(11) NOT NULL, - `devices` VARCHAR(256) NOT NULL + `devices` VARCHAR(65000) NULL ) ENGINE = InnoDB; CREATE TABLE `Zap` ( @@ -1172,7 +1172,7 @@ ALTER TABLE `Preprocessor` ALTER TABLE `Benchmark` ADD PRIMARY KEY (`benchmarkId`), - ADD KEY `agentId` (`agentId`); + ADD KEY `agentId` (`agentId`), ADD KEY `hardwareGroupId` (`hardwareGroupId`); ALTER TABLE `HardwareGroup` From 588e1ea6e0aa06443c556b6adb5033458cb964a8 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Fri, 7 Jul 2023 11:32:51 -0400 Subject: [PATCH 14/55] fixed bug in hashtopolis.sql, again --- src/install/hashtopolis.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index 110821348..141948f40 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -1010,7 +1010,7 @@ ALTER TABLE `AccessGroupUser` ALTER TABLE `Agent` ADD PRIMARY KEY (`agentId`), - ADD KEY `userId` (`userId`); + ADD KEY `userId` (`userId`), ADD KEY `hardwareGroupId` (`hardwareGroupId`); ALTER TABLE `AgentBinary` From 6049f5025baf6fe8221e4001c6a9d1e5a5e1aa0c Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Fri, 7 Jul 2023 11:43:46 -0400 Subject: [PATCH 15/55] fixed another bug in hashtopolis.sql, again --- src/install/hashtopolis.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index 141948f40..cd2ba9b0d 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -1008,6 +1008,9 @@ ALTER TABLE `AccessGroupUser` ADD KEY `accessGroupId` (`accessGroupId`), ADD KEY `userId` (`userId`); +ALTER TABLE `HardwareGroup` + ADD PRIMARY KEY (`hardwareGroupId`); + ALTER TABLE `Agent` ADD PRIMARY KEY (`agentId`), ADD KEY `userId` (`userId`), @@ -1172,7 +1175,6 @@ ALTER TABLE `Preprocessor` ALTER TABLE `Benchmark` ADD PRIMARY KEY (`benchmarkId`), - ADD KEY `agentId` (`agentId`), ADD KEY `hardwareGroupId` (`hardwareGroupId`); ALTER TABLE `HardwareGroup` From 468a50b505c97ce04dbae212d54d85eba5a2daab Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Fri, 7 Jul 2023 11:51:03 -0400 Subject: [PATCH 16/55] added hashmode and benchmarktype to Benchmark object in hashtopolis.sql --- src/install/hashtopolis.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index cd2ba9b0d..0a9ed0262 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -916,7 +916,9 @@ CREATE TABLE `Benchmark` ( `benchmarkValue` VARCHAR(256) NOT NULL, `hardwareGroupId` INT(11) NOT NULL, `attackParameters` VARCHAR(512) NOT NULL, - `ttl` int(11) NOT NULL + `ttl` int(11) NOT NULL, + `hashMode` int(11) NOT NULL, + `benchmarkType` varchar(10) NOT NULL, ) ENGINE = InnoDB; CREATE TABLE `HardwareGroup` ( From bd7043e52b24da2e4cc4b2e9938f4929b2f27823 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Sun, 9 Jul 2023 06:59:31 -0400 Subject: [PATCH 17/55] fixed bug in hashtopolis.sql, creat table benchmark didnt work --- src/install/hashtopolis.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index 0a9ed0262..fcc06e701 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -918,7 +918,7 @@ CREATE TABLE `Benchmark` ( `attackParameters` VARCHAR(512) NOT NULL, `ttl` int(11) NOT NULL, `hashMode` int(11) NOT NULL, - `benchmarkType` varchar(10) NOT NULL, + `benchmarkType` varchar(10) NOT NULL ) ENGINE = InnoDB; CREATE TABLE `HardwareGroup` ( From a1e8b7bdd433f578f976e4f96a5efa6f0c88e72b Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Sun, 9 Jul 2023 12:09:14 -0400 Subject: [PATCH 18/55] updated the update script --- .../updates/update_v0.14.x_v0.14.0.php | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/install/updates/update_v0.14.x_v0.14.0.php b/src/install/updates/update_v0.14.x_v0.14.0.php index 93da769dd..b87a87915 100644 --- a/src/install/updates/update_v0.14.x_v0.14.0.php +++ b/src/install/updates/update_v0.14.x_v0.14.0.php @@ -4,10 +4,11 @@ if (!Util::databaseTableExists("HardwareGroup")) { Factory::getAgentFactory()->getDB()->query("CREATE TABLE `HardwareGroup` ( `hardwareGroupId` INT(11) NOT NULL, - `devices` VARCHAR(65000) NOT NULL, + `devices` VARCHAR(65000) NOT NULL ) ENGINE=InnoDB;" ); - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` MODIFY `hardwareGroupId` int(11) NOT NULL AUTO_INCREMENT"); + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` MODIFY `hardwareGroupId` int(11) NOT NULL AUTO_INCREMENT;"); + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` ADD PRIMARY KEY (`hardwareGroupId`);"); } //change Agent table @@ -25,14 +26,27 @@ `benchmarkId` INT(11) NOT NULL, `benchmarkValue` VARCHAR(256) NOT NULL, `hardwareGroupId` INT(11) NOT NULL, - `attackParameters` VARCHAR(256) NOT NULL, + `attackParameters` VARCHAR(512) NOT NULL, `ttl` INT(11) NULL, `hashMode` INT(11) NULL, - `benchmarkType` VARCHAR(10) NULL, + `benchmarkType` VARCHAR(10) NULL ) ENGINE=InnoDB;" ); - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` MODIFY `benchmarkId` int(11) NOT NULL AUTO_INCREMENT"); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` MODIFY `benchmarkId` int(11) NOT NULL AUTO_INCREMENT;"); + + Factory::getAgentFactory()->getDB()->query(" + ALTER TABLE `Benchmark` + ADD PRIMARY KEY (`benchmarkId`), + ADD KEY `hardwareGroupId` (`hardwareGroupId`);"); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` + ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); } -Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` ADD CONSTRAINT FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); + +Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT `Agent_ibfk_2` + FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); +Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` ADD CONSTRAINT `Benchmark_ibfk_1` + FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); ?> \ No newline at end of file From df1f34c6be488a02ebab875903913119101098b3 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Sun, 9 Jul 2023 13:07:22 -0400 Subject: [PATCH 19/55] fixed bug in hashtopolis.sql, defined hardwareGroup primary key twice --- src/install/hashtopolis.sql | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index fcc06e701..2e089b9d6 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -1179,9 +1179,6 @@ ALTER TABLE `Benchmark` ADD PRIMARY KEY (`benchmarkId`), ADD KEY `hardwareGroupId` (`hardwareGroupId`); -ALTER TABLE `HardwareGroup` - ADD PRIMARY KEY (`hardwareGroupId`); - -- Add AUTO_INCREMENT for tables ALTER TABLE `AccessGroup` MODIFY `accessGroupId` INT(11) NOT NULL AUTO_INCREMENT; From 99d9aecb1aca622169a6fffc3fb59fe65dd1acc2 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Sun, 9 Jul 2023 13:25:33 -0400 Subject: [PATCH 20/55] fixed typo in hashtopolis.sql --- src/install/hashtopolis.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index 2e089b9d6..22a7ec7da 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -1328,8 +1328,8 @@ ALTER TABLE `AccessGroupUser` ADD CONSTRAINT `AccessGroupUser_ibfk_2` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`); ALTER TABLE `Agent` - ADD CONSTRAINT `Agent_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`); - ADD CONSTRAINT `Agent_ibfk_2` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`); + ADD CONSTRAINT `Agent_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`), + ADD CONSTRAINT `Agent_ibfk_2` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`); ALTER TABLE `AgentError` From 31991fdcf7e7faa25197fb6602e6217f159e6c97 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Mon, 10 Jul 2023 04:54:27 -0400 Subject: [PATCH 21/55] Made hardwareGroupId in agent table nullable --- src/install/hashtopolis.sql | 2 +- src/install/updates/update_v0.14.x_v0.14.0.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index 22a7ec7da..2d1aab38b 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -30,7 +30,7 @@ CREATE TABLE `Agent` ( `agentName` VARCHAR(100) NOT NULL, `uid` VARCHAR(100) NOT NULL, `os` INT(11) NOT NULL, - `hardwareGroupId` INT(11) NOT NULL, + `hardwareGroupId` INT(11) DEFAULT NULL, `cmdPars` VARCHAR(256) NOT NULL, `ignoreErrors` TINYINT(4) NOT NULL, `isActive` TINYINT(4) NOT NULL, diff --git a/src/install/updates/update_v0.14.x_v0.14.0.php b/src/install/updates/update_v0.14.x_v0.14.0.php index b87a87915..94cce19e5 100644 --- a/src/install/updates/update_v0.14.x_v0.14.0.php +++ b/src/install/updates/update_v0.14.x_v0.14.0.php @@ -16,7 +16,7 @@ DROP COLUMN devices; "); Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` - ADD COLUMN hardwareGroupId INT(11); + ADD COLUMN hardwareGroupId INT(11) DEFAULT NULL; "); Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); From 19c9f4c4a62d55167bd80606a58e550d576cb05b Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Mon, 10 Jul 2023 06:52:27 -0400 Subject: [PATCH 22/55] updated cache code to latest version --- src/dba/models/Benchmark.class.php | 34 +++++++++++++++++++---- src/dba/models/BenchmarkFactory.class.php | 4 +-- src/inc/api/APIGetChunk.class.php | 5 +++- src/inc/api/APISendBenchmark.class.php | 6 ++-- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/dba/models/Benchmark.class.php b/src/dba/models/Benchmark.class.php index 74b5f5b01..60aa4a51e 100644 --- a/src/dba/models/Benchmark.class.php +++ b/src/dba/models/Benchmark.class.php @@ -4,15 +4,19 @@ class Benchmark extends AbstractModel { private $benchmarkId; + private $benchmarkType; private $benchmarkValue; private $attackParameters; + private $hashMode; private $hardwareGroupId; private $ttl; - function __construct($benchmarkId, $benchmarkValue, $attackParameters, $hardwareGroupId, $ttl) { + function __construct($benchmarkId, $benchmarkType, $benchmarkValue, $attackParameters, $hashMode, $hardwareGroupId, $ttl) { $this->benchmarkId = $benchmarkId; + $this->benchmarkType = $benchmarkType; $this->benchmarkValue = $benchmarkValue; $this->attackParameters = $attackParameters; + $this->hashMode = $hashMode; $this->hardwareGroupId = $hardwareGroupId; $this->ttl = $ttl; } @@ -20,8 +24,10 @@ function __construct($benchmarkId, $benchmarkValue, $attackParameters, $hardware function getKeyValueDict() { $dict = array(); $dict['benchmarkId'] = $this->benchmarkId; + $dict['benchmarkType'] = $this->benchmarkType; $dict['benchmarkValue'] = $this->benchmarkValue; $dict['attackParameters'] = $this->attackParameters; + $dict['hashMode'] = $this->hashMode; $dict['hardwareGroupId'] = $this->hardwareGroupId; $dict['ttl'] = $this->ttl; @@ -40,8 +46,8 @@ function getId() { return $this->benchmarkId; } - function setId($benchmarkId) { - $this->benchmarkId = $benchmarkId; + function setId($id) { + $this->benchmarkId = $id; } /** @@ -52,6 +58,14 @@ public function expose() { return get_object_vars($this); } + function getBenchmarkType() { + return $this->benchmarkType; + } + + function setBenchmarkType($benchmarkType) { + $this->benchmarkType = $benchmarkType; + } + function getBenchmarkValue() { return $this->benchmarkValue; } @@ -68,6 +82,14 @@ function setAttackParameters($attackParameters) { $this->attackParameters = $attackParameters; } + function getHashMode() { + return $this->hashMode; + } + + function setHashMode($hashMode) { + $this->hashMode = $hashMode; + } + function getHardwareGroupId() { return $this->hardwareGroupId; } @@ -84,9 +106,11 @@ function setTtl($ttl) { $this->ttl = $ttl; } - const benchmarkId = "benchmarkId"; + const BENCHMARK_ID = "benchmarkId"; + const BENCHMARK_TYPE = "benchmarkType"; const BENCHMARK_VALUE = "benchmarkValue"; const ATTACK_PARAMETERS = "attackParameters"; - const HARDWARE_GROUP_benchmarkId = "hardwareGroupId"; + const HASH_MODE = "hashMode"; + const HARDWARE_GROUP_ID = "hardwareGroupId"; const TTL = "ttl"; } diff --git a/src/dba/models/BenchmarkFactory.class.php b/src/dba/models/BenchmarkFactory.class.php index ec8a2b4de..7a7533cb1 100644 --- a/src/dba/models/BenchmarkFactory.class.php +++ b/src/dba/models/BenchmarkFactory.class.php @@ -23,7 +23,7 @@ function getCacheValidTime() { * @return Benchmark */ function getNullObject() { - $o = new Benchmark(-1, null, null, null, null); + $o = new Benchmark(-1, null, null, null, null, null, null); return $o; } @@ -33,7 +33,7 @@ function getNullObject() { * @return Benchmark */ function createObjectFromDict($pk, $dict) { - $o = new Benchmark($dict['benchmarkId'], $dict['benchmarkValue'], $dict['attackParameters'], $dict['hardwareGroupId'], $dict['ttl']); + $o = new Benchmark($dict['benchmarkId'], $dict['benchmarkType'], $dict['benchmarkValue'], $dict['attackParameters'], $dict['hashMode'], $dict['hardwareGroupId'], $dict['ttl']); return $o; } diff --git a/src/inc/api/APIGetChunk.class.php b/src/inc/api/APIGetChunk.class.php index 734a7e63e..851416224 100644 --- a/src/inc/api/APIGetChunk.class.php +++ b/src/inc/api/APIGetChunk.class.php @@ -56,8 +56,11 @@ public function execute($QUERY = array()) { } else if ($assignment->getBenchmark() == 0 && $task->getIsSmall() == 0 && $task->getStaticChunks() == DTaskStaticChunking::NORMAL) { // benchmark only required on non-small tasks and on non-special chunk tasks //toegevoegde code voor cache + $taskWrapper = Factory::getTaskWrapperFactory()->get($task->getTaskWrapperId()); + $hashlist = Factory::getHashlistFactory()->get($taskWrapper->getHashlistId()); - $benchmark = BenchmarkUtils::getBenchmarkByValue($task->getAttackCmd(), $this->agent->getHardwareGroupId()); + + $benchmark = BenchmarkUtils::getBenchmarkByValue($task->getAttackCmd(), $this->agent->getHardwareGroupId(), $hashlist->getHashTypeId(), $task->getUseNewBench()); if ($benchmark === NULL) { DServerLog::log(DServerLog::INFO, "Need to run a benchmark!", [$this->agent, $task]); $this->sendResponse(array( diff --git a/src/inc/api/APISendBenchmark.class.php b/src/inc/api/APISendBenchmark.class.php index 7d512bf06..27c4c6771 100644 --- a/src/inc/api/APISendBenchmark.class.php +++ b/src/inc/api/APISendBenchmark.class.php @@ -78,11 +78,13 @@ public function execute($QUERY = array()) { $assignment->setBenchmark($benchmark); Factory::getAssignmentFactory()->update($assignment); - //save benchmark in cache + // save benchmark in cache // BenchmarkUtils::saveBenchmarkInCache($task->getAttackCmd() ,$this->agent->getId(), $benchmark); //todo $hardwareGroup = Factory::getHardwareGroupFactory()->get($this->agent->getHardwareGroupId()); - BenchmarkUtils::saveBenchmarkInCache($task->getAttackCmd(), $hardwareGroup, $benchmark); //todo + $hashlist = Factory::getHashlistFactory()->get($taskWrapper->getHashlistId()); + + BenchmarkUtils::saveBenchmarkInCache($task->getAttackCmd(), $hardwareGroup, $benchmark, $hashlist->getHashTypeId(), $type); //todo DServerLog::log(DServerLog::DEBUG, "Saved agent benchmark", [$this->agent, $task, $assignment]); $this->sendResponse(array( From 8f648383a2094b4ba3b8b919f60c1ef43ec0b72d Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Mon, 10 Jul 2023 06:59:20 -0400 Subject: [PATCH 23/55] Updated benchmark.utils --- src/inc/utils/BenchmarkUtils.class.php | 68 ++++++++++++++------------ 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/src/inc/utils/BenchmarkUtils.class.php b/src/inc/utils/BenchmarkUtils.class.php index be05c761b..5687a7d09 100644 --- a/src/inc/utils/BenchmarkUtils.class.php +++ b/src/inc/utils/BenchmarkUtils.class.php @@ -5,13 +5,13 @@ use DBA\OrderFilter; use DBA\Benchmark; -define("ttl", 216000); -define("size", 50); +// define("ttl", 216000); +// define("size", 50); -enum BenchmarkType { - case SpeedBenchmark; - case RuntimeBenchmark; -} +// enum BenchmarkType { +// case SpeedBenchmark; +// case RuntimeBenchmark; +// } class BenchmarkUtils { @@ -28,7 +28,7 @@ public static function delete($benchmarkId) { Factory::getBenchmarkFactory()->delete($benchmark); } - static function cleanupAttackParameters2($attackCmd) { + static function cleanupAttackParameters($attackCmd) { $attackCmd = trim($attackCmd); if (strlen($attackCmd) == 0) { @@ -86,10 +86,10 @@ static function cleanupAttackParameters2($attackCmd) { $arguments[$arg] = null; } - if (!array_key_exists("--hash-type", $arguments)) { //if --hash-type not in arguments that means hashtype 0 is in use - $arguments["--hash-type"] = "0"; - } - if (!array_key_exists("--attack-mode", $arguments)) { //if --hash-type not in arguments that means hashtype 0 is in use + // if (!array_key_exists("--hash-type", $arguments)) { //if --hash-type not in arguments that means hashtype 0 is in use + // $arguments["--hash-type"] = "0"; + // } + if (!array_key_exists("--attack-mode", $arguments)) { //if --hash-type not in arguments that means attackMode 0 is in use $arguments["--attack-mode"] = "0"; } @@ -109,19 +109,24 @@ static function cleanupAttackParameters2($attackCmd) { return $cleanAttackCmd; } - public static function getBenchmarkByValue($attackParameters, $hardwareGroupId) { + public static function getBenchmarkByValue($attackParameters, $hardwareGroupId, $hashmode, $useNewBenchmark) { $hardwareGroup = Factory::getHardwareGroupFactory()->get($hardwareGroupId); if (!isset($hardwareGroup)) { return null; } - $cleanAttackParameter = self::cleanupAttackParameters2($attackParameters); + $cleanAttackParameter = self::cleanupAttackParameters($attackParameters); $qF = new QueryFilter("attackParameters", $cleanAttackParameter, "="); $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroup->getId(), "="); + $qF3 = new QueryFilter("hashMode", $hashmode, "="); + + $benchmarkType = $useNewBenchmark == 1 ? "speed" : "runtime"; - $res = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2]], true); + $qF4 = new QueryFilter("benchmarkType", $benchmarkType, "="); + + $res = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2, $qF3, $qF4]], true); if(isset($res)){ if ($res->getTtl() < time()) { // if ttl has been exceeded, remove value and return null @@ -139,25 +144,24 @@ public static function deleteBenchmark($benchmark) { return true; } - public static function saveBenchmarkInCache($attackParameters, $hardwareGroup, $benchmarkValue) { - $cleanAttackParameters = self::cleanupAttackParameters2($attackParameters); - - $qF = new QueryFilter("attackParameters", $cleanAttackParameters, "="); - $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroup->getId(), "="); - - $foundBenchmark = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2]], true); - - if (isset($foundBenchmark)) { //if benchmark already in cache, update the value - $foundBenchmark->setTtl(time() + ttl); - $foundBenchmark->setBenchmarkValue($benchmarkValue); - $benchmark = Factory::getBenchmarkFactory()->update($foundBenchmark); - } else { - $newBenchmark = new Benchmark(null, $benchmarkValue, $cleanAttackParameters, $hardwareGroup->getID(), time() + ttl); - $benchmark = Factory::getBenchmarkFactory()->save($newBenchmark); - } + public static function saveBenchmarkInCache($attackParameters, $hardwareGroup, $benchmarkValue, $hashmode, $benchmarkType) { + $cleanAttackParameters = self::cleanupAttackParameters($attackParameters); - return $benchmark; - + $qF = new QueryFilter("attackParameters", $cleanAttackParameters, "="); + $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroup->getId(), "="); + + $foundBenchmark = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2]], true); + + if (isset($foundBenchmark)) { //if benchmark already in cache, update the value + $foundBenchmark->setTtl(time() + ttl); + $foundBenchmark->setBenchmarkValue($benchmarkValue); + $benchmark = Factory::getBenchmarkFactory()->update($foundBenchmark); + } else { + $newBenchmark = new Benchmark(null, $benchmarkType, $benchmarkValue, $cleanAttackParameters, $hashmode, $hardwareGroup->getID(), time() + ttl); + $benchmark = Factory::getBenchmarkFactory()->save($newBenchmark); + } + + return $benchmark; } //removes all values where the time to live has been exceeded From 9b23f5b4f46950daed94cebf8c394d151e08ba86 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Mon, 10 Jul 2023 07:01:20 -0400 Subject: [PATCH 24/55] removed foreignkey from agent to hardwareGroup becasue of bug --- src/install/hashtopolis.sql | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index 2d1aab38b..5b913741d 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -1015,8 +1015,8 @@ ALTER TABLE `HardwareGroup` ALTER TABLE `Agent` ADD PRIMARY KEY (`agentId`), - ADD KEY `userId` (`userId`), - ADD KEY `hardwareGroupId` (`hardwareGroupId`); + ADD KEY `userId` (`userId`); + -- ADD KEY `hardwareGroupId` (`hardwareGroupId`); ALTER TABLE `AgentBinary` ADD PRIMARY KEY (`agentBinaryId`); @@ -1328,9 +1328,8 @@ ALTER TABLE `AccessGroupUser` ADD CONSTRAINT `AccessGroupUser_ibfk_2` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`); ALTER TABLE `Agent` - ADD CONSTRAINT `Agent_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`), - ADD CONSTRAINT `Agent_ibfk_2` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`); - + ADD CONSTRAINT `Agent_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`); + -- ADD CONSTRAINT `Agent_ibfk_2` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`); ALTER TABLE `AgentError` ADD CONSTRAINT `AgentError_ibfk_1` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`), From d173c1ca6efcca35e26ea6014ed8ca6e5741ccf0 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Mon, 10 Jul 2023 07:37:24 -0400 Subject: [PATCH 25/55] updated frontend --- src/templates/benchmarks/index.template.html | 66 ++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/templates/benchmarks/index.template.html diff --git a/src/templates/benchmarks/index.template.html b/src/templates/benchmarks/index.template.html new file mode 100644 index 000000000..a288c4caf --- /dev/null +++ b/src/templates/benchmarks/index.template.html @@ -0,0 +1,66 @@ +{%TEMPLATE->struct/head%} +{%TEMPLATE->struct/menu%} +

Benchmarks ([[numBenchmarks]])

+{%TEMPLATE->struct/messages%} +
+
+ + + +
+
+
+
+
+ + + + + + + + + + + + + + {{FOREACH benchmark;[[benchmarks]]}} + + + + + + + + {{IF [[accessControl.hasPermission([[$DAccessControl::DELETE_BENCHMARK_ACCESS]])]]}} + + {{ELSE}} + + {{ENDIF}} + + {{ENDFOREACH}} + +
Benchmark idBenchmark CmdBenchmark HashmodeCPU/GPUBenchmark valuettlaction
[[benchmark.getId()]][[benchmark.getAttackParameters()]][[benchmark.getHashMode()]][[str_replace("\n","
",[[benchmark.getHardwareGroupId()]])]]
[[benchmark.getBenchmarkValue()]][[date([[config.getVal(DConfig::TIME_FORMAT)]], [[benchmark.getTtl()]])]] +
+ + + + +
+
 
+ +
+
+{%TEMPLATE->struct/foot%} \ No newline at end of file From 41945331c69459e6812865d4193d72784563fb0f Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Mon, 10 Jul 2023 07:47:40 -0400 Subject: [PATCH 26/55] uncommented the ttl --- src/inc/utils/BenchmarkUtils.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inc/utils/BenchmarkUtils.class.php b/src/inc/utils/BenchmarkUtils.class.php index 5687a7d09..33d1a44d5 100644 --- a/src/inc/utils/BenchmarkUtils.class.php +++ b/src/inc/utils/BenchmarkUtils.class.php @@ -5,7 +5,7 @@ use DBA\OrderFilter; use DBA\Benchmark; -// define("ttl", 216000); +define("ttl", 216000); // define("size", 50); // enum BenchmarkType { From 17c895612e95038964b0fdbe964a38472e6c5412 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Mon, 10 Jul 2023 07:51:38 -0400 Subject: [PATCH 27/55] Removed foreignkey from agent to hardwareGroup in updatescript because of bug --- src/install/updates/update_v0.14.x_v0.14.0.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/install/updates/update_v0.14.x_v0.14.0.php b/src/install/updates/update_v0.14.x_v0.14.0.php index 94cce19e5..822c5cde5 100644 --- a/src/install/updates/update_v0.14.x_v0.14.0.php +++ b/src/install/updates/update_v0.14.x_v0.14.0.php @@ -37,15 +37,15 @@ Factory::getAgentFactory()->getDB()->query(" ALTER TABLE `Benchmark` - ADD PRIMARY KEY (`benchmarkId`), - ADD KEY `hardwareGroupId` (`hardwareGroupId`);"); + ADD PRIMARY KEY (`benchmarkId`);"); + // ADD KEY `hardwareGroupId` (`hardwareGroupId`);"); Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); } -Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT `Agent_ibfk_2` - FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); +// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT `Agent_ibfk_2` +// FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); From cf390fd5c98a24ecdd2a3b1864960f04e7c781c3 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Fri, 14 Jul 2023 14:23:46 -0400 Subject: [PATCH 28/55] Added crackerBinary to cached benchmarks --- src/dba/models/AbstractModel.template.txt.txt | 46 +++++++++++ .../AbstractModelFactory.template.txt.txt | 82 +++++++++++++++++++ src/dba/models/Benchmark.class.php | 14 +++- src/dba/models/BenchmarkFactory.class.php | 4 +- src/dba/models/Factory.template.txt.txt | 15 ++++ src/dba/models/generator.php | 3 + src/inc/api/APIGetChunk.class.php | 2 +- src/inc/api/APISendBenchmark.class.php | 3 +- src/inc/utils/BenchmarkUtils.class.php | 18 ++-- src/install/hashtopolis.sql | 5 +- .../updates/update_v0.14.x_v0.14.0.php | 1 + src/templates/benchmarks/detail.template.html | 56 ------------- 12 files changed, 178 insertions(+), 71 deletions(-) create mode 100644 src/dba/models/AbstractModel.template.txt.txt create mode 100644 src/dba/models/AbstractModelFactory.template.txt.txt create mode 100644 src/dba/models/Factory.template.txt.txt delete mode 100644 src/templates/benchmarks/detail.template.html diff --git a/src/dba/models/AbstractModel.template.txt.txt b/src/dba/models/AbstractModel.template.txt.txt new file mode 100644 index 000000000..340b2c8e4 --- /dev/null +++ b/src/dba/models/AbstractModel.template.txt.txt @@ -0,0 +1,46 @@ +__MODEL_PK__; + } + + function getId() { + return $this->__MODEL_PK__; + } + + function setId($id) { + $this->__MODEL_PK__ = $id; + } + + /** + * Used to serialize the data contained in the model + * @return array + */ + public function expose() { + return get_object_vars($this); + } + + __MODEL_GETTER_SETTER__ + + __MODEL_VARIABLE_NAMES__ +} diff --git a/src/dba/models/AbstractModelFactory.template.txt.txt b/src/dba/models/AbstractModelFactory.template.txt.txt new file mode 100644 index 000000000..86169b5b5 --- /dev/null +++ b/src/dba/models/AbstractModelFactory.template.txt.txt @@ -0,0 +1,82 @@ +benchmarkId = $benchmarkId; $this->benchmarkType = $benchmarkType; $this->benchmarkValue = $benchmarkValue; @@ -19,6 +20,7 @@ function __construct($benchmarkId, $benchmarkType, $benchmarkValue, $attackParam $this->hashMode = $hashMode; $this->hardwareGroupId = $hardwareGroupId; $this->ttl = $ttl; + $this->crackerBinaryId = $crackerBinaryId; } function getKeyValueDict() { @@ -30,6 +32,7 @@ function getKeyValueDict() { $dict['hashMode'] = $this->hashMode; $dict['hardwareGroupId'] = $this->hardwareGroupId; $dict['ttl'] = $this->ttl; + $dict['crackerBinaryId'] = $this->crackerBinaryId; return $dict; } @@ -106,6 +109,14 @@ function setTtl($ttl) { $this->ttl = $ttl; } + function getCrackerBinaryId() { + return $this->crackerBinaryId; + } + + function setCrackerBinaryId($crackerBinaryId) { + $this->crackerBinaryId = $crackerBinaryId; + } + const BENCHMARK_ID = "benchmarkId"; const BENCHMARK_TYPE = "benchmarkType"; const BENCHMARK_VALUE = "benchmarkValue"; @@ -113,4 +124,5 @@ function setTtl($ttl) { const HASH_MODE = "hashMode"; const HARDWARE_GROUP_ID = "hardwareGroupId"; const TTL = "ttl"; + const CRACKER_BINARY_ID = "crackerBinaryId"; } diff --git a/src/dba/models/BenchmarkFactory.class.php b/src/dba/models/BenchmarkFactory.class.php index 7a7533cb1..1bcb5ff52 100644 --- a/src/dba/models/BenchmarkFactory.class.php +++ b/src/dba/models/BenchmarkFactory.class.php @@ -23,7 +23,7 @@ function getCacheValidTime() { * @return Benchmark */ function getNullObject() { - $o = new Benchmark(-1, null, null, null, null, null, null); + $o = new Benchmark(-1, null, null, null, null, null, null, null); return $o; } @@ -33,7 +33,7 @@ function getNullObject() { * @return Benchmark */ function createObjectFromDict($pk, $dict) { - $o = new Benchmark($dict['benchmarkId'], $dict['benchmarkType'], $dict['benchmarkValue'], $dict['attackParameters'], $dict['hashMode'], $dict['hardwareGroupId'], $dict['ttl']); + $o = new Benchmark($dict['benchmarkId'], $dict['benchmarkType'], $dict['benchmarkValue'], $dict['attackParameters'], $dict['hashMode'], $dict['hardwareGroupId'], $dict['ttl'], $dict['crackerBinaryId']); return $o; } diff --git a/src/dba/models/Factory.template.txt.txt b/src/dba/models/Factory.template.txt.txt new file mode 100644 index 000000000..1dca8550f --- /dev/null +++ b/src/dba/models/Factory.template.txt.txt @@ -0,0 +1,15 @@ +get($taskWrapper->getHashlistId()); - $benchmark = BenchmarkUtils::getBenchmarkByValue($task->getAttackCmd(), $this->agent->getHardwareGroupId(), $hashlist->getHashTypeId(), $task->getUseNewBench()); + $benchmark = BenchmarkUtils::getBenchmarkByValue($task->getAttackCmd(), $this->agent->getHardwareGroupId(), $hashlist->getHashTypeId(), $task->getUseNewBench(), $task->getCrackerBinaryId()); if ($benchmark === NULL) { DServerLog::log(DServerLog::INFO, "Need to run a benchmark!", [$this->agent, $task]); $this->sendResponse(array( diff --git a/src/inc/api/APISendBenchmark.class.php b/src/inc/api/APISendBenchmark.class.php index 27c4c6771..6ccd836fa 100644 --- a/src/inc/api/APISendBenchmark.class.php +++ b/src/inc/api/APISendBenchmark.class.php @@ -79,12 +79,11 @@ public function execute($QUERY = array()) { Factory::getAssignmentFactory()->update($assignment); // save benchmark in cache - // BenchmarkUtils::saveBenchmarkInCache($task->getAttackCmd() ,$this->agent->getId(), $benchmark); //todo $hardwareGroup = Factory::getHardwareGroupFactory()->get($this->agent->getHardwareGroupId()); $hashlist = Factory::getHashlistFactory()->get($taskWrapper->getHashlistId()); - BenchmarkUtils::saveBenchmarkInCache($task->getAttackCmd(), $hardwareGroup, $benchmark, $hashlist->getHashTypeId(), $type); //todo + BenchmarkUtils::saveBenchmarkInCache($task->getAttackCmd(), $hardwareGroup, $benchmark, $hashlist->getHashTypeId(), $type, $task->getCrackerBinaryId()); DServerLog::log(DServerLog::DEBUG, "Saved agent benchmark", [$this->agent, $task, $assignment]); $this->sendResponse(array( diff --git a/src/inc/utils/BenchmarkUtils.class.php b/src/inc/utils/BenchmarkUtils.class.php index 33d1a44d5..98dd8c84e 100644 --- a/src/inc/utils/BenchmarkUtils.class.php +++ b/src/inc/utils/BenchmarkUtils.class.php @@ -109,24 +109,26 @@ static function cleanupAttackParameters($attackCmd) { return $cleanAttackCmd; } - public static function getBenchmarkByValue($attackParameters, $hardwareGroupId, $hashmode, $useNewBenchmark) { + public static function getBenchmarkByValue($attackParameters, $hardwareGroupId, $hashmode, $useNewBenchmark, $crackerBinaryId) { $hardwareGroup = Factory::getHardwareGroupFactory()->get($hardwareGroupId); + $crackerBinary = Factory::getCrackerBinaryFactory()->get($crackerBinaryId); - if (!isset($hardwareGroup)) { + if (!isset($hardwareGroup) || !isset($crackerBinary)) { return null; } - + $cleanAttackParameter = self::cleanupAttackParameters($attackParameters); $qF = new QueryFilter("attackParameters", $cleanAttackParameter, "="); $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroup->getId(), "="); $qF3 = new QueryFilter("hashMode", $hashmode, "="); - + $benchmarkType = $useNewBenchmark == 1 ? "speed" : "runtime"; - + $qF4 = new QueryFilter("benchmarkType", $benchmarkType, "="); + $qF5 = new QueryFilter("crackerBinaryId", $crackerBinary->getId(), "="); - $res = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2, $qF3, $qF4]], true); + $res = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2, $qF3, $qF4, $qF5]], true); if(isset($res)){ if ($res->getTtl() < time()) { // if ttl has been exceeded, remove value and return null @@ -144,7 +146,7 @@ public static function deleteBenchmark($benchmark) { return true; } - public static function saveBenchmarkInCache($attackParameters, $hardwareGroup, $benchmarkValue, $hashmode, $benchmarkType) { + public static function saveBenchmarkInCache($attackParameters, $hardwareGroup, $benchmarkValue, $hashmode, $benchmarkType, $crackerBinaryId) { $cleanAttackParameters = self::cleanupAttackParameters($attackParameters); $qF = new QueryFilter("attackParameters", $cleanAttackParameters, "="); @@ -157,7 +159,7 @@ public static function saveBenchmarkInCache($attackParameters, $hardwareGroup, $ $foundBenchmark->setBenchmarkValue($benchmarkValue); $benchmark = Factory::getBenchmarkFactory()->update($foundBenchmark); } else { - $newBenchmark = new Benchmark(null, $benchmarkType, $benchmarkValue, $cleanAttackParameters, $hashmode, $hardwareGroup->getID(), time() + ttl); + $newBenchmark = new Benchmark(null, $benchmarkType, $benchmarkValue, $cleanAttackParameters, $hashmode, $hardwareGroup->getID(), time() + ttl, $crackerBinaryId); $benchmark = Factory::getBenchmarkFactory()->save($newBenchmark); } diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index 5b913741d..7246637ad 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -915,6 +915,7 @@ CREATE TABLE `Benchmark` ( `benchmarkId` INT(11) NOT NULL, `benchmarkValue` VARCHAR(256) NOT NULL, `hardwareGroupId` INT(11) NOT NULL, + `crackerBinaryId` INT(11) NOT NULL, `attackParameters` VARCHAR(512) NOT NULL, `ttl` int(11) NOT NULL, `hashMode` int(11) NOT NULL, @@ -1177,6 +1178,7 @@ ALTER TABLE `Preprocessor` ALTER TABLE `Benchmark` ADD PRIMARY KEY (`benchmarkId`), + ADD KEY `crackerBinaryId` (`crackerBinaryId`), ADD KEY `hardwareGroupId` (`hardwareGroupId`); -- Add AUTO_INCREMENT for tables @@ -1430,7 +1432,8 @@ ALTER TABLE `User` ADD CONSTRAINT `User_ibfk_1` FOREIGN KEY (`rightGroupId`) REFERENCES `RightGroup` (`rightGroupId`); ALTER TABLE `Benchmark` - ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`); + ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`), + ADD CONSTRAINT `Benchmark_ibfk_2` FOREIGN KEY (`crackerBinaryId`) REFERENCES `CrackerBinary` (`crackerBinaryId`); ALTER TABLE `Zap` ADD CONSTRAINT `Zap_ibfk_1` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`), diff --git a/src/install/updates/update_v0.14.x_v0.14.0.php b/src/install/updates/update_v0.14.x_v0.14.0.php index 822c5cde5..92397a4a0 100644 --- a/src/install/updates/update_v0.14.x_v0.14.0.php +++ b/src/install/updates/update_v0.14.x_v0.14.0.php @@ -26,6 +26,7 @@ `benchmarkId` INT(11) NOT NULL, `benchmarkValue` VARCHAR(256) NOT NULL, `hardwareGroupId` INT(11) NOT NULL, + `crackerBinaryId` INT(11) NOT NULL, `attackParameters` VARCHAR(512) NOT NULL, `ttl` INT(11) NULL, `hashMode` INT(11) NULL, diff --git a/src/templates/benchmarks/detail.template.html b/src/templates/benchmarks/detail.template.html deleted file mode 100644 index 9791bed27..000000000 --- a/src/templates/benchmarks/detail.template.html +++ /dev/null @@ -1,56 +0,0 @@ -{%TEMPLATE->struct/head%} -{%TEMPLATE->struct/menu%} -

Benchmarks ([[numBenchmarks]])

-{%TEMPLATE->struct/messages%} -
-
- - - - - - - - - - - - - {{FOREACH benchmark;[[benchmarks]]}} - - - - - - - {{IF [[accessControl.hasPermission([[$DAccessControl::DELETE_BENCHMARK_ACCESS]])]]}} - - {{ELSE}} - - {{ENDIF}} - - {{ENDFOREACH}} - -
Benchmark idBenchmark CmdCPU/GPUBenchmark valuettlaction
[[benchmark.getId()]][[benchmark.getAttackParameters()]][[str_replace("\n","
",[[benchmark.getHardwareGroupId()]])]]
[[benchmark.getBenchmarkValue()]][[date([[config.getVal(DConfig::TIME_FORMAT)]], [[benchmark.getTtl()]])]] -
- - - - -
-
 
- -
-
-{%TEMPLATE->struct/foot%} \ No newline at end of file From 579c8f9e3c935990f7d7519f1efd8150ccb35975 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Sat, 15 Jul 2023 05:29:45 -0400 Subject: [PATCH 29/55] Formatted the hardware of the benchmark prettier in the frontend --- src/benchmark.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/benchmark.php b/src/benchmark.php index d3826b4f0..448a84432 100644 --- a/src/benchmark.php +++ b/src/benchmark.php @@ -37,7 +37,13 @@ foreach ($benchmarks as $benchmark) { $devices = HardwareGroupUtils::getDevicesFromBenchmark($benchmark); - $benchmark->setHardwareGroupId($devices); + + $tmp_devices_tuple = array_count_values(explode("\n", $devices)); + $devices_tuple = array(); + foreach ($tmp_devices_tuple as $key => $value) { + $devices_tuple[] = str_replace("*", "  ", sprintf("%'*2d× ", $value) . $key); + } + $benchmark->setHardwareGroupId(implode("\n", $devices_tuple)); } From 164bc95338b3ebf5a20646ae17533c05a3d780ea Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Sat, 15 Jul 2023 06:05:22 -0400 Subject: [PATCH 30/55] Added the crackerbinary to the benchmark frontend --- src/benchmark.php | 35 ++++++++++++++------ src/templates/benchmarks/index.template.html | 8 +++-- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/benchmark.php b/src/benchmark.php index 448a84432..9ea013617 100644 --- a/src/benchmark.php +++ b/src/benchmark.php @@ -1,6 +1,8 @@ filter([]); } -foreach ($benchmarks as $benchmark) { - $devices = HardwareGroupUtils::getDevicesFromBenchmark($benchmark); +$oF = new OrderFilter(CrackerBinary::CRACKER_BINARY_ID, "DESC"); +$versions = Factory::getCrackerBinaryFactory()->filter([Factory::ORDER => $oF]); +usort($versions, ["Util", "versionComparisonBinary"]); + + foreach ($benchmarks as $benchmark) { + //format the devices pretty + $devices = HardwareGroupUtils::getDevicesFromBenchmark($benchmark); - $tmp_devices_tuple = array_count_values(explode("\n", $devices)); - $devices_tuple = array(); - foreach ($tmp_devices_tuple as $key => $value) { - $devices_tuple[] = str_replace("*", "  ", sprintf("%'*2d× ", $value) . $key); - } - $benchmark->setHardwareGroupId(implode("\n", $devices_tuple)); -} + $tmp_devices_tuple = array_count_values(explode("\n", $devices)); + $devices_tuple = array(); + foreach ($tmp_devices_tuple as $key => $value) { + $devices_tuple[] = str_replace("*", "  ", sprintf("%'*2d× ", $value) . $key); + } + $benchmark->setHardwareGroupId(implode("\n", $devices_tuple)); + //get the correct cracker binary for the benchmarks + foreach ($versions as $version) { + if ($benchmark->getCrackerBinaryId() == $version->getId()) { + + $benchmark->setCrackerBinaryId($version->getBinaryName() . " " . $version->getVersion()); + break; + } + } +} UI::add('benchmarks', $benchmarks); UI::add('numBenchmarks', sizeof($benchmarks)); echo Template::getInstance()->render(UI::getObjects()); - -?> \ No newline at end of file diff --git a/src/templates/benchmarks/index.template.html b/src/templates/benchmarks/index.template.html index a288c4caf..32083bfb5 100644 --- a/src/templates/benchmarks/index.template.html +++ b/src/templates/benchmarks/index.template.html @@ -15,9 +15,10 @@

Benchmarks ([[numBenchmarks]])

- - - + + + + @@ -30,6 +31,7 @@

Benchmarks ([[numBenchmarks]])

+ From dec578c2df9d857d781c583e17ec0e58a5470774 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Sat, 15 Jul 2023 06:10:05 -0400 Subject: [PATCH 31/55] Fixed bug in commandline parameters parsing where arguments in format: '-a3' werent properly parsed --- src/inc/utils/BenchmarkUtils.class.php | 170 ++++++++++++++----------- 1 file changed, 93 insertions(+), 77 deletions(-) diff --git a/src/inc/utils/BenchmarkUtils.class.php b/src/inc/utils/BenchmarkUtils.class.php index 98dd8c84e..8d7c315a5 100644 --- a/src/inc/utils/BenchmarkUtils.class.php +++ b/src/inc/utils/BenchmarkUtils.class.php @@ -13,22 +13,26 @@ // case RuntimeBenchmark; // } -class BenchmarkUtils { +class BenchmarkUtils +{ - public static function getBenchmark($benchmarkId) { - $benchmark = Factory::getBenchmarkFactory()->get($benchmarkId); - if ($benchmark == null) { + public static function getBenchmark($benchmarkId) + { + $benchmark = Factory::getBenchmarkFactory()->get($benchmarkId); + if ($benchmark == null) { throw new HTException("Invalid benchmark ID!"); - } - return $benchmark; + } + return $benchmark; } - public static function delete($benchmarkId) { + public static function delete($benchmarkId) + { $benchmark = BenchmarkUtils::getBenchmark($benchmarkId); Factory::getBenchmarkFactory()->delete($benchmark); } - static function cleanupAttackParameters($attackCmd) { + static function cleanupAttackParameters($attackCmd) + { $attackCmd = trim($attackCmd); if (strlen($attackCmd) == 0) { @@ -50,13 +54,12 @@ static function cleanupAttackParameters($attackCmd) { $arguments = array(); $hashlist = SConfig::getInstance()->getVal(DConfig::HASHLIST_ALIAS); - // $hashlist = "#HL#"; $attackValue = ""; //this is the dictionary or attack mask $i = 0; $size = sizeof($parts_cmd); - for ($i = 0;$i < count($parts_cmd);$i++) { + for ($i = 0; $i < count($parts_cmd); $i++) { $arg = $parts_cmd[$i]; if ($arg == $hashlist) { //the hashlist is always #HL# so it doesnt have to be parsed continue; @@ -66,21 +69,31 @@ static function cleanupAttackParameters($attackCmd) { $attackValue = $arg; continue; } - - if (array_key_exists($arg, $parameterParseMap)) { + + $number = null; + if (!str_contains($arg, "=")) { //if the argument is in format "-a3" the number needs to be split to properly parse + $number = preg_replace('/[^0-9]/', '', $arg); + $arg = preg_replace('/[^a-zA-Z\-]/', '', $arg); + } + + if (array_key_exists($arg, $parameterParseMap)) { //parse to long format $arg = $parameterParseMap[$arg]; } + if (!empty($number)) { //when an argument is in format -a3 use the number as value and continue to next itteration + $arguments[$arg] = $number; + continue; + } //parse longparameter in style: --remove-timer=30 if (str_contains($arg, '=')) { $longParameterSplit = explode('=', $arg); $arguments[$longParameterSplit[0]] = $longParameterSplit[1]; continue; - } else if($i <= ($size - 2)) { //if the next character doesnt start with '-' it means that its the value of the parameter - if (!str_starts_with($parts_cmd[$i+1], "-")) { - $arguments[$arg] = $parts_cmd[$i+1]; - $i++; - continue; + } else if ($i <= ($size - 2)) { //if the next character doesnt start with '-' it means that its the value of the parameter + if (!str_starts_with($parts_cmd[$i + 1], "-")) { + $arguments[$arg] = $parts_cmd[$i + 1]; + $i++; + continue; } } $arguments[$arg] = null; @@ -109,82 +122,85 @@ static function cleanupAttackParameters($attackCmd) { return $cleanAttackCmd; } - public static function getBenchmarkByValue($attackParameters, $hardwareGroupId, $hashmode, $useNewBenchmark, $crackerBinaryId) { - $hardwareGroup = Factory::getHardwareGroupFactory()->get($hardwareGroupId); - $crackerBinary = Factory::getCrackerBinaryFactory()->get($crackerBinaryId); + public static function getBenchmarkByValue($attackParameters, $hardwareGroupId, $hashmode, $useNewBenchmark, $crackerBinaryId) + { + $hardwareGroup = Factory::getHardwareGroupFactory()->get($hardwareGroupId); + $crackerBinary = Factory::getCrackerBinaryFactory()->get($crackerBinaryId); - if (!isset($hardwareGroup) || !isset($crackerBinary)) { - return null; - } - - $cleanAttackParameter = self::cleanupAttackParameters($attackParameters); - - $qF = new QueryFilter("attackParameters", $cleanAttackParameter, "="); - $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroup->getId(), "="); - $qF3 = new QueryFilter("hashMode", $hashmode, "="); - - $benchmarkType = $useNewBenchmark == 1 ? "speed" : "runtime"; - - $qF4 = new QueryFilter("benchmarkType", $benchmarkType, "="); - $qF5 = new QueryFilter("crackerBinaryId", $crackerBinary->getId(), "="); - - $res = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2, $qF3, $qF4, $qF5]], true); - - if(isset($res)){ - if ($res->getTtl() < time()) { // if ttl has been exceeded, remove value and return null - - Factory::getBenchmarkFactory()->delete($res); - return null; - } - } - - return $res; + if (!isset($hardwareGroup) || !isset($crackerBinary)) { + return null; } - public static function deleteBenchmark($benchmark) { - Factory::getBenchmarkFactory()->delete($benchmark); - return true; - } + $cleanAttackParameter = self::cleanupAttackParameters($attackParameters); + + $qF = new QueryFilter("attackParameters", $cleanAttackParameter, "="); + $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroup->getId(), "="); + $qF3 = new QueryFilter("hashMode", $hashmode, "="); + + $benchmarkType = $useNewBenchmark == 1 ? "speed" : "runtime"; + + $qF4 = new QueryFilter("benchmarkType", $benchmarkType, "="); + $qF5 = new QueryFilter("crackerBinaryId", $crackerBinary->getId(), "="); - public static function saveBenchmarkInCache($attackParameters, $hardwareGroup, $benchmarkValue, $hashmode, $benchmarkType, $crackerBinaryId) { - $cleanAttackParameters = self::cleanupAttackParameters($attackParameters); - - $qF = new QueryFilter("attackParameters", $cleanAttackParameters, "="); - $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroup->getId(), "="); - - $foundBenchmark = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2]], true); - - if (isset($foundBenchmark)) { //if benchmark already in cache, update the value - $foundBenchmark->setTtl(time() + ttl); - $foundBenchmark->setBenchmarkValue($benchmarkValue); - $benchmark = Factory::getBenchmarkFactory()->update($foundBenchmark); - } else { - $newBenchmark = new Benchmark(null, $benchmarkType, $benchmarkValue, $cleanAttackParameters, $hashmode, $hardwareGroup->getID(), time() + ttl, $crackerBinaryId); - $benchmark = Factory::getBenchmarkFactory()->save($newBenchmark); + $res = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2, $qF3, $qF4, $qF5]], true); + + if (isset($res)) { + if ($res->getTtl() < time()) { // if ttl has been exceeded, remove value and return null + + Factory::getBenchmarkFactory()->delete($res); + return null; } + } + + return $res; + } + + public static function deleteBenchmark($benchmark) + { + Factory::getBenchmarkFactory()->delete($benchmark); + return true; + } + + public static function saveBenchmarkInCache($attackParameters, $hardwareGroup, $benchmarkValue, $hashmode, $benchmarkType, $crackerBinaryId) + { + $cleanAttackParameters = self::cleanupAttackParameters($attackParameters); - return $benchmark; + $qF = new QueryFilter("attackParameters", $cleanAttackParameters, "="); + $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroup->getId(), "="); + + $foundBenchmark = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2]], true); + + if (isset($foundBenchmark)) { //if benchmark already in cache, update the value + $foundBenchmark->setTtl(time() + ttl); + $foundBenchmark->setBenchmarkValue($benchmarkValue); + $benchmark = Factory::getBenchmarkFactory()->update($foundBenchmark); + } else { + $newBenchmark = new Benchmark(null, $benchmarkType, $benchmarkValue, $cleanAttackParameters, $hashmode, $hardwareGroup->getID(), time() + ttl, $crackerBinaryId); + $benchmark = Factory::getBenchmarkFactory()->save($newBenchmark); } -//removes all values where the time to live has been exceeded -public static function refreshCache() { + return $benchmark; + } + + //removes all values where the time to live has been exceeded + public static function refreshCache() + { $qF = new QueryFilter("ttl", time(), "<"); Factory::getFileTaskFactory()->massDeletion([Factory::FILTER => $qF]); + } -} - -//removes all values in cache -public static function deleteCache() { + //removes all values in cache + public static function deleteCache() + { Factory::getBenchmarkFactory()->massDeletion([]); -} + } -public static function getCacheOfAgent($agentID) { + public static function getCacheOfAgent($agentID) + { $qF = new QueryFilter("agentID", $agentID, "="); $oF = new OrderFilter(ttl, "DESC"); $benchmarks = Factory::getBenchmarkFactory()->filter([Factory::FILTER => $qF, Factory::ORDER => $oF]); return $benchmarks; + } } -} - -?> \ No newline at end of file From a99be7de93761653222e9fb0da95edd06afc5623 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Mon, 17 Jul 2023 13:54:44 -0400 Subject: [PATCH 32/55] made small changes to hardwareGroupUtils --- src/inc/utils/HardwareGroupUtils.class.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/inc/utils/HardwareGroupUtils.class.php b/src/inc/utils/HardwareGroupUtils.class.php index 258f6ef2b..1be209a33 100644 --- a/src/inc/utils/HardwareGroupUtils.class.php +++ b/src/inc/utils/HardwareGroupUtils.class.php @@ -13,13 +13,14 @@ public static function updateHardwareOfAgent($devices, $agent) { if(isset($res)) { Factory::getAgentFactory()->set($agent, Agent::HARDWARE_GROUP_ID, $res->getId()); - } else { - //nieuwe hardware group maken en id bij agent zetten + } else { + //make new hardwareGroup and add the id to the agent $newHardwareGroup = new HardwareGroup(null, $devices); $savedHardwareGroup = Factory::getHardwareGroupFactory()->save($newHardwareGroup); - + Factory::getAgentFactory()->set($agent, Agent::HARDWARE_GROUP_ID, $savedHardwareGroup->getId()); } + return $agent; } public static function getDevicesFromBenchmark($benchmark) { From a835fd0d360734a4a75ae5cda9bf888af416dcea Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Tue, 18 Jul 2023 05:30:47 -0400 Subject: [PATCH 33/55] Added tests for the benchmarks --- ci/files/db_0.13.0.sql | 290 ++++++++++++++++++++----- ci/tests/BenchmarkTest.class.php | 115 ++++++++++ src/inc/api/APISendBenchmark.class.php | 4 +- src/inc/utils/BenchmarkUtils.class.php | 12 +- 4 files changed, 364 insertions(+), 57 deletions(-) create mode 100644 ci/tests/BenchmarkTest.class.php diff --git a/ci/files/db_0.13.0.sql b/ci/files/db_0.13.0.sql index 5e484cb69..7246637ad 100644 --- a/ci/files/db_0.13.0.sql +++ b/ci/files/db_0.13.0.sql @@ -30,7 +30,7 @@ CREATE TABLE `Agent` ( `agentName` VARCHAR(100) NOT NULL, `uid` VARCHAR(100) NOT NULL, `os` INT(11) NOT NULL, - `devices` TEXT NOT NULL, + `hardwareGroupId` INT(11) DEFAULT NULL, `cmdPars` VARCHAR(256) NOT NULL, `ignoreErrors` TINYINT(4) NOT NULL, `isActive` TINYINT(4) NOT NULL, @@ -55,7 +55,7 @@ CREATE TABLE `AgentBinary` ( ) ENGINE = InnoDB; INSERT INTO `AgentBinary` (`agentBinaryId`, `type`, `version`, `operatingSystems`, `filename`, `updateTrack`, `updateAvailable`) VALUES - (1, 'python', '0.5.0', 'Windows, Linux, OS X', 'hashtopolis.zip', 'stable', ''); + (1, 'python', '0.7.1', 'Windows, Linux, OS X', 'hashtopolis.zip', 'stable', ''); CREATE TABLE `AgentError` ( `agentErrorId` INT(11) NOT NULL, @@ -71,7 +71,7 @@ CREATE TABLE `AgentStat` ( `agentId` INT(11) NOT NULL, `statType` INT(11) NOT NULL, `time` BIGINT NOT NULL, - `value` VARCHAR(64) NOT NULL + `value` VARCHAR(128) NOT NULL ) ENGINE = InnoDB; CREATE TABLE `AgentZap` ( @@ -90,12 +90,12 @@ CREATE TABLE `Assignment` ( CREATE TABLE `Chunk` ( `chunkId` INT(11) NOT NULL, `taskId` INT(11) NOT NULL, - `skip` BIGINT(20) NOT NULL, - `length` BIGINT(20) NOT NULL, + `skip` BIGINT(20) UNSIGNED NOT NULL, + `length` BIGINT(20) UNSIGNED NOT NULL, `agentId` INT(11) NULL, `dispatchTime` BIGINT NOT NULL, `solveTime` BIGINT NOT NULL, - `checkpoint` BIGINT(20) NOT NULL, + `checkpoint` BIGINT(20) UNSIGNED NOT NULL, `progress` INT(11) NULL, `state` INT(11) NOT NULL, `cracked` INT(11) NOT NULL, @@ -124,8 +124,7 @@ INSERT INTO `Config` (`configId`, `configSectionId`, `item`, `value`) VALUES (16, 3, 'batchSize', '50000'), (18, 2, 'yubikey_id', ''), (19, 2, 'yubikey_key', ''), - (20, 2, 'yubikey_url', 'http://api.yubico.com/wsapi/2.0/verify'), - (21, 4, 'donateOff', '0'), + (20, 2, 'yubikey_url', 'https://api.yubico.com/wsapi/2.0/verify'), (22, 3, 'pagingSize', '5000'), (23, 3, 'plainTextMaxLength', '200'), (24, 3, 'hashMaxLength', '1024'), @@ -143,7 +142,7 @@ INSERT INTO `Config` (`configId`, `configSectionId`, `item`, `value`) VALUES (36, 4, 'showTaskPerformance', '0'), (37, 1, 'ruleSplitSmallTasks', '0'), (38, 1, 'ruleSplitAlways', '0'), - (39, 1, 'ruleSplitDisable', '0'), + (39, 1, 'ruleSplitDisable', '1'), (41, 4, 'agentStatLimit', '100'), (42, 1, 'agentDataLifetime', '3600'), (43, 4, 'agentStatTension', '0'), @@ -196,7 +195,7 @@ CREATE TABLE `CrackerBinary` ( ) ENGINE = InnoDB; INSERT INTO `CrackerBinary` (`crackerBinaryId`, `crackerBinaryTypeId`, `version`, `downloadUrl`, `binaryName`) VALUES - (1, 1, '5.1.0', 'https://hashcat.net/files/hashcat-5.1.0.7z', 'hashcat'); + (1, 1, '6.2.6', 'https://hashcat.net/files/hashcat-6.2.6.7z', 'hashcat'); CREATE TABLE `CrackerBinaryType` ( `crackerBinaryTypeId` INT(11) NOT NULL, @@ -208,12 +207,13 @@ INSERT INTO `CrackerBinaryType` (`crackerBinaryTypeId`, `typeName`, `isChunkingA (1, 'hashcat', 1); CREATE TABLE `File` ( - `fileId` INT(11) NOT NULL, - `filename` VARCHAR(100) NOT NULL, - `size` BIGINT(20) NOT NULL, - `isSecret` TINYINT(4) NOT NULL, - `fileType` INT(11) NOT NULL, - `accessGroupId` INT(11) NOT NULL + `fileId` INT(11) NOT NULL, + `filename` VARCHAR(100) NOT NULL, + `size` BIGINT(20) NOT NULL, + `isSecret` TINYINT(4) NOT NULL, + `fileType` INT(11) NOT NULL, + `accessGroupId` INT(11) NOT NULL, + `lineCount` BIGINT(20) DEFAULT NULL ) ENGINE = InnoDB; CREATE TABLE `FilePretask` ( @@ -237,7 +237,7 @@ CREATE TABLE `FileDelete` ( CREATE TABLE `Hash` ( `hashId` INT(11) NOT NULL, `hashlistId` INT(11) NOT NULL, - `hash` TEXT NOT NULL, + `hash` MEDIUMTEXT NOT NULL, `salt` VARCHAR(256) DEFAULT NULL, `plaintext` VARCHAR(256) DEFAULT NULL, `timeCracked` BIGINT DEFAULT NULL, @@ -250,7 +250,7 @@ CREATE TABLE `HashBinary` ( `hashBinaryId` INT(11) NOT NULL, `hashlistId` INT(11) NOT NULL, `essid` VARCHAR(100) NOT NULL, - `hash` MEDIUMTEXT NOT NULL, + `hash` LONGTEXT NOT NULL, `plaintext` VARCHAR(1024) DEFAULT NULL, `timeCracked` BIGINT DEFAULT NULL, `chunkId` INT(11) DEFAULT NULL, @@ -272,7 +272,8 @@ CREATE TABLE `Hashlist` ( `accessGroupId` INT(11) NOT NULL, `notes` TEXT NOT NULL, `brainId` INT(11) NOT NULL, - `brainFeatures` TINYINT(4) NOT NULL + `brainFeatures` TINYINT(4) NOT NULL, + `isArchived` TINYINT(4) NOT NULL ) ENGINE = InnoDB; CREATE TABLE `HashlistHashlist` ( @@ -297,10 +298,12 @@ INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) V (21, 'osCommerce, xt:Commerce', 1, 0), (22, 'Juniper Netscreen/SSG (ScreenOS)', 1, 0), (23, 'Skype', 1, 0), - (30, 'md5(unicode($pass).$salt)', 1, 0), - (40, 'md5($salt.unicode($pass))', 1, 0), + (24, 'SolarWinds Serv-U', 0, 0), + (30, 'md5(utf16le($pass).$salt)', 1, 0), + (40, 'md5($salt.utf16le($pass))', 1, 0), (50, 'HMAC-MD5 (key = $pass)', 1, 0), (60, 'HMAC-MD5 (key = $salt)', 1, 0), + (70, 'md5(utf16le($pass))', 0, 0), (100, 'SHA1', 0, 0), (101, 'nsldap, SHA-1(Base64), Netscape LDAP SHA', 0, 0), (110, 'sha1($pass.$salt)', 1, 0), @@ -309,23 +312,25 @@ INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) V (120, 'sha1($salt.$pass)', 1, 0), (121, 'SMF >= v1.1', 1, 0), (122, 'OS X v10.4, v10.5, v10.6', 0, 0), - (123, 'EPi', 0, 0), (124, 'Django (SHA-1)', 0, 0), (125, 'ArubaOS', 0, 0), - (130, 'sha1(unicode($pass).$salt)', 1, 0), + (130, 'sha1(utf16le($pass).$salt)', 1, 0), (131, 'MSSQL(2000)', 0, 0), (132, 'MSSQL(2005)', 0, 0), (133, 'PeopleSoft', 0, 0), - (140, 'sha1($salt.unicode($pass))', 1, 0), + (140, 'sha1($salt.utf16le($pass))', 1, 0), (141, 'EPiServer 6.x < v4', 0, 0), (150, 'HMAC-SHA1 (key = $pass)', 1, 0), (160, 'HMAC-SHA1 (key = $salt)', 1, 0), + (170, 'sha1(utf16le($pass))', 0, 0), (200, 'MySQL323', 0, 0), (300, 'MySQL4.1/MySQL5+', 0, 0), (400, 'phpass, MD5(Wordpress), MD5(Joomla), MD5(phpBB3)', 0, 0), (500, 'md5crypt, MD5(Unix), FreeBSD MD5, Cisco-IOS MD5 2', 0, 0), (501, 'Juniper IVE', 0, 0), (600, 'BLAKE2b-512', 0, 0), + (610, 'BLAKE2b-512($pass.$salt)', 1, 0), + (620, 'BLAKE2b-512($salt.$pass)', 1, 0), (900, 'MD4', 0, 0), (1000, 'NTLM', 0, 0), (1100, 'Domain Cached Credentials (DCC), MS Cache', 1, 0), @@ -335,11 +340,12 @@ INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) V (1411, 'SSHA-256(Base64), LDAP {SSHA256}', 0, 0), (1420, 'sha256($salt.$pass)', 1, 0), (1421, 'hMailServer', 0, 0), - (1430, 'sha256(unicode($pass).$salt)', 1, 0), - (1440, 'sha256($salt.unicode($pass))', 1, 0), + (1430, 'sha256(utf16le($pass).$salt)', 1, 0), + (1440, 'sha256($salt.utf16le($pass))', 1, 0), (1441, 'EPiServer 6.x >= v4', 0, 0), (1450, 'HMAC-SHA256 (key = $pass)', 1, 0), (1460, 'HMAC-SHA256 (key = $salt)', 1, 0), + (1470, 'sha256(utf16le($pass))', 0, 0), (1500, 'descrypt, DES(Unix), Traditional DES', 0, 0), (1600, 'md5apr1, MD5(APR), Apache MD5', 0, 0), (1700, 'SHA512', 0, 0), @@ -347,16 +353,19 @@ INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) V (1711, 'SSHA-512(Base64), LDAP {SSHA512}', 0, 0), (1720, 'sha512($salt.$pass)', 1, 0), (1722, 'OS X v10.7', 0, 0), - (1730, 'sha512(unicode($pass).$salt)', 1, 0), + (1730, 'sha512(utf16le($pass).$salt)', 1, 0), (1731, 'MSSQL(2012), MSSQL(2014)', 0, 0), - (1740, 'sha512($salt.unicode($pass))', 1, 0), + (1740, 'sha512($salt.utf16le($pass))', 1, 0), (1750, 'HMAC-SHA512 (key = $pass)', 1, 0), (1760, 'HMAC-SHA512 (key = $salt)', 1, 0), + (1770, 'sha512(utf16le($pass))', 0, 0), (1800, 'sha512crypt, SHA512(Unix)', 0, 0), + (2000, 'STDOUT', 0, 0), (2100, 'Domain Cached Credentials 2 (DCC2), MS Cache', 0, 1), (2400, 'Cisco-PIX MD5', 0, 0), (2410, 'Cisco-ASA MD5', 1, 0), (2500, 'WPA/WPA2', 0, 1), + (2501, 'WPA-EAPOL-PMK', 0, 1), (2600, 'md5(md5($pass))', 0, 0), (2611, 'vBulletin < v3.8.5', 1, 0), (2612, 'PHPS', 0, 0), @@ -365,6 +374,7 @@ INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) V (3000, 'LM', 0, 0), (3100, 'Oracle H: Type (Oracle 7+), DES(Oracle)', 1, 0), (3200, 'bcrypt, Blowfish(OpenBSD)', 0, 0), + (3500, 'md5(md5(md5($pass)))', 0, 0), (3710, 'md5($salt.md5($pass))', 1, 0), (3711, 'Mediawiki B type', 0, 0), (3800, 'md5($salt.$pass.$salt)', 1, 0), @@ -373,11 +383,15 @@ INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) V (4110, 'md5($salt.md5($pass.$salt))', 1, 0), (4300, 'md5(strtoupper(md5($pass)))', 0, 0), (4400, 'md5(sha1($pass))', 0, 0), + (4410, 'md5(sha1($pass).$salt)', 1, 0), (4500, 'sha1(sha1($pass))', 0, 0), + (4510, 'sha1(sha1($pass).$salt)', 1, 0), (4520, 'sha1($salt.sha1($pass))', 1, 0), (4521, 'Redmine Project Management Web App', 0, 0), (4522, 'PunBB', 0, 0), (4700, 'sha1(md5($pass))', 0, 0), + (4710, 'sha1(md5($pass).$salt)', 1, 0), + (4711, 'Huawei sha1(md5($pass).$salt)', 1, 0), (4800, 'MD5(Chap), iSCSI CHAP authentication', 1, 0), (4900, 'sha1($salt.$pass.$salt)', 1, 0), (5000, 'SHA-3(Keccak)', 0, 0), @@ -415,9 +429,12 @@ INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) V (7200, 'GRUB 2', 0, 1), (7300, 'IPMI2 RAKP HMAC-SHA1', 1, 0), (7400, 'sha256crypt, SHA256(Unix)', 0, 0), + (7401, 'MySQL $A$ (sha256crypt)', 0, 0), (7500, 'Kerberos 5 AS-REQ Pre-Auth', 0, 0), (7700, 'SAP CODVN B (BCODE)', 0, 0), + (7701, 'SAP CODVN B (BCODE) from RFC_READ_TABLE', 0, 0), (7800, 'SAP CODVN F/G (PASSCODE)', 0, 0), + (7801, 'SAP CODVN F/G (PASSCODE) from RFC_READ_TABLE', 0, 0), (7900, 'Drupal7', 0, 0), (8000, 'Sybase ASE', 0, 0), (8100, 'Citrix Netscaler', 0, 0), @@ -454,7 +471,13 @@ INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) V (10600, 'PDF 1.7 Level 3 (Acrobat 9)', 0, 0), (10700, 'PDF 1.7 Level 8 (Acrobat 10 - 11)', 0, 0), (10800, 'SHA384', 0, 0), + (10810, 'sha384($pass.$salt)', 1, 0), + (10820, 'sha384($salt.$pass)', 1, 0), + (10830, 'sha384(utf16le($pass).$salt)', 1, 0), + (10840, 'sha384($salt.utf16le($pass))', 1, 0), + (10870, 'sha384(utf16le($pass))', 0, 0), (10900, 'PBKDF2-HMAC-SHA256', 0, 1), + (10901, 'RedHat 389-DS LDAP (PBKDF2-HMAC-SHA256)', 0, 1), (11000, 'PrestaShop', 1, 0), (11100, 'PostgreSQL Challenge-Response Authentication (MD5)', 0, 0), (11200, 'MySQL Challenge-Response Authentication (SHA1)', 0, 0), @@ -463,7 +486,11 @@ INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) V (11500, 'CRC32', 1, 0), (11600, '7-Zip', 0, 0), (11700, 'GOST R 34.11-2012 (Streebog) 256-bit', 0, 0), + (11750, 'HMAC-Streebog-256 (key = $pass), big-endian', 0, 0), + (11760, 'HMAC-Streebog-256 (key = $salt), big-endian', 0, 0), (11800, 'GOST R 34.11-2012 (Streebog) 512-bit', 0, 0), + (11850, 'HMAC-Streebog-512 (key = $pass), big-endian', 0, 0), + (11860, 'HMAC-Streebog-512 (key = $salt), big-endian', 0, 0), (11900, 'PBKDF2-HMAC-MD5', 0, 1), (12000, 'PBKDF2-HMAC-SHA1', 0, 1), (12001, 'Atlassian (PBKDF2-HMAC-SHA1)', 0, 1), @@ -492,14 +519,27 @@ INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) V (13731, 'VeraCrypt PBKDF2-HMAC-Whirlpool + AES, Serpent, Twofish', 0, 1), (13732, 'VeraCrypt PBKDF2-HMAC-Whirlpool + AES-Twofish, Serpent-AES, Twofish-Serpent', 0, 1), (13733, 'VeraCrypt PBKDF2-HMAC-Whirlpool + Serpent-Twofish-AES', 0, 1), + (13741, 'VeraCrypt PBKDF2-HMAC-RIPEMD160 + boot-mode + AES', 0, 1), + (13742, 'VeraCrypt PBKDF2-HMAC-RIPEMD160 + boot-mode + AES-Twofish', 0, 1), + (13743, 'VeraCrypt PBKDF2-HMAC-RIPEMD160 + boot-mode + AES-Twofish-Serpent', 0, 1), (13751, 'VeraCrypt PBKDF2-HMAC-SHA256 + AES, Serpent, Twofish', 0, 1), (13752, 'VeraCrypt PBKDF2-HMAC-SHA256 + AES-Twofish, Serpent-AES, Twofish-Serpent', 0, 1), (13753, 'VeraCrypt PBKDF2-HMAC-SHA256 + Serpent-Twofish-AES', 0, 1), + (13761, 'VeraCrypt PBKDF2-HMAC-SHA256 + boot-mode (PIM + AES | Twofish)', 0, 1), + (13762, 'VeraCrypt PBKDF2-HMAC-SHA256 + boot-mode + Serpent-AES', 0, 1), + (13763, 'VeraCrypt PBKDF2-HMAC-SHA256 + boot-mode + Serpent-Twofish-AES', 0, 1), + (13771, 'VeraCrypt Streebog-512 + XTS 512 bit', 0, 1), + (13772, 'VeraCrypt Streebog-512 + XTS 1024 bit', 0, 1), + (13773, 'VeraCrypt Streebog-512 + XTS 1536 bit', 0, 1), + (13781, 'VeraCrypt Streebog-512 + XTS 512 bit + boot-mode (legacy)', 0, 1), + (13782, 'VeraCrypt Streebog-512 + XTS 1024 bit + boot-mode (legacy)', 0, 1), + (13783, 'VeraCrypt Streebog-512 + XTS 1536 bit + boot-mode (legacy)', 0, 1), (13800, 'Windows 8+ phone PIN/Password', 1, 0), (13900, 'OpenCart', 1, 0), (14000, 'DES (PT = $salt, key = $pass)', 1, 0), (14100, '3DES (PT = $salt, key = $pass)', 1, 0), (14400, 'sha1(CX)', 1, 0), + (14500, 'Linux Kernel Crypto API (2.4)', 0, 0), (14600, 'LUKS 10', 0, 1), (14700, 'iTunes Backup < 10.0 11', 0, 1), (14800, 'iTunes Backup >= 10.0 11', 0, 1), @@ -508,11 +548,13 @@ INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) V (15100, 'Juniper/NetBSD sha1crypt', 0, 1), (15200, 'Blockchain, My Wallet, V2', 0, 0), (15300, 'DPAPI masterkey file v1 and v2', 0, 1), + (15310, 'DPAPI masterkey file v1 (context 3)', 0, 1), (15400, 'ChaCha20', 0, 0), (15500, 'JKS Java Key Store Private Keys (SHA1)', 0, 0), (15600, 'Ethereum Wallet, PBKDF2-HMAC-SHA256', 0, 1), (15700, 'Ethereum Wallet, SCRYPT', 0, 0), (15900, 'DPAPI master key file version 2 + Active Directory domain context', 0, 1), + (15910, 'DPAPI masterkey file v2 (context 3)', 0, 1), (16000, 'Tripcode', 0, 0), (16100, 'TACACS+', 0, 0), (16200, 'Apple Secure Notes', 0, 1), @@ -524,6 +566,7 @@ INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) V (16800, 'WPA-PMKID-PBKDF2', 0, 1), (16801, 'WPA-PMKID-PMK', 0, 1), (16900, 'Ansible Vault', 0, 1), + (17010, 'GPG (AES-128/AES-256 (SHA-1($pass)))', 0, 1), (17200, 'PKZIP (Compressed)', 0, 0), (17210, 'PKZIP (Uncompressed)', 0, 0), (17220, 'PKZIP (Compressed Multi-File)', 0, 0), @@ -566,6 +609,7 @@ INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) V (20600, 'Oracle Transportation Management (SHA256)', 0, 0), (20710, 'sha256(sha256($pass).$salt)', 1, 0), (20711, 'AuthMe sha256', 0, 0), + (20720, 'sha256($salt.sha256($pass))', 1, 0), (20800, 'sha256(md5($pass))', 0, 0), (20900, 'md5(sha1($pass).md5($pass).sha1($pass))', 0, 0), (21000, 'BitShares v0.x - sha512(sha512_bin(pass))', 0, 0), @@ -573,7 +617,9 @@ INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) V (21200, 'md5(sha1($salt).md5($pass))', 1, 0), (21300, 'md5($salt.sha1($salt.$pass))', 1, 0), (21400, 'sha256(sha256_bin(pass))', 0, 0), + (21420, 'sha256($salt.sha256_bin($pass))', 1, 0), (21500, 'SolarWinds Orion', 0, 0), + (21501, 'SolarWinds Orion v2', 0, 0), (21600, 'Web2py pbkdf2-sha512', 0, 0), (21700, 'Electrum Wallet (Salt-Type 4)', 0, 0), (21800, 'Electrum Wallet (Salt-Type 5)', 0, 0), @@ -582,7 +628,140 @@ INSERT INTO `HashType` (`hashTypeId`, `description`, `isSalted`, `isSlowHash`) V (22100, 'BitLocker', 0, 0), (22200, 'Citrix NetScaler (SHA512)', 0, 0), (22300, 'sha256($salt.$pass.$salt)', 1, 0), + (22301, 'Telegram client app passcode (SHA256)', 0, 0), (22400, 'AES Crypt (SHA256)', 0, 0), + (22500, 'MultiBit Classic .key (MD5)', 0, 0), + (22600, 'Telegram Desktop App Passcode (PBKDF2-HMAC-SHA1)', 0, 0), + (22700, 'MultiBit HD (scrypt)', 0, 1), + (22911, 'RSA/DSA/EC/OPENSSH Private Keys ($0$)', 0, 0), + (22921, 'RSA/DSA/EC/OPENSSH Private Keys ($6$)', 0, 0), + (22931, 'RSA/DSA/EC/OPENSSH Private Keys ($1, $3$)', 0, 0), + (22941, 'RSA/DSA/EC/OPENSSH Private Keys ($4$)', 0, 0), + (22951, 'RSA/DSA/EC/OPENSSH Private Keys ($5$)', 0, 0), + (23001, 'SecureZIP AES-128', 0, 0), + (23002, 'SecureZIP AES-192', 0, 0), + (23003, 'SecureZIP AES-256', 0, 0), + (23100, 'Apple Keychain', 0, 1), + (23200, 'XMPP SCRAM PBKDF2-SHA1', 0, 0), + (23300, 'Apple iWork', 0, 0), + (23400, 'Bitwarden', 0, 0), + (23500, 'AxCrypt 2 AES-128', 0, 0), + (23600, 'AxCrypt 2 AES-256', 0, 0), + (23700, 'RAR3-p (Uncompressed)', 0, 0), + (23800, 'RAR3-p (Compressed)', 0, 0), + (23900, 'BestCrypt v3 Volume Encryption', 0, 0), + (24100, 'MongoDB ServerKey SCRAM-SHA-1', 0, 0), + (24200, 'MongoDB ServerKey SCRAM-SHA-256', 0, 0), + (24300, 'sha1($salt.sha1($pass.$salt))', 1, 0), + (24410, 'PKCS#8 Private Keys (PBKDF2-HMAC-SHA1 + 3DES/AES)', 0, 0), + (24420, 'PKCS#8 Private Keys (PBKDF2-HMAC-SHA256 + 3DES/AES)', 0, 0), + (24500, 'Telegram Desktop >= v2.1.14 (PBKDF2-HMAC-SHA512)', 0, 0), + (24600, 'SQLCipher', 0, 0), + (24700, 'Stuffit5', 0, 0), + (24800, 'Umbraco HMAC-SHA1', 0, 0), + (24900, 'Dahua Authentication MD5', 0, 0), + (25000, 'SNMPv3 HMAC-MD5-96/HMAC-SHA1-96', 0, 1), + (25100, 'SNMPv3 HMAC-MD5-96', 0, 1), + (25200, 'SNMPv3 HMAC-SHA1-96', 0, 1), + (25300, 'MS Office 2016 - SheetProtection', 0, 0), + (25400, 'PDF 1.4 - 1.6 (Acrobat 5 - 8) - edit password', 0, 0), + (25500, 'Stargazer Stellar Wallet XLM', 0, 0), + (25600, 'bcrypt(md5($pass)) / bcryptmd5', 0, 1), + (25700, 'MurmurHash', 1, 0), + (25800, 'bcrypt(sha1($pass)) / bcryptsha1', 0, 1), + (25900, 'KNX IP Secure - Device Authentication Code', 0, 0), + (26000, 'Mozilla key3.db', 0, 0), + (26100, 'Mozilla key4.db', 0, 0), + (26200, 'OpenEdge Progress Encode', 0, 0), + (26300, 'FortiGate256 (FortiOS256)', 0, 0), + (26401, 'AES-128-ECB NOKDF (PT = $salt, key = $pass)', 0, 0), + (26402, 'AES-192-ECB NOKDF (PT = $salt, key = $pass)', 0, 0), + (26403, 'AES-256-ECB NOKDF (PT = $salt, key = $pass)', 0, 0), + (26500, 'iPhone passcode (UID key + System Keybag)', 0, 0), + (26600, 'MetaMask Wallet', 0, 1), + (26700, 'SNMPv3 HMAC-SHA224-128', 0, 0), + (26800, 'SNMPv3 HMAC-SHA256-192', 0, 0), + (26900, 'SNMPv3 HMAC-SHA384-256', 0, 0), + (27000, 'NetNTLMv1 / NetNTLMv1+ESS (NT)', 0, 0), + (27100, 'NetNTLMv2 (NT)', 0, 0), + (27200, 'Ruby on Rails Restful Auth (one round, no sitekey)', 1, 0), + (27300, 'SNMPv3 HMAC-SHA512-384', 0, 0), + (27400, 'VMware VMX (PBKDF2-HMAC-SHA1 + AES-256-CBC)', 0, 0), + (27500, 'VirtualBox (PBKDF2-HMAC-SHA256 & AES-128-XTS)', 0, 1), + (27600, 'VirtualBox (PBKDF2-HMAC-SHA256 & AES-256-XTS)', 0, 1), + (27700, 'MultiBit Classic .wallet (scrypt)', 0, 0), + (27800, 'MurmurHash3', 1, 0), + (27900, 'CRC32C', 1, 0), + (28000, 'CRC64Jones', 1, 0), + (28100, 'Windows Hello PIN/Password', 0, 1), + (28200, 'Exodus Desktop Wallet (scrypt)', 0, 0), + (28300, 'Teamspeak 3 (channel hash)', 0, 0), + (28400, 'bcrypt(sha512($pass)) / bcryptsha512', 0, 0), + (28501, 'Bitcoin WIF private key (P2PKH), compressed', 0, 0), + (28502, 'Bitcoin WIF private key (P2PKH), uncompressed', 0, 0), + (28503, 'Bitcoin WIF private key (P2WPKH, Bech32), compressed', 0, 0), + (28504, 'Bitcoin WIF private key (P2WPKH, Bech32), uncompressed', 0, 0), + (28505, 'Bitcoin WIF private key (P2SH(P2WPKH)), compressed', 0, 0), + (28506, 'Bitcoin WIF private key (P2SH(P2WPKH)), uncompressed', 0, 0), + (28600, 'PostgreSQL SCRAM-SHA-256', 0, 1), + (28700, 'Amazon AWS4-HMAC-SHA256', 0, 0), + (28800, 'Kerberos 5, etype 17, DB', 0, 1), + (28900, 'Kerberos 5, etype 18, DB', 0, 1), + (29000, 'sha1($salt.sha1(utf16le($username).'':''.utf16le($pass)))', 0, 0), + (29100, 'Flask Session Cookie ($salt.$salt.$pass)', 0, 0), + (29200, 'Radmin3', 0, 0), + (29311, 'TrueCrypt RIPEMD160 + XTS 512 bit', 0, 0), + (29312, 'TrueCrypt RIPEMD160 + XTS 1024 bit', 0, 0), + (29313, 'TrueCrypt RIPEMD160 + XTS 1536 bit', 0, 0), + (29321, 'TrueCrypt SHA512 + XTS 512 bit', 0, 0), + (29322, 'TrueCrypt SHA512 + XTS 1024 bit', 0, 0), + (29323, 'TrueCrypt SHA512 + XTS 1536 bit', 0, 0), + (29331, 'TrueCrypt Whirlpool + XTS 512 bit', 0, 0), + (29332, 'TrueCrypt Whirlpool + XTS 1024 bit', 0, 0), + (29333, 'TrueCrypt Whirlpool + XTS 1536 bit', 0, 0), + (29341, 'TrueCrypt RIPEMD160 + XTS 512 bit + boot-mode', 0, 0), + (29342, 'TrueCrypt RIPEMD160 + XTS 1024 bit + boot-mode', 0, 0), + (29343, 'TrueCrypt RIPEMD160 + XTS 1536 bit + boot-mode', 0, 0), + (29411, 'VeraCrypt RIPEMD160 + XTS 512 bit', 0, 0), + (29412, 'VeraCrypt RIPEMD160 + XTS 1024 bit', 0, 0), + (29413, 'VeraCrypt RIPEMD160 + XTS 1536 bit', 0, 0), + (29421, 'VeraCrypt SHA512 + XTS 512 bit', 0, 0), + (29422, 'VeraCrypt SHA512 + XTS 1024 bit', 0, 0), + (29423, 'VeraCrypt SHA512 + XTS 1536 bit', 0, 0), + (29431, 'VeraCrypt Whirlpool + XTS 512 bit', 0, 0), + (29432, 'VeraCrypt Whirlpool + XTS 1024 bit', 0, 0), + (29433, 'VeraCrypt Whirlpool + XTS 1536 bit', 0, 0), + (29441, 'VeraCrypt RIPEMD160 + XTS 512 bit + boot-mode', 0, 0), + (29442, 'VeraCrypt RIPEMD160 + XTS 1024 bit + boot-mode', 0, 0), + (29443, 'VeraCrypt RIPEMD160 + XTS 1536 bit + boot-mode', 0, 0), + (29451, 'VeraCrypt SHA256 + XTS 512 bit', 0, 0), + (29452, 'VeraCrypt SHA256 + XTS 1024 bit', 0, 0), + (29453, 'VeraCrypt SHA256 + XTS 1536 bit', 0, 0), + (29461, 'VeraCrypt SHA256 + XTS 512 bit + boot-mode', 0, 0), + (29462, 'VeraCrypt SHA256 + XTS 1024 bit + boot-mode', 0, 0), + (29463, 'VeraCrypt SHA256 + XTS 1536 bit + boot-mode', 0, 0), + (29471, 'VeraCrypt Streebog-512 + XTS 512 bit', 0, 0), + (29472, 'VeraCrypt Streebog-512 + XTS 1024 bit', 0, 0), + (29473, 'VeraCrypt Streebog-512 + XTS 1536 bit', 0, 0), + (29481, 'VeraCrypt Streebog-512 + XTS 512 bit + boot-mode', 0, 0), + (29482, 'VeraCrypt Streebog-512 + XTS 1024 bit + boot-mode', 0, 0), + (29483, 'VeraCrypt Streebog-512 + XTS 1536 bit + boot-mode', 0, 0), + (29511, 'LUKS v1 SHA-1 + AES', 0, 1), + (29512, 'LUKS v1 SHA-1 + Serpent', 0, 1), + (29513, 'LUKS v1 SHA-1 + Twofish', 0, 1), + (29521, 'LUKS v1 SHA-256 + AES', 0, 1), + (29522, 'LUKS v1 SHA-256 + Serpent', 0, 1), + (29523, 'LUKS v1 SHA-256 + Twofish', 0, 1), + (29531, 'LUKS v1 SHA-512 + AES', 0, 1), + (29532, 'LUKS v1 SHA-512 + Serpent', 0, 1), + (29533, 'LUKS v1 SHA-512 + Twofish', 0, 1), + (29541, 'LUKS v1 RIPEMD-160 + AES', 0, 1), + (29542, 'LUKS v1 RIPEMD-160 + Serpent', 0, 1), + (29543, 'LUKS v1 RIPEMD-160 + Twofish', 0, 1), + (29600, 'Terra Station Wallet (AES256-CBC(PBKDF2($pass)))', 0, 1), + (29700, 'KeePass 1 (AES/Twofish) and KeePass 2 (AES) - keyfile only mode', 0, 1), + (30000, 'Python Werkzeug MD5 (HMAC-MD5 (key = $salt))', 0, 0), + (30120, 'Python Werkzeug SHA256 (HMAC-SHA256 (key = $salt))', 0, 0), (99999, 'Plaintext', 0, 0); CREATE TABLE `LogEntry` ( @@ -615,6 +794,7 @@ CREATE TABLE `Pretask` ( `isCpuTask` TINYINT(4) NOT NULL, `useNewBench` TINYINT(4) NOT NULL, `priority` INT(11) NOT NULL, + `maxAgents` INT(11) NOT NULL, `isMaskImport` TINYINT(4) NOT NULL, `crackerBinaryTypeId` INT(11) NOT NULL ) ENGINE = InnoDB; @@ -677,6 +857,7 @@ CREATE TABLE `Task` ( `keyspace` BIGINT(20) NOT NULL, `keyspaceProgress` BIGINT(20) NOT NULL, `priority` INT(11) NOT NULL, + `maxAgents` INT(11) NOT NULL, `color` VARCHAR(20) NULL, `isSmall` TINYINT(4) NOT NULL, `isCpuTask` TINYINT(4) NOT NULL, @@ -733,22 +914,25 @@ CREATE TABLE `User` ( CREATE TABLE `Benchmark` ( `benchmarkId` INT(11) NOT NULL, `benchmarkValue` VARCHAR(256) NOT NULL, - `hardwareGroupId` int(11) NOT NULL, - `attackParameters` VARCHAR(256) NOT NULL, - `ttl` int(11) NOT NULL + `hardwareGroupId` INT(11) NOT NULL, + `crackerBinaryId` INT(11) NOT NULL, + `attackParameters` VARCHAR(512) NOT NULL, + `ttl` int(11) NOT NULL, + `hashMode` int(11) NOT NULL, + `benchmarkType` varchar(10) NOT NULL ) ENGINE = InnoDB; CREATE TABLE `HardwareGroup` ( `hardwareGroupId` INT(11) NOT NULL, - `devices` VARCHAR(256) NOT NULL, + `devices` VARCHAR(65000) NULL ) ENGINE = InnoDB; CREATE TABLE `Zap` ( - `zapId` INT(11) NOT NULL, - `hash` TEXT NOT NULL, - `solveTime` BIGINT NOT NULL, - `agentId` INT(11) NULL, - `hashlistId` INT(11) NOT NULL + `zapId` INT(11) NOT NULL, + `hash` MEDIUMTEXT NOT NULL, + `solveTime` BIGINT NOT NULL, + `agentId` INT(11) NULL, + `hashlistId` INT(11) NOT NULL ) ENGINE = InnoDB; CREATE TABLE `ApiKey` ( @@ -827,16 +1011,13 @@ ALTER TABLE `AccessGroupUser` ADD KEY `accessGroupId` (`accessGroupId`), ADD KEY `userId` (`userId`); +ALTER TABLE `HardwareGroup` + ADD PRIMARY KEY (`hardwareGroupId`); + ALTER TABLE `Agent` ADD PRIMARY KEY (`agentId`), ADD KEY `userId` (`userId`); - -ALTER TABLE `Benchmark` - ADD PRIMARY KEY (`benchmarkId`), - ADD KEY `agentId` (`agentId`); - -ALTER TABLE `HardwareGroup` - ADD PRIMARY KEY (`hardwareGroupId`); + -- ADD KEY `hardwareGroupId` (`hardwareGroupId`); ALTER TABLE `AgentBinary` ADD PRIMARY KEY (`agentBinaryId`); @@ -995,6 +1176,11 @@ ALTER TABLE `Zap` ALTER TABLE `Preprocessor` ADD PRIMARY KEY (`preprocessorId`); +ALTER TABLE `Benchmark` + ADD PRIMARY KEY (`benchmarkId`), + ADD KEY `crackerBinaryId` (`crackerBinaryId`), + ADD KEY `hardwareGroupId` (`hardwareGroupId`); + -- Add AUTO_INCREMENT for tables ALTER TABLE `AccessGroup` MODIFY `accessGroupId` INT(11) NOT NULL AUTO_INCREMENT; @@ -1122,18 +1308,18 @@ ALTER TABLE `TaskWrapper` ALTER TABLE `User` MODIFY `userId` INT(11) NOT NULL AUTO_INCREMENT; -ALTER TABLE `Benchmark` - MODIFY `benchmarkId` INT(11) NOT NULL AUTO_INCREMENT; - -ALTER TABLE `HardwareGroup` - MODIFY `hardwareGroupId` INT(11) NOT NULL AUTO_INCREMENT; - ALTER TABLE `Zap` MODIFY `zapId` INT(11) NOT NULL AUTO_INCREMENT; ALTER TABLE `Preprocessor` MODIFY `preprocessorId` INT(11) NOT NULL AUTO_INCREMENT; +ALTER TABLE `Benchmark` + MODIFY `benchmarkId` INT(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `HardwareGroup` + MODIFY `hardwareGroupId` INT(11) NOT NULL AUTO_INCREMENT; + -- Add Constraints ALTER TABLE `AccessGroupAgent` ADD CONSTRAINT `AccessGroupAgent_ibfk_1` FOREIGN KEY (`accessGroupId`) REFERENCES `AccessGroup` (`accessGroupId`), @@ -1145,6 +1331,7 @@ ALTER TABLE `AccessGroupUser` ALTER TABLE `Agent` ADD CONSTRAINT `Agent_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`); + -- ADD CONSTRAINT `Agent_ibfk_2` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`); ALTER TABLE `AgentError` ADD CONSTRAINT `AgentError_ibfk_1` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`), @@ -1245,7 +1432,8 @@ ALTER TABLE `User` ADD CONSTRAINT `User_ibfk_1` FOREIGN KEY (`rightGroupId`) REFERENCES `RightGroup` (`rightGroupId`); ALTER TABLE `Benchmark` - ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`HardwareGroupId`) REFERENCES `Agent` (`hardwareGroupId`); + ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`), + ADD CONSTRAINT `Benchmark_ibfk_2` FOREIGN KEY (`crackerBinaryId`) REFERENCES `CrackerBinary` (`crackerBinaryId`); ALTER TABLE `Zap` ADD CONSTRAINT `Zap_ibfk_1` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`), diff --git a/ci/tests/BenchmarkTest.class.php b/ci/tests/BenchmarkTest.class.php new file mode 100644 index 000000000..51de74e23 --- /dev/null +++ b/ci/tests/BenchmarkTest.class.php @@ -0,0 +1,115 @@ +getTestName() . "..."); + parent::init($version); + } + + public function run() { + HashtopolisTestFramework::log(HashtopolisTestFramework::LOG_INFO, "Running " . $this->getTestName() . "..."); + $this->createAgentWithHardwareGroup(); + $this->testAddToCache(); + $this->testGetFromCache(); + $this->testDeleteCache(); + $this->testTtl(); + HashtopolisTestFramework::log(HashtopolisTestFramework::LOG_INFO, $this->getTestName() . " completed"); + } + + public function getTestName() { + return "Benchmark Test"; + } + + private function createAgentWithHardwareGroup() { + $agent = new Agent(100, "testAgent", "ebfc57ec-2d6f-4a60-932d-60f127dbb2a8",0, null, "", 0, 1, 0, "TeStToKeN0", "sendProgress", + 1683904809, "127.0.0.1", 1, 0, "s3-python-0.7.1"); + $agentSameHardware = new Agent(101, "testAgent2", "ebfc57ec-2d6f-4a60-932d-60f127dbb2a9",0, null, "", 0, 1, 0, "TeStToKeN1", "sendProgress", + 1683904809, "127.0.0.2", 1, 0, "s3-python-0.7.1"); + $agentDifferentHardware = new Agent(102, "testAgent3", "ebfc57ec-2d6f-4a60-932d-60f127dbb2b8",0, null, "", 0, 1, 0, "TeStToKeN2", "sendProgress", + 1683904809, "127.0.0.3", 1, 0, "s3-python-0.7.1"); + + Factory::getAgentFactory()->save($agent); + Factory::getAgentFactory()->save($agentSameHardware); + Factory::getAgentFactory()->save($agentDifferentHardware); + + $agent = HardwareGroupUtils::updateHardwareOfAgent("11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz", $agent); + $agentSameHardware = HardwareGroupUtils::updateHardwareOfAgent("11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz", $agentSameHardware); + $agentDifferentHardware = HardwareGroupUtils::updateHardwareOfAgent("10th Gen Intel(R) Core(TM) i6-1165G7 @ 2.80GHz", $agentDifferentHardware); + + if ($agent->getHardwareGroupId() != $agentSameHardware->getHardwareGroupId()) { + $this->testFailed("BenchmarkTest:createAgentWithHardwareGroup", "Agents with the same hardware are not added to the same hardwareGroup! + Agent1 hardwaregroup id: " . $agent->getHardwareGroupId() . "Agent2 hardwareGroupId: " . $agentSameHardware->getHardwareGroupId()); + } + if ($agent->getHardwareGroupId() == $agentDifferentHardware->getHardwareGroupId()) { + $this->testFailed("BenchmarkTest:createAgentWithHardwareGroup", "Agents with different hardware are added to the same hardwareGroup! + Agent1 hardwaregroup id: " . $agent->getHardwareGroupId() . "Agent2 hardwareGroupId: " . $agentDifferentHardware->getHardwareGroupId()); + } + + $this->agent = $agent; //save agent for future tests + $this->testSuccess("BenchmarkTest:createAgentWithHardwareGroup"); + } + + private function testAddToCache(){ + + $benchmark = BenchmarkUtils::saveBenchmarkInCache("#HL# -a 3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(), "676:1.78", 1000, "speed", 1); + + if(!isset($benchmark)) { + $this->testFailed("BenchmarkTest:testAddToCache", "Cannot add benchmark to cache"); + } else { + $this->testSuccess("BenchmarkTest:testAddToCache"); + } + } + + private function testGetFromCache(){ + $benchmark = BenchmarkUtils::getBenchmarkByValue("#HL# -a 3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(), 1000, 1, 1); + + if(!isset($benchmark)) { + $this->testFailed("BenchmarkTest:testGetFromCache", "Cannot get benchmark from cache in normal situation"); + } else { + $this->testSuccess("BenchmarkTest:testGetFromCache"); + } + + $benchmark2 = BenchmarkUtils::getBenchmarkByValue("#HL# -a3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(),1000, 1, 1); + $benchmark3 = BenchmarkUtils::getBenchmarkByValue("#HL# -d 1 --attack-mode 3 ?l?l?l?l --force", $this->agent->getHardwareGroupId(),1000, 1, 1); + $benchmark4 = BenchmarkUtils::getBenchmarkByValue("#HL# --force -a3 ?l?l?l?l -d 1", $this->agent->getHardwareGroupId(), 1000, 1, 1); + + if(!isset($benchmark2) || !isset($benchmark3) || !isset($benchmark4)) { + $this->testFailed("BenchmarkTest:testGetFromCache", "Cannot get benchmark from cache with parsing commandline in different formats"); + } else { + $this->testSuccess("BenchmarkTest:testGetFromCache"); + } + } + + private function testDeleteCache() { + BenchmarkUtils::deleteCache(); + $benchmark = BenchmarkUtils::getBenchmarkByValue(1000, "#HL# -a 3 ?l?l?l?l -d 1 --force", 1, "1", 0); + if(isset($benchmark)) { + $this->testFailed("BenchmarkTest:testDeleteCache", "There is still a value in the cache!"); + } else { + $this->testSuccess("BenchmarkTest:testDeleteCache"); + } + } + + private function testTtl() { + $benchmark = new Benchmark(3, "speed", "1234:88","#HL# -a 3 ?u?u?u", 200, 1, time() - 10, 1); //ttl in the past to test invalid ttl + Factory::getBenchmarkFactory()->save($benchmark); + $found = BenchmarkUtils::getBenchmarkByValue("#HL# -a 3 ?u?u?u", 1, 200, 1, 1); + if($found != null) { + $this->testFailed("BenchmarkTest:testTtl", "benchmark with ttl in the past should not be valid!"); + } else { + $this->testSuccess("BenchmarkTest:testTtl"); + } + } +} + +HashtopolisTestFramework::register(new BenchmarkTest()); diff --git a/src/inc/api/APISendBenchmark.class.php b/src/inc/api/APISendBenchmark.class.php index 6ccd836fa..18d76c826 100644 --- a/src/inc/api/APISendBenchmark.class.php +++ b/src/inc/api/APISendBenchmark.class.php @@ -79,11 +79,9 @@ public function execute($QUERY = array()) { Factory::getAssignmentFactory()->update($assignment); // save benchmark in cache - $hardwareGroup = Factory::getHardwareGroupFactory()->get($this->agent->getHardwareGroupId()); - $hashlist = Factory::getHashlistFactory()->get($taskWrapper->getHashlistId()); - BenchmarkUtils::saveBenchmarkInCache($task->getAttackCmd(), $hardwareGroup, $benchmark, $hashlist->getHashTypeId(), $type, $task->getCrackerBinaryId()); + BenchmarkUtils::saveBenchmarkInCache($task->getAttackCmd(), $this->agent->getHardwareGroupId(), $benchmark, $hashlist->getHashTypeId(), $type, $task->getCrackerBinaryId()); DServerLog::log(DServerLog::DEBUG, "Saved agent benchmark", [$this->agent, $task, $assignment]); $this->sendResponse(array( diff --git a/src/inc/utils/BenchmarkUtils.class.php b/src/inc/utils/BenchmarkUtils.class.php index 8d7c315a5..acb8ba6bc 100644 --- a/src/inc/utils/BenchmarkUtils.class.php +++ b/src/inc/utils/BenchmarkUtils.class.php @@ -161,12 +161,18 @@ public static function deleteBenchmark($benchmark) return true; } - public static function saveBenchmarkInCache($attackParameters, $hardwareGroup, $benchmarkValue, $hashmode, $benchmarkType, $crackerBinaryId) + public static function saveBenchmarkInCache($attackParameters, $hardwareGroupId, $benchmarkValue, $hashmode, $benchmarkType, $crackerBinaryId) { + $hardwareGroup = Factory::getHardwareGroupFactory()->get($hardwareGroupId); + + if (!isset($hardwareGroup)) { + return null; + } + $cleanAttackParameters = self::cleanupAttackParameters($attackParameters); $qF = new QueryFilter("attackParameters", $cleanAttackParameters, "="); - $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroup->getId(), "="); + $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroupId, "="); $foundBenchmark = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2]], true); @@ -175,7 +181,7 @@ public static function saveBenchmarkInCache($attackParameters, $hardwareGroup, $ $foundBenchmark->setBenchmarkValue($benchmarkValue); $benchmark = Factory::getBenchmarkFactory()->update($foundBenchmark); } else { - $newBenchmark = new Benchmark(null, $benchmarkType, $benchmarkValue, $cleanAttackParameters, $hashmode, $hardwareGroup->getID(), time() + ttl, $crackerBinaryId); + $newBenchmark = new Benchmark(null, $benchmarkType, $benchmarkValue, $cleanAttackParameters, $hashmode, $hardwareGroupId, time() + ttl, $crackerBinaryId); $benchmark = Factory::getBenchmarkFactory()->save($newBenchmark); } From 8be58e59739330bc6e5469d09d95044b64e897d9 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Tue, 18 Jul 2023 06:14:24 -0400 Subject: [PATCH 34/55] Fixed bug where hardware wasnt properly shown in agent detail page --- src/agents.php | 2 +- src/templates/agents/detail.template.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/agents.php b/src/agents.php index 7e9a1e452..7aee6d6d6 100755 --- a/src/agents.php +++ b/src/agents.php @@ -70,7 +70,7 @@ foreach ($tmp_devices_tuple as $key => $value) { $devices_tuple[] = str_replace("*", "  ", sprintf("%'*2d× ", $value) . $key); } - $hardwareGroup->setDevices(implode("\n", $devices_tuple)); + $agent->setHardwareGroupId(implode("\n", $devices_tuple)); UI::add('agent', $agent); UI::add('users', Factory::getUserFactory()->filter([])); diff --git a/src/templates/agents/detail.template.html b/src/templates/agents/detail.template.html index ba036d301..b40a7a580 100644 --- a/src/templates/agents/detail.template.html +++ b/src/templates/agents/detail.template.html @@ -126,7 +126,7 @@

Agent details

- + From 91330dffc838c13cf0862fa1c54a6777eb6cbd87 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Tue, 18 Jul 2023 10:19:57 -0400 Subject: [PATCH 35/55] Added the needed utils to the run.php test file --- ci/run.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ci/run.php b/ci/run.php index be903f482..ef1bb6085 100644 --- a/ci/run.php +++ b/ci/run.php @@ -11,6 +11,11 @@ require_once(dirname(__FILE__) . "/../src/inc/Util.class.php"); require_once(dirname(__FILE__) . "/../src/inc/Encryption.class.php"); require_once(dirname(__FILE__) . "/../src/inc/utils/AccessUtils.class.php"); +require_once(dirname(__FILE__) . "/../src/inc/utils/BenchmarkUtils.class.php"); +require_once(dirname(__FILE__) . "/../src/inc/utils/HardwareGroupUtils.class.php"); +require_once(dirname(__FILE__) . "/../src/inc/SConfig.class.php"); +require_once(dirname(__FILE__) . "/../src/inc/Dataset.class.php"); + require_once(dirname(__FILE__) . "/HashtopolisTest.class.php"); require_once(dirname(__FILE__) . "/HashtopolisTestFramework.class.php"); From 929350b5933906b0887aead2e32a9c86f0fd86cf Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Thu, 20 Jul 2023 14:52:00 -0400 Subject: [PATCH 36/55] Added the benchmark cache to the menu --- src/templates/struct/menu.template.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/templates/struct/menu.template.html b/src/templates/struct/menu.template.html index ddbe694b6..45385d761 100755 --- a/src/templates/struct/menu.template.html +++ b/src/templates/struct/menu.template.html @@ -16,9 +16,12 @@ {{IF [[accessControl.hasPermission([[$DAccessControl::CREATE_AGENT_ACCESS]])]]}} New Agent {{ENDIF}} - {{IF [[accessControl.hasPermission([[$DAccessControl::VIEW_AGENT_ACCESS]])]]}} + {{IF [[accessControl.hasPermission([[$DAccessControl::VIEW_AGENT_ACCESS]])]]}} Agent Status {{ENDIF}} + {{IF [[accessControl.hasPermission([[$DAccessControl::VIEW_BENCHMARK_ACCESS]])]]}} + Benchmark cache + {{ENDIF}} {{ENDIF}} From 973d64d826c69c5409460550282c69bae37edfff Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Tue, 25 Jul 2023 06:28:39 -0400 Subject: [PATCH 37/55] Removed accidently created files --- src/dba/models/AbstractModel.template.txt.txt | 46 ----------- .../AbstractModelFactory.template.txt.txt | 82 ------------------- 2 files changed, 128 deletions(-) delete mode 100644 src/dba/models/AbstractModel.template.txt.txt delete mode 100644 src/dba/models/AbstractModelFactory.template.txt.txt diff --git a/src/dba/models/AbstractModel.template.txt.txt b/src/dba/models/AbstractModel.template.txt.txt deleted file mode 100644 index 340b2c8e4..000000000 --- a/src/dba/models/AbstractModel.template.txt.txt +++ /dev/null @@ -1,46 +0,0 @@ -__MODEL_PK__; - } - - function getId() { - return $this->__MODEL_PK__; - } - - function setId($id) { - $this->__MODEL_PK__ = $id; - } - - /** - * Used to serialize the data contained in the model - * @return array - */ - public function expose() { - return get_object_vars($this); - } - - __MODEL_GETTER_SETTER__ - - __MODEL_VARIABLE_NAMES__ -} diff --git a/src/dba/models/AbstractModelFactory.template.txt.txt b/src/dba/models/AbstractModelFactory.template.txt.txt deleted file mode 100644 index 86169b5b5..000000000 --- a/src/dba/models/AbstractModelFactory.template.txt.txt +++ /dev/null @@ -1,82 +0,0 @@ - Date: Tue, 25 Jul 2023 06:32:44 -0400 Subject: [PATCH 38/55] Removed more accidently created files --- src/dba/models/Factory.template.txt.txt | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 src/dba/models/Factory.template.txt.txt diff --git a/src/dba/models/Factory.template.txt.txt b/src/dba/models/Factory.template.txt.txt deleted file mode 100644 index 1dca8550f..000000000 --- a/src/dba/models/Factory.template.txt.txt +++ /dev/null @@ -1,15 +0,0 @@ - Date: Thu, 27 Jul 2023 12:05:19 -0400 Subject: [PATCH 39/55] Removed old comments --- src/inc/api/APIGetChunk.class.php | 1 - src/inc/utils/BenchmarkUtils.class.php | 6 -- .../updates/update_v0.14.x_v0.14.0.php | 72 +++++++++---------- 3 files changed, 36 insertions(+), 43 deletions(-) diff --git a/src/inc/api/APIGetChunk.class.php b/src/inc/api/APIGetChunk.class.php index b0f5edd40..2d42cbe68 100644 --- a/src/inc/api/APIGetChunk.class.php +++ b/src/inc/api/APIGetChunk.class.php @@ -55,7 +55,6 @@ public function execute($QUERY = array()) { ); } else if ($assignment->getBenchmark() == 0 && $task->getIsSmall() == 0 && $task->getStaticChunks() == DTaskStaticChunking::NORMAL) { // benchmark only required on non-small tasks and on non-special chunk tasks - //toegevoegde code voor cache $taskWrapper = Factory::getTaskWrapperFactory()->get($task->getTaskWrapperId()); $hashlist = Factory::getHashlistFactory()->get($taskWrapper->getHashlistId()); diff --git a/src/inc/utils/BenchmarkUtils.class.php b/src/inc/utils/BenchmarkUtils.class.php index acb8ba6bc..9994ced31 100644 --- a/src/inc/utils/BenchmarkUtils.class.php +++ b/src/inc/utils/BenchmarkUtils.class.php @@ -6,12 +6,6 @@ use DBA\Benchmark; define("ttl", 216000); -// define("size", 50); - -// enum BenchmarkType { -// case SpeedBenchmark; -// case RuntimeBenchmark; -// } class BenchmarkUtils { diff --git a/src/install/updates/update_v0.14.x_v0.14.0.php b/src/install/updates/update_v0.14.x_v0.14.0.php index 92397a4a0..32ccee2a7 100644 --- a/src/install/updates/update_v0.14.x_v0.14.0.php +++ b/src/install/updates/update_v0.14.x_v0.14.0.php @@ -12,42 +12,42 @@ } //change Agent table -Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` - DROP COLUMN devices; -"); -Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` - ADD COLUMN hardwareGroupId INT(11) DEFAULT NULL; -"); -Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); - - -if (!Util::databaseTableExists("Benchmark")) { - Factory::getAgentFactory()->getDB()->query("CREATE TABLE `Benchmark` ( - `benchmarkId` INT(11) NOT NULL, - `benchmarkValue` VARCHAR(256) NOT NULL, - `hardwareGroupId` INT(11) NOT NULL, - `crackerBinaryId` INT(11) NOT NULL, - `attackParameters` VARCHAR(512) NOT NULL, - `ttl` INT(11) NULL, - `hashMode` INT(11) NULL, - `benchmarkType` VARCHAR(10) NULL - ) ENGINE=InnoDB;" - ); - - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` MODIFY `benchmarkId` int(11) NOT NULL AUTO_INCREMENT;"); - - Factory::getAgentFactory()->getDB()->query(" - ALTER TABLE `Benchmark` - ADD PRIMARY KEY (`benchmarkId`);"); - // ADD KEY `hardwareGroupId` (`hardwareGroupId`);"); - - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` - ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); -} - -// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT `Agent_ibfk_2` +// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` +// DROP COLUMN devices; +// "); +// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` +// ADD COLUMN hardwareGroupId INT(11) DEFAULT NULL; +// "); +// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); + + +// if (!Util::databaseTableExists("Benchmark")) { +// Factory::getAgentFactory()->getDB()->query("CREATE TABLE `Benchmark` ( +// `benchmarkId` INT(11) NOT NULL, +// `benchmarkValue` VARCHAR(256) NOT NULL, +// `hardwareGroupId` INT(11) NOT NULL, +// `crackerBinaryId` INT(11) NOT NULL, +// `attackParameters` VARCHAR(512) NOT NULL, +// `ttl` INT(11) NULL, +// `hashMode` INT(11) NULL, +// `benchmarkType` VARCHAR(10) NULL +// ) ENGINE=InnoDB;" +// ); + +// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` MODIFY `benchmarkId` int(11) NOT NULL AUTO_INCREMENT;"); + +// Factory::getAgentFactory()->getDB()->query(" +// ALTER TABLE `Benchmark` +// ADD PRIMARY KEY (`benchmarkId`);"); +// // ADD KEY `hardwareGroupId` (`hardwareGroupId`);"); + +// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` +// ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); +// } + +// // Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT `Agent_ibfk_2` +// // FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); +// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` ADD CONSTRAINT `Benchmark_ibfk_1` // FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); -Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` ADD CONSTRAINT `Benchmark_ibfk_1` - FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); ?> \ No newline at end of file From d15498cc81a0844733f7cfcdfc3779defeb1b85f Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Fri, 11 Aug 2023 03:27:09 -0400 Subject: [PATCH 40/55] Updated codestyle in benchmarkUtils --- src/inc/utils/BenchmarkUtils.class.php | 30 +++++++++----------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/inc/utils/BenchmarkUtils.class.php b/src/inc/utils/BenchmarkUtils.class.php index 9994ced31..b431bf5b0 100644 --- a/src/inc/utils/BenchmarkUtils.class.php +++ b/src/inc/utils/BenchmarkUtils.class.php @@ -7,11 +7,9 @@ define("ttl", 216000); -class BenchmarkUtils -{ +class BenchmarkUtils { - public static function getBenchmark($benchmarkId) - { + public static function getBenchmark($benchmarkId) { $benchmark = Factory::getBenchmarkFactory()->get($benchmarkId); if ($benchmark == null) { throw new HTException("Invalid benchmark ID!"); @@ -19,14 +17,12 @@ public static function getBenchmark($benchmarkId) return $benchmark; } - public static function delete($benchmarkId) - { + public static function delete($benchmarkId) { $benchmark = BenchmarkUtils::getBenchmark($benchmarkId); Factory::getBenchmarkFactory()->delete($benchmark); } - static function cleanupAttackParameters($attackCmd) - { + static function cleanupAttackParameters($attackCmd) { $attackCmd = trim($attackCmd); if (strlen($attackCmd) == 0) { @@ -116,8 +112,7 @@ static function cleanupAttackParameters($attackCmd) return $cleanAttackCmd; } - public static function getBenchmarkByValue($attackParameters, $hardwareGroupId, $hashmode, $useNewBenchmark, $crackerBinaryId) - { + public static function getBenchmarkByValue($attackParameters, $hardwareGroupId, $hashmode, $useNewBenchmark, $crackerBinaryId) { $hardwareGroup = Factory::getHardwareGroupFactory()->get($hardwareGroupId); $crackerBinary = Factory::getCrackerBinaryFactory()->get($crackerBinaryId); @@ -149,14 +144,12 @@ public static function getBenchmarkByValue($attackParameters, $hardwareGroupId, return $res; } - public static function deleteBenchmark($benchmark) - { + public static function deleteBenchmark($benchmark) { Factory::getBenchmarkFactory()->delete($benchmark); return true; } - public static function saveBenchmarkInCache($attackParameters, $hardwareGroupId, $benchmarkValue, $hashmode, $benchmarkType, $crackerBinaryId) - { + public static function saveBenchmarkInCache($attackParameters, $hardwareGroupId, $benchmarkValue, $hashmode, $benchmarkType, $crackerBinaryId) { $hardwareGroup = Factory::getHardwareGroupFactory()->get($hardwareGroupId); if (!isset($hardwareGroup)) { @@ -183,20 +176,17 @@ public static function saveBenchmarkInCache($attackParameters, $hardwareGroupId, } //removes all values where the time to live has been exceeded - public static function refreshCache() - { + public static function refreshCache() { $qF = new QueryFilter("ttl", time(), "<"); Factory::getFileTaskFactory()->massDeletion([Factory::FILTER => $qF]); } //removes all values in cache - public static function deleteCache() - { + public static function deleteCache() { Factory::getBenchmarkFactory()->massDeletion([]); } - public static function getCacheOfAgent($agentID) - { + public static function getCacheOfAgent($agentID) { $qF = new QueryFilter("agentID", $agentID, "="); $oF = new OrderFilter(ttl, "DESC"); From ecff047b4afc9a83292ac63ad97e9888da1655e7 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Fri, 11 Aug 2023 03:52:25 -0400 Subject: [PATCH 41/55] Added docStrings in benchmarkUtils --- src/inc/utils/BenchmarkUtils.class.php | 51 ++++++++++++++++++-------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/src/inc/utils/BenchmarkUtils.class.php b/src/inc/utils/BenchmarkUtils.class.php index b431bf5b0..8a28f93be 100644 --- a/src/inc/utils/BenchmarkUtils.class.php +++ b/src/inc/utils/BenchmarkUtils.class.php @@ -9,6 +9,10 @@ class BenchmarkUtils { + /** + * @param int $benchmarkId + * @throws HTException + */ public static function getBenchmark($benchmarkId) { $benchmark = Factory::getBenchmarkFactory()->get($benchmarkId); if ($benchmark == null) { @@ -17,11 +21,22 @@ public static function getBenchmark($benchmarkId) { return $benchmark; } + /** + * @param int $benchmarkId + * @throws HTException + */ public static function delete($benchmarkId) { $benchmark = BenchmarkUtils::getBenchmark($benchmarkId); + if ($benchmark == null) { + throw new HTException("Invalid benchmark ID!"); + } Factory::getBenchmarkFactory()->delete($benchmark); } + /** + * @param string $attackCmd + * @throws HTException + */ static function cleanupAttackParameters($attackCmd) { $attackCmd = trim($attackCmd); @@ -112,12 +127,22 @@ static function cleanupAttackParameters($attackCmd) { return $cleanAttackCmd; } + /** + * @param string $attackParameters + * @param int $hardwareGroupId + * @param int $hashmode + * @param string $useNewBenchmark + * @param int $crackerBinaryId + */ public static function getBenchmarkByValue($attackParameters, $hardwareGroupId, $hashmode, $useNewBenchmark, $crackerBinaryId) { $hardwareGroup = Factory::getHardwareGroupFactory()->get($hardwareGroupId); $crackerBinary = Factory::getCrackerBinaryFactory()->get($crackerBinaryId); - if (!isset($hardwareGroup) || !isset($crackerBinary)) { - return null; + if ($hardwareGroup == null) { + throw new HTException("Invallid hardwareGroupId!"); + } + if ($crackerBinary == null) { + throw new HTException("Invallid crackerBinaryId!"); } $cleanAttackParameter = self::cleanupAttackParameters($attackParameters); @@ -144,11 +169,15 @@ public static function getBenchmarkByValue($attackParameters, $hardwareGroupId, return $res; } - public static function deleteBenchmark($benchmark) { - Factory::getBenchmarkFactory()->delete($benchmark); - return true; - } - + /** + * @param string $attackParamters + * @param int $hardwareGroupId + * @param string $benchmarkValue + * @param int $hashmode + * @param string $benchmarkType + * @param int $crackerBinaryId + * @throws HTException + */ public static function saveBenchmarkInCache($attackParameters, $hardwareGroupId, $benchmarkValue, $hashmode, $benchmarkType, $crackerBinaryId) { $hardwareGroup = Factory::getHardwareGroupFactory()->get($hardwareGroupId); @@ -185,12 +214,4 @@ public static function refreshCache() { public static function deleteCache() { Factory::getBenchmarkFactory()->massDeletion([]); } - - public static function getCacheOfAgent($agentID) { - $qF = new QueryFilter("agentID", $agentID, "="); - $oF = new OrderFilter(ttl, "DESC"); - - $benchmarks = Factory::getBenchmarkFactory()->filter([Factory::FILTER => $qF, Factory::ORDER => $oF]); - return $benchmarks; - } } From 502dbe17bb09fe4ad3fdb7ce04923315837d7e50 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Fri, 11 Aug 2023 06:53:32 -0400 Subject: [PATCH 42/55] Made the update script working --- .../updates/update_v0.14.x_v0.14.0.php | 81 +++++++++---------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/install/updates/update_v0.14.x_v0.14.0.php b/src/install/updates/update_v0.14.x_v0.14.0.php index 32ccee2a7..706a18c6a 100644 --- a/src/install/updates/update_v0.14.x_v0.14.0.php +++ b/src/install/updates/update_v0.14.x_v0.14.0.php @@ -1,53 +1,52 @@ getDB()->query("CREATE TABLE `HardwareGroup` ( `hardwareGroupId` INT(11) NOT NULL, `devices` VARCHAR(65000) NOT NULL ) ENGINE=InnoDB;" ); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` + ADD PRIMARY KEY (`hardwareGroupId`); + "); + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` MODIFY `hardwareGroupId` int(11) NOT NULL AUTO_INCREMENT;"); - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` ADD PRIMARY KEY (`hardwareGroupId`);"); -} -//change Agent table -// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` -// DROP COLUMN devices; -// "); -// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` -// ADD COLUMN hardwareGroupId INT(11) DEFAULT NULL; -// "); -// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); - - -// if (!Util::databaseTableExists("Benchmark")) { -// Factory::getAgentFactory()->getDB()->query("CREATE TABLE `Benchmark` ( -// `benchmarkId` INT(11) NOT NULL, -// `benchmarkValue` VARCHAR(256) NOT NULL, -// `hardwareGroupId` INT(11) NOT NULL, -// `crackerBinaryId` INT(11) NOT NULL, -// `attackParameters` VARCHAR(512) NOT NULL, -// `ttl` INT(11) NULL, -// `hashMode` INT(11) NULL, -// `benchmarkType` VARCHAR(10) NULL -// ) ENGINE=InnoDB;" -// ); - -// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` MODIFY `benchmarkId` int(11) NOT NULL AUTO_INCREMENT;"); - -// Factory::getAgentFactory()->getDB()->query(" -// ALTER TABLE `Benchmark` -// ADD PRIMARY KEY (`benchmarkId`);"); -// // ADD KEY `hardwareGroupId` (`hardwareGroupId`);"); - -// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` -// ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); -// } - -// // Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT `Agent_ibfk_2` -// // FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); -// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` ADD CONSTRAINT `Benchmark_ibfk_1` -// FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); + //change Agent table + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` + DROP COLUMN devices; + "); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` + ADD COLUMN hardwareGroupId INT(11) DEFAULT NULL; + "); + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); + + Factory::getAgentFactory()->getDB()->query("CREATE TABLE `Benchmark` ( + `benchmarkId` INT(11) NOT NULL, + `benchmarkValue` VARCHAR(256) NOT NULL, + `hardwareGroupId` INT(11) NOT NULL, + `crackerBinaryId` INT(11) NOT NULL, + `attackParameters` VARCHAR(512) NOT NULL, + `ttl` INT(11) NULL, + `hashMode` INT(11) NULL, + `benchmarkType` VARCHAR(10) NULL + ) ENGINE=InnoDB;" + ); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` + ADD PRIMARY KEY (`benchmarkId`), + ADD KEY `crackerBinaryId` (`crackerBinaryId`), + ADD KEY `hardwareGroupId` (`hardwareGroupId`);"); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` MODIFY `benchmarkId` int(11) NOT NULL AUTO_INCREMENT;"); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` + ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); + + $EXECUTED["v0.14.x_benchmark_cache"] = true; +} ?> \ No newline at end of file From a1b04d6c6c7e0e23adf41cc96ecabd3add915b6e Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Fri, 11 Aug 2023 07:26:39 -0400 Subject: [PATCH 43/55] removed comments from install script and renamed update script to correct format --- src/install/hashtopolis.sql | 7 +++---- ...pdate_v0.14.x_v0.14.0.php => update_v0.14.x_v0.x.x.php} | 0 2 files changed, 3 insertions(+), 4 deletions(-) rename src/install/updates/{update_v0.14.x_v0.14.0.php => update_v0.14.x_v0.x.x.php} (100%) diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index 7246637ad..b5760d92e 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -1017,8 +1017,7 @@ ALTER TABLE `HardwareGroup` ALTER TABLE `Agent` ADD PRIMARY KEY (`agentId`), ADD KEY `userId` (`userId`); - -- ADD KEY `hardwareGroupId` (`hardwareGroupId`); - + ALTER TABLE `AgentBinary` ADD PRIMARY KEY (`agentBinaryId`); @@ -1330,8 +1329,8 @@ ALTER TABLE `AccessGroupUser` ADD CONSTRAINT `AccessGroupUser_ibfk_2` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`); ALTER TABLE `Agent` - ADD CONSTRAINT `Agent_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`); - -- ADD CONSTRAINT `Agent_ibfk_2` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`); + ADD CONSTRAINT `Agent_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `User` (`userId`), + ADD CONSTRAINT `Agent_ibfk_2` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`); ALTER TABLE `AgentError` ADD CONSTRAINT `AgentError_ibfk_1` FOREIGN KEY (`agentId`) REFERENCES `Agent` (`agentId`), diff --git a/src/install/updates/update_v0.14.x_v0.14.0.php b/src/install/updates/update_v0.14.x_v0.x.x.php similarity index 100% rename from src/install/updates/update_v0.14.x_v0.14.0.php rename to src/install/updates/update_v0.14.x_v0.x.x.php From 2d1364000fb35ac529ba72b707fa01ec9d7bbf6a Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Wed, 16 Aug 2023 05:17:05 -0400 Subject: [PATCH 44/55] Made benchmarkcache ttl conifgurable by using the configs --- src/inc/defines/config.php | 5 +++++ src/inc/utils/BenchmarkUtils.class.php | 9 ++++----- src/install/hashtopolis.sql | 3 ++- src/install/updates/update_v0.14.x_v0.x.x.php | 5 ++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/inc/defines/config.php b/src/inc/defines/config.php index b72d25672..4b4b498fb 100644 --- a/src/inc/defines/config.php +++ b/src/inc/defines/config.php @@ -54,6 +54,7 @@ class DConfig { const HASHCAT_BRAIN_PASS = "hashcatBrainPass"; const HASHLIST_IMPORT_CHECK = "hashlistImportCheck"; const HC_ERROR_IGNORE = "hcErrorIgnore"; + const BENCHMARKCACHE_TTL = "benchmarkcacheTtl"; // Section: Yubikey const YUBIKEY_ID = "yubikey_id"; @@ -272,6 +273,8 @@ public static function getConfigType($config) { return DConfigType::TICKBOX; case DConfig::HC_ERROR_IGNORE: return DConfigType::STRING_INPUT; + case DConfig::BENCHMARKCACHE_TTL: + return DConfigType::NUMBER_INPUT; } return DConfigType::STRING_INPUT; } @@ -406,6 +409,8 @@ public static function getConfigDescription($config) { return "Also send 'isComplete' for each task on the User API when listing all tasks (might affect performance)"; case DConfig::HC_ERROR_IGNORE: return "Ignore error messages from crackers which contain given strings (multiple values separated by comma)"; + case DConfig::BENCHMARKCACHE_TTL: + return "The time to live of the cached benchmarks in seconds (set to 0 to turn off caching)"; } return $config; } diff --git a/src/inc/utils/BenchmarkUtils.class.php b/src/inc/utils/BenchmarkUtils.class.php index 8a28f93be..c2f657669 100644 --- a/src/inc/utils/BenchmarkUtils.class.php +++ b/src/inc/utils/BenchmarkUtils.class.php @@ -2,11 +2,8 @@ use DBA\Factory; use DBA\QueryFilter; -use DBA\OrderFilter; use DBA\Benchmark; -define("ttl", 216000); - class BenchmarkUtils { /** @@ -186,6 +183,7 @@ public static function saveBenchmarkInCache($attackParameters, $hardwareGroupId, } $cleanAttackParameters = self::cleanupAttackParameters($attackParameters); + $ttl = SConfig::getInstance()->getVal(DConfig::BENCHMARKCACHE_TTL); $qF = new QueryFilter("attackParameters", $cleanAttackParameters, "="); $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroupId, "="); @@ -193,11 +191,12 @@ public static function saveBenchmarkInCache($attackParameters, $hardwareGroupId, $foundBenchmark = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2]], true); if (isset($foundBenchmark)) { //if benchmark already in cache, update the value - $foundBenchmark->setTtl(time() + ttl); + + $foundBenchmark->setTtl(time() + $ttl); $foundBenchmark->setBenchmarkValue($benchmarkValue); $benchmark = Factory::getBenchmarkFactory()->update($foundBenchmark); } else { - $newBenchmark = new Benchmark(null, $benchmarkType, $benchmarkValue, $cleanAttackParameters, $hashmode, $hardwareGroupId, time() + ttl, $crackerBinaryId); + $newBenchmark = new Benchmark(null, $benchmarkType, $benchmarkValue, $cleanAttackParameters, $hashmode, $hardwareGroupId, time() + $ttl, $crackerBinaryId); $benchmark = Factory::getBenchmarkFactory()->save($newBenchmark); } diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index b5760d92e..447a4b985 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -170,7 +170,8 @@ INSERT INTO `Config` (`configId`, `configSectionId`, `item`, `value`) VALUES (74, 4, 'agentUtilThreshold1', '90'), (75, 4, 'agentUtilThreshold2', '75'), (76, 3, 'uApiSendTaskIsComplete', '0'), - (77, 1, 'hcErrorIgnore', 'DeviceGetFanSpeed'); + (77, 1, 'hcErrorIgnore', 'DeviceGetFanSpeed'), + (78, 1, 'benchmarkcacheTtl', '216000'); CREATE TABLE `ConfigSection` ( `configSectionId` INT(11) NOT NULL, diff --git a/src/install/updates/update_v0.14.x_v0.x.x.php b/src/install/updates/update_v0.14.x_v0.x.x.php index 706a18c6a..ba84df3fb 100644 --- a/src/install/updates/update_v0.14.x_v0.x.x.php +++ b/src/install/updates/update_v0.14.x_v0.x.x.php @@ -45,7 +45,10 @@ Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); - + + Factory::getAgentFactory()->getDB()->query("INSERT INTO `Config` (`configId`, `configSectionId`, `item`, `value`) VALUES + (78, 1, 'benchmarkcacheTtl', '216000');"); + $EXECUTED["v0.14.x_benchmark_cache"] = true; } From 5b769de05fb79bad67d776676b6d1d9d8db31dea Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Mon, 21 Aug 2023 05:02:01 -0400 Subject: [PATCH 45/55] Added efault hardwaregroup so that foreignkey constraint wouldnt fail when creating new agent --- src/install/hashtopolis.sql | 3 + src/install/updates/update_v0.14.x_v0.x.x.php | 101 +++++++++--------- 2 files changed, 55 insertions(+), 49 deletions(-) diff --git a/src/install/hashtopolis.sql b/src/install/hashtopolis.sql index 447a4b985..3cbeb1e07 100644 --- a/src/install/hashtopolis.sql +++ b/src/install/hashtopolis.sql @@ -928,6 +928,9 @@ CREATE TABLE `HardwareGroup` ( `devices` VARCHAR(65000) NULL ) ENGINE = InnoDB; +INSERT INTO `HardwareGroup` (`hardwareGroupId`, `devices`) VALUES + (0, 'Default'); + CREATE TABLE `Zap` ( `zapId` INT(11) NOT NULL, `hash` MEDIUMTEXT NOT NULL, diff --git a/src/install/updates/update_v0.14.x_v0.x.x.php b/src/install/updates/update_v0.14.x_v0.x.x.php index ba84df3fb..50a0f2f12 100644 --- a/src/install/updates/update_v0.14.x_v0.x.x.php +++ b/src/install/updates/update_v0.14.x_v0.x.x.php @@ -1,55 +1,58 @@ getDB()->query("CREATE TABLE `HardwareGroup` ( - `hardwareGroupId` INT(11) NOT NULL, - `devices` VARCHAR(65000) NOT NULL - ) ENGINE=InnoDB;" - ); +// if (!isset($PRESENT["v0.14.x_benchmark_cache"])) { +// Factory::getAgentFactory()->getDB()->query("CREATE TABLE `HardwareGroup` ( +// `hardwareGroupId` INT(11) NOT NULL, +// `devices` VARCHAR(65000) NOT NULL +// ) ENGINE=InnoDB;" +// ); - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` - ADD PRIMARY KEY (`hardwareGroupId`); - "); - - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` MODIFY `hardwareGroupId` int(11) NOT NULL AUTO_INCREMENT;"); - - //change Agent table - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` - DROP COLUMN devices; - "); - - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` - ADD COLUMN hardwareGroupId INT(11) DEFAULT NULL; - "); - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); - - Factory::getAgentFactory()->getDB()->query("CREATE TABLE `Benchmark` ( - `benchmarkId` INT(11) NOT NULL, - `benchmarkValue` VARCHAR(256) NOT NULL, - `hardwareGroupId` INT(11) NOT NULL, - `crackerBinaryId` INT(11) NOT NULL, - `attackParameters` VARCHAR(512) NOT NULL, - `ttl` INT(11) NULL, - `hashMode` INT(11) NULL, - `benchmarkType` VARCHAR(10) NULL - ) ENGINE=InnoDB;" - ); - - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` - ADD PRIMARY KEY (`benchmarkId`), - ADD KEY `crackerBinaryId` (`crackerBinaryId`), - ADD KEY `hardwareGroupId` (`hardwareGroupId`);"); - - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` MODIFY `benchmarkId` int(11) NOT NULL AUTO_INCREMENT;"); - - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` - ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); - - Factory::getAgentFactory()->getDB()->query("INSERT INTO `Config` (`configId`, `configSectionId`, `item`, `value`) VALUES - (78, 1, 'benchmarkcacheTtl', '216000');"); - - $EXECUTED["v0.14.x_benchmark_cache"] = true; -} +// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` +// ADD PRIMARY KEY (`hardwareGroupId`); +// "); + +// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` MODIFY `hardwareGroupId` int(11) NOT NULL AUTO_INCREMENT;"); + +// //change Agent table +// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` +// DROP COLUMN devices; +// "); + +// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` +// ADD COLUMN hardwareGroupId INT(11) DEFAULT NULL; +// "); +// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); + +// Factory::getAgentFactory()->getDB()->query("CREATE TABLE `Benchmark` ( +// `benchmarkId` INT(11) NOT NULL, +// `benchmarkValue` VARCHAR(256) NOT NULL, +// `hardwareGroupId` INT(11) NOT NULL, +// `crackerBinaryId` INT(11) NOT NULL, +// `attackParameters` VARCHAR(512) NOT NULL, +// `ttl` INT(11) NULL, +// `hashMode` INT(11) NULL, +// `benchmarkType` VARCHAR(10) NULL +// ) ENGINE=InnoDB;" +// ); + +// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` +// ADD PRIMARY KEY (`benchmarkId`), +// ADD KEY `crackerBinaryId` (`crackerBinaryId`), +// ADD KEY `hardwareGroupId` (`hardwareGroupId`);"); + +// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` MODIFY `benchmarkId` int(11) NOT NULL AUTO_INCREMENT;"); + +// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` +// ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); + +// Factory::getAgentFactory()->getDB()->query("INSERT INTO `Config` (`configId`, `configSectionId`, `item`, `value`) VALUES +// (78, 1, 'benchmarkcacheTtl', '216000');"); + +// Factory::getAgentFactory()->getDB()->query("INSERT INTO `HardwareGroup` (`hardwareGroupId`, `devices`) VALUES +// (0, 'Default');"); + +// $EXECUTED["v0.14.x_benchmark_cache"] = true; +// } ?> \ No newline at end of file From 7b31337d3864e3a9512360215199e49ab4a26324 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Mon, 21 Aug 2023 05:09:55 -0400 Subject: [PATCH 46/55] Added default hardwaregroup so that foreignkey constraint wouldnt fail when creating new agent --- src/install/updates/update_v0.14.x_v0.x.x.php | 104 +++++++++--------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/src/install/updates/update_v0.14.x_v0.x.x.php b/src/install/updates/update_v0.14.x_v0.x.x.php index 50a0f2f12..2cc0b9310 100644 --- a/src/install/updates/update_v0.14.x_v0.x.x.php +++ b/src/install/updates/update_v0.14.x_v0.x.x.php @@ -1,58 +1,58 @@ getDB()->query("CREATE TABLE `HardwareGroup` ( -// `hardwareGroupId` INT(11) NOT NULL, -// `devices` VARCHAR(65000) NOT NULL -// ) ENGINE=InnoDB;" -// ); +if (!isset($PRESENT["v0.14.x_benchmark_cache"])) { + Factory::getAgentFactory()->getDB()->query("CREATE TABLE `HardwareGroup` ( + `hardwareGroupId` INT(11) NOT NULL, + `devices` VARCHAR(65000) NOT NULL + ) ENGINE=InnoDB;" + ); -// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` -// ADD PRIMARY KEY (`hardwareGroupId`); -// "); - -// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` MODIFY `hardwareGroupId` int(11) NOT NULL AUTO_INCREMENT;"); - -// //change Agent table -// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` -// DROP COLUMN devices; -// "); - -// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` -// ADD COLUMN hardwareGroupId INT(11) DEFAULT NULL; -// "); -// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); - -// Factory::getAgentFactory()->getDB()->query("CREATE TABLE `Benchmark` ( -// `benchmarkId` INT(11) NOT NULL, -// `benchmarkValue` VARCHAR(256) NOT NULL, -// `hardwareGroupId` INT(11) NOT NULL, -// `crackerBinaryId` INT(11) NOT NULL, -// `attackParameters` VARCHAR(512) NOT NULL, -// `ttl` INT(11) NULL, -// `hashMode` INT(11) NULL, -// `benchmarkType` VARCHAR(10) NULL -// ) ENGINE=InnoDB;" -// ); - -// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` -// ADD PRIMARY KEY (`benchmarkId`), -// ADD KEY `crackerBinaryId` (`crackerBinaryId`), -// ADD KEY `hardwareGroupId` (`hardwareGroupId`);"); - -// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` MODIFY `benchmarkId` int(11) NOT NULL AUTO_INCREMENT;"); - -// Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` -// ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); - -// Factory::getAgentFactory()->getDB()->query("INSERT INTO `Config` (`configId`, `configSectionId`, `item`, `value`) VALUES -// (78, 1, 'benchmarkcacheTtl', '216000');"); - -// Factory::getAgentFactory()->getDB()->query("INSERT INTO `HardwareGroup` (`hardwareGroupId`, `devices`) VALUES -// (0, 'Default');"); - -// $EXECUTED["v0.14.x_benchmark_cache"] = true; -// } + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` + ADD PRIMARY KEY (`hardwareGroupId`); + "); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` MODIFY `hardwareGroupId` int(11) NOT NULL AUTO_INCREMENT;"); + + //change Agent table + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` + DROP COLUMN devices; + "); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` + ADD COLUMN hardwareGroupId INT(11) DEFAULT NULL; + "); + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); + + Factory::getAgentFactory()->getDB()->query("CREATE TABLE `Benchmark` ( + `benchmarkId` INT(11) NOT NULL, + `benchmarkValue` VARCHAR(256) NOT NULL, + `hardwareGroupId` INT(11) NOT NULL, + `crackerBinaryId` INT(11) NOT NULL, + `attackParameters` VARCHAR(512) NOT NULL, + `ttl` INT(11) NULL, + `hashMode` INT(11) NULL, + `benchmarkType` VARCHAR(10) NULL + ) ENGINE=InnoDB;" + ); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` + ADD PRIMARY KEY (`benchmarkId`), + ADD KEY `crackerBinaryId` (`crackerBinaryId`), + ADD KEY `hardwareGroupId` (`hardwareGroupId`);"); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` MODIFY `benchmarkId` int(11) NOT NULL AUTO_INCREMENT;"); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` + ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); + + Factory::getAgentFactory()->getDB()->query("INSERT INTO `Config` (`configId`, `configSectionId`, `item`, `value`) VALUES + (78, 1, 'benchmarkcacheTtl', '216000');"); + + Factory::getAgentFactory()->getDB()->query("INSERT INTO `HardwareGroup` (`hardwareGroupId`, `devices`) VALUES + (0, 'Default');"); + + $EXECUTED["v0.14.x_benchmark_cache"] = true; +} ?> \ No newline at end of file From 864693eb442812d1cbb6f04bbd33c5a6954a172f Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Mon, 21 Aug 2023 07:10:44 -0400 Subject: [PATCH 47/55] Added the option to disable caching by setting ttl to 0 --- src/inc/api/APIGetChunk.class.php | 5 +++-- src/inc/api/APISendBenchmark.class.php | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/inc/api/APIGetChunk.class.php b/src/inc/api/APIGetChunk.class.php index 2d42cbe68..530078375 100644 --- a/src/inc/api/APIGetChunk.class.php +++ b/src/inc/api/APIGetChunk.class.php @@ -58,9 +58,10 @@ public function execute($QUERY = array()) { $taskWrapper = Factory::getTaskWrapperFactory()->get($task->getTaskWrapperId()); $hashlist = Factory::getHashlistFactory()->get($taskWrapper->getHashlistId()); - + $ttl = SConfig::getInstance()->getVal(DConfig::BENCHMARKCACHE_TTL); $benchmark = BenchmarkUtils::getBenchmarkByValue($task->getAttackCmd(), $this->agent->getHardwareGroupId(), $hashlist->getHashTypeId(), $task->getUseNewBench(), $task->getCrackerBinaryId()); - if ($benchmark === NULL) { + + if ($benchmark === NULL || $ttl == 0) { DServerLog::log(DServerLog::INFO, "Need to run a benchmark!", [$this->agent, $task]); $this->sendResponse(array( PResponseGetChunk::ACTION => PActions::GET_CHUNK, diff --git a/src/inc/api/APISendBenchmark.class.php b/src/inc/api/APISendBenchmark.class.php index 06f760866..37b685aad 100644 --- a/src/inc/api/APISendBenchmark.class.php +++ b/src/inc/api/APISendBenchmark.class.php @@ -78,10 +78,13 @@ public function execute($QUERY = array()) { $assignment->setBenchmark($benchmark); Factory::getAssignmentFactory()->update($assignment); - // save benchmark in cache - $hashlist = Factory::getHashlistFactory()->get($taskWrapper->getHashlistId()); + // save benchmark in cache if cache ttl is higher than 0 + $ttl = SConfig::getInstance()->getVal(DConfig::BENCHMARKCACHE_TTL); - BenchmarkUtils::saveBenchmarkInCache($task->getAttackCmd(), $this->agent->getHardwareGroupId(), $benchmark, $hashlist->getHashTypeId(), $type, $task->getCrackerBinaryId()); + if ($ttl != 0) { + $hashlist = Factory::getHashlistFactory()->get($taskWrapper->getHashlistId()); + BenchmarkUtils::saveBenchmarkInCache($task->getAttackCmd(), $this->agent->getHardwareGroupId(), $benchmark, $hashlist->getHashTypeId(), $type, $task->getCrackerBinaryId()); + } DServerLog::log(DServerLog::DEBUG, "Saved agent benchmark", [$this->agent, $task, $assignment]); $this->sendResponse(array( From 580a08db12b6a7b0a427f51730924e65c0e53b75 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Wed, 23 Aug 2023 02:57:29 -0400 Subject: [PATCH 48/55] Added the changes to the changelog --- doc/changelog.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/changelog.md b/doc/changelog.md index c5ae3b5de..890631094 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -3,6 +3,14 @@ ## Bugfixes - Clicking pretask in Supertask create screen now directs correctly to the pretask and not a task with the same id (#945) +## Benchmark cache system +A cache for the benchmarks so that benchmarks can be reused and the benchmark process can be skipped when the benchmark has already been cached. +Key components: + +- Added a benchmark model. The benchmark model got a field for all the dependencies of the benchmark output. These are the benchmark type (speed or runtime), the cracker binary, the hardware that is used, the attack parameters and the hashmode. +- Agents are split up into hardware groups, so that benchmark can be linked to a hardwaregroup and not a single agent. +- Benchmarks get invalidated by a time to live. +- frontend for the benchmarks in /benchmark.php to show what has been cached and to manually remove values. # v0.13.1 -> v0.14.0 From 3849695e9c9013a04c64b29a5b3619f13b34aa46 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Wed, 23 Aug 2023 03:08:49 -0400 Subject: [PATCH 49/55] cleaned up benchmark handler --- src/inc/handlers/BenchmarkHandler.class.php | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/inc/handlers/BenchmarkHandler.class.php b/src/inc/handlers/BenchmarkHandler.class.php index 4ffde5255..72a2254b6 100644 --- a/src/inc/handlers/BenchmarkHandler.class.php +++ b/src/inc/handlers/BenchmarkHandler.class.php @@ -1,28 +1,15 @@ agent = null; - return; - } - - $this->agent = Factory::getAgentFactory()->get($agentId); - if ($this->agent == null) { - UI::printError("FATAL", "Agent with ID $agentId not found!"); - } +class BenchmarkHandler implements Handler { + public function __construct($benchmarkId = null) { + //we need nothing to load } + public function handle($action) { try { switch ($action) { case DBenchmarkAction::DELETE_BENCHMARK: AccessControl::getInstance()->checkPermission(DBenchmarkAction::DELETE_BENCHMARK); - $benchId = $_POST['benchmarkId']; BenchmarkUtils::delete($_POST['benchmarkId']); break; default: From cdcecc337afe3ab1dfd52dd25c17bd1c9b96155d Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Fri, 25 Aug 2023 04:54:17 -0400 Subject: [PATCH 50/55] Updated code based on code review --- src/benchmark.php | 16 +-- src/dba/models/HardwareGroupFactory.class.php | 2 +- .../api/APIUpdateClientInformation.class.php | 2 - src/inc/defines/accessControl.php | 4 +- src/inc/defines/config.php | 6 +- src/inc/handlers/BenchmarkHandler.class.php | 3 +- src/inc/utils/BenchmarkUtils.class.php | 26 ++--- src/inc/utils/HardwareGroupUtils.class.php | 6 +- src/install/updates/update_v0.14.x_v0.x.x.php | 106 +++++++++--------- src/templates/benchmarks/index.template.html | 10 +- src/templates/struct/menu.template.html | 6 +- 11 files changed, 86 insertions(+), 101 deletions(-) diff --git a/src/benchmark.php b/src/benchmark.php index 9ea013617..e1578707c 100644 --- a/src/benchmark.php +++ b/src/benchmark.php @@ -15,6 +15,8 @@ AccessControl::getInstance()->checkPermission(DViewControl::AGENTS_VIEW_PERM); +Menu::get()->setActive("benchmark_cache"); + if (isset($_POST['action']) && CSRF::check($_POST['csrf'])) { $benchmarkHandler = new BenchmarkHandler(); $benchmarkHandler->handle($_POST['action']); @@ -23,20 +25,6 @@ } } -if (isset($_GET['id'])) { - //go to detail page - // Template::loadInstance("benchmark/detail"); - $agent = Factory::getAgentFactory()->get($_GET['id']); - if (!$agent) { - UI::printError("ERROR", "Agent not found!"); - } else { - $qF = new QueryFilter("agentId", $agent->getId(), "="); - $benchmarks = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF]]); - } -} else { - $benchmarks = Factory::getBenchmarkFactory()->filter([]); -} - $oF = new OrderFilter(CrackerBinary::CRACKER_BINARY_ID, "DESC"); $versions = Factory::getCrackerBinaryFactory()->filter([Factory::ORDER => $oF]); usort($versions, ["Util", "versionComparisonBinary"]); diff --git a/src/dba/models/HardwareGroupFactory.class.php b/src/dba/models/HardwareGroupFactory.class.php index 3a7370117..b879a91ba 100644 --- a/src/dba/models/HardwareGroupFactory.class.php +++ b/src/dba/models/HardwareGroupFactory.class.php @@ -33,7 +33,7 @@ function getNullObject() { * @return HardwareGroup */ function createObjectFromDict($pk, $dict) { - $o = new HardwareGroup($dict['hardwareGroupId'], $dict['devices'], $dict['benchmarkId']); + $o = new HardwareGroup($dict['hardwareGroupId'], $dict['devices']); return $o; } diff --git a/src/inc/api/APIUpdateClientInformation.class.php b/src/inc/api/APIUpdateClientInformation.class.php index b11580fca..8946cd672 100644 --- a/src/inc/api/APIUpdateClientInformation.class.php +++ b/src/inc/api/APIUpdateClientInformation.class.php @@ -31,8 +31,6 @@ public function execute($QUERY = array()) { } Factory::getAgentFactory()->mset($this->agent, [ - //change to hardware group - // Agent::DEVICES => htmlentities(implode("\n", $devices), ENT_QUOTES, "UTF-8"), Agent::UID => $uid, Agent::OS => $os ] diff --git a/src/inc/defines/accessControl.php b/src/inc/defines/accessControl.php index c4ebe0445..5c70a0038 100644 --- a/src/inc/defines/accessControl.php +++ b/src/inc/defines/accessControl.php @@ -26,8 +26,8 @@ class DAccessControl { const SERVER_CONFIG_ACCESS = "serverConfigAccess"; const USER_CONFIG_ACCESS = "userConfigAccess"; const MANAGE_ACCESS_GROUP_ACCESS = "manageAccessGroupAccess"; - const VIEW_BENCHMARK_ACCESS = "ViewBenchmarkAccess"; - const DELETE_BENCHMARK_ACCESS = "DeleteBenchmarkAccess"; + const VIEW_BENCHMARK_ACCESS = "ViewBenchmarkAccess"; + const DELETE_BENCHMARK_ACCESS = "DeleteBenchmarkAccess"; // special access definitions for public access pages and pages which are viewable if logged in const PUBLIC_ACCESS = "publicAccess"; diff --git a/src/inc/defines/config.php b/src/inc/defines/config.php index 4b4b498fb..b33b66d6b 100644 --- a/src/inc/defines/config.php +++ b/src/inc/defines/config.php @@ -54,7 +54,7 @@ class DConfig { const HASHCAT_BRAIN_PASS = "hashcatBrainPass"; const HASHLIST_IMPORT_CHECK = "hashlistImportCheck"; const HC_ERROR_IGNORE = "hcErrorIgnore"; - const BENCHMARKCACHE_TTL = "benchmarkcacheTtl"; + const BENCHMARKCACHE_TTL = "benchmarkcacheTtl"; // Section: Yubikey const YUBIKEY_ID = "yubikey_id"; @@ -409,8 +409,8 @@ public static function getConfigDescription($config) { return "Also send 'isComplete' for each task on the User API when listing all tasks (might affect performance)"; case DConfig::HC_ERROR_IGNORE: return "Ignore error messages from crackers which contain given strings (multiple values separated by comma)"; - case DConfig::BENCHMARKCACHE_TTL: - return "The time to live of the cached benchmarks in seconds (set to 0 to turn off caching)"; + case DConfig::BENCHMARKCACHE_TTL: + return "The time to live of the cached benchmarks in seconds (set to 0 to turn off caching)"; } return $config; } diff --git a/src/inc/handlers/BenchmarkHandler.class.php b/src/inc/handlers/BenchmarkHandler.class.php index 72a2254b6..687b77dcd 100644 --- a/src/inc/handlers/BenchmarkHandler.class.php +++ b/src/inc/handlers/BenchmarkHandler.class.php @@ -1,9 +1,8 @@ get($crackerBinaryId); if ($hardwareGroup == null) { - throw new HTException("Invallid hardwareGroupId!"); + throw new HTException("Invalid hardwareGroupId!"); } if ($crackerBinary == null) { - throw new HTException("Invallid crackerBinaryId!"); + throw new HTException("Invalid crackerBinaryId!"); } $cleanAttackParameter = self::cleanupAttackParameters($attackParameters); - $qF = new QueryFilter("attackParameters", $cleanAttackParameter, "="); - $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroup->getId(), "="); - $qF3 = new QueryFilter("hashMode", $hashmode, "="); + $qF1 = new QueryFilter(Benchmark::ATTACK_PARAMETERS, $cleanAttackParameter, "="); + $qF2 = new QueryFilter(Benchmark::HARDWARE_GROUP_ID, $hardwareGroup->getId(), "="); + $qF3 = new QueryFilter(Benchmark::HASH_MODE, $hashmode, "="); $benchmarkType = $useNewBenchmark == 1 ? "speed" : "runtime"; - $qF4 = new QueryFilter("benchmarkType", $benchmarkType, "="); - $qF5 = new QueryFilter("crackerBinaryId", $crackerBinary->getId(), "="); + $qF4 = new QueryFilter(Benchmark::BENCHMARK_TYPE, $benchmarkType, "="); + $qF5 = new QueryFilter(Benchmark::CRACKER_BINARY_ID, $crackerBinary->getId(), "="); - $res = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2, $qF3, $qF4, $qF5]], true); + $res = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF1, $qF2, $qF3, $qF4, $qF5]], true); if (isset($res)) { if ($res->getTtl() < time()) { // if ttl has been exceeded, remove value and return null @@ -185,10 +185,10 @@ public static function saveBenchmarkInCache($attackParameters, $hardwareGroupId, $cleanAttackParameters = self::cleanupAttackParameters($attackParameters); $ttl = SConfig::getInstance()->getVal(DConfig::BENCHMARKCACHE_TTL); - $qF = new QueryFilter("attackParameters", $cleanAttackParameters, "="); - $qF2 = new QueryFilter("hardwareGroupId", $hardwareGroupId, "="); + $qF1 = new QueryFilter(Benchmark::ATTACK_PARAMETERS, $cleanAttackParameters, "="); + $qF2 = new QueryFilter(Benchmark::HARDWARE_GROUP_ID, $hardwareGroupId, "="); - $foundBenchmark = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF, $qF2]], true); + $foundBenchmark = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF1, $qF2]], true); if (isset($foundBenchmark)) { //if benchmark already in cache, update the value @@ -205,8 +205,8 @@ public static function saveBenchmarkInCache($attackParameters, $hardwareGroupId, //removes all values where the time to live has been exceeded public static function refreshCache() { - $qF = new QueryFilter("ttl", time(), "<"); - Factory::getFileTaskFactory()->massDeletion([Factory::FILTER => $qF]); + $qF = new QueryFilter(Benchmark::TTL, time(), "<"); + Factory::getBenchmarkFactory()->massDeletion([Factory::FILTER => $qF]); } //removes all values in cache diff --git a/src/inc/utils/HardwareGroupUtils.class.php b/src/inc/utils/HardwareGroupUtils.class.php index 1be209a33..3884330ad 100644 --- a/src/inc/utils/HardwareGroupUtils.class.php +++ b/src/inc/utils/HardwareGroupUtils.class.php @@ -7,7 +7,7 @@ class HardwareGroupUtils { public static function updateHardwareOfAgent($devices, $agent) { - $qF = new QueryFilter("devices", $devices, "="); + $qF = new QueryFilter(HardwareGroup::DEVICES, $devices, "="); $res = Factory::getHardwareGroupFactory()->filter([Factory::FILTER => [$qF]], true); @@ -24,13 +24,13 @@ public static function updateHardwareOfAgent($devices, $agent) { } public static function getDevicesFromBenchmark($benchmark) { - $qF = new QueryFilter("HardwareGroupId", $benchmark->getHardwareGroupId(), "="); + $qF = new QueryFilter(HardwareGroup::HARDWARE_GROUP_ID, $benchmark->getHardwareGroupId(), "="); $res = Factory::getHardwareGroupFactory()->filter([Factory::FILTER => [$qF]], true); return $res->getDevices(); } public static function getHardwareGroupByDevices($devices) { - $qF = new QueryFilter("devices", $devices, "="); + $qF = new QueryFilter(HardwareGroup::DEVICES, $devices, "="); $res = Factory::getHardwareGroupFactory()->filter([Factory::FILTER => [$qF]], true); return $res; diff --git a/src/install/updates/update_v0.14.x_v0.x.x.php b/src/install/updates/update_v0.14.x_v0.x.x.php index 2cc0b9310..e88334086 100644 --- a/src/install/updates/update_v0.14.x_v0.x.x.php +++ b/src/install/updates/update_v0.14.x_v0.x.x.php @@ -2,57 +2,57 @@ use DBA\Factory; if (!isset($PRESENT["v0.14.x_benchmark_cache"])) { - Factory::getAgentFactory()->getDB()->query("CREATE TABLE `HardwareGroup` ( - `hardwareGroupId` INT(11) NOT NULL, - `devices` VARCHAR(65000) NOT NULL - ) ENGINE=InnoDB;" - ); - - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` - ADD PRIMARY KEY (`hardwareGroupId`); - "); - - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` MODIFY `hardwareGroupId` int(11) NOT NULL AUTO_INCREMENT;"); - - //change Agent table - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` - DROP COLUMN devices; - "); - - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` - ADD COLUMN hardwareGroupId INT(11) DEFAULT NULL; - "); - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); - - Factory::getAgentFactory()->getDB()->query("CREATE TABLE `Benchmark` ( - `benchmarkId` INT(11) NOT NULL, - `benchmarkValue` VARCHAR(256) NOT NULL, - `hardwareGroupId` INT(11) NOT NULL, - `crackerBinaryId` INT(11) NOT NULL, - `attackParameters` VARCHAR(512) NOT NULL, - `ttl` INT(11) NULL, - `hashMode` INT(11) NULL, - `benchmarkType` VARCHAR(10) NULL + if (!Util::databaseTableExists("HardwareGroup")) { + Factory::getAgentFactory()->getDB()->query("CREATE TABLE `HardwareGroup` ( + `hardwareGroupId` INT(11) NOT NULL, + `devices` VARCHAR(65000) NOT NULL ) ENGINE=InnoDB;" - ); - - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` - ADD PRIMARY KEY (`benchmarkId`), - ADD KEY `crackerBinaryId` (`crackerBinaryId`), - ADD KEY `hardwareGroupId` (`hardwareGroupId`);"); - - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` MODIFY `benchmarkId` int(11) NOT NULL AUTO_INCREMENT;"); - - Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` - ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); - - Factory::getAgentFactory()->getDB()->query("INSERT INTO `Config` (`configId`, `configSectionId`, `item`, `value`) VALUES - (78, 1, 'benchmarkcacheTtl', '216000');"); - - Factory::getAgentFactory()->getDB()->query("INSERT INTO `HardwareGroup` (`hardwareGroupId`, `devices`) VALUES - (0, 'Default');"); - - $EXECUTED["v0.14.x_benchmark_cache"] = true; -} - -?> \ No newline at end of file + ); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` + ADD PRIMARY KEY (`hardwareGroupId`); + "); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `HardwareGroup` MODIFY `hardwareGroupId` int(11) NOT NULL AUTO_INCREMENT;"); + + //change Agent table + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` + DROP COLUMN devices; + "); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` + ADD COLUMN hardwareGroupId INT(11) DEFAULT NULL; + "); + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Agent` ADD CONSTRAINT FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); + + Factory::getAgentFactory()->getDB()->query("CREATE TABLE `Benchmark` ( + `benchmarkId` INT(11) NOT NULL, + `benchmarkValue` VARCHAR(256) NOT NULL, + `hardwareGroupId` INT(11) NOT NULL, + `crackerBinaryId` INT(11) NOT NULL, + `attackParameters` VARCHAR(512) NOT NULL, + `ttl` INT(11) NULL, + `hashMode` INT(11) NULL, + `benchmarkType` VARCHAR(10) NULL + ) ENGINE=InnoDB;" + ); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` + ADD PRIMARY KEY (`benchmarkId`), + ADD KEY `crackerBinaryId` (`crackerBinaryId`), + ADD KEY `hardwareGroupId` (`hardwareGroupId`);"); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` MODIFY `benchmarkId` int(11) NOT NULL AUTO_INCREMENT;"); + + Factory::getAgentFactory()->getDB()->query("ALTER TABLE `Benchmark` + ADD CONSTRAINT `Benchmark_ibfk_1` FOREIGN KEY (`hardwareGroupId`) REFERENCES `HardwareGroup` (`hardwareGroupId`);"); + + Factory::getAgentFactory()->getDB()->query("INSERT INTO `Config` (`configId`, `configSectionId`, `item`, `value`) VALUES + (78, 1, 'benchmarkcacheTtl', '216000');"); + + Factory::getAgentFactory()->getDB()->query("INSERT INTO `HardwareGroup` (`hardwareGroupId`, `devices`) VALUES + (0, 'Default');"); + + $EXECUTED["v0.14.x_benchmark_cache"] = true; + } +} \ No newline at end of file diff --git a/src/templates/benchmarks/index.template.html b/src/templates/benchmarks/index.template.html index 32083bfb5..3adf0199b 100644 --- a/src/templates/benchmarks/index.template.html +++ b/src/templates/benchmarks/index.template.html @@ -3,7 +3,7 @@

Benchmarks ([[numBenchmarks]])

{%TEMPLATE->struct/messages%}
-
+ @@ -15,14 +15,14 @@

Benchmarks ([[numBenchmarks]])

Benchmark idBenchmark CmdBenchmark HashmodeidCmdHashmodeCracker Binary CPU/GPU Benchmark value ttl [[benchmark.getId()]] [[benchmark.getAttackParameters()]] [[benchmark.getHashMode()]][[benchmark.getCrackerBinaryId()]] [[str_replace("\n","
",[[benchmark.getHardwareGroupId()]])]]
[[benchmark.getBenchmarkValue()]] [[date([[config.getVal(DConfig::TIME_FORMAT)]], [[benchmark.getTtl()]])]]
Graphic cards:[[str_replace("\n","
",[[hardwareGroup.getDevices()]])]]
[[str_replace("\n","
",[[agent.getHardwareGroupId()]])]]
Member of access groups:
- - + + - - + + diff --git a/src/templates/struct/menu.template.html b/src/templates/struct/menu.template.html index 45385d761..863ca3987 100755 --- a/src/templates/struct/menu.template.html +++ b/src/templates/struct/menu.template.html @@ -19,9 +19,9 @@ {{IF [[accessControl.hasPermission([[$DAccessControl::VIEW_AGENT_ACCESS]])]]}} Agent Status {{ENDIF}} - {{IF [[accessControl.hasPermission([[$DAccessControl::VIEW_BENCHMARK_ACCESS]])]]}} - Benchmark cache - {{ENDIF}} + {{IF [[accessControl.hasPermission([[$DAccessControl::VIEW_BENCHMARK_ACCESS]])]]}} + Benchmark Cache + {{ENDIF}} {{ENDIF}} From 47984148f3adc1b4d90e602e5abf2a701b4618b3 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Fri, 25 Aug 2023 06:05:06 -0400 Subject: [PATCH 51/55] Added accidently removed code --- src/benchmark.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/benchmark.php b/src/benchmark.php index e1578707c..27aaaa3d9 100644 --- a/src/benchmark.php +++ b/src/benchmark.php @@ -25,6 +25,8 @@ } } +$benchmarks = Factory::getBenchmarkFactory()->filter([]); + $oF = new OrderFilter(CrackerBinary::CRACKER_BINARY_ID, "DESC"); $versions = Factory::getCrackerBinaryFactory()->filter([Factory::ORDER => $oF]); usort($versions, ["Util", "versionComparisonBinary"]); From 5cca11a0ccdd0c8274c06caad9204360924659d8 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Sat, 26 Aug 2023 04:37:22 -0400 Subject: [PATCH 52/55] Made the benchmark cache also use the agent specific CMD parameters --- src/inc/api/APIGetChunk.class.php | 4 +++- src/inc/api/APISendBenchmark.class.php | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/inc/api/APIGetChunk.class.php b/src/inc/api/APIGetChunk.class.php index 530078375..c383a8ade 100644 --- a/src/inc/api/APIGetChunk.class.php +++ b/src/inc/api/APIGetChunk.class.php @@ -59,7 +59,9 @@ public function execute($QUERY = array()) { $hashlist = Factory::getHashlistFactory()->get($taskWrapper->getHashlistId()); $ttl = SConfig::getInstance()->getVal(DConfig::BENCHMARKCACHE_TTL); - $benchmark = BenchmarkUtils::getBenchmarkByValue($task->getAttackCmd(), $this->agent->getHardwareGroupId(), $hashlist->getHashTypeId(), $task->getUseNewBench(), $task->getCrackerBinaryId()); + $attackParameters = $task->getAttackCmd() . " " . $this->agent->getCmdPars(); + + $benchmark = BenchmarkUtils::getBenchmarkByValue($attackParameters, $this->agent->getHardwareGroupId(), $hashlist->getHashTypeId(), $task->getUseNewBench(), $task->getCrackerBinaryId()); if ($benchmark === NULL || $ttl == 0) { DServerLog::log(DServerLog::INFO, "Need to run a benchmark!", [$this->agent, $task]); diff --git a/src/inc/api/APISendBenchmark.class.php b/src/inc/api/APISendBenchmark.class.php index 37b685aad..ba8b5f26f 100644 --- a/src/inc/api/APISendBenchmark.class.php +++ b/src/inc/api/APISendBenchmark.class.php @@ -83,10 +83,12 @@ public function execute($QUERY = array()) { if ($ttl != 0) { $hashlist = Factory::getHashlistFactory()->get($taskWrapper->getHashlistId()); - BenchmarkUtils::saveBenchmarkInCache($task->getAttackCmd(), $this->agent->getHardwareGroupId(), $benchmark, $hashlist->getHashTypeId(), $type, $task->getCrackerBinaryId()); + $attackParameters = $task->getAttackCmd(). " " . $this->agent->getCmdPars(); + + BenchmarkUtils::saveBenchmarkInCache($attackParameters, $this->agent->getHardwareGroupId(), $benchmark, $hashlist->getHashTypeId(), $type, $task->getCrackerBinaryId()); + DServerLog::log(DServerLog::DEBUG, "Saved agent benchmark", [$this->agent, $task, $assignment]); } - DServerLog::log(DServerLog::DEBUG, "Saved agent benchmark", [$this->agent, $task, $assignment]); $this->sendResponse(array( PResponseSendBenchmark::ACTION => PActions::SEND_BENCHMARK, PResponseSendBenchmark::RESPONSE => PValues::SUCCESS, From 5d30ad299d11ef14867eb991c96aa96274e06aa5 Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Sat, 26 Aug 2023 05:37:09 -0400 Subject: [PATCH 53/55] Fixed benchmarktests --- ci/run.php | 1 + ci/tests/BenchmarkTest.class.php | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ci/run.php b/ci/run.php index b0304d0a7..9e3299440 100644 --- a/ci/run.php +++ b/ci/run.php @@ -18,6 +18,7 @@ require_once(dirname(__FILE__) . "/HashtopolisTest.class.php"); require_once(dirname(__FILE__) . "/HashtopolisTestFramework.class.php"); +require_once(dirname(__FILE__) . "/../src/inc/HTException.class.php"); $dir = scandir(dirname(__FILE__) . "/tests/"); foreach ($dir as $entry) { diff --git a/ci/tests/BenchmarkTest.class.php b/ci/tests/BenchmarkTest.class.php index 51de74e23..a54ecebb6 100644 --- a/ci/tests/BenchmarkTest.class.php +++ b/ci/tests/BenchmarkTest.class.php @@ -2,6 +2,7 @@ use DBA\Agent; use DBA\Benchmark; +use DBA\CrackerBinary; use DBA\Factory; class BenchmarkTest extends HashtopolisTest { @@ -10,6 +11,7 @@ class BenchmarkTest extends HashtopolisTest { protected $runType = HashtopolisTest::RUN_FAST; private $agent = null; + private $crackerBinary = null; public function init($version) { HashtopolisTestFramework::log(HashtopolisTestFramework::LOG_INFO, "Initializing " . $this->getTestName() . "..."); @@ -60,18 +62,21 @@ private function createAgentWithHardwareGroup() { } private function testAddToCache(){ - - $benchmark = BenchmarkUtils::saveBenchmarkInCache("#HL# -a 3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(), "676:1.78", 1000, "speed", 1); + $crackerBinary = new CrackerBinary(3036, 1, "6.2.6", "https://hashcat.net/files/hashcat-6.2.6.7z", "hashcat"); + Factory::getCrackerBinaryFactory()->save($crackerBinary); + $benchmark = BenchmarkUtils::saveBenchmarkInCache("#HL# -a 3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(), "676:1.78", 1000, "speed", $crackerBinary->getId()); if(!isset($benchmark)) { $this->testFailed("BenchmarkTest:testAddToCache", "Cannot add benchmark to cache"); } else { $this->testSuccess("BenchmarkTest:testAddToCache"); } + + $this->crackerBinary = $crackerBinary; //save crackerbinary for future tests } private function testGetFromCache(){ - $benchmark = BenchmarkUtils::getBenchmarkByValue("#HL# -a 3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(), 1000, 1, 1); + $benchmark = BenchmarkUtils::getBenchmarkByValue("#HL# -a 3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(), 1000, 1, $this->crackerBinary->getId()); if(!isset($benchmark)) { $this->testFailed("BenchmarkTest:testGetFromCache", "Cannot get benchmark from cache in normal situation"); @@ -79,9 +84,9 @@ private function testGetFromCache(){ $this->testSuccess("BenchmarkTest:testGetFromCache"); } - $benchmark2 = BenchmarkUtils::getBenchmarkByValue("#HL# -a3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(),1000, 1, 1); - $benchmark3 = BenchmarkUtils::getBenchmarkByValue("#HL# -d 1 --attack-mode 3 ?l?l?l?l --force", $this->agent->getHardwareGroupId(),1000, 1, 1); - $benchmark4 = BenchmarkUtils::getBenchmarkByValue("#HL# --force -a3 ?l?l?l?l -d 1", $this->agent->getHardwareGroupId(), 1000, 1, 1); + $benchmark2 = BenchmarkUtils::getBenchmarkByValue("#HL# -a3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(),1000, 1, $this->crackerBinary->getId()); + $benchmark3 = BenchmarkUtils::getBenchmarkByValue("#HL# -d 1 --attack-mode 3 ?l?l?l?l --force", $this->agent->getHardwareGroupId(),1000, 1, $this->crackerBinary->getId()); + $benchmark4 = BenchmarkUtils::getBenchmarkByValue("#HL# --force -a3 ?l?l?l?l -d 1", $this->agent->getHardwareGroupId(), 1000, 1, $this->crackerBinary->getId()); if(!isset($benchmark2) || !isset($benchmark3) || !isset($benchmark4)) { $this->testFailed("BenchmarkTest:testGetFromCache", "Cannot get benchmark from cache with parsing commandline in different formats"); @@ -92,7 +97,7 @@ private function testGetFromCache(){ private function testDeleteCache() { BenchmarkUtils::deleteCache(); - $benchmark = BenchmarkUtils::getBenchmarkByValue(1000, "#HL# -a 3 ?l?l?l?l -d 1 --force", 1, "1", 0); + $benchmark = BenchmarkUtils::getBenchmarkByValue("#HL# -a 3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(), 1000, "1", $this->crackerBinary->getId()); if(isset($benchmark)) { $this->testFailed("BenchmarkTest:testDeleteCache", "There is still a value in the cache!"); } else { @@ -101,9 +106,9 @@ private function testDeleteCache() { } private function testTtl() { - $benchmark = new Benchmark(3, "speed", "1234:88","#HL# -a 3 ?u?u?u", 200, 1, time() - 10, 1); //ttl in the past to test invalid ttl + $benchmark = new Benchmark(3, "speed", "1234:88","#HL# -a 3 ?u?u?u", 200, $this->agent->getHardwareGroupId(), time() - 10, $this->crackerBinary->getId()); //ttl in the past to test invalid ttl Factory::getBenchmarkFactory()->save($benchmark); - $found = BenchmarkUtils::getBenchmarkByValue("#HL# -a 3 ?u?u?u", 1, 200, 1, 1); + $found = BenchmarkUtils::getBenchmarkByValue("#HL# -a 3 ?u?u?u", $this->agent->getHardwareGroupId(), 200, 1, $this->crackerBinary->getId()); if($found != null) { $this->testFailed("BenchmarkTest:testTtl", "benchmark with ttl in the past should not be valid!"); } else { From 18dbd9058cc41faae90459230fd81eeee357c87f Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Sat, 26 Aug 2023 06:36:33 -0400 Subject: [PATCH 54/55] Fixed agent API --- src/inc/user-api/UserAPIAgent.class.php | 7 +++++-- src/inc/utils/HardwareGroupUtils.class.php | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/inc/user-api/UserAPIAgent.class.php b/src/inc/user-api/UserAPIAgent.class.php index 17394ab31..4f29e5629 100644 --- a/src/inc/user-api/UserAPIAgent.class.php +++ b/src/inc/user-api/UserAPIAgent.class.php @@ -79,12 +79,13 @@ private function deleteAgent($QUERY) { */ private function getAgent($QUERY) { $agent = AgentUtils::getAgent($QUERY[UQueryAgent::AGENT_ID], $this->user); + $devices = HardwareGroupUtils::getDevicesForAgent($agent); $response = [ UResponseAgent::SECTION => $QUERY[UQueryAgent::SECTION], UResponseAgent::REQUEST => $QUERY[UQueryAgent::REQUEST], UResponseAgent::RESPONSE => UValues::OK, UResponseAgent::AGENT_NAME => $agent->getAgentName(), - UResponseAgent::AGENT_DEVICES => explode("\n", $agent->getDevices()), + UResponseAgent::AGENT_DEVICES => explode("\n", $devices), UResponseAgent::AGENT_OWNER => [ UResponseAgent::AGENT_OWNER_ID => (int)$agent->getUserId(), UResponseAgent::AGENT_OWNER_NAME => Util::getUsernameById($agent->getUserId()) @@ -203,10 +204,12 @@ private function listAgents() { $agents = Factory::getAgentFactory()->filter([Factory::FILTER => $qF, Factory::ORDER => $oF]); $arr = []; foreach ($agents as $agent) { + $devices = HardwareGroupUtils::getDevicesForAgent($agent); + $arr[] = array( UResponseAgent::AGENTS_ID => $agent->getId(), UResponseAgent::AGENTS_NAME => $agent->getAgentName(), - UResponseAgent::AGENTS_DEVICES => explode("\n", $agent->getDevices()) + UResponseAgent::AGENTS_DEVICES => explode("\n", $devices) ); } $this->sendResponse(array( diff --git a/src/inc/utils/HardwareGroupUtils.class.php b/src/inc/utils/HardwareGroupUtils.class.php index 3884330ad..ce0f8489d 100644 --- a/src/inc/utils/HardwareGroupUtils.class.php +++ b/src/inc/utils/HardwareGroupUtils.class.php @@ -23,6 +23,12 @@ public static function updateHardwareOfAgent($devices, $agent) { return $agent; } +public static function getDevicesForAgent($agent) { + $qF = new QueryFilter(HardwareGroup::HARDWARE_GROUP_ID, $agent->getHardwareGroupId(), "="); + $res = Factory::getHardwareGroupFactory()->filter([Factory::FILTER => [$qF]], true); + return $res->getDevices(); +} + public static function getDevicesFromBenchmark($benchmark) { $qF = new QueryFilter(HardwareGroup::HARDWARE_GROUP_ID, $benchmark->getHardwareGroupId(), "="); $res = Factory::getHardwareGroupFactory()->filter([Factory::FILTER => [$qF]], true); From dd03d7d750c30ce9ddfc9ab1ffa464d6bc3e518b Mon Sep 17 00:00:00 2001 From: "jessevanzutphen7@hotmail.com" Date: Wed, 30 Aug 2023 14:28:42 -0400 Subject: [PATCH 55/55] Added code to make benchmark working with new ui and API v2 --- src/api/v2/index.php | 2 + src/dba/models/Agent.class.php | 2 +- src/dba/models/Benchmark.class.php | 14 ++++++ src/dba/models/HardwareGroup.class.php | 17 +++---- src/inc/api/APISendBenchmark.class.php | 1 - src/inc/apiv2/agents.routes.php | 2 +- src/inc/apiv2/benchmark.routes.php | 67 +++++++++++++++++++++++++ src/inc/apiv2/hardwaregroup.routes.php | 68 ++++++++++++++++++++++++++ src/inc/apiv2/shared.inc.php | 4 ++ 9 files changed, 165 insertions(+), 12 deletions(-) create mode 100644 src/inc/apiv2/benchmark.routes.php create mode 100644 src/inc/apiv2/hardwaregroup.routes.php diff --git a/src/api/v2/index.php b/src/api/v2/index.php index 4c83b737a..823f554ee 100644 --- a/src/api/v2/index.php +++ b/src/api/v2/index.php @@ -247,6 +247,8 @@ public function process(Request $request, RequestHandler $handler): Response { require __DIR__ . "/../../inc/apiv2/users.routes.php"; require __DIR__ . "/../../inc/apiv2/vouchers.routes.php"; require __DIR__ . "/../../inc/apiv2/taskwrappers.routes.php"; +require __DIR__ . "/../../inc/apiv2/benchmark.routes.php"; +require __DIR__ . "/../../inc/apiv2/hardwaregroup.routes.php"; $errorMiddleware = $app->addErrorMiddleware(true, true, true); diff --git a/src/dba/models/Agent.class.php b/src/dba/models/Agent.class.php index c841dca16..c21dae26b 100644 --- a/src/dba/models/Agent.class.php +++ b/src/dba/models/Agent.class.php @@ -67,7 +67,7 @@ static function getFeatures() { $dict['agentName'] = ['read_only' => False, "type" => "str(100)", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "agentName"]; $dict['uid'] = ['read_only' => False, "type" => "str(100)", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "uid"]; $dict['os'] = ['read_only' => False, "type" => "int", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "os"]; - $dict['devices'] = ['read_only' => False, "type" => "str(65535)", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "devices"]; + $dict['hardwareGroupId'] = ['read_only' => False, "type" => "int", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "hardwareGroupId"]; $dict['cmdPars'] = ['read_only' => False, "type" => "str(256)", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "cmdPars"]; $dict['ignoreErrors'] = ['read_only' => False, "type" => "bool", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "ignoreErrors"]; $dict['isActive'] = ['read_only' => False, "type" => "bool", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "isActive"]; diff --git a/src/dba/models/Benchmark.class.php b/src/dba/models/Benchmark.class.php index b7f2cc528..66581073a 100644 --- a/src/dba/models/Benchmark.class.php +++ b/src/dba/models/Benchmark.class.php @@ -36,6 +36,20 @@ function getKeyValueDict() { return $dict; } + + static function getFeatures() { + $dict = array(); + $dict['benchmarkId'] = ['read_only' => True, "type" => "int", "subtype" => "unset", "null" => False, "pk" => True, "protected" => True, "private" => False, "alias" => "benchmarkId"]; + $dict['benchmarkType'] = ['read_only' => True, "type" => "str(10)", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "benchmarkType"]; + $dict['benchmarkValue'] = ['read_only' => True, "type" => "str(256)", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "benchmarkValue"]; + $dict['attackParameters'] = ['read_only' => True, "type" => "str(512)", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "attackParameters"]; + $dict['hashMode'] = ['read_only' => True, "type" => "int", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "hashMode"]; + $dict['hardwareGroupId'] = ['read_only' => True, "type" => "int", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "hardwareGroupId"]; + $dict['ttl'] = ['read_only' => True, "type" => "int", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "ttl"]; + $dict['crackerBinaryId'] = ['read_only' => True, "type" => "int", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "crackerBinaryId"]; + + return $dict; + } function getPrimaryKey() { return "benchmarkId"; diff --git a/src/dba/models/HardwareGroup.class.php b/src/dba/models/HardwareGroup.class.php index e61d46c84..9bb956370 100644 --- a/src/dba/models/HardwareGroup.class.php +++ b/src/dba/models/HardwareGroup.class.php @@ -18,6 +18,14 @@ function getKeyValueDict() { return $dict; } + + static function getFeatures() { + $dict = array(); + $dict['hardwareGroupId'] = ['read_only' => True, "type" => "int", "subtype" => "unset", "null" => False, "pk" => True, "protected" => True, "private" => False, "alias" => "benchmarkId"]; + $dict['devices'] = ['read_only' => True, "type" => "str(65000)", "subtype" => "unset", "null" => False, "pk" => False, "protected" => False, "private" => False, "alias" => "devices"]; + + return $dict; + } function getPrimaryKey() { return "hardwareGroupId"; @@ -51,15 +59,6 @@ function setDevices($devices) { $this->devices = $devices; } - // function getBenchmarkId() { - // return $this->benchmarkId; - // } - - // function setBenchmarkId($benchmarkId) { - // $this->benchmarkId = $benchmarkId; - // } - const HARDWARE_GROUP_ID = "hardwareGroupId"; const DEVICES = "devices"; - // const BENCHMARK_ID = "benchmarkId"; } diff --git a/src/inc/api/APISendBenchmark.class.php b/src/inc/api/APISendBenchmark.class.php index ba8b5f26f..82dec608f 100644 --- a/src/inc/api/APISendBenchmark.class.php +++ b/src/inc/api/APISendBenchmark.class.php @@ -84,7 +84,6 @@ public function execute($QUERY = array()) { if ($ttl != 0) { $hashlist = Factory::getHashlistFactory()->get($taskWrapper->getHashlistId()); $attackParameters = $task->getAttackCmd(). " " . $this->agent->getCmdPars(); - BenchmarkUtils::saveBenchmarkInCache($attackParameters, $this->agent->getHardwareGroupId(), $benchmark, $hashlist->getHashTypeId(), $type, $task->getCrackerBinaryId()); DServerLog::log(DServerLog::DEBUG, "Saved agent benchmark", [$this->agent, $task, $assignment]); } diff --git a/src/inc/apiv2/agents.routes.php b/src/inc/apiv2/agents.routes.php index e9cb61396..d1d17b510 100644 --- a/src/inc/apiv2/agents.routes.php +++ b/src/inc/apiv2/agents.routes.php @@ -33,7 +33,7 @@ protected function getFactory(): object { } public function getExpandables(): array { - return ['agentstats']; + return ['agentstats', "hardwareGroup"]; } protected function getFilterACL(): array { diff --git a/src/inc/apiv2/benchmark.routes.php b/src/inc/apiv2/benchmark.routes.php new file mode 100644 index 000000000..b9868d6e1 --- /dev/null +++ b/src/inc/apiv2/benchmark.routes.php @@ -0,0 +1,67 @@ +getId()); + } +} + +BenchmarkAPI::register($app); \ No newline at end of file diff --git a/src/inc/apiv2/hardwaregroup.routes.php b/src/inc/apiv2/hardwaregroup.routes.php new file mode 100644 index 000000000..9d7fa9fcd --- /dev/null +++ b/src/inc/apiv2/hardwaregroup.routes.php @@ -0,0 +1,68 @@ +get($item['accessGroupId']); $item[$NAME] = $this->obj2Array($obj); break; + case 'hardwareGroup': + $obj = Factory::getHardwareGroupFactory()->get($item['hardwareGroupId']); + $item[$NAME] = $this->obj2Array($obj); + break; case 'chunk': if ($item['chunkId'] === null) { /* Chunk expansions are optional, hence the chunk object could be null */
idCmdIDCMD Hashmode Cracker Binary CPU/GPU Benchmark valuettlactionTTLAction