Skip to content

Instantly share code, notes, and snippets.

@scudette
Created May 18, 2020 01:46
Show Gist options
  • Select an option

  • Save scudette/44540483c9fcf577507434259735e891 to your computer and use it in GitHub Desktop.

Select an option

Save scudette/44540483c9fcf577507434259735e891 to your computer and use it in GitHub Desktop.
Artifact to remove Velociraptor that has been installed manually
name: Custom.Uninstall.Velociraptor
description: |
Uninstall Velociraptor which was installed using
```
Velociraptor.exe --config client.config.yaml service install
```
The problem with installation method is that it becomes hard to remove since it
is not properly managed by the windows installer. We can not delete the executable
we are running from and if we stopped the service, we wont be around to delete the
executable
This artifact creates a scheduled task in 2 minutes to remove the executable, then we
stop and delete the service. The executable should be removed by the scheduled task later.
parameters:
- name: PostInstallScript
description: This script will be run inside the scheduled task.
default: |
Get-ChildItem "C:/Program Files/velociraptor/*" -Include *.exe | Remove-Item
- name: PowershellScript
default: |
sc.exe delete velociraptor
schtasks /delete /tn vraptor /f
$time = [DateTime]::Now.AddMinutes(2)
$user = "system"
$action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument ' -ExecutionPolicy Unrestricted -encodedCommand %s'
$trigger = New-ScheduledTaskTrigger -Once -At $time
Register-ScheduledTask -Action $action -User $user -TaskName "vraptor" -Trigger $trigger
echo stopping service - This will kill us but the scheduled task above will clean up after.
sc.exe stop velociraptor
sources:
- precondition:
SELECT OS From info() where OS = 'windows'
query: |
SELECT * FROM execve(argv=[
"powershell",
"-ExecutionPolicy", "Unrestricted", "-encodedCommand",
base64encode(string=utf16_encode(
string=format(format=PowershellScript,
args=base64encode(string=utf16_encode(
string=PostInstallScript)))))])
@dfirhoze
Copy link

Is there any method to fully remove everything, even the Velociraptor directory created in Program Files?

@scudette
Copy link
Author

scudette commented May 11, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment