Skip to content

Commit cb12210

Browse files
author
Till Brehm
committed
FS#3640 - Add Intrusion Detection System
1 parent fb6c56e commit cb12210

33 files changed

+5979
-7
lines changed

install/dist/lib/fedora.lib.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,12 @@ public function install_ispconfig()
10101010
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
10111011
$command = 'chown root:ispconfig '.$install_dir.'/security';
10121012
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
1013+
$command = 'chown root:ispconfig '.$install_dir.'/security/ids.whitelist';
1014+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
1015+
$command = 'chown root:ispconfig '.$install_dir.'/security/ids.htmlfield';
1016+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
1017+
$command = 'chown root:ispconfig '.$install_dir.'/security/apache_directives.blacklist';
1018+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
10131019

10141020
//* Make the global language file directory group writable
10151021
exec("chmod -R 770 $install_dir/interface/lib/lang");

install/dist/lib/gentoo.lib.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,12 @@ public function install_ispconfig()
903903
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
904904
$command = 'chown root:ispconfig '.$install_dir.'/security';
905905
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
906+
$command = 'chown root:ispconfig '.$install_dir.'/security/ids.whitelist';
907+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
908+
$command = 'chown root:ispconfig '.$install_dir.'/security/ids.htmlfield';
909+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
910+
$command = 'chown root:ispconfig '.$install_dir.'/security/apache_directives.blacklist';
911+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
906912

907913
//* Make the global language file directory group writable
908914
exec("chmod -R 770 $install_dir/interface/lib/lang");

install/dist/lib/opensuse.lib.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,12 @@ public function install_ispconfig()
10811081
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
10821082
$command = 'chown root:ispconfig '.$install_dir.'/security';
10831083
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
1084+
$command = 'chown root:ispconfig '.$install_dir.'/security/ids.whitelist';
1085+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
1086+
$command = 'chown root:ispconfig '.$install_dir.'/security/ids.htmlfield';
1087+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
1088+
$command = 'chown root:ispconfig '.$install_dir.'/security/apache_directives.blacklist';
1089+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
10841090

10851091
//* Make the global language file directory group writable
10861092
exec("chmod -R 770 $install_dir/interface/lib/lang");

install/lib/installer_base.lib.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,12 @@ public function install_ispconfig() {
19371937
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
19381938
$command = 'chown root:ispconfig '.$install_dir.'/security';
19391939
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
1940+
$command = 'chown root:ispconfig '.$install_dir.'/security/ids.whitelist';
1941+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
1942+
$command = 'chown root:ispconfig '.$install_dir.'/security/ids.htmlfield';
1943+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
1944+
$command = 'chown root:ispconfig '.$install_dir.'/security/apache_directives.blacklist';
1945+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
19401946

19411947
//* Make the global language file directory group writable
19421948
exec("chmod -R 770 $install_dir/interface/lib/lang");

interface/lib/app.inc.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class app {
4848
private $_wb;
4949
private $_loaded_classes = array();
5050
private $_conf;
51+
private $_security_config;
5152

5253
public $loaded_plugins = array();
5354

@@ -109,7 +110,8 @@ public function __construct() {
109110
}
110111

111112
$this->uses('functions'); // we need this before all others!
112-
$this->uses('auth,plugin');
113+
$this->uses('auth,plugin,ini_parser,getconf');
114+
113115
}
114116

115117
public function __get($prop) {
@@ -327,4 +329,13 @@ public function tpl_defaults() {
327329
//* possible future = new app($conf);
328330
$app = new app();
329331

332+
// load and enable PHP Intrusion Detection System (PHPIDS)
333+
$ids_security_config = $app->getconf->get_security_config('ids');
334+
335+
if(is_dir(ISPC_CLASS_PATH.'/IDS') && $ids_security_config['ids_enabled'] == 'yes') {
336+
$app->uses('ids');
337+
$app->ids->start();
338+
}
339+
unset($ids_security_config);
340+
330341
?>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# in case PHPIDS is placed in the web-root
2+
deny from all
3+
4+
# silence is golden
5+
php_flag display_errors off
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
/**
3+
* PHPIDS
4+
*
5+
* Requirements: PHP5, SimpleXML
6+
*
7+
* Copyright (c) 2008 PHPIDS group (https://phpids.org)
8+
*
9+
* PHPIDS is free software; you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* PHPIDS is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
* PHP version 5.1.6+
23+
*
24+
* @category Security
25+
* @package PHPIDS
26+
* @author Mario Heiderich <mario.heiderich@gmail.com>
27+
* @author Christian Matthies <ch0012@gmail.com>
28+
* @author Lars Strojny <lars@strojny.net>
29+
* @license http://www.gnu.org/licenses/lgpl.html LGPL
30+
* @link http://php-ids.org/
31+
*/
32+
33+
namespace IDS\Caching;
34+
35+
/**
36+
* APC caching wrapper
37+
*
38+
* This class inhabits functionality to get and set cache via memcached.
39+
*
40+
* @category Security
41+
* @package PHPIDS
42+
* @author Yves Berkholz <godzilla80@gmx.net>
43+
* @copyright 2007-2009 The PHPIDS Groupoup
44+
* @license http://www.gnu.org/licenses/lgpl.html LGPL
45+
* @link http://php-ids.org/
46+
* @since Version 0.6.5
47+
*/
48+
class ApcCache implements CacheInterface
49+
{
50+
/**
51+
* Caching type
52+
*
53+
* @var string
54+
*/
55+
private $type = null;
56+
57+
/**
58+
* Cache configuration
59+
*
60+
* @var array
61+
*/
62+
private $config = null;
63+
64+
/**
65+
* Flag if the filter storage has been found in memcached
66+
*
67+
* @var boolean
68+
*/
69+
private $isCached = false;
70+
71+
/**
72+
* Holds an instance of this class
73+
*
74+
* @var object
75+
*/
76+
private static $cachingInstance = null;
77+
78+
/**
79+
* Constructor
80+
*
81+
* @param string $type caching type
82+
* @param array $init the IDS_Init object
83+
*
84+
* @return void
85+
*/
86+
public function __construct($type, $init)
87+
{
88+
$this->type = $type;
89+
$this->config = $init->config['Caching'];
90+
}
91+
92+
/**
93+
* Returns an instance of this class
94+
*
95+
* @param string $type caching type
96+
* @param object $init the IDS_Init object
97+
*
98+
* @return object $this
99+
*/
100+
public static function getInstance($type, $init)
101+
{
102+
if (!self::$cachingInstance) {
103+
self::$cachingInstance = new ApcCache($type, $init);
104+
}
105+
106+
return self::$cachingInstance;
107+
}
108+
109+
/**
110+
* Writes cache data
111+
*
112+
* @param array $data the caching data
113+
*
114+
* @return object $this
115+
*/
116+
public function setCache(array $data)
117+
{
118+
if (!$this->isCached) {
119+
apc_store(
120+
$this->config['key_prefix'] . '.storage',
121+
$data,
122+
$this->config['expiration_time']
123+
);
124+
}
125+
126+
return $this;
127+
}
128+
129+
/**
130+
* Returns the cached data
131+
*
132+
* Note that this method returns false if either type or file cache is
133+
* not set
134+
*
135+
* @return mixed cache data or false
136+
*/
137+
public function getCache()
138+
{
139+
$data = apc_fetch($this->config['key_prefix'] . '.storage');
140+
$this->isCached = !empty($data);
141+
142+
return $data;
143+
}
144+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
/**
3+
* PHPIDS
4+
*
5+
* Requirements: PHP5, SimpleXML
6+
*
7+
* Copyright (c) 2008 PHPIDS group (https://phpids.org)
8+
*
9+
* PHPIDS is free software; you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* PHPIDS is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
* PHP version 5.1.6+
23+
*
24+
* @category Security
25+
* @package PHPIDS
26+
* @author Mario Heiderich <mario.heiderich@gmail.com>
27+
* @author Christian Matthies <ch0012@gmail.com>
28+
* @author Lars Strojny <lars@strojny.net>
29+
* @license http://www.gnu.org/licenses/lgpl.html LGPL
30+
* @link http://php-ids.org/
31+
*/
32+
namespace IDS\Caching;
33+
34+
/**
35+
* Caching factory
36+
*
37+
* This class is used as a factory to load the correct concrete caching
38+
* implementation.
39+
*
40+
* @category Security
41+
* @package PHPIDS
42+
* @author Christian Matthies <ch0012@gmail.com>
43+
* @author Mario Heiderich <mario.heiderich@gmail.com>
44+
* @author Lars Strojny <lars@strojny.net>
45+
* @copyright 2007-2009 The PHPIDS Group
46+
* @license http://www.gnu.org/licenses/lgpl.html LGPL
47+
* @link http://php-ids.org/
48+
* @since Version 0.4
49+
*/
50+
class CacheFactory
51+
{
52+
/**
53+
* Factory method
54+
*
55+
* @param object $init the IDS_Init object
56+
* @param string $type the caching type
57+
*
58+
* @return object the caching facility
59+
*/
60+
public static function factory($init, $type)
61+
{
62+
$object = false;
63+
$wrapper = preg_replace(
64+
'/\W+/m',
65+
null,
66+
ucfirst($init->config['Caching']['caching'])
67+
);
68+
$class = '\\IDS\\Caching\\' . $wrapper . 'Cache';
69+
$path = dirname(__FILE__) . DIRECTORY_SEPARATOR . $wrapper . 'Cache.php';
70+
71+
if (file_exists($path)) {
72+
include_once $path;
73+
74+
if (class_exists($class)) {
75+
$object = call_user_func(
76+
array('' . $class, 'getInstance'),
77+
$type,
78+
$init
79+
);
80+
}
81+
}
82+
83+
return $object;
84+
}
85+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* PHPIDS
4+
*
5+
* Requirements: PHP5, SimpleXML
6+
*
7+
* Copyright (c) 2008 PHPIDS group (https://phpids.org)
8+
*
9+
* PHPIDS is free software; you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* PHPIDS is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
* PHP version 5.1.6+
23+
*
24+
* @category Security
25+
* @package PHPIDS
26+
* @author Mario Heiderich <mario.heiderich@gmail.com>
27+
* @author Christian Matthies <ch0012@gmail.com>
28+
* @author Lars Strojny <lars@strojny.net>
29+
* @license http://www.gnu.org/licenses/lgpl.html LGPL
30+
* @link http://php-ids.org/
31+
*/
32+
namespace IDS\Caching;
33+
34+
/**
35+
* Caching wrapper interface
36+
*
37+
* @category Security
38+
* @package PHPIDS
39+
* @author Christian Matthies <ch0012@gmail.com>
40+
* @author Mario Heiderich <mario.heiderich@gmail.com>
41+
* @author Lars Strojny <lars@strojny.net>
42+
* @copyright 2007-2009 The PHPIDS Group
43+
* @license http://www.gnu.org/licenses/lgpl.html LGPL
44+
* @since Version 0.4
45+
* @link http://php-ids.org/
46+
*/
47+
interface CacheInterface
48+
{
49+
/**
50+
* Interface method
51+
*
52+
* @param array $data the cache data
53+
*
54+
* @return void
55+
*/
56+
public function setCache(array $data);
57+
58+
/**
59+
* Interface method
60+
*
61+
* @return void
62+
*/
63+
public function getCache();
64+
}

0 commit comments

Comments
 (0)