Skip to content

Instantly share code, notes, and snippets.

View superstes's full-sized avatar
🎯
Focusing

Rath Pascal superstes

🎯
Focusing
View GitHub Profile
@superstes
superstes / netfilter_rate_limit_test.py
Last active May 24, 2025 21:19
Netfilter Rate-Limit Test-Script (NFTables/IPTables)
#!/usr/bin/env python3
# the netfilter uses the 'token bucket algorithm'
# it sometimes can be a bit 'unintuitive' how this rate-limit-algorithm works
# the algorithm expects the packets, as defined by the limit, to be somewhat spread over the whole timewindow (second/minute/..)
# token bucket punishes short-term overages beyond the burst capacity
# limit source code: https://github.com/torvalds/linux/blob/master/net/netfilter/nft_limit.c
# this script provides a way to easily test "rate-limit + burst" configurations
# to get practical data you can simply run "tcpdump" on your target system and extract the packet-times from its output
@superstes
superstes / form_input_validation_regex.js
Last active March 5, 2025 19:37
Simple Regex for Form-Input-Validation
/*
NOTE:
These are not perfect, but good enough for frontend-validation.
A exact validation needs to be done on the backend anyways..
*/
const REGEX_IP4 = /^([1-2]?)[0-9]{1,2}\.([1-2]?)[0-9]{1,2}\.([1-2]?)[0-9]{1,2}\.([1-2]?)[0-9]{1,2}$/
/*
tested:
10.0.0.0
@superstes
superstes / ssl-ocsp-check.sh
Created October 14, 2024 20:27 — forked from NiceRath/ssl-ocsp-check.sh
Script to check if website has OCSP enabled or issues with it
#!/bin/bash
if [ -z "$1" ]
then
echo 'Provide a hostname of a website to check!'
exit 1
fi
if [ -z "$2" ]
then
@superstes
superstes / ssl-validate.sh
Created October 14, 2024 20:26 — forked from NiceRath/ssl-validate.sh
Script to validate certificate of service
#!/bin/bash
if [ -z "$1" ]
then
echo 'Provide the target hostname!'
exit 1
fi
TARGET="$1"
@superstes
superstes / in_ip_list.py
Created October 12, 2024 15:46
Python Script to check if an IP is inside an IP-List-File
#!/usr/bin/env python3
from sys import exit as sys_exit
from pathlib import Path
from argparse import ArgumentParser
from ipaddress import IPv4Address, IPv6Address, IPv4Network, IPv6Network, AddressValueError, NetmaskValueError
def _load_ip_list(ip_list_file: str) -> (list, list):
safe_ips = []
@superstes
superstes / check_IP_is_public.sh
Created October 8, 2024 17:19
Bash Script to check if IP is Public (using Python3 inline)
#!/bin/bash
IP="1.1.1.1"
ip4="$(python3 -c "from ipaddress import IPv4Address; from sys import argv; ip=argv[1]; print(ip) if IPv4Address(ip).is_global else print('1')" "$IP" 2>/dev/null || echo '0')"
if [[ "$ip4" == '0' ]]
then
ip6="$(python3 -c "from ipaddress import IPv6Address; from sys import argv; ip=argv[1]; print(ip) if IPv6Address(ip).is_global else print('1')" "$IP" 2>/dev/null || echo '0')"
@superstes
superstes / log_top_ps.sh
Created October 3, 2024 20:55
Bash script to log top N resource-consuming processes
#!/bin/bash
LOG_DIR='/var/log/ps/'
TOP_N=5
TOP_N_H=$(( TOP_N + 1 ))
mkdir -p "$LOG_DIR"
date >> "${LOG_DIR}/mem.log"
ps -eo rss,pid,user,command --sort -rss | head -n "$TOP_N_H" | tail -n "$TOP_N" >> "${LOG_DIR}/mem.log"
@superstes
superstes / light-dark-element-switch.css
Last active September 27, 2024 08:52
CSS Switch Images/Elements with Light/Dark-Mode
body.light {
--darkVisible: hidden;
--darkDisplay: none;
--lightVisible: unset;
--lightDisplay: inline-block;
}
body.dark {
--darkVisible: unset;
--darkDisplay: inline-block;
@superstes
superstes / write_secrets_to_named_pipe.py
Last active September 22, 2024 12:48
Python3 pass secrets over named-pipe
#!/usr/bin/env python3
# this is handy if you need to pass secrets between two processes
# the secrets are not written to disk and can only be read once
from os import mkfifo
from pathlib import Path
from os import remove as remove_file
from threading import Thread
@superstes
superstes / go-listen-unix-socket.go
Created September 18, 2024 12:44
GoLang - Listen on Unix Socket
var bindTo = "/tmp/test.sock"
// check if socket file exists and remove it
if _, err := os.Stat(bindTo); err == nil {
if err := os.Remove(bindTo); err != nil {
globalLogger.Fatal().Err(err).Msg("Failed to remove existing socket-file")
}
}
// listen on socket-file