Skip to content

Commit a49400d

Browse files
committed
This PR introduces the --update-sums parameter, which updates the SHA-256 hashes of modified files in the DIGEST_FILE. This parameter must be provided after --smoke.
1 parent fa9dc20 commit a49400d

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

Diff for: data/txt/sha256sums.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ de2b0220db1c79d8720b636d267b11e117151f5f99740567096e9b4cbb7cc9d5 lib/controller
166166
1d6e741e19e467650dce2ca84aa824d6df68ff74aedbe4afa8dbdb0193d94918 lib/controller/__init__.py
167167
41c7fb7e486c4383a114c851f0c32c81c53c2b4f1d2a0fd99f70885072646387 lib/core/agent.py
168168
f848dcfdacb5143f803f4e9474cf3eef939039c26c522ca09777c425661300f0 lib/core/bigarray.py
169-
eaf9d2d47305764213ada74b7a83721fc5f49578f2d8afa78799855068acb416 lib/core/common.py
169+
0c0dc1676b895f15a58ec6676d5e627188fbe491e9646c22b00c85ec718d37fc lib/core/common.py
170170
88fbbe7c41511b17d7ef449d675a84eaa80cac6ebf457a18577eadd62f6f1330 lib/core/compat.py
171171
5ce8f2292f99d17d69bfc40ded206bfdfd06e2e3660ff9d1b3c56163793f8d1c lib/core/convert.py
172172
f561310b3cea570cc13d9f0aff16cce8b097d51275f8b947e7fff4876ac65c32 lib/core/data.py
@@ -199,7 +199,7 @@ b1071f449a66b4ceacd4b84b33a73d9e0a3197d271d72daaa406ba473a8bb625 lib/core/testi
199199
12cbead4e9e563b970fafb891127927445bd53bada1fac323b9cd27da551ba30 lib/core/wordlist.py
200200
1d6e741e19e467650dce2ca84aa824d6df68ff74aedbe4afa8dbdb0193d94918 lib/__init__.py
201201
a027f4c44811cb74aa367525f353706de3d3fc719e6c6162f7a61dc838acf0c2 lib/parse/banner.py
202-
9c7f95948cb6ee20b2b5bff7b36c23179c44303d3c8ad555247f65f12f30e0a9 lib/parse/cmdline.py
202+
0976f36b36c15b3e1f64d5b5dfd21c3274e57b8bb3218ca9d23cd5582a47cff5 lib/parse/cmdline.py
203203
3907765df08c31f8d59350a287e826bd315a7714dc0e87496f67c8a0879c86ac lib/parse/configfile.py
204204
ced03337edd5a16b56a379c9ac47775895e1053003c25f6ba5bec721b6e3aa64 lib/parse/handler.py
205205
3704a02dcf00b0988b101e30b2e0d48acdd20227e46d8b552e46c55d7e9bf28c lib/parse/headers.py
@@ -477,7 +477,7 @@ b3d9d0644197ecb864e899c04ee9c7cd63891ecf2a0d3c333aad563eef735294 plugins/generi
477477
8c4fd81d84598535643cf0ef1b2d350cd92977cb55287e23993b76eaa2215c30 sqlmapapi.py
478478
168309215af7dd5b0b71070e1770e72f1cbb29a3d8025143fb8aa0b88cd56b62 sqlmapapi.yaml
479479
6da15963699aa8916118f92c8838013bc02c84e4d7b9f33d971324c2ff348728 sqlmap.conf
480-
3795c6d03bc341a0e3aef3d7990ea8c272d91a4c307e1498e850594375af39f7 sqlmap.py
480+
4b1905d382dfb21184abc18736e7734f42d7f1e812da93e20bb73c8831b41d85 sqlmap.py
481481
9d408612a6780f7f50a7f7887f923ff3f40be5bfa09a951c6dc273ded05b56c0 tamper/0eunion.py
482482
c1c2eaa7df016cc7786ccee0ae4f4f363b1dce139c61fb3e658937cb0d18fc54 tamper/apostrophemask.py
483483
19023093ab22aec3bce9523f28e8111e8f6125973e6d9c82adb60da056bdf617 tamper/apostrophenullencode.py

Diff for: lib/core/common.py

+31-15
Original file line numberDiff line numberDiff line change
@@ -2554,7 +2554,7 @@ def initCommonOutputs():
25542554
if line not in kb.commonOutputs[key]:
25552555
kb.commonOutputs[key].add(line)
25562556

2557-
def getFileItems(filename, commentPrefix='#', unicoded=True, lowercase=False, unique=False):
2557+
def getFileItems(filename, commentPrefix='#', unicoded=True, lowercase=False, unique=False, raiseOnError=True):
25582558
"""
25592559
Returns newline delimited items contained inside file
25602560
@@ -2567,7 +2567,7 @@ def getFileItems(filename, commentPrefix='#', unicoded=True, lowercase=False, un
25672567
if filename:
25682568
filename = filename.strip('"\'')
25692569

2570-
checkFile(filename)
2570+
checkFile(filename, raiseOnError=raiseOnError)
25712571

25722572
try:
25732573
with openFile(filename, 'r', errors="ignore") if unicoded else open(filename, 'r') as f:
@@ -5599,18 +5599,34 @@ def checkSums():
55995599

56005600
retVal = True
56015601

5602-
if paths.get("DIGEST_FILE"):
5603-
for entry in getFileItems(paths.DIGEST_FILE):
5604-
match = re.search(r"([0-9a-f]+)\s+([^\s]+)", entry)
5605-
if match:
5606-
expected, filename = match.groups()
5607-
filepath = os.path.join(paths.SQLMAP_ROOT_PATH, filename).replace('/', os.path.sep)
5608-
if not checkFile(filepath, False):
5609-
continue
5610-
with open(filepath, "rb") as f:
5611-
content = f.read()
5612-
if not hashlib.sha256(content).hexdigest() == expected:
5613-
retVal &= False
5614-
break
5602+
for entry in getFileItems(paths.DIGEST_FILE, raiseOnError=False):
5603+
file_data = entry.split()
5604+
if len(file_data) == 2 and len(file_data[0]) == 64:
5605+
filepath = os.path.join(paths.SQLMAP_ROOT_PATH, file_data[1]).replace('/', os.path.sep)
5606+
content = openFile(filepath, 'rb', None).read()
5607+
if not hashlib.sha256(content).hexdigest() == file_data[0]:
5608+
retVal &= False
5609+
break
56155610

56165611
return retVal
5612+
5613+
5614+
def updateSums():
5615+
# Read existing entries to maintain file order
5616+
entries = []
5617+
for entry in getFileItems(paths.DIGEST_FILE):
5618+
file_data = entry.split()
5619+
if len(file_data) == 2 and len(file_data[0]) == 64:
5620+
filepath = os.path.join(paths.SQLMAP_ROOT_PATH, file_data[1]).replace('/', os.path.sep)
5621+
content = openFile(filepath, 'rb', None).read()
5622+
newline = "%s %s\n" % (
5623+
hashlib.sha256(content).hexdigest(),
5624+
file_data[1].encode('utf-8').decode('utf-8'),
5625+
)
5626+
entries.append(newline)
5627+
5628+
5629+
# Write updated hashes back to file
5630+
if entries:
5631+
with open(paths.DIGEST_FILE, "w") as f:
5632+
f.write("".join(entries))

Diff for: lib/parse/cmdline.py

+3
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,9 @@ def cmdLineParser(argv=None):
854854
parser.add_argument("--smoke-test", dest="smokeTest", action="store_true",
855855
help=SUPPRESS)
856856

857+
parser.add_argument("--update-sums", dest="updateSums", action="store_true",
858+
help=SUPPRESS)
859+
857860
parser.add_argument("--vuln-test", dest="vulnTest", action="store_true",
858861
help=SUPPRESS)
859862

Diff for: sqlmap.py

+3
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ def main():
179179
if not conf.updateAll:
180180
# Postponed imports (faster start)
181181
if conf.smokeTest:
182+
if conf.updateSums:
183+
from lib.core.common import updateSums
184+
updateSums()
182185
from lib.core.testing import smokeTest
183186
os._exitcode = 1 - (smokeTest() or 0)
184187
elif conf.vulnTest:

0 commit comments

Comments
 (0)