diff --git a/ci/apiv2/hashtopolis_agent.py b/ci/apiv2/hashtopolis_agent.py index 5e9d3dd8c..8af05afce 100644 --- a/ci/apiv2/hashtopolis_agent.py +++ b/ci/apiv2/hashtopolis_agent.py @@ -35,18 +35,22 @@ def _load_config(): class ProcessState(enum.IntEnum): - """ See src/inc/defines/hashcat.php for mapping""" + """ See src/inc/defines/DHashcatStatus.php for mapping""" INIT = 0 AUTOTUNE = 1 - RUNNING = 2 - PAUSED = 3 - EXHAUSTED = 4 - CRACKED = 5 - ABORTED = 6 - QUIT = 7 - BYPASS = 8 - ABORTED_CHECKPOINT = 9 - STATUS_ABORTED_RUNTIME = 10 + SELFTEST = 2 + RUNNING = 3 + PAUSED = 4 + EXHAUSTED = 5 + CRACKED = 6 + ABORTED = 7 + QUIT = 8 + BYPASS = 9 + ABORTED_CHECKPOINT = 10 + ABORTED_RUNTIME = 11 + ERROR = 13 + ABORTED_FINISH = 14 + AUTODETECT = 16 class HashtopolisConfig(object): diff --git a/ci/apiv2/test_agent_protocol.py b/ci/apiv2/test_agent_protocol.py index fa07eaceb..9233e55fe 100644 --- a/ci/apiv2/test_agent_protocol.py +++ b/ci/apiv2/test_agent_protocol.py @@ -1162,7 +1162,7 @@ def test_get_chunk_fully_dispatched(self): "keyspaceProgress": resp['skip'] + resp['length'], "relativeProgress": 10000, "speed": 1000, - "state": 4, + "state": 5, "cracks": [], }) code, body = agent_request({ @@ -1438,7 +1438,7 @@ def _make_chunk(self, dummy, task_id): return self._drive_agent_to_chunk(dummy, task_id) @staticmethod - def _send_progress(token, chunk, state=2, cracks=None, progress=100): + def _send_progress(token, chunk, state=3, cracks=None, progress=100): """Send a progress update and return the parsed response.""" _, body = agent_request({ "action": "sendProgress", @@ -1583,7 +1583,7 @@ def test_send_progress_no_zaps_without_other_cracks(self): self.assertNotIn(self.CRACK_HASH, resp['zaps']) def test_send_progress_state_aborted(self): - """Sending progress with state=ABORTED (6) returns error 'Chunk was aborted!'.""" + """Sending progress with state=ABORTED (7) returns error 'Chunk was aborted!'.""" dummy, agent, task, _ = self._setup_with_two_hashes() chunk = self._make_chunk(dummy, task.id) code, body = agent_request({ @@ -1593,14 +1593,14 @@ def test_send_progress_state_aborted(self): "keyspaceProgress": chunk['skip'] + 1, "relativeProgress": 100, "speed": 5700, - "state": 6, + "state": 7, "cracks": [], }) assert_error_envelope(self, body, "sendProgress") self.assertEqual(parse_envelope(body)['message'], "Chunk was aborted!") def test_send_progress_state_quit(self): - """Sending progress with state=QUIT (7) returns error 'Chunk was aborted!'.""" + """Sending progress with state=QUIT (8) returns error 'Chunk was aborted!'.""" dummy, agent, task, _ = self._setup_with_two_hashes() chunk = self._make_chunk(dummy, task.id) code, body = agent_request({ @@ -1610,12 +1610,55 @@ def test_send_progress_state_quit(self): "keyspaceProgress": chunk['skip'] + 1, "relativeProgress": 100, "speed": 5700, - "state": 7, + "state": 8, + "cracks": [], + }) + assert_error_envelope(self, body, "sendProgress") + self.assertEqual(parse_envelope(body)['message'], "Chunk was aborted!") + + def test_send_progress_state_error(self): + """Sending progress with state=ERROR (13) returns error 'Chunk was aborted!'.""" + dummy, agent, task, _ = self._setup_with_two_hashes() + chunk = self._make_chunk(dummy, task.id) + code, body = agent_request({ + "action": "sendProgress", + "token": dummy.token, + "chunkId": chunk['chunkId'], + "keyspaceProgress": chunk['skip'] + 1, + "relativeProgress": 100, + "speed": 5700, + "state": 13, + "cracks": [], + }) + assert_error_envelope(self, body, "sendProgress") + self.assertEqual(parse_envelope(body)['message'], "Chunk was aborted!") + + def test_send_progress_state_aborted_finish(self): + """Sending progress with state=ABORTED_FINISH (14) returns error 'Chunk was aborted!'.""" + dummy, agent, task, _ = self._setup_with_two_hashes() + chunk = self._make_chunk(dummy, task.id) + code, body = agent_request({ + "action": "sendProgress", + "token": dummy.token, + "chunkId": chunk['chunkId'], + "keyspaceProgress": chunk['skip'] + 1, + "relativeProgress": 100, + "speed": 5700, + "state": 14, "cracks": [], }) assert_error_envelope(self, body, "sendProgress") self.assertEqual(parse_envelope(body)['message'], "Chunk was aborted!") + def test_send_progress_state_transient_states(self): + """Transient states SELFTEST (2) and AUTODETECT (16) are handled like RUNNING.""" + dummy, agent, task, _ = self._setup_with_two_hashes() + chunk = self._make_chunk(dummy, task.id) + resp = self._send_progress(dummy.token, chunk, state=2) + self.assertEqual(resp['response'], "SUCCESS") + resp = self._send_progress(dummy.token, chunk, state=16) + self.assertEqual(resp['response'], "SUCCESS") + def test_send_progress_on_already_aborted_chunk(self): """Sending progress on an already-aborted chunk returns 'Chunk was aborted!' via the aborting path.""" dummy, agent, task, _ = self._setup_with_two_hashes() @@ -1627,7 +1670,7 @@ def test_send_progress_on_already_aborted_chunk(self): "keyspaceProgress": chunk['skip'] + 1, "relativeProgress": 100, "speed": 5700, - "state": 6, + "state": 7, "cracks": [], }) code, body = agent_request({ @@ -1637,14 +1680,14 @@ def test_send_progress_on_already_aborted_chunk(self): "keyspaceProgress": chunk['skip'] + 2, "relativeProgress": 200, "speed": 5700, - "state": 2, + "state": 3, "cracks": [], }) assert_error_envelope(self, body, "sendProgress") self.assertEqual(parse_envelope(body)['message'], "Chunk was aborted!") - def test_send_progress_state_status_aborted_runtime(self): - """Sending progress with state=STATUS_ABORTED_RUNTIME (10) returns 'Chunk was manually interrupted.'.""" + def test_send_progress_state_aborted_runtime(self): + """Sending progress with state=ABORTED_RUNTIME (11) returns 'Chunk was manually interrupted.'.""" dummy, agent, task, _ = self._setup_with_two_hashes() chunk = self._make_chunk(dummy, task.id) code, body = agent_request({ @@ -1654,17 +1697,17 @@ def test_send_progress_state_status_aborted_runtime(self): "keyspaceProgress": chunk['skip'] + 1, "relativeProgress": 100, "speed": 5700, - "state": 10, + "state": 11, "cracks": [], }) assert_error_envelope(self, body, "sendProgress") self.assertEqual(parse_envelope(body)['message'], "Chunk was manually interrupted.") def test_send_progress_state_exhausted(self): - """Sending progress with state=EXHAUSTED (4) returns SUCCESS with cracked/skipped fields.""" + """Sending progress with state=EXHAUSTED (5) returns SUCCESS with cracked/skipped fields.""" dummy, agent, task, _ = self._setup_with_two_hashes() chunk = self._make_chunk(dummy, task.id) - resp = self._send_progress(dummy.token, chunk, state=4, progress=100) + resp = self._send_progress(dummy.token, chunk, state=5, progress=100) self.assertEqual(resp['response'], "SUCCESS") self.assertIsInstance(resp['cracked'], int) self.assertIsInstance(resp['skipped'], int) @@ -1678,7 +1721,7 @@ def test_send_progress_agent_stop_on_all_cracked(self): """ dummy, agent, task, _ = self._setup_assigned_agent() chunk = self._make_chunk(dummy, task.id) - resp = self._send_progress(dummy.token, chunk, state=2, cracks=[ + resp = self._send_progress(dummy.token, chunk, state=3, cracks=[ [self.CRACK_HASH, self.CRACK_PLAIN, self.CRACK_HEX, "1"], ]) self.assertEqual(resp['response'], "SUCCESS") @@ -1694,7 +1737,7 @@ def test_send_progress_invalid_chunk(self): "keyspaceProgress": 1, "relativeProgress": 1, "speed": 1, - "state": 2, + "state": 3, "cracks": [], }) assert_error_envelope(self, body, "sendProgress") @@ -1712,7 +1755,7 @@ def test_send_progress_not_assigned_to_chunk(self): "keyspaceProgress": chunk['skip'] + 1, "relativeProgress": 100, "speed": 5700, - "state": 2, + "state": 3, "cracks": [], }) assert_error_envelope(self, body, "sendProgress") @@ -1731,7 +1774,7 @@ def test_send_progress_inactive_agent(self): "keyspaceProgress": chunk['skip'] + 1, "relativeProgress": 100, "speed": 5700, - "state": 2, + "state": 3, "cracks": [], }) assert_error_envelope(self, body, "sendProgress") @@ -1746,20 +1789,20 @@ def test_send_progress_invalid_token(self): "keyspaceProgress": 1, "relativeProgress": 1, "speed": 1, - "state": 2, + "state": 3, "cracks": [], }) assert_error_envelope(self, body, "sendProgress") self.assertEqual(parse_envelope(body)['message'], "Invalid token!") def test_send_progress_state_cracked(self): - """Sending progress with state=CRACKED (5) returns SUCCESS (deprioritizes all tasks and unassigns all agents). + """Sending progress with state=CRACKED (6) returns SUCCESS (deprioritizes all tasks and unassigns all agents). Uses a single-hash hashlist so cracking it triggers the CRACKED state. """ dummy, agent, task, _ = self._setup_assigned_agent() chunk = self._make_chunk(dummy, task.id) - resp = self._send_progress(dummy.token, chunk, state=5, cracks=[ + resp = self._send_progress(dummy.token, chunk, state=6, cracks=[ [self.CRACK_HASH, self.CRACK_PLAIN, self.CRACK_HEX, "1"], ]) self.assertEqual(resp['response'], "SUCCESS") diff --git a/ci/apiv2/test_realworld_dump.py b/ci/apiv2/test_realworld_dump.py index bd87dffc0..97ed86cb0 100644 --- a/ci/apiv2/test_realworld_dump.py +++ b/ci/apiv2/test_realworld_dump.py @@ -143,7 +143,10 @@ def test_chunk_pagination_on_large_task(self): first_ids = [chunk.id for chunk in first_page] self.assertEqual(first_ids, list(range(1157, 1167))) self.assertTrue(all(chunk.taskId == 1308 for chunk in first_page)) - self.assertTrue(all(chunk.state == 4 for chunk in first_page)) + # State 5 is EXHAUSTED in hashcat's aligned status_rc_t enum; the dump itself + # still carries the old pre-SELFTEST numbering (4) which the server migration + # shifts on startup. + self.assertTrue(all(chunk.state == 5 for chunk in first_page)) second_page = Chunk.objects.paginate(size=10, after=self._cursor_after('chunkId', first_ids[-1])) \ .filter(taskId=1308).order_by('chunkId').get_pagination() diff --git a/ci/phpunit/inc/UtilTest.php b/ci/phpunit/inc/UtilTest.php index fa16b6a6e..bb3d9ab8b 100644 --- a/ci/phpunit/inc/UtilTest.php +++ b/ci/phpunit/inc/UtilTest.php @@ -8,6 +8,7 @@ use Hashtopolis\dba\models\StoredValue; use Hashtopolis\TestBase; use Hashtopolis\inc\defines\DConfig; +use Hashtopolis\inc\defines\DHashcatStatus; require_once(dirname(__FILE__) . '/../TestBase.php'); @@ -618,9 +619,13 @@ public function testGetStaticArrayOsUnknown(): void { * getStaticArray returns the state label for each chunk state. */ public function testGetStaticArrayStates(): void { - $this->assertEquals("New", Util::getStaticArray("0", "states")); - $this->assertEquals("Running", Util::getStaticArray("2", "states")); - $this->assertEquals("Cracked", Util::getStaticArray("5", "states")); + $this->assertEquals("New", Util::getStaticArray(DHashcatStatus::INIT, "states")); + $this->assertEquals("Running", Util::getStaticArray(DHashcatStatus::RUNNING, "states")); + $this->assertEquals("Cracked", Util::getStaticArray(DHashcatStatus::CRACKED, "states")); + $this->assertEquals("Aborted at runtime", Util::getStaticArray(DHashcatStatus::ABORTED_RUNTIME, "states")); + $this->assertEquals("Error", Util::getStaticArray(DHashcatStatus::ERROR, "states")); + $this->assertEquals("Autodetect", Util::getStaticArray(DHashcatStatus::AUTODETECT, "states")); + $this->assertEquals("Unknown", Util::getStaticArray(12, "states")); } /** diff --git a/ci/phpunit/inc/defines/DHashcatStatusTest.php b/ci/phpunit/inc/defines/DHashcatStatusTest.php new file mode 100644 index 000000000..46033a271 --- /dev/null +++ b/ci/phpunit/inc/defines/DHashcatStatusTest.php @@ -0,0 +1,57 @@ +assertSame(0, DHashcatStatus::INIT); + $this->assertSame(1, DHashcatStatus::AUTOTUNE); + $this->assertSame(2, DHashcatStatus::SELFTEST); + $this->assertSame(3, DHashcatStatus::RUNNING); + $this->assertSame(4, DHashcatStatus::PAUSED); + $this->assertSame(5, DHashcatStatus::EXHAUSTED); + $this->assertSame(6, DHashcatStatus::CRACKED); + $this->assertSame(7, DHashcatStatus::ABORTED); + $this->assertSame(8, DHashcatStatus::QUIT); + $this->assertSame(9, DHashcatStatus::BYPASS); + $this->assertSame(10, DHashcatStatus::ABORTED_CHECKPOINT); + $this->assertSame(11, DHashcatStatus::ABORTED_RUNTIME); + $this->assertSame(13, DHashcatStatus::ERROR); + $this->assertSame(14, DHashcatStatus::ABORTED_FINISH); + $this->assertSame(16, DHashcatStatus::AUTODETECT); + } + + /** + * ABORTED_STATES covers exactly the states telling that a chunk was stopped + * prematurely and none of the states of a normally completed chunk. + */ + public function testAbortedStatesContents(): void { + $this->assertSame( + [ + DHashcatStatus::ABORTED, + DHashcatStatus::QUIT, + DHashcatStatus::BYPASS, + DHashcatStatus::ABORTED_CHECKPOINT, + DHashcatStatus::ABORTED_RUNTIME, + DHashcatStatus::ERROR, + DHashcatStatus::ABORTED_FINISH, + ], + DHashcatStatus::ABORTED_STATES + ); + $this->assertNotContains(DHashcatStatus::EXHAUSTED, DHashcatStatus::ABORTED_STATES); + $this->assertNotContains(DHashcatStatus::CRACKED, DHashcatStatus::ABORTED_STATES); + } +} diff --git a/ci/phpunit/inc/utils/AccessGroupUtilsTest.php b/ci/phpunit/inc/utils/AccessGroupUtilsTest.php index 74dc7adcb..dd3725082 100644 --- a/ci/phpunit/inc/utils/AccessGroupUtilsTest.php +++ b/ci/phpunit/inc/utils/AccessGroupUtilsTest.php @@ -146,6 +146,7 @@ public function testAbortChunksGroupOnlyAbortsInitAndRunningChunks(): void { $statusCases = [ DHashcatStatus::INIT => DHashcatStatus::ABORTED, DHashcatStatus::AUTOTUNE => DHashcatStatus::AUTOTUNE, + DHashcatStatus::SELFTEST => DHashcatStatus::SELFTEST, DHashcatStatus::RUNNING => DHashcatStatus::ABORTED, DHashcatStatus::PAUSED => DHashcatStatus::PAUSED, DHashcatStatus::EXHAUSTED => DHashcatStatus::EXHAUSTED, @@ -154,7 +155,10 @@ public function testAbortChunksGroupOnlyAbortsInitAndRunningChunks(): void { DHashcatStatus::QUIT => DHashcatStatus::QUIT, DHashcatStatus::BYPASS => DHashcatStatus::BYPASS, DHashcatStatus::ABORTED_CHECKPOINT => DHashcatStatus::ABORTED_CHECKPOINT, - DHashcatStatus::STATUS_ABORTED_RUNTIME => DHashcatStatus::STATUS_ABORTED_RUNTIME, + DHashcatStatus::ABORTED_RUNTIME => DHashcatStatus::ABORTED_RUNTIME, + DHashcatStatus::ERROR => DHashcatStatus::ERROR, + DHashcatStatus::ABORTED_FINISH => DHashcatStatus::ABORTED_FINISH, + DHashcatStatus::AUTODETECT => DHashcatStatus::AUTODETECT, ]; diff --git a/openapi.json b/openapi.json index e0a861214..2e6e2c505 100644 --- a/openapi.json +++ b/openapi.json @@ -41095,48 +41095,68 @@ }, { "const": 2, - "title": "Running", + "title": "Selftest", "type": "integer" }, { "const": 3, - "title": "Paused", + "title": "Running", "type": "integer" }, { "const": 4, - "title": "Exhausted", + "title": "Paused", "type": "integer" }, { "const": 5, - "title": "Cracked", + "title": "Exhausted", "type": "integer" }, { "const": 6, - "title": "Aborted", + "title": "Cracked", "type": "integer" }, { "const": 7, - "title": "Quit", + "title": "Aborted", "type": "integer" }, { "const": 8, - "title": "Bypass", + "title": "Quit", "type": "integer" }, { "const": 9, - "title": "Aborted at checkpoint", + "title": "Bypass", "type": "integer" }, { "const": 10, + "title": "Aborted at checkpoint", + "type": "integer" + }, + { + "const": 11, "title": "Aborted at runtime", "type": "integer" + }, + { + "const": 13, + "title": "Error", + "type": "integer" + }, + { + "const": 14, + "title": "Aborted at finish", + "type": "integer" + }, + { + "const": 16, + "title": "Autodetect", + "type": "integer" } ] }, @@ -42106,48 +42126,68 @@ }, { "const": 2, - "title": "Running", + "title": "Selftest", "type": "integer" }, { "const": 3, - "title": "Paused", + "title": "Running", "type": "integer" }, { "const": 4, - "title": "Exhausted", + "title": "Paused", "type": "integer" }, { "const": 5, - "title": "Cracked", + "title": "Exhausted", "type": "integer" }, { "const": 6, - "title": "Aborted", + "title": "Cracked", "type": "integer" }, { "const": 7, - "title": "Quit", + "title": "Aborted", "type": "integer" }, { "const": 8, - "title": "Bypass", + "title": "Quit", "type": "integer" }, { "const": 9, - "title": "Aborted at checkpoint", + "title": "Bypass", "type": "integer" }, { "const": 10, + "title": "Aborted at checkpoint", + "type": "integer" + }, + { + "const": 11, "title": "Aborted at runtime", "type": "integer" + }, + { + "const": 13, + "title": "Error", + "type": "integer" + }, + { + "const": 14, + "title": "Aborted at finish", + "type": "integer" + }, + { + "const": 16, + "title": "Autodetect", + "type": "integer" } ] }, @@ -43169,48 +43209,68 @@ }, { "const": 2, - "title": "Running", + "title": "Selftest", "type": "integer" }, { "const": 3, - "title": "Paused", + "title": "Running", "type": "integer" }, { "const": 4, - "title": "Exhausted", + "title": "Paused", "type": "integer" }, { "const": 5, - "title": "Cracked", + "title": "Exhausted", "type": "integer" }, { "const": 6, - "title": "Aborted", + "title": "Cracked", "type": "integer" }, { "const": 7, - "title": "Quit", + "title": "Aborted", "type": "integer" }, { "const": 8, - "title": "Bypass", + "title": "Quit", "type": "integer" }, { "const": 9, - "title": "Aborted at checkpoint", + "title": "Bypass", "type": "integer" }, { "const": 10, + "title": "Aborted at checkpoint", + "type": "integer" + }, + { + "const": 11, "title": "Aborted at runtime", "type": "integer" + }, + { + "const": 13, + "title": "Error", + "type": "integer" + }, + { + "const": 14, + "title": "Aborted at finish", + "type": "integer" + }, + { + "const": 16, + "title": "Autodetect", + "type": "integer" } ] }, @@ -49195,48 +49255,68 @@ }, { "const": 2, - "title": "Running", + "title": "Selftest", "type": "integer" }, { "const": 3, - "title": "Paused", + "title": "Running", "type": "integer" }, { "const": 4, - "title": "Exhausted", + "title": "Paused", "type": "integer" }, { "const": 5, - "title": "Cracked", + "title": "Exhausted", "type": "integer" }, { "const": 6, - "title": "Aborted", + "title": "Cracked", "type": "integer" }, { "const": 7, - "title": "Quit", + "title": "Aborted", "type": "integer" }, { "const": 8, - "title": "Bypass", + "title": "Quit", "type": "integer" }, { "const": 9, - "title": "Aborted at checkpoint", + "title": "Bypass", "type": "integer" }, { "const": 10, + "title": "Aborted at checkpoint", + "type": "integer" + }, + { + "const": 11, "title": "Aborted at runtime", "type": "integer" + }, + { + "const": 13, + "title": "Error", + "type": "integer" + }, + { + "const": 14, + "title": "Aborted at finish", + "type": "integer" + }, + { + "const": 16, + "title": "Autodetect", + "type": "integer" } ] }, @@ -49800,48 +49880,68 @@ }, { "const": 2, - "title": "Running", + "title": "Selftest", "type": "integer" }, { "const": 3, - "title": "Paused", + "title": "Running", "type": "integer" }, { "const": 4, - "title": "Exhausted", + "title": "Paused", "type": "integer" }, { "const": 5, - "title": "Cracked", + "title": "Exhausted", "type": "integer" }, { "const": 6, - "title": "Aborted", + "title": "Cracked", "type": "integer" }, { "const": 7, - "title": "Quit", + "title": "Aborted", "type": "integer" }, { "const": 8, - "title": "Bypass", + "title": "Quit", "type": "integer" }, { "const": 9, - "title": "Aborted at checkpoint", + "title": "Bypass", "type": "integer" }, { "const": 10, + "title": "Aborted at checkpoint", + "type": "integer" + }, + { + "const": 11, "title": "Aborted at runtime", "type": "integer" + }, + { + "const": 13, + "title": "Error", + "type": "integer" + }, + { + "const": 14, + "title": "Aborted at finish", + "type": "integer" + }, + { + "const": 16, + "title": "Autodetect", + "type": "integer" } ] }, @@ -58773,48 +58873,68 @@ }, { "const": 2, - "title": "Running", + "title": "Selftest", "type": "integer" }, { "const": 3, - "title": "Paused", + "title": "Running", "type": "integer" }, { "const": 4, - "title": "Exhausted", + "title": "Paused", "type": "integer" }, { "const": 5, - "title": "Cracked", + "title": "Exhausted", "type": "integer" }, { "const": 6, - "title": "Aborted", + "title": "Cracked", "type": "integer" }, { "const": 7, - "title": "Quit", + "title": "Aborted", "type": "integer" }, { "const": 8, - "title": "Bypass", + "title": "Quit", "type": "integer" }, { "const": 9, - "title": "Aborted at checkpoint", + "title": "Bypass", "type": "integer" }, { "const": 10, + "title": "Aborted at checkpoint", + "type": "integer" + }, + { + "const": 11, "title": "Aborted at runtime", "type": "integer" + }, + { + "const": 13, + "title": "Error", + "type": "integer" + }, + { + "const": 14, + "title": "Aborted at finish", + "type": "integer" + }, + { + "const": 16, + "title": "Autodetect", + "type": "integer" } ] }, @@ -59298,48 +59418,68 @@ }, { "const": 2, - "title": "Running", + "title": "Selftest", "type": "integer" }, { "const": 3, - "title": "Paused", + "title": "Running", "type": "integer" }, { "const": 4, - "title": "Exhausted", + "title": "Paused", "type": "integer" }, { "const": 5, - "title": "Cracked", + "title": "Exhausted", "type": "integer" }, { "const": 6, - "title": "Aborted", + "title": "Cracked", "type": "integer" }, { "const": 7, - "title": "Quit", + "title": "Aborted", "type": "integer" }, { "const": 8, - "title": "Bypass", + "title": "Quit", "type": "integer" }, { "const": 9, - "title": "Aborted at checkpoint", + "title": "Bypass", "type": "integer" }, { "const": 10, + "title": "Aborted at checkpoint", + "type": "integer" + }, + { + "const": 11, "title": "Aborted at runtime", "type": "integer" + }, + { + "const": 13, + "title": "Error", + "type": "integer" + }, + { + "const": 14, + "title": "Aborted at finish", + "type": "integer" + }, + { + "const": 16, + "title": "Autodetect", + "type": "integer" } ] }, diff --git a/src/api/taskimg.php b/src/api/taskimg.php index 203ebb708..e9b67a312 100755 --- a/src/api/taskimg.php +++ b/src/api/taskimg.php @@ -9,6 +9,7 @@ use Hashtopolis\dba\QueryFilter; use Hashtopolis\dba\models\Task; use Hashtopolis\dba\Factory; +use Hashtopolis\inc\defines\DHashcatStatus; use Hashtopolis\inc\defines\DTaskTypes; use Hashtopolis\inc\Login; @@ -113,7 +114,7 @@ } if ($end - $start < 3) { - if ($chunk->getState() >= 6) { + if (in_array($chunk->getState(), DHashcatStatus::ABORTED_STATES, true)) { imagefilledrectangle($image, $start, 0, $end, $size[1] - 1, $red); } else if ($chunk->getCracked() > 0) { @@ -124,7 +125,7 @@ } } else { - if ($chunk->getState() >= 6) { + if (in_array($chunk->getState(), DHashcatStatus::ABORTED_STATES, true)) { imagerectangle($image, $start, 0, $end, ($size[1] - 1), $red); } else { diff --git a/src/dba/models/Chunk.php b/src/dba/models/Chunk.php index 34e32a3f1..8f4ed9cd1 100644 --- a/src/dba/models/Chunk.php +++ b/src/dba/models/Chunk.php @@ -62,7 +62,7 @@ static function getFeatures(): array { $dict['solveTime'] = ['read_only' => True, "type" => "int64", "subtype" => "unset", "choices" => "unset", "null" => False, "pk" => False, "protected" => True, "private" => False, "alias" => "solveTime", "public" => False, "dba_mapping" => False]; $dict['checkpoint'] = ['read_only' => True, "type" => "int64", "subtype" => "unset", "choices" => "unset", "null" => False, "pk" => False, "protected" => True, "private" => False, "alias" => "checkpoint", "public" => False, "dba_mapping" => False]; $dict['progress'] = ['read_only' => True, "type" => "int", "subtype" => "unset", "choices" => "unset", "null" => False, "pk" => False, "protected" => True, "private" => False, "alias" => "progress", "public" => False, "dba_mapping" => False]; - $dict['state'] = ['read_only' => True, "type" => "int", "subtype" => "unset", "choices" => [0 => "Init", 1 => "Autotune", 2 => "Running", 3 => "Paused", 4 => "Exhausted", 5 => "Cracked", 6 => "Aborted", 7 => "Quit", 8 => "Bypass", 9 => "Aborted at checkpoint", 10 => "Aborted at runtime", ], "null" => False, "pk" => False, "protected" => True, "private" => False, "alias" => "state", "public" => False, "dba_mapping" => False]; + $dict['state'] = ['read_only' => True, "type" => "int", "subtype" => "unset", "choices" => [0 => "Init", 1 => "Autotune", 2 => "Selftest", 3 => "Running", 4 => "Paused", 5 => "Exhausted", 6 => "Cracked", 7 => "Aborted", 8 => "Quit", 9 => "Bypass", 10 => "Aborted at checkpoint", 11 => "Aborted at runtime", 13 => "Error", 14 => "Aborted at finish", 16 => "Autodetect", ], "null" => False, "pk" => False, "protected" => True, "private" => False, "alias" => "state", "public" => False, "dba_mapping" => False]; $dict['cracked'] = ['read_only' => True, "type" => "int", "subtype" => "unset", "choices" => "unset", "null" => False, "pk" => False, "protected" => True, "private" => False, "alias" => "cracked", "public" => False, "dba_mapping" => False]; $dict['speed'] = ['read_only' => True, "type" => "int64", "subtype" => "unset", "choices" => "unset", "null" => False, "pk" => False, "protected" => True, "private" => False, "alias" => "speed", "public" => False, "dba_mapping" => False]; diff --git a/src/dba/models/generator.php b/src/dba/models/generator.php index f6d608a3f..8d855c469 100644 --- a/src/dba/models/generator.php +++ b/src/dba/models/generator.php @@ -73,6 +73,7 @@ $FieldHashcatStatusChoices = [ ['key' => DHashcatStatus::INIT, 'label' => 'Init'], ['key' => DHashcatStatus::AUTOTUNE, 'label' => 'Autotune'], + ['key' => DHashcatStatus::SELFTEST, 'label' => 'Selftest'], ['key' => DHashcatStatus::RUNNING, 'label' => 'Running'], ['key' => DHashcatStatus::PAUSED, 'label' => 'Paused'], ['key' => DHashcatStatus::EXHAUSTED, 'label' => 'Exhausted'], @@ -81,7 +82,10 @@ ['key' => DHashcatStatus::QUIT, 'label' => 'Quit'], ['key' => DHashcatStatus::BYPASS, 'label' => 'Bypass'], ['key' => DHashcatStatus::ABORTED_CHECKPOINT, 'label' => 'Aborted at checkpoint'], - ['key' => DHashcatStatus::STATUS_ABORTED_RUNTIME, 'label' => 'Aborted at runtime'], + ['key' => DHashcatStatus::ABORTED_RUNTIME, 'label' => 'Aborted at runtime'], + ['key' => DHashcatStatus::ERROR, 'label' => 'Error'], + ['key' => DHashcatStatus::ABORTED_FINISH, 'label' => 'Aborted at finish'], + ['key' => DHashcatStatus::AUTODETECT, 'label' => 'Autodetect'], ]; $FieldFileTypeChoices = [ diff --git a/src/inc/Util.php b/src/inc/Util.php index b12b01a47..444d97864 100755 --- a/src/inc/Util.php +++ b/src/inc/Util.php @@ -38,6 +38,7 @@ use Hashtopolis\inc\defines\DDeviceCompress; use Hashtopolis\inc\defines\DDirectories; use Hashtopolis\inc\defines\DFileType; +use Hashtopolis\inc\defines\DHashcatStatus; use Hashtopolis\inc\defines\DHashlistFormat; use Hashtopolis\inc\defines\DLogEntry; use Hashtopolis\inc\defines\DLogEntryIssuer; @@ -1050,17 +1051,21 @@ public static function getStaticArray(int $val, string $id): string { "hashes_binary" ); $states = array( - "New", - "Init", - "Running", - "Paused", - "Exhausted", - "Cracked", - "Aborted", - "Quit", - "Bypass", - "Trimmed", - "Aborting..." + DHashcatStatus::INIT => "New", + DHashcatStatus::AUTOTUNE => "Autotune", + DHashcatStatus::SELFTEST => "Selftest", + DHashcatStatus::RUNNING => "Running", + DHashcatStatus::PAUSED => "Paused", + DHashcatStatus::EXHAUSTED => "Exhausted", + DHashcatStatus::CRACKED => "Cracked", + DHashcatStatus::ABORTED => "Aborted", + DHashcatStatus::QUIT => "Quit", + DHashcatStatus::BYPASS => "Bypass", + DHashcatStatus::ABORTED_CHECKPOINT => "Aborted at checkpoint", + DHashcatStatus::ABORTED_RUNTIME => "Aborted at runtime", + DHashcatStatus::ERROR => "Error", + DHashcatStatus::ABORTED_FINISH => "Aborted at finish", + DHashcatStatus::AUTODETECT => "Autodetect" ); switch ($id) { case 'os': @@ -1069,7 +1074,7 @@ public static function getStaticArray(int $val, string $id): string { } return $oses[$val]; case 'states': - return $states[$val]; + return $states[$val] ?? "Unknown"; case 'formats': return $formats[$val]; case 'formattables': diff --git a/src/inc/agentapi/model/GetChunkAction.php b/src/inc/agentapi/model/GetChunkAction.php index edb1c4e7f..10d93c378 100644 --- a/src/inc/agentapi/model/GetChunkAction.php +++ b/src/inc/agentapi/model/GetChunkAction.php @@ -174,7 +174,7 @@ public function __invoke(Request $request, Response $response): ResponseInterfac } } $timeoutTime = time() - SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT); - if ($chunk->getState() == DHashcatStatus::ABORTED || $chunk->getState() == DHashcatStatus::STATUS_ABORTED_RUNTIME || max($chunk->getDispatchTime(), $chunk->getSolveTime()) < $timeoutTime) { + if (in_array($chunk->getState(), [DHashcatStatus::ABORTED, DHashcatStatus::ABORTED_RUNTIME, DHashcatStatus::ERROR, DHashcatStatus::ABORTED_FINISH], true) || max($chunk->getDispatchTime(), $chunk->getSolveTime()) < $timeoutTime) { DServerLog::log(DServerLog::DEBUG, 'Found existing chunk which is not done yet', [$agent, $task, $chunk]); $result = $this->sendChunk($response, ChunkUtils::handleExistingChunk($chunk, $task, $assignment)); if ($result !== null) { diff --git a/src/inc/agentapi/model/SendProgressAction.php b/src/inc/agentapi/model/SendProgressAction.php index 2e93a387f..1331a6e6a 100644 --- a/src/inc/agentapi/model/SendProgressAction.php +++ b/src/inc/agentapi/model/SendProgressAction.php @@ -267,7 +267,7 @@ public function __invoke(Request $request, Response $response): ResponseInterfac DServerLog::log(DServerLog::TRACE, 'Updated with received cracks', [$agent, $chunk]); - if ($chunk->getState() == DHashcatStatus::STATUS_ABORTED_RUNTIME) { + if ($chunk->getState() == DHashcatStatus::ABORTED_RUNTIME) { $chunk = Factory::getChunkFactory()->set($chunk, Chunk::STATE, DHashcatStatus::ABORTED); DServerLog::log(DServerLog::TRACE, 'Chunk was manually interrupted', [$agent]); return $this->error($response, PActions::SEND_PROGRESS, 'Chunk was manually interrupted.'); @@ -339,6 +339,8 @@ public function __invoke(Request $request, Response $response): ResponseInterfac case DHashcatStatus::ABORTED: case DHashcatStatus::QUIT: + case DHashcatStatus::ERROR: + case DHashcatStatus::ABORTED_FINISH: $chunk = Factory::getChunkFactory()->set($chunk, Chunk::SPEED, 0); return $this->error($response, PActions::SEND_PROGRESS, 'Chunk was aborted!'); diff --git a/src/inc/agentapi/schema/SchemaRegistry.php b/src/inc/agentapi/schema/SchemaRegistry.php index 0054efaa1..f43e9695f 100644 --- a/src/inc/agentapi/schema/SchemaRegistry.php +++ b/src/inc/agentapi/schema/SchemaRegistry.php @@ -252,7 +252,7 @@ public static function getSchema(): array { PQuerySendProgress::KEYSPACE_PROGRESS => ['type' => 'integer', 'required' => true, 'description' => 'Keyspace progress (current position)'], PQuerySendProgress::RELATIVE_PROGRESS => ['type' => 'integer', 'required' => true, 'description' => 'Relative progress (0-10000)'], PQuerySendProgress::SPEED => ['type' => 'integer', 'required' => true, 'description' => 'Cracking speed (H/s)'], - PQuerySendProgress::HASHCAT_STATE => ['type' => 'integer', 'required' => true, 'description' => 'Hashcat state (0=INIT, 2=RUNNING, 4=EXHAUSTED, 5=CRACKED, 6=ABORTED, 7=QUIT, 10=STATUS_ABORTED_RUNTIME)'], + PQuerySendProgress::HASHCAT_STATE => ['type' => 'integer', 'required' => true, 'description' => 'Hashcat state (0=INIT, 1=AUTOTUNE, 2=SELFTEST, 3=RUNNING, 4=PAUSED, 5=EXHAUSTED, 6=CRACKED, 7=ABORTED, 8=QUIT, 9=BYPASS, 10=ABORTED_CHECKPOINT, 11=ABORTED_RUNTIME, 13=ERROR, 14=ABORTED_FINISH, 16=AUTODETECT)'], PQuerySendProgress::CRACKED_HASHES => ['type' => 'array', 'required' => true, 'description' => 'Cracked hashes: [[hash, plain, hex_plain, crack_pos], ...]'], PQuerySendProgress::DEBUG_OUTPUT => ['type' => 'array', 'required' => false, 'description' => 'Debug output lines'], PQuerySendProgress::GPU_TEMP => ['type' => 'array', 'required' => false, 'description' => 'GPU temperatures'], diff --git a/src/inc/apiv2/helper/GetTaskProgressImageHelperAPI.php b/src/inc/apiv2/helper/GetTaskProgressImageHelperAPI.php index bb554f7b5..360002780 100644 --- a/src/inc/apiv2/helper/GetTaskProgressImageHelperAPI.php +++ b/src/inc/apiv2/helper/GetTaskProgressImageHelperAPI.php @@ -8,6 +8,7 @@ use Hashtopolis\inc\apiv2\common\AbstractHelperAPI; use Hashtopolis\inc\apiv2\error\HttpError; use Hashtopolis\inc\apiv2\error\HttpForbidden; +use Hashtopolis\inc\defines\DHashcatStatus; use Hashtopolis\inc\defines\DTaskTypes; use Hashtopolis\inc\HTException; use Psr\Http\Message\ResponseInterface as Response; @@ -186,7 +187,7 @@ public function handleGet(Request $request, Response $response): Response { } if ($end - $start < 3) { - if ($chunk->getState() >= 6) { + if (in_array($chunk->getState(), DHashcatStatus::ABORTED_STATES, true)) { imagefilledrectangle($image, $start, 0, $end, $size[1] - 1, $red); } else if ($chunk->getCracked() > 0) { @@ -197,7 +198,7 @@ public function handleGet(Request $request, Response $response): Response { } } else { - if ($chunk->getState() >= 6) { + if (in_array($chunk->getState(), DHashcatStatus::ABORTED_STATES, true)) { imagerectangle($image, $start, 0, $end, ($size[1] - 1), $red); } else { diff --git a/src/inc/defines/DHashcatStatus.php b/src/inc/defines/DHashcatStatus.php index e1532c938..4e3532ddd 100644 --- a/src/inc/defines/DHashcatStatus.php +++ b/src/inc/defines/DHashcatStatus.php @@ -2,17 +2,34 @@ namespace Hashtopolis\inc\defines; -// hashcat status values (NOTE: these are the old values, clients do handle this issue) +// hashcat status values, kept in sync with hashcat's status_rc_t enum +// (include/types.h in the hashcat repository). The values 12 and 15 are +// unused by hashcat and therefore intentionally missing here as well. class DHashcatStatus { - const INIT = 0; - const AUTOTUNE = 1; - const RUNNING = 2; - const PAUSED = 3; - const EXHAUSTED = 4; - const CRACKED = 5; - const ABORTED = 6; - const QUIT = 7; - const BYPASS = 8; - const ABORTED_CHECKPOINT = 9; - const STATUS_ABORTED_RUNTIME = 10; + const INIT = 0; + const AUTOTUNE = 1; + const SELFTEST = 2; + const RUNNING = 3; + const PAUSED = 4; + const EXHAUSTED = 5; + const CRACKED = 6; + const ABORTED = 7; + const QUIT = 8; + const BYPASS = 9; + const ABORTED_CHECKPOINT = 10; + const ABORTED_RUNTIME = 11; + const ERROR = 13; + const ABORTED_FINISH = 14; + const AUTODETECT = 16; + + // States telling that a chunk was stopped before it was completed normally. + const ABORTED_STATES = [ + DHashcatStatus::ABORTED, + DHashcatStatus::QUIT, + DHashcatStatus::BYPASS, + DHashcatStatus::ABORTED_CHECKPOINT, + DHashcatStatus::ABORTED_RUNTIME, + DHashcatStatus::ERROR, + DHashcatStatus::ABORTED_FINISH, + ]; } \ No newline at end of file diff --git a/src/migrations/mysql/20261112131400_chunk-state-hashcat-enum.sql b/src/migrations/mysql/20261112131400_chunk-state-hashcat-enum.sql new file mode 100644 index 000000000..92b9b3b93 --- /dev/null +++ b/src/migrations/mysql/20261112131400_chunk-state-hashcat-enum.sql @@ -0,0 +1,22 @@ +-- Realign the chunk states with hashcat's status_rc_t enum. The server used to store the +-- pre-SELFTEST hashcat numbering while agents reported hashcat's status codes shifted down +-- by one, so 2..10 move up by one. 12, 13 and 15 are the shifted forms of hashcat's ERROR +-- (13), ABORTED_FINISH (14) and AUTODETECT (16) which agents wrote when running newer +-- hashcat versions. 0 (INIT) and 1 (AUTOTUNE) keep their meaning. A single CASE expression +-- per row avoids any ordering hazards. +UPDATE `Chunk` SET `state` = CASE `state` + WHEN 2 THEN 3 + WHEN 3 THEN 4 + WHEN 4 THEN 5 + WHEN 5 THEN 6 + WHEN 6 THEN 7 + WHEN 7 THEN 8 + WHEN 8 THEN 9 + WHEN 9 THEN 10 + WHEN 10 THEN 11 + WHEN 12 THEN 13 + WHEN 13 THEN 14 + WHEN 15 THEN 16 + ELSE `state` +END +WHERE `state` BETWEEN 2 AND 15; diff --git a/src/migrations/postgres/20261112131400_chunk-state-hashcat-enum.sql b/src/migrations/postgres/20261112131400_chunk-state-hashcat-enum.sql new file mode 100644 index 000000000..632389196 --- /dev/null +++ b/src/migrations/postgres/20261112131400_chunk-state-hashcat-enum.sql @@ -0,0 +1,22 @@ +-- Realign the chunk states with hashcat's status_rc_t enum. The server used to store the +-- pre-SELFTEST hashcat numbering while agents reported hashcat's status codes shifted down +-- by one, so 2..10 move up by one. 12, 13 and 15 are the shifted forms of hashcat's ERROR +-- (13), ABORTED_FINISH (14) and AUTODETECT (16) which agents wrote when running newer +-- hashcat versions. 0 (INIT) and 1 (AUTOTUNE) keep their meaning. A single CASE expression +-- per row avoids any ordering hazards. +UPDATE chunk SET state = CASE state + WHEN 2 THEN 3 + WHEN 3 THEN 4 + WHEN 4 THEN 5 + WHEN 5 THEN 6 + WHEN 6 THEN 7 + WHEN 7 THEN 8 + WHEN 8 THEN 9 + WHEN 9 THEN 10 + WHEN 10 THEN 11 + WHEN 12 THEN 13 + WHEN 13 THEN 14 + WHEN 15 THEN 16 + ELSE state +END +WHERE state BETWEEN 2 AND 15; diff --git a/src/templates/chunks.template.html b/src/templates/chunks.template.html index e66e490f4..c65718512 100755 --- a/src/templates/chunks.template.html +++ b/src/templates/chunks.template.html @@ -40,7 +40,7 @@

Chunk activity

[[chunk.getId()]] - {{IF [[max([[chunk.getSolveTime()]], [[chunk.getDispatchTime()]])]] > [[time()]] - [[config.getVal('chunktimeout')]] && [[chunk.getProgress()]] < [[chunk.getLength()]] && [[chunk.getState()]] < 4}} + {{IF [[max([[chunk.getSolveTime()]], [[chunk.getDispatchTime()]])]] > [[time()]] - [[config.getVal('chunktimeout')]] && [[chunk.getProgress()]] < [[chunk.getLength()]] && [[chunk.getState()]] < 5}} {{ENDIF}}