Blog


My .bashrc

Jul 18, 2018 | 3 minutes read

Tags: bash, dotfiles, htb, qol

Here is my .bashrc. Mostly it’s just functions and aliases I’ve accumulated or written over time that are useful to me.

My PS1

PS1="\n\[\033[1;37m\]\342\224\214($(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]\h'; else echo '\[\033[01;34m\]\u@\h'; fi)\[\033[1;37m\])\$([[ \$? != 0 ]] && echo \"\342\224\200(\[\033[0;31m\]\342\234\227\[\033[1;37m\])\")\342\224\200(\[\033[1;34m\]\@ \d\[\033[1;37m\])\[\033[1;37m\]\n\342\224\224\342\224\200(\[\033[1;32m\]\W\[\033[1;37m\])\342\224\200> \[\033[0m\]"

My aliases

alias lt='ls -altr --color=auto'
alias psg='ps -ef | egrep -i '
alias ..='cd ..'
alias ...='cd ../..'
alias grep='egrep --color -i '
alias serve='python3 -m http.server'
alias wanip='dig +short myip.opendns.com @resolver1.opendns.com'

Setup my environment to use a .pythonrc file

export PYTHONSTARTUP=$HOME/.pythonrc.py

The contents of my .pythonrc.py. You can add whatever imports you choose to this and they’ll be pre-loaded when you fire up your interpreter.

import sys
from pathlib import Path
from pprint import pprint

print('loaded:', [x for x in globals().keys() if not x.startswith('_')])

grep through netstat or ss output, whichever is appropriate

nsg() {
    if [[ $(which netstat) ]]
    then
        netstat -pan | egrep -i "${1}"
    else
        ss -pan | egrep -i "${1}"
    fi
}

Get my HTB ip

myip() {
    echo $(ip a s tun0 | grep -w inet | awk '{print $2}' | awk -F/ '{print $1}')
}

JTR with .pot removal

john() {
    if [[ -f ~/.john/john.pot ]]
    then
        rm ~/.john/john.pot
    fi
    /usr/sbin/john hash --wordlist=/usr/share/wordlists/rockyou.txt
}

IPv4 socat listener for callbacks

socat-listen() {
    socat file:`tty`,echo=0,raw tcp4-listen:$1
}

Sane defaults for gobuster

function gobust() {
    if [[ -z $2 ]]; then
        wordlist=/usr/share/wordlists/SecLists/Discovery/Web-Content/common.txt
    else
        wordlist=$2
    fi
    if [[ "${1}" == "-h" || "${1}" == "--help" ]]; then
        echo gobuster -u $1 -w $wordlist -s '200,204,301,302,307,403,500' -e -t 20 | tee gobuster.$1.out
    else
        gobuster -u $1 -w $wordlist -s '200,204,301,302,307,403,500' -e -t 20 | tee gobuster.$1.out
    fi
}

Quick listener for a windows shell

winshell() {
    msfconsole -r <(echo "use multi/handler
    set payload windows/shell/reverse_tcp
    set lhost tun0
    set lport $1
    exploit -j")
}

Sane defaults for onetwopunch

onetwopunch() {
    /opt/onetwopunch.sh -t <(echo "${1}") -p all -i tun0 -n '-sV --script=default -oN nmap'
}

masscan defaults for both TCP and UDP

massudp() {
    masscan -e tun0 --ports U:0-65535 -oL "scan.${1}.udp" --rate 700 "${1}"
}
masstcp() {
    masscan -e tun0 -p0-65535 --rate 700 -oL "scan.${1}.tcp" "${1}"
}

nikto defaults that conform to my workflow

nikto() {
    /usr/bin/nikto -host "${1}" | tee nikto."${1}".out
}

Dump shellcode from a compiled binary or object file

dump-shellcode() {
    accum=0
    sentry="No nulls found"
    for i in $(objdump -d "${1}" | grep "^ " | cut -f 2)
    do
        echo -n '\x'$i
        accum=$(( accum + 1 ))
        if [[ "${i}" = "00" ]]
        then
            sentry="You have nulls, try again"
        fi
    done
    echo && echo "length of shellcode: $accum"
    echo "${sentry}"
}

Assemble and link .nasm/.asm files

assemble() {
    name="${1}"
    base="$(basename ${name} .nasm)"
    base="$(basename ${base} .asm)"
    nasm -f elf64 "${name}" -o "${base}".o
    ld "${base}".o -o "${base}"
}

Locate syscall number

findsyscall() {
   egrep --color=auto --color -i "${1}" /usr/include/x86_64-linux-gnu/asm/unistd_64.h
}

Setup bash command logging via syslog and easily search it

-------- /etc/bash.bashrc --------
export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$(whoami):$(pwd) [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"'

----------------------------------

-------- /etc/rsyslog.d/bash.conf --------
template(name="add-year" type="string" string="%timereported:::date-month% %timereported:::date-day% %timereported:::date-year% %timereported:::date-hour%:%timereported:::date-minute%:%timereported:::date-second% %HOSTNAME% %app-name% %msg%\n")

local6.*    /var/log/bash-commands.log;add-year
------------------------------------------

-------- /etc/logrotate.d/rsyslog --------
/var/log/bash-commands.log
{
    rotate 5200
    copy
    weekly
    missingok
    notifempty
    postrorate
        invoke-rc.d rsyslog rotate > /dev/null && /bin/cat /dev/null > /var/log/bash-commands.log
    endscript
    create 0644
}
-------------------------------------------

sudo systemctl restart rsyslog

-------- ~/.bashrc --------
hsg() { 
    strings -a /var/log/bash-commands.log* | egrep -i "${1}" | sort -k 1.1n -k 2.1n | uniq 
}
-------------------------------------------


comments powered by Disqus