DFOR510 Week02 PythonIntro
DFOR510 Week02 PythonIntro
2
PRESENTATIONS 1 (PR1)
▪ Topics were assigned via BB – so check your grade AND my
comments
▪ Grade of 0? Read my comments and email me ASAP
▪ Grade of 0 and no comments? Did you submit topics?
5
6
Back to Basics…
▪ Guido van Rossum – creator
▪ Object-oriented, Interpreted scripting language
▪ Interactive development
▪ Lots of pre-developed standard libraries
▪ Portable
▪ Easy to learn and read
7
https://en.wikipedia.org/wiki/Python_(programming_language)
▪ www.python.org – official Python site
▪ https://www.codecademy.com/ - (free) online tutorials
▪ https://www.coursera.org – online (not always free) courses
▪ https://https://www.udemy.com/ – online (not always free)
courses
▪ https://codingbat.com/python - online exercises (free!)
▪ https://www.python.org/dev/peps/pep-0008/ - community Python
practices
8
https://www.python.org/
https://www.jetbrains.com/pycharm/
https://www.anaconda.com/
https://www.pydev.org/index.html 9
https://wingware.com/
Windows Command Prompt and MacOS ‘Terminal
https://www.vim.org
https://notepad-plus-plus.org/
https://atom.io/
Windows PowerShell
10
▪ Recovering deleted/corrupt files
▪ Repetitive tasks (e.g. file hashing, searches, etc.)
▪ Comparing partial and full artifacts
▪ Extracting metadata
▪ …And much more
12
https://www.python.org/
Use Python: NOT use Python:
▪ Triage ▪ A preexisting tool is
▪ Repetitive tasks
available
▪ General case analysis
▪ Quick/simple prototype
▪ Use a preexisting tool
14
https://clipartfest.com/categories/view/5f6d1b4e501002dc76b23f4bcd5ffba37535c1d7/clipart-thumbs-up-and-down.html
1.
2.
3.
5.
4.
15
P. Miller, C. Bryce, Learning Python for Forensics, Packt Publishing, May 2016
▪ Indentation!
▪ Four(4) spaces;
▪ <Tab>
What does PEP 8 say to use???
▪ Case Sensitive
▪ var1 ≠ vAr1
16
▪ 0 indexed language
Indices 0 1 2 ?
C F R S 5 1 0
len(gth) = 8
17
https://docs.python.org/3/reference/lexical_analysis.html
18
QUICK CHECK 1
1. This style guide is used for best Python best practices.
2. Name a reason to:
a. Use Python in DFOR?
b. NOT use Python in DFOR?
3. What does the ‘Plan’ stage of the development cycle consist of?
4. In Python, a variable named ‘hw1’ is the same as variable ‘hW1’?
5. Given the string: “Say Hash!”, what is the index value of the ‘H’?
6. T or F. In your Python scripts, it is OK use “global” as a variable
name?
19
20
Library Description
os allows user to get OS information → easy OS portability
sys Functions for interacting with Interpreter
time time-related functions handled in UNIX format (e.g. epoch time)
datetime date/times functions for simple and verbose display
hashlib cryptographic hash functions
platform used to collect system information (e.g. OS, processor, etc.)
21
Data Type Symbol Im/Mutable Description
▪ Creating lists:
23
▪ Ordered, immutable sequences;
▪ available methods?
24
▪ Unordered mutable sequence type – (key, value) pairs
▪ methods?
▪ Adding items to a dictionary:
25
▪ Accessing data from a dictionary:
26
Operation Description Operation Description
Add 1. Mathematical operand to add numbers; Assignment Assigns operator: var1 = ‘hello’
+ 2. Combine same-type data. =
Subtract Mathematical operand to subtract numbers Equality Checks if objects are of equal value
- ==
Divide Division operator Inequality Checking if items do not equal the same
/ != or <>
Multiply 1. Multiplication operator for numbers Greater than Returns true if value on left side is greater
* 2. String repetition operator > than the value on the right
Exponent Power (exponent) operator Lesser than Returns true if value on left side is lesser
** < than the value on the right
Modulus Returns the remainder of the divided
% numbers
27
▪ Casting the variable as the desired data type. For instance:
28
▪ Common conversion methods
Method Description
str(), int(), float(), list(), Basic class constructs
set(), tuple(), dict()
bin(), hex(), oct() Converts an integer to binary (bin), base 16 (hex)
or base 8 (oct) notation
chr() Converts an integer to ASCII
ord() Converts a character to its ASCII representation
bytes(object, encoding) Converts object into bytes
29
QUICK CHECK 2
1. Declare an empty:
a. List
b. Tuple
c. Dictionary
Samples: Samples:
32
If statements Else-if statement
33
34
▪ Reusable blocks of code
35
36
QUICK CHECK 3
1. If not handled properly, this conditional statement can result
in an infinite loop!
2. T or F. Function blocks can only be used from within the local
script (e.g. the program file it is written in).
3. A function is declared with what reserved word?
4. T or F. A function must take input and return an output.
37
▪ Due Thursday, 16-September-2021 @ 7pm (EST)
▪ Submit on BB:
39
▪ Write up (.pdf, .doc, etc) – do not ZIP file
▪ Hard drives, File Systems, Operating System artifacts (Windows)
▪ Please install:
▪ Image analysis tool (you have to do this for HW1)
▪ FTK, Sleuthkit Autopsy, OSForensics (whatever you prefer)
▪ Prefetch File Analyzer (e.g. WinPreFetchView) – only works on
Windows OSs.
▪ Registry View (e.g. Access Data Registry Viewer)
▪ If on MacOS – you may want to install a Virtual Machine
▪ Download VMWare Workstation Pro for free here
40
Python Resources
1. www.python.org – official Python site
2. https://www.codecademy.com/ - free online tutorials
3. http://www.coursera.org – online (not always free) courses
4. https://codingbat.com/python - online exercises (free!)
5. https://www.python.org/dev/peps/pep-0008/ - community Python practices
Character Encoding
8. https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-
unicode-and-character-sets-no-excuses/
9. http://tutorials.jenkov.com/unicode/utf-8.html
10. https://www.rapidtables.com/web/html/html-codes.html
11. http://www.unicode.org/charts/ (Unicode Charts)
12. https://www.youtube.com/watch?v=-n2nlPHEMG8&feature=youtu.be (Unicode)
41
42
BITS & CHARACTERS
▪ Every character (e.g. “C”) is represented by a code point
(numerical value)
▪ Depending on encoding scheme, characters can be stored
using 1 or more bytes.
▪ ASCII: 8-bit representation (1 byte representation)
▪ Unicode Transformation Format (UTF):
▪ UTF–8: 8 bit code encoding scheme – uses 1, 2, 3, or 4 bytes per
character
▪ UTF-16: 16 bit code unit representation – uses 2, 3, or 4 bytes per
character
44
45
Decimal (base 10) Binary (base 2) Octal (base 8) Hexadecimal (base 16)
0 0000 000 0
1 0001 001 1
2 0010 002 2
3 0011 003 3
4 0100 004 4
5 0101 005 5
6 0110 006 6
7 0111 007 7
8 1000 010 8
9 1001 011 9
10 1010 012 A
11 1011 013 B
12 1100 014 C
13 1101 015 D
14 1110 016 E
15 1111 017 F 46
▪ MD5 – 128 bit output which also translates to 32 character output (hexadecimal
characters that is!)
▪ SHA-1 – 160 bit hash which is a 40 character output
4 hexadecimal characters!