{"id":394,"date":"2018-07-06T09:16:06","date_gmt":"2018-07-06T07:16:06","guid":{"rendered":"https:\/\/www.gluecksgriff-taschen.de\/?p=394"},"modified":"2022-07-02T17:45:27","modified_gmt":"2022-07-02T15:45:27","slug":"wordpress-mit-fail2ban-gegen-brute-force-angriffe-schuetzen","status":"publish","type":"post","link":"https:\/\/www.gluecksgriff-taschen.de\/?p=394","title":{"rendered":"WordPress mit Fail2Ban gegen Brute Force Angriffe sch\u00fctzen"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">WordPress bietet von Hause aus leider keinen Schutz gegen Brute Force Angriffe. Ich m\u00f6chte gerne nach drei vergeblichen Login-Versuchen die IP-Adresse sperren, von der die Login-Versuche erfolgten.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Da bei mir sowieso Fail2Ban l\u00e4uft, um SSH-Logins zu limitieren, bietet es sich geradezu an das auch f\u00fcr WordPress zu verwenden. Hierzu muss ich allerdings erstmal heraus finden wie ich denn einen erfolgreichen von einem misslungenen Login unterscheiden kann.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">Schauen wir uns zun\u00e4chst mal einen misslungenen Login im Apache-Log <code>\/var\/log\/apache2\/access.log<\/code> an:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n217.89.77.180 - - &#x5B;06\/Jul\/2018:08:53:43 +0200] \"POST \/wp-login.php HTTP\/1.1\" 200 6337 \"https:\/\/www.gluecksgriff-taschen.de\/wp-login.php?loggedout=true\" \"Mozilla\/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/67.0.3396.99 Safari\/537.36\"\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Und nun einen erfolgreichen Login:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n217.89.77.180 - - &#x5B;06\/Jul\/2018:08:54:06 +0200] \"POST \/wp-login.php HTTP\/1.1\" 302 5278 \"https:\/\/www.gluecksgriff-taschen.de\/wp-login.php\" \"Mozilla\/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/67.0.3396.99 Safari\/537.36\"\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Offensichtlich gibt ein erfolgreicher Login einen Redirect-Status 302 zur\u00fcck, w\u00e4hrend bei einem misslungenem Login-Versuch ein Status 200 zur\u00fcckgegeben wird. Das kann ich nat\u00fcrlich prima f\u00fcr eine entsprechende Fail2Ban-Regel nutzen.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hierzu erstelle ich unter <code>\/etc\/fail2ban\/filter.d<\/code> einen Datei namens <code>wordpress.conf<\/code> mit folgendem Inhalt.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;INCLUDES]\nbefore = common.conf\n\n&#x5B;Definition]\nfailregex = &amp;lt;HOST&gt;.*POST.*(wp-login\\.php|xmlrpc\\.php).* 200\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Der unter failregex angegebene regul\u00e4re Ausdruck bedeutet die Zeile beginnt mit der IP-Adresse, danach kommt irgendwann das Wort &#8222;POST&#8220;, dann irgendwann &#8222;wp-login.php&#8220; und dann irgendwann ein Leerzeichen gefolgt von der Zahl 200. Das passt genau auf die Logzeile mit dem fehlgeschlagenem Login, sollte also funktionieren.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Nun muss ich Fail2Ban nur noch mitteilen, dass er diese Definition auch verwenden soll. Dazu erstelle ich eine Datei <code>\/etc\/fail2ban\/jail.d\/wordpress.conf<\/code> mit folgendem Inhalt:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;wordpress]\nenabled = true\nport = http,https\nfilter = wordpress\nlogpath = \/var\/log\/apache2\/access.log\nmaxretry = 3\nbantime = 3600\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Hiermit wird die f\u00fcr die Login-Versuche verwendete IP f\u00fcr 1 Stunde gesperrt. Zum Testen von der eigenen IP-Adresse aus w\u00fcrde ich nat\u00fcrlich erstmal deutlich geringere Werte bei <code>bantime<\/code> setzen.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Nach einem Neustart des Service mittels<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; gutter: false; highlight: [1]; title: ; notranslate\" title=\"\">\nsudo service fail2ban restart\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">ist die Regel aktiv, wie man im Logfile <code>\/var\/log\/fail2ban.log<\/code> kontrollieren kann.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n2018-11-21 16:38:33,198 fail2ban.server         &#x5B;7289]: INFO    Changed logging target to \/var\/log\/fail2ban.log for Fail2ban v0.9.6\n2018-11-21 16:38:33,199 fail2ban.database       &#x5B;7289]: INFO    Connected to fail2ban persistent database '\/var\/lib\/fail2ban\/fail2ban.sqlite3'\n2018-11-21 16:38:33,210 fail2ban.jail           &#x5B;7289]: INFO    Creating new jail 'dovecot'\n2018-11-21 16:38:33,329 fail2ban.jail           &#x5B;7289]: INFO    Jail 'dovecot' uses pyinotify {}\n2018-11-21 16:38:33,349 fail2ban.jail           &#x5B;7289]: INFO    Initiated 'pyinotify' backend\n2018-11-21 16:38:33,351 fail2ban.filter         &#x5B;7289]: INFO    Set findtime = 900\n2018-11-21 16:38:33,351 fail2ban.actions        &#x5B;7289]: INFO    Set banTime = 3600\n2018-11-21 16:38:33,352 fail2ban.filter         &#x5B;7289]: INFO    Set jail log file encoding to UTF-8\n2018-11-21 16:38:33,353 fail2ban.filter         &#x5B;7289]: INFO    Added logfile = \/var\/log\/mail.log\n2018-11-21 16:38:33,354 fail2ban.filter         &#x5B;7289]: INFO    Set maxRetry = 4\n2018-11-21 16:38:33,377 fail2ban.server         &#x5B;7289]: INFO    Jail dovecot is not a JournalFilter instance\n2018-11-21 16:38:33,391 fail2ban.jail           &#x5B;7289]: INFO    Creating new jail 'wordpress'\n2018-11-21 16:38:33,392 fail2ban.jail           &#x5B;7289]: INFO    Jail 'wordpress' uses pyinotify {}\n2018-11-21 16:38:33,397 fail2ban.jail           &#x5B;7289]: INFO    Initiated 'pyinotify' backend\n2018-11-21 16:38:33,398 fail2ban.filter         &#x5B;7289]: INFO    Set findtime = 900\n2018-11-21 16:38:33,398 fail2ban.actions        &#x5B;7289]: INFO    Set banTime = 43200\n2018-11-21 16:38:33,399 fail2ban.filter         &#x5B;7289]: INFO    Set jail log file encoding to UTF-8\n2018-11-21 16:38:33,400 fail2ban.filter         &#x5B;7289]: INFO    Added logfile = \/var\/log\/apache2\/access.log\n2018-11-21 16:38:33,401 fail2ban.filter         &#x5B;7289]: INFO    Set maxRetry = 3\n2018-11-21 16:38:33,409 fail2ban.jail           &#x5B;7289]: INFO    Creating new jail 'ssh'\n2018-11-21 16:38:33,409 fail2ban.jail           &#x5B;7289]: INFO    Jail 'ssh' uses pyinotify {}\n2018-11-21 16:38:33,416 fail2ban.jail           &#x5B;7289]: INFO    Initiated 'pyinotify' backend\n2018-11-21 16:38:33,417 fail2ban.filter         &#x5B;7289]: INFO    Set findtime = 900\n2018-11-21 16:38:33,417 fail2ban.actions        &#x5B;7289]: INFO    Set banTime = 43200\n2018-11-21 16:38:33,418 fail2ban.filter         &#x5B;7289]: INFO    Set jail log file encoding to UTF-8\n2018-11-21 16:38:33,419 fail2ban.filter         &#x5B;7289]: INFO    Added logfile = \/var\/log\/auth.log\n2018-11-21 16:38:33,420 fail2ban.filter         &#x5B;7289]: INFO    Set maxRetry = 3\n2018-11-21 16:38:33,420 fail2ban.filter         &#x5B;7289]: INFO    Set maxlines = 10\n2018-11-21 16:38:33,507 fail2ban.server         &#x5B;7289]: INFO    Jail ssh is not a JournalFilter instance\n2018-11-21 16:38:33,518 fail2ban.jail           &#x5B;7289]: INFO    Jail 'dovecot' started\n2018-11-21 16:38:33,523 fail2ban.jail           &#x5B;7289]: INFO    Jail 'wordpress' started\n2018-11-21 16:38:33,528 fail2ban.jail           &#x5B;7289]: INFO    Jail 'ssh' started\n2018-11-21 16:38:33,734 fail2ban.actions        &#x5B;7289]: NOTICE  &#x5B;wordpress] Ban 193.201.224.225\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Wer sich beim Austesten jetzt selbst ausgesperrt hat, <a href=\"https:\/\/www.gluecksgriff-taschen.de\/?p=285\">hier<\/a> steht wie man eine IP-Adresse bei Fail2Ban wieder vorzeitig entsperren kann.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress bietet von Hause aus leider keinen Schutz gegen Brute Force Angriffe. Ich m\u00f6chte gerne nach drei vergeblichen Login-Versuchen die IP-Adresse sperren, von der die Login-Versuche erfolgten. Da bei mir sowieso Fail2Ban l\u00e4uft, um SSH-Logins zu limitieren, bietet es sich geradezu an das auch f\u00fcr WordPress zu verwenden. Hierzu muss ich allerdings erstmal heraus finden &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/www.gluecksgriff-taschen.de\/?p=394\"> <span class=\"screen-reader-text\">WordPress mit Fail2Ban gegen Brute Force Angriffe sch\u00fctzen<\/span> Weiterlesen &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[3],"tags":[80,46,81],"class_list":["post-394","post","type-post","status-publish","format-standard","hentry","category-linux","tag-brute-force","tag-fail2ban","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.gluecksgriff-taschen.de\/index.php?rest_route=\/wp\/v2\/posts\/394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gluecksgriff-taschen.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gluecksgriff-taschen.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gluecksgriff-taschen.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gluecksgriff-taschen.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=394"}],"version-history":[{"count":18,"href":"https:\/\/www.gluecksgriff-taschen.de\/index.php?rest_route=\/wp\/v2\/posts\/394\/revisions"}],"predecessor-version":[{"id":797,"href":"https:\/\/www.gluecksgriff-taschen.de\/index.php?rest_route=\/wp\/v2\/posts\/394\/revisions\/797"}],"wp:attachment":[{"href":"https:\/\/www.gluecksgriff-taschen.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gluecksgriff-taschen.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gluecksgriff-taschen.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}