-
Notifications
You must be signed in to change notification settings - Fork 253
Add Windows PowerShell Timeline artifact #1144
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
Open
0xHasanM
wants to merge
9
commits into
Velocidex:master
Choose a base branch
from
0xHasanM:patch-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b6fe4a2
Add Windows PowerShell Timeline artifact
0xHasanM 58ac0f2
Update Windows.Powershell.Timeline
0xHasanM 84f712f
Update Windows.Powershell.Timeline
0xHasanM 88ead83
Refactor queries to include additional fields
0xHasanM a7e0820
Merge branch 'master' into patch-2
0xHasanM 041eaac
Rename Windows.Powershell.Timeline to Windows.Powershell.Timeline.yaml
0xHasanM 9ba2ba6
Merge branch 'master' into patch-2
0xHasanM ad763ff
Merge branch 'master' into patch-2
0xHasanM 34607cd
Merge branch 'master' into patch-2
0xHasanM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
content/exchange/artifacts/Windows.Powershell.Timeline.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| name: Windows.Powershell.Timeline | ||
| author: Mohammed Hasan, 0xHasanm | ||
| description: | | ||
| This artifact extracts commands executed from each user's ConsoleHost_History.txt and correlates the timestamps of Data_Added events in the USNJRNL with those commands to construct a timeline of PowerShell command execution. | ||
|
|
||
| # Can be CLIENT, CLIENT_EVENT, SERVER, SERVER_EVENT or NOTEBOOK | ||
| type: CLIENT | ||
|
|
||
| parameters: | ||
| - name: user | ||
| default: . | ||
|
|
||
| references: | ||
| - https://www.linkedin.com/posts/0xhasanm_sundfirday-dfir-powershell-activity-7395908066409484288-eNSo | ||
|
|
||
| sources: | ||
| - precondition: | ||
| SELECT OS From info() where OS = 'windows' | ||
|
|
||
| query: | | ||
| LET USN_EVENTS <= SELECT | ||
| Timestamp, | ||
| split(string=OSPath, sep_string="\\")[-8] AS username, | ||
| Reason | ||
| FROM Artifact.Windows.Forensics.Usn(FileNameRegex="ConsoleHost_History.txt") | ||
| WHERE username =~ user | ||
| and len(list=Reason) = 2 | ||
| and (Reason[0] = "DATA_EXTEND" or Reason[1] = "DATA_EXTEND") | ||
| ORDER BY Timestamp DESC | ||
|
|
||
| LET PSReadline <= SELECT LineNum, | ||
| Line, | ||
| Username | ||
| FROM Artifact.Windows.System.Powershell.PSReadline() | ||
| WHERE Username =~ user | ||
| ORDER BY LineNum DESC | ||
|
|
||
| LET USN_EVENTS_Indexed <= SELECT count() AS EventID, | ||
| * | ||
| FROM USN_EVENTS | ||
|
|
||
| LET PSReadline_Indexed <= SELECT count() AS CommandID, | ||
| * | ||
| FROM PSReadline | ||
|
|
||
| LET results_with_timestamp <= SELECT * | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be very slow. It looks like you want to do a join. See this |
||
| FROM foreach(row={ | ||
| SELECT * | ||
| FROM USN_EVENTS_Indexed | ||
| }, | ||
| query={ | ||
| SELECT Timestamp, | ||
| Line AS Command, | ||
| Username | ||
| FROM PSReadline_Indexed | ||
| WHERE CommandID = EventID | ||
| }) | ||
|
|
||
| LET PSReadline_length <= array(_={ SELECT CommandID FROM PSReadline_Indexed }).CommandID | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just do |
||
|
|
||
| LET usn_results_without_command <= SELECT * | ||
| FROM foreach(row={ | ||
| SELECT PSReadline_length[-1] AS PSReadline_LineNumbers | ||
| FROM scope() | ||
| }, | ||
| query={ | ||
| SELECT Timestamp, | ||
| "N/A" AS Command, | ||
| username | ||
| FROM USN_EVENTS_Indexed | ||
| WHERE EventID > PSReadline_LineNumbers | ||
| }) | ||
|
|
||
| LET USN_EVENTS_length <= array(_={ SELECT EventID FROM USN_EVENTS_Indexed }).EventID | ||
|
|
||
| LET psreadline_results_without_timestamp <= SELECT * | ||
| FROM foreach(row={ | ||
| SELECT USN_EVENTS_length[-1] AS USN_EVENTS_EventNumbers | ||
| FROM scope() | ||
| }, | ||
| query={ | ||
| SELECT "N/A" AS Timestamp, | ||
| Line AS Command, | ||
| Username | ||
| FROM PSReadline_Indexed | ||
| WHERE CommandID > USN_EVENTS_EventNumbers | ||
| }) | ||
|
|
||
| SELECT * | ||
| FROM chain(a={ | ||
| SELECT * | ||
| FROM results_with_timestamp | ||
| }, | ||
| b={ | ||
| SELECT * | ||
| FROM usn_results_without_command | ||
| }, | ||
| c={ | ||
| SELECT * | ||
| FROM psreadline_results_without_timestamp | ||
| }) | ||
| ORDER BY Timestamp | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You dont need to split here - just use OSPath[-8]
https://docs.velociraptor.app/docs/forensic/filesystem/paths/