├── README.md ├── old ├── pre-suspend ├── autolock ├── ddns-updater.conf ├── propersuspend ├── getphotos ├── ddns-updater ├── mp3clean ├── securegpgsign ├── pdfmergetoc ├── srf ├── dyndnslogin ├── fixjollaphotos ├── packtebooksrename ├── sshfpgen ├── mkgallery ├── braindump.sh └── firewall ├── ip.php ├── telnetwitness ├── dnssnoop ├── download-burpsuite-bapps ├── magnify ├── gppdecrypt ├── fileupload-checker-form.php ├── LICENSE ├── templates ├── python └── bash ├── imageshrink ├── screenshot ├── pic2vid ├── htmlsmuggler ├── fileupload-checker-plain.php ├── Dump-PublicAzureBlobStorage.ps1 ├── dollyx509 ├── base16 ├── wecker ├── screenctl ├── download-boot-isos ├── Extract-AzureTokens.ps1 ├── ip-forwarding-scanner ├── ip6-forwarding-scanner ├── makecert └── 802.11evil /README.md: -------------------------------------------------------------------------------- 1 | # Scripts 2 | 3 | Some scripts. 4 | -------------------------------------------------------------------------------- /old/pre-suspend: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if pgrep mpd >/dev/null 2>&1 && `which mpc` >/dev/null 2>&1 4 | then 5 | mpc pause >/dev/null 2>&1 6 | fi 7 | 8 | pkill mplayer >/dev/null 2>&1 9 | i3lock -u --dpms -c 333333 --pointer default 10 | -------------------------------------------------------------------------------- /old/autolock: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | exec xautolock -detectsleep \ 4 | -time 5 -locker "i3lock -u --dpms -c 333333 --pointer default" \ 5 | -notify 30 \ 6 | -notifier "notify-send -u critical -t 10000 -- 'LOCKING screen in 30 seconds'" 7 | 8 | -------------------------------------------------------------------------------- /old/ddns-updater.conf: -------------------------------------------------------------------------------- 1 | # 2 | # ddns-updater.conf 3 | # 4 | 5 | KEYFILE="/etc/Kfoobar.example.org.+157+51053.private" 6 | NAMESERVER="ns.example.org" 7 | ZONE="example.org" 8 | HOSTNAME="foobar.example.org" 9 | TTL="60" 10 | #CUSTOMIP="10.42.23.5" 11 | #CUSTOMIP6="10.42.23.5" 12 | -------------------------------------------------------------------------------- /ip.php: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /telnetwitness: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # telnetwitness 4 | # 5 | # Receives the telnet banner of the systems provided from stdin 6 | # 7 | # Author: Emanuel Duss 8 | # 9 | 10 | while read host 11 | do 12 | echo "$ telnet $host" 13 | ( 14 | sleep 2 | telnet $host; 15 | ) 16 | echo 17 | echo 18 | done 19 | -------------------------------------------------------------------------------- /old/propersuspend: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # propersuspend - Script wich suspends the computer 4 | # 5 | 6 | if pgrep mpd >/dev/null 2>&1 && `which mpc` >/dev/null 2>&1 7 | then 8 | mpc pause >/dev/null 2>&1 9 | fi 10 | 11 | for i in mplayer pmv vlc 12 | do 13 | pkill $i >/dev/null 2>&1 14 | done 15 | 16 | i3lock -u --dpms -c 333333 --pointer default 17 | systemctl suspend 18 | -------------------------------------------------------------------------------- /dnssnoop: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # dnssnoop 4 | # 5 | # Check if the DNS server has the hostnames from STDIN in the cache 6 | # 7 | # Author: Emanuel Duss 8 | # 9 | 10 | NAMESERVER="$1" 11 | 12 | while read domain 13 | do 14 | if (( "$(dig $domain "@$NAMESERVER" +norec +noall +short | wc -l)" > 0 )) 15 | then 16 | echo "$domain is in the cache." 17 | fi 18 | done 19 | -------------------------------------------------------------------------------- /download-burpsuite-bapps: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # download-burpsuite-bapps 4 | # 5 | # Download all Burp Suite BApps from the BAppstore. 6 | # 7 | # Author: Emanuel Duss 8 | # 9 | 10 | mkdir bapps 11 | curl -s https://portswigger.net/bappstore | awk -F '["<>/]' '/bapp-label heading-4/{ print $7,$9 }' | while read id name 12 | do 13 | echo "Downloading $name..." 14 | curl -s -L "https://portswigger-cdn.net/bappstore/bapps/download/$id" -o "bapps/${name//[^a-z0-9A-Z]/_}.bapp" 15 | done 16 | -------------------------------------------------------------------------------- /old/getphotos: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # getphotos - Get photos from a camera, rename and rotate 4 | # 5 | 6 | FOLDER="`date +GetPhotos_%Y-%m-%d`" 7 | 8 | mkdir "$FOLDER" 9 | cd "$FOLDER" 10 | 11 | gphoto2 --get-all-files 12 | 13 | jhead -autorot *.[jJ][pP][gG] 14 | jhead -norot *.[jJ][pP][gG] 15 | 16 | jhead -nf%Y-%m-%d_%H-%M-%S *.[jJ][pP][gG] 17 | 18 | mkdir "`ls *.jpg | cut -c 1-10 | sort -u`" 19 | 20 | ls *.jpg | cut -c 1-10 | sort -u | while read line 21 | do 22 | mv "$line*.jpg" "$line" 23 | done 24 | 25 | cd .. 26 | chown -R emanuel.users "$FOLDER" 27 | -------------------------------------------------------------------------------- /magnify: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # magnify 4 | # 5 | # Show current screen in imageviewer to zoom in for presentations 6 | # 7 | # Author: Emanuel Duss 8 | # 9 | 10 | PrintUsage(){ 11 | cat << EOI 12 | Usage: magnify 13 | 14 | A simple screen magnifier. 15 | 16 | Use the arrow keys to zoom in or out. 17 | Use the mouse cursor to adjust screen section. 18 | Press q to quit. 19 | EOI 20 | } 21 | 22 | if ! hash scrot 2>/dev/null && hash feh 2>/dev/null 23 | then 24 | echo "Could not find scrot and feh" 25 | exit 1 26 | fi 27 | 28 | IMAGE="$(mktemp --tmpdir="/tmp" magnify_XXXXX.png)" 29 | trap 'rm "$IMAGE"' EXIT 30 | 31 | scrot "$IMAGE" 32 | feh --borderless --image-bg black --fullscreen "$IMAGE" 33 | -------------------------------------------------------------------------------- /old/ddns-updater: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # ddns-updater - Update dynamic dns entries 4 | # 5 | 6 | CONF="${1:-/etc/ddns-updater.conf}" 7 | . "$CONF" 8 | 9 | if [[ -z "$KEYFILE" || -z "$NAMESERVER" || -z "$ZONE" \ 10 | || -z "$HOSTNAME" || -z "$TTL" ]] 11 | then 12 | echo "Error loading configuration file $CONF" 13 | exit 1 14 | fi 15 | 16 | IPADDR="${CUSTOMIP:-$(curl -s -4 https://motd.ch/ip.php)}" 17 | IPADDROLD="$(dig $HOSTNAME @$NAMESERVER +short)" 18 | IP6ADDR="${CUSTOMIP6:-$(curl -s -6 https://motd.ch/ip.php)}" 19 | IP6ADDROLD="$(dig $HOSTNAME AAAA @$NAMESERVER +short)" 20 | 21 | if [[ "$IPADDR" == "$IPADDROLD" && "$IP6ADDR" == "$IP6ADDROLD" ]] 22 | then 23 | exit 24 | fi 25 | 26 | ( 27 | echo "server $NAMESERVER" 28 | echo "zone $ZONE" 29 | echo "update delete $HOSTNAME" 30 | echo "update add $HOSTNAME $TTL A $IPADDR" 31 | echo "update add $HOSTNAME $TTL AAAA $IP6ADDR" 32 | echo "send" 33 | ) | nsupdate -v -k "$KEYFILE" 34 | -------------------------------------------------------------------------------- /old/mp3clean: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # MP3-Sammlung Sortieren 4 | # 5 | # History 6 | # 2010-06-28 [Emanuel Duss] Erste Version 7 | # 8 | 9 | # Lese Angaben ein 10 | echo -n "Artist: " 11 | read ARTIST 12 | echo -n "Album: " 13 | YEAR=`pwd | sed -r -e 's/.*\/([0-9]{4})[^\/]*/\1/g'` 14 | read ALBUM 15 | echo -n "Jahr: " 16 | read YEAR 17 | echo -n "Genre: " 18 | read GENRE 19 | echo -n "Kommentar: " 20 | read COMMENT 21 | echo 22 | 23 | echo "Artist: $ARTIST" 24 | echo "Album: $ALBUM" 25 | echo "Jahr: $YEAR" 26 | echo "Genre: $GENRE" 27 | echo "Kommentar: $COMMENT" 28 | 29 | echo "MP3 Dateien taggen? [ENTER]" 30 | ls *.mp3 31 | mp3info -a "$ARTIST" -g "$GENRE" -l "$ALBUM" -y "$YEAR" -c "$COMMENT" *.mp3 32 | echo "ID3-Tags sind gesetzt" 33 | read 34 | mp3info *.mp3 35 | 36 | mkdir -p "$ARTIST/$YEAR - $ALBUM" 37 | 38 | for file in *.mp3 39 | do 40 | echo $file 41 | mv "$file" "$(mp3info -p "%a/%y - %l/%n - %t.mp3" "$file")" 42 | done 43 | 44 | -------------------------------------------------------------------------------- /gppdecrypt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # gppdecrypt 4 | # 5 | # Decrypt credentials stored in Windows Group Policy Preferences 6 | # 7 | # See Blog for more information: 8 | # https://blog.compass-security.com/2012/04/exploit-credentials-stored-in-windows-group-policy-preferences/ 9 | # 10 | # Author: Emanuel Duss 11 | # 12 | 13 | # Microsoft released AES key 14 | # https://msdn.microsoft.com/en-us/library/2c15cbf0-f086-4c74-8b70-1f2fa45dd4be.aspx 15 | KEY="4e9906e8fcb66cc9faf49310620ffee8f496e806cc057990209b09a433b66c1b" 16 | 17 | PASSWORD="$1" 18 | PASSWORD="foobar==" 19 | 20 | add_padding(){ 21 | PADDINGLEHGTH="$((4 - $(echo "$1" | wc -L) % 4))" 22 | for i in $(seq "$PADDINGLEHGTH") 23 | do 24 | PADDING="${PADDING}$(echo -n =)" 25 | done 26 | echo "${1}${PADDING}" 27 | } 28 | 29 | decrypt_password(){ 30 | echo "$1" \ 31 | | openssl enc \ 32 | -a \ 33 | -d \ 34 | -aes-256-cbc \ 35 | -K "$KEY" \ 36 | -iv 00000000000000000000000000 37 | echo 38 | } 39 | 40 | main(){ 41 | decrypt_password "$(add_padding "$PASSWORD")" 42 | } 43 | 44 | main "$@" 45 | -------------------------------------------------------------------------------- /fileupload-checker-form.php: -------------------------------------------------------------------------------- 1 | 8 | // 9 | 10 | if ($_SERVER['REQUEST_METHOD'] == 'POST') { 11 | $rawData = file_get_contents('php://input'); 12 | $dataSize = strlen($rawData); 13 | 14 | if ($dataSize > 0) { 15 | $hashContext = hash_init('sha256'); 16 | hash_update($hashContext, $rawData); 17 | $fileHash = hash_final($hashContext); 18 | 19 | $first20Bytes = substr($rawData, 0, 20); 20 | $hexFirst20Bytes = bin2hex($first20Bytes); 21 | 22 | echo "

Data processed successfully!

\n"; 23 | echo "

Data Size: " . htmlspecialchars(number_format($dataSize)) . " bytes

\n"; 24 | echo "

SHA256 Hash: " . htmlspecialchars($fileHash, ENT_QUOTES, 'UTF-8') . "

\n"; 25 | echo "

First 20 Bytes (Hex): " . htmlspecialchars($hexFirst20Bytes, ENT_QUOTES, 'UTF-8') . "

\n"; 26 | } else { 27 | echo "

No data received.

"; 28 | } 29 | } 30 | ?> 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2017 Emanuel Duss 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /templates/python: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | template 4 | 5 | This is a tempalte for python scripts. 6 | 7 | Author: Emanuel Duss 8 | """ 9 | 10 | import argparse 11 | import logging 12 | 13 | def parse_args(): 14 | parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter) 15 | 16 | parser.add_argument('-x', '--xxx',metavar='file', required=False, dest='myvar', help='Somehelp') 17 | 18 | return parser.parse_args() 19 | 20 | class MyClass: 21 | foo = "bar" 22 | bar = ["one", "two", "three"] 23 | 24 | def __init__(self): 25 | print("Hello") 26 | 27 | def hello(self, input: str): 28 | print(f"Hello {input}!") 29 | 30 | def main(): 31 | args = parse_args() 32 | 33 | logger = logging.getLogger('simple_example') 34 | logger.setLevel(logging.DEBUG) 35 | logging.warning('Warning!') # will print a message to the console 36 | 37 | myclass = MyClass() 38 | myclass.hello("sugus") 39 | 40 | if __name__ == '__main__': 41 | # main() 42 | 43 | list_3 = ['Accidental', '4daa7fe9', 'eM131Me', 'Y!.90'] 44 | secret = [] 45 | 46 | for x in list_3: 47 | secret.append(x[:2]) 48 | 49 | print(''.join(secret)) -------------------------------------------------------------------------------- /old/securegpgsign: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | KEY="$1" 4 | SECUREDEVICE="/dev/${2:-sdc1}" 5 | SECUREDEVICENAME="securegpg" 6 | SECUREHOME="/media/securegpg" 7 | SECUREGPGDIR="$SECUREHOME/.gnupg" 8 | 9 | PrintUsage(){ 10 | cat <<< EOI 11 | Usage: 12 | securegpgsign key [devicename] 13 | securegpgsign -h | --help 14 | 15 | Default Device name is sdc1 16 | 17 | Examples: 18 | securegpgsign 0x23FOOBA2 19 | securegpgsign 0x23FOOBA2 sde 20 | 21 | EOI 22 | } 23 | 24 | if [[ $1 == "-h" || $1 == "--help" ]] 25 | then 26 | PrintUsage 27 | fi 28 | 29 | if (($# < 1)) 30 | then 31 | PrintUsage 32 | exit 1 33 | fi 34 | 35 | gpg --recv-key "$KEY" 36 | gpg --fingerprint "$KEY" 37 | 38 | echo "Is the fingerprint correct?" 39 | echo "Press Enter to continue or ^C to canel." 40 | read 41 | 42 | cryptsetup luksOpen "$SECUREDEVICE" "$SECUREDEVICENAME" 43 | mount "/dev/mapper/$SECUREDEVICENAME" "$SECUREHOME" 44 | 45 | gpg --export "$KEY" | gpg --homedir "$SECUREGPGDIR" --import 46 | gpg --homedir "$SECUREGPGDIR" --sign-key "$KEY" 47 | gpg --homedir "$SECUREGPGDIR" --send-keys "$KEY" 48 | gpg --homedir "$SECUREGPGDIR" --export "$KEY" | gpg --import 49 | 50 | pkill gpg-agent 51 | 52 | umount "$SECUREHOME" 53 | cryptsetup luksClose "/dev/mapper/$SECUREDEVICENAME" 54 | -------------------------------------------------------------------------------- /old/pdfmergetoc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # pdfmergetoc 4 | # 5 | # Merges multiple PDFs and adds a table of contents 6 | # 7 | # Author: Emanuel Duss 8 | # 9 | 10 | PrintUsage(){ 11 | cat << EOI 12 | Usage: 13 | pdfmergetoc [-t title] [-s subtitle] [-a author] [-d date] files ... 14 | EOI 15 | } 16 | 17 | WORKDIR="`mktemp -d`" 18 | TITLE=$1 19 | AUTHOR=$2 20 | DATE=".." 21 | 22 | DOCUMENTFILE="document.tex" 23 | INCLUDEFILE="include.tex" 24 | 25 | cat > $WORKDIR/$DOCUMENTFILE << EOI 26 | \documentclass{scrartcl} 27 | \usepackage{ngerman} 28 | \usepackage{lmodern} 29 | \usepackage[utf8]{inputenc} 30 | \usepackage[ngerman]{babel} 31 | \usepackage{amsmath} 32 | \usepackage{pdfpages} 33 | 34 | \title{$TITLE} 35 | \author{$AUTHOR} 36 | % \date{$DATE} 37 | \begin{document} 38 | \maketitle 39 | \tableofcontents 40 | \newpage 41 | \input{include.tex} 42 | \end{document} 43 | EOI 44 | 45 | > $INCLUDEFILE 46 | for i in $@ 47 | do 48 | TITEL="$(sed -e 's/^includefiles\///g;s/_/\ /g;s/\.pdf//g' <<< \"$i\")" 49 | echo "\includepdf[scale=0.9pages=1,pagecommand=\section{$TITEL}]{${i}}" >> $INCLUDEFILE 50 | if ((`pdfinfo $i | awk '/^Pages:/{print $2}'` >= 2)) 51 | then 52 | echo "\includepdf[pages=2-]{${i}}" >> $INCLUDEFILE 53 | fi 54 | done 55 | 56 | latexmk -pdf $DOCUMENTFILE 57 | latexmk -c 58 | -------------------------------------------------------------------------------- /imageshrink: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # imageshrink 4 | # 5 | # Shrink the specified image(s) 6 | # 7 | # Author: Emanuel Duss 8 | # 9 | 10 | set -o errexit 11 | set -o nounset 12 | set -o pipefail 13 | 14 | print_help(){ 15 | cat << EOI 16 | Usage: imageshrink [files ...] 17 | 18 | EOI 19 | } 20 | 21 | check_dependencies(){ 22 | FAIL=0 23 | for tool in $@ 24 | do 25 | if ! hash "$tool" &> /dev/null 26 | then 27 | echo "The tool $tool does not exist." 28 | FAIL=1 29 | fi 30 | done 31 | if [[ "$FAIL" == 1 ]] 32 | then 33 | exit 1 34 | fi 35 | } 36 | 37 | main(){ 38 | check_dependencies convert 39 | 40 | FOLDER="small" 41 | QUALITY="75" 42 | SIZE="1280x1280" 43 | SIZE="2048x2048" 44 | 45 | if [[ ! -d "$FOLDER" ]] 46 | then 47 | mkdir "$FOLDER" 48 | fi 49 | 50 | TOTAL="$(echo $@ | wc -w)" 51 | COUNT=0 52 | for photo in $@ 53 | do 54 | COUNT=$((COUNT + 1)) 55 | echo -ne "\r\033[KProcessing $photo: $COUNT/$TOTAL ($(( 100 * $COUNT / $TOTAL))%)" 56 | destination="$FOLDER/$photo" 57 | if [[ ! -f "$destination" && -f "$photo" && ! -d "$photo" ]] 58 | then 59 | if ! convert -resize "$SIZE" -quality "$QUALITY" "$photo" "$destination" 60 | then 61 | echo "Error while processing $photo." 62 | fi 63 | fi 64 | done 65 | echo 66 | } 67 | 68 | trap "echo; exit 1" SIGINT SIGTERM 69 | 70 | main "$@" 71 | -------------------------------------------------------------------------------- /screenshot: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # screenshot 4 | # 5 | # Simple screenshot wrapper around maim 6 | # 7 | # Author: Emanuel Duss 8 | # 9 | 10 | set -o errexit 11 | set -o pipefail 12 | 13 | APP="feh -g 600x600+50%+50% --borderless --scale-down --image-bg checks" 14 | 15 | print_usage(){ 16 | cat << EOI 17 | Usage: screenshot [OPTION] [FILE] 18 | 19 | By default, the selection is saved to your home directory. 20 | 21 | Options: 22 | -f fullscreen screenshot 23 | -c copy selection to clipboard 24 | -h display this help and exit 25 | 26 | File: 27 | filename or directory where to save the screenshot. 28 | 29 | EOI 30 | } 31 | 32 | check_dependencies(){ 33 | local FAIL=0 34 | for tool in "$@" 35 | do 36 | if ! hash "$tool" &> /dev/null 37 | then 38 | echo "The tool $tool does not exist." 39 | FAIL=1 40 | fi 41 | done 42 | if [[ "$FAIL" == 1 ]] 43 | then 44 | exit 1 45 | fi 46 | } 47 | 48 | main(){ 49 | check_dependencies maim 50 | 51 | case $1 in 52 | "full") 53 | FILENAME="$HOME/$(date +%Y-%m-%d_%H-%M-%S).png" 54 | maim "$FILENAME" 55 | $APP "$FILENAME" 56 | ;; 57 | "copy") 58 | check_dependencies xclip 59 | maim -s | xclip -selection clipboard -t image/png 60 | ;; 61 | *) 62 | FILENAME="$HOME/$(date +%Y-%m-%d_%H-%M-%S).png" 63 | maim -s "$FILENAME" 64 | $APP "$FILENAME" 65 | ;; 66 | esac 67 | } 68 | 69 | main "$@" 70 | -------------------------------------------------------------------------------- /old/srf: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # plays the latest issue of some srf media productions. 4 | # 5 | 6 | print_help(){ 7 | cat << EOI 8 | Usage: 9 | srf 10vor10 | 100sekunden | arena | dok | kassensturz | netznatur 10 | srf podcast url 11 | EOI 12 | } 13 | 14 | first_rss_url(){ 15 | curl -s "$1" | xmllint -xpath "string((rss/channel/item/enclosure/@url)[1])" - 16 | } 17 | play_latest_rss(){ 18 | mpv "$(first_rss_url $1)" 19 | } 20 | 21 | main(){ 22 | case $1 in 23 | 10vor10|10v*) 24 | play_latest_rss http://www.srf.ch/feed/podcast/hd/c38cc259-b5cd-4ac1-b901-e3fddd901a3d.xml 25 | ;; 26 | 100sekunden|100*) 27 | play_latest_rss http://podcasts.srf.ch/100_sekunden_wissen_mpx.xml 28 | ;; 29 | arena|are*) 30 | play_latest_rss http://www.srf.ch/feed/podcast/hd/09784065-687b-4b60-bd23-9ed0d2d43cdc.xml 31 | ;; 32 | dok) 33 | play_latest_rss http://www.srf.ch/feed/podcast/hd/3b016ffc-afa2-466d-a694-c48b7ffe1783.xml 34 | ;; 35 | kassensturz|kas*) 36 | play_latest_rss http://www.srf.ch/feed/podcast/hd/78a6014e-8058-4bdd-88aa-824f846ca6f0.xml 37 | ;; 38 | netznatur|net*) 39 | play_latest_rss http://www.srf.ch/feed/podcast/hd/7225ec3b-e259-4af1-b9b0-31b293c70763.xml 40 | ;; 41 | http*) 42 | play_latest_rss "$1" 43 | ;; 44 | help) 45 | print_help 46 | ;; 47 | *) 48 | print_help 49 | exit 1 50 | ;; 51 | esac 52 | } 53 | 54 | main "$@" 55 | -------------------------------------------------------------------------------- /old/dyndnslogin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # dyndnslogin - Automate login to prevent account expiration 4 | # 5 | 6 | ######################################################################## 7 | # DynDNS Settings (default-value, overwrite with $1 and $2) 8 | # If you have special chars in your password, you need to urlencode: 9 | # python -c "from urllib.parse import quote; 10 | # print(quote('your password', safe=''))" 11 | DEFAULT_USERNAME="username" 12 | DEFAULT_PASSWORD="password" 13 | 14 | 15 | # Import settings from /etc/ddclient.conf if available 16 | DDCONF="/etc/ddclient.conf" 17 | if [ -r "$DDCONF" ] && grep -q "^server=members.dyndns.org" "$DDCONF" 18 | then 19 | DEFAULT_USERNAME="`awk -F= '/^login=/{ print $2 }' $DDCONF`" 20 | DEFAULT_PASSWORD="`awk -F= '/^password=/{ print $2 }' $DDCONF`" 21 | fi 22 | 23 | USERNAME=${1:-$DEFAULT_USERNAME} 24 | PASSWORD=${2:-$DEFAULT_PASSWORD} 25 | 26 | PROGNAME=dyndnslogin 27 | COOKIE=`mktemp --tmpdir="/tmp" -t ${PROGNAME}_cookie_XXXXX` 28 | OUTPUT=`mktemp --tmpdir="/tmp" -t ${PROGNAME}_output_XXXXX` 29 | USERAGENT="Mozilla/5.0" 30 | 31 | MULTIFORM=`curl -s -A $USERAGENT -c $COOKIE https://account.dyn.com \ 32 | | awk -F\' '/multiform/{ print $6 }'` 33 | 34 | curl -s --location -A "$USERAGENT" -b $COOKIE -c $COOKIE -o $OUTPUT \ 35 | --data-urlencode "username=$USERNAME&password=$PASSWORD&iov_id=&submit=Log+in&multiform=$MULTIFORM" \ 36 | https://account.dyn.com/ 37 | 38 | if grep -i -E "(Welcome|Hi).*$USERNAME" $OUTPUT > /dev/null 2>&1 39 | then 40 | echo Login successful 41 | else 42 | echo Login failed 43 | FAILED="true" 44 | fi 45 | 46 | rm $COOKIE 47 | rm $OUTPUT 48 | 49 | if [ "$FAILED" = "true" ] 50 | then 51 | exit 1 52 | fi 53 | -------------------------------------------------------------------------------- /old/fixjollaphotos: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | 7 | DATEFORMAT="%Y-%m-%d_%H-%M-%S" 8 | 9 | print_help(){ 10 | cat << EOI 11 | Usage: fixjollaphotos file [files ...] 12 | 13 | This scripts does the following for your pictures taken by your Jolla phone: 14 | 15 | * Add the EXIF timestamp according to the filesystem timestamp 16 | * Renames the photo like YYYY-mm-dd_HH-MM-SS 17 | * Rotates the photo correctly 18 | 19 | The tools exiftool and jhead must be installed. 20 | EOI 21 | } 22 | 23 | check_dependencies(){ 24 | FAIL=0 25 | for tool in $@ 26 | do 27 | if ! hash "$tool" &> /dev/null 28 | then 29 | echo "The tool $tool does not exist." 30 | FAIL=1 31 | fi 32 | done 33 | if [[ "$FAIL" == 1 ]] 34 | then 35 | exit 1 36 | fi 37 | } 38 | 39 | fix_photo(){ 40 | echo -n Fixing "$file -> " 41 | 42 | touch --reference="$file" $file.savedate 43 | # Add dummy timestamp, so we can it modify later 44 | exiftool -"DateTimeOriginal=1984:05:23 13:37:42" "$file" &> /dev/null 45 | touch --reference="$file.savedate" $file 46 | 47 | # Set EXIF timestamp to the file timestamp 48 | jhead -dsft "$file" &> /dev/null 49 | rm "$file.savedate" 50 | 51 | # Correct timezone (Timestamp of file is UTC) 52 | TIMEOFFSET="$(date +%:z)" 53 | jhead -ta${TIMEOFFSET} "$file" &> /dev/null 54 | 55 | # Rotate the photo 56 | jhead -autorot "$file" &> /dev/null 57 | 58 | # Rename the file, print new filename and OK 59 | jhead -nf$DATEFORMAT "$file" | awk '{ ORS=""; print $NF }' 60 | rm "${file}_original" 61 | 62 | echo " [OK]" 63 | } 64 | 65 | main(){ 66 | check_dependencies jhead exiftool 67 | 68 | for file in "$@" 69 | do 70 | fix_photo "$file" 71 | done 72 | } 73 | 74 | main "$@" 75 | -------------------------------------------------------------------------------- /old/packtebooksrename: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | 7 | print_help(){ 8 | cat << EOI 9 | packtebooksrename 10 | 11 | This script renames the free learning eBooks from Packt Publishing to a more 12 | human friendly and more meaningful filename. 13 | 14 | Download a free eBook from Packt Publishing here every day: 15 | https://www.packtpub.com/packt/offers/free-learning 16 | 17 | Rename files like: 18 | 9781783283378_code.zip 9781783283378-LEARNING_PYTHON_DESIGN_PATTERNS.pdf 19 | 9781783283378.epub 9781783283378.mobi 20 | 21 | To the pattern "Title_in_Title_Case_PACKT_ISBN.ext": 22 | Learning_Python_Design_Patterns_PACKT_9781783283378{.pdf,.epub,.mobi,_code.zip} 23 | 24 | Usage: 25 | packtebooksrename 26 | 27 | Where the files are the PDF, EPUB, MOBI or ZIP files from the website. 28 | The tool can rename multiple books at once. 29 | EOI 30 | } 31 | 32 | rename_files(){ 33 | echo "$@" | grep -o -E "[0-9]{13}" | sort -u | while read ISBN 34 | do 35 | PDF="$(echo $ISBN*.pdf | head -1)" 36 | EPUB="$(echo $ISBN*.epub | head -1)" 37 | MOBI="$(echo $ISBN*.mobi | head -1)" 38 | CODE="$(echo $ISBN*.zip | head -1)" 39 | 40 | TITLE="$(echo $PDF | sed 's/[^-]*-\(.*\).pdf/\1/' | \ 41 | sed 's/.*/\L&/; s/[a-z]*/\u&/g')" # Title_Case_Like_Title 42 | FILENAME="${TITLE}_PACKT_${ISBN}" 43 | 44 | echo "[*] Processing $TITLE ($ISBN)... " 45 | 46 | mv "$PDF" "$FILENAME.pdf" 47 | 48 | if [[ -f "$EPUB" ]] 49 | then 50 | mv "$EPUB" "$FILENAME.epub" 51 | fi 52 | 53 | if [[ -f "$MOBI" ]] 54 | then 55 | mv "$MOBI" "$FILENAME.mobi" 56 | fi 57 | 58 | if [[ -f "$CODE" ]] 59 | then 60 | mv "$CODE" "${FILENAME}_code.zip" 61 | fi 62 | done 63 | } 64 | 65 | main(){ 66 | if [[ "$#" == 0 ]] 67 | then 68 | print_help 69 | fi 70 | 71 | rename_files "$@" 72 | } 73 | 74 | main "$@" 75 | -------------------------------------------------------------------------------- /pic2vid: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # pic2vid 4 | # 5 | # Convert multiple pictures to a video (time lapse) 6 | # 7 | # Author: Emanuel Duss 8 | # 9 | 10 | DIR="$1" 11 | PICDIR="pic2vid" 12 | SMALLDIR="$DIR/$PICDIR" 13 | SIZE="x1080" 14 | QUALITY="90" 15 | OUTPUTFILE="output.mpg" 16 | CODEC="libx264" 17 | FRAMESPERSECOND="25" 18 | 19 | Printusage () { 20 | echo "Usage: 21 | $0 directory" 22 | } 23 | 24 | if [ -z "$1" ] 25 | then 26 | Printusage 27 | exit 1 28 | fi 29 | 30 | if [ ! -d "$DIR" ] 31 | then 32 | echo "$DIR ist kein Verzeichnis" 33 | Printusage 34 | exit 1 35 | fi 36 | 37 | if [ -d "$SMALLDIR" ] 38 | then 39 | echo "Verzeichnis für aufzubereitende Fotos bereits vorhanden." 40 | else 41 | mkdir "$SMALLDIR" 42 | fi 43 | if [ ! -d "$SMALLDIR" ] 44 | then 45 | echo "Kann $SMALLDIR nicht anlegen. Bitte Berechtigungen prüfen." 46 | exit 1 47 | fi 48 | 49 | cd $DIR 50 | 51 | 52 | TOTAL="`ls *.[Jj][Pp][Gg] | wc -l`" 53 | COUNT="1" 54 | for file in *.[Jj][Pp][Gg] 55 | do 56 | if [ -f "${PICDIR}/$file" ] 57 | then 58 | echo "Überspringe $file, da bereits konvertiert (${PICDIR}/$file)" 59 | else 60 | echo "$file: Foto $COUNT von $TOTAL ($((100 * $COUNT / $TOTAL))%)" 61 | convert -resize $SIZE -quality $QUALITY "$file" "${PICDIR}/$file" 62 | fi 63 | ((COUNT++)) 64 | done 65 | 66 | # Rename pictures (like 0001.jpg to 2342.jpg) 67 | cd $PICDIR 68 | LENGTH="`ls *.[Jj][Pp][Gg] | wc -l | wc -L`" 69 | NUMBER="1" 70 | for file in *.[Jj][Pp][Gg] 71 | do 72 | NEWNAME="`printf %0${LENGTH}d $NUMBER`.jpg" 73 | if [ -f "$NEWNAME" ] 74 | then 75 | echo "Datei $file bereits umbenannt. OK." 76 | else 77 | # Symlink statt umbenennen, damit die Prüfung ob schon konvertiert auch funktioniert 78 | ln -s "$file" "`printf %0${LENGTH}d $NUMBER`".jpg 79 | fi 80 | ((NUMBER++)) 81 | done 82 | 83 | # create the video 84 | ffmpeg -f image2 -i %0${LENGTH}d.jpg -r $FRAMESPERSECOND -vcodec $CODEC ../$OUTPUTFILE 85 | -------------------------------------------------------------------------------- /old/sshfpgen: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # sshfpgen - Creates SSHFP Records for all available keys 4 | # 5 | 6 | HOST="${1-$(hostname -f)}" 7 | 8 | if [[ "$1" == "-h" || "$1" == "--help" ]] 9 | then 10 | echo "Usage: sshfpgen " 11 | fi 12 | 13 | if which openssl >/dev/null 2>&1 14 | then 15 | if ! which sha1sum >/dev/null 2>&1 16 | then 17 | sha1sum() { 18 | openssl dgst -sha1 | grep -E -o "[0-9a-f]{40}" 19 | } 20 | fi 21 | if ! which sha256sum >/dev/null 2>&1 22 | then 23 | sha256sum() { 24 | openssl dgst -sha256 | grep -E -o "[0-9a-f]{64}" 25 | } 26 | fi 27 | fi 28 | 29 | for pubkey in /etc/ssh/ssh_host_*_key.pub /etc/ssh_host_*_key.pub 30 | do 31 | case "$(cut -d _ -f3 <<< "$pubkey")" 32 | in 33 | rsa) 34 | echo "$HOST IN SSHFP 1 1 $(cut -f2 -d ' ' "$pubkey" | base64 --decode | sha1sum | cut -f 1 -d ' ')" 35 | echo "$HOST IN SSHFP 1 2 $(cut -f2 -d ' ' "$pubkey" | base64 --decode | sha256sum | cut -f 1 -d ' ')" 36 | ;; 37 | dsa) 38 | echo "$HOST IN SSHFP 2 1 $(cut -f2 -d ' ' "$pubkey" | base64 --decode | sha1sum | cut -f 1 -d ' ')" 39 | echo "$HOST IN SSHFP 2 2 $(cut -f2 -d ' ' "$pubkey" | base64 --decode | sha256sum | cut -f 1 -d ' ')" 40 | ;; 41 | ecdsa) 42 | echo "$HOST IN SSHFP 3 1 $(cut -f2 -d ' ' "$pubkey" | base64 --decode | sha1sum | cut -f 1 -d ' ')" 43 | echo "$HOST IN SSHFP 3 2 $(cut -f2 -d ' ' "$pubkey" | base64 --decode | sha256sum | cut -f 1 -d ' ')" 44 | ;; 45 | ed25519) 46 | echo "$HOST IN SSHFP 4 1 $(cut -f2 -d ' ' "$pubkey" | base64 --decode | sha1sum | cut -f 1 -d ' ')" 47 | echo "$HOST IN SSHFP 4 2 $(cut -f2 -d ' ' "$pubkey" | base64 --decode | sha256sum | cut -f 1 -d ' ')" 48 | ;; 49 | ed448) 50 | echo "$HOST IN SSHFP 6 1 $(cut -f2 -d ' ' "$pubkey" | base64 --decode | sha1sum | cut -f 1 -d ' ')" 51 | echo "$HOST IN SSHFP 6 2 $(cut -f2 -d ' ' "$pubkey" | base64 --decode | sha256sum | cut -f 1 -d ' ')" 52 | ;; 53 | esac 54 | done 55 | 56 | -------------------------------------------------------------------------------- /htmlsmuggler: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # htmlsmuggler 4 | # 5 | # Create HTML file for HTML smuggling content 6 | # 7 | # Author: Emanuel Duss 8 | # 9 | 10 | set -o errexit 11 | set -o nounset 12 | set -o pipefail 13 | 14 | print_usage(){ 15 | cat << EOI 16 | Usage: htmlsmuggler payload.docm 17 | EOI 18 | } 19 | 20 | generate_payload(){ 21 | 22 | FILENAME="$(basename "$INPUTFILE")" 23 | TYPE="$(file -b --mime-type "$INPUTFILE")" 24 | PAYLOAD="$(base64 -w0 "$INPUTFILE" | tr 'AaZz+/=' '@_()%?$')" 25 | HASH="$(sha256sum "$INPUTFILE" | cut -d ' ' -f 1)" 26 | 27 | cat << EOI 28 | 29 | Simple HTML Smuggler 30 | 31 |

Simple HTML Smuggler

32 |

File: $FILENAME
SHA256: $HASH

33 | 70 | 71 | 72 | EOI 73 | } 74 | 75 | main(){ 76 | if [[ -z "${1:-}" ]] 77 | then 78 | print_usage 79 | exit 1 80 | fi 81 | 82 | TEMPLATE="template.html" 83 | INPUTFILE="$1" 84 | OUTPUTFILE="$INPUTFILE.html" 85 | 86 | generate_payload 87 | } 88 | 89 | main "$@" 90 | -------------------------------------------------------------------------------- /fileupload-checker-plain.php: -------------------------------------------------------------------------------- 1 | 8 | // 9 | ?> 10 | 11 | 12 | 13 | 14 | 15 | 16 | File Upload Tester 17 | 18 | 19 |

File Upload Tester

20 |

Upload a file to calculate its SHA256 sum, display its size, and show the first 20 bytes in hex:

21 |
22 | 23 |

24 | 25 |
26 | 27 | 28 | 29 | File uploaded successfully!\n\n"; 55 | echo "

File Size: " . htmlspecialchars(number_format($fileSize)) . " bytes

\n"; 56 | echo "

SHA256 Hash: " . htmlspecialchars($fileHash, ENT_QUOTES, 'UTF-8') . "

\n"; 57 | echo "

First 20 Bytes (Hex): " . htmlspecialchars($hexFirst20Bytes, ENT_QUOTES, 'UTF-8') . "

\n"; 58 | } else { 59 | echo "

File upload failed.

"; 60 | } 61 | } 62 | ?> 63 | -------------------------------------------------------------------------------- /Dump-PublicAzureBlobStorage.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Dumps all data of a public Azure Blob storage. 4 | 5 | .DESCRIPTION 6 | This script dumps all files of a public Azure Blob Storage and saves them 7 | in the current directory. For every container, a new directory with the 8 | same name is created. 9 | 10 | This is still beta and was only used once. Not considered as stable. 11 | 12 | .PARAMETER Url 13 | The SAS url to the public Azure Blob storage. 14 | 15 | .EXAMPLE 16 | .\Dump-PublicAzureBlobStorage.ps1 https://example.blob.core.windows.net/ 17 | 18 | If you have a SAS URL, omit the path but keep the parameters like sig, sp, ... 19 | 20 | .NOTES 21 | Author: Emanuel Duss 22 | #> 23 | 24 | param ( 25 | [string]$Url 26 | ) 27 | 28 | 29 | $parameters = "restype=container&comp=list" 30 | 31 | # Check if URL already contains parameters and add parameters to list containers and blobs 32 | if ($Url -match "\?") { 33 | $fullUrl = "${Url}&$parameters" 34 | } else { 35 | $Url = "${Url}/?" 36 | $fullUrl = "${Url}?$parameters" 37 | } 38 | 39 | $response = [xml](Invoke-RestMethod -Uri $fullUrl).Substring(3) # Remove strange prefix 40 | 41 | $containers = $response.EnumerationResults.Containers.Container 42 | 43 | foreach ($container in $containers) { 44 | $containerName = $container.Name 45 | Write-Host "Found Container $containerName" 46 | 47 | $containerDir = Join-Path -Path (Get-Location) -ChildPath $containerName 48 | if (-not (Test-Path -Path $containerDir)) { 49 | New-Item -ItemType Directory -Path $containerDir | Out-Null 50 | } 51 | 52 | $containerUrl = $fullUrl.Replace("?", "${containerName}?") # Add container name to path 53 | 54 | $blobResponse = [xml](Invoke-RestMethod -Uri $containerUrl).Substring(3) 55 | 56 | $blobs = $blobResponse.EnumerationResults.Blobs.Blob 57 | 58 | foreach ($blob in $blobs) { 59 | $blobName = $blob.Name 60 | $blobPath = Join-Path -Path $containerDir -ChildPath $blobName 61 | 62 | $blobDir = Split-Path -Path $blobPath -Parent 63 | if (-not (Test-Path -Path $blobDir)) { 64 | New-Item -ItemType Directory -Path $blobDir | Out-Null 65 | } 66 | 67 | $blobUrl = $Url.Replace("?", "$containerName/${blobName}?") 68 | Invoke-WebRequest -Uri $blobUrl -OutFile $blobPath 69 | Write-Host "Downloaded $blobName to $blobPath" 70 | } 71 | } 72 | 73 | Write-Host "All files downloaded successfully." 74 | -------------------------------------------------------------------------------- /dollyx509: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | dollyx509 4 | 5 | Clone X.509 certificates by reading a certificate and generating new key material. 6 | 7 | Author: Emanuel Duss 8 | """ 9 | 10 | import argparse 11 | import OpenSSL.crypto 12 | 13 | def parse_args(): 14 | parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter) 15 | 16 | parser.add_argument('-i', '--certin',metavar='inputcert', required=True, 17 | dest='inputcert', help='Certificate to clone') 18 | parser.add_argument('-c', '--certout',metavar='outputcert', required=True, 19 | dest='outputcert', help='Output file of cloned certificate') 20 | parser.add_argument('-k', '--keyout',metavar='outputkey', required=True, 21 | dest='outputkey', help='Output file of generated private key') 22 | parser.add_argument('--inform', choices={'pem', 'der'}, default='pem', 23 | dest='inputformat', help='Input format of certificate') 24 | parser.add_argument('--outform', choices={'pem', 'der'}, default='pem', 25 | dest='outputformat', help='Output format of certificate/key') 26 | 27 | return parser.parse_args() 28 | 29 | class Certificate: 30 | def __init__(self, file, format='pem'): 31 | self.import_certificate(file, format) 32 | 33 | def __get_filetype(self, format): 34 | if format == 'der': 35 | return OpenSSL.crypto.FILETYPE_ASN1 36 | else: 37 | return OpenSSL.crypto.FILETYPE_PEM 38 | 39 | def import_certificate(self, file, format='pem'): 40 | with open(file, "r") as f: 41 | self.cert = OpenSSL.crypto.load_certificate(self.__get_filetype(format), f.read()) 42 | 43 | def clone(self): 44 | self.key = OpenSSL.crypto.PKey() 45 | self.key.generate_key(self.cert.get_pubkey().type(), self.cert.get_pubkey().bits()) 46 | self.cert.set_pubkey(self.key) 47 | self.cert.sign(self.key,'sha256') 48 | 49 | def export_certificate(self, file, format='pem'): 50 | with open(file, "wb") as f: 51 | f.write(OpenSSL.crypto.dump_certificate(self.__get_filetype(format), self.cert)) 52 | 53 | def export_privatekey(self, file, format='pem'): 54 | with open(file, "wb") as f: 55 | f.write(OpenSSL.crypto.dump_privatekey(self.__get_filetype(format), self.key)) 56 | 57 | def main(): 58 | args = parse_args() 59 | 60 | certificate = Certificate(args.inputcert, args.inputformat) 61 | certificate.clone() 62 | certificate.export_certificate(args.outputcert, args.outputformat) 63 | certificate.export_privatekey(args.outputkey, args.outputformat) 64 | 65 | if __name__ == '__main__': 66 | main() 67 | -------------------------------------------------------------------------------- /templates/bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # template 4 | # 5 | # This is a template for bash scripts 6 | # 7 | # Author: Emanuel Duss 8 | # 9 | 10 | set -o errexit 11 | set -o nounset 12 | set -o pipefail 13 | 14 | _red="$(tput setaf 1)" 15 | _green="$(tput setaf 2)" 16 | _yellow="$(tput setaf 3)" 17 | _blue="$(tput setaf 4)" 18 | _orange="$(tput setaf 6)" 19 | _bold="$(tput bold)" 20 | _reset="$(tput sgr0)" 21 | 22 | print_usage(){ 23 | cat << EOI 24 | Usage: template [OPTION ...] 25 | 26 | Program: 27 | This is just a template 28 | 29 | Options: 30 | -a Option alice (default: alice) 31 | EOI 32 | } 33 | 34 | check_dependencies(){ 35 | local fail=0 36 | for command in "$@" 37 | do 38 | if ! hash "$command" &> /dev/null 39 | then 40 | echo_error "Command \"$command\" not found." 41 | fail=1 42 | fi 43 | done 44 | [[ "$fail" == 1 ]] && exit 1 45 | } 46 | 47 | echo_debug(){ echo "${_blue}[+] ${*}${_reset}" >&2; } 48 | echo_info(){ echo "${_green}[*] ${*}${_reset}" >&2; } 49 | echo_warning(){ echo "${_yellow}[!] ${*}${_reset}" >&2; } 50 | echo_error(){ echo "${_red}[#] ${*}${_reset}" >&2; } 51 | 52 | parse_arguments(){ 53 | ALICE="alice" 54 | 55 | while getopts ab: name 56 | do 57 | case $name 58 | in 59 | a) 60 | ${ALICE}="${OPTARG}" 61 | ;; 62 | h) 63 | print_usage 64 | exit 65 | ;; 66 | ?) 67 | print_usage >&2 68 | exit 1 69 | ;; 70 | esac 71 | done 72 | } 73 | 74 | check_preconditions(){ 75 | if [[ "$UID" != 0 ]] 76 | then 77 | echo_error "Program must be run as root." 78 | ABORT=1 79 | exit 1 80 | fi 81 | } 82 | 83 | # Always run exit_trap; only run exit_cleanup when set to 1 84 | CLEANUP="0" 85 | enable_cleanup(){ CLEANUP="1"; } 86 | 87 | exit_trap(){ 88 | echo 89 | echo_info "Stopping ..." 90 | 91 | [[ "${CLEANUP}" == "1" ]] && exit_cleanup 92 | } 93 | trap exit_trap EXIT 94 | 95 | cleanup(){ 96 | echo_info "Other stuff to clean up..." 97 | } 98 | trap cleanup EXIT 99 | 100 | log(){ 101 | echo "[*] $(date +"%F %T"): $@" 102 | } 103 | 104 | do_stuff(){ 105 | foo="${1:-foo}" 106 | echo "[OK] Foo is: $foo" 107 | echo "Haloo $DATETIME" 108 | 109 | echo_debug "This is a debug message. ($DATETIME)" 110 | echo_info "This is an info message." 111 | echo_warning "This is a warning message." 112 | sleep 1 113 | echo_error "This is an error message. ($DATETIME)" 114 | } 115 | 116 | main(){ 117 | check_dependencies jhead exiftool 118 | 119 | parse_arguments "$@" 120 | shift $((OPTIND - 1)) 121 | echo "Remaining arguments: $@" 122 | 123 | check_preconditions 124 | enable_cleanup 125 | 126 | if [[ -z "${1:-}" ]] 127 | then 128 | echo "\$1 is not set" 129 | fi 130 | 131 | do_stuff 1 2 3 132 | } 133 | 134 | main "$@" 135 | -------------------------------------------------------------------------------- /base16: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # base16 4 | # 5 | # Base16 encode/decode data. 6 | # 7 | # Author: Emanuel Duss 8 | # 9 | 10 | set -o errexit 11 | set -o nounset 12 | set -o pipefail 13 | 14 | print_usage(){ 15 | cat << EOI 16 | Usage: base16 [OPTION]... [FILE] 17 | Base16 (Hex) encode or decode FILE, or standard input, to standard output. 18 | With no FILE, or when FILE is -, read standard input. 19 | 20 | Options: 21 | -d decode data 22 | -i when decoding, ignore non-alphabet characters 23 | -w COLS wrap encoded lines after COLS character (default 76). 24 | Use 0 to disable line wrapping 25 | 26 | -h display this help and exit 27 | 28 | The data are encoded as described for the base16 alphabet in RFC 4648. 29 | When decoding, the input may contain newlines in addition to the bytes of 30 | the formal base64 alphabet. Use -i to attempt to recover from any other 31 | non-alphabet bytes in the encoded stream. 32 | EOI 33 | } 34 | 35 | check_dependencies(){ 36 | local FAIL=0 37 | local MISSING="" 38 | for tool in $@ 39 | do 40 | if ! hash "$tool" &> /dev/null 41 | then 42 | MISSING="$MISSING, $tool" 43 | FAIL=1 44 | fi 45 | done 46 | if [[ "$FAIL" == 1 ]] 47 | then 48 | echo "Missing dependency: ${MISSING/, }." 49 | exit 1 50 | fi 51 | } 52 | 53 | parse_arguments(){ 54 | WRAP_COLS="76" 55 | while getopts diw:h name 56 | do 57 | case $name 58 | in 59 | d) 60 | DECODE="1" 61 | ;; 62 | i) 63 | IGNORE_GARBAGE="1" 64 | ;; 65 | w) 66 | WRAP="1" 67 | WRAP_COLS="$OPTARG" 68 | ;; 69 | h) 70 | print_usage 71 | exit 72 | ;; 73 | ?) 74 | print_usage >&2 75 | exit 1 76 | ;; 77 | esac 78 | done 79 | } 80 | 81 | hex_to_binary(){ 82 | perl -e ' 83 | local $/; 84 | $i = <>; 85 | $i =~ s/[\r\n]//g; 86 | if ($i =~ /[^0-9a-fA-F]/){ 87 | print STDERR "base16: invalid input\n"; 88 | exit 1; 89 | } 90 | print pack "H*", $i;' 91 | } 92 | 93 | hex_to_binary_ignore_garbage(){ 94 | perl -e ' 95 | local $/; 96 | $i = <>; 97 | $i =~ s/[^0-9a-fA-F\n\r]//g; 98 | print pack "H*", $i' 99 | } 100 | 101 | binary_to_hex(){ 102 | # hexdump -ve '1/1 "%.2x"' 103 | perl -e ' 104 | local $/; 105 | print unpack "H*", <>' 106 | } 107 | 108 | main(){ 109 | check_dependencies perl 110 | 111 | parse_arguments "$@" 112 | shift $(($OPTIND - 1)) 113 | 114 | # Only one file is allowed 115 | if [[ "$#" > 1 ]] 116 | then 117 | echo -e "base16: extra operand '$1'" 118 | echo "Try 'base16 -h for more information." 119 | exit 1 120 | fi 121 | 122 | # Use STDIN (-) if $1 is not set 123 | FILE="${1:--}" 124 | 125 | # Decode 126 | if [[ -n "${DECODE:-}" ]] 127 | then 128 | if [[ -n "${IGNORE_GARBAGE:-}" ]] 129 | then 130 | cat "$FILE" | hex_to_binary_ignore_garbage 131 | else 132 | cat "$FILE" | hex_to_binary 133 | fi 134 | # Encode 135 | else 136 | if [[ "$WRAP_COLS" == "0" ]] 137 | then 138 | cat "$FILE" | binary_to_hex | tr -d '\n' 139 | else 140 | cat "$FILE" | binary_to_hex | fold -w "$WRAP_COLS" 141 | echo # Print newline at the end 142 | fi 143 | fi 144 | 145 | } 146 | 147 | main "$@" 148 | -------------------------------------------------------------------------------- /wecker: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # wecker 4 | # 5 | # Use your computer as an alarm clock 6 | # 7 | # Author: Emanuel Duss 8 | # 9 | 10 | NOW=`date +%s` 11 | 12 | PrintUsage() { 13 | echo "Usage: 14 | wecker option 15 | 16 | Options: 17 | set