Sometimes people put files into my home directory without giving me the ownership. This Gist fixes the problem.
Dienstag, 13. September 2016
Montag, 5. September 2016
Freitag, 2. September 2016
Replace all editors with Emacs client
I have to work on a Ubuntu system having installed some text editors I would never use. Instead I like to use Emacs client, because I have Emacs always running.
Graphical desktops like Gnome are believed to be user friendly, but it took me more than a hour to replace the useless editors with Emacs client. First it is necessary to remove all existing MIME type associations. Next it is necessary to define a new application. And finally new MIME type associations have to be set. This is done in two files in the directory $HOME/.local/share/applications.
- mimeapps.list
- This file defines your own associations overriding the system defaults.
- emacsclient.desktop
- This is a newly defined application necessary to execute Emacs client.
I have cloned the already existing Emacs application to define the Emacs client application. The original Emacs application definition is stored in /usr/share/applications/emacs24.desktop. This is the application definition.
[Desktop Entry] Name=Emacs Client Type=Application Terminal=false MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++; Exec=emacsclient -n %F Categories=Utility;TextEditor;Development; Comment= Keywords=editor Icon=/usr/share/icons/hicolor/scalable/apps/emacs24.svg
Now it is necessary to override the existing MIME type associations. This is done in the section "Default Applications" of the file mimeapps.list.
[Default Applications] application/x-shellscript=emacsclient.desktop text/english=emacsclient.desktop text/plain=emacsclient.desktop text/x-c++=emacsclient.desktop text/x-c++hdr=emacsclient.desktop text/x-c++src=emacsclient.desktop text/x-c=emacsclient.desktop text/x-chdr=emacsclient.desktop text/x-csrc=emacsclient.desktop text/x-java=emacsclient.desktop text/x-makefile=emacsclient.desktop text/x-moc=emacsclient.desktop text/x-pascal=emacsclient.desktop text/x-tcl=emacsclient.desktop text/x-tex=emacsclient.desktop
And next all already existing associations have to be removed. This is done in the section "Removed Associations" of the same file.
[Removed Associations] application/x-shellscript=emacs24.desktop text/english=emacs24.desktop text/plain=emacs24.desktop;gedit.desktop;leafpad.desktop text/x-c++=emacs24.desktop text/x-c++hdr=emacs24.desktop text/x-c++src=emacs24.desktop text/x-c=emacs24.desktop text/x-chdr=emacs24.desktop text/x-csrc=emacs24.desktop text/x-java=emacs24.desktop text/x-makefile=emacs24.desktop text/x-moc=emacs24.desktop text/x-pascal=emacs24.desktop text/x-tcl=emacs24.desktop text/x-tex=emacs24.desktop
The MIME type text/plain had three associations separated by semicolon. After this modifications the file manager PCManFM does not show any useless but only one useful program in the context menu.
Montag, 11. Januar 2016
Compile Git on Solaris 10
To compile Git 2.7.0 on Solaris the Makefile must be changed to use gcc
CC = gcc
After that Git compiles, when I disable gettext, iconv and Tcl/Tk. I did not need curl but it seems to work.
NO_GETTEXT=1 NO_ICONV=1 NO_TCLTK=1 CURLDIR=/usr/local \ gmake prefix=/my/git install
Freitag, 8. Januar 2016
Diablo III Beta 2.4 PTR: Delseres Opus Magnum
Normalerweise bin ich kein Freund von Online-Services, die einem den Eindruck vermitteln, sie würden die tollste Erfindung seit geschnitten Brot sein, obwohl sie nur mit ein paar OpenSource-Tools zusammengeschustert sind. Aber in diesem Fall muss ich eine Ausnahme machen. Wenn man "mal schnell" ein Video zu einer animierten GIF-Grafik machen will, ist Ezgif.com ein prima Webseite. Man sollte natürlich tunlichst nur völlig öffentliche Videos dort hoch laden.
Das folgende GIF meiner Zauberin Horima aus der Diablo III PTR Beta 2.4 ist mit Hilfe des Dienstes entstanden. Aufgenommen habe ich mit OBS. Ezgif hat konvertiert, zugeschnitten und skaliert. Und mit Gimp habe ich das Fine-Tuning der Frames gemacht, damit die Animation sauber loopt.
Es ist meine erste Melee-Sorc seit Diablo I, die wirklich funktioniert. Alle Zauberinnen, die ich bislang geskillt habe, mussten sich schön weit von den Gegnern fernhalten. Auch die Experimente mit dem Sturmschild in Diablo II waren nicht wirklich effektiv. Aber mit dem 2.4er Patch hat Blizzard endlich mal ein Set mit ein paar praktischen legendären Ergänzungen geschaffen, mit denen man sich auch als Zauberin an die Gegner ran trauen kann. Es ist das Set "Delseres Opus Magnum". Das Set an sich ist nicht neu.
Und der dazu gehörige Helm ist es auch nicht.
Aber die neuen beziehungsweise überarbeiteten Zusatzgegenstände haben es in sich. Da wäre zuerst dieser Ring, der eine Schadensreduktion von 60% bietet. Und damit nicht genug: außerdem castet er quasi ständig Frost-Nova. Der Ring zusammen mit dem Helm lassen alles um einen herum so gut wie zum Stillstand kommen.
Als weitere Unterstützung gibt es die folgende Armschiene, die die Schilde verdoppelt.
Aber so richtig genial sind erst die nächsten Teilchen. Fragment der Bestimmung gibt eine 50% erhöhte Angriffsgeschwindigkeit für Spektralklinge und eine Erhöhung des Schadens von 200%. Damit alleine wäre Spektralklinge schon super schnell. Aber es kommt noch besser.
Der folgende Gürtel gibt nochmal eine Erhöhung der Angriffsgeschwindigkeit von Primärfertigkeiten um 50%. Damit ist Spektralklinge 100% schneller und geht ab wie eine Nähmaschine.
Das alleine ist angesichts der 2000% Schadenserhöhung durch das Set schon recht knackig. Aber so richtig knallt es erst mit dem neuen Triumvirat. Der erhöht nämlich den Schaden von Arkankugel um satte 200%. Und das ist auch noch drei mal stapelbar. Zusammen mit der 100%igen Geschwindigkeitserhöhung von Spektralklinge hat man die drei Stapel quasi sofort.
Und wem das immer noch nicht reicht: es gibt noch ein Sahne-Häubchen: Instabiles Zepter. Das lässt Arkankugel doppelt explodieren und steigert zusätzlich noch den Schaden von Arkankugel um 65%. Zusammen mit den 600% vom Triumvirat und den 2000% vom Set knallt man damit alles um, was nicht bei drei auf den Bäumen ist.
Damit habe ich gerade relativ entspannt im Solo ein Level 60 Portal beendet. Zugegeben am Ende hat mich der Steinsänger mit seinem Sprungangriff ein paar mal umgehauen aber bis dahin war alles problemlos.
Ich bin mal gespannt, wie schnell die Items nach der Beta droppen. Die Zeiten des Überflusses dürften in Kürze vorbei sein.
T_T
Freitag, 11. Dezember 2015
Screencast an X11 window by keyboard events
Recently I had the requirement to generate a screen cast of a keyboard interaction. There are many full featured application for Windows or Linux to generate screen casts, but they generate often big MPEG files, because they capture 30 or 60 screens per second and use lossy compression algorithms to minimize the file size. This is fine for video games and OBS does a pretty fine job, I have used it recently myself to capture a Diablo III PTR 2.4 session. But all this is not necessary, if one wants to capture keyboard interactions.
Keyboard interaction is triggered by pressing any keys. On Linux running a X11 server xinput can be used to capture keyboard events. And the standard X11 tool xwd can capture a window. And the ImageMagic can be used to combine several images into an animated GIF. This makes it possible to illustrate a keyboard interaction by pretty small GIF images.
I wrote a simple tool called xscreencast, which implements the above idea. It is hosted on GitHub. I have used it to illustrate the difference of the cursor color of a terminal window and Emacs on Stackexchange. This are the screen casts generated by the Perl script.
This is the terminal.
And this is Emacs.
Automatically follow IFRAME wrapper in Google's image search
Google adds a wrapper around the search result of image searches. They say that this might add some kind of convenience, which is by no means obvious to me. I would say that this is just another way to monitor your internet usage.
In order to get rid of it, you need Tampermonkey, if you use Chrome. The following script automatically follows the IFRAME in the search result.
// ==UserScript==
// @name Follow IFRAME in Google image search
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @include *://images.google.*/imgres?*
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';
location.replace(document.querySelector('iframe').src)
By default Tampermonkey uses the @match option, which is quite limited, because it is not possible to match any top level domain. Instead of @match you have to use @include, which supports a more general globing.
Dienstag, 1. Dezember 2015
Selecting the schema of a Sqlite database
.schema to read the Schema of a database. This works fine, but of course it is not a valid SQL query. The following query returns the whole schema in one string and is a valid SQL query.
SELECT group_concat(sql, ';' || char(10)) || ';' FROM sqlite_master WHERE name NOT LIKE 'sqlite_%';
Mittwoch, 14. Oktober 2015
Using the last command in the Bash prompt
Today I had the idea that it might be useful to have the return value of the last command in the PUtty title. And next step is to put also the last command into the title.
The command history 1 prints the last command from the Bash history of commands. The Output is prefixed by a number and two spaces. The following Bash expression removes the prefix and prints just the command.
$(h=$(history 1);n=${h/% */};echo "${h#$n }")
First h is initialized with the whole history line. Then n is set to the remaining part of h after the longest match from the right up the a space is removed from h. And in the end h without the prefix stored in n is printed.
Donnerstag, 8. Oktober 2015
Limit the length of the path in a Bash prompt
It is possible to define the Bash prompt by setting the PS1 variable. A typical prompt definition is a combination of user name, host name and working directory:
# export PS1='\u@\h:\w\$ ' root@server:/tmp/aaa/bbb/ccc/ddd/eee/fff/ggg/hhh/jjj/kkk# ▉
But this makes it difficult to dive into really deep directory tries. If the directory gets longer than the width of the terminal, the prompt will span two lines. And if you have to use a limited terminal on a Solaris system, the screen gets totally messed.
For this situations it is possible to define the prompt in that way, that only the last directory is part of the prompt.
# export PS1='\u@\h:\W\$ ' root@server:kkk# ▉
But having only one directory is often not enough. If you have some source packages, each containing a src directory, it not possible any more to distinguish them.
The best solution for the problem would be to clip the path to a maximum length and indicate the clipping by some kind of special character. That can be done by the following prompt definition.
# export PS1='\u@\h:$(p=${PWD: -30};p=${p:+<$p};echo ${p:-$PWD})\$ '
root@server:<cc/ddd/eee/fff/ggg/hhh/jjj/kkk# ▉
The definition uses Bash's parameter expansion feature in three steps. First a variable p is defined and 30 characters of PWD are taken from the right. If PWD is less than 30 characters p is an empty string. Otherwise p is the clipped part of PWD. In the next step p gets prefixed with the '<' character, if it is set. Otherwise it will be still undefined. And in the last step either p will be printed, if it is set, or PWD, if p is still undefined. This means that either the clipped and prefixed part of PWD gets printed, if it is longer than 30 characters, or PWD is printed without any modifications.
Montag, 28. September 2015
Comparing SunOS patches
showrev -p |sed 's/^Patch: \([^ ]*\) .*/\1/'And the following Perl script takes the output of the above command from two different systems and compares the patches. The script assumes, that the patches on the second system are newer.
#! /usr/bin/perl use strict; use warnings; #showrev -p |sed 's/^Patch: \([^ ]*\) .*/\1/' sub max { my $max = shift; my $next = shift; return $max if not $next; unshift @_, $max > $next ? $max : $next; goto &max; } sub read_patches { my $file = shift; my $hash; while (<$file>) { s/\r?\n$//; my ($patch, $number) = split ('-'); push @{$hash->{$patch}}, $number; } return $hash; } my ($f1, $f2) = @ARGV; my ($fd1, $fd2); open $fd1, "<", $f1 || die "Can not open input file $f1, $!"; open $fd2, "<", $f2 || die "Can not open input file $f2, $!"; my ($p1, $p2); $p1 = read_patches ($fd1); $p2 = read_patches ($fd2); print $f1, ": ", scalar(keys %$p1), "\n"; print $f2, ": ", scalar(keys %$p2), "\n"; my ($p, $n1, $n2); foreach $p (sort keys %$p2) { $n1 = max(@{$p1->{$p}}); $n2 = max(@{$p2->{$p}}); if (!defined $n1 || $n1 < $n2) { print $p, ": ", (defined $n1 ? $n1 : "()"), " -> ", $n2, "\n"; } }
Sonntag, 6. September 2015
Windows-Schriften unter Linux verwenden
Wer unter Windows eine virtuelle Maschine verwendet, um Linux zu benutzen, kann sehr einfach die Windows-Schriften auch unter Linux verwenden. Dazu muss lediglich das Verzeichnis, in dem sich unter Windows die Schriften befinden als Shared-Folder für den Linux-Gast freigegeben werden. Die entsprechende Option sieht VirtualBox folgendermaßen aus.
Mit Hilfe des Namens kann das Verzeichnis unter Linux eingebunden werden. Dazu muss erst ein Mount-Point angelegt werden.
mkdir /usr/local/share/fonts/windows
Anschließend kann ein Eintrag in der fstab-Datei hinzugefügt werden, damit das Verzeichnis beim Start automatisch eingebunden wird.
echo fonts /usr/local/share/fonts/windows vboxsf ro,comment=systemd.automount 0 0 >> /etc/fstab
Wer sein System nicht neu starten will, muss jetzt das Verzeichnis manuell einbinden.
mount fonts
Abschließend muss der Font-Cache aktualisiert werden. Das kann je nach Anzahl der Fonts unter Windows etwas dauern.
fc-cache -fv
Jetzt stehen die Schriften im System zur Verfügung und können in den entsprechenden Programm ausgewählt werden. Zum Beispiel Tahoma für XFCE ...
... oder Emacs mit Lucida Console wie damals auf den SPARCstations unter OpenWindows.
Nachtrag
Emacs dazu zu überreden, dass das richtige Font-Hinting verwendet wird, gestaltet sich schwieriger als erwartet. Der Font-Dialog erlaubt es nicht, das Font-Hinting auszuwählen. Wer es trotzdem verwenden will darf nicht über die Emacs-Customization die Schrift auswählen. Statt dessen muss sie als X11-Resource in der Datei ~/.Xresources definiert werden. Für Lucida-Console auf einem 72dpi-Display sieht der Eintrag folgendermaßen aus:
Emacs.font: Lucida Console-14:antialias=true:hinting=true:autohint=false:hintstyle=3
Bei Systemen mit einer höheren Auflösung kann man auch kleinere Schrift-Größen wählen.
Mittwoch, 12. August 2015
Absätze durch Zeilenumbrüche in MS-Word ersetzen
Man kann sich das Problem vereinfachen, indem man die Suchen-und-Ersetzten-Funktion von Word nutzt. Ein Absatz ist in Word die Zeichen-Sequenz "^p" und ein Zeilenumbruch "^l". Damit kann man in dem betreffenden Code-Block alle Absätze durch Zeilenumbrüche ein einem Rutsch ersetzen.
Donnerstag, 8. Januar 2015
Langsamer ist besser!
#include <stdint.h> #include <stdio.h> #include <stdlib.h> int main (int argc, char **argv) { int8_t a, b, c; a = atoi (argv[1]); b = atoi (argv[2]); c = a + b; printf ("%d\n", c); return 0; }
Das Programm erwartet zwei Zahlen als Argument, addiert sie und gibt das Ergebnis aus. Es lässt sich ohne Fehler und Warnungen übersetzen.
cc -Wall -c -o c-speed.o c-speed.c cc c-speed.o -o c-speedUnd auf den ersten Blick scheint es ganz gut zu funktionieren.
$ ./c-speed 1 2 3Auf den zweiten Blick auch noch.
$ ./c-speed 10 20 30
Nur auf den dritten leider nicht mehr.
$ ./c-speed 100 200 44
Das Problem ist, dass für die Speicherung der Zahl 8 Bit verwendet wurden. Integer-Zahlen werden von heutzutage üblichen Architekturen als Zweierkomplement gespeichert. Das bedeutet, dass ein Bit für das Vorzeichen reserviert wird und die restlichen für die Zahl. Der Wertebereich ist somit -128 bis 127. Darin lässt sich eine 100 speichern aber keine 200 und erst recht keine 300.
Die binäre Darstellung der drei Zahlen sieht folgendermaßen aus.
| 100 ⇒ | 0 1 1 0 0 1 0 0 |
| 200 ⇒ | 0 1 1 0 0 1 0 0 0 |
| 300 ⇒ | 0 1 0 0 1 0 1 1 0 0 |
Auf der rechten Seite ist das niedrigstwertige Bit und auf der linken das höchstwertige Bit. Die führende Null gibt an, dass es sich um eine positive Zahl handelt. Für die 200 reichen somit 8 Bit nicht mehr aus, es werden 9 benötigt. Und für die 300 werden schon 10 benötigt.
C ist dieser Sachverhalt völlig egal. Statt den Überlauf zu erkennen wird einfach mit dem weiter gerechnet, was übrig bleibt nachdem die übergelaufenen Bits weggeschmissen wurden. Dafür gibt es auch eine hochtrabende Bezeichnung: rechnen in Restklassenringen. Und das ist etwas völlig anderes als das, was Schülern in Unter- und Mittelstufe als "Rechnen" beigebracht wird.
In diesem konkreten Fall bedeutet es, dass das neunte Bit der 200 und das neunte und zehnte Bit der 300 über Bord gehen. Allerdings kommt es bei der 300 dazu gar nicht erst, weil durch den Wegfall des neunten Bits die 200 negativ wird, weil jetzt das höchste Bit nicht mehr eine Null sondern eine Eins ist.
| 200 ⇒ | 0 1 1 0 0 1 0 0 0 | |
| 1 1 0 0 1 0 0 0 | ⇒ -56 |
Somit entsteht bei der Addition gar kein Überlauf, da C aus der Addition eine Subtraktion macht: 100 + (-56) = 44. Somit wäre erklärt wie C bei der Addition von 100 und 200 auf 44 kommt. Und da C keine Addition sondern eine Restklassen-Addition durchgeführt hat, hat es auch alles richtig gemacht. Dass weder das Restklassen-Ergebnis noch die Erklärung, was genau es denn ist, einem normal sterblichen Anwender irgend etwas bringen, der auf seinem Kontoauszug eine 44 liest, obwohl er gerade 200€ eingezahlt hat und zuvor noch 100€ auf dem Konto waren, dürfte offensichtlich sein.
Ein typischer C-Programmierer wird nun darauf hinweisen, dass man ja auch mehr Bits für die Speicherung von Zahlen verwenden kann. Die Zeiten, dass man mit Prozessoren auskommen musste, die nur 8 Bit verarbeiten konnten sind lange vorbei und somit könnte man zur Speicherung der Zahl int16_t oder int32_t oder int64_t verwenden. Schon int16_t würde für die Speicherung von 100, 200 und 300 völlig ausreichen, da für die 300 nur 10 Bit nötig waren.
Auf den ersten Blick erscheint das einleuchtend aber das ist nicht wirklich eine Lösung für das Problem. Das Problem ist lediglich aufgeschoben und aufgeschoben ist bekannter Weise nicht aufgehoben. Die Aufschiebung besteht darin, dass der Überlauf bei der Verwendung von int16_t nicht mehr bei Zahlen größer als 127 auftritt sondern bei Zahlen größer als 32767. Das Spielchen kann man jetzt weiter treiben und immer größere Wortbreiten verwenden.
| 8 Bit: | 127 |
| 16 Bit: | 32767 |
| 32 Bit: | 2147483647 |
| 64 Bit: | 9223372036854775807 |
| 128 Bit: | 170141183460469231731687303715884105727 |
| 256 Bit: | 57896044618658097711785492504343953926634992332820282019728792003956564819967 |
Die 256 Bit erscheinen auf den ersten Blick recht groß und man könnte auf die Idee kommen, die Wahrscheinlichkeit, dass es in einem Programm, das mit 256 Bit Zahlen arbeitet, zu einem Überlauf kommt, könne man jetzt wirklich vernachlässigen.
Allerdings sollte man sich klar machen, dass es durchaus Anwendungen gibt, bei denen längere Zahlen benötigt werden. Eine RSA-Verschlüsselung mit 256 Bit Zahlen ist heutzutage als lächerlich zu betrachten, da zur Zeit mindestens 2048 Bits benötigt werden, um einigermaßen sicher zu sein. Und ebenso wichtig dürfte der Sachverhalt sein, dass man nicht davon ausgehen darf, dass ein Programm in dem vom Programmierer vorgesehenen Zahlenbereich arbeitet. Jemand, der eine Sicherheitslücke in einer Software aufspüren will, wird selbstverständlich ein Programm gerade mit solchen Eingaben füttern, die außerhalb dessen liegen, was der Programmierer der Software ursprünglich bei der Planung und Entwicklung als normal angesehen hatte.
Das bedeutet, dass das typische Verhalten eines C-Programmierers, Zahlenüberläufe zu ignorieren, ein sehr großes Sicherheitsrisiko darstellt. Die Geschwindigkeit, die man dadurch erreicht, dass man einfach ungenau arbeitet, wird durch Fehler und Sicherheitsprobleme erkauft. Und somit ist die Aussage "C sei schnell" mehr ein Fluch als ein Segen.
Wenn man also Zahlenüberläufe wirklich vermeiden will, dann ist die logische Konsequenz, dass man eine Zahl nicht mehr in etwas speichern kann, das durch den Restklassenring der gerade zur Verfügung stehenden CPU beschränkt ist. Denn genau das macht C. Statt dessen muss man eine Zahl als eine sog. Bignum oder Big-Integer speichern. Das wiederum geht auch in C unter Verwendung der GMP-Bibliothek. Aber dadurch verliert man die sagenumwobene Geschwindigkeit von C, weil eine Zahl nicht mehr mit nur einem CPU-Befehl addiert werden kann. Statt dessen sieht die Rechnung mit Bignums folgendermaßen aus.
- Dekodierung der Zahl von der in der Bignum-Bibliothek gewählten Kodierung in eine für die verwendete CPU verständliche Darstellung.
- Durchführung der gewünschten Rechnung unter zu Hilfenahme von diversen von der CPU bereitgestellten Operationen.
- Codierung der Zahl in die von der Bignum-Bibliothek benötigte Form.
Wer also der Meinung ist, in C zu programmieren sei eine gute Idee, weil die Programme so schön schnell sind oder die Verwendung des Java-Typs int sei eine gute Idee, weil er so viel schneller als BigInteger ist, dem kann ich nur mein Beileid aussprechen. Die Schnelligkeit von C ist keine Eigenschaft der Sprache, sondern man bezahlt für sie in barer Münze. Heutzutage kann man Exploits wie geschnitten Brot kaufen. Wer also sicher programmieren will, sollte darauf Wert legen, dass seine Programmiersprache keine Werbung damit macht, wie schnell sie sei. Statt dessen gilt beim Programmieren wie in der 30-Zone vor dem Kindergarten:
Langsamer ist besser!
Mittwoch, 7. Januar 2015
Raspberry Pi ohne Bildschirm und Tastatur booten
Man benötigt für das Login über die serielle Schnittstelle ein speziell für den Raspberry Pi angebotenes serielles USB-Kabel. Ich habe meins für 8,80€ bei Reichelt bestellt. Es nennt sich dort "USB zu TTL für Raspberry Pi, 1,0 m" und die Artikelbezeichnung ist "RPI USB TTL". Man kann kein "gewöhnliches" RS232-USB-Kabel benutzen und die entsprechenden Adern verbinden, weil die Pegel der RS232-Schnittstelle für den GPIO-Port des Raspberry Pi den Tod bedeuten.
Wenn man den Raspi über das Kabel mit dem Computer verbindet, steckt man die rote Ader für die Stromversorgung praktischer weise erst mal nicht. Andernfalls würde er direkt booten und man könnte den Boot-Vorgang im Terminal nicht sehen, da Windows erst mal den Treiber für die serielle Schnittstelle installieren muss.
Wenn Windows den Treiber richtig installiert hat, taucht im Gerätemanager der entsprechende COM-Port mit der Nummer auf, die man für Putty benötigt.
In meinem Fall ist es COM15. Die serielle Schnittstelle des Raspi wird meist mit 115200 Baud betrieben und nicht wie früher üblich mit 9600 Baud. Wenn man in Putty den "Serial" "Connection type" auswählt, kann man COM-Port und Baud-Rate setzen.
Jetzt kann man dem Raspi mit dem roten Kabel seine Versorgungsspannung geben. Die vier Adern des seriellen Kabels müssen folgendermaßen angeschlossen werden
█ Rot: auf den äußeren beiden Beinen sind die 5 Volt Versorgungsspannung
█ Schwarz: das dritte Bein ist Ground
█ Weiß: das vierte Bein ist TX (GPIO 14)
█ Grün: und das fünfte Bein ist RX (GPIO 15)
Wenn man die Adern richtig gesteckt hat, fängt der Raspi direkt an zu booten.
In Putty kann man parallel verfolgen, wie die Boot-Meldungen durch rauschen. Dank der hohen Baud-Rate geht das angenehm schnell.
Und schließlich kann man sich über die serielle Schnittstelle auch anmelden, ohne dafür eine Tastatur oder einen Monitor bemühen zu müssen.
Hintergrund
Warum funktioniert das so wie oben beschrieben? Grundsätzlich funktioniert eine serielle Konsole an jedem System, das eine serielle Schnittstelle hat. Allerdings muss man jeder Komponente, die eine Ausgabe erzeugt oder Eingaben erwartet, separat mitteilen, dass sie die serielle Schnittstelle nutzen soll. Bei klassischen PC-Systemen sind das die folgenden gemäß der Reihenfolge, wie sie beim Boot aktiv sind:- BIOS: zum Beispiel Phoenix, AMI, OpenBIOS etc.
- Boot-Loader: zum Beispiel Grub, Syslinux etc.
- Kernel: zum Beispiel Linux.
- Konsole: zum Beispiel agetty aus der "util-linux"-Programm-Sammlung.
Beim Raspi mit Raspbian ist die Situation erfreulicher Weise anders und auch etwas einfacher, weil er weder ein interaktives BIOS noch einen interaktiven Boot-Loader hat. Somit muss man nur noch dem Kernel und der Konsole sagen, dass sie die serielle Schnittstelle verwenden sollen.
Der Kernel wird beim Raspi-Boot-Loader über die Datei "cmdline.txt" auf der SD-Karte parametrisiert. Nachdem das System gebootet ist, ist die SD-Karte unter dem Verzeichnis /boot gemountet:
pi@raspberrypi:~$ cat /boot/cmdline.txt dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwaitDer relevante Paramter ist console=ttyAMA0,115200. Die Syntax für den Parameter ist in der Linux-Kernel-Dokumentation zu finden. Das erste Argument ist das serielle Gerät und das zweite die Baud-Rate.
Die Linux-Konsole wird durch den ersten aller Prozesse also Init gestartet. Init wiederum wird durch die Datei /etc/inittab konfiguriert. In der Inittab stehen Programm-Aufrufe pro Runlevel. Der normale Runlevel ist bei Raspbian 2:
pi@raspberrypi:~$ runlevel N 2Dem entsprechend muss in der Inittab für Runlevel 2 ein Aufruf von getty konfiguriert sein:
pi@raspberrypi:~$ awk -F: '/^[^#]/ && $2~2' /etc/inittab id:2:initdefault: l2:2:wait:/etc/init.d/rc 2 ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now 1:2345:respawn:/sbin/getty --noclear 38400 tty1 2:23:respawn:/sbin/getty 38400 tty2 3:23:respawn:/sbin/getty 38400 tty3 4:23:respawn:/sbin/getty 38400 tty4 5:23:respawn:/sbin/getty 38400 tty5 6:23:respawn:/sbin/getty 38400 tty6 T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100Und dort ist der Aufruf auch in der letzten Zeile zu finden. Wichtig ist, dass überall die gleiche Baud-Rate verwendet wird, da man zum Zeitpunkt der Übergabe der serielle Schnittstelle vom Kernel an Getty in Putty schlecht die Baud-Rate ändern kann.
Wenn man den GPIO-Port 14 für was anderes wie zum Beispiel eine Strom-Trennung verwenden möchte, könnte man den Raspi auch über zwei klassische USB-Seriell-Adapter mit dem PC verbinden: einer käme in den PC und der andere in einen USB-Port des Raspis und verbunden würden die beiden über ein Null-Modem-Kabel. Damit das funktioniert muss im Kernel der passende Treiber für den USB-Seriell-Adapter sein und man müsste anstatt ttyAMA0 das entsprechende Gerät für den USB-Seriell-Adapter verwenden. Typischerweise wäre das ttyUSB0. Allerdings würde dies eine Anpassung am Standard-Raspbian-Image erfordern, was bedeutet, dass man unter Windows die zweite Partition der SD-Karte mounten muss, um dort die Inittab zu ändern. Unter Windows gehört der Schreib-Zugriff auf EXT4-Partitionen nicht zu den Standard-Funktionen. Von Paragon wird ein Tool angeboten, mit dem das möglich sein soll. Wie gut das funktioniert bleibt zu testen.
Dienstag, 30. Dezember 2014
Linphone auf dem Iphone für T-Online konfigurieren
Wer zwangsweise auf VoIP umgestellt wurde, hat die Möglichkeit auf dem Handy einen SIP-Client zu benutzen, um über die ehemals "Festnetz"-Nummer zu telefonieren. Wer dabei nicht von Google und Co belauscht werden will, benötigt einen Open-Source-SIP-Client, um sicher zu stellen, dass die Software keine Backdoors enthält. Linphone ist freie Software und auch für das Iphone verfügbar.
Leider funktioniert der Konfigurationsassistent nicht. Aber wenn man unter "Settings" die Option "Advanced account" aktiviert kann man die richtigen Daten eingeben.
| User name | Telefonnummer mit Ortsvorwahl und 0 aber ohne Landesvorwahl |
| User ID | T-Online-Nummer mit @t-online.de am Ende |
| Password | das Passwort, das auch für das Kundencenter benötigt wird |
| Domain | tel.t-online.de |
| Proxy | |
| Transport | TCP |
Leider geht TLS als Transport nicht, was sehr schwach ist, da so wahrscheinlich das T-Online-Passwort im Klartext über das Netz geht. So können unsere "befreundeten" Geheimdienste besser mitlesen. Naja drauf geschissen, für etwas Blabla wird es reichen.
Dienstag, 23. Dezember 2014
Use the right HOME directory in Cygwin
Cygwin knows a bind option in fstab, which makes it quite easy to have the right HOME directory in Cygwin. The following lines show how to set /home and /usr/local.
d:/Users /home none bind 0 0 e:/Cygwin-local /usr/local none bind 0 0
After restarting the Cygwin terminal mount shows the following output:
C:/cygwin64/bin on /usr/bin type ntfs (binary,auto) C:/cygwin64/lib on /usr/lib type ntfs (binary,auto) E:/Cygwin-local on /usr/local type ntfs (text,user,bind) C:/cygwin64 on / type ntfs (binary,auto) D:/Users on /home type ntfs (text,user,bind) C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto) D: on /cygdrive/d type ntfs (binary,posix=0,user,noumount,auto) E: on /cygdrive/e type ntfs (binary,posix=0,user,noumount,auto)
Volumen C is a SSD, volume D is a RAID-1 and volume E is a simple hard disk.
Sonntag, 23. November 2014
Limit the number of simultaneous SSH connections
Brute-force attacks on user passwords via SSH work, because SSH does not limit the number of simultaneous connections. If you use SSH and Screen to manage your host, you will most likely never need more than three connections.
- A connections for the Screen session.
- A connections to transfer files with SCP.
- And a spare connection, if your Screen connection hangs or you need another simultaneous file transfer.
This means that it is sufficient to allow three TCP SYN packets on port 22. The following command inserts the appropriate rule at the beginning of the Netfilter INPUT chain.
iptables -I INPUT 1 -p tcp --syn --dport 22 \
-m connlimit --connlimit-above 3 --connlimit-mask 32 \
-j DROP
Just another abuse joke
Yesterday my server was under attack by the following addresses.
- 62.210.141.172
- 62.210.172.143
- 62.210.172.206
A revers lookup of the addresses shows that they belong to poneytelecom.eu.
# for addr in 62.210.141.172 62.210.172.143 62.210.172.206; do dig -x $addr +short; done 62-210-141-172.rev.poneytelecom.eu. 62-210-172-143.rev.poneytelecom.eu. 62-210-172-206.rev.poneytelecom.eu.
Taking a look at the web page reveals an abuse link. I was impressed and gave it a try. I entered the IP addresses and the correct time. Next I entered my e-mail address the abuse type "Bruteforce" and pasted a copy of my ssh authentication log.
auth.info: Nov 22 17:04:22 sshd[2199]: Failed password for root from 62.210.172.206 port 50916 ssh2 auth.info: Nov 22 17:04:28 sshd[2199]: Failed password for root from 62.210.172.206 port 50916 ssh2 auth.info: Nov 22 17:04:33 sshd[2199]: Failed password for root from 62.210.172.206 port 50916 ssh2 auth.info: Nov 22 17:04:43 sshd[2218]: Failed password for root from 62.210.172.206 port 55633 ssh2 auth.info: Nov 22 17:04:50 sshd[2218]: Failed password for root from 62.210.172.206 port 55633 ssh2 auth.info: Nov 22 17:04:57 sshd[2218]: Failed password for root from 62.210.172.206 port 55633 ssh2 auth.info: Nov 22 17:05:07 sshd[2251]: Failed password for root from 62.210.172.206 port 60456 ssh2 auth.info: Nov 22 17:05:14 sshd[2251]: Failed password for root from 62.210.172.206 port 60456 ssh2 auth.info: Nov 22 17:05:20 sshd[2251]: Failed password for root from 62.210.172.206 port 60456 ssh2 auth.info: Nov 22 17:05:31 sshd[2271]: Failed password for root from 62.210.172.206 port 35897 ssh2 auth.info: Nov 22 17:05:38 sshd[2271]: Failed password for root from 62.210.172.206 port 35897 ssh2 auth.info: Nov 22 17:05:44 sshd[2271]: Failed password for root from 62.210.172.206 port 35897 ssh2 auth.info: Nov 22 17:05:52 sshd[2293]: Failed password for root from 62.210.172.206 port 39627 ssh2 auth.info: Nov 22 17:05:58 sshd[2293]: Failed password for root from 62.210.172.206 port 39627 ssh2 auth.info: Nov 22 17:06:02 sshd[2293]: Failed password for root from 62.210.172.206 port 39627 ssh2 auth.info: Nov 22 17:06:10 sshd[2315]: Failed password for root from 62.210.172.206 port 42566 ssh2 auth.info: Nov 22 17:06:16 sshd[2315]: Failed password for root from 62.210.172.206 port 42566 ssh2 auth.info: Nov 22 17:06:22 sshd[2315]: Failed password for root from 62.210.172.206 port 42566 ssh2 auth.info: Nov 22 17:06:30 sshd[2337]: Failed password for root from 62.210.172.206 port 55252 ssh2 auth.info: Nov 22 17:06:34 sshd[2337]: Failed password for root from 62.210.172.206 port 55252 ssh2 auth.info: Nov 22 17:06:38 sshd[2337]: Failed password for root from 62.210.172.206 port 55252 ssh2 auth.info: Nov 22 17:06:48 sshd[2354]: Failed password for root from 62.210.172.206 port 38336 ssh2 auth.info: Nov 22 17:06:55 sshd[2354]: Failed password for root from 62.210.172.206 port 38336 ssh2 auth.info: Nov 22 17:07:01 sshd[2354]: Failed password for root from 62.210.172.206 port 38336 ssh2 auth.info: Nov 22 17:07:11 sshd[2374]: Failed password for root from 62.210.172.206 port 53116 ssh2 auth.info: Nov 22 17:07:18 sshd[2374]: Failed password for root from 62.210.172.206 port 53116 ssh2 auth.info: Nov 22 17:07:24 sshd[2374]: Failed password for root from 62.210.172.206 port 53116 ssh2 auth.info: Nov 22 17:07:34 sshd[2397]: Failed password for root from 62.210.172.206 port 40920 ssh2 auth.info: Nov 22 17:07:40 sshd[2397]: Failed password for root from 62.210.172.206 port 40920 ssh2 auth.info: Nov 22 17:07:46 sshd[2397]: Failed password for root from 62.210.172.206 port 40920 ssh2 auth.info: Nov 22 17:07:56 sshd[2421]: Failed password for root from 62.210.172.206 port 55725 ssh2 auth.info: Nov 22 17:08:06 sshd[2421]: Failed password for root from 62.210.172.206 port 55725 ssh2 auth.info: Nov 22 17:08:12 sshd[2421]: Failed password for root from 62.210.172.206 port 55725 ssh2 auth.info: Nov 22 17:08:23 sshd[2444]: Failed password for root from 62.210.172.206 port 52929 ssh2 auth.info: Nov 22 17:08:29 sshd[2444]: Failed password for root from 62.210.172.206 port 52929 ssh2 auth.info: Nov 22 17:08:36 sshd[2444]: Failed password for root from 62.210.172.206 port 52929 ssh2 auth.info: Nov 22 17:08:47 sshd[2464]: Failed password for root from 62.210.172.206 port 48487 ssh2 auth.info: Nov 22 17:08:53 sshd[2464]: Failed password for root from 62.210.172.206 port 48487 ssh2 auth.info: Nov 22 17:08:59 sshd[2464]: Failed password for root from 62.210.172.206 port 48487 ssh2 auth.info: Nov 22 17:09:11 sshd[2494]: Failed password for root from 62.210.172.206 port 41285 ssh2 auth.info: Nov 22 17:09:16 sshd[2494]: Failed password for root from 62.210.172.206 port 41285 ssh2 auth.info: Nov 22 17:09:21 sshd[2494]: Failed password for root from 62.210.172.206 port 41285 ssh2 auth.info: Nov 22 17:09:32 sshd[2516]: Failed password for root from 62.210.172.206 port 34060 ssh2 auth.info: Nov 22 17:09:37 sshd[2516]: Failed password for root from 62.210.172.206 port 34060 ssh2 auth.info: Nov 22 17:09:43 sshd[2516]: Failed password for root from 62.210.172.206 port 34060 ssh2 auth.info: Nov 22 17:09:51 sshd[2537]: Failed password for root from 62.210.172.206 port 52864 ssh2 auth.info: Nov 22 17:09:56 sshd[2537]: Failed password for root from 62.210.172.206 port 52864 ssh2 auth.info: Nov 22 17:10:02 sshd[2537]: Failed password for root from 62.210.172.206 port 52864 ssh2 auth.info: Nov 22 17:10:13 sshd[2565]: Failed password for root from 62.210.172.206 port 41045 ssh2 auth.info: Nov 22 17:10:19 sshd[2565]: Failed password for root from 62.210.172.206 port 41045 ssh2 auth.info: Nov 22 17:10:24 sshd[2565]: Failed password for root from 62.210.172.206 port 41045 ssh2 auth.info: Nov 22 17:10:35 sshd[2593]: Failed password for root from 62.210.172.206 port 35403 ssh2 auth.info: Nov 22 17:10:41 sshd[2593]: Failed password for root from 62.210.172.206 port 35403 ssh2 auth.info: Nov 22 17:10:47 sshd[2593]: Failed password for root from 62.210.172.206 port 35403 ssh2 auth.info: Nov 22 17:10:58 sshd[2615]: Failed password for root from 62.210.172.206 port 37722 ssh2 auth.info: Nov 22 17:11:04 sshd[2615]: Failed password for root from 62.210.172.206 port 37722 ssh2 auth.info: Nov 22 17:11:11 sshd[2615]: Failed password for root from 62.210.172.206 port 37722 ssh2 auth.info: Nov 22 17:11:22 sshd[2638]: Failed password for root from 62.210.172.206 port 53056 ssh2 auth.info: Nov 22 17:11:28 sshd[2638]: Failed password for root from 62.210.172.206 port 53056 ssh2 auth.info: Nov 22 17:11:35 sshd[2638]: Failed password for root from 62.210.172.206 port 53056 ssh2 auth.info: Nov 22 17:11:46 sshd[2660]: Failed password for root from 62.210.172.206 port 43890 ssh2 auth.info: Nov 22 17:12:22 sshd[2688]: Failed password for root from 62.210.172.206 port 58024 ssh2 auth.info: Nov 22 17:12:27 sshd[2688]: Failed password for root from 62.210.172.206 port 58024 ssh2 auth.info: Nov 22 17:12:32 sshd[2688]: Failed password for root from 62.210.172.206 port 58024 ssh2 auth.info: Nov 22 17:12:39 sshd[2702]: Failed password for root from 62.210.172.206 port 34130 ssh2 auth.info: Nov 22 17:12:44 sshd[2702]: Failed password for root from 62.210.172.206 port 34130 ssh2 auth.info: Nov 22 17:12:48 sshd[2702]: Failed password for root from 62.210.172.206 port 34130 ssh2 auth.info: Nov 22 17:12:57 sshd[2718]: Failed password for root from 62.210.172.206 port 40606 ssh2 auth.info: Nov 22 17:13:04 sshd[2718]: Failed password for root from 62.210.172.206 port 40606 ssh2 auth.info: Nov 22 17:13:11 sshd[2718]: Failed password for root from 62.210.172.206 port 40606 ssh2 auth.info: Nov 22 17:13:21 sshd[2788]: Failed password for root from 62.210.172.206 port 48292 ssh2 auth.info: Nov 22 17:13:26 sshd[2788]: Failed password for root from 62.210.172.206 port 48292 ssh2 auth.info: Nov 22 17:13:31 sshd[2788]: Failed password for root from 62.210.172.206 port 48292 ssh2 auth.info: Nov 22 17:13:41 sshd[2814]: Failed password for root from 62.210.172.206 port 43521 ssh2 auth.info: Nov 22 17:13:47 sshd[2814]: Failed password for root from 62.210.172.206 port 43521 ssh2 auth.info: Nov 22 17:13:52 sshd[2814]: Failed password for root from 62.210.172.206 port 43521 ssh2 auth.info: Nov 22 17:14:02 sshd[2834]: Failed password for root from 62.210.172.206 port 43164 ssh2 auth.info: Nov 22 17:14:07 sshd[2834]: Failed password for root from 62.210.172.206 port 43164 ssh2 auth.info: Nov 22 17:14:13 sshd[2834]: Failed password for root from 62.210.172.206 port 43164 ssh2 auth.info: Nov 22 17:14:22 sshd[2854]: Failed password for root from 62.210.172.206 port 37908 ssh2 auth.info: Nov 22 17:14:27 sshd[2854]: Failed password for root from 62.210.172.206 port 37908 ssh2 auth.info: Nov 22 17:14:32 sshd[2854]: Failed password for root from 62.210.172.206 port 37908 ssh2 auth.info: Nov 22 17:14:42 sshd[2874]: Failed password for root from 62.210.172.206 port 56492 ssh2 auth.info: Nov 22 17:14:44 sshd[2874]: Failed password for root from 62.210.172.206 port 56492 ssh2 auth.info: Nov 22 17:14:50 sshd[2874]: Failed password for root from 62.210.172.206 port 56492 ssh2 auth.info: Nov 22 17:15:00 sshd[2889]: Failed password for root from 62.210.172.206 port 41655 ssh2 auth.info: Nov 22 17:15:05 sshd[2889]: Failed password for root from 62.210.172.206 port 41655 ssh2 auth.info: Nov 22 17:15:10 sshd[2889]: Failed password for root from 62.210.172.206 port 41655 ssh2 auth.info: Nov 22 17:15:21 sshd[2910]: Failed password for root from 62.210.172.206 port 34993 ssh2 auth.info: Nov 22 17:15:26 sshd[2910]: Failed password for root from 62.210.172.206 port 34993 ssh2 auth.info: Nov 22 17:15:32 sshd[2910]: Failed password for root from 62.210.172.206 port 34993 ssh2 auth.info: Nov 22 17:15:41 sshd[2933]: Failed password for root from 62.210.172.206 port 52663 ssh2 auth.info: Nov 22 17:15:44 sshd[2933]: Failed password for root from 62.210.172.206 port 52663 ssh2 auth.info: Nov 22 17:15:50 sshd[2933]: Failed password for root from 62.210.172.206 port 52663 ssh2 auth.info: Nov 22 17:15:58 sshd[2951]: Failed password for root from 62.210.172.206 port 35746 ssh2 auth.info: Nov 22 17:16:04 sshd[2951]: Failed password for root from 62.210.172.206 port 35746 ssh2 auth.info: Nov 22 17:16:11 sshd[2951]: Failed password for root from 62.210.172.206 port 35746 ssh2 auth.info: Nov 22 17:16:19 sshd[2973]: Failed password for root from 62.210.172.206 port 57551 ssh2 auth.info: Nov 22 17:16:25 sshd[2973]: Failed password for root from 62.210.172.206 port 57551 ssh2 auth.info: Nov 22 17:16:29 sshd[2973]: Failed password for root from 62.210.172.206 port 57551 ssh2 auth.info: Nov 22 17:16:37 sshd[2993]: Failed password for root from 62.210.172.206 port 40210 ssh2 auth.info: Nov 22 17:16:41 sshd[2993]: Failed password for root from 62.210.172.206 port 40210 ssh2 auth.info: Nov 22 17:16:47 sshd[2993]: Failed password for root from 62.210.172.206 port 40210 ssh2 auth.info: Nov 22 17:16:54 sshd[3019]: Failed password for root from 62.210.172.206 port 53521 ssh2 auth.info: Nov 22 17:16:59 sshd[3019]: Failed password for root from 62.210.172.206 port 53521 ssh2 auth.info: Nov 22 17:17:04 sshd[3019]: Failed password for root from 62.210.172.206 port 53521 ssh2 auth.info: Nov 22 17:17:11 sshd[3043]: Failed password for root from 62.210.172.206 port 33313 ssh2 auth.info: Nov 22 17:17:14 sshd[3043]: Failed password for root from 62.210.172.206 port 33313 ssh2 auth.info: Nov 22 17:17:19 sshd[3043]: Failed password for root from 62.210.172.206 port 33313 ssh2 auth.info: Nov 22 17:17:28 sshd[3062]: Failed password for root from 62.210.172.206 port 60962 ssh2 auth.info: Nov 22 17:17:33 sshd[3062]: Failed password for root from 62.210.172.206 port 60962 ssh2 auth.info: Nov 22 17:17:37 sshd[3062]: Failed password for root from 62.210.172.206 port 60962 ssh2 auth.info: Nov 22 17:17:45 sshd[3078]: Failed password for root from 62.210.172.206 port 43115 ssh2 auth.info: Nov 22 17:17:52 sshd[3078]: Failed password for root from 62.210.172.206 port 43115 ssh2 auth.info: Nov 22 17:17:58 sshd[3078]: Failed password for root from 62.210.172.206 port 43115 ssh2 auth.info: Nov 22 17:18:05 sshd[3096]: Failed password for root from 62.210.172.206 port 55068 ssh2 auth.info: Nov 22 17:18:09 sshd[3096]: Failed password for root from 62.210.172.206 port 55068 ssh2 auth.info: Nov 22 17:18:14 sshd[3096]: Failed password for root from 62.210.172.206 port 55068 ssh2 auth.info: Nov 22 17:18:20 sshd[3114]: Failed password for root from 62.210.172.206 port 59523 ssh2 auth.info: Nov 22 17:18:26 sshd[3114]: Failed password for root from 62.210.172.206 port 59523 ssh2 auth.info: Nov 22 17:18:32 sshd[3114]: Failed password for root from 62.210.172.206 port 59523 ssh2 auth.info: Nov 22 17:18:40 sshd[3130]: Failed password for root from 62.210.172.206 port 41482 ssh2 auth.info: Nov 22 17:18:46 sshd[3130]: Failed password for root from 62.210.172.206 port 41482 ssh2 auth.info: Nov 22 17:18:52 sshd[3130]: Failed password for root from 62.210.172.206 port 41482 ssh2 auth.info: Nov 22 17:19:01 sshd[3148]: Failed password for root from 62.210.172.206 port 59707 ssh2 auth.info: Nov 22 17:19:04 sshd[3148]: Failed password for root from 62.210.172.206 port 59707 ssh2 auth.info: Nov 22 17:19:08 sshd[3148]: Failed password for root from 62.210.172.206 port 59707 ssh2 auth.info: Nov 22 17:19:14 sshd[3165]: Failed password for root from 62.210.172.206 port 33131 ssh2 auth.info: Nov 22 17:19:18 sshd[3165]: Failed password for root from 62.210.172.206 port 33131 ssh2 auth.info: Nov 22 17:19:21 sshd[3165]: Failed password for root from 62.210.172.206 port 33131 ssh2 auth.info: Nov 22 17:19:26 sshd[3177]: Failed password for root from 62.210.172.206 port 53828 ssh2 auth.info: Nov 22 17:19:30 sshd[3177]: Failed password for root from 62.210.172.206 port 53828 ssh2 auth.info: Nov 22 17:19:33 sshd[3177]: Failed password for root from 62.210.172.206 port 53828 ssh2 auth.info: Nov 22 17:19:36 sshd[3186]: Failed password for root from 62.210.172.206 port 40026 ssh2 auth.info: Nov 22 17:19:39 sshd[3186]: Failed password for root from 62.210.172.206 port 40026 ssh2 auth.info: Nov 22 17:19:41 sshd[3186]: Failed password for root from 62.210.172.206 port 40026 ssh2
I did the same for the two other attacking addresses.
Next I got thre e-mails from noreply@online.net which tell me that I should confirm the abuse report. I did so and thought nice, it seems to work.
[Online] Abuse #38682 - mail confirmation for abuse on server ip address 62.210.172.206 ONLINE SAS Technical assistance BP 438 - 75366 Paris CEDEX 08 France Tel: +33 1 84 13 00 00 Fax: +33 899 173 788 (1.35 EUR / call then 0.34 EUR / min from a French landline) Subject : Abuse request Dear Sir or Madam, Thank you for your abuse request on server ip address 62.210.172.206. We have record it with reference A-38682. Please confirm your abuse using this address: https://console.online.net/en/account/abuses/confirm/38682/1416672261/a70bdf4c27fff2db6e16bf0a67ed4aa2 You will receive an answer from our customer or our abuse service in 24 to 48 hours delay after confirmation. If you have any questions, please contact our assistance https://console.online.net/assistance/ Best regards, -- The Online team
Fine so far, I thought.
But this morning I had a choking cough, because I made to mistake to check my e-mail while eating a bun. I got three masterpiece of incident resolution intelligence. This is one of them.
[Online] Abuse #38682 - abuse for server ip address 62.210.172.206 resolved ONLINE SAS Technical assistance BP 438 - 75366 Paris CEDEX 08 France Tel: +33 1 84 13 00 00 Fax: +33 899 173 788 (1.35 EUR / call then 0.34 EUR / min from a French landline) Subject : Abuse notification resolved Dear Sir or Madam, Your abuse number 38682 is now closed. Here is a comment left by our customer: ---------------------------------------------------------------- Why root account password will change by oneself? ---------------------------------------------------------------- If you have any questions, please contact our assistance https://console.online.net/assistance/ Best regards, -- The Online team
All the effort to implement a nice abuse workflow is rendered superfluous by a stupid bone-head user accepting a useless counter question having nothing to do with the attack and explaining even less.
Samstag, 22. November 2014
Ban assholes trying to hack SSH passwords.
Normally I do not care much about those assholes trying to hack my system by probing SSH passwords. But today a probing attack took so much resources, that my own session starts lagging. So I had to take a fly swap to smash the gadfly. Here is the swap.
#! /bin/bash ## ## Ban SSH password cracking attempts. ## ## Time-stamp: <2014-11-22 19:26:44 szi> ## set -eu FILE="$1"; shift IP='[0-9]\+\.[0-9]\+\.[0-9]\+.[0-9]\+' TZ=$(date '+%Y-%m-%d %H:%M:%S %z') # Search failed SSH logins. sed -n 's/.* sshd\[[0-9]*\]: Failed password .* \('"$IP"'\).*/\1/p' "$FILE" | # Count the number of failures. sort | uniq -c | # Select all addresses with more than 3 failures. awk '$1>3 {print $2}' | # Remove the already banned. grep -v -f <(iptables -n -L INPUT | awk '$1=="DROP" {print $4}') | # Report tee >(read LINE < <(xargs echo); echo "Banning: ${LINE:-none}" >&2) | # And ban the new assholes. xargs -i iptables -A INPUT -s '{}' -m comment --comment "$TZ" -j DROP
The script needs the file containing the SSH auth log as an argument and can be run in a cron job every five minutes. Each drop rule gets a time stamp. This makes it possible to remove old entries, if the INPUT chain gets too big.
Here is an example. Flush the INPUT chain:
# iptables -F INPUT
Run the script:
# banip /var/log/auth.log Banning: 103.41.124.12 122.225.109.211 122.225.97.75 122.225.97.97 222.186.34.119 61.136.171.198 62.210.141.172 62.210.172.143 62.210.172.206 82.165.128.189
Control the new input chain:
# iptables -n -L INPUT Chain INPUT (policy ACCEPT) target prot opt source destination DROP all -- 103.41.124.12 0.0.0.0/0 /* 2014-11-22 19:27:44 +0100 */ DROP all -- 122.225.109.211 0.0.0.0/0 /* 2014-11-22 19:27:44 +0100 */ DROP all -- 122.225.97.75 0.0.0.0/0 /* 2014-11-22 19:27:44 +0100 */ DROP all -- 122.225.97.97 0.0.0.0/0 /* 2014-11-22 19:27:44 +0100 */ DROP all -- 222.186.34.119 0.0.0.0/0 /* 2014-11-22 19:27:44 +0100 */ DROP all -- 61.136.171.198 0.0.0.0/0 /* 2014-11-22 19:27:44 +0100 */ DROP all -- 62.210.141.172 0.0.0.0/0 /* 2014-11-22 19:27:44 +0100 */ DROP all -- 62.210.172.143 0.0.0.0/0 /* 2014-11-22 19:27:44 +0100 */ DROP all -- 62.210.172.206 0.0.0.0/0 /* 2014-11-22 19:27:44 +0100 */ DROP all -- 82.165.128.189 0.0.0.0/0 /* 2014-11-22 19:27:44 +0100 */
Of course it is also possible to install fail2ban but my small Geode has only 256MB RAM and therefor I have to minimize my services. The above script is enough for me.
The code can be found on Github.






















