Skip to content

Instantly share code, notes, and snippets.

View jcefoli's full-sized avatar

Joe Cefoli jcefoli

View GitHub Profile
@jcefoli
jcefoli / kickjenkins.ps1
Created September 24, 2019 22:32
Kick Jenkins Job With CSRF Protection Enabled [Powershell REST Request]
# Force TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Basic Auth Credentials
$user = 'changeme'
$pass = 'insecure-password'
# Handle Basic Auth (Hacky in Powershell)
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
@jcefoli
jcefoli / asus-cheatsheet.txt
Last active August 31, 2023 17:15
[Asus Router] Useful SSH Commands
# Modify Hosts file (/jffs/configs/hosts.add)
service restart_dnsmasq
# Parse Custom Client List
nvram get custom_clientlist | sed 's/</\n/g; s/>/\t/g' | sed 's/^/custom\t/' | tail '+2' | sed 's/\(^.*\)\(\t.*\)\(\t[0-9A-F][0-9A-F]:.*$\)/\1\3\2/'
# Remove Logged in User restriction
nvram unset login_ip
nvram commit
@jcefoli
jcefoli / keepalive.ps1
Last active August 18, 2023 16:16
Powershell Computer Keepalive (Anti-Idle)
<#
This script will prevent GPOs from enabling the screensaver, shutting off your screen, or force-locking your workstation
It works by sending an F15 keystroke every minute (only if there have been no keystrokes or mouse movement for 30 seconds)
Be green - if you want to use this, power off your monitor(s)!
#>
Add-Type @'
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
@jcefoli
jcefoli / random-ip-in-cidr.ps1
Last active July 25, 2023 21:33
[pwsh] Generate a random IP address in a given CIDR range
function Get-RandomIPAddressInCIDR {
param (
[string]$CIDR
)
# Split the CIDR into network address and subnet mask
$networkAddress, $subnetMaskBits = $CIDR -split '/'
$subnetMaskBits = [int]$subnetMaskBits
if ($subnetMaskBits -eq 32) {
@jcefoli
jcefoli / spaceinput.bat
Last active June 23, 2023 00:03
Batch File User Input: Convert Spaces to %20
@ECHO OFF
REM This snippet will take an input string with spaces and replace them with %20
SET /p input=Input string:
SETLOCAL ENABLEDELAYEDEXPANSION
SET input=!input: =%%20!
ECHO.
ECHO %input%
PAUSE
@jcefoli
jcefoli / file_datetime.ps1
Created May 10, 2023 15:58
File DateTimeStamp Output
$outputFileName = "C:\Temp\File_{0:yyyyMMdd}_{0:HHmmss}.csv" -f (Get-Date)
#C:/Temp/File_20230510_115723.csv
@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 / lolbanner.sh
Created April 24, 2023 14:06
LolBanner Setup Script (Debian) - Create colorful text banners using the 3d.flf font, figlet and lolcat (wrapped by a bash function called lolcat)
#!/usr/bin/env bash
sudo apt install figlet lolcat --no-install-recommends -y
wget https://raw.githubusercontent.com/xero/figlet-fonts/master/3d.flf -P ~/.local/share/fonts/
sudo tee ~/.bashrc << 'EOF'
lolbanner ()
{
echo
figlet -f ~/.local/share/fonts/3d.flf $@ | lolcat
@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.
@jcefoli
jcefoli / Update-SessionEnvironment.ps1
Created January 27, 2023 19:53
Refresh Path In Powershell Session Using Chocolatey
# Use chocolatey to refresh the path
Import-Module "$env:ChocolateyInstall\helpers\chocolateyInstaller.psm1"
Update-SessionEnvironment -Full