Skip to content

Instantly share code, notes, and snippets.

View ormaaj's full-sized avatar

Daniel Douglas ormaaj

View GitHub Profile
#!/usr/bin/env bash
shopt -s lastpipe extglob expand_aliases
typeset -gx BASH_COMPAT=51
function unset2 {
command unset "$@"
}
function nonlocal_alias {
typeset s=0
@ormaaj
ormaaj / unsetall.bash
Created July 11, 2026 14:22
unfixable broken unsetall function
# unexport and unset all instances of named variable arguments.
# `unsetall` cannot tolerate `att_invisible | att_nameref`. Passing one will cause unpredictable failure.
function unsetall {
if [[ ${FUNCNAME[0]} != "${FUNCNAME[1]}" ]]; then
typeset -a z
for z do
[[ $z == z ]] ||
z+=("$z")
done
if (( ${#z[@]} - 1 < $# )); then
@ormaaj
ormaaj / libunamewrap.c
Created July 10, 2026 21:50
uname field spoof `LD_PRELOAD`
#define _GNU_SOURCE
#include <dlfcn.h>
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <sys/utsname.h>
typedef int (*uname_fn_t)(struct utsname*);
@ormaaj
ormaaj / pipe_splice.bash
Created June 26, 2026 15:25
shell i/o trickery
$ time ( echo; bash /proc/self/fd/9 9<<\_EOF 8<<\_EOF )
shopt -s lastpipe
{
pipesz -n 1
pipesz -gn 3 3<&1 1<&2;
head -c "$(( 4 * 2 ** 31 ))" </dev/urandom
} | len=${ python3 /proc/self/fd/8 "${| ${ exec {REPLY}<&1; }; }"; } fd=$_ || exit # Inner assignment to `REPLY` falls through to ${|; }
printf 'bytes copied: %d\n' "$len"
lsfd -p "$BASHPID" -Q "FD==${fd}" -o +flags,pos,size
exec {fd}<&-
@ormaaj
ormaaj / fexecve.bash
Created June 13, 2026 22:21
stdin executor
~ $ { readlink -zf /proc/self/fd/0 | IFS= read -rd '' c; python -c 'import sys,os;from ctypes import*;CFUNCTYPE(c_int,c_int,POINTER(c_char_p),POINTER(c_char_p),use_errno=True)(CDLL(None).fexecve)(int(sys.argv[1]),*[(c_char_p*(len(t:=tuple(x))+1))(*t,None)for x in((os.fsencode(a)for a in sys.argv[2:]),(b"=".join(kv)for kv in os.environb.items()))])' 0 "${c##*/}" hello world; } <${BASH_CMDS[echo]:-${| enable -n echo; hash echo; enable echo; REPLY=${BASH_CMDS[echo]}; }}
hello world
# grub.cfg
function loadModules {
insmod regexp
for x in "$@"; do
if regexp -s 1:y '([^/]+)\.mod$' "$x"; then
if regexp 'test|^tpm$|^regexp$|^[uoea]hci|^gcry_' "$y"; then
continue
else
insmod "$y"
@ormaaj
ormaaj / refchain.md
Last active March 31, 2026 16:52
nameref chaining and dangling namerefs
{ exename=$(python3) exename=${exename%%?} || exit; } <<\EOF
import os, sys
try:
        fd = os.open(os.path.join(b"/proc", os.fsencode(str(os.getppid())), b"exe"), os.O_PATH | os.O_NOFOLLOW)
        sys.stdout.buffer.write(os.path.basename(os.readlink(b"", dir_fd = fd)).__add__(b"\x01"))
except: sys.exit(1)
finally: os.close(fd)
EOF
case $exename in
@ormaaj
ormaaj / symsync.md
Last active March 21, 2026 14:52
build relative symlink trees using a source tree as a template
#!/usr/bin/python3

import os
import shutil
import logging
from pathlib import Path
from typing import Iterable

logging.basicConfig(level=logging.INFO, format="%(message)s")
@ormaaj
ormaaj / chanstats.ksh
Last active February 26, 2026 20:44
weechat log stats analyzer
#!/usr/bin/env ksh
function chanStats {
nameref ret=$1
typeset -T ChanStats=(
logdir=~/.weechat/logs
typeset logfile channel network
typeset -a stats
@ormaaj
ormaaj / ssh_config
Created February 3, 2026 12:00
openssh ProxyCommand for ProxyUseFdpass SCM_RIGHTS IPC
ProxyUseFdpass yes
ProxyCommand python3 -c 'import socket,sys,struct; s=socket.create_connection((sys.argv[1],int(sys.argv[2]))); socket.fromfd(1,socket.AF_UNIX,socket.SOCK_STREAM).sendmsg([b"\0"],[(socket.SOL_SOCKET,socket.SCM_RIGHTS,struct.pack("i",s.fileno()))])' %h %p