forked from gaiterjones/magento-appsec-file-check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagento_appsec_file_check.php
executable file
·189 lines (162 loc) · 5.64 KB
/
magento_appsec_file_check.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/php
<?php
// 0.13
//
// PATH TO MAGENTO ROOT
//
if (!isset($argv[1])) {
cliNotice('Usage: ' . $argv[0] . ' <magento path>');
exit;
}
$_magentoPath = getcwd() . '/';
$magePhpPath = $_magentoPath . '/app/Mage.php';
if (!file_exists($magePhpPath)) {
cliError(sprintf('Magento not found in "%s"!', $magePhpPath));
exit;
}
$_whiteListedConfigPaths = array(
'web/unsecure/base_url',
'web/secure/base_url',
'trans_email/ident_support/name',
'trans_email/ident_support/email',
'trans_email/ident_general/name',
'trans_email/ident_general/email',
'trans_email/ident_sales/name',
'trans_email/ident_sales/email',
'trans_email/ident_custom1/name',
'trans_email/ident_custom1/email',
'trans_email/ident_custom2/name',
'trans_email/ident_custom2/email',
'general/store_information/name',
'general/store_information/phone',
'general/store_information/address',
);
$_whiteListedBlockTypes = array(
'core/template',
'catalog/product_new',
'enterprise_catalogevent/event_lister',
);
// SECURITY PATCHES and APPSECS
//
$_securityPatches = array(
'SUPEE-6788' => array
(
'APPSEC-1034' => array(
'text' => 'addressing bypassing custom admin URL',
'exec' => array(
'path' => array(
$_magentoPath . 'app/code/community',
$_magentoPath . 'app/code/local'
),
'cmds' => array(
'custom admin url' => 'grep -ro "<use>admin</use>" %s'
)
),
'magentopath' => $_magentoPath
),
'APPSEC-1063' => array(
'text' => 'addressing possible SQL injection',
'exec' => array(
'path' => array(
$_magentoPath . 'app/code/community',
$_magentoPath . 'app/code/local'
),
'cmds' => array(
'addFieldToFilter with backtick' => 'grep -ro "addFieldToFilter(\\\'\\`.*)" %s',
'addFieldToFilter with open parenthesis' => 'grep -ro "addFieldToFilter(\\\'(.*)" %s',
)
),
'magentopath' => $_magentoPath
),
'APPSEC-1057' => array(
'text' => 'template processing method allows access to private information',
'exec' => array(
'path' => array(
$_magentoPath . 'app/code/community',
$_magentoPath . 'app/code/local',
$_magentoPath . 'app/locale',
$_magentoPath . 'app/design/frontend'
),
'cmds' => array(
'config path whitelist violation' =>
'grep -ro "{{config path=.*}}" %s | grep -v "' . implode('\|', $_whiteListedConfigPaths) . '"',
'block type whitelist violation' =>
'grep -ro "{{block type=.*}}" %s | grep -v "' . implode('\|', $_whiteListedBlockTypes) . '"',
)
),
'magentopath' => $_magentoPath
)
)
);
// EXEC
//
echo '*** ' . "\033[1;32m" . 'Magento security file check' . "\033[0m" . ' ***' . "\n";
$_count = 1;
foreach ($_securityPatches as $_patchName => $_securityNotices) {
echo $_patchName . "\n";
$_total = 0;
foreach ($_securityNotices as $_appsec => $_securityNotice) {
$_count += 1;
echo '[' . $_count . '] ' . $_appsec . ', ' . $_securityNotice['text'] . "\n";
$_result = doExec($_securityNotice, $_appsec);
$_total = $_total + $_result['total'];
echo $_result['text'] . "\n";
}
if ($_total == 0) {
echo "$_patchName: 0 affected files.\n";
} else {
echo "$_patchName: \033[1;31m$_total\033[0m affected files.\n";
}
}
echo '***********************************' . "\n";
exit;
function doExec($_securityNotice, $_appsec)
{
$_text = '';
$_total = 0;
foreach ($_securityNotice['exec']['path'] as $_searchPath) {
if (!is_dir($_searchPath)) {
cliNotice(sprintf('Path "%s" doesn\'t exist, skipping.', $_searchPath));
continue;
}
$_text = $_text . 'looking in ' . $_searchPath . "\n";
$_count = 0;
foreach ($_securityNotice['exec']['cmds'] as $_key => $_searchCommandTemplate) {
$_output = array();
$_searchCommand = sprintf($_searchCommandTemplate, $_searchPath);
exec($_searchCommand, $_output, $_status);
if (1 === $_status) {
$_text .= "$_key not found.\n";
continue;
}
if (0 === $_status) {
$_count += count($_output);
$_total += $_count;
$_text .= "{$_key} found;\033[1;31m {$_count} \033[0maffected files:\n";
foreach ($_output as $_line) {
list($_filePath, $_match) = explode(':', $_line, 2);
$_fileName = str_replace($_securityNotice['magentopath'], ' ', $_filePath);
$_text .= "[\033[1;32m$_appsec\033[0m] $_match found in\033[1;31m$_fileName\033[0m\n";
}
} else {
$_text .= "Command $_searchCommand failed with status: $_status\n";
}
}
}
return array(
'text' => $_text,
'total' => $_total
);
}
function cliError($msg)
{
echo "\033[0;31m" . $msg . "\033[0m" . PHP_EOL;
}
function cliNotice($msg)
{
echo "\033[0;33m" . $msg . "\033[0m" . PHP_EOL;
}
function cliSuccess($msg)
{
echo "\033[0;32m" . $msg . "\033[0m" . PHP_EOL;
}