Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add RuleTitle to ttp-summary command output #83

Merged
merged 4 commits into from
Jan 2, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG-Japanese.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**改善:**

- `ttp-visualize` コマンドで、MITRE ATT&CK Navigator上のテクニックをマウスオーバーしたときに、検知ルール名が表示されるようした。(#82) (@fukusuket)
- `ttp-summary`コマンドの結果にルールのタイトルを追加した。(#83) (@fukusuket)

## 2.3.0 [2023/12/23] - SECCON Christmas Release

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Enhancements:**

- In the `ttp-visualize` command, the name of the rule that detected the technique will now be shown in the comment when hovering over the technique in MITRE ATT&CK Navigator. (#82) (@fukusuket)
- Added rule titles to the `ttp-summary` command output. (#83) (@fukusuket)

## 2.3.0 [2023/12/23] - SECCON Christmas Release

Expand Down
26 changes: 16 additions & 10 deletions src/takajopkg/ttpSummary.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ proc readJsonFromFile(filename: string): JsonNode =
file.close()
result = parseJson(content)

proc compareArrays(a, b: array[4, string]): int =
proc compareArrays(a, b: array[5, string]): int =
for i in 0..<4:
if a[i] < b[i]:
return -1
Expand Down Expand Up @@ -58,7 +58,7 @@ proc ttpSummary(output: string = "", quiet: bool = false, timeline: string) =
let attack = readJsonFromFile("mitre-attack.json")
var
bar: SuruBar = initSuruBar()
seqOfResultsTables: seq[array[4, string]]
seqOfResultsTables: seq[array[5, string]]

bar[0].total = totalLines
bar.setup()
Expand All @@ -77,15 +77,16 @@ proc ttpSummary(output: string = "", quiet: bool = false, timeline: string) =
let tac = tac_no[dat] & dat
let tec = res["Technique"].getStr()
let sub = res["Sub-Technique"].getStr()
seqOfResultsTables.add([com, tac, tec, sub])
let rul = jsonLine["RuleTitle"].getStr()
seqOfResultsTables.add([com, tac, tec, sub, rul])
except CatchableError:
continue
seqOfResultsTables.sort(compareArrays)
bar.finish()

let header = ["Computer", "Tactic", "Technique", "Sub-Technique", "Count"]
var prev = ["","","",""]
let header = ["Computer", "Tactic", "Technique", "Sub-Technique", "RuleTitle", "Count"]
var prev = ["","","","",""]
var count = 1
var ruleStr = initHashSet[string]()
if output != "":
# Open file to save results
var outputFile = open(output, fmWrite)
Expand All @@ -95,14 +96,17 @@ proc ttpSummary(output: string = "", quiet: bool = false, timeline: string) =

## Write contents
for arr in seqOfResultsTables:
if arr == prev:
ruleStr.incl(arr[4])
if arr[0..<4] == prev[0..<4]:
count += 1
continue
for i, val in enumerate(arr):
for i, val in enumerate(arr[0..<4]):
outputFile.write(escapeCsvField(val) & ",")
outputFile.write(escapeCsvField(ruleStr.mapIt($it).join(", ")) & ",")
outputFile.write(escapeCsvField(intToStr(count)))
prev = arr
count = 1
ruleStr = initHashSet[string]()
outputFile.write("\p")
outputFile.close()
let fileSize = getFileSize(output)
Expand All @@ -113,12 +117,14 @@ proc ttpSummary(output: string = "", quiet: bool = false, timeline: string) =
var table: TerminalTable
table.add header
for arr in seqOfResultsTables:
if arr == prev:
ruleStr.incl(arr[4])
if arr[0..<4] == prev[0..<4]:
count += 1
continue
table.add arr[0], arr[1], arr[2], arr[3], intToStr(count)
table.add arr[0], arr[1], arr[2], arr[3], ruleStr.mapIt($it).join(", "), intToStr(count)
prev = arr
count = 1
ruleStr = initHashSet[string]()
table.echoTableSepsWithStyled(seps = boxSeps)

echo ""
Expand Down