#requires -RunAsAdministrator Import-Module NetSecurity #Useful to manipulate firewall rules $HOST_FILE = "$env:windir\System32\drivers\etc\hosts" $HOST_IP = "0.0.0.0" $ErrorActionPreference = "SilentlyContinue" #Thanks to https://gist.github.com/markembling/173887 function BlockHost { param( [Parameter( ValueFromPipeline=$False, ParameterSetName="params", Position = 0 )] [object]$params ) if ( $params.file ) { Foreach ($line in Get-Content $params.file ){ BlockHost -params @{host=$line} } } if ( $params.host ) { Write-Host -NoNewline "`t$($params.host) : " try { if ( ! $(IsHostAlreadyBlocked $HOST_FILE $params.host) ){ $HOST_IP + "`t`t" + $params.host | Out-File -encoding ASCII -append $HOST_FILE } else { Write-Host -ForegroundColor Yellow "already blocked " return } } catch { Write-Host -ForegroundColor Red "error" return } Write-Host -ForegroundColor Green "done" } } function IsHostAlreadyBlocked { param([string]$filename, [string]$hostname) $c = Get-Content $filename foreach ($line in $c) { $bits = [regex]::Split($line, "\t+") if ($bits[1] -eq $hostname) { return $true } } return $false } function FwBlockOutputIP { param( [object]$params ) if ( $params.file ) { foreach ($line in Get-Content $params.file ){ FwBlockOutputIP @{"ip"="$line"} } } if ( $params.ip) { Write-Host -NoNewline "`t$($params.ip) : " if ( Get-NetFirewallRule -Name Blacklist_$($params.ip) -ErrorAction SilentlyContinue) { Write-Host -ForegroundColor Yellow "already blacklisted" return } else { Try { New-NetFirewallRule -Name Blacklist_$($params.ip) -DisplayName "BlackList $($params.ip)" -Protocol any -Enabled True -Profile Any -RemoteAddress $params.ip -Action Block | Out-Null } Catch { Write-Host -ForegroundColor Red "error" return } Write-Host -ForegroundColor Green "done" } } } function remove_shitty_tasks () { param($taskList) Foreach ($task in $taskList){ Write-Host -NoNewline "`t$task : " if ($PSVersionTable.PSVersion.Major -gt 2) { if (Get-ScheduledTask -TaskName $task -ErrorAction SilentlyContinue) { Write-Host -NoNewline -ForegroundColor DarkGreen "found! " Write-Host -Nonewline -ForegroundColor white "removing : " Try {Unregister-ScheduledTask -TaskName $task -ErrorAction SilentlyContinue -Confirm:$false} Catch { Write-Host -Nonewline -ForegroundColor Red "error" } Write-Host -ForegroundColor Green "done" } else { Write-Host -ForegroundColor Yellow "already removed"} } else { Write-Host -ForegroundColor Red "damned! this is not Windows 10!" } } } # Modify a reg value # Params : # path : the complete path to reg key # key : key name # value : The value to write function AddRegKey { param( [Parameter(Mandatory=$false)] [object]$params ) Write-Host -NoNewline "`t$($params.key) reg key to $($params.value) : " if ( -not $params.path -or -not $params.key -or -not $params.value ) { Write-Host -ForegroundColor Red -NoNewline "Error in AddRegKey : no path, key or value" } if ( -not $params.type ){ $params.type="DWORD" } if ( -not (Test-Path $params.path) ){ Write-Host -NoNewline "- creating path -" New-Item -Path $params.path -Force | Out-Null } try { Set-ItemProperty -Path $params.path -Name $params.key -Value $params.value -Type $params.type -Force } catch [System.Security.SecurityException]{ Write-Host -ForegroundColor Red "access denied" return } catch { Write-Host -NoNewLine -ForegroundColor Red "`tError`n`t" write-Host -ForegroundColor DarkRed $Error[0].Exception.Message return } Write-host -ForegroundColor Green "done" } # Delete a reg key # Params : # path : the complete path to reg key # key : key name function delete_shitty_reg_key { param([string]$path, [string]$key) Write-Host -NoNewline "`tDelete key $key reg : " if (!(Test-Path $path)){ Write-Host -ForegroundColor Red -NoNewline "path not found" return } try { Remove-ItemProperty -Path $path -Name $key } catch [System.Security.SecurityException]{ Write-Host -ForegroundColor Red "access denied" return } catch { Write-Host -ForegroundColor Red "error" Write-Host "`t$Error[0]" return } Write-host -ForegroundColor Green "done" } # Function to remove shitty prog from shitty win # Params : # $name : Feature name function disable_shitty_feature { param ($name) Write-Host -NoNewline "`t$name : " $requestInstall = dism /online /Get-FeatureInfo /FeatureName:$name /English $isInstalled = $requestInstall | Select-String "state" If ($isInstalled -match "Enable") { try { Dism /online /Disable-Feature /FeatureName:$name /NoRestart | Out-Null } catch { Write-Host -ForegroundColor Red "error" Return } Write-Host -ForegroundColor Green "done" } else { Write-Host -ForegroundColor Yellow "already disable" } } # remove unwanted "Modern App" # Params # function UninstallModernApp { param( [cmdletbinding( DefaultParameterSetName='params' )] [Parameter( ValueFromPipeline=$False, ParameterSetName="params", Position = 0 )] [object]$params, [Parameter( ValueFromPipeline=$True, ParameterSetName="pkg", Position = 0 )] [Object]$pkg ) if ( $params.file ) { Get-AppxPackage -AllUsers | Where-Object { $_.name -in $(Get-Content $params.file) } | foreach { $_ | UninstallModernApp } } elseif ( $params.name ) { $(Get-AppxPackage -AllUsers | Where-Object { $_.name -like "*$($params.name)*" } ) | UninstallModernApp } elseif ( $pkg ) { try { Write-Host -NoNewLine "`tUninstall $($pkg.Name) :" $pkg | Remove-AppxPackage | Out-Null Write-Host -ForegroundColor Green "done" } catch { Write-Host -NoNewLine -ForegroundColor Red "`tError in UninstallModernApp`n`t" write-Host -ForegroundColor DarkRed $Error[0].Exception.Message return } } if ( $params.removeProvisionned ) { UninstallModernProvisonnedApp $params } } function UninstallModernProvisonnedApp { param( [cmdletbinding( DefaultParameterSetName='params' )] [Parameter( ValueFromPipeline=$False, #ParameterSetName="params", Position = 0 )] [object]$params, [Parameter( ValueFromPipeline=$True, ParameterSetName="pkg", Position = 0 )] [Object]$pkg ) if ( $params.file ) { Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -in $(Get-Content $params.file) } | foreach { UninstallModernProvisonnedApp -pkg $_ } } elseif ( $params.name ) { UninstallModernProvisonnedApp -pkg $(Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -like "*$($params.name)*" }) } elseif ( $pkg ) { try { Write-Host -NoNewLine "`tUninstall Provisonned $($pkg.DisplayName) :" $pkg | Remove-AppxProvisionedPackage -Online | Out-Null Write-Host -ForegroundColor Green "done" } catch { Write-Host -NoNewLine -ForegroundColor Red "`tError in UninstallModernApp`n`t" write-Host -ForegroundColor DarkRed $Error[0].Exception.Message return } } } function disable_shitty_service { param([string]$name) Write-Host -NoNewline "`t$name : " $serv = Get-Service -name $name if ( !$serv) { Write-Host -ForegroundColor Red "not found" return } if ( $serv.StartType -eq "Disable") { Write-Host -ForegroundColor Yellow "already disabled" } else { Stop-Service -InputObject $serv -PassThru | Set-Service -StartupType disabled Write-Host -ForegroundColor Green "done " } } # Kill a process # Param : # $process : name of process to kill (String) function kill_shitty_process { param([string]$process) Write-Host -NoNewLine "`tKilling $process : " try { $p = Get-Process $process Stop-Process $p | Out-Null Write-Host -ForegroundColor Green "Done" } catch { Write-host -ForegroundColor Yellow "Not started" } } Write-Output "`nI's time to kick ass and chew bubble gum" Write-Output "________________________________________`n" Get-ChildItem -Path $PSScriptRoot"\modules.d" -Filter "*.conf" | foreach { $module = "" $module = Get-Content $_.FullName -Raw | ConvertFrom-Json Write-Host -ForegroundColor White "`nProcess Module $($module.name)" $module_dir = $_.Directory.FullName + "\" + $_.BaseName + "\" $module.actions | Foreach { $action_file = "" $current_action = $_ # If action content a file element, nedd to test if file exist if ( $_.file) { $action_file = $module_dir + $_.file if ( -not (Test-Path $action_file) ) { Write-Host -ForegroundColor Red "`tError in $($module.name) : file $($_.file) not found" return } $_.file = $action_file } # Invoke function Invoke-Expression "$($_.action) -params `$_" } }