Skip to content

Commit 044c4ce

Browse files
authored
Merge branch 'dev' into apiv2
2 parents 9c3b524 + c18333e commit 044c4ce

33 files changed

+522
-44
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@
5454
"NODE_OPTIONS": "--use-openssl-ca"
5555
},
5656
"remoteUser": "vscode",
57+
"overrideCommand": false,
5758
"postStartCommand": "composer install --working-dir=/var/www/html/"
5859
}

.vscode/launch.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"name": "Listen for Xdebug",
77
"type": "php",
88
"request": "launch",
9-
"port": 9003
9+
"port": 9003,
10+
"xdebugSettings": {
11+
"max_data": 10240
12+
}
1013
},
1114
{
1215
"name": "Launch currently open script",

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ ENTRYPOINT [ "docker-entrypoint.sh" ]
9393
FROM hashtopolis-server-base as hashtopolis-server-dev
9494

9595
# Setting up development requirements, install xdebug
96-
RUN yes | pecl install xdebug \
96+
RUN yes | pecl install xdebug && docker-php-ext-enable xdebug \
9797
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
9898
&& echo "xdebug.mode = debug" >> /usr/local/etc/php/conf.d/xdebug.ini \
9999
&& echo "xdebug.start_with_request = yes" >> /usr/local/etc/php/conf.d/xdebug.ini \
100100
&& echo "xdebug.client_port = 9003" >> /usr/local/etc/php/conf.d/xdebug.ini \
101+
&& echo "xdebug.idekey = PHPSTORM" >> /usr/local/etc/php/conf.d/xdebug.ini \
101102
\
102103
# Configuring PHP
103104
&& touch "/usr/local/etc/php/conf.d/custom.ini" \

ci/HashtopolisTest.class.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ abstract class HashtopolisTest {
3434
"0.13.0" => "c7036800be5b2e21542df0fa9bd4d19ebf7ecdf3",
3535
"0.13.1" => "fc4b5226c1d36dc0197f4d17d216298972055c09",
3636
"0.14.0" => "0af7193310c9c1f37a274578e159ab3ae0a6caad",
37-
"0.14.1" => "375f2ce022c4b3e0780abf9dcca1e6af8e966c1a"
37+
"0.14.1" => "375f2ce022c4b3e0780abf9dcca1e6af8e966c1a",
38+
"0.14.2" => "d397e4b8ec1d2591b93fa44c8660edc314401da5"
3839
];
3940

4041
public function initAndUpgrade($fromVersion) {
@@ -239,4 +240,4 @@ protected function deleteFileIfExists($name) {
239240
}
240241
return true;
241242
}
242-
}
243+
}

ci/apiv2/hashtopolis.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,3 +867,56 @@ def purge_task(self, task):
867867
'taskId': task.id,
868868
}
869869
return self._helper_request("purgeTask", payload)
870+
871+
def export_cracked_hashes(self, hashlist):
872+
payload = {
873+
'hashlistId': hashlist.id,
874+
}
875+
response = self._helper_request("exportCrackedHashes", payload)
876+
return File(**response['data'])
877+
878+
def export_left_hashes(self, hashlist):
879+
payload = {
880+
'hashlistId': hashlist.id,
881+
}
882+
response = self._helper_request("exportLeftHashes", payload)
883+
return File(**response['data'])
884+
885+
def export_wordlist(self, hashlist):
886+
payload = {
887+
'hashlistId': hashlist.id,
888+
}
889+
response = self._helper_request("exportWordlist", payload)
890+
return File(**response['data'])
891+
892+
def import_cracked_hashes(self, hashlist, source_data, separator):
893+
payload = {
894+
'hashlistId': hashlist.id,
895+
'sourceData': source_data,
896+
'separator': separator,
897+
}
898+
response = self._helper_request("importCrackedHashes", payload)
899+
return response['data']
900+
901+
902+
def recount_file_lines(self, file):
903+
payload = {
904+
'fileId': file.id,
905+
}
906+
response = self._helper_request("recountFileLines", payload)
907+
return File(**response['data'])
908+
909+
def unassign_agent(self, agent):
910+
payload = {
911+
'agentId': agent.id,
912+
}
913+
response = self._helper_request("unassignAgent", payload)
914+
return response['data']
915+
916+
def assign_agent(self, agent, task):
917+
payload = {
918+
'agentId': agent.id,
919+
'taskId': task.id,
920+
}
921+
response = self._helper_request("assignAgent", payload)
922+
return response['data']

ci/apiv2/test_agent.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from hashtopolis import Agent
1+
from test_task import TaskTest
2+
from hashtopolis import Agent, Helper
23
from hashtopolis import HashtopolisError
34

45
from utils import BaseTest
@@ -37,3 +38,21 @@ def test_expandables(self):
3738
model_obj = self.create_test_object()
3839
expandables = ['accessGroups', 'agentStats']
3940
self._test_expandables(model_obj, expandables)
41+
42+
def test_assign_unassign_agent(self):
43+
agent_obj = self.create_test_object()
44+
45+
task_test = TaskTest()
46+
task_obj = task_test.create_test_object(delete=True)
47+
48+
helper = Helper()
49+
50+
result = helper.assign_agent(agent=agent_obj, task=task_obj)
51+
52+
self.assertEqual(result['assign'], 'success')
53+
54+
result = helper.unassign_agent(agent=agent_obj)
55+
56+
self.assertEqual(result['unassign'], 'success')
57+
58+
task_test.tearDown()

ci/apiv2/test_file.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from hashtopolis import File
1+
from hashtopolis import File, Helper
22
from utils import BaseTest
33

44

@@ -28,3 +28,14 @@ def test_expandables(self):
2828
def test_create_binary(self):
2929
model_obj = self.create_test_object(compress=True)
3030
self._test_create(model_obj)
31+
32+
def test_recount_wordlist(self):
33+
# Note: After the object creation, the line count is already updated, but afterward it is immutable on the API.
34+
# There the test just check that the API function is callable and returns the file, but the count is
35+
# already the same beforehand.
36+
model_obj = self.create_test_object()
37+
38+
helper = Helper()
39+
file = helper.recount_file_lines(file=model_obj)
40+
41+
self.assertEqual(file.lineCount, 3)

ci/apiv2/test_hashlist.py

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from hashtopolis import Hashlist, Helper
1+
from hashtopolis import Hashlist, Helper, File
22
from utils import BaseTest
33

44

@@ -38,6 +38,104 @@ def test_create_alternative_hashtype(self):
3838
model_obj = self.create_test_object(file_id='003')
3939
self._test_create(model_obj)
4040

41+
def test_export_cracked_hashes(self):
42+
model_obj = self.create_test_object(file_id='001')
43+
44+
helper = Helper()
45+
file = helper.export_cracked_hashes(model_obj)
46+
47+
obj = File.objects.get(fileId=file.id)
48+
self.assertEqual(int(file.id), obj.id)
49+
self.assertIn('Pre-cracked_', obj.filename)
50+
51+
self.delete_after_test(obj)
52+
53+
def test_export_left_hashes(self):
54+
model_obj = self.create_test_object(file_id='001')
55+
56+
helper = Helper()
57+
file = helper.export_left_hashes(model_obj)
58+
59+
obj = File.objects.get(fileId=file.id)
60+
self.assertEqual(int(file.id), obj.id)
61+
self.assertIn('Leftlist_', obj.filename)
62+
63+
self.delete_after_test(obj)
64+
65+
def test_export_wordlist(self):
66+
model_obj = self.create_test_object(file_id='001')
67+
68+
cracked = "cc03e747a6afbbcbf8be7668acfebee5:test123"
69+
70+
helper = Helper()
71+
helper.import_cracked_hashes(model_obj, cracked, ':')
72+
73+
file = helper.export_wordlist(model_obj)
74+
75+
obj = File.objects.get(fileId=file.id)
76+
self.assertEqual(int(file.id), obj.id)
77+
self.assertIn('Wordlist_', obj.filename)
78+
79+
self.delete_after_test(obj)
80+
81+
def test_import_cracked_hashes(self):
82+
model_obj = self.create_test_object(file_id='001')
83+
84+
cracked = "cc03e747a6afbbcbf8be7668acfebee5:test123"
85+
86+
helper = Helper()
87+
result = helper.import_cracked_hashes(model_obj, cracked, ':')
88+
89+
self.assertEqual(result['totalLines'], 1)
90+
self.assertEqual(result['newCracked'], 1)
91+
92+
obj = Hashlist.objects.get(hashlistId=model_obj.id)
93+
self.assertEqual(obj.cracked, 1)
94+
95+
def test_import_cracked_hashes_invalid(self):
96+
model_obj = self.create_test_object(file_id='001')
97+
98+
cracked = "cc03e747a6afbbcbf8be7668acfebee5__test123"
99+
100+
helper = Helper()
101+
result = helper.import_cracked_hashes(model_obj, cracked, ':')
102+
103+
self.assertEqual(result['totalLines'], 1)
104+
self.assertEqual(result['invalid'], 1)
105+
106+
obj = Hashlist.objects.get(hashlistId=model_obj.id)
107+
self.assertEqual(obj.cracked, 0)
108+
109+
def test_import_cracked_hashes_notfound(self):
110+
model_obj = self.create_test_object(file_id='001')
111+
112+
cracked = "ffffffffffffffffffffffffffffffff:test123"
113+
114+
helper = Helper()
115+
result = helper.import_cracked_hashes(model_obj, cracked, ':')
116+
117+
self.assertEqual(result['totalLines'], 1)
118+
self.assertEqual(result['notFound'], 1)
119+
120+
obj = Hashlist.objects.get(hashlistId=model_obj.id)
121+
self.assertEqual(obj.cracked, 0)
122+
123+
def test_import_cracked_hashes_already_cracked(self):
124+
model_obj = self.create_test_object(file_id='001')
125+
126+
cracked = "cc03e747a6afbbcbf8be7668acfebee5:test123"
127+
128+
helper = Helper()
129+
helper.import_cracked_hashes(model_obj, cracked, ':')
130+
131+
result = helper.import_cracked_hashes(model_obj, cracked, ':')
132+
133+
self.assertEqual(result['totalLines'], 1)
134+
self.assertEqual(result['alreadyCracked'], 1)
135+
136+
obj = Hashlist.objects.get(hashlistId=model_obj.id)
137+
self.assertEqual(obj.cracked, 1)
138+
41139
def test_helper_create_superhashlist(self):
42140
hashlists = [self.create_test_object() for _ in range(2)]
43141

doc/changelog.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
# v0.14.1 -> x.x.x
1+
# v0.14.1 -> v0.14.2
2+
3+
## Tech Preview New API
4+
Release 0.14.2 comes with an update to the tech preview of APIv2. Be aware, it is a preview, it contains bugs and it will change; To use it, please see https://github.com/hashtopolis/server/wiki/Installation.
25

36
## Bugfixes
47
- Setting maxAgent after creating doesn't update the maxAgents of the taskwrapper. This only causes issues when the maxAgents was set at creation time. #1013
58

6-
# v0.14.0 -> 0.14.1
9+
# v0.14.0 -> v0.14.1
710

811
## Tech Preview New API
912
Release 0.14.1 comes with an update to the tech preview of APIv2. Be aware, it is a preview, it contains bugs and it will change; To use it, please see https://github.com/hashtopolis/server/wiki/Installation.

src/api/v2/index.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,19 @@ public function process(Request $request, RequestHandler $handler): Response {
267267
require __DIR__ . "/../../inc/apiv2/model/vouchers.routes.php";
268268

269269
require __DIR__ . "/../../inc/apiv2/helper/abortChunk.routes.php";
270+
require __DIR__ . "/../../inc/apiv2/helper/assignAgent.routes.php";
270271
require __DIR__ . "/../../inc/apiv2/helper/createSupertask.routes.php";
271272
require __DIR__ . "/../../inc/apiv2/helper/createSuperHashlist.routes.php";
273+
require __DIR__ . "/../../inc/apiv2/helper/exportCrackedHashes.routes.php";
274+
require __DIR__ . "/../../inc/apiv2/helper/exportLeftHashes.routes.php";
275+
require __DIR__ . "/../../inc/apiv2/helper/exportWordlist.routes.php";
276+
require __DIR__ . "/../../inc/apiv2/helper/importCrackedHashes.routes.php";
272277
require __DIR__ . "/../../inc/apiv2/helper/importFile.routes.php";
273278
require __DIR__ . "/../../inc/apiv2/helper/purgeTask.routes.php";
279+
require __DIR__ . "/../../inc/apiv2/helper/recountFileLines.routes.php";
274280
require __DIR__ . "/../../inc/apiv2/helper/resetChunk.routes.php";
275281
require __DIR__ . "/../../inc/apiv2/helper/setUserPassword.routes.php";
282+
require __DIR__ . "/../../inc/apiv2/helper/unassignAgent.routes.php";
276283

277284
// NOTE: The ErrorMiddleware should be added after any middleware which may modify the response body
278285
$errorMiddleware = $app->addErrorMiddleware(true, true, true);

0 commit comments

Comments
 (0)