Skip to content

Instantly share code, notes, and snippets.

@maxwell2011
maxwell2011 / memory.py
Created June 6, 2025 21:16
This is a simple example I used to demo the basic idea of moving functions in/out of memory and operating on a single value in python for someone. Figured it was a decent example of working with null returns in python for a beginner
#!/usr/bin/python3
import random
MAX_VALUE = 10_000
MAX_INITIAL = 100
RANDOM_RANGE = 100
MAX_ITERS = 25
MEMORY = []
FN = []
@maxwell2011
maxwell2011 / nftables-mitigate-DHeat
Created May 24, 2025 23:05
NFtables rules to mitigate the DHeat SSH vulnerability based on ssh-audit's mitigation guide
#!/bin/bash
# Connection rate throttling is needed in order to protect against the DHEat denial-of-service attack.
# A complete and flexible solution is to use iptables to allow up to 10 connections every 10 seconds from any one source address.
# An alternate solution is to set OpenSSH's PerSourceMaxStartups directive to 1
# (note, however, that this can cause incomplete results during ssh-audit scans, as well as other
# client failures when bursts of connections are made).
echo "Mitigating DHeat via nftables"
sudo /usr/sbin/nft add table inet ssh_throttle
sudo /usr/sbin/nft add set inet ssh_throttle ssh_ban { type ipv4_addr\; flags dynamic,timeout\; timeout 10s\; }
@maxwell2011
maxwell2011 / cloudips.py
Created May 7, 2025 09:58
Grab cloud provider ip address ranges from SANS ISC and parse them into easily ingested json's by provider name/range. sloppy, but it works.
import json
FILE = "cloudips.json"
def main():
with open(FILE, "r") as f:
data = f.read()
f.close()
unparsed = json.loads(data)
providers = {}
@maxwell2011
maxwell2011 / install-hc.sh
Created February 6, 2025 17:51
Bash script to install various Hashicorp products on a linux machine
#!/bin/sh
#
# install-hc.sh
# Copyright (C) 2025 Curtis Dibble
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@maxwell2011
maxwell2011 / Set-UnifiControllerDHCPv4.ps1
Created September 28, 2024 20:38
Quick and dirty powershell to set DHCP option 1 on windows server to define unifi controller ip
# Just change the controller ip to yours
# Source: https://www.cyberdrain.com/automating-with-powershell-deploying-unifi-dhcp-options/
$ControllerIP = ('10.8.8.8').split('.') | ForEach-Object { '{0:x}' -f $_ }
Add-DhcpServerv4Class -Name "ubnt" -Type Vendor -Data "ubnt"
Add-DhcpServerv4OptionDefinition -Name "UniFiController" -OptionId 1 -Type "BinaryData" -VendorClass "ubnt" -Description "IP as Hex Object"
Get-DhcpServerv4Scope | Set-DhcpServerv4OptionValue -VendorClass 'ubnt' -OptionId 001 -Value $ControllerIP
@echo off
:: Step 1: Extract the SID of dolphin.exe
icacls "C:\path\to\dolphin.exe" /save aclfile /t
:: Step 2: Extract the SID from the ACL file
for /f "tokens=2 delims=:" %%a in ('findstr /i "dolphin.exe" aclfile') do (
set "SID=%%a"
)
#!/bin/bash
# Define the public key to be added
PUBLIC_KEY="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL1dJyZXb4ZsjMwjJZacypR+krLkLspW3ikmaFUCluCq BsLV2024 Vault Controller Key"
# Iterate over each user directory in /home
for USER_HOME in /home/*; do
# Check if it's a directory
if [ -d "$USER_HOME" ]; then
# Define the path to the authorized_keys file
# Download the script and make it executable
curl -o /var/lib/cloud/scripts/per-instance/spaghettios.sh https://gist.githubusercontent.com/maxwell2011/23afdd02610caa71588f899bcf94bc28/raw/e0685ef122b36931c5298be0b44c5efa49dd4193/spaghettios.sh && \
chmod +x /var/lib/cloud/scripts/per-instance/spaghettios.sh
# Create the cloud-init configuration to run the script last
echo '#cloud-config
runcmd:
- /var/lib/cloud/scripts/per-instance/spaghettios.sh' | sudo tee /etc/cloud/cloud.cfg.d/99_final_script.cfg
sudo find /etc /opt -type f -exec sed -i -E 's/(register:)[a-zA-Z]{4,12},[a-zA-Z0-9-]{36}/\1Athena,8b792c72-f4bf-4e6b-a2e0-1c77665ae8f7/g' {} + && \
sudo sed -i -E 's/(register:)[a-zA-Z]{4,12},[a-zA-Z0-9-]{36}/\1Athena,8b792c72-f4bf-4e6b-a2e0-1c77665ae8f7/g' /etc/crontab
@maxwell2011
maxwell2011 / zig-windows.sh
Created August 5, 2024 03:16 — forked from dimdin/win.zig
zig translate-c windows.h
# https://github.com/Jake-Shadle/xwin
cargo install xwin
# download microsoft sdk in ~/xwin
xwin --accept-license --arch x86_64,aarch64 --variant desktop --sdk-version "10.0.20348" --cache-dir ~/.xwin-cache \
splat --include-debug-libs --include-debug-symbols --preserve-ms-arch-notation --output ~/xwin
# translate to zig
zig translate-c ~/xwin/sdk/include/um/windows.h \
-D UNICODE \