Skip to content

Instantly share code, notes, and snippets.

View jcefoli's full-sized avatar

Joe Cefoli jcefoli

View GitHub Profile
@jcefoli
jcefoli / iisHeaders.ps1
Created September 16, 2022 21:40
IIS Header Examples
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"
@jcefoli
jcefoli / wsl_helper.ps1
Last active May 10, 2024 04:03
Set WSL Version
# Check WSL Version
wsl -l -v
# Set WSL Version to 2
wsl --set-version Ubuntu-22.04 2
# Fix WSL2 Networking (per https://stackoverflow.com/a/65325532)
rm /etc/resolv.conf || true
rm /etc/wsl.conf || true
@jcefoli
jcefoli / su-gitlab-runner.sh
Created January 27, 2022 18:54
Login to Gitlab Runner (to initiate SSH connections and add server to known_hosts)
sudo su -l gitlab-runner -s /bin/bash
@jcefoli
jcefoli / retry.sh
Created December 6, 2021 19:44
Powershell Retry Logic
Begin {
$retryCount = 0
$retryMax = 5
$retryPauseSeconds = 30
}
Process {
do {
$retryCount++
try {
@jcefoli
jcefoli / ubuntu_cleanup.sh
Last active January 23, 2024 06:28
Ubuntu Cleanup (WIP)
sudo apt autoremove --purge
#Remove VSCode Server Space Hog Bullshit
rm -rf /home/jcefoli/.vscode-server
# Clean Journal BS
sudo journalctl --vacuum-size=100M
# Remove logs
sudo -s
@jcefoli
jcefoli / nopasswd_sudo.sh
Created October 11, 2021 04:50
Remove password prompt from sudo elevation, with paranoia checks (Ubuntu 20.04 LTS)
#!/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 August 12, 2021 17:54
Web Config to disable aggressive IIS caching for php development on Windows
<?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 March 9, 2021 18:30
Powershell AWS CLI SSM Parameter Store Helper
<#
.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 3, 2023 20:12
Script that creates a scheduled task to keep your RDP session alive to work around nonsensical GPOs that inhibit productivity
<#
.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 January 30, 2023 18:14
RDP Keepalive using Kernel SetThreadExecutionState
$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.