Sleuth Kit Java Bindings (JNI)  4.10.0
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;
39 
47 public final class WebBrowserArtifactsHelper extends ArtifactHelperBase {
48 
49  private static final Logger LOGGER = Logger.getLogger(WebBrowserArtifactsHelper.class.getName());
50 
59  public WebBrowserArtifactsHelper(SleuthkitCase caseDb, String moduleName, Content srcContent) {
60  super(caseDb, moduleName, srcContent);
61  }
62 
77  public BlackboardArtifact addWebBookmark(String url, String title, long creationTime, String progName) throws TskCoreException, BlackboardException {
78  return addWebBookmark(url, title, creationTime, progName,
79  Collections.emptyList());
80  }
81 
97  public BlackboardArtifact addWebBookmark(String url, String title, long creationTime, String progName,
98  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
99 
100  BlackboardArtifact bookMarkArtifact;
101  Collection<BlackboardAttribute> attributes = new ArrayList<>();
102 
103  // create artifact
104  bookMarkArtifact = getContent().newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_BOOKMARK);
105 
106  // construct attributes
107  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, getModuleName(), url));
108 
109  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED, creationTime, attributes);
110  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE, title, attributes);
111  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN, extractDomain(url), attributes);
112  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, progName, attributes);
113 
114  // add attributes to artifact
115  attributes.addAll(otherAttributesList);
116  bookMarkArtifact.addAttributes(attributes);
117 
118  // post artifact
119  getSleuthkitCase().getBlackboard().postArtifact(bookMarkArtifact, getModuleName());
120 
121  // return the artifact
122  return bookMarkArtifact;
123  }
124 
140  public BlackboardArtifact addWebCookie(String url, long creationTime,
141  String name, String value, String programName) throws TskCoreException, BlackboardException {
142 
143  return addWebCookie(url, creationTime, name, value, programName,
144  Collections.emptyList());
145  }
146 
166  public BlackboardArtifact addWebCookie(String url,
167  long creationTime, String name, String value, String programName,
168  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
169 
170  BlackboardArtifact cookieArtifact;
171  Collection<BlackboardAttribute> attributes = new ArrayList<>();
172 
173  // create artifact
174  cookieArtifact = getContent().newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_COOKIE);
175 
176  // construct attributes
177  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, getModuleName(), url));
178 
179  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, creationTime, attributes);
180  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, name, attributes);
181  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_VALUE, value, attributes);
182  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN, extractDomain(url), attributes);
183  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, programName, attributes);
184 
185  // add attributes to artifact
186  attributes.addAll(otherAttributesList);
187  cookieArtifact.addAttributes(attributes);
188 
189  // post artifact
190  getSleuthkitCase().getBlackboard().postArtifact(cookieArtifact, getModuleName());
191 
192  // return the artifact
193  return cookieArtifact;
194  }
195 
210  public BlackboardArtifact addWebDownload(String url, long startTime, String path, String programName) throws TskCoreException, BlackboardException {
211  return addWebDownload(path, startTime, url, programName, Collections.emptyList());
212  }
213 
229  public BlackboardArtifact addWebDownload(String url, long startTime, String path, String programName,
230  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
231 
232  BlackboardArtifact webDownloadArtifact;
233  Collection<BlackboardAttribute> attributes = new ArrayList<>();
234 
235  // reate artifact
236  webDownloadArtifact = getContent().newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD);
237 
238  // construct attributes
239  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH, getModuleName(), path));
240  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, getModuleName(), url));
241 
242  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED, startTime, attributes);
243  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, programName, attributes);
244  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN, extractDomain(url), attributes);
245 
246  // add attributes to artifact
247  attributes.addAll(otherAttributesList);
248  webDownloadArtifact.addAttributes(attributes);
249 
250  // post artifact
251  getSleuthkitCase().getBlackboard().postArtifact(webDownloadArtifact, getModuleName());
252 
253  // return the artifact
254  return webDownloadArtifact;
255  }
256 
273  public BlackboardArtifact addWebFormAddress(String personName, String email,
274  String phoneNumber, String mailingAddress,
275  long creationTime, long accessTime, int count) throws TskCoreException, BlackboardException {
276  return addWebFormAddress(personName, email, phoneNumber,
277  mailingAddress, creationTime, accessTime, count,
278  Collections.emptyList());
279  }
280 
298  public BlackboardArtifact addWebFormAddress(String personName, String email,
299  String phoneNumber, String mailingAddress,
300  long creationTime, long accessTime, int count,
301  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
302 
303  BlackboardArtifact webFormAddressArtifact;
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  // create artifact
325  webFormAddressArtifact = getContent().newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_FORM_ADDRESS);
326 
327  // construct attributes
328  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, getModuleName(), personName));
329 
330  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL, email, attributes);
331  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER, phoneNumber, attributes);
332  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION, mailingAddress, attributes);
333 
334  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED, creationTime, attributes);
335  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED, accessTime, attributes);
336  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COUNT, count, attributes);
337 
338  // add artifact
339  attributes.addAll(otherAttributesList);
340  webFormAddressArtifact.addAttributes(attributes);
341 
342  // post artifact
343  getSleuthkitCase().getBlackboard().postArtifact(webFormAddressArtifact, getModuleName());
344 
345  // return the artifact
346  return webFormAddressArtifact;
347  }
348 
363  public BlackboardArtifact addWebFormAutofill(String name, String value,
364  long creationTime, long accessTime, int count) throws TskCoreException, BlackboardException {
365  return addWebFormAutofill(name, value, creationTime, accessTime, count,
366  Collections.emptyList());
367  }
368 
386  public BlackboardArtifact addWebFormAutofill(String name, String value,
387  long creationTime, long accessTime, int count,
388  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
389  BlackboardArtifact webFormAutofillArtifact;
390  Collection<BlackboardAttribute> attributes = new ArrayList<>();
391 
392  // create artifact
393  webFormAutofillArtifact = getContent().newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_FORM_AUTOFILL);
394 
395  // construct attributes
396  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, getModuleName(), name));
397  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_VALUE, getModuleName(), value));
398 
399  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED, creationTime, attributes);
400  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED, accessTime, attributes);
401  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COUNT, count, attributes);
402 
403  // add attributes to artifact
404  attributes.addAll(otherAttributesList);
405  webFormAutofillArtifact.addAttributes(attributes);
406 
407  // post artifact
408  getSleuthkitCase().getBlackboard().postArtifact(webFormAutofillArtifact, getModuleName());
409 
410  // return the artifact
411  return webFormAutofillArtifact;
412  }
413 
429  public BlackboardArtifact addWebHistory(String url, long accessTime,
430  String referrer, String title, String programName) throws TskCoreException, BlackboardException {
431  return addWebHistory(url, accessTime, referrer, title, programName,
432  Collections.emptyList());
433  }
434 
451  public BlackboardArtifact addWebHistory(String url, long accessTime,
452  String referrer, String title, String programName,
453  Collection<BlackboardAttribute> otherAttributesList) throws TskCoreException, BlackboardException {
454 
455  BlackboardArtifact webHistoryArtifact;
456  Collection<BlackboardAttribute> attributes = new ArrayList<>();
457 
458  // create artifact
459  webHistoryArtifact = getContent().newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_HISTORY);
460 
461  // construct attributes
462  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL, getModuleName(), url));
463 
464  addAttributeIfNotZero(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED, accessTime, attributes);
465  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE, title, attributes);
466  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_REFERRER, referrer, attributes);
467 
468  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, programName, attributes);
469  addAttributeIfNotNull(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN, extractDomain(url), attributes);
470 
471  // add attributes to artifact
472  attributes.addAll(otherAttributesList);
473  webHistoryArtifact.addAttributes(attributes);
474 
475  // post artifact
476  getSleuthkitCase().getBlackboard().postArtifact(webHistoryArtifact, getModuleName());
477 
478  // return the artifact
479  return webHistoryArtifact;
480  }
481 
482  // TBD: this is duplicated in Autopsy.
483  // We should move this to new Util class in TSK, and have Autopsy delegate to it.
492  private static String extractDomain(String urlString) {
493  if (urlString == null) {
494  return "";
495  }
496  String result;
497 
498  try {
499  URL url = new URL(urlString);
500  result = url.getHost();
501  } catch (MalformedURLException ex) {
502  // not a valid URL - we will try to extract it ourselves
503  result = null;
504  }
505 
506  //was not a valid URL, try a less picky method
507  if (result == null || StringUtils.isBlank(result)) {
508  return getBaseDomain(urlString);
509  }
510  return result;
511  }
512 
520  private static String getBaseDomain(String url) {
521  String host;
522 
523  //strip protocol
524  String cleanUrl = url.replaceFirst(".*:\\/\\/", "");
525 
526  //strip after slashes
527  String dirToks[] = cleanUrl.split("\\/");
528  if (dirToks.length > 0) {
529  host = dirToks[0];
530  } else {
531  host = cleanUrl;
532  }
533 
534  //get the domain part from host (last 2)
535  StringTokenizer tok = new StringTokenizer(host, ".");
536  StringBuilder hostB = new StringBuilder();
537  int toks = tok.countTokens();
538 
539  for (int count = 0; count < toks; ++count) {
540  String part = tok.nextToken();
541  int diff = toks - count;
542  if (diff < 3) {
543  hostB.append(part);
544  }
545  if (diff == 2) {
546  hostB.append('.');
547  }
548  }
549 
550  String base = hostB.toString();
551  // verify there are no special characters in there
552  if (base.matches(".*[~`!@#$%^&\\*\\(\\)\\+={}\\[\\];:\\?<>,/ ].*")) {
553  return "";
554  }
555 
556  //verify that the base domain actually has a '.', details JIRA-4609
557  if (!base.contains(".")) {
558  return "";
559  }
560 
561  return base;
562  }
563 }
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)
void addAttributes(Collection< BlackboardAttribute > attributes)
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 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)
static final Account.Type EMAIL
Definition: Account.java:50

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