Skip to content

Instantly share code, notes, and snippets.

@s1037989
s1037989 / extract-hmackey
Created July 24, 2023 23:06
Brute force FIPS HMAC Key extract from binaries
#!/bin/bash
# This allows modifying a library with, e.g., patchelf and updating the FIPS-required .libXXX.hmac
# to ensure that the library can be loaded on a FIPS-enabled system.
# $ extract-hmackey libcrypto.so.1.1 '^[A-Za-z0-9 ]+$' '.\{16,64\}'
# orboDeJITITejsirpADONivirpUkvarP
# success
# $ extract-hmackey libcrypto.so.1.1 '^a$' '.\{16,64\}'
# fail
exec 73>&- 74<&- 74> >(perl -nE 'say "...$_..."') 73> >(LANG=C exec stdbuf -o0 perl -nE 'say ,,,$_,,,' >&74 2>&1)
function perl::start {
read TMPDIR < <(/usr/bin/mktemp -d /dev/shm/conn_shell_XXXXXXX)
mkfifo $TMPDIR/perl
nextFd PERLIN
echo $PERLIN
eval "exec $PERLIN> >(LANG=C exec stdbuf -o0 -i0 perl -pE '\$_="1\n\r"' >$TMPDIR/perl 2>&1)"
nextFd PERLOUT
echo $PERLOUT
# src is a staging area... copy files into src and then backup src to have them moved de-duped to dst
unset MYHOST STAGINGDIR BACKUPDIR REMOTEHOST REMOTEDIR
test -f ~/.backuprc && . ~/.backuprc
: ${MYHOST:=${HOSTNAME:-$(hostname -f)}}
: ${STAGINGDIR:=~/.backup}
STAGINGDIR=${STAGINGDIR/%//$MYHOST}; test -d $STAGINGDIR || mkdir -p $STAGINGDIR
: ${BACKUPDIR:=~/backup}
FILESTORE=$BACKUPDIR/.filestore; test -d $FILESTORE || mkdir -p $FILESTORE
BACKUPDIR=${BACKUPDIR/%//$MYHOST};
@s1037989
s1037989 / bashrc.md
Last active May 12, 2023 12:14
Multiple bash_histories

Maintain separate bash_histories and remember the last pwd for each tmux session/window/pane!

This is useful for setting up tmux project sessions with multiple windows and panes. Each time you create a new tmux session with the same name as a previous session, each windows' pane will maintain it's own separate bash_history and pwd!

This is very useful for long-running tmux sessions, especially when something happens to any of the shells. That very complex but useful log tailer that was started 6 months ago? It's the last command that was run ... in that pane!

Pay attention to the pwd and command history for each of the split-window panes in tmux!

asciicast

package Mojolicious::Plugin::Minion::Schedule;
use Mojo::Base 'Mojolicious::Plugin', -signatures;
use Algorithm::Cron;
use Minion::Job;
use Mojo::Date;
use Mojo::JSON qw(j);
use Mojo::Util qw(monkey_patch sha1_sum);
monkey_patch 'Minion::Job',
@s1037989
s1037989 / bash.txt
Last active March 3, 2023 03:33
Mojo::Promise
# Need a separate process to block to show what happens when a waiting for a non-blocking op
# 12 workers that each handle only 1 concurrent connection so that each connection can immediately be fulfilled and start the countdown
$ perl -Mojo -MTime::HiRes=time,sleep -E 'a("/#n" => sub { my $time = time; my $n = $_->param("n"); sleep $n; $_->render(inline => "<title>$n : Sleep <%= \$n %> seconds</title>", n => time - $time) })->start' prefork -w 12 -c 1
Web application available at http://127.0.0.1:3000
---
$ perl promise.pl 1 http://localhost:3000/4 http://localhost:3000/3 http://localhost:3000/2 http://localhost:3000/5 http://localhost:3000/6 http://localhost:3000/7
Getting 6 URLs starting at 1677811334.05866
$ mojo version
CORE
  Perl        (v5.34.0, linux)
  Mojolicious (9.30, Waffle)

OPTIONAL
  Cpanel::JSON::XS 4.09+   (n/a)
  EV 4.32+                 (n/a)
  IO::Socket::Socks 0.64+  (n/a)
use Mojo::Base -strict, -signatures;
BEGIN { $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll' }
use Test::Mojo;
use Mojo::Server::Daemon;
use Mojo::URL;
use Mojolicious;
use Mojolicious::Lite;
@s1037989
s1037989 / proxy
Last active November 18, 2022 02:40
use Mojolicious::Lite -signatures;
app->ua->max_redirects(10);
# Just forward the response
any '/*whatever' => {whatever => ''} => sub ($c) {
my $proxy_to = Mojo::URL->new($c->req->headers->header('X-Proxy-To') || $ENV{PROXY_TO}) or return $c->reply->not_found;
#my $proxy_for = Mojo::URL->new($c->req->headers->header('X-Proxy-For') || $ENV{PROXY_FOR}) or return $c->reply->not_found;
my $req = $c->req;
my $method = $req->method;
bindir = /usr/bin
sharedir = /usr/share/my_app
all:
cpanm -L local --installdeps .
mkdir -p blib
cp -a script blib
cp -a lib blib
cp -a local/bin blib
cp -a local/lib/perl5/* blib/lib