Skip to content

Commit

Permalink
fix: Added check for jsonl format
Browse files Browse the repository at this point in the history
  • Loading branch information
fukusuket committed Sep 30, 2023
1 parent 4dd7e92 commit fa366b7
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/takajopkg/general.nim
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,25 @@ proc isLocalIP*(ip: string): bool =
return ip == "127.0.0.1" or ip == "-" or ip == "::1"


proc isJsonConvertible*(timeline: string) : bool =
var
file: File
firstLine: string
jsonLine: JsonNode
if file.open(timeline):
try:
firstLine = file.readLine()
jsonLine = parseJson(firstLine)
return true
except:
echo "Failed to convert '" & timeline & "'.This file is not in JSONL format."
echo "Please specify a file that has been executed with the Hayabusa json-timeline command --JSONL-output(-L) option."
return false
finally:
close(file)
echo "Failed to open '" & timeline & "'.Please specify a valid file path."
return false

type VirusTotalResult* = object
resTable*: TableRef[string, string]
resJson*: JsonNode
Expand Down
3 changes: 3 additions & 0 deletions src/takajopkg/listDomains.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ proc listDomains(includeSubdomains: bool = false, includeWorkstations: bool = fa
echo "The file '" & timeline & "' does not exist. Please specify a valid file path."
quit(1)

if not isJsonConvertible(timeline):
quit(1)

echo "Started the List Domains command"
echo ""
echo "Local queries to workstations are filtered out by default, but can be included with -w, --includeWorkstations."
Expand Down
3 changes: 3 additions & 0 deletions src/takajopkg/listHashes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ proc listHashes(level: string = "high", output: string, quiet: bool = false, tim
echo "The file '" & timeline & "' does not exist. Please specify a valid file path."
quit(1)

if not isJsonConvertible(timeline):
quit(1)

if level != "critical" and level != "high" and level != "medium" and level != "low" and level != "informational":
echo "You must specify a minimum level of critical, high, medium, low or informational. (default: high)"
echo ""
Expand Down
3 changes: 3 additions & 0 deletions src/takajopkg/listIpAddresses.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ proc listIpAddresses(inbound: bool = true, outbound: bool = true, output: string
echo "The file '" & timeline & "' does not exist. Please specify a valid file path."
quit(1)

if not isJsonConvertible(timeline):
quit(1)

# Error if both inbound and outbound are set to false as there is nothing to search for.
if inbound == false and outbound == false:
echo "You must enable inbound and/or outbound searching."
Expand Down
3 changes: 3 additions & 0 deletions src/takajopkg/splitJsonTimeline.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ proc splitJsonTimeline(output: string = "output", quiet: bool = false, timeline:
echo "The file '" & timeline & "' does not exist. Please specify a valid file path."
quit(1)

if not isJsonConvertible(timeline):
quit(1)

echo "Started the Split JSONL Timeline command"
echo ""
echo "This command will split a large JSONL timeline into many multiple ones based on computer name."
Expand Down
3 changes: 3 additions & 0 deletions src/takajopkg/stackLogons.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ proc stackLogons(localSrcIpAddresses = false, output: string = "", quiet: bool =
echo "The file '" & timeline & "' does not exist. Please specify a valid file path."
quit(1)

if not isJsonConvertible(timeline):
quit(1)

echo "Started the Stack Logons command"
echo ""
echo "This command will stack logons based on target user, target computer, source IP address and source computer."
Expand Down
3 changes: 3 additions & 0 deletions src/takajopkg/sysmonProcessTree.nim
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ proc sysmonProcessTree(output: string = "", processGuid: string,
echo "The file '" & timeline & "' does not exist. Please specify a valid file path."
quit(1)

if not isJsonConvertible(timeline):
quit(1)

echo ""
echo "Running the Process Tree module"
echo ""
Expand Down
3 changes: 3 additions & 0 deletions src/takajopkg/timelineLogon.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ proc timelineLogon(calculateElapsedTime: bool = true, output: string, outputLogo
echo "The file '" & timeline & "' does not exist. Please specify a valid file path."
quit(1)

if not isJsonConvertible(timeline):
quit(1)

echo "Started the Timeline Logon command"
echo ""
echo "This command creates a CSV timeline of logon events."
Expand Down
3 changes: 3 additions & 0 deletions src/takajopkg/timelineSuspiciousProcesses.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ proc timelineSuspiciousProcesses(level: string = "high", output: string = "", qu
echo "The file '" & timeline & "' does not exist. Please specify a valid file path."
quit(1)

if not isJsonConvertible(timeline):
quit(1)

if level != "critical" and level != "high" and level != "medium" and level != "low" and level != "informational":
echo "You must specify a minimum level of critical, high, medium, low or informational. (default: high)"
echo ""
Expand Down

0 comments on commit fa366b7

Please sign in to comment.