bd9c37c523e4ceb6f3965d792fefad0ba1d41562
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");
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)   {
16)     logger("inc/security.php", "cracklib", "could not open cracklib-dictionary »{$config['cracklib_dict']}«");
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 Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

48)     logger('inc/security.php', 'verify_input_general', 'Ungültige Daten: '.$input);
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 Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

62)     logger('inc/security.php', 'verify_input_username', 'Ungültige Daten: '.$input);
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 Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

80) 
81) 
bernd Im Passwort dürfen auch kei...

bernd authored 16 years ago

82) function filter_quotes( $input )
83) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

85) }
86) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

87) 
88) 
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

89) function filter_shell( $input )
90) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

91)   return ereg_replace('[^-[:alnum:]\_\.\+ßäöüÄÖÜ/%§=]', '', $input );
92) }
93) 
94) function verify_shell( $input )
95) {
96)   if (filter_shell($input) != $input)
97)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

98) }
bernd input-filtering

bernd authored 16 years ago

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

bernd authored 16 years ago

100) 
101) 
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

110)   }
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

111)   $components = explode("/", $input);
112)   foreach ($components AS $item)
113)   {
114)     if ($item == '..')
115)     {
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

118)       return False;
119)     }
120)   }
bernd Auch Großbuchstaben sind im...

bernd authored 16 years ago

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

bernd authored 16 years ago

122) }
123) 
124) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

125) function check_emailaddr( $input )
126) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

127)   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

128) }
129)