f550c0ef0e015ecc4096f8d52c5ea2208f6f5176
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!");
73)   return $input;
bernd check auf hostname

bernd authored 16 years ago

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

bernd authored 16 years ago

76) 
77) 
bernd Im Passwort dürfen auch kei...

bernd authored 16 years ago

78) function filter_quotes( $input )
79) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

81) }
82) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

83) 
84) 
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

85) function filter_shell( $input )
86) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

94) }
bernd input-filtering

bernd authored 16 years ago

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

bernd authored 16 years ago

96) 
97) 
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

106)   }
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

114)       return False;
115)     }
116)   }
bernd Auch Großbuchstaben sind im...

bernd authored 16 years ago

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

bernd authored 16 years ago

118) }
119) 
120) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

121) function check_emailaddr( $input )
122) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

124) }
125)