d5f2f3f40845c818f65b41258a2ba19f6c494175
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 use config

bernd authored 15 years ago

8)   global $config;
bernd cracklib ausschaltbar machen

bernd authored 16 years ago

9)   if (isset($config['use_cracklib']) and $config['use_cracklib'] == false) {
10)     DEBUG('Cracklib deaktiviert');
11)     return true;
12)   }
bernd * Passwörter mit cracklib p...

bernd authored 16 years ago

13)   DEBUG("Öffne Wörterbuch: {$config['cracklib_dict']}");
14)   if (! ($dict = crack_opendict($config['cracklib_dict'])))
15)   {
bernd eliminate .php extensions f...

bernd authored 15 years ago

16)     logger("inc/security", "cracklib", "could not open cracklib-dictionary »{$config['cracklib_dict']}«");
bernd * Passwörter mit cracklib p...

bernd authored 16 years ago

17)     system_failure("Kann Crack-Lib-Wörterbuch nicht öffnen: {$config['cracklib_dict']}");
18)   }
19)   // Führe eine Überprüfung des Passworts durch
20)   $check = crack_check($dict, $password);
21) 
22)   $message = crack_getlastmessage();
23)   crack_closedict($dict);
24) 
25)   if ($check === True)
26)   {
27)     DEBUG("Passwort ok");
28)     return true;
29)   }
30)   else
31)   {
32)     DEBUG("Passwort nicht ok: {$message}");
33)     return $message;
34)   }
35) }
36) 
37) 
bernd input-filtering

bernd authored 16 years ago

38) function filter_input_general( $input )
39) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

40)   return htmlspecialchars(iconv('UTF-8', 'UTF-8', $input), ENT_QUOTES, 'UTF-8');
41) }
42) 
43) 
44) function verify_input_general( $input )
45) {
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

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

bernd authored 16 years ago

47)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd eliminate .php extensions f...

bernd authored 15 years ago

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

bernd authored 16 years ago

49)   }
bernd input-filtering

bernd authored 16 years ago

50) }
51) 
52) 
53) function filter_input_username( $input )
54) {
hanno Hatte die Kompatibilität ge...

hanno authored 16 years ago

55)   return ereg_replace("[^[:alnum:]\_\.\+\-]", "", $input );
56) }
57) 
58) function verify_input_username( $input )
59) {
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

60)   if (filter_input_username( $input ) != $input) {
bernd eliminate .php extensions f...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

63)   }
bernd input-filtering

bernd authored 16 years ago

64) }
65) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

66) 
67) 
bernd check auf hostname

bernd authored 16 years ago

68) function filter_input_hostname( $input )
69) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

71)   $input = rtrim($input, "\t\n\r\x00 .");
72)   $input = ltrim($input, "\t\n\r\x00 .");
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

73)   if (ereg_replace("[^[:alnum:]äöü\.\-]", "", $input ) != $input)
74)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Hostname darf kein »..« ent...

bernd authored 16 years ago

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

bernd authored 16 years ago

77)   return $input;
bernd check auf hostname

bernd authored 16 years ago

78) }
79) 
bernd Add IP-address patterns

bernd authored 15 years ago

80) function verify_input_hostname( $input )
81) {
82)   if (filter_input_hostname( $input ) != $input) {
83)     logger('inc/security', 'verify_input_hostname', 'Ungültige Daten: '.$input);
84)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
85)   }
86) }
87) 
88) 
89) function verify_input_ipv4( $input )
90) {
91)   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))
92)     system_failure('Keine IP-Adresse');
93) }
94) 
95) 
96) function verify_input_ipv6( $input )
97) {
98)   // ripped from Perl module Net-IPv6Addr v0.2
99)   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))
100)     system_failure("Ungültige IPv6-Adresse");
101) }
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

102) 
103) 
bernd Im Passwort dürfen auch kei...

bernd authored 16 years ago

104) function filter_quotes( $input )
105) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

107) }
108) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

109) 
110) 
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

111) function filter_shell( $input )
112) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

113)   return ereg_replace('[^-[:alnum:]\_\.\+ßäöüÄÖÜ/%§=]', '', $input );
114) }
115) 
116) function verify_shell( $input )
117) {
118)   if (filter_shell($input) != $input)
119)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

120) }
bernd input-filtering

bernd authored 16 years ago

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

bernd authored 16 years ago

122) 
123) 
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

128)   {
bernd eliminate .php extensions f...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

132)   }
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

133)   $components = explode("/", $input);
134)   foreach ($components AS $item)
135)   {
136)     if ($item == '..')
137)     {
bernd eliminate .php extensions f...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

140)       return False;
141)     }
142)   }
bernd Auch Großbuchstaben sind im...

bernd authored 16 years ago

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

bernd authored 16 years ago

144) }
145) 
146) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

147) function in_homedir($path)
148) {
149)   DEBUG("Prüfe »{$path}«");
150)   if (! check_path($path))
151)   {
152)     DEBUG('Kein Pfad');
153)     return False;
154)   }
155)   if (! isset($_SESSION['userinfo']['homedir']))
156)   {
157)     DEBUG("Kann homedir nicht ermitteln");
158)     return False;
159)   }
160)   return strncmp($_SESSION['userinfo']['homedir'], $path, count($_SESSION['userinfo']['homedir'])) == 0;
161) }
162) 
163) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

164) function check_emailaddr( $input )
165) {
bernd Syntax-fehler

bernd authored 16 years ago

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

bernd authored 16 years ago

167) }
168) 
169) function check_domain( $input )
170) {
171)   return (bool) preg_match("/[a-z0-9\.\-]+\.[a-z]{2,4}$/i", $input );