• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NathanGibbs3 / BASE / 624

pending completion
624

push

travis-ci-com

NathanGibbs3
Merge branch 'devel'

562 of 562 new or added lines in 28 files covered. (100.0%)

3145 of 17504 relevant lines covered (17.97%)

23.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/base_local_rules.php
1
<?php
2

3
$sc = DIRECTORY_SEPARATOR;
×
4
require_once("includes$sc" . 'base_krnl.php');
×
5
include_once ("$BASE_path/includes/base_include.inc.php");
×
6

7
$rv = false;
×
8

9
if( is_key('external_sig_link',$GLOBALS) ){
×
10
        $dir = $GLOBALS['external_sig_link']['local_rules_dir'][0];
×
11
}else{
×
12
        $dir = 'rules/';
×
13
}
14
if ( isset($_GET['sid']) ){
×
15
        $sid = $_GET['sid'];
×
16
}
17
$ODir = XSSPrintSafe($dir);
×
18
$OSid = XSSPrintSafe($sid);
×
19
if ( $debug_mode > 0 ){
×
20
        ErrorMessage($ODir,'black',1);
×
21
        ErrorMessage($OSid,'black',1);
×
22
}
23

24
function print_element($item, $key)
25
{
26
        echo "<BR><BR>\n\n-------\n" . htmlspecialchars($item) . "\n--------\n\n<BR><BR>";
×
27
}
28

29
function pcre_grep_file( $file, $sid ){
30
        if ( !LoadedString($file) ){
×
31
                ErrorMessage($EMPfx ."file is empty.", 0, 1);
×
32
                return FALSE;
×
33
        }
34
        if ( !LoadedString($sid) ){
×
35
                ErrorMessage($EMPfx ."sid is empty.", 0, 1);
×
36
                return FALSE;
×
37
        }
38

39
        // This pattern per se does work for rules which stretch over several lines.
40
        // However, it crashes php: Segmentation fault.
41
        $pattern = "/^(?:[ \t]*)(?:alert|log|drop)(?:.|\n)*sid:[ \t]*$sid(?:[ \t]*);(?:.|\n)*?[^\\\]$/ims";
×
42

43
        $lines = file_get_contents($file);
×
44
        $rv = preg_match($pattern, $lines, $matches);
×
45

46
        print_r($matches);
×
47
        #array_walk($matches, 'print_element');
48

49
        return $rv;
×
50
}
51

52
function pcre_grep_file_poor($file, $key, $sid){
53
        GLOBAL $debug_mode;
54
        $EMPfx = __FUNCTION__ . ': ERROR: ';
×
55
        $rv = FALSE;
×
56
        if ( !LoadedString($file) ){
×
57
                ErrorMessage($EMPfx ."file is empty.", 0, 1);
×
58
                return FALSE;
×
59
        }
60
        if ( !LoadedString($sid) ){
×
61
                ErrorMessage($EMPfx ."sid is empty.", 0, 1);
×
62
                return FALSE;
×
63
        }
64
        $OFile = XSSPrintSafe($file);
×
65
        $tmp = ChkAccess($file);
×
66
        if ( $tmp != 1 ){
×
67
                $EMsg = $EMPfx . '"' . $OFile . '" not ';
×
68
                if ( $tmp == -1 ){
×
69
                        $EMsg .= 'found';
×
70
                }elseif ( $tmp == -2 ){
×
71
                        $EMsg .= 'readable';
×
72
                }
73
                $$EMsg .= '. Ignoring this file.';
×
74
                ErrorMessage($EMsg, 0, 1);
×
75
                return FALSE;
×
76
        }
77

78
        $pattern = "/^(?:[ \t]*)(?:alert|log|drop).*?sid:[ \t]*$sid(?:[ \t]*);.*$/i";
×
79
        $return_value = false;
×
80

81
        $lines_array = file($file);
×
82

83
        if ( $debug_mode > 1 ){
×
84
                echo "Pattern = \"" . htmlspecialchars($pattern) . "\"\n<BR>";
×
85
        }
86
        foreach ( $lines_array as $val ){ // Issue #153
×
87
                $rv = preg_match($pattern, $val, $matches);
×
88
                if ( $rv ){
×
89
                        echo "<TH ALIGN=LEFT>$OFile:</TH>\n";
×
90
                        echo "<TR>\n";
×
91
                        foreach ( $matches as $rule ){ // Issue #153
×
92
                                echo '<td>'. XSSPrintSafe($rule) .'</td>';
×
93
                        }
94
                        echo "</TR>\n";
×
95
                        $return_value = true;
×
96
                }
97
        }
98
        return $return_value;
×
99
}
100

101
function search_dir($dir, $sid){
102
        GLOBAL $debug_mode;
103
        $EMPfx = __FUNCTION__ . ': ERROR: ';
×
104
        $sc = DIRECTORY_SEPARATOR;
×
105
        $rv = FALSE;
×
106
        if ( !LoadedString($dir) ){
×
107
                ErrorMessage($EMPfx . 'dir is empty.', 0, 1);
×
108
                return FALSE;
×
109
        }
110
        if ( !LoadedString($sid) ){
×
111
                ErrorMessage($EMPfx . 'sid is empty.', 0, 1);
×
112
                return FALSE;
×
113
        }
114
        if ( $debug_mode > 1 ){
×
115
                echo "In front of glob, with \$dir = " . XSSPrintSafe($dir) . "\n<BR>";
×
116
        }
117
        $OF = XSSPrintSafe($filename);
×
118
        foreach ( glob($dir . $sc . "*") as $filename ){
×
119
                if ( $debug_mode > 1 ){
×
120
                        echo "Filename: $OF ";
×
121
                }
122
                if ( ChkAccess($filename,'d') == 1 ){
×
123
                        search_dir($filename, $sid);
×
124
                }else{
×
125
                        $tmp = ChkAccess($filename);
×
126
                        if ( $tmp == 1 ){
×
127
                                if ( pcre_grep_file_poor($filename, '', $sid) ){
×
128
                                        $rv = true;
×
129
                                        if ( $debug_mode > 0 ){
×
130
                                                echo "Found\n<BR>";
×
131
                                        }
132
                                        break;
×
133
                                }
134
                        }else{
×
135
                                $EMsg = $EMPfx . '"' . $OF . '" not ';
×
136
                                if ( $tmp == -1 ){
×
137
                                        $EMsg .= 'found';
×
138
                                }elseif ( $tmp == -2 ){
×
139
                                        $EMsg .= 'readable';
×
140
                                }
141
                                $$EMsg .= '. Ignoring this file.';
×
142
                                ErrorMessage($EMsg, 0, 1);
×
143
                        }
144
                }
145
        }
146
        return $rv;
×
147
}
148

149
############# main() ##############
150
AuthorizedRole(10000);
×
151
PrintBASESubHeader('Local Rule Lookup');
×
152
if (file_exists($dir))
×
153
{
154
        if (is_executable($dir))
×
155
        {
156
                if ( is_readable($dir) ){
×
157
                        echo "<H1>sid: $OSid</H1>\n";
×
158
                        if ( $debug_mode > 0 ){
×
159
                                ErrorMessage('Calling search_dir()...',0,1);
×
160
                        }
161
                        echo "<TABLE>\n";
×
162
                        $rv = search_dir($dir, $sid);
×
163
                        echo "</TABLE>\n";
×
164
                        if ( $rv ){
×
165
                                if ( $debug_mode ){
×
166
                                        echo "Ok. Found.\n<BR>";
×
167
                                }
168
                        }else{
×
169
                                ErrorMessage("Sig Not found: \"sig: $OSid\" in directory \"$ODir\"."
×
170
                                , 0, 1);
171
                        }
172
                }else{
×
173
                        echo "ERROR: Directory $ODir can not be searched. It must also be readable for the user the web server is running as. However, this is not required by the web server per se, but by the glob() command of php.\n<BR>";
×
174
                }
175
        }else{
×
176
                echo "ERROR: Directory \"$ODir\" can not be searched. It must be executable (required by the web server).\n<BR>";
×
177
        }
178
}else{
×
179
        echo "ERROR: Directory \"$ODir\" does not exist.\n<BR>";
×
180
}
181
PrintBASESubFooter();
×
182
?>
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc