17c66ad05a8e324ca827aa20a0f725e71611db0d
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) {
bernd detect if cracklib is insta...

bernd authored 14 years ago

8)   if (! function_exists("crack_opendict"))
9)   {
10)     DEBUG("cracklib not available!");
11)     return true;
12)   }
bernd Einige Dummheiten repariert...

bernd authored 14 years ago

13)   if (config('use_cracklib') === NULL or config('use_cracklib') === false) {
bernd cracklib ausschaltbar machen

bernd authored 16 years ago

14)     DEBUG('Cracklib deaktiviert');
15)     return true;
16)   }
bernd Einige Dummheiten repariert...

bernd authored 14 years ago

17)   DEBUG("Öffne Wörterbuch: ".config('cracklib_dict'));
bernd Mehr config-optionen und co...

bernd authored 14 years ago

18)   if (! ($dict = crack_opendict(config('cracklib_dict'))))
bernd * Passwörter mit cracklib p...

bernd authored 16 years ago

19)   {
bernd Logger mit Logleveln

bernd authored 14 years ago

20)     logger(LOG_ERR, "inc/security", "cracklib", "could not open cracklib-dictionary »".config('cracklib_dict')."«");
bernd Einige Dummheiten repariert...

bernd authored 14 years ago

21)     system_failure("Kann Crack-Lib-Wörterbuch nicht öffnen: ".config('cracklib_dict'));
bernd * Passwörter mit cracklib p...

bernd authored 16 years ago

22)   }
23)   // Führe eine Überprüfung des Passworts durch
24)   $check = crack_check($dict, $password);
25) 
26)   $message = crack_getlastmessage();
27)   crack_closedict($dict);
28) 
29)   if ($check === True)
30)   {
31)     DEBUG("Passwort ok");
32)     return true;
33)   }
34)   else
35)   {
36)     DEBUG("Passwort nicht ok: {$message}");
37)     return $message;
38)   }
39) }
40) 
41) 
bernd input-filtering

bernd authored 16 years ago

42) function filter_input_general( $input )
43) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

44)   return htmlspecialchars(iconv('UTF-8', 'UTF-8', $input), ENT_QUOTES, 'UTF-8');
45) }
46) 
47) 
48) function verify_input_general( $input )
49) {
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

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

bernd authored 16 years ago

51)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Logger mit Logleveln

bernd authored 14 years ago

52)     logger(LOG_WARNING, 'inc/security', 'verify_input_general', 'Ungültige Daten: '.$input);
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

53)   }
bernd input-filtering

bernd authored 16 years ago

54) }
55) 
56) 
57) function filter_input_username( $input )
58) {
hanno Hatte die Kompatibilität ge...

hanno authored 16 years ago

59)   return ereg_replace("[^[:alnum:]\_\.\+\-]", "", $input );
60) }
61) 
62) function verify_input_username( $input )
63) {
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

64)   if (filter_input_username( $input ) != $input) {
bernd Logger mit Logleveln

bernd authored 14 years ago

65)     logger(LOG_WARNING, 'inc/security', 'verify_input_username', 'Ungültige Daten: '.$input);
bernd Add IP-address patterns

bernd authored 15 years ago

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

bernd authored 16 years ago

67)   }
bernd input-filtering

bernd authored 16 years ago

68) }
69) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

70) 
71) 
bernd Erlaube * im Hostname

bernd authored 14 years ago

72) function filter_input_hostname( $input, $wildcard=false )
bernd check auf hostname

bernd authored 16 years ago

73) {
bernd Erlaube * im Hostname

bernd authored 14 years ago

74)   // FIXME: Eine "filter"-Funktion sollte keinen system_failure verursachen sondern einfach einen bereinigten String liefern.
75)   
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

76)   $input = str_replace(array('Ä', 'Ö', 'Ü'), array('ä', 'ö', 'ü'), strtolower($input));
bernd Hostnames sollten nicht mit...

bernd authored 16 years ago

77)   $input = rtrim($input, "\t\n\r\x00 .");
78)   $input = ltrim($input, "\t\n\r\x00 .");
bernd Erlaube * im Hostname

bernd authored 14 years ago

79)   if (ereg_replace("[^[:alnum:]äöü*\.\-]", "", $input ) != $input)
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

80)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Erlaube * im Hostname

bernd authored 14 years ago

81)   if (! $wildcard && ereg_replace("\*", "", $input ) != $input)
82)     system_failure("Ihre Daten enthielten ungültige Zeichen (Keine Wildcards erlaubt)!");
bernd Hostname darf kein »..« ent...

bernd authored 16 years ago

83)   if (strstr($input, '..'))
84)     system_failure("Ungültiger Hostname");
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

85)   return $input;
bernd check auf hostname

bernd authored 16 years ago

86) }
87) 
bernd Erlaube * im Hostname

bernd authored 14 years ago

88) function verify_input_hostname( $input, $wildcard=false )
bernd Add IP-address patterns

bernd authored 15 years ago

89) {
bernd Erlaube * im Hostname

bernd authored 14 years ago

90)   if (filter_input_hostname( $input, $wildcard ) != $input) {
bernd Logger mit Logleveln

bernd authored 14 years ago

91)     logger(LOG_WARNING, 'inc/security', 'verify_input_hostname', 'Ungültige Daten: '.$input);
bernd Add IP-address patterns

bernd authored 15 years ago

92)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
93)   }
94) }
95) 
96) 
97) function verify_input_ipv4( $input )
98) {
99)   if (! preg_match("/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/", $input))
100)     system_failure('Keine IP-Adresse');
101) }
102) 
103) 
104) function verify_input_ipv6( $input )
105) {
106)   // ripped from Perl module Net-IPv6Addr v0.2
107)   if (! preg_match("/^(([0-9a-f]{1,4}:){7}[0-9a-f]{1,4}|[0-9a-f]{0,4}::|:(?::[a-f0-9]{1,4}){1,6}|(?:[a-f0-9]{1,4}:){1,6}:|(?:[a-f0-9]{1,4}:)(?::[a-f0-9]{1,4}){1,6}|(?:[a-f0-9]{1,4}:){2}(?::[a-f0-9]{1,4}){1,5}|(?:[a-f0-9]{1,4}:){3}(?::[a-f0-9]{1,4}){1,4}|(?:[a-f0-9]{1,4}:){4}(?::[a-f0-9]{1,4}){1,3}|(?:[a-f0-9]{1,4}:){5}(?::[a-f0-9]{1,4}){1,2}|(?:[a-f0-9]{1,4}:){6}(?::[a-f0-9]{1,4}))$/i", $input))
108)     system_failure("Ungültige IPv6-Adresse");
109) }
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

110) 
111) 
bernd Im Passwort dürfen auch kei...

bernd authored 16 years ago

112) function filter_quotes( $input )
113) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

115) }
116) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

117) 
118) 
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

119) function filter_shell( $input )
120) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

121)   return ereg_replace('[^-[:alnum:]\_\.\+ßäöüÄÖÜ/%§=]', '', $input );
122) }
123) 
124) function verify_shell( $input )
125) {
126)   if (filter_shell($input) != $input)
127)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

128) }
bernd input-filtering

bernd authored 16 years ago

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

bernd authored 16 years ago

130) 
131) 
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

136)   {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

140)   }
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

141)   $components = explode("/", $input);
142)   foreach ($components AS $item)
143)   {
144)     if ($item == '..')
145)     {
bernd Logger mit Logleveln

bernd authored 14 years ago

146)       logger(LOG_WARNING, 'inc/security', 'check_path', '»..« im Pfad: '.$input);
bernd check auf hostname

bernd authored 16 years ago

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

bernd authored 16 years ago

148)       return False;
149)     }
150)   }
bernd Auch Großbuchstaben sind im...

bernd authored 16 years ago

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

bernd authored 16 years ago

152) }
153) 
154) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

155) function in_homedir($path)
156) {
157)   DEBUG("Prüfe »{$path}«");
158)   if (! check_path($path))
159)   {
160)     DEBUG('Kein Pfad');
161)     return False;
162)   }
163)   if (! isset($_SESSION['userinfo']['homedir']))
164)   {
165)     DEBUG("Kann homedir nicht ermitteln");
166)     return False;
167)   }
168)   return strncmp($_SESSION['userinfo']['homedir'], $path, count($_SESSION['userinfo']['homedir'])) == 0;
169) }
170) 
171) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

172) function check_emailaddr( $input )
173) {
bernd Syntax-fehler

bernd authored 16 years ago

174)   return (bool) filter_var($input, FILTER_VALIDATE_EMAIL) == $input;
bernd don't be too complicated. /...

bernd authored 16 years ago

175) }
176) 
177) function check_domain( $input )
178) {
179)   return (bool) preg_match("/[a-z0-9\.\-]+\.[a-z]{2,4}$/i", $input );