Skip to content

Instantly share code, notes, and snippets.

View mkorthof's full-sized avatar
⌨️
cli connoisseur

Marius mkorthof

⌨️
cli connoisseur
View GitHub Profile
@mkorthof
mkorthof / ldbdump.py
Last active March 21, 2024 13:58
ldbdump - dumps LevelDB keys/values
#!/usr/bin/python3
# ldbdump - dumps LevelDB keys/values
#
# a LevelDB is a dir with files such a these:
# 000050.ldb 000100.log CURRENT LOCK LOG MANIFEST-000099
#
# sources: https://github.com/tos-kamiya/levelobjdb dump()
import os
@mkorthof
mkorthof / sshpk.py
Last active March 24, 2017 23:48
sshpubkeys - shows ssh pubkey details
#!/usr/bin/env python3
# https://github.com/ojarva/python-sshpubkeys
import sys
from sshpubkeys import SSHKey
# example (error: <1024 bits)
#ssh = SSHKey("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAYQCxO38tKAJXIs9ivPxt7AY"
# "dfybgtAR1ow3Qkb9GPQ6wkFHQqcFDe6faKCxH6iDRteo4D8L8B"
@mkorthof
mkorthof / ipv6test.sh
Last active January 19, 2018 22:48
ipv6test - test/show your ipv6 addr
#!/bin/sh
ARGS=""
if [ "$interface" ]; then ARGS="$ARGS --interface $interface"; fi
echo
for i in ipv6.test-ipv6.com/ip/\?callback=\?\&asn=1 whatismyv6.com ipv6-test.com ipv6now.com.au ipv6-speedtest.net testmyipv6.com; do
echo "Testing $i:"
#lynx -connect_timeout=5 -read_timeout=5 -dump http://$i | grep -A 2 "\(Your\? are\|Your IP\|Welcome\)" | grep -v "\(\[.*\]\|FAQ\)" | sed -e '/^$/d' -e 's/ //g'
curl -6 --connect-timeout 5 -s http://$i $ARGS | sed -e 's/<[^>]*>/ /g' | grep -A 1 "\(Your\? are\|Your IP\|Welcome\|callback\)" | grep -v "\(\[.*\]\|FAQ\|[yY]our\ browser\)"
echo
done | sed -e 's/\( *\|[(){}]\|\"[:,]\"\|"\"\)/ /g' -e '/^\( \|\r\|--\)$/d'
@mkorthof
mkorthof / sshfp.py
Created March 25, 2017 12:37
ssh fingerprints
#!/usr/bin/env python3
# http://stackoverflow.com/questions/6682816/deriving-an-ssh-fingerprint-from-a-public-key-in-python
import base64
import hashlib
def debug(line, field):
# try: print ("DEBUG: line.strip(): %s\n" % line.strip())
# except Exception as e: print ("ERROR: line.strip(): %s \n" % e)
@mkorthof
mkorthof / clamav-freshclam
Created June 14, 2017 17:19
limit freshclam memory usage (cron)
29 */1 * * * clamav [ -x /usr/bin/freshclam ] && { ulimit -Sm 512000; ulimit -Sv 512000; ulimit -Hm 1024000; ulimit -Hv 1024000; /usr/bin/freshclam --quiet; } > /dev/null
@mkorthof
mkorthof / pslog.sh
Last active September 10, 2022 21:48
Piped logger for Apache to use with OpenVPN port_share (logs real client ip)
#!/bin/sh
# pslog.sh - Piped logger for Apache to use with OpenVPN + port sharing
# Replaces remote ip in logs with real client ip
#
# USAGE: ErrorLog "|/usr/local/bin/pslog.sh ${APACHE_LOG_DIR}/error.log"
# CustomLog "|/usr/local/bin/pslog.sh ${APACHE_LOG_DIR}/access.log" combined
#
# REQUIRES: openvpn server config "port-share 127.0.0.1 10443 portshare"
# where 'portshare' is journal dir for tmp files (e.g. /run/openvpn/portshare if chrooted)
@mkorthof
mkorthof / uptime.cmd
Created August 24, 2017 12:39
windows uptime
@PowerShell -ExecutionPolicy RemoteSigned -Command Invoke-Expression $('$args=@(^&{$args} %*);'+[String]::Join(';',(Get-Content -LiteralPath '%~f0') -notmatch '^^@PowerShell.*EOF$')) & goto :EOF
$d = Get-Date
$upTime = (($d) - ([wmi]'').ConvertToDateTime((Get-WmiObject win32_operatingsystem).LastBootUpTime)).ToString("d' days, 'h\:mm")
$ActiveUsers = @()
foreach($User in (Get-WmiObject Win32_LoggedOnUser).Antecedent) { $ActiveUsers += $User.Substring($User.LastIndexOf('=') + 2, $User.Length - $User.LastIndexOf('=') -3) }
$UserText = "$($ActiveUsers.Count) user"
if ( $ActiveUsers.Count -gt 1 ) { $UserText += "s" }
$TotalProcTime = (Get-Counter "\Processor(_total)\% Processor Time") | foreach {$_.CounterSamples[0].CookedValue}
@mkorthof
mkorthof / vboxsave.bat
Created August 24, 2017 13:49
VirtualBox savestate all running VM's (Windows)
@echo off
:: https://superuser.com/questions/959567/virtualbox-windows-graceful-shutdown-of-guests-on-host-shutdown
SET "LOG=0"
SET "LOGFILE=%~dp0%vboxsave.log"
SET VBoxManage="%ProgramFiles%\Oracle\VirtualBox\VBoxManage.exe"
IF "%~1"=="LOG" ( SET "LOG=1" )
IF EXIST "%LOGFILE%.tmp" ( del %LOGFILE%.tmp )
IF %LOG% EQU 1 ( CALL :msg logging is enabled )
@mkorthof
mkorthof / ipset-country.md
Last active May 5, 2023 00:28
Block countries using iptables + ipset + ipdeny.com -> moved to https://github.com/mkorthof/ipset-country
@mkorthof
mkorthof / ipset-logpat.sh
Last active December 20, 2023 19:48
creates ipset sets matching certain patterns in httpd logs
#!/bin/bash
# ipset-logpat
# searches httpd access logs for pattern, whoises matching ip's and uses
# ip blocks to create ipset set. also adds iptables rules to log and reject
# requires: iptables, ipset, aggregate (optional)
# other useful ipset commands: ipset list [-terse], ipset destroy
# more info: