8b3e6a3867de9c51c0e416f4b3db538083a73b1a
bernd input-filtering

bernd authored 16 years ago

1) <?php
2) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

3) require_once('inc/error.php');
4) 
bernd input-filtering

bernd authored 16 years ago

5) 
bernd * Passwörter mit cracklib p...

bernd authored 16 years ago

6) function strong_password($password)
7) {
8)   include("config.php");
9)   DEBUG("Öffne Wörterbuch: {$config['cracklib_dict']}");
10)   if (! ($dict = crack_opendict($config['cracklib_dict'])))
11)   {
12)     logger("inc/security.php", "cracklib", "could not open cracklib-dictionary »{$config['cracklib_dict']}«");
13)     system_failure("Kann Crack-Lib-Wörterbuch nicht öffnen: {$config['cracklib_dict']}");
14)   }
15)   // Führe eine Überprüfung des Passworts durch
16)   $check = crack_check($dict, $password);
17) 
18)   $message = crack_getlastmessage();
19)   crack_closedict($dict);
20) 
21)   if ($check === True)
22)   {
23)     DEBUG("Passwort ok");
24)     return true;
25)   }
26)   else
27)   {
28)     DEBUG("Passwort nicht ok: {$message}");
29)     return $message;
30)   }
31) }
32) 
33) 
bernd input-filtering

bernd authored 16 years ago

34) function filter_input_general( $input )
35) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

36)   return htmlspecialchars(iconv('UTF-8', 'UTF-8', $input), ENT_QUOTES, 'UTF-8');
37) }
38) 
39) 
40) function verify_input_general( $input )
41) {
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

42)   if (filter_input_general($input) != $input) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

43)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

44)     logger('inc/security.php', 'verify_input_general', 'Ungültige Daten: '.$input);
45)   }
bernd input-filtering

bernd authored 16 years ago

46) }
47) 
48) 
49) function filter_input_username( $input )
50) {
hanno Hatte die Kompatibilität ge...

hanno authored 16 years ago

51)   return ereg_replace("[^[:alnum:]\_\.\+\-]", "", $input );
52) }
53) 
54) function verify_input_username( $input )
55) {
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

56)   if (filter_input_username( $input ) != $input) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

57)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

58)     logger('inc/security.php', 'verify_input_username', 'Ungültige Daten: '.$input);
59)   }
bernd input-filtering

bernd authored 16 years ago

60) }
61) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

62) 
63) 
bernd check auf hostname

bernd authored 16 years ago

64) function filter_input_hostname( $input )
65) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

66)   $input = str_replace(array('Ä', 'Ö', 'Ü'), array('ä', 'ö', 'ü'), strtolower($input));
67)   if (ereg_replace("[^[:alnum:]äöü\.\-]", "", $input ) != $input)
68)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
69)   return $input;
bernd check auf hostname

bernd authored 16 years ago

70) }
71) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

72) 
73) 
bernd Im Passwort dürfen auch kei...

bernd authored 16 years ago

74) function filter_quotes( $input )
75) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

76)   return ereg_replace('["\'`]', '', $input );
bernd Im Passwort dürfen auch kei...

bernd authored 16 years ago

77) }
78) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

79) 
80) 
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

81) function filter_shell( $input )
82) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

83)   return ereg_replace('[^-[:alnum:]\_\.\+ßäöüÄÖÜ/%§=]', '', $input );
84) }
85) 
86) function verify_shell( $input )
87) {
88)   if (filter_shell($input) != $input)
89)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

90) }
bernd input-filtering

bernd authored 16 years ago

91) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

92) 
93) 
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

94) function check_path( $input )
95) {
bernd Auch @ darf im Mailbox-Pfad...

bernd authored 16 years ago

96)   DEBUG("checking {$input} for valid path name");
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

97)   if ($input != filter_input_general($input))
bernd Auch @ darf im Mailbox-Pfad...

bernd authored 16 years ago

98)   {
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

99)     logger('inc/security.php', 'check_path', 'HTML-Krams im Pfad: '.$input);
bernd Auch @ darf im Mailbox-Pfad...

bernd authored 16 years ago

100)     DEBUG("HTML-Krams im Pfad");
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

101)     return False;
bernd Auch @ darf im Mailbox-Pfad...

bernd authored 16 years ago

102)   }
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

103)   $components = explode("/", $input);
104)   foreach ($components AS $item)
105)   {
106)     if ($item == '..')
107)     {
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

108)       Alogger('inc/security.php', 'check_path', '»..« im Pfad: '.$input);
bernd check auf hostname

bernd authored 16 years ago

109)       DEBUG("»..« im Pfad");
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

110)       return False;
111)     }
112)   }
bernd Auch @ darf im Mailbox-Pfad...

bernd authored 16 years ago

113)   return (preg_match('/^[a-z0-9.@\/_-]*$/',$input) == 1);
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

114) }
115) 
116) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

117) function check_emailaddr( $input )
118) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

119)   return (preg_match("/^[a-z]+[a-z0-9]*[\.|\-|_]?[a-z0-9]+@([a-z0-9]*[\.|\-]?[a-z0-9]+){1,4}\.[a-z]{2,4}$/i", $input ) == 1);
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

120) }
121)