Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan Castellucci ryancdotorg

View GitHub Profile
@ryancdotorg
ryancdotorg / frag32.py
Created Aug 20, 2015
A FAT32 fragmenter, because I am a horrible person.
View frag32.py
#!/usr/bin/env python
import random
import struct
import sys
# Most of the Fat32 class was cribbed from https://gist.github.com/jonte/4577833
def ppNum(num):
return "%s (%s)" % (hex(num), num)
@ryancdotorg
ryancdotorg / dnaas.c
Created Oct 30, 2013
Wrapper library to use /dev/null as a service on Linux via LD_PRELOAD
View dnaas.c
/* This is a wrapper library that will give your server the power of
* /dev/null as a service, as seen at http://devnull-as-a-service.com/
*
* Compile:
* gcc -ggdb -shared -fPIC dnaas.c -ldl -lcurl -o libdnaas.so
*
* Try:
* LD_PRELOAD=./libdnaas.so dd if=/dev/sda of=/dev/null bs=8192 count=16
*
* Install:
@ryancdotorg
ryancdotorg / rotate_dkim.py
Last active Sep 23, 2021
Experimental DKIM rotate/revoke/repudiate script for Exim+Route53. I take no responsibility for its use.
View rotate_dkim.py
#!/usr/bin/env python
import os
import grp
import sys
import stat
import time
import hmac
import boto3
import tempfile
@ryancdotorg
ryancdotorg / rsabd.py
Last active Aug 31, 2021
backdoored rsa key generation
View rsabd.py
#!/usr/bin/env python
import sys
import gmpy
import curve25519
from struct import pack
from hashlib import sha256
from binascii import hexlify, unhexlify
@ryancdotorg
ryancdotorg / rand.c
Created Aug 23, 2021
A simple command line random number generator that can compile on x86_64 without libc
View rand.c
// gcc -Os -DNO_LIBC -fno-builtin -static -nostdlib -fomit-frame-pointer rand.c -o rand
// gcc -O3 rand.c -o rand
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/random.h>
#include <inttypes.h>
@ryancdotorg
ryancdotorg / cryptroot.patch
Created Dec 25, 2011
patch to the cryptroot hook that comes with cryptsetup on debian/ubuntu
View cryptroot.patch
--- cryptroot.dist 2011-12-24 16:50:11.000000000 -0800
+++ cryptroot 2011-12-24 17:07:33.000000000 -0800
@@ -211,7 +211,7 @@
fi
# We have all the basic options, let's go trough them
- OPTIONS="target=$target,source=$source,key=$key"
+ OPTIONS="target=$target,source=$source"
local IFS=", "
unset HASH_FOUND
@ryancdotorg
ryancdotorg / default.conf
Created Feb 7, 2021
An opinionated nginx default server configuration block
View default.conf
# An opinionated nginx default server configuration block
# Author: Ryan Castellucci https://rya.nc/ @ryancdotorg
# Revision: 2021-02-07
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
# Send ACME (LetsEncrypt) requests to a special directory
View c_str.py
# escape a `str`, `bytes`, `bytearray` or `Iterable[int]` value as a C string
def c_str(s):
out = '' # see https://w.wiki/34HP
trigraph = {33, 39, 40, 41, 45, 47, 60, 61, 62}
escape = {8: 98, 9: 116, 10: 110, 13: 114, 34: 34, 39: 39, 92: 92}
if isinstance(s, bytearray): s = bytes(s)
if isinstance(s, bytes):
try: s = s.decode()
except: pass
if isinstance(s, str): s = map(ord, s)
@ryancdotorg
ryancdotorg / fnode.js
Last active Jan 11, 2021
A nodejs REPL that'll autoload code
View fnode.js
#!/usr/bin/env node
// save somewhere in $PATH as fnode, remember to chmod +x
const vm = require('vm');
const fs = require('fs');
const tty = require('tty');
const path = require('path');
const repl = require('repl');
@ryancdotorg
ryancdotorg / setImmediate.js
Created Jan 3, 2021
A setImmediate polyfill optimized for size.
View setImmediate.js
(function(global, name, mc, counter, slice){
if (!(name in global)) {
if (mc = mc in global && new global[mc]) {
mc.port1.onmessage = function(evt) {
slice[evt = evt.data]();
delete slice[evt];
};
global[name] = function(cb) {
var args = slice.call(arguments, 1);