• This forum has a zero tolerance policy regarding spam. If you register here to publish advertising, your user account will be deleted without further questions.

[Howto] Plesk Control Panel zusätzlich mit htaccess schützen.

tessa

Vorsicht Ätzend!
[Howto] Plesk 9 bzw. 10 Control Panel zusätzlich mit htaccess schützen.

Hier ein kleines Tutorial, wie man den Plesk 9 und auch Plesk 10 Admin-Login zusätzlich mit .htaccess schützen kann.

Zuerst erstellen wir im Ordner /opt/psa/admin eine Passwortdatei mit dem Namen .meinepasswortdatei mit z.B. folgendem Inhalt:
Code:
PippiLangstrumpf:DeinPasswort

Die Konfigurationsdatei für den lighthttpd, den Plesk für das Control Panel nutzt, liegt unter: /etc/sw-cp-server/applications.d/plesk.conf

Hier fügt man die rot gekennzeichneten Einträge hinzu:

Bitte darauf achten, dass mod_auth geladen wird.
Code:
server.modules += ("mod_expire", "mod_fastcgi", "mod_rewrite", "mod_accesslog", "mod_alias", "mod_compress", "mod_setenv"[COLOR="Red"], "mod_auth"[/COLOR])

compress.filetype = ("text/plain", "text/html", "text/javascript", "text/css", "text/xml")
$HTTP["url"] !~ "\.php3?$" {
    expire.url = ( "" => "access 1 months")
}

server.tag = "sw-cp-server"

# Do not forget to repeat all your changes in the section for port 8880
$SERVER["socket"] == ":8443" {
    include_shell "/opt/psa/admin/conf/ssl-conf.sh"
    index-file.names = ("index.php")
    server.document-root = "/opt/psa/admin/htdocs"
    setenv.add-response-header  = ( "X-UA-Compatible" => "IE=EmulateIE7")
    accesslog.filename = "/opt/psa/admin/logs/httpsd_access_log"
    mimetype.assign += (".png"  => "image/png",
                        ".jpg"  => "image/jpeg",
                        ".jpeg" => "image/jpeg",
                        ".gif"  => "image/gif",
                        ".html" => "text/html",
			".htm" => "text/html",
                        ".js" => "text/javascript",
                        ".css"  => "text/css")
    fastcgi.map-extensions = ( ".php3" => ".php" )
    fastcgi.server = (
	".php" => (
	    (
		"socket" => "/opt/psa/tmp/sw-engine.sock",
		"bin-path" => "/usr/bin/sw-engine-cgi -c /opt/psa/admin/conf/php.ini -d auto_prepend_file=auth.php3 -u psaadm",
		"bin-username" => "root",
		"max-procs" => 1,
		"min-procs" => 0,
		"idle-timeout" => 60,
		"bin-environment" => (
		    "PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
		    "PHP_FCGI_CHILDREN" => "3",
		    "PHP_FCGI_MAX_REQUESTS" => "10"
		),
	    )
	)
    )
    alias.url = (
		"/plesk-billing/app-modernbill-admin" => "/opt/plesk-billing/admin/",
		"/plesk-billing/app-modernbill-api" => "/opt/plesk-billing/action-api/",
		"/plesk-billing/app-modernbill-client" => "/opt/plesk-billing/client/",
		"/plesk-billing/app-modernbill-order" => "/opt/plesk-billing/order/",
		"/plesk-billing" => "/opt/plesk-billing/"
	)
    url.rewrite-once = ("^/plesk/([^\\?]*)(\?(.*))?" => "/plesk.php?$3"
			, "^/sitepreview/(.*)?" => "/sitepreview.php/$1"
			, "^/sso/ui" => "/sso/ui.php"
			, "^/sso/users" => "/sso/users.php"
			, "^/sso/signout" => "/sso/signout.php")
[COLOR="Red"]    auth.debug = 2
    auth.backend = "plain"
    auth.backend.plain.userfile = "/opt/psa/admin/.meinepasswortdatei"
    auth.require = ( "/" =>

                     (
                        "method"  => "basic",
                        "realm"   => "Restricted Area",
                        "require" => "user=PippiLangstrumpf"
                     )
             )[/COLOR]
}


$SERVER["socket"] == ":8880" {
    index-file.names = ("index.php")
    server.document-root = "/opt/psa/admin/htdocs"
    setenv.add-response-header  = ( "X-UA-Compatible" => "IE=EmulateIE7")
    accesslog.filename = "/opt/psa/admin/logs/httpsd_access_log"
    mimetype.assign += (".png"  => "image/png",
                        ".jpg"  => "image/jpeg",
                        ".jpeg" => "image/jpeg",
                        ".gif"  => "image/gif",
                        ".html" => "text/html",
			".htm" => "text/html",
                        ".js" => "text/javascript",
                        ".css"  => "text/css")
    fastcgi.map-extensions = ( ".php3" => ".php" )
    fastcgi.server = (
	".php" => (
	    (
		"socket" => "/opt/psa/tmp/sw-engine-8880.sock",
		"bin-path" => "/usr/bin/sw-engine-cgi -c /opt/psa/admin/conf/php.ini -d auto_prepend_file=auth.php3 -u psaadm",
		"bin-username" => "root",
		"max-procs" => 1,
		"min-procs" => 0,
		"idle-timeout" => 60,
		"bin-environment" => (
		    "PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
		    "PHP_FCGI_CHILDREN" => "3",
		    "PHP_FCGI_MAX_REQUESTS" => "10"
		),
	    )
	)
    )
    alias.url = (
		"/plesk-billing/app-modernbill-admin" => "/opt/plesk-billing/admin/",
		"/plesk-billing/app-modernbill-api" => "/opt/plesk-billing/action-api/",
		"/plesk-billing/app-modernbill-client" => "/opt/plesk-billing/client/",
		"/plesk-billing/app-modernbill-order" => "/opt/plesk-billing/order/",
		"/plesk-billing" => "/opt/plesk-billing/"
	)
    url.rewrite-once = ("^/plesk/([^\\?]*)(\?(.*))?" => "/plesk.php?$3"
			, "^/sitepreview/(.*)?" => "/sitepreview.php/$1"
			, "^/sso/ui" => "/sso/ui.php"
			, "^/sso/users" => "/sso/users.php"
			, "^/sso/signout" => "/sso/signout.php")
[COLOR="Red"]    auth.debug = 2
    auth.backend = "plain"
    auth.backend.plain.userfile = "/opt/psa/admin/.meinepasswortdatei"
    auth.require = ( "/" =>

                     (
                        "method"  => "basic",
                        "realm"   => "Restricted Area",
                        "require" => "user=PippiLangstrumpf"
                     )
             )[/COLOR]
}

Nachdem alles abgespeichert ist, restartet man den Plesk Server mit: /etc/init.d/psa restart

Für den Fall, dass die plesk.conf bei zukünftigen Updates/Upgrades überschrieben wird, sollte man sich eine Sicherung anlegen, damit man die Datei jederzeit wieder einspielen kann.

Regards tessa
 
Last edited by a moderator:
Danke für dein Howto. Mich würde interessieren wie du auf die Idee gekommen bist Plesk zusätzlich abzusichern?
 
Die Antwort fällt mir leicht, wenn ich sehe, wieviel Bots auf auf das Control-Panel zugreifen und versuchen, den Admin-Login zu knacken.

Da dachte ich mir, dass ein doppelter Schutz das Beste sei.

Somit kann auch nicht jeder gleich erkennen, dass ein Plesk dahinter rennt.

Also erst gar keine Angriffsfläche bieten. ;)
 
Wäre vielleicht auch nicht schlecht, wenn du hin schreibst, für welche Plesk-Version das ist ;)
 
Ansonsten kannst doch auch noch den Port (die PORTS 8080 / 8443) vom Plesk verlegen, da suchen dann die BOTS auch erstmal vergebens..
 
Die Plesk-Version steht da lediglich implizit:
Halt seit lighthttpd eingesetzt wird. Das ist seit Plesk-Version 9.0 der Fall.

Mich würde viel mehr interessieren ob die Sache auch Update-resistent ist. ;)

huschi.
 
Bzgl. Update-resistent kann ich dir sagen, dass die Datei überschrieben wurde bei einem Update (9.2.X nach 9.5.X).
 
Ansonsten kannst doch auch noch den Port (die PORTS 8080 / 8443) vom Plesk verlegen, da suchen dann die BOTS auch erstmal vergebens..


Es wäre es der Port 8880 und nicht 8080 ;)

Nach einem Portscan hätte ich aber das gleiche Problem. Intelligente Bots scannen vorher das System.

Regards tessa
 
sehr merkwürdig, ich nutze Plesk 10.0.1 und Ubuntu 10.4. LTS, auch nach mehrfachem reload des lighthttpd funktioniert das nicht.

Sollte es in aktuellen Pleskversionen 10.x immer noch funktionieren?
 
sehr merkwürdig, ich nutze Plesk 10.0.1 und Ubuntu 10.4. LTS, auch nach mehrfachem reload des lighthttpd funktioniert das nicht.

Sollte es in aktuellen Pleskversionen 10.x immer noch funktionieren?

Versuch mal /etc/init.d/psa restart

Viele übersehen auch, in der ersten Zeile der plesk.conf motd_auth zu laden. ;)

Code:
server.modules += ("mod_expire", "mod_fastcgi", "mod_rewrite", "mod_accesslog", "mod_alias", "mod_compress", "mod_setenv"[COLOR="Red"], "mod_auth"[/COLOR])
 
Last edited by a moderator:
Die Plesk-Version steht da lediglich implizit:
Halt seit lighthttpd eingesetzt wird. Das ist seit Plesk-Version 9.0 der Fall.

Mich würde viel mehr interessieren ob die Sache auch Update-resistent ist. ;)

huschi.

Nur nochmal zur Klarstellung:

Die Sache ist Updateresistent. Ich betreibe mittlerweile die Version 10.4.4 und die plesk.conf wurde jedes Mal übernommen. Der .htaccess-Login ist seit der Implementierung unverändert.

LG
 
Die Sache ist Updateresistent. Ich betreibe mittlerweile die Version 10.4.4 und die plesk.conf wurde jedes Mal übernommen. Der .htaccess-Login ist seit der Implementierung unverändert.

Würdest Du ein Tutorial für die 10.4.4 einmal schreiben, denn die Verzeichnis bzw. Datenstruktur ist doich etwas anders als oben beschrieben...
 
Evtl. müssen die Pfade von /opt/psa/ auf /usr/local/psa/ geändert werden. Ansonsten bleibt alles gleich.

@tessa:
/usr/local/psa/ war bisher auf allen Systemen vorhanden. Auch wenn es nur ein Symlink auf /opt/psa/ war. Andersherum hingegen trifft es nicht zu. Daher wäre ein Hinweis am Anfang eines Howtos ganz nützlich, oder eben den bisher immer verwendbaren Pfad zu nutzten.

huschi.
 
[Howto] Plesk 10.4.4 Control Panel zusätzlich mit htaccess schützen.

Hey hey!

boptom hat recht. In Plesk 10.4.4 sieht die Dateistrucktur etwas anders aus.
Hier mal das Tutorial für Plesk 10.4.4 unter Ubuntu 10.04 LTS Server 64bit

Genauso wie bei tessa zuerst eine Passwortdatei mit beliebigen Namen z.B. .meinepasswortdatei unter /opt/psa/admin mit folgendem Inhalt erstellen:
Code:
PippiLangstrumpf:DeinPasswort
Wobei PippiLangstrumpf der Benutzer ist und DeinPasswort... is klar ;)

Nun ebenfalls die Konfigurationsdatei des lighthttp unter /etc/sw-cp-server/applications.d/plesk.conf öffnen.
Hier NUR in der ersten Zeile das aktivieren des mod_auth eintragen (habe ebefalls alles veränderte rot markiert)
Code:
server.modules += ("mod_expire", "mod_fastcgi", "mod_rewrite", "mod_accesslog", "mod_alias", "mod_compress"[COLOR="Red"], "mod_auth"[/COLOR])

compress.filetype = ("text/plain", "text/html", "text/javascript", "text/css", "text/xml")
$HTTP["url"] !~ "\.php3?$" {
    expire.url = ( "" => "access 1 months")
}
url.rewrite-once = (
    "/skins/branding/.*\.php.*" => "/",
    "/sitebuilder/skins/branding/.*\.php.*" => "/"
)

server.tag = "sw-cp-server"

include_shell "/etc/sw-cp-server/applications.d/plesk.socket.sh 8443 ssl"
include_shell "/etc/sw-cp-server/applications.d/plesk.socket.sh 8880"
include_shell "/etc/sw-cp-server/applications.d/plesk.socket.sh 8443 ipv6 ssl"
include_shell "/etc/sw-cp-server/applications.d/plesk.socket.sh 8880 ipv6"

Nun müssen wir die /etc/sw-cp-server/applications.d/plesk.socket.sh öffnen und am ende - noch vor der letzten geschweiften Klammer "}" - folgendes einfügen:
Code:
    auth.debug = 2
    auth.backend = "plain"
    auth.backend.plain.userfile = "/opt/psa/admin/.meinepasswortdatei"
    auth.require = ( "/" =>

                     (
                        "method"  => "basic",
                        "realm"   => "Restricted Area",
                        "require" => "user=PippiLangstrumpf"
                     )
             )
Unter auth.backend.plain.userfile = "/opt/psa/admin/.meinepasswortdatei" natürlich dein gewählten Namen eintragen
Und unter "require" => "user=PippiLangstrumpf" natürlich auch dein Username der in der .meinepasswortdatei steht eintragen.

Hier die Datei nochmal im Ganzen. Habe wieder das neu eingetragene rot markiert...
Code:
#!/bin/sh

USAGE="Usage: $0 <port> [ipv6] [ssl]"

if [ -z "$1" ]; then
    echo $USAGE 1>&2
    exit 1
fi

PORT="$1"
shift

IPV6="no"
SSL="no"


if [ "$1" = "ipv6" ] ; then
    IPV6="yes"
    shift
fi

if [ "$1" = "ssl" ] ; then
    SSL="yes"
    shift
fi

if [ -n "$1" ] ; then
    echo "Unknown extra args: $@" 1>&2
    echo $USAGE 1>&2
    exit 1
fi


# Checking IPv6 into system status:
IPV6_SOCKET="no"

# TODO: adaptation for FreeBSD
if [ -f /proc/net/if_inet6 ] ; then
    IPV6_SOCKET="only"

    # is IPv6 socket accepts IPv4 connections?
    if [ "X`/sbin/sysctl -n net.ipv6.bindv6only`" = "X0" ] ; then
        IPV6_SOCKET="yes"
    elif [ -d "/proc/vz" ] ; then
        # Bind only v6 under Virtuozzo
        IPV6_SOCKET="yes"
    fi
fi

# IPv6 is not supported by OS settings.
if [ $IPV6 = "yes" -a $IPV6_SOCKET = "no" ] ; then
    exit 0
fi

# In that case IPv6 socket can server IPv4 clients,
# so IPv4 section not needed at all
if [ $IPV6 = "no" -a $IPV6_SOCKET = "yes" ] ; then
    exit 0
fi

SOCK="/opt/psa/tmp/sw-engine"
if [ $PORT != "8443" ] ; then
    SOCK="$SOCK-$PORT"
fi
if [ $IPV6_SOCKET = "only" ] ; then
    SOCK="$SOCK-ipv6"
fi
SOCK="$SOCK.sock"


if [ $IPV6_SOCKET = "only" -a $IPV6 = "yes" ] ; then
    cat <<EOF
\$SERVER["socket"] == "[::]:$PORT" {
EOF
else
    cat <<EOF
\$SERVER["socket"] == ":$PORT" {
EOF
fi


if [ $IPV6 = "yes" ] ; then
cat <<EOF
    server.use-ipv6 = "enable"
EOF
fi

if [ $SSL = "yes" ] ; then
cat <<EOF
    \$HTTP["useragent"] =~ ".*MSIE [456]\..*" {
        server.max-keep-alive-requests = 0
    }
    include_shell "/opt/psa/admin/conf/ssl-conf.sh"
EOF
fi

cat <<EOF
    index-file.names = ("index.php")
    server.document-root = "/opt/psa/admin/htdocs"
    accesslog.filename = "/opt/psa/admin/logs/httpsd_access_log"
    mimetype.assign += (".png"  => "image/png",
                        ".jpg"  => "image/jpeg",
                        ".jpeg" => "image/jpeg",
                        ".gif"  => "image/gif",
                        ".html" => "text/html",
                        ".htm" => "text/html",
                        ".js" => "text/javascript",
                        ".css"  => "text/css",
                        ".xml" => "text/xml")
    fastcgi.map-extensions += ( ".php3" => ".php" )
    fastcgi.server += (
	".php" => (
	    (
		"socket" => "$SOCK",
		"bin-path" => "/usr/bin/sw-engine-cgi -c /opt/psa/admin/conf/php.ini -d auto_prepend_file=auth.php3 -u psaadm",
		"bin-username" => "root",
		"max-procs" => 1,
		"min-procs" => 0,
		"idle-timeout" => 60,
		"broken-scriptfilename" => "enable",
		"allow-x-send-file" => "enable",
		"bin-environment" => (
		    "PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
		    "PHP_FCGI_CHILDREN" => "3",
		    "PHP_FCGI_MAX_REQUESTS" => "10"
		),
	    )
	)
    )
    alias.url += (
        "/sitebuilder/skins/branding" => "/opt/psa/var/branding/sb/skins",
        "/sitebuilder" => "/usr/local/sb/htdocs",
    )
    url.rewrite-once += ("^/plesk/([^\\\\?]*)(\\?(.*))?" => "/plesk.php?\$3"
			, "^/sitepreview/(.*)?" => "/sitepreview.php/\$1"
			, "^/sso/ui" => "/sso/ui.php"
			, "^/sso/users" => "/sso/users.php"
			, "^/sso/signout" => "/sso/signout.php"
			, "^/sitebuilder/api/(.*)" => "/sitebuilder/index.php/\$1"
			, "^/sitebuilder/((.*)\.(.*))$" => "\$0"
			, "^/sitebuilder/(.*)" => "/sitebuilder/index.php/\$1")

    # Admin panel configuration
    alias.url += (
        "/skins/branding" => "/opt/psa/var/branding/panel/skins",
        "/admin" => "/opt/psa/admin/panel/application/public",
    )
    url.rewrite-once += (
        "^/admin/(styles|scripts|images|externals)/.*" => "\$0",
        "^/admin/(.*)" => "/admin/index.php/admin/\$1"
    )
    \$HTTP["url"] =~ "^/admin/" {
        server.error-handler-404 = "/admin/index.php"
    }

    # End-Client panel configuration
    alias.url += ("/smb" => "/opt/psa/admin/smb/application/public")
    url.rewrite-once += (
        "^/smb/(styles|scripts|images|externals)/.*" => "\$0",
        "^/smb/(.*)" => "/smb/index.php/smb/\$1"
    )
    \$HTTP["url"] =~ "^/smb/" {
        server.error-handler-404 = "/smb/index.php"
    }

    # Billing configuration
    alias.url += (
		"/plesk-billing/app-modernbill-admin" => "/opt/plesk-billing/htdocs/admin/",
		"/plesk-billing/app-modernbill-api" => "/opt/plesk-billing/htdocs/action-api/",
		"/plesk-billing/app-modernbill-client" => "/opt/plesk-billing/htdocs/client/",
		"/plesk-billing/app-modernbill-order" => "/opt/plesk-billing/store/htdocs/",
		"/store" => "/opt/plesk-billing/store/htdocs/",
		"/plesk-billing/lib-themes/default/lib-billing" => "/opt/plesk-billing/lib/lib-themes/default/lib-billing/",
		"/plesk-billing" => "/opt/plesk-billing/htdocs/",
		"/hspc-data" => "/var/opt/hspc-root/data/"
	)
    url.rewrite-once += (
		"^/plesk-billing/plugin/(styles|scripts|images|externals)/.*" => "\$0",
		"^/plesk-billing/plugin/(.*)" => "/plesk-billing/plugin/index.php/plesk-billing/plugin/\$1",
		"^/store/(css|js|images|uploads|themes|sf)/.*" => "\$0",
		"^/store/frontend_dev.php/(.*)" => "/store/frontend_dev.php/\$1",
		"^/store/(.*)" => "/store/index.php/\$1",
		"^/plesk-billing/order/products.php\?.*wwid=(\d+)" => "/store/index.php/entry-point/widget/\$1.html",
		"^/plesk-billing/order/products.php\?.*storeID=(\d+)" => "/store/index.php/entry-point/store/\$1.html",
		"^/plesk-billing/order(/.*)?$" => "/store/index.php/",
		"^/plesk-billing/lib-billing/include/lib-mbapi/remote.php$" => "/plesk-billing/mbapi/remote.php",
		"^/plesk-billing/lib-mbapi/include/modules/gateway/return/(.*)" => "/plesk-billing/gw/\$1"
    )

[COLOR="red"]    auth.debug = 2
    auth.backend = "plain"
    auth.backend.plain.userfile = "/opt/psa/admin/.pswdplesk"
    auth.require = ( "/" =>

                     (
                        "method"  => "basic",
                        "realm"   => "Restricted Area",
                        "require" => "user=plesk"
                     )
             )[/COLOR]
}

EOF

Jetzt noch ein restart des Pleskservers mit /etc/init.d/psa restart und es sollte klappen :)

Grüße!
 
geht das irgenwie für Plesk 12 auch? Weil wie hier aufgeführt geht es bei mir bei 12 nicht mehr und auch schon bei 11 ging es nicht mehr.
 
Diese Methode mit Plesk Onyx wäre sehr geil.

Weiß jemand ob das mit Plesk Onyx geht?

Gern! Ist nämlich etwas einfacher geworden und jetzt sind nur folgende Schritte notwendig:

1. Erstelle die Datei protect-plesk.inc im Ordner /etc/sw-cp-server/conf.d/
mit folgendem Inhalt:
Code:
location / {
auth_basic "Restricted";
auth_basic_user_file /etc/sw-cp-server/conf.d/passwd;
}

Code:
# Erstelle die passwd-Datei in der Konsole:
htpasswd -m /etc/sw-cp-server/conf.d/passwd Dein_Benutzername

# Berechtigungen anpassen:
chown sw-cp-server:psaadm /etc/sw-cp-server/conf.d/passwd
chmod 640 /etc/sw-cp-server/conf.d/passwd

# Plesk neustarten
/etc/init.d/sw-cp-server restart

Fertig!

Solange die Verzeichnisstruktur nicht geändert wird, überstehen diese Änderungen auch Updates.

Edit: Diese Anleitung funktioniert auch mit Plesk Obsidian

LG tessa
 
Last edited:
Back
Top