Skip to content

Instantly share code, notes, and snippets.

Avatar

Joe Cefoli jcefoli

View GitHub Profile
@jcefoli
jcefoli / iisHeaders.ps1
Created Sep 16, 2022
IIS Header Examples
View iisHeaders.ps1
Import-Module WebAdministration
# Add Custom Header - Server Level
Add-WebConfigurationProperty -PSPath MACHINE/WEBROOT/APPHOST `
-Name . -Filter system.webServer/httpProtocol/customHeaders `
-AtElement @{name = "X-Custom" ; value = 'value' }
#Remove Server: Microsoft-IIS/10.0 Header
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webServer/security/requestFiltering" -name "removeServerHeader" -value "True"
View wsl_helper.ps1
#Check WSL Version
wsl -l -v
#Set WSL Version to 1
wsl --set-version Ubuntu-20.04 1
@jcefoli
jcefoli / su-gitlab-runner.sh
Created Jan 27, 2022
Login to Gitlab Runner (to initiate SSH connections and add server to known_hosts)
View su-gitlab-runner.sh
sudo su -l gitlab-runner -s /bin/bash
@jcefoli
jcefoli / retry.sh
Created Dec 6, 2021
Powershell Retry Logic
View retry.sh
Begin {
$retryCount = 0
$retryMax = 5
$retryPauseSeconds = 30
}
Process {
do {
$retryCount++
try {
@jcefoli
jcefoli / ubuntu_cleanup.sh
Created Dec 3, 2021
Ubuntu Cleanup (WIP)
View ubuntu_cleanup.sh
sudo apt autoremove --purge
# Remove logs
sudo -s
sudo rm -rf /var/log/*.gz
sudo rm -rf /var/log/apt/*.gz && sudo rm -rf /var/log/apt/*.xz
sudo rm -rf /var/log/installer/*.gz
@jcefoli
jcefoli / nopasswd_sudo.sh
Created Oct 11, 2021
Remove password prompt from sudo elevation, with paranoia checks (Ubuntu 20.04 LTS)
View nopasswd_sudo.sh
#!/usr/bin/env bash
cp --no-preserve=mode,ownership /etc/sudoers /etc/sudoers.tmp
sed -i "s/%sudo\tALL=(ALL:ALL) ALL/%sudo\tALL=(ALL) NOPASSWD: ALL/g" /etc/sudoers.tmp
visudo -c -f /etc/sudoers.tmp
if [ "$?" -eq "0" ]; then
cp /tmp/sudoers.tmp /etc/sudoers
@jcefoli
jcefoli / web.config
Created Aug 12, 2021
Web Config to disable aggressive IIS caching for php development on Windows
View web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<urlCompression doStaticCompression="false" doDynamicCompression="false" />
<caching>
<profiles>
<add extension=".html" policy="DisableCache" kernelCachePolicy="DisableCache" />
<add extension=".php" policy="DisableCache" kernelCachePolicy="DisableCache" />
<add extension=".txt" policy="DisableCache" kernelCachePolicy="DisableCache" />
</profiles>
@jcefoli
jcefoli / aws-ssm-param.ps1
Last active Mar 9, 2021
Powershell AWS CLI SSM Parameter Store Helper
View aws-ssm-param.ps1
<#
.SYNOPSIS
Helper script to manage SSM parameters
.PARAMETER name
SSM key name to set
.PARAMETER value
SSM key value to set
@jcefoli
jcefoli / keepaliveScheduler.ps1
Last active May 24, 2021
Script that creates a scheduled task to keep your RDP session alive to work around nonsensical GPOs that inhibit productivity
View keepaliveScheduler.ps1
<#
.SYNOPSIS
Keeps you productive by spoofing activity to prevent GPO idle timeouts, RDP disconnects, sleep, etc.
.Description
This script creates a Scheduled Task that runs at login which uses Kernel SetThreadExecutionState to prevent GPOs
from disconnecting your RDP session. Will also prevent sleeping/screensavers/display timeouts
See the example below for a one liner that will download and execute this script directly from GitHub!
@jcefoli
jcefoli / rdp-keepalive.ps1
Last active Jan 5, 2021
RDP Keepalive using Kernel SetThreadExecutionState
View rdp-keepalive.ps1
$host.ui.RawUI.WindowTitle = "Idle Keepalive"
$dotNetCode = @'
[DllImport("kernel32.dll", CharSet = CharSet.Auto,SetLastError = true)]
public static extern void SetThreadExecutionState(uint esFlags);
'@
$ste = Add-Type -memberDefinition $dotNetCode -name System -namespace Win32 -passThru
$ES_CONTINUOUS = [uint32]"0x80000000" #Requests that the other EXECUTION_STATE flags set remain in effect until SetThreadExecutionState is called again with the ES_CONTINUOUS flag set and one of the other EXECUTION_STATE flags cleared.
$ES_AWAYMODE_REQUIRED = [uint32]"0x00000040" #Requests Away Mode to be enabled.