This repository was archived by the owner on Dec 23, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathEntry.java
More file actions
181 lines (159 loc) · 5.53 KB
/
Copy pathEntry.java
File metadata and controls
181 lines (159 loc) · 5.53 KB
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
package kamil.cve;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import javax.swing.JFrame;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.io.IOException;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
/**
* Entry class retrieves, parses and displays detailed information about given CVE entry.
* @author Kamil Mas³owski
*
*/
public class Entry {
static Logger log = LogManager.getLogger();
private static final String url_prefix = "http://web.nvd.nist.gov/view/vuln/detail?vulnId=";
// Storage elements with default values
String title = "none";
String overview = "none";
String source = "none";
String original_release = "none";
String last_revised = "none";
float CVSS_score_num = -1f;
String CVSS_score_vector = "none";
float impact_subscore = -1f;
float exploitability_subscore = -1f;
boolean in_progress = false;
/**
* Debug function used to dump Entry data into log file.
*/
public void printAll(){
log.info("Title: " + title);
log.info("Overview: " + overview);
log.info("Source: " + source);
log.info("Original Release: " + original_release);
log.info("Last Revised: " + last_revised);
log.info("CVSS Score: " + Float.toString(CVSS_score_num));
log.info("CVSS info " + CVSS_score_vector);
log.info("Impact Subscore: " + Float.toString(impact_subscore));
log.info("Exploitability Subscore: " + Float.toString(exploitability_subscore));
}
/**
* Function responsible for creating GUI windows displaying all parsed data
*/
public void createAndDisplayGUI(){
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
// create all panels
JFrame jf = new JFrame(title);
// header elements
JLabel titleLabel = new JLabel(title);
JLabel sourceLabel = new JLabel("Source: " + source);
JLabel originalReleaseLabel = new JLabel("Original release: " + original_release);
JLabel lastRevisedLabel = new JLabel("Last revised: " + last_revised);
// center
JTextArea overviewTextArea = new JTextArea();
overviewTextArea.setColumns(40);
overviewTextArea.setLineWrap(true);
overviewTextArea.setRows(5);
overviewTextArea.setWrapStyleWord(true);
overviewTextArea.setEditable(false);
overviewTextArea.setText(overview);
// footer elements
JLabel CVSS_score_num_label = new JLabel("CVSS Score: " + Float.toString(CVSS_score_num) + " " + CVSS_score_vector);
// place all elements
jf.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
// place title label
c.fill = GridBagConstraints.CENTER;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 3;
jf.getContentPane().add(titleLabel, c);
// place source label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 1;
jf.getContentPane().add(sourceLabel, c);
// place release label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 1;
c.gridy = 1;
c.gridwidth = 1;
jf.getContentPane().add(originalReleaseLabel, c);
// place last revised label
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 2;
c.gridy = 1;
c.gridwidth = 1;
jf.getContentPane().add(lastRevisedLabel, c);
// place overview text area
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 3;
jf.getContentPane().add(overviewTextArea, c);
// place CVSS score, if CVE entry is complete
if (!in_progress){
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 3;
c.gridwidth = 3;
jf.getContentPane().add(CVSS_score_num_label, c);
}
// pack and display window
jf.pack();
jf.setVisible(true);
}
});
}
/**
* Static function responsible for retrieving desired CVE entry and triggering all actions necessary to display it.
* Each entry is retrieved and parsed in seperate thread.
* @param cveNumber Wanted CVE entry number
*/
public static void getAndDisplay(String cveNumber){
// Spawn new thread for retrieval and parsing of CVE entry
Thread queryThread = new Thread() {
public void run() {
// build full url
String url = url_prefix+cveNumber;
try{
// Get desired website
Document page = Jsoup.connect(url).timeout(CVEList.TIMEOUT).get();
// parse retrieved website
EntryParser parser = new EntryParser();
Entry entry = parser.parse(page);
// display windows
entry.createAndDisplayGUI();
}
catch (IOException e){
log.error("Fetching failed for url: " + url + " " + e.getMessage());
log.error("Connection timed out.");
JOptionPane.showMessageDialog(new JFrame(), "Connection timed out for: " + url,"Connection timed out", JOptionPane.ERROR_MESSAGE);
}
catch (CVEParseException e){
log.error("Parsing failed for url: " + url + " " + e.getMessage());
JOptionPane.showMessageDialog(new JFrame(), "Parsing failed for: " + url,"Parsing failed", JOptionPane.ERROR_MESSAGE);
}
}
};
queryThread.start();
}
}