Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
EvalURIObj.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.modules.stix;
20 
22 import org.sleuthkit.datamodel.SleuthkitCase;
23 import org.sleuthkit.datamodel.BlackboardArtifact;
24 import org.sleuthkit.datamodel.BlackboardAttribute;
25 import org.sleuthkit.datamodel.TskCoreException;
26 
27 import java.util.List;
28 import java.util.ArrayList;
29 import org.mitre.cybox.common_2.ConditionApplicationEnum;
30 
31 import org.mitre.cybox.objects.URIObjectType;
32 
36 class EvalURIObj extends EvaluatableObject {
37 
38  private final URIObjectType obj;
39 
40  public EvalURIObj(URIObjectType a_obj, String a_id, String a_spacing) {
41  obj = a_obj;
42  id = a_id;
43  spacing = a_spacing;
44  }
45 
46  @Override
47  public synchronized ObservableResult evaluate() {
48 
49  setWarnings("");
50 
51  if (obj.getValue() == null) {
52  return new ObservableResult(id, "URIObject: No URI value field found", //NON-NLS
53  spacing, ObservableResult.ObservableState.INDETERMINATE, null);
54  }
55  String addressStr = obj.getValue().getValue().toString();
56 
57  // Strip off http:// or https://
58  String modifiedAddressStr = addressStr.toLowerCase();
59  modifiedAddressStr = modifiedAddressStr.replaceAll("http(s)?://", ""); //NON-NLS
60 
61  // Since we have single URL artifacts, ALL and NONE conditions probably don't make sense to test
62  if (!((obj.getValue().getApplyCondition() == null)
63  || (obj.getValue().getApplyCondition() == ConditionApplicationEnum.ANY))) {
64  return new ObservableResult(id, "URIObject: Can not process apply condition " + obj.getValue().getApplyCondition().toString() //NON-NLS
65  + " on URI object", spacing, ObservableResult.ObservableState.INDETERMINATE, null); //NON-NLS
66  }
67 
68  Case case1 = Case.getCurrentCase();
69  SleuthkitCase sleuthkitCase = case1.getSleuthkitCase();
70 
71  try {
72  /*
73  * if ((obj.getValue().getCondition() == null) ||
74  * (obj.getValue().getCondition() == ConditionTypeEnum.EQUALS)) {
75  *
76  * // Old version - uses a database query but only works on full
77  * strings. // It will be faster to use this in the "equals" case
78  * String[] parts = addressStr.split("##comma##");
79  * List<BlackboardArtifact> arts = new
80  * ArrayList<BlackboardArtifact>(); for (String part : parts) {
81  * arts.addAll(sleuthkitCase.getBlackboardArtifacts(
82  * BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT,
83  * BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD, part)); }
84  *
85  * if (!arts.isEmpty()) {
86  *
87  * List<StixArtifactData> artData = new
88  * ArrayList<StixArtifactData>(); for (BlackboardArtifact a : arts)
89  * { artData.add(new StixArtifactData(a.getObjectID(), id,
90  * "URIObject")); }
91  *
92  * return new ObservableResult(id, "URIObject: Found " + arts.size()
93  * + " matches for address = \"" + addressStr + "\"", spacing,
94  * ObservableResult.ObservableState.TRUE, artData);
95  *
96  * } else { return new ObservableResult(id, "URIObject: Found no
97  * matches for address = \"" + addressStr + "\"", spacing,
98  * ObservableResult.ObservableState.FALSE, null); } } else {
99  */
100 
101  // This is inefficient, but the easiest way to do it.
102  List<BlackboardArtifact> finalHits = new ArrayList<BlackboardArtifact>();
103 
104  // Get all the URL artifacts
105  List<BlackboardArtifact> artList
106  = sleuthkitCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT);
107 
108  for (BlackboardArtifact art : artList) {
109 
110  for (BlackboardAttribute attr : art.getAttributes()) {
111  if (attr.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD.getTypeID()) {
112 
113  String modifiedAttrString = attr.getValueString();
114  if (modifiedAttrString != null) {
115  modifiedAttrString = modifiedAttrString.toLowerCase();
116  modifiedAttrString = modifiedAttrString.replaceAll("http(s)?://", ""); //NON-NLS
117  }
118 
119  if (compareStringObject(modifiedAddressStr, obj.getValue().getCondition(),
120  obj.getValue().getApplyCondition(), modifiedAttrString)) {
121  finalHits.add(art);
122  }
123  }
124  }
125  }
126 
127  if (!finalHits.isEmpty()) {
128  List<StixArtifactData> artData = new ArrayList<StixArtifactData>();
129  for (BlackboardArtifact a : finalHits) {
130  artData.add(new StixArtifactData(a.getObjectID(), id, "UriObject")); //NON-NLS
131  }
132  return new ObservableResult(id, "UriObject: Found a match for " + addressStr, //NON-NLS
133  spacing, ObservableResult.ObservableState.TRUE, artData);
134  }
135 
136  return new ObservableResult(id, "URIObject: Found no matches for " + addressStr, //NON-NLS
137  spacing, ObservableResult.ObservableState.FALSE, null);
138  /*
139  * }
140  */
141 
142  } catch (TskCoreException ex) {
143  return new ObservableResult(id, "URIObject: Exception during evaluation: " + ex.getLocalizedMessage(), //NON-NLS
144  spacing, ObservableResult.ObservableState.INDETERMINATE, null);
145  }
146 
147  }
148 
149 }

Copyright © 2012-2016 Basis Technology. Generated on: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.