Autopsy  4.5.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
TextMessageAnalyzer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014 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.iOS;
20 
21 import java.sql.Connection;
22 import java.sql.DriverManager;
23 import java.sql.ResultSet;
24 import java.sql.SQLException;
25 import java.sql.Statement;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.List;
29 import java.util.logging.Level;
30 import org.openide.util.NbBundle;
31 import org.openide.util.NbBundle.Messages;
38 import org.sleuthkit.datamodel.AbstractFile;
39 import org.sleuthkit.datamodel.BlackboardArtifact;
40 import org.sleuthkit.datamodel.BlackboardAttribute;
41 import org.sleuthkit.datamodel.SleuthkitCase;
42 import org.sleuthkit.datamodel.TskCoreException;
43 
44 class TextMessageAnalyzer {
45 
46  private Connection connection = null;
47  private ResultSet resultSet = null;
48  private Statement statement = null;
49  private String dbPath = "";
50  private long fileId = 0;
51  private java.io.File jFile = null;
52  List<AbstractFile> absFiles;
53  private String moduleName = iOSModuleFactory.getModuleName();
54  private static final Logger logger = Logger.getLogger(TextMessageAnalyzer.class.getName());
55  private Blackboard blackboard;
56 
57  void findTexts(IngestJobContext context) {
58  blackboard = Case.getCurrentCase().getServices().getBlackboard();
59  try {
60  SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase();
61  absFiles = skCase.findAllFilesWhere("name ='mmssms.db'"); //NON-NLS //get exact file name
62  if (absFiles.isEmpty()) {
63  return;
64  }
65  for (AbstractFile AF : absFiles) {
66  try {
67  jFile = new java.io.File(Case.getCurrentCase().getTempDirectory(), AF.getName().replaceAll("[<>%|\"/:*\\\\]", ""));
68  ContentUtils.writeToFile(AF, jFile, context::dataSourceIngestIsCancelled);
69  dbPath = jFile.toString(); //path of file as string
70  fileId = AF.getId();
71  findTextsInDB(dbPath, fileId);
72  } catch (Exception e) {
73  logger.log(Level.SEVERE, "Error parsing text messages", e); //NON-NLS
74  }
75  }
76  } catch (TskCoreException e) {
77  logger.log(Level.SEVERE, "Error finding text messages", e); //NON-NLS
78  }
79  }
80 
81  @Messages({"TextMessageAnalyzer.indexError.message=Failed to index text message artifact for keyword search."})
82  private void findTextsInDB(String DatabasePath, long fId) {
83  if (DatabasePath == null || DatabasePath.isEmpty()) {
84  return;
85  }
86  try {
87  Class.forName("org.sqlite.JDBC"); //NON-NLS //load JDBC driver
88  connection = DriverManager.getConnection("jdbc:sqlite:" + DatabasePath); //NON-NLS
89  statement = connection.createStatement();
90  } catch (ClassNotFoundException | SQLException e) {
91  logger.log(Level.SEVERE, "Error opening database", e); //NON-NLS
92  }
93 
94  Case currentCase = Case.getCurrentCase();
95  SleuthkitCase skCase = currentCase.getSleuthkitCase();
96  try {
97  AbstractFile f = skCase.getAbstractFileById(fId);
98  if (f == null) {
99  logger.log(Level.SEVERE, "Error getting abstract file " + fId); //NON-NLS
100  return;
101  }
102 
103  try {
104  resultSet = statement.executeQuery(
105  "SELECT address,date,type,subject,body FROM sms;"); //NON-NLS
106 
107  BlackboardArtifact bba;
108  String address; // may be phone number, or other addresses
109  String date;//unix time
110  String type; // message received in inbox = 1, message sent = 2
111  String subject;//message subject
112  String body; //message body
113  while (resultSet.next()) {
114  address = resultSet.getString("address"); //NON-NLS
115  date = resultSet.getString("date"); //NON-NLS
116  type = resultSet.getString("type"); //NON-NLS
117  subject = resultSet.getString("subject"); //NON-NLS
118  body = resultSet.getString("body"); //NON-NLS
119 
120  bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE); //create Message artifact and then add attributes from result set.
121  Collection<BlackboardAttribute> attributes = new ArrayList<>();
122  // @@@ NEed to put into more specific TO or FROM
123  if (type.equals("1")) {
124  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, NbBundle.getMessage(this.getClass(), "TextMessageAnalyzer.bbAttribute.incoming")));
125  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM, moduleName, address));
126  } else {
127  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, NbBundle.getMessage(this.getClass(), "TextMessageAnalyzer.bbAttribute.outgoing")));
128  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO, moduleName, address));
129  }
130  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, moduleName, date));
131  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION, moduleName, type));
132  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT, moduleName, subject));
133  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TEXT, moduleName, body));
134  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MESSAGE_TYPE, moduleName, NbBundle.getMessage(this.getClass(), "TextMessageAnalyzer.bbAttribute.smsMessage")));
135 
136  bba.addAttributes(attributes);
137  try {
138  // index the artifact for keyword search
139  blackboard.indexArtifact(bba);
140  } catch (Blackboard.BlackboardException ex) {
141  logger.log(Level.SEVERE, "Unable to index blackboard artifact " + bba.getArtifactID(), ex); //NON-NLS
142  MessageNotifyUtil.Notify.error(
143  Bundle.TextMessageAnalyzer_indexError_message(), bba.getDisplayName());
144  }
145  }
146 
147  } catch (Exception e) {
148  logger.log(Level.SEVERE, "Error parsing text messages to Blackboard", e); //NON-NLS
149  } finally {
150  try {
151  resultSet.close();
152  statement.close();
153  connection.close();
154  } catch (Exception e) {
155  logger.log(Level.SEVERE, "Error closing database", e); //NON-NLS
156  }
157  }
158  } catch (Exception e) {
159  logger.log(Level.SEVERE, "Error parsing text messages to Blackboard", e); //NON-NLS
160  }
161 
162  }
163 
164 }

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