Sleuth Kit Java Bindings (JNI)  4.6
Java bindings for using The Sleuth Kit
WebBrowserArtifactsHelper.java
Go to the documentation of this file.
1 /*
2  * Sleuth Kit Data Model
3  *
4  * Copyright 2019 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.datamodel.blackboardutils;
20 
21 import java.net.MalformedURLException;
22 import java.net.URL;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.StringTokenizer;
27 import org.apache.commons.lang3.StringUtils;
35 
43 public final class WebBrowserArtifactsHelper extends ArtifactHelperBase {
44 
53  public WebBrowserArtifactsHelper(SleuthkitCase caseDb, String moduleName, Content srcContent) {
54  super(caseDb, moduleName, srcContent);
55  }
56 
71  public BlackboardArtifact addWebBookmark(String url, String title, long creationTime, String progName) throws TskCoreException, BlackboardException {
72  return addWebBookmark(url, title, creationTime, progName,
73  Collections.emptyList());
74  }
75 
91  public BlackboardArtifact addWebBookmark(String url, String title, long creationTime, String progName,
92  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
93 
94  BlackboardArtifact bookMarkArtifact;
95  Collection<BlackboardAttribute> attributes = new ArrayList<>();
96 
97  // create artifact
98  bookMarkArtifact = getContent().newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_BOOKMARK);
99 
100  // construct attributes
101  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, getModuleName(), url));
102 
103  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED, creationTime, attributes);
104  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE, title, attributes);
105  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN, extractDomain(url), attributes);
106  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, progName, attributes);
107 
108  // add attributes to artifact
109  attributes.addAll(otherAttributesList);
110  bookMarkArtifact.addAttributes(attributes);
111 
112  // post artifact
113  getSleuthkitCase().getBlackboard().postArtifact(bookMarkArtifact, getModuleName());
114 
115  // return the artifact
116  return bookMarkArtifact;
117  }
118 
134  public BlackboardArtifact addWebCookie(String url, long creationTime,
135  String name, String value, String programName) throws TskCoreException, BlackboardException {
136 
137  return addWebCookie(url, creationTime, name, value, programName,
138  Collections.emptyList());
139  }
140 
160  public BlackboardArtifact addWebCookie(String url,
161  long creationTime, String name, String value, String programName,
162  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
163 
164  BlackboardArtifact cookieArtifact;
165  Collection<BlackboardAttribute> attributes = new ArrayList<>();
166 
167  // create artifact
168  cookieArtifact = getContent().newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_COOKIE);
169 
170  // construct attributes
171  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, getModuleName(), url));
172 
173  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, creationTime, attributes);
174  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, name, attributes);
175  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_VALUE, value, attributes);
176  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN, extractDomain(url), attributes);
177  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, programName, attributes);
178 
179  // add attributes to artifact
180  attributes.addAll(otherAttributesList);
181  cookieArtifact.addAttributes(attributes);
182 
183  // post artifact
184  getSleuthkitCase().getBlackboard().postArtifact(cookieArtifact, getModuleName());
185 
186  // return the artifact
187  return cookieArtifact;
188  }
189 
204  public BlackboardArtifact addWebDownload(String url, long startTime, String path, String programName) throws TskCoreException, BlackboardException {
205  return addWebDownload(path, startTime, url, programName, Collections.emptyList());
206  }
207 
223  public BlackboardArtifact addWebDownload(String url, long startTime, String path, String programName,
224  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
225 
226  BlackboardArtifact webDownloadArtifact;
227  Collection<BlackboardAttribute> attributes = new ArrayList<>();
228 
229  // reate artifact
230  webDownloadArtifact = getContent().newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD);
231 
232  // construct attributes
233  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH, getModuleName(), path));
234  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, getModuleName(), url));
235 
236  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED, startTime, attributes);
237  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, programName, attributes);
238  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN, extractDomain(url), attributes);
239 
240  // add attributes to artifact
241  attributes.addAll(otherAttributesList);
242  webDownloadArtifact.addAttributes(attributes);
243 
244  // post artifact
245  getSleuthkitCase().getBlackboard().postArtifact(webDownloadArtifact, getModuleName());
246 
247  // return the artifact
248  return webDownloadArtifact;
249  }
250 
267  public BlackboardArtifact addWebFormAddress(String personName, String email,
268  String phoneNumber, String mailingAddress,
269  long creationTime, long accessTime, int count) throws TskCoreException, BlackboardException {
270  return addWebFormAddress(personName, email, phoneNumber,
271  mailingAddress, creationTime, accessTime, count,
272  Collections.emptyList());
273  }
274 
292  public BlackboardArtifact addWebFormAddress(String personName, String email,
293  String phoneNumber, String mailingAddress,
294  long creationTime, long accessTime, int count,
295  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
296 
297  BlackboardArtifact webFormAddressArtifact;
298  Collection<BlackboardAttribute> attributes = new ArrayList<>();
299 
300  // create artifact
301  webFormAddressArtifact = getContent().newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_FORM_ADDRESS);
302 
303  // construct attributes
304  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, getModuleName(), personName));
305 
306  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL, email, attributes);
307  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER, phoneNumber, attributes);
308  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION, mailingAddress, attributes);
309 
310  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED, creationTime, attributes);
311  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED, accessTime, attributes);
312  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COUNT, count, attributes);
313 
314  // add artifact
315  attributes.addAll(otherAttributesList);
316  webFormAddressArtifact.addAttributes(attributes);
317 
318  // post artifact
319  getSleuthkitCase().getBlackboard().postArtifact(webFormAddressArtifact, getModuleName());
320 
321  // return the artifact
322  return webFormAddressArtifact;
323  }
324 
339  public BlackboardArtifact addWebFormAutofill(String name, String value,
340  long creationTime, long accessTime, int count) throws TskCoreException, BlackboardException {
341  return addWebFormAutofill(name, value, creationTime, accessTime, count,
342  Collections.emptyList());
343  }
344 
362  public BlackboardArtifact addWebFormAutofill(String name, String value,
363  long creationTime, long accessTime, int count,
364  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
365  BlackboardArtifact webFormAutofillArtifact;
366  Collection<BlackboardAttribute> attributes = new ArrayList<>();
367 
368  // create artifact
369  webFormAutofillArtifact = getContent().newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_FORM_AUTOFILL);
370 
371  // construct attributes
372  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, getModuleName(), name));
373  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_VALUE, getModuleName(), value));
374 
375  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED, creationTime, attributes);
376  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED, accessTime, attributes);
377  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COUNT, count, attributes);
378 
379  // add attributes to artifact
380  attributes.addAll(otherAttributesList);
381  webFormAutofillArtifact.addAttributes(attributes);
382 
383  // post artifact
384  getSleuthkitCase().getBlackboard().postArtifact(webFormAutofillArtifact, getModuleName());
385 
386  // return the artifact
387  return webFormAutofillArtifact;
388  }
389 
405  public BlackboardArtifact addWebHistory(String url, long accessTime,
406  String referrer, String title, String programName) throws TskCoreException, BlackboardException {
407  return addWebHistory(url, accessTime, referrer, title, programName,
408  Collections.emptyList());
409  }
410 
427  public BlackboardArtifact addWebHistory(String url, long accessTime,
428  String referrer, String title, String programName,
429  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
430 
431  BlackboardArtifact webHistoryArtifact;
432  Collection<BlackboardAttribute> attributes = new ArrayList<>();
433 
434  // create artifact
435  webHistoryArtifact = getContent().newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_HISTORY);
436 
437  // construct attributes
438  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, getModuleName(), url));
439 
440  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED, accessTime, attributes);
441  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE, title, attributes);
442  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_REFERRER, referrer, attributes);
443 
444  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, programName, attributes);
445  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN, extractDomain(url), attributes);
446 
447  // add attributes to artifact
448  attributes.addAll(otherAttributesList);
449  webHistoryArtifact.addAttributes(attributes);
450 
451  // post artifact
452  getSleuthkitCase().getBlackboard().postArtifact(webHistoryArtifact, getModuleName());
453 
454  // return the artifact
455  return webHistoryArtifact;
456  }
457 
458  // TBD: this is duplicated in Autopsy.
459  // We should move this to new Util class in TSK, and have Autopsy delegate to it.
468  private static String extractDomain(String urlString) {
469  if (urlString == null) {
470  return "";
471  }
472  String result;
473 
474  try {
475  URL url = new URL(urlString);
476  result = url.getHost();
477  } catch (MalformedURLException ex) {
478  // not a valid URL - we will try to extract it ourselves
479  result = null;
480  }
481 
482  //was not a valid URL, try a less picky method
483  if (result == null || StringUtils.isBlank(result)) {
484  return getBaseDomain(urlString);
485  }
486  return result;
487  }
488 
496  private static String getBaseDomain(String url) {
497  String host;
498 
499  //strip protocol
500  String cleanUrl = url.replaceFirst(".*:\\/\\/", "");
501 
502  //strip after slashes
503  String dirToks[] = cleanUrl.split("\\/");
504  if (dirToks.length > 0) {
505  host = dirToks[0];
506  } else {
507  host = cleanUrl;
508  }
509 
510  //get the domain part from host (last 2)
511  StringTokenizer tok = new StringTokenizer(host, ".");
512  StringBuilder hostB = new StringBuilder();
513  int toks = tok.countTokens();
514 
515  for (int count = 0; count < toks; ++count) {
516  String part = tok.nextToken();
517  int diff = toks - count;
518  if (diff < 3) {
519  hostB.append(part);
520  }
521  if (diff == 2) {
522  hostB.append('.');
523  }
524  }
525 
526  String base = hostB.toString();
527  // verify there are no special characters in there
528  if (base.matches(".*[~`!@#$%^&\\*\\(\\)\\+={}\\[\\];:\\?<>,/ ].*")) {
529  return "";
530  }
531 
532  //verify that the base domain actually has a '.', details JIRA-4609
533  if (!base.contains(".")) {
534  return "";
535  }
536 
537  return base;
538  }
539 }
BlackboardArtifact addWebDownload(String url, long startTime, String path, String programName)
BlackboardArtifact addWebBookmark(String url, String title, long creationTime, String progName)
BlackboardArtifact addWebDownload(String url, long startTime, String path, String programName, Collection< BlackboardAttribute > otherAttributesList)
BlackboardArtifact addWebFormAddress(String personName, String email, String phoneNumber, String mailingAddress, long creationTime, long accessTime, int count)
BlackboardArtifact addWebHistory(String url, long accessTime, String referrer, String title, String programName, Collection< BlackboardAttribute > otherAttributesList)
BlackboardArtifact addWebCookie(String url, long creationTime, String name, String value, String programName, Collection< BlackboardAttribute > otherAttributesList)
BlackboardArtifact addWebHistory(String url, long accessTime, String referrer, String title, String programName)
BlackboardArtifact newArtifact(int artifactTypeID)
BlackboardArtifact addWebFormAutofill(String name, String value, long creationTime, long accessTime, int count)
BlackboardArtifact addWebFormAutofill(String name, String value, long creationTime, long accessTime, int count, Collection< BlackboardAttribute > otherAttributesList)
BlackboardArtifact addWebBookmark(String url, String title, long creationTime, String progName, Collection< BlackboardAttribute > otherAttributesList)
BlackboardArtifact addWebCookie(String url, long creationTime, String name, String value, String programName)
WebBrowserArtifactsHelper(SleuthkitCase caseDb, String moduleName, Content srcContent)
BlackboardArtifact addWebFormAddress(String personName, String email, String phoneNumber, String mailingAddress, long creationTime, long accessTime, int count, Collection< BlackboardAttribute > otherAttributesList)

Copyright © 2011-2018 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.