Skip to content

Instantly share code, notes, and snippets.

@tcely
tcely / keybase.md
Created December 11, 2017 20:21
keybase.io: keybase prove github tcely

Keybase proof

I hereby claim:

  • I am tcely on github.
  • I am tcely (https://keybase.io/tcely) on keybase.
  • I have a public key ASCepDrTFuNbJ51KamisH6cg9iNJN90f5vFYyIQYJ4nTWgo

To claim this, I am signing this object:

@tcely
tcely / defensive_bash.sh
Created December 9, 2017 21:36
Clean bash aliases and functions
#!/bin/bash
# *Temporarily* force Bash into POSIX compatibility mode, where `unset` cannot
# be shadowed, which allows us to undefine any `unset` *function* as well
# as other functions that may shadow crucial commands.
# Note: Fortunately, POSIXLY_CORRECT= works even without `export`, because
# use of `export` is not safe at this point.
# By contrast, a simple assignment cannot be tampered with.
POSIXLY_CORRECT=
@tcely
tcely / qnap-crypt-plaintext.sh
Last active September 18, 2017 02:25
QNAP LUKS password hashing
#!/bin/sh
docker run --rm -it perl:5-threaded \
perl -e 'print(q{Enter pass phrase: }); system("stty -echo"); chomp($pt = <>); system("stty echo"); print(qq{\n}, crypt($pt, q{$1$YCCaQNAP$}), qq{\n});'
@tcely
tcely / ssh-limit.sh
Created August 9, 2017 17:26
SSH brute-force limiting using iptables
#!/bin/sh
iptables -F SSH_PORT_LIMIT || iptables -N SSH_PORT_LIMIT
iptables -A SSH_PORT_LIMIT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A SSH_PORT_LIMIT -p tcp -m state --state NEW -m hashlimit --hashlimit-mode srcip --hashlimit-upto 10/hour --hashlimit-burst 15 --hashlimit-name ssh -j ACCEPT
iptables -A SSH_PORT_LIMIT -j LOG --log-level info --log-prefix 'ssh-port-limit: '
iptables -A SSH_PORT_LIMIT -p tcp -j REJECT --reject-with tcp-reset
iptables -A SSH_PORT_LIMIT -j DROP
@tcely
tcely / touch.py
Last active June 11, 2017 00:20
A better touch than provided by busybox
#!/usr/bin/env python
import io, os, sys
from argparse import ArgumentParser
from calendar import timegm
from time import gmtime, localtime, mktime, strftime, strptime
def touchUTCString(t):
return timegm(strptime(t, '%a, %d %b %Y %H:%M:%S %Z'))
@tcely
tcely / .bash_profile
Last active June 5, 2016 09:04
Mac OS X ssh-askpass in AppleScript
if [ -s ~/.bashrc ]; then
. ~/.bashrc
fi
# Additions to fix the lack of confirmation when keys are added from the Keychain
if [ -s ~/.ssh/ssh-agent.pid ]; then
. ~/.ssh/ssh-agent.pid
if [ -n "$SSH_AGENT_PID" ] && ! kill -0 "$SSH_AGENT_PID" &>/dev/null; then
rm -f ~/.ssh/ssh-agent.pid
unset -v SSH_AGENT_PID
@tcely
tcely / clear-gnome-altfn-shortcuts.sh
Created March 10, 2016 18:54
Clear shortcuts from Alt+Fn keys in GNOME
#!/bin/bash
# Inspiration from: http://askubuntu.com/questions/126817/how-to-disable-alt-f1-alt-f2-shortcuts
unset -v _key _value _schema
_schema='org.gnome.desktop.wm.keybindings'
while IFS= read -r _key; do
_value="$(gsettings get "$_schema" "$_key")"
while [[ "$_value" =~ \''<Alt>F'[1-9]\' ]] || [[ "$_value" =~ \''<Alt>F1'[0-2]\' ]]; do
#_value="$(sed -e "s/\(, \)\?${BASH_REMATCH[0]}\(, \)\?//;s/''/', '/;" <<<"$_value")"
@tcely
tcely / sha256sumc.sh
Last active September 21, 2023 04:21
replace 'sha256sum -c' with openssl / cmp in bash
#!/bin/bash
sha256sumc ()
{
local err file hash out rc=0;
while IFS=' ' read -r hash file; do
file="${file#[*]}";
out="$(openssl dgst -sha256 -r "$file" 2>/dev/null)" && cmp -s <(echo "$out") <(printf -- '%s *%s\n' "$hash" "$file") && printf -- '%s: OK\n' "$file" || {
printf -- '%s: FAILED' "$file";
err="$(openssl dgst -sha256 -r "$file" 2>&1 >/dev/null)";
if [[ "$err" =~ ': No such file or directory'$'\n' ]]; then
@tcely
tcely / list_ciphers.sh
Last active May 14, 2022 17:15
Check supported ciphers with bash and openssl s_client
#!/bin/bash
host="${1:-127.0.0.1}"
port="${2:-443}"
ciphers='ALL:!eNULL'
printf 'Using openssl at: '
command -v openssl
openssl version -a
printf '\nCiphers selected by server at %s using TCP port %s:\n' "$host" "$port"
while : ; do
@tcely
tcely / str_hex_conversion.func.sh
Last active May 14, 2022 17:15
Bash functions for converting hexadecimal strings back to ASCII and for converting ASCII strings to hexadecimal strings.
#!/bin/bash
#
hextostr() {
local i _hs="$*"
local _hsl="${#_hs}"
printf '%s\n' "$(for ((i=0; i < _hsl; i+=2)); do echo -ne "\x${_hs:i:2}"; done)"
unset -v _hsl _hs i
}
#hextostr '48656C6C6F20776F726C6421'