-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathparse.php
139 lines (107 loc) · 4.26 KB
/
parse.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
<?php
function parse_cve_list($html) {
$urls = array();
if (preg_match_all('~<h2><a href="\/node\/(\d+)">.*?SA~', $html, $matches)) {
foreach ($matches[1] as $node) {
$urls[] = 'https://www.drupal.org/node/' . $node;
}
}
return $urls;
}
function parse_cve($html) {
$u = array();
// First, parse the meta for the advisory id, project name, and versions
if (preg_match('~<meta name="description" content="(.*?)"~', $html, $m)) {
$meta = $m[1];
} else {
return false;
}
// Advisory ID
if (preg_match('~Advisory ID:\s?(.*?)\s~', $meta, $matches))
$u['advisory_id'] = $matches[1];
else if (preg_match('~(.*?)Project~', $meta, $matches)) // missing tag
$u['advisory_id'] = $matches[1];
// Project Name
if (preg_match('~Projects?: (.*?)Version~', $meta, $matches))
$u['project_name'] = str_replace(array('(third-party modules)', '(third-party module)'), '', $matches[1]);
// Versions affected
if (preg_match('~.*Version(s?): (.*?)(Date|Sec)~', $meta, $matches)) {
//$u['versions'] = $matches[2];
$versions = explode(',', $matches[2]);
foreach ($versions as $k => $v)
$versions[$k] = trim($v);
if (in_array('7.x', $versions))
$u['drupal_7'] = 'Yes';
if (in_array('6.x', $versions))
$u['drupal_6'] = 'Yes';
if (in_array('5.x', $versions))
$u['drupal_5'] = 'Yes';
if (in_array('4.7.x', $versions))
$u['drupal_4'] = 'Yes';
}
if (preg_match('~Date: (.*?) ~', $meta, $matches)) {
if (strtotime($matches[1]) !== false) {
$u['advisory_date'] = date("Y-m-d", strtotime($matches[1]));
} else { // Date is missing or corrupt on a few cves
if (preg_match('~<time.*>(.*?) at.*?</time>~', $html, $matches)) {
$u['advisory_date'] = date("Y-m-d", strtotime($matches[1]));
}
}
}
// Vulnerability Hunt -- seems more accurate to check the whole doc vs just the meta
if (stristr($html, 'xss'))
$u['s_xss'] = 'Yes';
if (stristr($html, 'cross site scripting'))
$u['s_xss'] = 'Yes';
if (stristr($html, 'csrf'))
$u['s_csrf'] = 'Yes';
if (stristr($html, 'cross site request forgery'))
$u['s_csrf'] = 'Yes';
if (stristr($html, 'access bypass'))
$u['s_access_bypass'] = 'Yes';
if (stristr($html, 'code execution'))
$u['s_arbitrary_code_execution'] = 'Yes';
if (stristr($html, 'open redirect'))
$u['s_open_redirect'] = 'Yes';
if (stristr($html, 'information disclosure'))
$u['s_information_disclosure'] = 'Yes';
if (stristr($html, 'sql injection'))
$u['s_sql_injection'] = 'Yes';
if (stristr($html, 'session fixation'))
$u['s_session_fixation'] = 'Yes';
if (stristr($html, 'denial of service'))
$u['s_dos'] = 'Yes';
if (stristr($html, 'filesystem overwrite'))
$u['s_file_access'] = 'Yes'; // generic for various file issues
if (stristr($html, 'privilege escalation'))
$u['s_privilege_escalation'] = 'Yes'; // generic for various file issues
if (stristr($html, 'spam'))
$u['s_spam'] = 'Yes'; // generic for various file issues
if (preg_match('/<h2>Reported by<\/h2>.*?<li>(.*?)<\/li>/ms', $html, $matches))
$u['reported_by'] = trim($matches[1]);
if (preg_match('/<h2>Fixed by<\/h2>.*?<li>(.*?)<\/li>/ms', $html, $matches))
$u['fixed_by'] = trim($matches[1]);
if (preg_match('/<h2>Coordinated by<\/h2>.*?<li>(.*?)<\/li>/ms', $html, $matches))
$u['coordinated_by'] = trim($matches[1]);
// Unsupported? TODO: Improve check for this.
if (stristr($html, 'unsupported'))
$u['unsupported'] = 'Yes';
// Project short name
if (preg_match('~a href="https?://www.drupal.org/project/(.*?)"~', $html, $m))
$u['project_short_name'] = $m[1];
// Account for project differences in the short name
if (empty($u['project_short_name']) || $u['project_short_name'] === 'drupal') {
if (preg_match('~a href="https?://drupal.org/project/(.*?)"~', $html, $m)) {
$u['project_short_name'] = $m[1];
} else {
die("Cannot find the short name for {$u['project_name']}\r\n");
}
}
// Project url and git repo
$u['project_url'] = "https://www.drupal.org/project/{$u['project_short_name']}";
$u['project_git_url'] = "http://git.drupal.org/project/{$u['project_short_name']}.git";
// Trim whitespace
foreach ($u as $k => $v)
$u[$k] = trim($v);
return $u;
}