- Learning Python for Forensics
- Preston Miller Chapin Bryce
- 516字
- 2021-07-02 16:41:11
Forensic scripting best practices
Forensic best practices play a big part in what we do and, traditionally, refer to handling or acquiring evidence. However, we've designated some forensic best practices of our own when it comes to programming, as follows:
- Do not modify original data you're working with and to that effect
- Work on copies of the original data
- Comment code
- Validate your program's results
- Maintain extensive logging
- Return output in an easy-to-analyze or understand format
The golden rule of forensics: do not modify the original data. Always work on a forensic copy or through a write-blocker. However, this may not be an option for other disciplines such as for incident responders where the parameters and scope varies.
In these cases, it is important to consider what the code does and how it might interact with the system at runtime. What kind of footprint does the code leave behind? Could it inadvertently destroy artifacts or references to them? Has the program been validated in similar conditions to ensure that it operates properly? These are the kinds of considerations necessary when it comes to running a program on a live system.
We've touched on commenting code before, but it cannot hurt to overstate its value. Soon, we will create our first forensic script, usb_lookup.py
, which is a little over 90 lines of code. Imagine being handed the code without any explanation or comments. It might take a few minutes to read and understand what exactly it does, even for an experienced developer. Now imagine a large project's source code that has thousands of lines of code—it should be apparent how valuable comments are, not just for the developer but also those who examine the code afterwards.
Validation essentially comes down to knowing the code's behavior. Obviously, bugs are going to be found and fixed. However, bugs have a way of frequently turning up and are ultimately unavoidable as it is impossible to test against all possible situations during development. Instead, what can be established is an understanding of the behavior of the code in a variety of environments and situations. Mastering the behavior of your code is important, not only to be able to determine if the code is up for the task at hand, but also when asked to explain its function and inner workings in a court room.
Logging can help keep track of any potential errors during runtime and act as an audit-chain of sorts for what the program did and when. Python supplies a robust logging module in the standard library, unsurprisingly named logging
. We will use this module and its various options throughout the book.
The purpose of our scripts is to automate some of the tedious repetitive tasks in forensics and supply analysts with actionable knowledge. Often, the latter refers to storing data in a format that is easily manipulated. In most cases, a CSV file is the simplest way to achieve this so that it can be opened with a variety of different text or workbook editors. We will use the csv
module in many of our programs.
- 數據庫系統原理及MySQL應用教程(第2版)
- C語言程序設計實踐教程(第2版)
- Objective-C Memory Management Essentials
- Java EE 6 企業級應用開發教程
- Computer Vision for the Web
- iOS 9 Game Development Essentials
- 基于Java技術的Web應用開發
- MySQL 8 DBA基礎教程
- Android傳感器開發與智能設備案例實戰
- 零基礎學Python編程(少兒趣味版)
- 大學計算機基礎實驗指導
- 算法設計與分析:基于C++編程語言的描述
- PyQt編程快速上手
- Building Business Websites with Squarespace 7(Second Edition)
- Keil Cx51 V7.0單片機高級語言編程與μVision2應用實踐