Sleuth Kit Java Bindings (JNI)  4.10.2
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-2020 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 java.util.logging.Level;
28 import java.util.logging.Logger;
29 import org.apache.commons.lang3.StringUtils;
40 
48 public final class WebBrowserArtifactsHelper extends ArtifactHelperBase {
49 
50  private static final Logger LOGGER = Logger.getLogger(WebBrowserArtifactsHelper.class.getName());
55  private static final BlackboardArtifact.Type WEB_FORM_AUTOFILL_TYPE = new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_FORM_AUTOFILL);
57 
66  public WebBrowserArtifactsHelper(SleuthkitCase caseDb, String moduleName, Content srcContent) {
67  super(caseDb, moduleName, srcContent);
68  }
69 
84  public BlackboardArtifact addWebBookmark(String url, String title, long creationTime, String progName) throws TskCoreException, BlackboardException {
85  return addWebBookmark(url, title, creationTime, progName,
86  Collections.emptyList());
87  }
88 
104  public BlackboardArtifact addWebBookmark(String url, String title, long creationTime, String progName,
105  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
106 
107  Collection<BlackboardAttribute> attributes = new ArrayList<>();
108 
109  // construct attributes
110  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, getModuleName(), url));
111 
112  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED, creationTime, attributes);
113  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE, title, attributes);
114  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN, extractDomain(url), attributes);
115  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, progName, attributes);
116 
117  // add attributes to artifact
118  attributes.addAll(otherAttributesList);
119 
120  Content content = getContent();
121  BlackboardArtifact bookMarkArtifact = content.newDataArtifact(WEB_BOOKMARK_TYPE, attributes);
122 
123  // post artifact
124  getSleuthkitCase().getBlackboard().postArtifact(bookMarkArtifact, getModuleName());
125 
126  // return the artifact
127  return bookMarkArtifact;
128  }
129 
145  public BlackboardArtifact addWebCookie(String url, long creationTime,
146  String name, String value, String programName) throws TskCoreException, BlackboardException {
147 
148  return addWebCookie(url, creationTime, name, value, programName,
149  Collections.emptyList());
150  }
151 
171  public BlackboardArtifact addWebCookie(String url,
172  long creationTime, String name, String value, String programName,
173  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
174 
175  Collection<BlackboardAttribute> attributes = new ArrayList<>();
176 
177  // construct attributes
178  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, getModuleName(), url));
179 
180  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, creationTime, attributes);
181  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, name, attributes);
182  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_VALUE, value, attributes);
183  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN, extractDomain(url), attributes);
184  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, programName, attributes);
185 
186  // add attributes to artifact
187  attributes.addAll(otherAttributesList);
188 
189  Content content = getContent();
190  BlackboardArtifact cookieArtifact = content.newDataArtifact(WEB_COOKIE_TYPE, attributes);
191 
192  // post artifact
193  getSleuthkitCase().getBlackboard().postArtifact(cookieArtifact, getModuleName());
194 
195  // return the artifact
196  return cookieArtifact;
197  }
198 
213  public BlackboardArtifact addWebDownload(String url, long startTime, String path, String programName) throws TskCoreException, BlackboardException {
214  return addWebDownload(path, startTime, url, programName, Collections.emptyList());
215  }
216 
232  public BlackboardArtifact addWebDownload(String url, long startTime, String path, String programName,
233  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
234 
235  Collection<BlackboardAttribute> attributes = new ArrayList<>();
236 
237  // construct attributes
238  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH, getModuleName(), path));
239  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, getModuleName(), url));
240 
241  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED, startTime, attributes);
242  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, programName, attributes);
243  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN, extractDomain(url), attributes);
244 
245  // add attributes to artifact
246  attributes.addAll(otherAttributesList);
247 
248  Content content = getContent();
249  BlackboardArtifact webDownloadArtifact = content.newDataArtifact(WEB_DOWNLOAD_TYPE, attributes);
250 
251  // post artifact
252  getSleuthkitCase().getBlackboard().postArtifact(webDownloadArtifact, getModuleName());
253 
254  // return the artifact
255  return webDownloadArtifact;
256  }
257 
274  public BlackboardArtifact addWebFormAddress(String personName, String email,
275  String phoneNumber, String mailingAddress,
276  long creationTime, long accessTime, int count) throws TskCoreException, BlackboardException {
277  return addWebFormAddress(personName, email, phoneNumber,
278  mailingAddress, creationTime, accessTime, count,
279  Collections.emptyList());
280  }
281 
299  public BlackboardArtifact addWebFormAddress(String personName, String email,
300  String phoneNumber, String mailingAddress,
301  long creationTime, long accessTime, int count,
302  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
303 
304  Collection<BlackboardAttribute> attributes = new ArrayList<>();
305 
306  CommunicationsManager commManager = this.getSleuthkitCase().getCommunicationsManager();
307 
308  if (StringUtils.isNotEmpty(email)) {
309  try {
310  commManager.createAccountFileInstance(Account.Type.EMAIL, email, this.getModuleName(), this.getContent());
311  } catch (InvalidAccountIDException ex) {
312  LOGGER.log(Level.WARNING, String.format("Invalid account identifier %s", email), ex);
313  }
314  }
315 
316  if(StringUtils.isNotEmpty(phoneNumber)) {
317  try {
318  commManager.createAccountFileInstance(Account.Type.PHONE, phoneNumber, this.getModuleName(), this.getContent());
319  } catch (InvalidAccountIDException ex) {
320  LOGGER.log(Level.WARNING, String.format("Invalid account identifier %s", phoneNumber), ex);
321  }
322  }
323 
324  // construct attributes
325  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, getModuleName(), personName));
326 
327  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL, email, attributes);
328  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER, phoneNumber, attributes);
329  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION, mailingAddress, attributes);
330 
331  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED, creationTime, attributes);
332  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED, accessTime, attributes);
333  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COUNT, count, attributes);
334 
335  // add artifact
336  Content content = getContent();
337  BlackboardArtifact webFormAddressArtifact = content.newDataArtifact(WEB_FORM_ADDRESS_TYPE, attributes);
338 
339  // post artifact
340  getSleuthkitCase().getBlackboard().postArtifact(webFormAddressArtifact, getModuleName());
341 
342  // return the artifact
343  return webFormAddressArtifact;
344  }
345 
360  public BlackboardArtifact addWebFormAutofill(String name, String value,
361  long creationTime, long accessTime, int count) throws TskCoreException, BlackboardException {
362  return addWebFormAutofill(name, value, creationTime, accessTime, count,
363  Collections.emptyList());
364  }
365 
383  public BlackboardArtifact addWebFormAutofill(String name, String value,
384  long creationTime, long accessTime, int count,
385  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
386 
387  Collection<BlackboardAttribute> attributes = new ArrayList<>();
388 
389  // construct attributes
390  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, getModuleName(), name));
391  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_VALUE, getModuleName(), value));
392 
393  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED, creationTime, attributes);
394  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED, accessTime, attributes);
395  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COUNT, count, attributes);
396 
397  // add attributes to artifact
398  attributes.addAll(otherAttributesList);
399 
400  Content content = getContent();
401  BlackboardArtifact webFormAutofillArtifact = content.newDataArtifact(WEB_FORM_AUTOFILL_TYPE, attributes);
402 
403  // post artifact
404  getSleuthkitCase().getBlackboard().postArtifact(webFormAutofillArtifact, getModuleName());
405 
406  // return the artifact
407  return webFormAutofillArtifact;
408  }
409 
425  public BlackboardArtifact addWebHistory(String url, long accessTime,
426  String referrer, String title, String programName) throws TskCoreException, BlackboardException {
427  return addWebHistory(url, accessTime, referrer, title, programName,
428  Collections.emptyList());
429  }
430 
447  public BlackboardArtifact addWebHistory(String url, long accessTime,
448  String referrer, String title, String programName,
449  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
450 
451  Collection<BlackboardAttribute> attributes = new ArrayList<>();
452 
453  // construct attributes
454  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, getModuleName(), url));
455 
456  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED, accessTime, attributes);
457  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE, title, attributes);
458  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_REFERRER, referrer, attributes);
459 
460  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, programName, attributes);
461  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN, extractDomain(url), attributes);
462 
463  // add attributes to artifact
464  attributes.addAll(otherAttributesList);
465 
466  Content content = getContent();
467  BlackboardArtifact webHistoryArtifact = content.newDataArtifact(WEB_HISTORY_TYPE, attributes);
468 
469  // post artifact
470  getSleuthkitCase().getBlackboard().postArtifact(webHistoryArtifact, getModuleName());
471 
472  // return the artifact
473  return webHistoryArtifact;
474  }
475 
476  // TBD: this is duplicated in Autopsy.
477  // We should move this to new Util class in TSK, and have Autopsy delegate to it.
486  private static String extractDomain(String urlString) {
487  if (urlString == null) {
488  return "";
489  }
490  String result;
491 
492  try {
493  URL url = new URL(urlString);
494  result = url.getHost();
495  } catch (MalformedURLException ex) {
496  // not a valid URL - we will try to extract it ourselves
497  result = null;
498  }
499 
500  //was not a valid URL, try a less picky method
501  if (result == null || StringUtils.isBlank(result)) {
502  return getBaseDomain(urlString);
503  }
504  return result;
505  }
506 
514  private static String getBaseDomain(String url) {
515  String host;
516 
517  //strip protocol
518  String cleanUrl = url.replaceFirst(".*:\\/\\/", "");
519 
520  //strip after slashes
521  String dirToks[] = cleanUrl.split("\\/");
522  if (dirToks.length > 0) {
523  host = dirToks[0];
524  } else {
525  host = cleanUrl;
526  }
527 
528  //get the domain part from host (last 2)
529  StringTokenizer tok = new StringTokenizer(host, ".");
530  StringBuilder hostB = new StringBuilder();
531  int toks = tok.countTokens();
532 
533  for (int count = 0; count < toks; ++count) {
534  String part = tok.nextToken();
535  int diff = toks - count;
536  if (diff < 3) {
537  hostB.append(part);
538  }
539  if (diff == 2) {
540  hostB.append('.');
541  }
542  }
543 
544  String base = hostB.toString();
545  // verify there are no special characters in there
546  if (base.matches(".*[~`!@#$%^&\\*\\(\\)\\+={}\\[\\];:\\?<>,/ ].*")) {
547  return "";
548  }
549 
550  //verify that the base domain actually has a '.', details JIRA-4609
551  if (!base.contains(".")) {
552  return "";
553  }
554 
555  return base;
556  }
557 }
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)
DataArtifact newDataArtifact(BlackboardArtifact.Type artifactType, Collection< BlackboardAttribute > attributesList)
AccountFileInstance createAccountFileInstance(org.sleuthkit.datamodel.Account.Type accountType, String accountUniqueID, String moduleName, Content sourceFile)
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)
static final Account.Type PHONE
Definition: Account.java:49
BlackboardArtifact addWebHistory(String url, long accessTime, String referrer, String title, String programName)
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)
static final Account.Type EMAIL
Definition: Account.java:50

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