2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
42 var $results = array();
45 foreach($this->results as $result){
46 echo '<tr><td>' . nl2br($result) . '</td></tr>';
51 function save($file=''){
52 $fp = fopen($file, 'a');
53 foreach($this->results as $result){
54 fwrite($fp , $result);
59 function scan($path= '.', $ext = '.php'){
61 while($entry = $dir->read()){
62 if(is_dir($path . '/' . $entry) && $entry != '.' && $entry != '..'){
63 $this->scan($path .'/' . $entry);
65 if(is_file($path . '/'. $entry) && substr($entry, strlen($entry) - strlen($ext), strlen($ext)) == $ext){
66 $contents = file_get_contents($path .'/'. $entry);
67 $this->scanContents($contents, $path .'/'. $entry);
72 function scanContents($contents){
79 class ScanFileIncludes extends SugarSecure{
80 function scanContents($contents, $file){
83 /*preg_match_all("'(require_once\([^\)]*\\$[^\)]*\))'si", $contents, $results, PREG_SET_ORDER);
84 foreach($results as $result){
86 $found .= "\n" . $result[0];
89 preg_match_all("'include_once\([^\)]*\\$[^\)]*\)'si", $contents, $results, PREG_SET_ORDER);
90 foreach($results as $result){
91 $found .= "\n" . $result[0];
95 preg_match_all("'require\([^\)]*\\$[^\)]*\)'si", $contents, $results, PREG_SET_ORDER);
96 foreach($results as $result){
97 $found .= "\n" . $result[0];
100 preg_match_all("'include\([^\)]*\\$[^\)]*\)'si", $contents, $results, PREG_SET_ORDER);
101 foreach($results as $result){
102 $found .= "\n" . $result[0];
105 preg_match_all("'require_once\([^\)]*\\$[^\)]*\)'si", $contents, $results, PREG_SET_ORDER);
106 foreach($results as $result){
107 $found .= "\n" . $result[0];
110 preg_match_all("'fopen\([^\)]*\\$[^\)]*\)'si", $contents, $results, PREG_SET_ORDER);
111 foreach($results as $result){
112 $found .= "\n" . $result[0];
115 preg_match_all("'file_get_contents\([^\)]*\\$[^\)]*\)'si", $contents, $results, PREG_SET_ORDER);
116 foreach($results as $result){
117 $found .= "\n" . $result[0];
120 $this->results[] = $file . $found."\n\n";
130 class SugarSecureManager{
131 var $scanners = array();
132 function registerScan($class){
133 $this->scanners[] = new $class();
138 while($scanner = current($this->scanners)){
140 $scanner = next($this->scanners);
142 reset($this->scanners);
147 while($scanner = current($this->scanners)){
148 echo 'Scan Results: ';
150 $scanner = next($this->scanners);
152 reset($this->scanners);
156 //reset($this->scanners);
157 $name = 'SugarSecure'. time() . '.txt';
158 while($this->scanners = next($this->scanners)){
159 $scanner->save($name);
164 $secure = new SugarSecureManager();
165 $secure->registerScan('ScanFileIncludes');