dissect.database 0.1.dev3__tar.gz → 0.1.dev5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/PKG-INFO +24 -4
  2. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/README.md +21 -2
  3. dissect_database-0.1.dev5/dissect/database/__init__.py +13 -0
  4. dissect_database-0.1.dev5/dissect/database/ese/__init__.py +24 -0
  5. dissect_database-0.1.dev5/dissect/database/ese/btree.py +166 -0
  6. dissect_database-0.1.dev5/dissect/database/ese/c_ese.py +471 -0
  7. dissect_database-0.1.dev5/dissect/database/ese/c_ese.pyi +491 -0
  8. dissect_database-0.1.dev5/dissect/database/ese/compression.py +50 -0
  9. dissect_database-0.1.dev5/dissect/database/ese/cursor.py +210 -0
  10. dissect_database-0.1.dev5/dissect/database/ese/ese.py +108 -0
  11. dissect_database-0.1.dev5/dissect/database/ese/exception.py +15 -0
  12. dissect_database-0.1.dev5/dissect/database/ese/index.py +297 -0
  13. dissect_database-0.1.dev5/dissect/database/ese/lcmapstring.py +218 -0
  14. dissect_database-0.1.dev5/dissect/database/ese/page.py +270 -0
  15. dissect_database-0.1.dev5/dissect/database/ese/record.py +515 -0
  16. dissect_database-0.1.dev5/dissect/database/ese/sorting_table.py +8198 -0
  17. dissect_database-0.1.dev5/dissect/database/ese/table.py +386 -0
  18. dissect_database-0.1.dev5/dissect/database/ese/tools/impacket.py +72 -0
  19. dissect_database-0.1.dev5/dissect/database/ese/tools/sru.py +173 -0
  20. dissect_database-0.1.dev5/dissect/database/ese/tools/ual.py +107 -0
  21. dissect_database-0.1.dev5/dissect/database/ese/util.py +93 -0
  22. dissect_database-0.1.dev5/dissect/database/exception.py +5 -0
  23. dissect_database-0.1.dev5/dissect/database/sqlite3/__init__.py +25 -0
  24. dissect_database-0.1.dev5/dissect/database/sqlite3/c_sqlite3.py +72 -0
  25. dissect_database-0.1.dev5/dissect/database/sqlite3/c_sqlite3.pyi +132 -0
  26. dissect_database-0.1.dev5/dissect/database/sqlite3/exception.py +27 -0
  27. dissect_database-0.1.dev5/dissect/database/sqlite3/sqlite3.py +650 -0
  28. dissect_database-0.1.dev5/dissect/database/sqlite3/util.py +144 -0
  29. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/dissect.database.egg-info/PKG-INFO +24 -4
  30. dissect_database-0.1.dev5/dissect.database.egg-info/SOURCES.txt +89 -0
  31. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/dissect.database.egg-info/requires.txt +1 -0
  32. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/pyproject.toml +2 -1
  33. dissect_database-0.1.dev5/tests/_data/ese/Windows.edb.gz +0 -0
  34. dissect_database-0.1.dev5/tests/_data/ese/basic.edb.gz +0 -0
  35. dissect_database-0.1.dev5/tests/_data/ese/binary.edb.gz +0 -0
  36. dissect_database-0.1.dev5/tests/_data/ese/default.edb.gz +0 -0
  37. dissect_database-0.1.dev5/tests/_data/ese/index.edb.gz +0 -0
  38. dissect_database-0.1.dev5/tests/_data/ese/large.edb.gz +0 -0
  39. dissect_database-0.1.dev5/tests/_data/ese/multi.edb.gz +0 -0
  40. dissect_database-0.1.dev5/tests/_data/ese/text.edb.gz +0 -0
  41. dissect_database-0.1.dev5/tests/_data/ese/tools/Current.mdb.gz +0 -0
  42. dissect_database-0.1.dev5/tests/_data/ese/tools/SRUDB.dat.gz +0 -0
  43. dissect_database-0.1.dev5/tests/_data/sqlite3/empty.sqlite +0 -0
  44. dissect_database-0.1.dev5/tests/_data/sqlite3/test.sqlite +0 -0
  45. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/tests/_docs/conf.py +1 -0
  46. dissect_database-0.1.dev5/tests/_util.py +22 -0
  47. dissect_database-0.1.dev5/tests/bsd/__init__.py +0 -0
  48. {dissect_database-0.1.dev3/tests → dissect_database-0.1.dev5/tests/bsd}/conftest.py +2 -16
  49. dissect_database-0.1.dev5/tests/ese/__init__.py +0 -0
  50. dissect_database-0.1.dev5/tests/ese/conftest.py +60 -0
  51. dissect_database-0.1.dev5/tests/ese/test_cursor.py +59 -0
  52. dissect_database-0.1.dev5/tests/ese/test_ese.py +355 -0
  53. dissect_database-0.1.dev5/tests/ese/test_index.py +107 -0
  54. dissect_database-0.1.dev5/tests/ese/test_page.py +25 -0
  55. dissect_database-0.1.dev5/tests/ese/test_record.py +81 -0
  56. dissect_database-0.1.dev5/tests/ese/test_table.py +32 -0
  57. dissect_database-0.1.dev5/tests/ese/tools/__init__.py +0 -0
  58. dissect_database-0.1.dev5/tests/ese/tools/test_sru.py +12 -0
  59. dissect_database-0.1.dev5/tests/ese/tools/test_ual.py +15 -0
  60. dissect_database-0.1.dev5/tests/sqlite3/__init__.py +0 -0
  61. dissect_database-0.1.dev5/tests/sqlite3/conftest.py +20 -0
  62. dissect_database-0.1.dev5/tests/sqlite3/test_default_values.py +75 -0
  63. dissect_database-0.1.dev5/tests/sqlite3/test_row.py +36 -0
  64. dissect_database-0.1.dev5/tests/sqlite3/test_sqlite3.py +64 -0
  65. dissect_database-0.1.dev5/tests/sqlite3/test_util.py +163 -0
  66. dissect_database-0.1.dev3/dissect/database/bsd/__init__.py +0 -5
  67. dissect_database-0.1.dev3/dissect.database.egg-info/SOURCES.txt +0 -33
  68. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/.gitattributes +0 -0
  69. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/COPYRIGHT +0 -0
  70. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/LICENSE +0 -0
  71. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/MANIFEST.in +0 -0
  72. {dissect_database-0.1.dev3/dissect/database → dissect_database-0.1.dev5/dissect/database/bsd}/__init__.py +0 -0
  73. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/dissect/database/bsd/c_db.py +0 -0
  74. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/dissect/database/bsd/c_db.pyi +0 -0
  75. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/dissect/database/bsd/db.py +0 -0
  76. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/dissect/database/bsd/tools/__init__.py +0 -0
  77. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/dissect/database/bsd/tools/c_rpm.py +0 -0
  78. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/dissect/database/bsd/tools/c_rpm.pyi +0 -0
  79. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/dissect/database/bsd/tools/rpm.py +0 -0
  80. {dissect_database-0.1.dev3/tests → dissect_database-0.1.dev5/dissect/database/ese/tools}/__init__.py +0 -0
  81. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/dissect.database.egg-info/dependency_links.txt +0 -0
  82. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/dissect.database.egg-info/top_level.txt +0 -0
  83. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/setup.cfg +0 -0
  84. {dissect_database-0.1.dev3/tests/bsd → dissect_database-0.1.dev5/tests}/__init__.py +0 -0
  85. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/tests/_data/bsd/btree.db.gz +0 -0
  86. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/tests/_data/bsd/hash.db.gz +0 -0
  87. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/tests/_data/bsd/recno.db.gz +0 -0
  88. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/tests/_data/bsd/rpm/Packages.gz +0 -0
  89. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/tests/_docs/Makefile +0 -0
  90. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/tests/_docs/index.rst +0 -0
  91. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/tests/bsd/test_db.py +0 -0
  92. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/tests/bsd/test_rpm.py +0 -0
  93. {dissect_database-0.1.dev3 → dissect_database-0.1.dev5}/tox.ini +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dissect.database
3
- Version: 0.1.dev3
4
- Summary: A Dissect module implementing parsers for various database formats
3
+ Version: 0.1.dev5
4
+ Summary: A Dissect module implementing parsers for various database formats, including Berkeley DB, Microsofts Extensible Storage Engine (ESE) and SQLite3
5
5
  Author-email: Dissect Team <dissect@fox-it.com>
6
6
  License-Expression: Apache-2.0
7
7
  Project-URL: homepage, https://dissect.tools
@@ -22,6 +22,7 @@ Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
23
  License-File: COPYRIGHT
24
24
  Requires-Dist: dissect.cstruct<5,>=4
25
+ Requires-Dist: dissect.util<4,>=3.5
25
26
  Provides-Extra: dev
26
27
  Requires-Dist: dissect.cstruct<5.0.dev,>=4.0.dev; extra == "dev"
27
28
  Requires-Dist: dissect.util<4.0.dev,>=3.5.dev; extra == "dev"
@@ -29,8 +30,13 @@ Dynamic: license-file
29
30
 
30
31
  # dissect.database
31
32
 
32
- A Dissect module implementing parsers for various database formats. For more information,
33
- please see [the documentation](https://docs.dissect.tools/en/latest/projects/dissect.database/index.html).
33
+ A Dissect module implementing parsers for various database formats, including:
34
+
35
+ - Berkeley DB, used for example in older RPM databases
36
+ - Microsofts Extensible Storage Engine (ESE), used for example in Active Directory, Exchange and Windows Update
37
+ - SQLite3, commonly used by applications to store configuration data
38
+
39
+ For more information, please see [the documentation](https://docs.dissect.tools/en/latest/projects/dissect.database/index.html).
34
40
 
35
41
  ## Installation
36
42
 
@@ -42,6 +48,20 @@ pip install dissect.database
42
48
 
43
49
  This module is also automatically installed if you install the `dissect` package.
44
50
 
51
+ ## Tools
52
+
53
+ ### Impacket compatibility shim for secretsdump.py
54
+
55
+ Impacket does not ([yet](https://github.com/fortra/impacket/pull/1452)) have native support for `dissect.database`,
56
+ so in the meantime a compatibility shim is provided. To use this shim, simply install `dissect.database` using the
57
+ instructions above, and execute `secretsdump.py` like so:
58
+
59
+ ```bash
60
+ python -m dissect.database.ese.tools.impacket /path/to/impacket/examples/secretsdump.py -h
61
+ ```
62
+
63
+ Impacket `secretsdump.py` will now use `dissect.database` for parsing the `NTDS.dit` file, resulting in a significant performance improvement!
64
+
45
65
  ## Build and test instructions
46
66
 
47
67
  This project uses `tox` to build source and wheel distributions. Run the following command from the root folder to build
@@ -1,7 +1,12 @@
1
1
  # dissect.database
2
2
 
3
- A Dissect module implementing parsers for various database formats. For more information,
4
- please see [the documentation](https://docs.dissect.tools/en/latest/projects/dissect.database/index.html).
3
+ A Dissect module implementing parsers for various database formats, including:
4
+
5
+ - Berkeley DB, used for example in older RPM databases
6
+ - Microsofts Extensible Storage Engine (ESE), used for example in Active Directory, Exchange and Windows Update
7
+ - SQLite3, commonly used by applications to store configuration data
8
+
9
+ For more information, please see [the documentation](https://docs.dissect.tools/en/latest/projects/dissect.database/index.html).
5
10
 
6
11
  ## Installation
7
12
 
@@ -13,6 +18,20 @@ pip install dissect.database
13
18
 
14
19
  This module is also automatically installed if you install the `dissect` package.
15
20
 
21
+ ## Tools
22
+
23
+ ### Impacket compatibility shim for secretsdump.py
24
+
25
+ Impacket does not ([yet](https://github.com/fortra/impacket/pull/1452)) have native support for `dissect.database`,
26
+ so in the meantime a compatibility shim is provided. To use this shim, simply install `dissect.database` using the
27
+ instructions above, and execute `secretsdump.py` like so:
28
+
29
+ ```bash
30
+ python -m dissect.database.ese.tools.impacket /path/to/impacket/examples/secretsdump.py -h
31
+ ```
32
+
33
+ Impacket `secretsdump.py` will now use `dissect.database` for parsing the `NTDS.dit` file, resulting in a significant performance improvement!
34
+
16
35
  ## Build and test instructions
17
36
 
18
37
  This project uses `tox` to build source and wheel distributions. Run the following command from the root folder to build
@@ -0,0 +1,13 @@
1
+ from __future__ import annotations
2
+
3
+ from dissect.database.bsd.db import DB
4
+ from dissect.database.ese.ese import ESE
5
+ from dissect.database.exception import Error
6
+ from dissect.database.sqlite3.sqlite3 import SQLite3
7
+
8
+ __all__ = [
9
+ "DB",
10
+ "ESE",
11
+ "Error",
12
+ "SQLite3",
13
+ ]
@@ -0,0 +1,24 @@
1
+ from __future__ import annotations
2
+
3
+ from dissect.database.ese.ese import ESE
4
+ from dissect.database.ese.exception import (
5
+ InvalidDatabase,
6
+ KeyNotFoundError,
7
+ NoNeighbourPageError,
8
+ )
9
+ from dissect.database.ese.index import Index
10
+ from dissect.database.ese.page import Page
11
+ from dissect.database.ese.record import Record
12
+ from dissect.database.ese.table import Table
13
+
14
+ __all__ = [
15
+ "ESE",
16
+ "CompressedTaggedDataError",
17
+ "Index",
18
+ "InvalidDatabase",
19
+ "KeyNotFoundError",
20
+ "NoNeighbourPageError",
21
+ "Page",
22
+ "Record",
23
+ "Table",
24
+ ]
@@ -0,0 +1,166 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING
4
+
5
+ from dissect.database.ese.exception import KeyNotFoundError, NoNeighbourPageError
6
+
7
+ if TYPE_CHECKING:
8
+ from dissect.database.ese.ese import ESE
9
+ from dissect.database.ese.page import Node, Page
10
+
11
+
12
+ class BTree:
13
+ """A simple implementation for searching the ESE B+Trees.
14
+
15
+ This is a stateful interactive class that moves an internal cursor to a position within the BTree.
16
+
17
+ Args:
18
+ db: An instance of :class:`~dissect.database.ese.ese.ESE`.
19
+ page: The page to open the :class:`BTree` on.
20
+ """
21
+
22
+ def __init__(self, db: ESE, root: int | Page):
23
+ self.db = db
24
+
25
+ if isinstance(root, int):
26
+ page_num = root
27
+ root = db.page(page_num)
28
+ else:
29
+ page_num = root.num
30
+
31
+ self.root = root
32
+
33
+ self._page = root
34
+ self._page_num = page_num
35
+ self._node_num = 0
36
+
37
+ def reset(self) -> None:
38
+ """Reset the internal state to the root of the BTree."""
39
+ self._page = self.root
40
+ self._page_num = self._page.num
41
+ self._node_num = 0
42
+
43
+ def node(self) -> Node:
44
+ """Return the node the BTree is currently on.
45
+
46
+ Returns:
47
+ A :class:`~dissect.database.ese.page.Node` object of the current node.
48
+ """
49
+ return self._page.node(self._node_num)
50
+
51
+ def next(self) -> Node:
52
+ """Move the BTree to the next node and return it.
53
+
54
+ Can move the BTree to the next page as a side effect.
55
+
56
+ Returns:
57
+ A :class:`~dissect.database.ese.page.Node` object of the next node.
58
+ """
59
+ if self._node_num + 1 > self._page.node_count - 1:
60
+ self.next_page()
61
+ else:
62
+ self._node_num += 1
63
+
64
+ return self.node()
65
+
66
+ def next_page(self) -> None:
67
+ """Move the BTree to the next page in the tree.
68
+
69
+ Raises:
70
+ NoNeighbourPageError: If the current page has no next page.
71
+ """
72
+ if self._page.next_page:
73
+ self._page = self.db.page(self._page.next_page)
74
+ self._node_num = 0
75
+ else:
76
+ raise NoNeighbourPageError(f"{self._page} has no next page")
77
+
78
+ def prev(self) -> Node:
79
+ """Move the BTree to the previous node and return it.
80
+
81
+ Can move the BTree to the previous page as a side effect.
82
+
83
+ Returns:
84
+ A :class:`~dissect.database.ese.page.Node` object of the previous node.
85
+ """
86
+ if self._node_num - 1 < 0:
87
+ self.prev_page()
88
+ else:
89
+ self._node_num -= 1
90
+
91
+ return self.node()
92
+
93
+ def prev_page(self) -> None:
94
+ """Move the BTree to the previous page in the tree.
95
+
96
+ Raises:
97
+ NoNeighbourPageError: If the current page has no previous page.
98
+ """
99
+ if self._page.previous_page:
100
+ self._page = self.db.page(self._page.previous_page)
101
+ self._node_num = self._page.node_count - 1
102
+ else:
103
+ raise NoNeighbourPageError(f"{self._page} has no previous page")
104
+
105
+ def search(self, key: bytes, exact: bool = True) -> Node:
106
+ """Search the tree for the given ``key``.
107
+
108
+ Moves the BTree to the matching node, or on the last node that is less than the requested key.
109
+
110
+ Args:
111
+ key: The key to search for.
112
+ exact: Whether to only return successfully on an exact match.
113
+
114
+ Raises:
115
+ KeyNotFoundError: If an ``exact`` match was requested but not found.
116
+ """
117
+ page = self._page
118
+ while True:
119
+ node = find_node(page, key)
120
+
121
+ if page.is_branch:
122
+ page = self.db.page(node.child)
123
+ else:
124
+ self._page = page
125
+ self._page_num = page.num
126
+ self._node_num = node.num
127
+ break
128
+
129
+ if exact and key != node.key:
130
+ raise KeyNotFoundError(f"Can't find key: {key}")
131
+
132
+ return self.node()
133
+
134
+
135
+ def find_node(page: Page, key: bytes) -> Node:
136
+ """Search a page for a node matching ``key``.
137
+
138
+ Args:
139
+ page: The page to search.
140
+ key: The key to search.
141
+ """
142
+ first_node_idx = 0
143
+ last_node_idx = page.node_count - 1
144
+
145
+ node = None
146
+ while first_node_idx < last_node_idx:
147
+ node_idx = (first_node_idx + last_node_idx) // 2
148
+ node = page.node(node_idx)
149
+
150
+ # It turns out that the way BTree keys are compared matches 1:1 with how Python compares bytes
151
+ # First compare data, then length
152
+ if key < node.key:
153
+ last_node_idx = node_idx
154
+ elif key == node.key:
155
+ if page.is_branch:
156
+ # If there's an exact match on a key on a branch page, the actual leaf nodes are in the next branch
157
+ # Page keys for branch pages appear to be non-inclusive upper bounds
158
+ node_idx = min(node_idx + 1, page.node_count - 1)
159
+ node = page.node(node_idx)
160
+
161
+ return node
162
+ else:
163
+ first_node_idx = node_idx + 1
164
+
165
+ # We're at the last node
166
+ return page.node(first_node_idx)