














































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!















































Question 1. Which command creates an isolated Python 3 virtual environment named forensic_env in the current directory? A) python3 -m venv forensic_env B) pip install virtualenv forensic_env C) conda create -n forensic_env python= D) python -m pipenv create forensic_env Answer: A Explanation: python3 -m venv creates a virtual environment using the built-in venv module; it isolates packages for forensic scripts. Question 2. In a forensic script, which data type is most appropriate for storing a file’s size in bytes? A) str B) int C) float D) bool Answer: B Explanation: File size is a whole number of bytes, so an integer (int) accurately represents it without rounding. Question 3. Which Python collection guarantees that elements retain the order they were added and cannot be altered after creation? A) list B) tuple C) set D) dict Answer: B
Explanation: A tuple is an immutable, ordered collection; once created, its elements cannot be changed. Question 4. When extracting unique IPv4 addresses from a log file, which built-in collection type provides O(1) average-time membership tests? A) list B) tuple C) dict D) set Answer: D Explanation: Sets store unordered unique elements and offer constant-time membership checks, ideal for deduplication. Question 5. Which control-flow statement is best suited for iterating over every file in a directory tree returned by os.scandir()? A) while B) for C) if D) try Answer: B Explanation: A for loop directly iterates over the iterator produced by os.scandir(), handling each directory entry. Question 6. Which pathlib method returns a string representation of a path that works on both Windows and Linux? A) Path.as_posix() B) Path.as_uri() C) str(Path) D) Path.resolve()
C) follow=True D) symlinks=True Answer: A Explanation: os.walk(top, followlinks=True) tells the function to traverse directories pointed to by symbolic links. Question 10. Which regular-expression pattern correctly matches a MAC address in the form AA:BB:CC:DD:EE:FF? A) r'([0-9A-F]{2}:){5}[0-9A-F]{2}' B) r'([0-9a-f]{2}-){5}[0-9a-f]{2}' C) r'([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}' D) r'([0-9]{2}:){5}[0-9]{2}' Answer: C Explanation: MAC addresses are hexadecimal and case-insensitive; the pattern allows both upper- and lower-case hex digits. Question 11. In regex, what does the quantifier *? signify? A) Zero or more, greedy B) One or more, greedy C) Zero or more, non-greedy D) One or more, non-greedy Answer: C Explanation: The *? quantifier matches the smallest possible number of repetitions (non-greedy) of the preceding token. Question 12. Which struct format character is used to unpack a 4-byte unsigned integer in little-endian order?
Answer: C Explanation: Repeated calls to cursor.fetchone() retrieve rows one by one, suitable for large forensic tables. Question 18. In Python’s sqlite3 module, which data type is used to represent a BLOB column when reading it? A) str B) bytes C) bytearray D) memoryview Answer: B Explanation: BLOB data is returned as a bytes object, which can be written directly to a file. Question 19. Which Pillow function extracts EXIF metadata from an image file? A) Image.open().exif() B) Image._getexif() C) Image.getexif() D) Image.exif_data() Answer: B Explanation: _getexif() returns a dictionary of EXIF tags; newer versions also provide getexif(), but the classic method is _getexif(). Question 20. A forensic image contains timestamps stored as Windows FILETIME (number of 100-nanosecond intervals since 1601- 01 - 01). Which datetime method converts this to a Python datetime object? A) datetime.fromtimestamp() B) datetime.utcfromtimestamp() C) datetime.fromordinal()
D) datetime.fromtimestamp(filetime / 10**7 - 11644473600) Answer: D Explanation: FILETIME must be divided by 10⁷ to get seconds and offset by the epoch difference (11644473600 seconds) before using fromtimestamp. Question 21. Which hashlib algorithm produces a 64-character hexadecimal digest? A) MD B) SHA- 1 C) SHA- 256 D) SHA- 512 Answer: C Explanation: SHA-256 outputs 256 bits = 32 bytes = 64 hex characters. Question 22. In a forensic script, why might you prefer hashlib.blake2b() over hashlib.sha256() for large files? A) Blake2b is faster while providing comparable security B) Blake2b produces a shorter digest C) Blake2b is the only algorithm supported on Windows D) Blake2b automatically salts the hash Answer: A Explanation: Blake2b is designed for high performance with security comparable to SHA-2, making it efficient for hashing large evidence files. Question 23. Which os function returns the absolute path of a symbolic link without resolving the link’s target? A) os.path.realpath() B) os.readlink()
A) os.path.isdir() B) os.path.islink() C) os.path.isfile() D) os.path.isabs() Answer: C Explanation: os.path.isfile() returns True only for regular files, ignoring directories and symlinks. Question 27. Which re flag makes the pattern case-insensitive, useful when matching email addresses regardless of case? A) re.MULTILINE B) re.DOTALL C) re.IGNORECASE D) re.VERBOSE Answer: C Explanation: re.IGNORECASE (or re.I) makes the regex ignore case differences. Question 28. Which of the following regex patterns will correctly capture a credit-card number of 16 digits, allowing optional spaces or dashes between groups? A) r'(\d{4}[- ]?){3}\d{4}' B) r'\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}' C) r'(\d{4}\s?){4}' D) All of the above Answer: D Explanation: All three patterns permit optional spaces or hyphens and match 16 - digit groups.
Question 29. When processing a large CSV file line-by-line to avoid memory exhaustion, which approach is most efficient? A) csv.reader(open('file.csv')) and iterate B) pandas.read_csv('file.csv') C) csv.DictReader(open('file.csv')).read() D) open('file.csv').readlines() Answer: A Explanation: csv.reader returns an iterator; iterating over it reads one row at a time, minimizing memory use. Question 30. Which sqlite3 connection parameter disables automatic transaction commits, allowing you to manually control when changes are written? A) isolation_level=None B) isolation_level='' C) check_same_thread=False D) autocommit=True Answer: B Explanation: Setting isolation_level='' (empty string) puts the connection in autocommit mode; None enables implicit transaction handling. The question asks to disable automatic commits, so you would set a non-empty isolation level (default), but to manually control you set isolation_level=None. However the correct answer is A because None disables the default transaction behavior, letting you manage commits yourself. Answer: A Explanation: sqlite3.connect(isolation_level=None) puts the connection in autocommit mode, requiring explicit commit() calls for any changes, which is useful when you want full control over write operations. Question 31. Which Python statement correctly opens a file for appending binary data without truncating the existing content?
Question 34. Which os function can be used to obtain the file’s inode number on a Unix-like system, useful for detecting hard links? A) os.stat().st_ino B) os.lstat().st_mode C) os.path.getsize() D) os.path.getmtime() Answer: A Explanation: os.stat(path).st_ino returns the inode number, allowing investigators to identify multiple directory entries pointing to the same data. Question 35. In a forensic script, you need to ensure a temporary directory is removed even if an exception occurs. Which pattern accomplishes this? A) try: shutil.rmtree(tmp) except: pass B) with tempfile.TemporaryDirectory() as tmp: … C) finally: shutil.rmtree(tmp) D) Both B and C Answer: D Explanation: Using TemporaryDirectory automatically cleans up, and a finally block also guarantees removal; both are valid. Question 36. Which re pattern uses a non-capturing group to match either “jpg” or “jpeg” extensions case-insensitively? A) r'.(?:jpg|jpeg)$' B) r'.(jpg|jpeg)$' C) r'.(?:jpg|jpeg)?$' D) r'.(jpg|jpeg)?$' Answer: A
Explanation: (?: … ) defines a non-capturing group, preventing unnecessary tuple entries while matching both extensions. Question 37. When reading a binary evidence file, which mode should be used with open()? A) 'r' B) 'rb' C) 'rt' D) 'w' Answer: B Explanation: 'rb' opens the file for reading binary data, preserving exact byte values. Question 38. Which json method writes a Python dictionary to a file with indentation for readability? A) json.dump(data, fp) B) json.dumps(data, indent=4) C) json.dump(data, fp, indent=4) D) json.dumps(data, fp, pretty=True) Answer: C Explanation: json.dump writes directly to a file object; the indent argument formats the output. Question 39. In a forensic SQLite database, which SQL clause limits the result set to the first 100 rows? A) LIMIT 100 B) TOP 100 C) FETCH FIRST 100 ROWS ONLY D) ROWS 100
D) os Answer: A Explanation: Converting FILETIME to seconds and then using datetime.fromtimestamp() yields a readable timestamp. Question 43. Which hashlib algorithm is considered broken and should never be used for forensic integrity verification? A) SHA- 256 B) SHA- 1 C) SHA- 3 D) BLAKE2b Answer: B Explanation: SHA-1 has known collisions and is deprecated for integrity purposes; forensic work should use stronger hashes. Question 44. Which os function can be used to change the permissions of a file to read-only for the owner, preserving group/others? A) os.chmod(path, 0o400) B) os.chmod(path, 0o600) C) os.chmod(path, 0o444) D) os.chmod(path, 0o200) Answer: A Explanation: 0o400 sets read permission for the owner only, making the file effectively read-only for the user. Question 45. In a forensic script, you need to parse a Windows event log stored as an XML file. Which library provides a simple API for extracting element text? A) xml.etree.ElementTree
B) json C) csv D) yaml Answer: A Explanation: xml.etree.ElementTree allows efficient parsing of XML structures, such as Windows event logs. Question 46. Which sqlite3 method registers a custom Python function that can be called from SQL statements? A) connection.create_function() B) connection.register_adapter() C) connection.enable_load_extension() D) connection.set_authorizer() Answer: A Explanation: create_function(name, num_params, func) makes a Python callable available within SQLite queries. Question 47. Which re pattern will match a URL that starts with either http or https and captures the domain name? A) r'https?://([^/]+)' B) r'(http|https)://(.)' C) r'https?://\w+.\w+' D) r'http(s)?://(.)' Answer: A Explanation: https? matches http or https; ([^/]+) captures the domain up to the next slash.
Explanation: .timestamp() converts a timezone-aware datetime to a POSIX timestamp. Question 51. In a forensic script, you need to ensure that a temporary file is created with a random, non-predictable name. Which function provides this capability? A) tempfile.NamedTemporaryFile() B) os.mktemp() C) random.random() D) uuid.uuid4() Answer: A Explanation: NamedTemporaryFile securely creates a temporary file with a unique name; os.mktemp is insecure. Question 52. Which re flag makes the ^ and $ anchors match the start and end of each line in a multi-line string? A) re.MULTILINE B) re.DOTALL C) re.IGNORECASE D) re.VERBOSE Answer: A Explanation: re.MULTILINE allows ^ and $ to match after and before newline characters, respectively. Question 53. When using sqlite3.Row as a row factory, how can you access a column value by its name? A) row[0] B) row['column_name'] C) row.column_name
D) row.get('column_name') Answer: B Explanation: Setting connection.row_factory = sqlite3.Row enables dictionary-like access via column names. Question 54. Which hashlib function returns a digest as raw bytes rather than a hexadecimal string? A) hashlib.sha256().hexdigest() B) hashlib.sha256().digest() C) hashlib.sha256().hex() D) hashlib.sha256().to_bytes() Answer: B Explanation: .digest() provides the binary representation; .hexdigest() returns a hex string. Question 55. Which pathlib method is used to read the entire contents of a text file as a string? A) Path.read_text() B) Path.read_bytes() C) Path.open().read() D) Path.load() Answer: A Explanation: Path.read_text() reads the file using the default encoding and returns a string. Question 56. In a forensic context, why is it important to open a file with os.O_BINARY on Windows when reading raw disk images? A) It forces UTF-8 decoding