4c7e58dd02818d315e2a37eeac117374bc903fed
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 Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

8)   if ($password == '' || strlen($password) < 4) {
9)     DEBUG("Passwort zu kurz!");
10)     return "Passwort ist zu kurz!";
11)   }
12) 
bernd detect if cracklib is insta...

bernd authored 14 years ago

13)   if (! function_exists("crack_opendict"))
14)   {
15)     DEBUG("cracklib not available!");
16)     return true;
17)   }
bernd Einige Dummheiten repariert...

bernd authored 14 years ago

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

bernd authored 16 years ago

19)     DEBUG('Cracklib deaktiviert');
20)     return true;
21)   }
bernd Einige Dummheiten repariert...

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

24)   {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

47) function filter_input_general( $input )
48) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

49)   return htmlspecialchars(iconv('UTF-8', 'UTF-8', $input), ENT_QUOTES, 'UTF-8');
50) }
51) 
52) 
53) function verify_input_general( $input )
54) {
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

58)   }
bernd input-filtering

bernd authored 16 years ago

59) }
60) 
61) 
62) function filter_input_username( $input )
63) {
bernd deprecation of ereg* functi...

bernd authored 14 years ago

64)   return preg_replace("/[^[:alnum:]\_\.\+\-]/", "", $input );
hanno Hatte die Kompatibilität ge...

hanno authored 16 years ago

65) }
66) 
67) function verify_input_username( $input )
68) {
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

72)   }
bernd input-filtering

bernd authored 16 years ago

73) }
74) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

75) 
76) 
bernd Erlaube * im Hostname

bernd authored 14 years ago

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

bernd authored 16 years ago

78) {
bernd Erlaube * im Hostname

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

82)   $input = rtrim($input, "\t\n\r\x00 .");
83)   $input = ltrim($input, "\t\n\r\x00 .");
bernd deprecation of ereg* functi...

bernd authored 14 years ago

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

bernd authored 16 years ago

85)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Erlaube wildcards bei vhosts

bernd authored 13 years ago

86)   if (preg_match("/^.+\*/", $input ))
87)     system_failure("Ihre Daten enthielten ungültige Zeichen (Wildcard-Stern muss ganz vorne stehen)!");
88)   if (! $wildcard && preg_replace("/^\*/", "", $input ) != $input)
bernd Erlaube * im Hostname

bernd authored 14 years ago

89)     system_failure("Ihre Daten enthielten ungültige Zeichen (Keine Wildcards erlaubt)!");
bernd Hostname darf kein »..« ent...

bernd authored 16 years ago

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

bernd authored 16 years ago

92)   return $input;
bernd check auf hostname

bernd authored 16 years ago

93) }
94) 
bernd Erlaube * im Hostname

bernd authored 14 years ago

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

bernd authored 15 years ago

96) {
bernd Erlaube * im Hostname

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

99)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
100)   }
101) }
102) 
103) 
104) function verify_input_ipv4( $input )
105) {
106)   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))
107)     system_failure('Keine IP-Adresse');
108) }
109) 
110) 
111) function verify_input_ipv6( $input )
112) {
113)   // ripped from Perl module Net-IPv6Addr v0.2
114)   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))
115)     system_failure("Ungültige IPv6-Adresse");
116) }
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

117) 
118) 
bernd Im Passwort dürfen auch kei...

bernd authored 16 years ago

119) function filter_quotes( $input )
120) {
bernd deprecation of ereg* functi...

bernd authored 14 years ago

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

bernd authored 16 years ago

122) }
123) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

124) 
125) 
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

126) function filter_shell( $input )
127) {
bernd deprecation of ereg* functi...

bernd authored 14 years ago

128)   return preg_replace('/[^-[:alnum:]\_\.\+ßäöüÄÖÜ/%§=]/', '', $input );
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

129) }
130) 
131) function verify_shell( $input )
132) {
133)   if (filter_shell($input) != $input)
134)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

135) }
bernd input-filtering

bernd authored 16 years ago

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

bernd authored 16 years ago

137) 
138) 
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

143)   {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

147)   }
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

148)   $components = explode("/", $input);
149)   foreach ($components AS $item)
150)   {
151)     if ($item == '..')
152)     {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

155)       return False;
156)     }
157)   }
bernd Erlaube Leerzeichen im Pfad

bernd authored 13 years ago

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

bernd authored 16 years ago

159) }
160) 
161) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

162) function in_homedir($path)
163) {
164)   DEBUG("Prüfe »{$path}«");
165)   if (! check_path($path))
166)   {
167)     DEBUG('Kein Pfad');
168)     return False;
169)   }
170)   if (! isset($_SESSION['userinfo']['homedir']))
171)   {
172)     DEBUG("Kann homedir nicht ermitteln");
173)     return False;
174)   }
175)   return strncmp($_SESSION['userinfo']['homedir'], $path, count($_SESSION['userinfo']['homedir'])) == 0;
176) }
177) 
178) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

179) function check_emailaddr( $input )
180) {
bernd Syntax-fehler

bernd authored 16 years ago

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

bernd authored 16 years ago

182) }
183) 
184) function check_domain( $input )
185) {
186)   return (bool) preg_match("/[a-z0-9\.\-]+\.[a-z]{2,4}$/i", $input );