Table of Contents
GnuPG
Einrichten
Unter debian gnupg (+gnupg2) installieren
Key generieren:
# gpg –gen-key
alle defaut-Werte übernehmen.
Keys anzeigen:
# gpg –list-key
Pub-Key ausgeben: (ASCII auf STOUT)
# gpg –armor –export <UID>
Pub-Key in Datei schreiben:
# gpg –output <file_name> –export <UID>
Symmetrisches Verfahren
Eine Datei wird mit einem beliebigen passphrase verschlüsselt und kann mit dem gleichen passphrase wieder entschlüsselt werden.
Datei verschlüsseln:
# gpg –output <verschl-dateiname> –symmetric <dateiname>
Beispiel: die Datei gehalt.pdf soll verschlüsselt werden
# gpg –output gehalt.pgp –symmetric gehalt.pdf
Enter passphrase: *
Repeat passphrase: *
Danach hat man eine verschlüsselte Datei gehalt.pgp die auch kompriemiert wurde.
Datei entschlüsseln:
# gpg –output <dateiname> –decrypt <verschl-dateiname>
Beispiel: die Datei gehalt.pgp soll wieder entschlüsselt werden
# gpg –output gehalt.pdf –decrypt gehalt.pgp
Enter passphrase: *
Danach hat man wieder die originale Datei gehalt.pdf.
OpenSSL
Verschlüsseln
openssl enc -e -aes256 -in file -out file.enc
Entschlüsseln
openssl enc -d -aes256 -in file.enc -out file
binary-File in ascii-File umwandeln
openssl enc -base64 -in file.bin -out file.ascii
ascii-File in binary-File umwandeln
openssl enc -d -base64 -in file.ascii -out file.bin
User Logging
Herausfinden wann sich welcher User am System angeledet hat und wie lange er angemeldet war.
Login und Logout informationen stehen in der Datei /var/log/wtmp in einem binärformat.
Zum auslesen der Daten benötigt man spezielle Programme wie w; who; last; lastlog oder ac.
Ist die Datei /var/log/wtmp nicht vorhanden, so wird auch nichts mitgeloggt.
Ein touch /var/log/wtmp aktiviert das Userlogging.
Bei Debian 5.0 sind die Programme w; who; last; lastlog schon dabei, ac muss evtl. nachinstalliert werden.
Wann hat sich der User angemeldet
lastlog -u <user>
Wie lange war der User angemeldet
Die Dauer einer User-Sitzung kann mit dem Programm ac ausgelesen werden.
Falls ac nicht installiert ist dann muss es nachinstalliert werden:
apt-get install acct
Danach kann man verschieden Abfragen starten.
ac -d <user>
zeigt die Sitzungsdauer eines Users an.
Keypas
install xclip
sap ( a | c | d | upmwk | x ) <search-string>
sap ( in | ls )
a = upmwk -> u = user, p = pass, m = mail, w = website, k = kommentar
x = output user + website + hidden pass
c = change pass
d = delete item
in = input new item
ls = list content
#!/bin/bash
set +o history
unset pas || exit 1
function savedat {
cp /home/.pas4 /home/.pas5
cp /home/.pas3 /home/.pas4
cp /home/.pas2 /home/.pas3
cp /home/.pas1 /home/.pas2
cp /home/.pas /home/.pas1
}
function datin {
echo "user:"
read user
echo "pass:"
read pass
echo "mail:"
read mail
echo "web:"
read web
echo "kommentar:"
read komm
}
function out_check () {
exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -pass fd:3|grep -i $1|cut -d\| -f1,3-|sed 's/|/ | /g'
if [ `exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -pass fd:3|grep -i $1|cut -d\| -f1|wc -l` -ne 1 ]; then
unset pas
echo
echo " Nur eine Zeile !"
exit 0
fi
}
if [ $1 = in ]; then
savedat
datin
read -s pas
exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -out /tmp/pas.txt -pass fd:3
if [ $(file --mime-type -b /tmp/pas.txt) == "text/plain" ]; then
chmod 600 /tmp/pas.txt
echo "$user|$pass|$mail|$web|$komm">>/tmp/pas.txt
exec 3<<<"$pas"; openssl enc -aes256 -in /tmp/pas.txt -out /home/.pas -pass fd:3
rm /tmp/pas.txt
unset pas
exit 0
fi
rm /tmp/pas.txt
unset pas
fi
if [ $1 = ls ]; then
read -s pas
exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -pass fd:3|cut -d\| -f1,3-|sed 's/|/ | /g'
unset pas
exit 0
fi
if [ -z "$2" ]; then
unset pas
exit 0
fi
read -s pas
if [ $1 = d ]; then
savedat
out_check $2
echo
read -p " Delete ? [y/n] " -n 2 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -out /tmp/pas.txt -pass fd:3
chmod 600 /tmp/pas.txt
delnum=`cat -n /tmp/pas.txt|grep -i $2|awk '{print $1}'`
cat /tmp/pas.txt|sed "$delnum d">/tmp/pas.tmp
chmod 600 /tmp/pas.tmp
rm /tmp/pas.txt
exec 3<<<"$pas"; openssl enc -aes256 -in /tmp/pas.tmp -out /home/.pas -pass fd:3
rm /tmp/pas.tmp
unset pas
exit 0
fi
unset pas
exit 0
fi
if [ $1 = c ]; then
savedat
out_check $2
echo
read -p " Change Password ? [y/n] " -n 2 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
read -s -p " Input Password "
ps1=$REPLY
echo
read -s -p " Repeat Password "
ps2=$REPLY
if [ $ps1 == $ps2 ]; then
item1=`exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -pass fd:3|grep -i $2|cut -d\| -f1`
item2=`exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -pass fd:3|grep -i $2|cut -d\| -f3-`
exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -out /tmp/pas.txt -pass fd:3
chmod 600 /tmp/pas.txt
echo "$item1|$ps2|$item2">>/tmp/pas.txt
delnum=`cat -n /tmp/pas.txt|grep -i $2|head -1|awk '{print $1}'`
cat /tmp/pas.txt|sed "$delnum d">/tmp/pas.tmp
chmod 600 /tmp/pas.tmp
rm /tmp/pas.txt
exec 3<<<"$pas"; openssl enc -aes256 -in /tmp/pas.tmp -out /home/.pas -pass fd:3
rm /tmp/pas.tmp
echo
fi
fi
unset pas
exit 0
fi
i=$1
if [ $i = a ]; then
i="upmwk"
fi
l=${#i}
for ((k=0; k<=$l-1; k++))
do
if [ ${i:$k:1} = u ]; then
exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -pass fd:3|grep -i $2|cut -d\| -f1
elif [ ${i:$k:1} = p ]; then
exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -pass fd:3|grep -i $2|cut -d\| -f2
elif [ ${i:$k:1} = m ]; then
exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -pass fd:3|grep -i $2|cut -d\| -f3
elif [ ${i:$k:1} = w ]; then
exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -pass fd:3|grep -i $2|cut -d\| -f4
elif [ ${i:$k:1} = k ]; then
exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -pass fd:3|grep -i $2|cut -d\| -f5
elif [ ${i:$k:1} = x ]; then
exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -pass fd:3|grep -i $2|cut -d\| -f1
exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -pass fd:3|grep -i $2|cut -d\| -f4
# sleep 20
for i in 10 9 8 7 6 5 4 3 2 1 0; do echo -ne " $i\033[0K\r"; sleep 1; done
echo "***"
exec 3<<<"$pas"; openssl enc -d -aes256 -in /home/.pas -pass fd:3|grep -i $2|cut -d\| -f2|xclip
# sleep 20
for i in 10 9 8 7 6 5 4 3 2 1 0; do echo -ne " $i\033[0K\r"; sleep 1; done
echo " "|xclip
fi
done
unset pas