EWA
Transcrição
EWA
EWA SS 07 EWA SS 07 1 2 EWA Upload, Authentifizierung, Wiederholung aufgrund Minitest <form enctype="multipart/form-data" action="upload.php" method="post"> <input type="hidden" name="max_file_size" value="1000"> <label for="uploadFile”>Datei:</label> <input id="uploadFile" type="file"> <input type="submit" value="senden"> </form> Voreinstellung Dateityp/-endung nicht möglich Dr. Ute Blechschmidt-Trapp Dr. Ute Blechschmidt-Trapp EWA SS 07 3 • • • • Dr. Ute Blechschmidt-Trapp Upload - PHP $uploaddir = $_SERVER["DOCUMENT_ROOT"] . "/ewa/uploads/"; $uploadfile = $uploaddir . basename($_FILES["userfile"]["name"]); if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $uploadfile)) { echo "ok"; } else { echo "so nicht"; } $_FILES['userfile']['name'] (Name Client-Maschine) $_FILES['userfile']['type'] (Mime-Type) $_FILES['userfile']['size'] (Größe in Bytes) $_FILES['userfile']['tmp_name'] (Tmp-Dateiname, wie auf dem Server gespeichert) $_FILES['userfile']['error'] (Fehlercode) Dr. Ute Blechschmidt-Trapp Upload - Formular EWA SS 07 4 • • Zugriffsschutz - http.conf Standardeinstellung von Apache sehr restriktiv Mögliche Einträge in http.conf: – restriktiv <Directory /> keine sonstigen Options Options None .htaccess wirkungslos AllowOverride None </Directory> – offen <Directory "C:/Programme/Apache/htdocs"> AllowOverride All .htaccess wirksam Allow from all </Directory> freigeben, Beschränkung auf host/IP möglich – Zugriff auf .htacess veweigern <Files ~ "^\.ht"> Deny from all </Files> Dr. Ute Blechschmidt-Trapp EWA SS 07 Zugriffsschutz - .htaccess • Zugriffsschutz mit .htaccess-Dateien – nur verwenden, falls kein Zugriff auf http.conf – alle Möglichkeiten wie bei <Directory> in http.conf – bezieht sich auf das Verzeichnis, in dem .htaccess steht – muss in httpd.conf freigegeben sein mit AllowOverride All – z.B. Options -Indexes (Auflisten des Verzeichnisses nicht erlaubt) 5 EWA SS 07 6 • HTTP – Apache (mod_auth, mod_auth_dbm, mod_auth_ldap) – IIS: auch Windows Authentifzierung • Skript • Ablage der Benutzer/Gruppen (Authentifizierung gegen): – LDAP – DB – Datei – System (IIS) Dr. Ute Blechschmidt-Trapp EWA SS 07 7 • • Dr. Ute Blechschmidt-Trapp Ablauf Basic Authentifizierung HTTP Client fordert eine Ressource an Server erkennt, das Ressource passwortgeschützt ist und fordert Client zur Authentifizierung auf Authentifizierung EWA SS 07 Ablauf Basic Authentification 8 Basic: Art der Authentifizierung HTTP/1.1 401 Unauthorized realm: Anzeigeinfo im Dialogfenster .... WWW-Authenticate: BASIC realm="EWA Authorization" • Browser fragt Benutzername und Passwort ab und schickt die Eingaben an den Server (Benutzername:Passwort Base 64 kodiert) GET /index.htm HTTP/1.1 .... Authorization: BASIC d2VibWFzdGVyOnpycW1hNHY= • Server liefert Dokument =base64_encode("webmaster:zrqma4v") Dr. Ute Blechschmidt-Trapp Dr. Ute Blechschmidt-Trapp EWA SS 07 9 Digest Authentifizierung HTTP Authentifizierungsaufforderung HTTP/1.1 401 Unauthorized WWW-Authenticate: Digest realm="Webengineering Testinstallation", nonce="7aEjFtHKAwA=57e4252a2c68c0f9d30b0699f9b7de79d7895e1b", algorithm=MD5, qop="auth” EWA SS 07 10 Authentifizierung Authorization: Digest username="hugo", realm="EWA", nonce="7aEjFtHKAwA=57e4252a2c68c0f9d30b0699f9b7de79d7895e1b", uri="/", algorithm=MD5, response="e6f59508c24c4893b1acadf5551839b9", qop=auth, nc=00000001, cnonce="e3719279e8bdaee1" • Basic Access Authentication – Einfaches Username - Password Schema – <user>:<passwd> Base64 kodiert – Keine Verschlüsselung! • Digest Access Authentication (ab HTTP 1.1) – Challenge Response Verfahren – Keine Übertragung des Passworts im Klartext • Passwort wird im Browser gespeichert und bei jeder Seitenanforderung an denselben Server übermittelt – notwendig, weil HTTP zustandslos ist • Webserver ( Betriebssystem):beliebig viele Login-Versuche (Angriffsverdacht durch Analyse der Log-Datei). Dr. Ute Blechschmidt-Trapp Dr. Ute Blechschmidt-Trapp Authentifizierung mit mod_auth EWA SS 07 11 EWA SS 07 (Textdatei) • .htaccess AuthName "Video" AuthType Basic AuthUserFile /ewa/.htpasswd Require valid-user • http.conf: – Directory: Angabe für Verzeichnis – Location: Angabe für URL – File: Angabe für einzelne Datei(en) <Directory /ewa/video> AllowOveride AuthConfig ... </Directory> • Anlegen eines Benutzers: – htpasswsd –c /ewa/.htpasswd ute 12 Dr. Ute Blechschmidt-Trapp Authentifizierung Apache Authentifizierung mit mod_auth_dbm .htaccess AuthType Basic AuthName ”Admin Users Only" AuthDBMUserFile /usr/local/apache2/misc/.htdb Require user webadmin • http.conf: <Directory /ewa/video> AllowOveride AuthConfig ... </Directory> • Anlegen eines Benutzers: – dbmmanage /usr/www/zul_dbm/benutzer.db adduser webadmin Dr. Ute Blechschmidt-Trapp Authentifizierung LDAP EWA SS 07 13 LDAP EWA SS 07 (Lightweight Directory Access Protocol) Client Client Username Passwort Username Passwort Apache mod_auth_ldap Apache mod_auth_ldap LDAP Webseite 14 PHP LDAP: zus. installieren LoadModuleldap_modulemodules/util_ldap.so LoadModuleauth_ldap_modulemodules/mod_auth_ldap.so <Location "/auth_ldap"> AuthName Test_Auth AuthType basic AuthLDAP Enabledon AuthLDAPURL ldap://ldap1.airius.com ldap2.airius.com/ou=People, o=Airius require valid-user </Location> http://httpd.apache.org/docs/2.0/mod/mod_auth_ldap.html Webseite Dr. Ute Blechschmidt-Trapp Dr. Ute Blechschmidt-Trapp HTTP Authentifizierung mit PHP EWA SS 07 15 LDAP Authentifizierung mit mod_auth_ldap in http.conf EWA SS 07 (falls PHP als Modul läuft) if (!isset($_SERVER['PHP_AUTH_USER'])) { Header("WWW-Authenticate: Basic realm=\”Authentifizierung\""); Header("HTTP/1.0 401 Unauthorized"); echo "Cancelled"; exit; } else { echo "Hello {$_SERVER['PHP_AUTH_USER']}"; } Dr. Ute Blechschmidt-Trapp 16 Skriptbasierte Authentifizierung üblicher Ablauf • Login-Formular • Action Skript zur Authentifizierung: – Post-Daten mit DB vergleichen (bei Fehler auf Fehlerseite, erneutes Login mit Fehlermeldung beispielsweise in der Session abgelegt - umleiten: header("Location: login.php");) – Benutzername und IP ($_SERVER["REMOTE_ADDR"]) in Session ablegen: Dr. Ute Blechschmidt-Trapp