Skip to content

Instantly share code, notes, and snippets.

@jo-makar
jo-makar / metrics.py
Last active March 27, 2018 11:55
Thread-safe metrics storage that calculates rate of change using linear regression
import collections, datetime, threading, time
class MetricsThread(threading.Thread):
'''
Thread-safe metrics storage that calculates rate of change using linear regression (ie line-fitting).
Values can be stored by (external) increment calls and/or by periodic callback functions.
Keyword arguments:
callbacks -- metrics to be also determined periodically via callbacks,
@jo-makar
jo-makar / suricata.py
Last active September 11, 2018 19:48
Suricata rule lexer/parser
# Suricata rule lexer/parser
#
# http://www.dabeaz.com/ply/ply.html
# https://suricata.readthedocs.io/en/latest/rules/intro.html
#
# TODO Perhaps a better approach is to isolate the signature parsing code from the suricata source
# and create bindings for higher-level languages around that isolated code
# See https://github.com/OISF/suricata/tree/master/src/detect-parse.{c,h} SigParse()
@jo-makar
jo-makar / 0-sqli.md
Last active April 2, 2019 15:14
SQL injection notes / tools

SQL injection notes / tools

userpass.py

Assume a login page with the query: select password from admins where username=\'%s\'

Login outright use:

  • username: ' union select "foo"; --
  • password: foo
@jo-makar
jo-makar / logstream.cpp
Created April 19, 2019 14:15
Logging framework implemented as an input stream
#include "logstream.hpp"
#include <chrono>
#include <ctime>
#include <mutex>
#include <thread>
using namespace std;
unsigned int thread_id() {
static unsigned int idx = 0;
@jo-makar
jo-makar / pxeboot.md
Last active May 28, 2024 17:42
Setup a PXE boot server

Setup a PXE boot server

Using dnsmasq (on Debian)

apt-get install dnsmasq pxelinux syslinux-common syslinux-efi

mkdir /srv/tftpboot

ln -s /usr/lib/PXELINUX/pxelinux.0 /srv/tftpboot/
@jo-makar
jo-makar / proc-mem.md
Last active October 17, 2019 20:02
Read live process memory

Read live process memory

/proc/$pid/maps describes virtual memory regions with the first column being the address range

cd /proc/$pid/mem

# Extract the start and end address for the first entry (NR==1)
eval $(awk -F'[- ]' 'NR==1 {print "s="$1" e="$2}' maps)
@jo-makar
jo-makar / i3-session.py
Last active December 24, 2019 01:32
Framework to restore/build an i3 session
#!/usr/bin/env python3
# Restore/build an i3 session
import argparse, json, logging, queue, subprocess, threading
if __name__ == '__main__':
def i3msg(args):
cmd = ['i3-msg'] + args
logging.info('cmd = %r', cmd)
subprocess.check_call(cmd, stderr=subprocess.STDOUT, encoding='utf-8')
@jo-makar
jo-makar / debian-ssh-install.md
Created May 8, 2020 03:40
Install Debian over SSH

Create the modified ISO

mount -o loop debian-10.0.0-amd64-netinst.iso /mnt/loop
mkdir debian-10.0.0-amd64-netinst
shopt -s dotglob; cp -rv /mnt/loop/* debian-10.0.0-amd64-netinst/
umount /mnt/loop

dd if=debian-10.0.0-amd64-netinst.iso of=isohdpfx.bin bs=1 count=432

cp debian-10.0.0-amd64-netinst/.disk/mkisofs .
@jo-makar
jo-makar / 0-systray-notify.md
Last active May 11, 2020 03:16
Systray notifier

Systray notifier

This is a simple project to receive D-Bus desktop notifications and display them with a systray application.

Purposefully displaying notifications only when the systray application is right-clicked, if OSD notifications is your preference there are a multitude of options available: notification-daemon, notify-osd, dunst, etc.

screenshot

@jo-makar
jo-makar / logger.go
Last active May 11, 2020 18:00
Logging framework
package logger
import (
"fmt"
"io"
"path"
"runtime"
"strings"
"sync"
"time"