From b1c57fc5c72ecebf961a2bb5bf817c3ff2c10903 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Wed, 15 Jul 2026 20:32:50 -0400 Subject: [PATCH] Feature: Add new js function to retrieve and Audit log Password reveals, still need to get the edit modals --- agent/ajax.php | 25 ++++++++++++ agent/asset.php | 6 +-- agent/client_overview.php | 8 ++-- agent/contact.php | 6 +-- agent/credentials.php | 5 +-- agent/js/credential_show_password_via_id.js | 43 +++++++++++++++++++++ agent/modals/asset/asset.php | 7 ++-- agent/modals/contact/contact.php | 10 ++--- 8 files changed, 88 insertions(+), 22 deletions(-) create mode 100644 agent/js/credential_show_password_via_id.js diff --git a/agent/ajax.php b/agent/ajax.php index f63380c5..4bf9cfdf 100644 --- a/agent/ajax.php +++ b/agent/ajax.php @@ -1050,3 +1050,28 @@ if (isset($_GET['get_internal_users'])) { echo json_encode($response); exit; } + +if (isset($_GET['get_credential_via_id'])) { + enforceUserPermission('module_credential'); + + $credential_id = intval($_GET['credential_id']); + + $sql = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT credential_name, credential_username, credential_password, credential_client_id FROM credentials WHERE credential_id = $credential_id")); + $name = escapeSql($sql['credential_name']); + $client_id = intval($sql['credential_client_id']); + + enforceClientAccess($client_id); + + $response = array( + 'username' => decryptCredentialEntry($sql['credential_username']), + 'password' => decryptCredentialEntry($sql['credential_password']) + ); + echo json_encode($response); + + // Only log if this user hasn't viewed this credential recently (mirrors TOTP dedup) + $check_recent_view = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT(log_id) AS recent_view FROM logs WHERE log_type = 'Credential' AND log_action = 'View' AND log_user_id = $session_user_id AND log_entity_id = $credential_id AND log_client_id = $client_id AND log_created_at > (NOW() - INTERVAL 5 MINUTE)")); + + if (intval($check_recent_view['recent_view']) == 0) { + logAudit("Credential", "View", "$session_name viewed credential $name", $client_id, $credential_id); + } +} diff --git a/agent/asset.php b/agent/asset.php index bd1c487c..380a93c6 100644 --- a/agent/asset.php +++ b/agent/asset.php @@ -654,7 +654,6 @@ if (isset($_GET['asset_id'])) { } else { $credential_username_display = "$credential_username"; } - $credential_password = escapeHtml(decryptCredentialEntry($row['credential_password'])); $credential_otp_secret = escapeHtml($row['credential_otp_secret']); $credential_id_with_secret = '"' . $row['credential_id'] . '","' . $row['credential_otp_secret'] . '"'; if (empty($credential_otp_secret)) { @@ -701,7 +700,7 @@ if (isset($_GET['asset_id'])) { - + @@ -1257,8 +1256,9 @@ if (isset($_GET['asset_id'])) { }); - + + diff --git a/agent/client_overview.php b/agent/client_overview.php index b54aec39..e8012d87 100644 --- a/agent/client_overview.php +++ b/agent/client_overview.php @@ -256,7 +256,7 @@ $sql_asset_retired = mysqli_query(
@@ -378,7 +378,6 @@ $sql_asset_retired = mysqli_query( } else { $credential_username_display = "$credential_username"; } - $credential_password = escapeHtml(decryptCredentialEntry($row['credential_password'])); $credential_otp_secret = escapeHtml($row['credential_otp_secret']); $credential_id_with_secret = '"' . $row['credential_id'] . '","' . $row['credential_otp_secret'] . '"'; if (empty($credential_otp_secret)) { @@ -397,7 +396,7 @@ $sql_asset_retired = mysqli_query( - +
@@ -800,8 +799,9 @@ $sql_asset_retired = mysqli_query(
- + + - + + "; } - $credential_password = escapeHtml(decryptCredentialEntry($row['credential_password'])); $credential_otp_secret = escapeHtml($row['credential_otp_secret']); - $credential_id_with_secret = '"' . $row['credential_id'] . '","' . $row['credential_otp_secret'] . '"'; if (empty($credential_otp_secret)) { $otp_display = "-"; } else { @@ -444,7 +442,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); - + @@ -541,6 +539,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); + "; } - $credential_password = escapeHtml(decryptCredentialEntry($row['credential_password'])); $credential_otp_secret = escapeHtml($row['credential_otp_secret']); $credential_id_with_secret = '"' . $row['credential_id'] . '","' . $row['credential_otp_secret'] . '"'; if (empty($credential_otp_secret)) { @@ -573,8 +572,7 @@ ob_start(); - - + @@ -590,8 +588,9 @@ ob_start(); - + + diff --git a/agent/modals/contact/contact.php b/agent/modals/contact/contact.php index f4695ea3..9807c735 100644 --- a/agent/modals/contact/contact.php +++ b/agent/modals/contact/contact.php @@ -556,8 +556,6 @@ ob_start(); $credential_username_display = "$credential_username "; } - $credential_password = escapeHtml(decryptCredentialEntry($row['credential_password'])); - $credential_otp_secret = escapeHtml($row['credential_otp_secret']); if (empty($credential_otp_secret)) { $otp_display = "-"; @@ -570,10 +568,10 @@ ob_start(); - - @@ -586,7 +584,9 @@ ob_start(); + +