Skip to content

Commit

Permalink
Merge pull request #371 from ColonelThirtyTwo/oplog-entry-identifier
Browse files Browse the repository at this point in the history
Add "Identifier" to oplog entry
  • Loading branch information
chrismaddalena authored Dec 14, 2023
2 parents c33041b + 97faee6 commit 9b42699
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 44 deletions.
10 changes: 7 additions & 3 deletions ghostwriter/oplog/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,13 @@ def __init__(self, *args, **kwargs):

self.helper.layout = Layout(
Row(
Column(Field("start_date", step=1), css_class="form-group col-4 mb-0"),
Column(Field("end_date", step=1), css_class="form-group col-4 mb-0"),
Column("operator_name", css_class="form-group col-4 mb-0"),
Column(Field("start_date", step=1), css_class="form-group col-6 mb-0"),
Column(Field("end_date", step=1), css_class="form-group col-6 mb-0"),
css_class="form-row",
),
Row(
Column("entry_identifier", css_class="form-group col-6 mb-0"),
Column("operator_name", css_class="form-group col-6 mb-0"),
css_class="form-row",
),
Row(
Expand Down
22 changes: 22 additions & 0 deletions ghostwriter/oplog/migrations/0012_auto_20231211_2154.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.19 on 2023-12-11 21:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('oplog', '0011_auto_20230323_2248'),
]

operations = [
migrations.AddField(
model_name='oplogentry',
name='entry_identifier',
field=models.CharField(blank=True, help_text='Integrations may use this to track log entries.', max_length=65535, null=True, verbose_name='Identifier'),
),
migrations.AddIndex(
model_name='oplogentry',
index=models.Index(fields=['oplog_id', 'entry_identifier'], name='oplog_oplog_oplog_i_0e03f5_idx'),
),
]
10 changes: 10 additions & 0 deletions ghostwriter/oplog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ def __str__(self):
class OplogEntry(models.Model):
"""Stores an individual log entry, related to :model:`oplog.Oplog`."""

entry_identifier = models.CharField(
"Identifier",
null=True,
blank=True,
help_text="Integrations may use this to track log entries.",
max_length=65535,
)
start_date = models.DateTimeField(
"Start Date",
null=True,
Expand Down Expand Up @@ -135,6 +142,9 @@ class Meta:
ordering = ["-start_date", "-end_date", "oplog_id"]
verbose_name = "Activity log entry"
verbose_name_plural = "Activity log entries"
indexes = [
models.Index(fields=["oplog_id", "entry_identifier"]),
]

def clean(self, *args, **kwargs):
if isinstance(self.start_date, str):
Expand Down
2 changes: 2 additions & 0 deletions ghostwriter/oplog/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def test_view_uses_correct_template(self):
def test_post_data_and_permissions(self):
filename = "oplog_import_test.csv"
fieldnames = [
"entry_identifier",
"start_date",
"end_date",
"source_ip",
Expand Down Expand Up @@ -207,6 +208,7 @@ def test_oplog_id_override(self):
"""Test that the ``oplog_id`` field is overridden when importing."""
filename = "oplog_import_test.csv"
fieldnames = [
"entry_identifier",
"oplog_id",
"start_date",
"end_date",
Expand Down
57 changes: 24 additions & 33 deletions ghostwriter/static/js/oplog.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ let hiddenLogTblColumns = JSON.parse((localStorage.getItem('hiddenLogTblColumns'
// Assemble the array of column information for the table
let columnInfo = []
columnInfo = [
['startDateCheckBox', 'startDateColumn', 'Start Date', 'start_date'],
['endDateCheckbox', 'endDateColumn', 'End Date', 'end_date'],
// [checkBoxID, columnClass, Pretty Name, name_in_json, toHtmlFunc (default `jsescape`), shownByDefault (default true)]
['identifierCheckBox', 'identifierColumn', 'Identifier', 'entry_identifier', undefined, false],
['startDateCheckBox', 'startDateColumn', 'Start Date', 'start_date', entry => jsEscape(entry).replace(/\.\d+/, "").replace("Z", "").replace("T", " ")],
['endDateCheckbox', 'endDateColumn', 'End Date', 'end_date', entry => jsEscape(entry).replace(/\.\d+/, "").replace("Z", "").replace("T", " ")],
['sourceIPCheckbox', 'sourceIPColumn', 'Source', 'source_ip'],
['destIPCheckbox', 'destIPColumn', 'Destination', 'dest_ip'],
['toolNameCheckbox', 'toolNameColumn', 'Tool Name', 'tool'],
Expand All @@ -17,25 +19,17 @@ columnInfo = [
['outputCheckbox', 'outputColumn', 'Output', 'output'],
['commentsCheckbox', 'commentsColumn', 'Comments', 'comments'],
['operatorCheckbox', 'operatorColumn', 'Operator', 'operator_name'],
['tagsCheckbox', 'tagsColumn', 'Tags', 'tags'],
['tagsCheckbox', 'tagsColumn', 'Tags', 'tags', entry => stylizeTags(jsEscape(entry))],
['optionsCheckbox', 'optionsColumn', 'Options', ''],
]

// Generate a table row based on a log entry
function generateTableHeaders() {
return `<th class="${columnInfo[0][1]} align-middle">${columnInfo[0][2]}</th>
<th class="${columnInfo[1][1]} align-middle">${columnInfo[1][2]}</th>
<th class="${columnInfo[2][1]} align-middle">${columnInfo[2][2]}</th>
<th class="${columnInfo[3][1]} align-middle">${columnInfo[3][2]}</th>
<th class="${columnInfo[4][1]} align-middle">${columnInfo[4][2]}</th>
<th class="${columnInfo[5][1]} align-middle">${columnInfo[5][2]}</th>
<th class="${columnInfo[6][1]} align-middle">${columnInfo[6][2]}</th>
<th class="${columnInfo[7][1]} align-middle">${columnInfo[7][2]}</th>
<th class="${columnInfo[8][1]} align-middle">${columnInfo[8][2]}</th>
<th class="${columnInfo[9][1]} align-middle">${columnInfo[9][2]}</th>
<th class="${columnInfo[10][1]} align-middle">${columnInfo[10][2]}</th>
<th class="${columnInfo[11][1]} align-middle">${columnInfo[11][2]}</th>
<th class="${columnInfo[12][1]} align-middle">${columnInfo[12][2]}</th>`
let out = "";
columnInfo.forEach(column => {
out += `<th class="${column[1]} align-middle">${column[2]}</th>`
});
return out;
}

// Convert a table row to JSON and copy it to the clipboard
Expand Down Expand Up @@ -84,25 +78,21 @@ function convertRowToJSON(row_id) {

// Generate a table row based on a log entry
function generateRow(entry) {
return `<tr id="${entry["id"]}" class="editableRow">
<td class="${columnInfo[0][1]} align-middle">${jsEscape(entry["start_date"]).replace(/\.\d+/, "").replace("Z", "").replace("T", " ")}</td>
<td class="${columnInfo[1][1]} align-middle">${jsEscape(entry["end_date"]).replace(/\.\d+/, "").replace("Z", "").replace("T", " ")}</td>
<td class="${columnInfo[2][1]} align-middle">${jsEscape(entry["source_ip"])}</td>
<td class="${columnInfo[3][1]} align-middle">${jsEscape(entry["dest_ip"])}</td>
<td class="${columnInfo[4][1]} align-middle">${jsEscape(entry["tool"])}</td>
<td class="${columnInfo[5][1]} align-middle">${jsEscape(entry["user_context"])}</td>
<td class="${columnInfo[6][1]} align-middle"><div>${jsEscape(entry["command"])}<div></td>
<td class="${columnInfo[7][1]} align-middle"><div>${jsEscape(entry["description"])}</div></td>
<td class="${columnInfo[8][1]} align-middle"><div>${jsEscape(entry["output"])}</div></td>
<td class="${columnInfo[9][1]} align-middle"><div>${jsEscape(entry["comments"])}</div></td>
<td class="${columnInfo[10][1]} align-middle">${jsEscape(entry["operator_name"])}</td>
<td class="${columnInfo[11][1]} align-middle">${stylizeTags(jsEscape(entry["tags"]))}</td>
<td class="${columnInfo[12][1]} align-middle">
let out = `<tr id="${entry["id"]}" class="editableRow">`;
columnInfo.forEach(column => {
if(column[0] == "optionsCheckbox") {
out += `<td class="${column[1]} align-middle">
<button class="btn" data-toggle="tooltip" data-placement="left" title="Create a copy of this log entry" onClick="copyEntry(this);" entry-id="${entry['id']}"><i class="fa fa-copy"></i></button>
<button class="btn" data-toggle="tooltip" data-placement="left" title="Copy this entry to your clipboard as JSON" onClick="convertRowToJSON(${entry["id"]});"><i class="fas fa-clipboard"></i></button>
<button class="btn danger" data-toggle="tooltip" data-placement="left" title="Delete this log entry" onClick="deleteEntry(this);" entry-id="${entry['id']}"><i class="fa fa-trash"></i></button>
</td>
</tr>`
</td>`
} else {
let value = entry[column[3]];
let filter = column[4] ?? jsEscape;
out += `<td class="${column[1]} align-middle">${filter(value)}</td>`;
}
});
return out + "</tr>";
}

// Add a placeholder row that spans the entire table
Expand Down Expand Up @@ -156,10 +146,11 @@ function coupleCheckboxColumn(checkboxId, columnClass) {
// Build the column show/hide checkboxes
function buildColumnsCheckboxes() {
columnInfo.forEach(function (value, _, _) {
let checked = (value[5] === undefined || value[5]) ? "checked" : "";
let checkboxEntry = `
<div class="form-check-inline">
<div class="custom-control custom-switch">
<input type="checkbox" id="${value[0]}" class="form-check-input custom-control-input" checked/>
<input type="checkbox" id="${value[0]}" class="form-check-input custom-control-input" ${checked}/>
<label class="form-check-label custom-control-label" for="${value[0]}">${value[2]}</label>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ insert_permissions:
- description
- dest_ip
- end_date
- entry_identifier
- operator_name
- oplog_id_id
- output
Expand Down Expand Up @@ -70,30 +71,32 @@ insert_permissions:
- description
- dest_ip
- end_date
- entry_identifier
- operator_name
- oplog_id_id
- output
- source_ip
- start_date
- tool
- user_context
- operator_name
select_permissions:
- role: manager
permission:
columns:
- id
- oplog_id_id
- operator_name
- command
- comments
- description
- dest_ip
- end_date
- entry_identifier
- id
- operator_name
- oplog_id_id
- output
- source_ip
- start_date
- tool
- user_context
- end_date
- start_date
filter: {}
- role: user
permission:
Expand Down Expand Up @@ -121,6 +124,7 @@ update_permissions:
- description
- dest_ip
- end_date
- entry_identifier
- operator_name
- oplog_id_id
- output
Expand All @@ -138,13 +142,14 @@ update_permissions:
- description
- dest_ip
- end_date
- entry_identifier
- operator_name
- oplog_id_id
- output
- source_ip
- start_date
- tool
- user_context
- operator_name
filter:
log:
project:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ event_triggers:
value_from_env: HASURA_ACTION_SECRET
- name: DeleteReportFinding
definition:
enable_manual: false
delete:
columns: '*'
enable_manual: false
retry_conf:
interval_sec: 10
num_retries: 0
Expand Down

0 comments on commit 9b42699

Please sign in to comment.