Skip to content

Commit 96410a8

Browse files
committed
Merge pull request #76 from Fuzion24/feature/vulnerability_sorting
Matches Vulnerability results with their descriptions and allows filtering sorting
2 parents 3da9877 + d7319c4 commit 96410a8

File tree

5 files changed

+203
-99
lines changed

5 files changed

+203
-99
lines changed

app/src/main/assets/vuln_map.json

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"https://github.com/torvalds/linux/commit/a134f083e79fb4c3d0a925691e732c56911b4326"
1616
],
1717
"cvssv2": 4.9,
18-
"cvedate": "2012-04-21"
18+
"cvedate": "08/05/2015"
1919
},
2020
"CVE-2014-4943": {
2121
"cve": "CVE-2014-4943",
@@ -32,7 +32,7 @@
3232
"patch": [
3333
"https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=3cf521f7dc87c031617fd47e4b7aa2593c2f3daf"
3434
],
35-
"cvedate": "2015-08-05"
35+
"cvedate": "07/19/2014"
3636
},
3737
"CVE-2015-1528": {
3838
"cve": "CVE-2015-1528",
@@ -67,7 +67,7 @@
6767
"patch": [
6868
"https://android.googlesource.com/platform/libcore/+/2bc5e811a817a8c667bca4318ae98582b0ee6dc6"
6969
],
70-
"cvedate": ""
70+
"cvedate": "08/01/2014"
7171
},
7272
"CVE-2015-6602": {
7373
"cve": "CVE-2015-6602",
@@ -138,10 +138,11 @@
138138
],
139139
"cvedate": "08/10/2015"
140140
},
141-
"ZipBug 8219321": {
142-
"cve": "ZipBug 8219321",
141+
"CVE-2013-4787": {
142+
"cve": "CVE-2013-4787",
143143
"altnames": [
144-
"Masterkey"
144+
"Masterkey",
145+
"ZipBug 8219321"
145146
],
146147
"description": "Zip bug allows modifying apk files without breaking the signature. Essentially, you can replace existing files in an app. Fixed around Android 4.4",
147148
"impact": "A local attacker can modify a system apk file and gain elevated privileges. A remote attacker can try to trick the user (or another app) into installing the malicious apk file.",
@@ -256,41 +257,7 @@
256257
"__comment": "calculated using (AV:N/AC:L/AU:N/C:P/I:P/A:C/E:ND/RL:ND/RC:ND/CDP:ND/TD:ND/CR:ND/IR:ND/AR:ND). ",
257258
"cvssv2": 9.0,
258259
"patch": [],
259-
"cvedate": ""
260-
},
261-
"StumpRoot": {
262-
"cve": "StumpRoot",
263-
"altnames": [
264-
""
265-
],
266-
"description": "",
267-
"impact": "",
268-
"external_links": [
269-
"",
270-
""
271-
],
272-
"cvssv2": 0,
273-
"patch": [
274-
""
275-
],
276-
"cvedate": ""
277-
},
278-
"WeakSauce": {
279-
"cve": "WeakSauce",
280-
"altnames": [
281-
""
282-
],
283-
"description": "",
284-
"impact": "",
285-
"external_links": [
286-
"",
287-
""
288-
],
289-
"cvssv2": 0,
290-
"patch": [
291-
""
292-
],
293-
"cvedate": ""
260+
"cvedate": "10/27/2015"
294261
},
295262
"CVE-2011-3874": {
296263
"cve": "CVE-2011-3874",
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package fuzion24.device.vulnerability.test;
2+
3+
import android.content.Context;
4+
5+
import org.json.JSONArray;
6+
import org.json.JSONObject;
7+
8+
import java.text.SimpleDateFormat;
9+
import java.util.ArrayList;
10+
import java.util.Date;
11+
import java.util.HashMap;
12+
import java.util.Iterator;
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
import fuzion24.device.vulnerability.vulnerabilities.VulnerabilityTest;
17+
import fuzion24.device.vulnerability.vulnerabilities.helper.BinaryAssets;
18+
19+
/**
20+
* Created by fuzion24 on 11/23/15.
21+
*/
22+
public class VulnerabilityDescriptor {
23+
24+
25+
private final String CVEorID;
26+
private final String description;
27+
private final String impact;
28+
private final Double CVSSV2Score;
29+
private final Date CVEDate;
30+
private final List<String> externalLinks;
31+
private final List<String> altNames;
32+
private final List<String> patches;
33+
34+
private VulnerabilityDescriptor(String cve,
35+
String desc,
36+
String impact,
37+
Double cvssv2,
38+
String cveDate,
39+
List<String> externLinks,
40+
List<String> altNames,
41+
List<String> patches) throws Exception {
42+
this.CVEorID = cve;
43+
this.description = desc;
44+
this.impact = impact;
45+
this.CVSSV2Score = cvssv2;
46+
this.externalLinks = externLinks;
47+
this.altNames = altNames;
48+
this.patches = patches;
49+
50+
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
51+
Date d = sdf.parse(cveDate);
52+
this.CVEDate = d;
53+
}
54+
55+
56+
private static List<String> extractStringArray(JSONObject obj, String arrayName) throws Exception {
57+
JSONArray jsonStringArray = obj.getJSONArray(arrayName);
58+
List<String> items = new ArrayList<String>();
59+
for (int i = 0; i < jsonStringArray.length(); i++) {
60+
items.add(jsonStringArray.getString(i));
61+
}
62+
return items;
63+
}
64+
65+
66+
public static Map<String, VulnerabilityDescriptor> getParsedVulnMap(Context ctx) throws Exception {
67+
String jsonVulns = BinaryAssets.extractAsset(ctx, "vuln_map.json");
68+
JSONObject vulnMap = new JSONObject(jsonVulns);
69+
70+
Map<String, VulnerabilityDescriptor> descriptorMap = new HashMap<String, VulnerabilityDescriptor>();
71+
Iterator<String> keys = vulnMap.keys();
72+
73+
while (keys.hasNext()) {
74+
JSONObject jobj = null;
75+
String description = null;
76+
String impact = null;
77+
Double cvssV2Score = null;
78+
String cveDate = null;
79+
List<String> externalLinks = null;
80+
List<String> altNames = null;
81+
List<String> patches = null;
82+
83+
String key = keys.next();
84+
jobj = vulnMap.getJSONObject(key);
85+
String cve = jobj.getString("cve");
86+
altNames = extractStringArray(jobj, "altnames");
87+
description = jobj.getString("description");
88+
impact = jobj.getString("impact");
89+
externalLinks = extractStringArray(jobj, "external_links");
90+
cvssV2Score = jobj.getDouble("cvssv2");
91+
patches = extractStringArray(jobj, "patch");
92+
cveDate = jobj.getString("cvedate");
93+
94+
VulnerabilityDescriptor vd = new VulnerabilityDescriptor(
95+
cve,
96+
description,
97+
impact,
98+
cvssV2Score,
99+
cveDate,
100+
externalLinks,
101+
altNames,
102+
patches);
103+
104+
descriptorMap.put(key, vd);
105+
}
106+
107+
return descriptorMap;
108+
}
109+
110+
111+
public String getCVEorID() {
112+
return CVEorID;
113+
}
114+
115+
public String getDescription() {
116+
return description;
117+
}
118+
119+
public String getImpact() {
120+
return impact;
121+
}
122+
123+
public Double getCVSSV2Score() {
124+
return CVSSV2Score;
125+
}
126+
127+
public Date getCVEDate() {
128+
return CVEDate;
129+
}
130+
131+
public List<String> getExternalLinks() {
132+
return externalLinks;
133+
}
134+
135+
public List<String> getAltNames() {
136+
return altNames;
137+
}
138+
139+
public List<String> getPatches() {
140+
return patches;
141+
}
142+
143+
144+
145+
}

app/src/main/java/fuzion24/device/vulnerability/test/adapter/RecyclerAdapter.java

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import android.graphics.Color;
55
import android.support.v7.widget.RecyclerView;
66
import android.text.TextUtils;
7+
import android.util.Log;
8+
import android.util.Pair;
79
import android.view.LayoutInflater;
810
import android.view.View;
911
import android.view.ViewGroup;
@@ -14,28 +16,52 @@
1416
import org.json.JSONObject;
1517

1618
import java.util.ArrayList;
19+
import java.util.Collection;
20+
import java.util.Collections;
21+
import java.util.Comparator;
22+
import java.util.Iterator;
1723
import java.util.List;
24+
import java.util.Map;
1825

26+
import fuzion24.device.vulnerability.test.VulnerabilityDescriptor;
1927
import fuzion24.device.vulnerability.test.VulnerabilityTestResult;
2028
import fuzion24.device.vulnerability.test.adapter.viewholder.RecyclerItemViewHolder;
2129
import fuzion24.device.vulnerability.vulnerabilities.helper.BinaryAssets;
2230

2331
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
2432

25-
private List<VulnerabilityTestResult> mResults;
33+
private static final String TAG = "RecycleAdapter";
34+
final private List<Pair<VulnerabilityTestResult, VulnerabilityDescriptor>> mResults;
2635
private Context mContext;
27-
private JSONObject mVulnMap;
2836

2937
public RecyclerAdapter(Context context, List<VulnerabilityTestResult> itemList) {
3038
this.mContext = context;
31-
this.mResults = itemList;
39+
List<Pair<VulnerabilityTestResult, VulnerabilityDescriptor>> res = new ArrayList<>();
3240

3341
try {
34-
String jsonVulns = BinaryAssets.extractAsset(context, "vuln_map.json");
35-
mVulnMap = new JSONObject(jsonVulns);
36-
} catch (Exception e) {
42+
Map<String, VulnerabilityDescriptor> vMap = VulnerabilityDescriptor.getParsedVulnMap(context);
43+
44+
for (VulnerabilityTestResult vtr : itemList) {
45+
String cveOrId = vtr.getCVEorID();
46+
VulnerabilityDescriptor vd = vMap.get(cveOrId);
47+
if(vd == null){
48+
Log.d(TAG, cveOrId + " has a null vulnerability descriptor");
49+
}
50+
res.add(Pair.create(vtr, vd));
51+
}
52+
53+
Collections.sort(res, new Comparator<Pair<VulnerabilityTestResult, VulnerabilityDescriptor>>() {
54+
@Override
55+
public int compare(Pair<VulnerabilityTestResult, VulnerabilityDescriptor> lhs, Pair<VulnerabilityTestResult, VulnerabilityDescriptor> rhs) {
56+
VulnerabilityDescriptor lhDesc = lhs.second;
57+
VulnerabilityDescriptor rhDesc = rhs.second;
58+
return lhDesc.getCVEDate().before(rhDesc.getCVEDate()) ? 1 : -1;
59+
}
60+
});
61+
}catch(Exception e){
3762
e.printStackTrace();
3863
}
64+
mResults = res;
3965
}
4066

4167
@Override
@@ -46,52 +72,23 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType
4672
return RecyclerItemViewHolder.newInstance(view);
4773
}
4874

49-
private List<String> extractStringArray(JSONObject obj, String arrayName) throws Exception {
50-
JSONArray jsonStringArray = obj.getJSONArray(arrayName);
51-
List<String> items = new ArrayList<String>();
52-
for (int i = 0; i < jsonStringArray.length(); i++) {
53-
items.add(jsonStringArray.getString(i));
54-
}
55-
return items;
56-
}
5775

5876
@Override
5977
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
6078
RecyclerItemViewHolder holder = (RecyclerItemViewHolder) viewHolder;
61-
VulnerabilityTestResult item = mResults.get(position);
79+
Pair<VulnerabilityTestResult, VulnerabilityDescriptor> item = mResults.get(position);
6280

63-
holder.setItemTestName(item.getCVEorID());
81+
VulnerabilityTestResult vulnRes = item.first;
82+
VulnerabilityDescriptor vulnDesc = item.second;
6483

65-
JSONObject jobj = null;
66-
String description = null;
67-
String impact = null;
68-
Double cvssV2Score = null;
69-
String cveDate = null;
70-
List<String> externalLinks = null;
71-
List<String> altNames = null;
72-
List<String> patches = null;
84+
holder.setItemTestName(vulnRes.getCVEorID());
7385

74-
try {
75-
jobj = mVulnMap.getJSONObject(item.getCVEorID());
76-
String cve = jobj.getString("cve");
77-
altNames = extractStringArray(jobj, "altnames");
78-
description = jobj.getString("description");
79-
impact = jobj.getString("impact");
80-
externalLinks = extractStringArray(jobj, "external_links");
81-
cvssV2Score = jobj.getDouble("cvssv2");
82-
patches = extractStringArray(jobj, "patch");
83-
cveDate = jobj.getString("cvedate");
84-
85-
} catch (Exception e) {
86-
//We dont have an entry or are missing necessary components of it
87-
e.printStackTrace();
88-
}
8986

90-
if (item.getException() != null) {
91-
holder.setItemTestResult(mContext.getString(R.string.error_test, item.getException().getMessage()));
87+
if (vulnRes.getException() != null) {
88+
holder.setItemTestResult(mContext.getString(R.string.error_test, vulnRes.getException().getMessage()));
9289
holder.setItemTestResultColor(mContext.getResources().getColor(R.color.orange));
9390
} else {
94-
if (item.getResult()) {
91+
if (vulnRes.getResult()) {
9592
holder.setItemTestResultColor(mContext.getResources().getColor(R.color.red));
9693
holder.setItemTestResult(mContext.getString(R.string.test_result_failure));
9794
} else {
@@ -100,19 +97,16 @@ public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
10097
}
10198
}
10299

103-
if (!TextUtils.isEmpty(description)) {
104-
holder.setItemTestResultDescription(description);
105-
holder.setButtonShowDetailsClickListner(mContext, item.getCVEorID(), altNames, description, impact, externalLinks, patches, cvssV2Score, cveDate);
106-
} else {
107-
holder.setItemTestResultDescription(mContext.getString(R.string.information_not_available));
108-
109-
if (jobj != null) {
110-
holder.setButtonShowDetailsClickListner(mContext, item.getCVEorID(), altNames, description, impact, externalLinks, patches, cvssV2Score, cveDate);
111-
} else {
112-
holder.setButtonShowDetailsClickListner(mContext, item.getCVEorID());
113-
}
114-
}
115-
100+
holder.setItemTestResultDescription(vulnDesc.getDescription());
101+
holder.setButtonShowDetailsClickListner(mContext,
102+
vulnRes.getCVEorID(),
103+
vulnDesc.getAltNames(),
104+
vulnDesc.getDescription(),
105+
vulnDesc.getImpact(),
106+
vulnDesc.getExternalLinks(),
107+
vulnDesc.getPatches(),
108+
vulnDesc.getCVSSV2Score(),
109+
vulnDesc.getCVEDate().toString());
116110
}
117111

118112
@Override

app/src/main/java/fuzion24/device/vulnerability/vulnerabilities/framework/media/CVE_2015_6608.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
1|shell@flounder_lte:/ $ grep -F "b/23881715" /system/lib64/libstagefright.so
3030
*/
3131

32-
33-
3432
public class CVE_2015_6608 implements VulnerabilityTest {
3533

3634
private static final String TAG = "CVE-2015-6608";

0 commit comments

Comments
 (0)