27.2.15

Cronjobs aller Nutzer auflisten

Bevor es irgendwann verschwindet, möchte ich ein hier gefundenes Script für die Nachwelt erhalten.
Damit lassen sich alle Cronjobs sämtlicher Nutzer auflisten.

#!/bin/bash

# System-wide crontab file and cron job directory. Change these for your system.
CRONTAB='/etc/crontab'
CRONDIR='/etc/cron.d'

# Single tab character. Annoyingly necessary.
tab=$(echo -en "\t")

# Given a stream of crontab lines, exclude non-cron job lines, replace
# whitespace characters with a single space, and remove any spaces from the
# beginning of each line.
function clean_cron_lines() {
    while read line ; do
        echo "${line}" |
            egrep --invert-match '^($|\s*#|\s*[[:alnum:]_]+=)' |
            sed --regexp-extended "s/\s+/ /g" |
            sed --regexp-extended "s/^ //"
    done;
}

# Given a stream of cleaned crontab lines, echo any that don't include the
# run-parts command, and for those that do, show each job file in the run-parts
# directory as if it were scheduled explicitly.
function lookup_run_parts() {
    while read line ; do
        match=$(echo "${line}" | egrep -o 'run-parts (-{1,2}\S+ )*\S+')

        if [[ -z "${match}" ]] ; then
            echo "${line}"
        else
            cron_fields=$(echo "${line}" | cut -f1-6 -d' ')
            cron_job_dir=$(echo  "${match}" | awk '{print $NF}')

            if [[ -d "${cron_job_dir}" ]] ; then
                for cron_job_file in "${cron_job_dir}"/* ; do  # */ <not a comment>
                    [[ -f "${cron_job_file}" ]] && echo "${cron_fields} ${cron_job_file}"
                done
            fi
        fi
    done;
}

# Temporary file for crontab lines.
temp=$(mktemp) || exit 1

# Add all of the jobs from the system-wide crontab file.
cat "${CRONTAB}" | clean_cron_lines | lookup_run_parts >"${temp}" 

# Add all of the jobs from the system-wide cron directory.
cat "${CRONDIR}"/* | clean_cron_lines >>"${temp}"  # */ <not a comment>

# Add each user's crontab (if it exists). Insert the user's name between the
# five time fields and the command.
while read user ; do
    crontab -l -u "${user}" 2>/dev/null |
        clean_cron_lines |
        sed --regexp-extended "s/^((\S+ +){5})(.+)$/\1${user} \3/" >>"${temp}"
done < <(cut --fields=1 --delimiter=: /etc/passwd)

# Output the collected crontab lines. Replace the single spaces between the
# fields with tab characters, sort the lines by hour and minute, insert the
# header line, and format the results as a table.
cat "${temp}" |
    sed --regexp-extended "s/^(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(.*)$/\1\t\2\t\3\t\4\t\5\t\6\t\7/" |
    sort --numeric-sort --field-separator="${tab}" --key=2,1 |
    sed "1i\mi\th\td\tm\tw\tuser\tcommand" |
    column -s"${tab}" -t

rm --force "${temp}"

26.2.15

Serversicherheit

Nützliche Tools, die dabei helfen, einen Überblick über Hacking-Versuche zu behalten und solche zu verhindern.

fail2ban

apt-get install fail2ban

Testen von Filtern:
fail2ban-regex "/var/log/apache2/error.log" /etc/fail2ban/filter.d/apache-noscript.conf
Status:

fail2ban-client status


logwatch

apt-get install logwatch

Unter /etc/cron.daily/00logwatch befindet sich nun ein neuer täglicher Cronjob:


#!/bin/bash

#Check if removed-but-not-purged
test -x /usr/share/logwatch/scripts/logwatch.pl || exit 0
#execute
/usr/sbin/logwatch --output mail --mailto me@home.de --format html

#Note: It's possible to force the recipient in above command
#Just pass --mailto address@a.com instead of --output mail
Mit --mailto Mail an den Admin-Emailaccount senden.


debian-goodies

apt-get install debian-goodies
Mit checkrestart kann man testen, ob es noch Prozesse gibt, die auf alte, inzwischen aber aktualisiert Bibliotheken zugreifen.

checkrestart

Offene Ports & Prozesse anzeigen

lsof -i

5.1.15

Deutsches Datum mit PHP - Anpassung von setlocale

Problem:

Trotz setlocale(LC_ALL, 'de_DE') wollte die Ausgabe eines deutschen Datums nicht gelingen.

Schuld war der nicht unter diesem Namen installierte  deutsche Zeichensatz.

Unter Linux lässt sich mittels

locale -a

anzeigen, welche Zeichensätze installiert sind.

Dort aufgeführt war u.a.

de_DE.utf8


Die Änderung

setlocale(LC_ALL, 'de_DE.utf8');

erbrachte die Lösung!

Schnell überprüfen lässt sich das durch die Ausgabe von

print(strftime('%A %B'));


27.12.14

Aircrack-ng auf dem Raspberry PI - Teil 2

Nachdem ich den ersten Versuch aus Kompatibilitätsgründen abbrechen musste, folgt nach Bestellung des TP-Link TL-WN722N 150Mbps High Gain Wireless USB Adapter der nächste.

Vorher hatte ich sowohl den TP-Link TL-WN823N WLAN USB-Adapter als auch einen EDUP EP-n1557 300Mbps-Wireless-USB-Adapter erfolglos getestet.
Die verwendeten Chipsätze ließen keinen Monitor-Mode zu :(


Nun aber:
Nach dem Anstecken meldet sich der Adapter mittels lsusb mit:
Bus 001 Device 004: ID 0cf3:9271 Atheros Communications, Inc. AR9271 802.11n
(Die nächsten Befehle immer als root absetzen!)

Mit

airmon-ng start wlan0

schalte ich in den Monitor-Mode.

Ausgabe:

Found 6 processes that could cause trouble.
If airodump-ng, aireplay-ng or airtun-ng stops working after
a short period of time, you may want to kill (some of) them!
-e
PID    Name
1683    ifplugd
1703    ifplugd
1709    ifplugd
1742    wpa_supplicant
1856    wpa_cli
2438    dhclient
Process with PID 1703 (ifplugd) is running on interface wlan0
Process with PID 1742 (wpa_supplicant) is running on interface wlan0
Process with PID 1856 (wpa_cli) is running on interface wlan0


Interface    Chipset        Driver

wlan0        Atheros AR9271    ath9k - [phy0]
                (monitor mode enabled on mon0)
 Danach kann ich nach Wlans in meinem Bereich scannen mit

airodump-ng mon0



Aircrack-ng mit dem Raspberry - Teil 1

Ziel: Aufbau eines Hotspots, welches als MITM snifft "ohne Ende".
Hardware: Raspberry Pi Model B
System: Wheezy

apt-get -y install libssl-dev
apt-get install libnl-genl-3-dev

Neueste Version von Aircrack holen, entpacken  und installieren:
wget http://download.aircrack-ng.org/aircrack-ng-1.2-rc1.tar.gz
tar -zxvf aircrack-ng-1.2-rc1.tar.gz
cd aircrack-ng-1.2-rc1/
make 
make install

Zunächst gab es eine Fehlermeldung:

/usr/bin/ld: cannot find -lnl-genl-3
Hier half (komischerweise) ein erneutes Installieren der o.a. libnl Bibliothek (oder ich hatte mich vertippt?).

 Dann ein Update anschieben:

airodump-ng-oui-update

iw installieren:

apt-get -y install iw

iw dev wlan0 interface add mon0 type monitor
Und hier kam der Break! Meine USB Wlan-Karte konnte nicht in den Monitor Mode geswitcht werden, da der verwendete Chipsatz RTL 8192CU.

Mit einer anderen Wlan-Karte geht es weiter und zwar hier.....

22.12.14

Ubuntu 14.04 und Virtualbox - Auflösung nur 640*480 (VGA)

Nach Installation von Ubuntu 14.04.x konnte ich nur die VGA-Auflösung wählen.

Lösung: Suche nach Treiber im Dashboard


Dann Installation von x86 virtualization solution....


Danach Neustart und schwupps! Löpt! :)


22.11.14

Wlan mit dem Raspberry

Auf meinem Raspberry läuft Debian Wheezy und mit Hilfe der Wiki-Seite von Debian wollte ich ein (billig erworbenes) Wlan-Modul installieren.

Das hat nicht geklappt, warum auch immer.
Doch hier habe ich eine Anleitung gefunden, die sofort funktioniert hat.
Sehr schön!


WPA-Passphrase erstellen mit  wpa_passphrase <SSID des Routers> und den Inhalt der Ausgabe einfügen in

/etc/wpa_supplicant/wpa_supplicant.conf


In die Datei /etc/network/interfaces folgendes hinzugefügt:

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
 Nach ifdown wlan0 und ifup wlan0 hat es funktioniert!


Next step:  Konfigurieren des PI als "Universal Hotspot"

 

Openhab und Ecoflow Max - API Anbindung

 Ich wollte die neu erworbene Powerstation in Openhab einbinden, um den aktuellen Status (Ladestand etc.) über Openhab auswerten zu können. ...