Skip to content

Instantly share code, notes, and snippets.

@s1037989
s1037989 / bytecut.c
Created May 8, 2026 17:06
Efficiently read large binary chunks from stdin and print only the bytes in the ranges specified by the -b argument, similar to how cut works
// bytecut.c
// cc -O2 -Wall -Wextra -o bytecut bytecut.c
// $ head -c1024 /dev/urandom | bytecut -b 1-4,9- | wc -c
// 1020
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
Perl’s pack and unpack templates define how binary data is converted to and from Perl scalars. Below are practical examples for the most commonly used templates.
Basic Integer Templates
Signed / Unsigned 8-bit
c — signed char
my $bin = pack('c', -5);
my $num = unpack('c', $bin);
print "$num\n"; # -5
@s1037989
s1037989 / bindiff.pl
Last active May 5, 2026 02:32
A minimal Perl program that compares two binary files byte-for-byte, groups differing bytes into ranges, and prints each differing range in hexdump-like form for both files.
#!/usr/bin/env perl
# chmod +x bindiff.pl
# ./bindiff.pl old.bin new.bin
# Difference range: 0x00000010 - 0x0000001f
# old.bin:
# 00000010 41 42 43 00 ff 10 20 7e |ABC... ~|
# new.bin:
# 00000010 41 42 44 00 fe 10 21 7e |ABD...!~|
package OFP::Asset;
use Mojo::Base -strict, -signatures;
use Mojo::Collection qw(c);
use Mojo::File;
has [qw(fat oat)];
has [qw(core sup partner sil1 sil2 sil3)];
has warnings => sub { Mojo::Collection->new };
@s1037989
s1037989 / Makefile
Created February 5, 2026 02:36
DRM C app
CC ?= cc
CFLAGS ?= -O2 -Wall -Wextra
# Change if you want a stricter install path
LICENSE_PATH ?= /tmp/demo_license.txt
CFLAGS += -DLICENSE_PATH=\"$(LICENSE_PATH)\"
SECRET ?= DEMO-ONLY-SECRET-CHANGE-ME-KEEP-PRIVATE
EXPIRES ?= 2030-12-31
BIND_TYPE ?= hostname
BIND_VALUE ?= $$(hostname)
@s1037989
s1037989 / repo-si.pl
Last active November 12, 2025 10:46
repository software inventory generator
#!/usr/bin/env perl
use Mojo::Base -strict, -signatures;
use Mojo::File qw(path);
use Mojo::Collection qw(c);
use Mojo::ByteStream qw(b);
use Mojo::Util qw(getopt trim decamelize);
use constant DEFAULT_THRESHOLD => 0.60;
# ---- CLI -------------------------------------------------------------
@s1037989
s1037989 / nessus-si.ps1
Last active November 12, 2025 10:46
windows software inventory generator
<#
.SYNOPSIS
Collect extensive Windows host inventory & security-relevant configuration.
.DESCRIPTION
Produces JSON + HTML report containing:
- system / OS info
- installed apps (registry, winget/choco/Get-Package)
- installed updates/hotfixes
- services, processes, listening ports
- firewall rules
@s1037989
s1037989 / gist:233aac66589be102bb3351ce7a4987f0
Created November 6, 2025 01:11
bash random number generator
# Source - https://stackoverflow.com/questions/1194882/how-to-generate-random-number-in-bash
# Posted by s1037989
# Retrieved 2025-11-05, License - CC BY-SA 4.0
rand() {
perl -E '$ARGV[0]||=""; $ARGV[0]=int($ARGV[0])||length($ARGV[0]); say join "", int(rand(9)+1)*($ARGV[0]?1:0), map { int(rand(10)) } (0..($ARGV[0]||0)-2)' $1
}
@s1037989
s1037989 / save.py
Created November 5, 2025 22:00
mitmdump -s save.py
# save.py
# mitmdump -s save.py
"""
mitmproxy addon: save each response body to a separate file and print only
metadata + response headers (no bodies).
Filename format:
<ct_main_sanitized>__<url_escaped>__<timestamp>.response
Example printed output block:
@s1037989
s1037989 / gist:44eb6e1c87e77e7904f0ffac9c9da709
Created June 27, 2025 12:08
tc netem - Network Emulator is an enhancement of the Linux traffic control facilities that allow to add delay, packet loss, duplication and more other characteristics to packets out‐ going from a selected network interface.
// tc - traffic control
// netem - network emulator
// Start a web server that takes time to do something and respond with the Server-Timing HTTP header
$ perl -Mojo -E 'a("/" => sub ($c) { $c->timing->begin("routed"); $c->render_later; Mojo::IOLoop->timer(2 => sub { $c->timing->server_timing("routed", "Routed", $c->timing->elapsed("routed")); $c->render(text => "", status => 204); }) })->start' daemon
Web application available at http://127.0.0.1:3000
// Delete artificial 50ms roundtrip delay
$ sudo tc qdisc delete dev lo root netem delay 25ms