-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmirf.py
More file actions
executable file
·109 lines (84 loc) · 2.58 KB
/
mirf.py
File metadata and controls
executable file
·109 lines (84 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!python
#
# mirf - A missing record finder for SQLite DBs
#
# Inspired by the Windows tool Missing Record Finder
# Developed by Ian Whiffin (@blakdouble)
# More great tools and research on his site: https://www.doubleblak.com/
#
# Conceptualized by - Shafik Punja (@qubytelogic)
# Coded by - Sheran Gunasekera (@chopstick_)
#
# First release 22nd Dec 2020
#
# This tool will look through an SQLite Database and find any gaps in
# either primary key based columns or autoincrement columns
#
import sys
from colorama import Fore, Back, Style, init
from mdb import SqliteDB
init(autoreset=True)
# Check if command line arguments are given
if len(sys.argv) < 2:
print(Style.BRIGHT + Fore.RED + "Missing DB file name, please provide a "\
"filename")
sys.exit(1)
# Check if the provided arg is a file and is an SQLite DB
db_file = sys.argv[1]
db = SqliteDB(db_file)
try:
db.open()
except Exception as e:
print(e)
sys.exit(1)
if not db.isSQLite3():
print(Style.BRIGHT + Fore.RED + f"File {db_file} is not an SQLite DB")
sys.exit(1)
# Check if file is an iOS SMS DB
if db.isSMSDb():
db.parseIosSMSDB()
sys.exit(0)
elif db.isCHDb():
db.parseIosCHDB()
sys.exit(0)
else:
print("Starting guided mode:")
# Start Guided mode
# First gather the following data:
# 1) Name of table to check for missing rows
# 2) Name of field in the table from 1 that contains the row count
# 3) [Optional] A table that contains the maximum row count at present
# Get all tables in db
tables = db.readAllTables()
for table in tables:
print(f"[-] {table}")
table = input(Style.BRIGHT + "Which of the above tables do you want to " \
"analyze for missing rows? ")
if table not in tables:
print(Style.BRIGHT + Fore.RED + "Table name selected isn't in DB")
db.close()
sys.exit(1)
print(Style.RESET_ALL)
cols = db.getColNames(table)
for col in cols:
print(f"[-] {col}")
col = input(Style.BRIGHT + "Enter a column to analyze ")
if col not in cols:
print(Style.BRIGHT + Fore.RED + "Column name selected isn't in table")
db.close()
sys.exit(1)
print(Style.RESET_ALL)
if db.getColType(table, col) != "INTEGER":
print(Style.BRIGHT + Fore.RED + "The column selected is not an INTEGER so "\
"we cannot analyze")
db.close()
sys.exit(1)
gaps = db.findGaps(table,col)
if len(gaps) == 0:
print(f"No missing entries in the {col} column from the {table} table")
else:
print(f"Found the following gaps for the {col} column:")
print(f"Col"+ (len(col)-2) * " " + "ID")
for gap in gaps:
print(f"{col} {gap}")
db.close()