Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/inc/api/APISendProgress.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,11 @@ public function execute(array $QUERY = array()): void {
// the chunk has finished (exhausted)
$chunk = Factory::getChunkFactory()->mset($chunk, [Chunk::SPEED => 0, Chunk::PROGRESS => 10000, Chunk::CHECKPOINT => $chunk->getSkip() + $chunk->getLength()]);
DServerLog::log(DServerLog::TRACE, "Chunk is exhausted (cracker status)", [$this->agent, $chunk]);

// If we don't make use of static chunks we attempt to tune the duration a chunk takes to calculate
if($task->getStaticChunks() === 0 && SConfig::getInstance()->getVal(DConfig::CHUNK_DURATION_AUTO_TUNE) === 1) {
TaskUtils::tuneChunkDuration($chunk, $task);
}
break;
case DHashcatStatus::CRACKED:
// the chunk has finished (cracked whole hashList)
Expand Down
41 changes: 22 additions & 19 deletions src/inc/defines/DConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@

class DConfig {
// Section: Cracking/Tasks
const BENCHMARK_TIME = "benchtime";
const CHUNK_DURATION = "chunktime";
const CHUNK_TIMEOUT = "chunktimeout";
const AGENT_TIMEOUT = "agenttimeout";
const FIELD_SEPARATOR = "fieldseparator";
const HASHLIST_ALIAS = "hashlistAlias";
const STATUS_TIMER = "statustimer";
const BLACKLIST_CHARS = "blacklistChars";
const DISP_TOLERANCE = "disptolerance";
const DEFAULT_BENCH = "defaultBenchmark";
const AGENT_DATA_LIFETIME = "agentDataLifetime";
const DISABLE_TRIMMING = "disableTrimming";
const PRIORITY_0_START = "priority0Start";
const HASHCAT_BRAIN_ENABLE = "hashcatBrainEnable";
const HASHCAT_BRAIN_HOST = "hashcatBrainHost";
const HASHCAT_BRAIN_PORT = "hashcatBrainPort";
const HASHCAT_BRAIN_PASS = "hashcatBrainPass";
const HASHLIST_IMPORT_CHECK = "hashlistImportCheck";
const HC_ERROR_IGNORE = "hcErrorIgnore";
const BENCHMARK_TIME = "benchtime";
const CHUNK_DURATION = "chunktime";
const CHUNK_DURATION_AUTO_TUNE = "chunktimeAutoTune";
const CHUNK_TIMEOUT = "chunktimeout";
const AGENT_TIMEOUT = "agenttimeout";
const FIELD_SEPARATOR = "fieldseparator";
const HASHLIST_ALIAS = "hashlistAlias";
const STATUS_TIMER = "statustimer";
const BLACKLIST_CHARS = "blacklistChars";
const DISP_TOLERANCE = "disptolerance";
const DEFAULT_BENCH = "defaultBenchmark";
const AGENT_DATA_LIFETIME = "agentDataLifetime";
const DISABLE_TRIMMING = "disableTrimming";
const PRIORITY_0_START = "priority0Start";
const HASHCAT_BRAIN_ENABLE = "hashcatBrainEnable";
const HASHCAT_BRAIN_HOST = "hashcatBrainHost";
const HASHCAT_BRAIN_PORT = "hashcatBrainPort";
const HASHCAT_BRAIN_PASS = "hashcatBrainPass";
const HASHLIST_IMPORT_CHECK = "hashlistImportCheck";
const HC_ERROR_IGNORE = "hcErrorIgnore";

// Section: Yubikey
const YUBIKEY_ID = "yubikey_id";
Expand Down Expand Up @@ -122,6 +123,7 @@ public static function getConfigType(string $config): string {
return match ($config) {
DConfig::BENCHMARK_TIME => DConfigType::NUMBER_INPUT,
DConfig::CHUNK_DURATION => DConfigType::NUMBER_INPUT,
DConfig::CHUNK_DURATION_AUTO_TUNE => DConfigType::TICKBOX,
DConfig::CHUNK_TIMEOUT => DConfigType::NUMBER_INPUT,
DConfig::AGENT_TIMEOUT => DConfigType::NUMBER_INPUT,
DConfig::HASHES_PAGE_SIZE => DConfigType::NUMBER_INPUT,
Expand Down Expand Up @@ -190,6 +192,7 @@ public static function getConfigDescription(string $config): string {
return match ($config) {
DConfig::BENCHMARK_TIME => "Time in seconds an agent should benchmark a task.",
DConfig::CHUNK_DURATION => "Time in seconds a client should be working on a single chunk.",
DConfig::CHUNK_DURATION_AUTO_TUNE => "Automatically adjust chunk sizes to get the actual chunk working time for a client as close as possible to the configured chunk duration.",
DConfig::CHUNK_TIMEOUT => "Time in seconds the server will consider an issued chunk as inactive or timed out and will reallocate to another client.",
DConfig::AGENT_TIMEOUT => "Time in seconds the server will consider a client inactive or timed out.",
DConfig::HASHES_PAGE_SIZE => "Number of hashes shown on each page of the hashes view.",
Expand Down
86 changes: 43 additions & 43 deletions src/inc/utils/AgentUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function getDeviceUtilStatusColor(?AgentStat $deviceUtil, Agent $a
return "#800000";
}
}

/**
* @param ?AgentStat $deviceTemp
* @param Agent $agent
Expand Down Expand Up @@ -104,7 +104,7 @@ public static function getDeviceTempStatusColor(?AgentStat $deviceTemp, Agent $a
return "#800000";
}
}

/**
* @param ?AgentStat $cpuUtil
* @param Agent $agent
Expand Down Expand Up @@ -138,7 +138,7 @@ public static function getCpuUtilStatusColor(?AgentStat $cpuUtil, Agent $agent):
return "#800000";
}
}

/**
* @param ?AgentStat $deviceUtil
* @return string
Expand All @@ -159,7 +159,7 @@ public static function getDeviceUtilStatusValue(?AgentStat $deviceUtil): string
$avg = $sum / sizeof($deviceUtil);
return round($avg, 1) . "%";
}

/**
* @param ?AgentStat $deviceTemp
* @return string
Expand All @@ -179,7 +179,7 @@ public static function getDeviceTempStatusValue(?AgentStat $deviceTemp): string
}
return $max . "°";
}

/**
* @param ?AgentStat $cpuUtil
* @return string
Expand All @@ -200,7 +200,7 @@ public static function getCpuUtilStatusValue(?AgentStat $cpuUtil): string {
$avg = $sum / sizeof($cpuUtil);
return round($avg, 1) . "%";
}

/**
* @param Agent $agent
* @param mixed $types
Expand All @@ -212,7 +212,7 @@ public static function getGraphData(Agent $agent, mixed $types): array {
if ($limit <= 0) {
$limit = 100;
}

$qF1 = new ContainFilter(AgentStat::STAT_TYPE, $types);
$qF2 = new QueryFilter(AgentStat::AGENT_ID, $agent->getId(), "=");
$oF1 = new OrderFilter(AgentStat::TIME, "DESC");
Expand Down Expand Up @@ -274,7 +274,7 @@ public static function getGraphData(Agent $agent, mixed $types): array {
}
return ["xlabels" => $xlabels, "sets" => $datasets, "axes" => $axes];
}

/**
* @param int $agentId
* @param boolean $isCpuOnly
Expand All @@ -286,7 +286,7 @@ public static function setAgentCpu(int $agentId, bool $isCpuOnly, User $user): v
$agent = AgentUtils::getAgent($agentId, $user);
Factory::getAgentFactory()->set($agent, Agent::CPU_ONLY, ($isCpuOnly) ? 1 : 0);
}

/**
* @param int $agentId
* @param User $user
Expand All @@ -295,11 +295,11 @@ public static function setAgentCpu(int $agentId, bool $isCpuOnly, User $user): v
*/
public static function clearErrors(int $agentId, User $user): void {
$agent = AgentUtils::getAgent($agentId, $user);

$qF = new QueryFilter(AgentError::AGENT_ID, $agent->getId(), "=");
Factory::getAgentErrorFactory()->massDeletion([Factory::FILTER => $qF]);
}

/**
* @param int $agentId
* @param string $newname
Expand All @@ -315,7 +315,7 @@ public static function rename(int $agentId, string $newname, User $user): void {
}
Factory::getAgentFactory()->set($agent, Agent::AGENT_NAME, $name);
}

/**
* @param int $agentId
* @param ?User $user
Expand All @@ -324,13 +324,13 @@ public static function rename(int $agentId, string $newname, User $user): void {
*/
public static function delete(int $agentId, ?User $user): void {
$agent = AgentUtils::getAgent($agentId, $user);

Factory::getAgentFactory()->getDB()->beginTransaction();
$name = $agent->getAgentName();

$payload = new DataSet(array(DPayloadKeys::AGENT => $agent));
NotificationHandler::checkNotifications(DNotificationType::DELETE_AGENT, $payload);

if (AgentUtils::deleteDependencies($agent)) {
Factory::getAgentFactory()->getDB()->commit();
Util::createLogEntry("User", (($user == null) ? 0 : ($user->getId())), DLogEntry::INFO, "Agent " . $name . " got deleted.");
Expand All @@ -340,7 +340,7 @@ public static function delete(int $agentId, ?User $user): void {
throw new HTException("Error occured on deletion of agent!");
}
}

/**
* @param Agent $agent
* @return boolean
Expand All @@ -358,34 +358,34 @@ public static function deleteDependencies(Agent $agent): bool {
}
$qF = new QueryFilter(AgentError::AGENT_ID, $agent->getId(), "=");
Factory::getAgentErrorFactory()->massDeletion([Factory::FILTER => $qF]);

$qF = new QueryFilter(AgentStat::AGENT_ID, $agent->getId(), "=");
Factory::getAgentStatFactory()->massDeletion([Factory::FILTER => $qF]);

$qF = new QueryFilter(AgentZap::AGENT_ID, $agent->getId(), "=");
Factory::getAgentZapFactory()->massDeletion([Factory::FILTER => $qF]);

$qF = new QueryFilter(HealthCheckAgent::AGENT_ID, $agent->getId(), "=");
Factory::getHealthCheckAgentFactory()->massDeletion([Factory::FILTER => $qF]);

$qF = new QueryFilter(Speed::AGENT_ID, $agent->getId(), "=");
Factory::getSpeedFactory()->massDeletion([Factory::FILTER => $qF]);

$qF = new QueryFilter(Zap::AGENT_ID, $agent->getId(), "=");
$uS = new UpdateSet(Zap::AGENT_ID, null);
Factory::getZapFactory()->massUpdate([Factory::FILTER => $qF, Factory::UPDATE => $uS]);

$qF = new QueryFilter(AccessGroupAgent::AGENT_ID, $agent->getId(), "=");
Factory::getAccessGroupAgentFactory()->massDeletion([Factory::FILTER => $qF]);

$qF = new QueryFilter(Chunk::AGENT_ID, $agent->getId(), "=");
$uS = new UpdateSet(Chunk::AGENT_ID, null);
Factory::getChunkFactory()->massUpdate([Factory::FILTER => $qF, Factory::UPDATE => $uS]);

Factory::getAgentFactory()->delete($agent);
return true;
}

/**
* @param int $agentId
* @param int $taskId
Expand All @@ -397,7 +397,7 @@ public static function deleteDependencies(Agent $agent): bool {
*/
public static function assign(int $agentId, int $taskId, User $user): ?Assignment {
$agent = AgentUtils::getAgent($agentId, $user);

if ($taskId == 0) { // unassign
$qF = new QueryFilter(Agent::AGENT_ID, $agent->getId(), "=");
Factory::getAssignmentFactory()->massDeletion([Factory::FILTER => $qF]);
Expand All @@ -407,29 +407,29 @@ public static function assign(int $agentId, int $taskId, User $user): ?Assignmen
}
return null;
}

$task = Factory::getTaskFactory()->get($taskId);
if ($task == null) {
throw new HttpError("Invalid task!");
}
else if (!AccessUtils::agentCanAccessTask($agent, $task)) {
throw new HttpError("This agent cannot access this task - either group mismatch, or agent is not configured as Trusted to access secret tasks");
}

$taskWrapper = Factory::getTaskWrapperFactory()->get($task->getTaskWrapperId());
if (!AccessUtils::userCanAccessTask($taskWrapper, $user)) {
throw new HttpError("No access to this task!");
}

$qF = new QueryFilter(Assignment::TASK_ID, $task->getId(), "=");
$assignments = Factory::getAssignmentFactory()->filter([Factory::FILTER => $qF]);
if ($task->getIsSmall() && sizeof($assignments) > 0) {
throw new HttpError("You cannot assign agent to this task as the limit of assignments is reached!");
}

$qF = new QueryFilter(Agent::AGENT_ID, $agent->getId(), "=");
$assignments = Factory::getAssignmentFactory()->filter([Factory::FILTER => $qF]);

$benchmark = 0;
if (sizeof($assignments) > 0) {
if ($assignments[0]->getTaskId() === $taskId) {
Expand All @@ -451,7 +451,7 @@ public static function assign(int $agentId, int $taskId, User $user): ?Assignmen
}
return $assignment;
}

/**
* @param int $agentId
* @param int $ignoreErrors
Expand All @@ -466,7 +466,7 @@ public static function changeIgnoreErrors(int $agentId, int $ignoreErrors, User
}
Factory::getAgentFactory()->set($agent, Agent::IGNORE_ERRORS, $ignoreErrors);
}

/**
* @param int $agentId
* @param ?User $user
Expand All @@ -484,7 +484,7 @@ public static function getAgent(int $agentId, ?User $user = null): Agent {
}
return $agent;
}

/**
* @param int $agentId
* @param boolean $trusted
Expand All @@ -496,7 +496,7 @@ public static function setTrusted(int $agentId, bool $trusted, User $user): void
$agent = AgentUtils::getAgent($agentId, $user);
Factory::getAgentFactory()->set($agent, Agent::IS_TRUSTED, ($trusted) ? 1 : 0);
}

/**
* @param int $agentId
* @param int|string $ownerId
Expand Down Expand Up @@ -526,7 +526,7 @@ public static function changeOwner(int $agentId, int|string $ownerId, User $user
}
Util::createLogEntry(DLogEntryIssuer::USER, $user->getId(), DLogEntry::INFO, "Owner for agent " . $agent->getAgentName() . " was changed to " . $username);
}

/**
* @param int $agentId
* @param string $cmdParameters
Expand All @@ -541,7 +541,7 @@ public static function changeCmdParameters(int $agentId, string $cmdParameters,
}
Factory::getAgentFactory()->set($agent, Agent::CMD_PARS, $cmdParameters);
}

/**
* @param int $agentId
* @param boolean $active
Expand All @@ -558,7 +558,7 @@ public static function setActive(int $agentId, bool $active, User $user, bool $t
else if (!AccessUtils::userCanAccessAgent($agent, $user)) {
throw new HTException("No access to this agent!");
}

if ($toggle) {
$set = ($agent->getIsActive() == 1) ? 0 : 1;
}
Expand All @@ -567,7 +567,7 @@ public static function setActive(int $agentId, bool $active, User $user, bool $t
}
Factory::getAgentFactory()->set($agent, Agent::IS_ACTIVE, $set);
}

/**
* @param string $newVoucher
* @return RegVoucher
Expand All @@ -580,12 +580,12 @@ public static function createVoucher(string $newVoucher): RegVoucher {
if ($check != null) {
throw new HttpConflict("Same voucher already exists!");
}

$key = htmlentities($newVoucher, ENT_QUOTES, "UTF-8");
$voucher = new RegVoucher(null, $key, time());
return Factory::getRegVoucherFactory()->save($voucher);
}

/**
* @param int|string $voucher
* @throws HTException
Expand All @@ -604,7 +604,7 @@ public static function deleteVoucher(int|string $voucher): void {
}
Factory::getRegVoucherFactory()->delete($voucher);
}

/**
* Get the aggregate cracking time of an agent or
* (if task ID is specified) of an agent on a specific task.
Expand All @@ -627,7 +627,7 @@ public static function getAggregateCrackingTime(int $agentId, ?int $taskId = nul
$results = Factory::getChunkFactory()->multicolAggregationFilter([Factory::FILTER => array_filter([$qF1, $qF2, $qF3, $qF4])], [$agg1, $agg2]);
return $results[$agg1->getName()] - $results[$agg2->getName()];
}

/**
* Get the aggregate number of hashes cracked by an agent or
* (if task ID is specified) by an agent on a specific task.
Expand Down
Loading