b0d6649b94966f9088df8dd95eec1f1fba027898
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));
71)   if (ereg_replace("[^[:alnum:]äöü\.\-]", "", $input ) != $input)
72)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Hostname darf kein »..« ent...

bernd authored 16 years ago

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

bernd authored 16 years ago

75)   return $input;
bernd check auf hostname

bernd authored 16 years ago

76) }
77) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

78) 
79) 
bernd Im Passwort dürfen auch kei...

bernd authored 16 years ago

80) function filter_quotes( $input )
81) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

83) }
84) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

85) 
86) 
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

87) function filter_shell( $input )
88) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

96) }
bernd input-filtering

bernd authored 16 years ago

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

bernd authored 16 years ago

98) 
99) 
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

108)   }
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

116)       return False;
117)     }
118)   }
bernd Auch Großbuchstaben sind im...

bernd authored 16 years ago

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

bernd authored 16 years ago

120) }
121) 
122) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

123) function check_emailaddr( $input )
124) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

126) }
127)