19 package org.sleuthkit.autopsy.modules.stix;
27 import java.util.List;
28 import java.util.ArrayList;
29 import org.mitre.cybox.common_2.ConditionApplicationEnum;
30 import org.mitre.cybox.common_2.ConditionTypeEnum;
32 import org.mitre.cybox.objects.Address;
37 class EvalAddressObj
extends EvaluatableObject {
39 private final Address obj;
41 public EvalAddressObj(Address a_obj, String a_id, String a_spacing) {
48 public synchronized ObservableResult evaluate() {
52 if (obj.getAddressValue() == null) {
53 return new ObservableResult(
id,
"AddressObject: No address value field found",
54 spacing, ObservableResult.ObservableState.INDETERMINATE, null);
57 String origAddressStr = obj.getAddressValue().getValue().toString();
61 if (((obj.getAddressValue().getApplyCondition() != null)
62 && (obj.getAddressValue().getApplyCondition() == ConditionApplicationEnum.NONE))) {
63 return new ObservableResult(
id,
"AddressObject: Can not process apply condition " + obj.getAddressValue().getApplyCondition().toString()
64 +
" on Address object", spacing, ObservableResult.ObservableState.INDETERMINATE, null);
68 setUnsupportedFieldWarnings();
70 Case case1 = Case.getCurrentCase();
71 SleuthkitCase sleuthkitCase = case1.getSleuthkitCase();
76 boolean everyPartMatched =
true;
77 List<BlackboardArtifact> combinedArts =
new ArrayList<BlackboardArtifact>();
78 String searchString =
"";
79 String[] parts = origAddressStr.split(
"##comma##");
81 for (String addressStr : parts) {
84 if (!searchString.isEmpty()) {
86 if ((obj.getAddressValue().getApplyCondition() != null)
87 && (obj.getAddressValue().getApplyCondition() == ConditionApplicationEnum.ALL)) {
88 searchString +=
" AND ";
90 searchString +=
" OR ";
93 searchString += addressStr;
95 if ((obj.getAddressValue().getCondition() == null)
96 || (obj.getAddressValue().getCondition() == ConditionTypeEnum.EQUALS)) {
97 List<BlackboardArtifact> arts = sleuthkitCase.getBlackboardArtifacts(
98 BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT,
99 BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD,
102 if (arts.isEmpty()) {
103 everyPartMatched =
false;
105 combinedArts.addAll(arts);
111 List<BlackboardArtifact> finalHits =
new ArrayList<BlackboardArtifact>();
114 List<BlackboardArtifact> artList
115 = sleuthkitCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT);
117 for (BlackboardArtifact art : artList) {
119 for (BlackboardAttribute attr : art.getAttributes()) {
120 if (attr.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD.getTypeID()) {
121 if (compareStringObject(addressStr, obj.getAddressValue().getCondition(),
122 obj.getAddressValue().getApplyCondition(), attr.getValueString())) {
129 if (finalHits.isEmpty()) {
130 everyPartMatched =
false;
132 combinedArts.addAll(finalHits);
138 if ((obj.getAddressValue().getApplyCondition() != null)
139 && (obj.getAddressValue().getApplyCondition() == ConditionApplicationEnum.ALL)
140 && (!everyPartMatched)) {
141 return new ObservableResult(
id,
"AddressObject: No matches for " + searchString,
142 spacing, ObservableResult.ObservableState.FALSE, null);
145 if (!combinedArts.isEmpty()) {
146 List<StixArtifactData> artData =
new ArrayList<StixArtifactData>();
147 for (BlackboardArtifact a : combinedArts) {
148 artData.add(
new StixArtifactData(a.getObjectID(), id,
"AddressObject"));
150 return new ObservableResult(
id,
"AddressObject: Found a match for " + searchString,
151 spacing, ObservableResult.ObservableState.TRUE, artData);
154 return new ObservableResult(
id,
"AddressObject: Found no matches for " + searchString,
155 spacing, ObservableResult.ObservableState.FALSE, null);
157 }
catch (TskCoreException ex) {
158 return new ObservableResult(
id,
"AddressObject: Exception during evaluation: " + ex.getLocalizedMessage(),
159 spacing, ObservableResult.ObservableState.INDETERMINATE, null);
166 private void setUnsupportedFieldWarnings() {
167 List<String> fieldNames =
new ArrayList<String>();
169 if (obj.getVLANName() != null) {
170 fieldNames.add(
"VLAN_Name");
172 if (obj.getVLANName() != null) {
173 fieldNames.add(
"VLAN_Num");
176 String warningStr =
"";
177 for (String name : fieldNames) {
178 if (!warningStr.isEmpty()) {
184 addWarning(
"Unsupported field(s): " + warningStr);