f20a077bbae272d467e0fd6bc7beb8a2e42ae882
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 cracklib ausschaltbar machen

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

48)   }
bernd input-filtering

bernd authored 16 years ago

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

hanno authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

62)   }
bernd input-filtering

bernd authored 16 years ago

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

bernd authored 16 years ago

65) 
66) 
bernd check auf hostname

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

76)   return $input;
bernd check auf hostname

bernd authored 16 years ago

77) }
78) 
bernd Add IP-address patterns

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

119) }
bernd input-filtering

bernd authored 16 years ago

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

bernd authored 16 years ago

121) 
122) 
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

131)   }
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

143) }
144) 
145) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

146) function check_emailaddr( $input )
147) {
bernd Syntax-fehler

bernd authored 16 years ago

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

bernd authored 16 years ago

149) }
150) 
151) function check_domain( $input )
152) {
153)   return (bool) preg_match("/[a-z0-9\.\-]+\.[a-z]{2,4}$/i", $input );