forked from gaiterjones/magento-appsec-file-check
/
magento_appsec_file_check.php
141 lines (115 loc) · 3.24 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
<?php
// 0.13
//
// PATH TO MAGENTO ROOT
//
$_magentoPath='/home/www/magento/';
if (!file_exists($_magentoPath. 'app/Mage.php')) {
echo 'Magento not found!'. "\n";
exit;
}
// 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/*'
),
'cmd' => 'grep -irl ' ,
'query' => array(
'"<use>admin</use>"'
)
),
'magentopath' => $_magentoPath),
'APPSEC-1063' => array(
'text' => 'addressing possible SQL injection',
'exec' => array(
'path' => array(
$_magentoPath. 'app/code/community/*',
$_magentoPath. 'app/code/local/*'
),
'cmd' => 'grep -irl ' ,
'query' => array(
'"collection->addFieldToFilter(\'"',
'"collection->addFieldToFilter(\'\`"',
)
),
'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/*'
),
'cmd' => 'grep -irl ' ,
'query' => array(
'"{{config path="',
'"{{block type="',
)
),
'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)
{
echo '['. $_count++. '] '. $_appsec. ', '. $_securityNotice['text']. "\n";
$_result=doExec($_securityNotice,$_appsec);
$_total=$_total + $_result['total'];
echo $_result['text']. "\n";
}
echo $_patchName. ' '. ($_total > 0 ? "\033[1;31m". $_total. "\033[0m". ' affected files.' : $_total. ' affected files.'). "\n";
}
echo '***********************************'. "\n";
exit;
function doExec($_securityNotice,$_appsec)
{
$_text='';
$_exec=$_securityNotice['exec']['cmd'];
$_total=0;
foreach ($_securityNotice['exec']['path'] as $_searchPath)
{
$_text=$_text.'looking in '. $_searchPath. "\n";
$_count=0;
$_search='';
foreach ($_securityNotice['exec']['query'] as $_searchQuery)
{
exec($_exec. $_searchQuery. ' '. $_searchPath, $_output, $_status);
if (1 === $_status)
{
$_text=$_text.$_searchQuery. ' not found.'. "\n";
continue;
}
if (0 === $_status)
{
$_count=$_count + count($_output);
$_total=$_total + $_count;
foreach ($_output as $_line)
{
$_search=$_search.'['. "\033[1;32m". $_appsec. "\033[0m". '] '. $_searchQuery. ' found in '. "\033[1;31m". str_replace($_securityNotice['magentopath'],' ', $_line). "\033[0m\n";
}
} else {
$_text=$_text. 'Command '. $_securityNotice['exec']['cmd']. ' failed with status: ' . $_status. "\n";
}
}
$_text=$_text.($_count > 0 ? "\033[1;31m". $_count. "\033[0m". ' affected files : ' : "\033[1;32m". $_count. ' affected files.'. "\033[0m"). "\n". $_search. "\n";
}
return array(
'text' => $_text,
'total' => $_total
);
}