Skip to content

Sourcery Starbot ⭐ refactored gosirys/sqlmap#1

Open
SourceryAI wants to merge 1 commit intogosirys:masterfrom
SourceryAI:master
Open

Sourcery Starbot ⭐ refactored gosirys/sqlmap#1
SourceryAI wants to merge 1 commit intogosirys:masterfrom
SourceryAI:master

Conversation

@SourceryAI
Copy link
Copy Markdown

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch https://github.com/sourcery-ai-bot/sqlmap master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Copy link
Copy Markdown
Author

@SourceryAI SourceryAI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery timed out performing refactorings.

Due to GitHub API limits, only the first 60 comments can be shown.

Comment on lines -120 to +131
errMsg = "your system does not properly handle non-ASCII paths. "
errMsg += "Please move the sqlmap's directory to the other location"
errMsg = (
"your system does not properly handle non-ASCII paths. "
+ "Please move the sqlmap's directory to the other location"
)
logger.critical(errMsg)
raise SystemExit

if LooseVersion(VERSION) < LooseVersion("1.0"):
errMsg = "your runtime environment (e.g. PYTHONPATH) is "
errMsg += "broken. Please make sure that you are not running "
errMsg = (
"your runtime environment (e.g. PYTHONPATH) is "
+ "broken. Please make sure that you are not running "
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function checkEnvironment refactored with the following changes:

# Reference: https://lists.gnu.org/archive/html/emacs-devel/2014-09/msg00815.html
def _cygwin_beep(filename):
os.system("play-sound-file '%s' 2>/dev/null" % filename)
os.system(f"play-sound-file '{filename}' 2>/dev/null")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _cygwin_beep refactored with the following changes:

def _linux_wav_play(filename):
for _ in ("aplay", "paplay", "play"):
if not os.system("%s '%s' 2>/dev/null" % (_, filename)):
if not os.system(f"{_} '{filename}' 2>/dev/null"):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _linux_wav_play refactored with the following changes:


def main():
usage = '%s [-d] -i <input file> [-o <output file>]' % sys.argv[0]
usage = f'{sys.argv[0]} [-d] -i <input file> [-o <output file>]'
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

Comment on lines -23 to +34
print("ERROR: the provided input file '%s' is too big for debug.exe" % inputFile)
print(f"ERROR: the provided input file '{inputFile}' is too big for debug.exe")
sys.exit(1)

script = "n %s\nr cx\n" % os.path.basename(inputFile.replace(".", "_"))
script += "%x\nf 0100 ffff 00\n" % fileSize
scrString = ""
counter = 256
counter2 = 0

fp = open(inputFile, "rb")
fileContent = fp.read()

for fileChar in fileContent:
for counter, fileChar in enumerate(fileContent, start=256):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function convert refactored with the following changes:

Comment on lines -162 to +163
vector = "%s%s" % (vector, comment)
vector = f"{vector}{comment}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _formatInjection refactored with the following changes:

Comment on lines -184 to +199
data = "".join(set(_formatInjection(_) for _ in kb.injections)).rstrip("\n")
data = "".join({_formatInjection(_) for _ in kb.injections}).rstrip("\n")
conf.dumper.string(header, data)

if conf.tamper:
warnMsg = "changes made by tampering scripts are not "
warnMsg += "included in shown payload content(s)"
warnMsg = (
"changes made by tampering scripts are not "
+ "included in shown payload content(s)"
)
logger.warning(warnMsg)

if conf.hpp:
warnMsg = "changes made by HTTP parameter pollution are not "
warnMsg += "included in shown payload content(s)"
warnMsg = (
"changes made by HTTP parameter pollution are not "
+ "included in shown payload content(s)"
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _showInjections refactored with the following changes:

Comment on lines -200 to +221
if extractRegexResult(EMPTY_FORM_FIELDS_REGEX, value):
if extractRegexResult(EMPTY_FORM_FIELDS_REGEX, retVal):
message = "do you want to fill blank fields with random values? [Y/n] "

if readInput(message, default='Y', boolean=True):
for match in re.finditer(EMPTY_FORM_FIELDS_REGEX, retVal):
item = match.group("result")
if not any(_ in item for _ in IGNORE_PARAMETERS) and not re.search(ASP_NET_CONTROL_REGEX, item):
if all(
_ not in item for _ in IGNORE_PARAMETERS
) and not re.search(ASP_NET_CONTROL_REGEX, item):
newValue = randomStr() if not re.search(r"^id|id$", item, re.I) else randomInt()
if item[-1] == DEFAULT_GET_POST_DELIMITER:
retVal = retVal.replace(item, "%s%s%s" % (item[:-1], newValue, DEFAULT_GET_POST_DELIMITER))
retVal = retVal.replace(
item,
f"{item[:-1]}{newValue}{DEFAULT_GET_POST_DELIMITER}",
)
else:
retVal = retVal.replace(item, "%s%s" % (item, newValue))
retVal = retVal.replace(item, f"{item}{newValue}")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _randomFillBlankFields refactored with the following changes:

Comment on lines -244 to +254
techniques = dict((_[1], _[0]) for _ in getPublicTypeMembers(PAYLOAD.TECHNIQUE))
techniques = {_[1]: _[0] for _ in getPublicTypeMembers(PAYLOAD.TECHNIQUE)}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _saveToResultsFile refactored with the following changes:

Comment on lines -177 to +181
else:
if not isinstance(ex, NameError):
raise
else:
msg = "support for direct connection to '%s' is not available. " % dbms
msg += "Please rerun with '--dependencies'"
raise SqlmapConnectionException(msg)
if not isinstance(ex, NameError):
raise
msg = f"support for direct connection to '{dbms}' is not available. "
msg += "Please rerun with '--dependencies'"
raise SqlmapConnectionException(msg)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function setHandler refactored with the following changes:

Comment on lines -161 to +173
value = "%s%s AND %s LIKE %s" % (origValue, match.group() if match else "", _, _ + 1)
value = f'{origValue}{match.group() if match else ""} AND {_} LIKE {_ + 1}'
elif conf.invalidBignum:
value = randomInt(6)
elif conf.invalidString:
value = randomStr(6)
else:
if newValue.startswith("-"):
value = ""
else:
value = "-%s" % randomInt()
value = "" if newValue.startswith("-") else f"-{randomInt()}"
elif where == PAYLOAD.WHERE.REPLACE:
value = ""
else:
value = origValue

newValue = "%s%s" % (value, newValue)
newValue = f"{value}{newValue}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Agent.payload refactored with the following changes:

Comment on lines -281 to -290
# If the technique is stacked queries (<stype>) do not put a space
# after the prefix or it is in GROUP BY / ORDER BY (<clause>)
elif getTechnique() == PAYLOAD.TECHNIQUE.STACKED:
query = kb.injection.prefix
elif kb.injection.clause == [2, 3] or kb.injection.clause == [2] or kb.injection.clause == [3]:
elif kb.injection.clause in [[2, 3], [2], [3]]:
query = kb.injection.prefix
elif clause == [2, 3] or clause == [2] or clause == [3]:
elif clause in [[2, 3], [2], [3]]:
query = prefix

# In any other case prepend with the full prefix
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Agent.prefixQuery refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator [×2] (merge-comparisons)

This removes the following comments ( why? ):

# If the technique is stacked queries (<stype>) do not put a space
# In any other case prepend with the full prefix
# after the prefix or it is in GROUP BY / ORDER BY (<clause>)

Comment on lines -373 to +391
payload = getUnicode(payload).replace("[ORIGVALUE]", origValue if origValue.isdigit() else unescaper.escape("'%s'" % origValue))
payload = getUnicode(payload).replace(
"[ORIGVALUE]",
origValue
if origValue.isdigit()
else unescaper.escape(f"'{origValue}'"),
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Agent.cleanupPayload refactored with the following changes:

except IOError as ex:
errMsg = "exception occurred while retrieving data "
errMsg += "from a temporary file ('%s')" % ex
errMsg += f"from a temporary file ('{ex}')"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BigArray.pop refactored with the following changes:

Comment on lines -127 to +130
for index in xrange(len(self)):
if self[index] == value:
return index

return ValueError, "%s is not in list" % value
return next(
(index for index in xrange(len(self)) if self[index] == value),
(ValueError, f"{value} is not in list"),
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BigArray.index refactored with the following changes:

Comment on lines -528 to +535
if not isNoneValue(versions):
return versions[0]
else:
return None
return versions[0] if not isNoneValue(versions) else None
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Backend.getVersion refactored with the following changes:

Comment on lines -536 to +540
if not isNoneValue(versions):
return versions
else:
return None
return versions if not isNoneValue(versions) else None
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Backend.getVersionList refactored with the following changes:

Comment on lines -563 to +566
singleTimeWarnMessage("identified ('%s') and fingerprinted ('%s') DBMSes differ. If you experience problems in enumeration phase please rerun with '--flush-session'" % (Backend.getIdentifiedDbms(), Backend.getDbms()))
singleTimeWarnMessage(
f"identified ('{Backend.getIdentifiedDbms()}') and fingerprinted ('{Backend.getDbms()}') DBMSes differ. If you experience problems in enumeration phase please rerun with '--flush-session'"
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Backend.isDbms refactored with the following changes:

Comment on lines -583 to +589
for _ in Backend.getVersionList():
if _ != UNKNOWN_DBMS_VERSION and _ in versionList:
return True

return False
return any(
_ != UNKNOWN_DBMS_VERSION and _ in versionList
for _ in Backend.getVersionList()
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Backend.isVersionWithin refactored with the following changes:

  • Use any() instead of for loop (use-any)

match = re.search(r"\A(\d[\d.]*)", version or "")

if match:
if match := re.search(r"\A(\d[\d.]*)", version or ""):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LooseVersion refactored with the following changes:

except:
warnMsg = "problem occurred while serializing "
warnMsg += "instance of a type '%s'" % type(value)
warnMsg += f"instance of a type '{type(value)}'"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function base64pickle refactored with the following changes:

return six.text_type(value, UNICODE_ENCODING, errors="reversible")
elif isListLike(value):
value = list(getUnicode(_, encoding, noneToNull) for _ in value)
value = [getUnicode(_, encoding, noneToNull) for _ in value]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getUnicode refactored with the following changes:

Comment on lines -403 to +405
match = re.search(r": (\d{3,})", output or "")

if match:
if match := re.search(r": (\d{3,})", output or ""):
try:
candidate = "cp%s" % match.group(1)
candidate = f"cp{match.group(1)}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function stdoutEncode refactored with the following changes:

Comment on lines -452 to +454
if isinstance(value, six.text_type):
retVal = sum((2 if ord(_) >= 0x3000 else 1) for _ in value)
else:
retVal = len(value)

return retVal
return (
sum((2 if ord(_) >= 0x3000 else 1) for _ in value)
if isinstance(value, six.text_type)
else len(value)
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getConsoleLength refactored with the following changes:

except KeyError:
if self.keycheck:
raise AttributeError("unable to access item '%s'" % item)
raise AttributeError(f"unable to access item '{item}'")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AttribDict.__getattr__ refactored with the following changes:

Comment on lines 45 to 46
except ImportError as ex:
raise SqlmapMissingDependence("missing dependence ('%s')" % getSafeExString(ex))
raise SqlmapMissingDependence(f"missing dependence ('{getSafeExString(ex)}')")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function runGui refactored with the following changes:

This removes the following comments ( why? ):

# Reference: https://www.reddit.com/r/learnpython/comments/985umy/limit_user_input_to_only_int_with_tkinter/e4dj9k9?utm_source=share&utm_medium=web2x
# Reference: https://code.activestate.com/recipes/580726-tkinter-notebook-that-fits-to-the-height-of-every-/


match = re.search(r"\[([A-Z ]+)\]", message) # log level
if match:
if match := re.search(r"\[([A-Z ]+)\]", message):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _ColorizingStreamHandler.colorize refactored with the following changes:

This removes the following comments ( why? ):

# counter
# time
# dirty patch
# log level

except Exception as ex:
errMsg = "something appears to be wrong with "
errMsg += "the file '%s' ('%s'). Please make " % (paths.QUERIES_XML, getSafeExString(ex))
errMsg += f"the file '{paths.QUERIES_XML}' ('{getSafeExString(ex)}'). Please make "
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _loadQueries refactored with the following changes:

return

debugMsg = "parsing targets list from '%s'" % conf.logFile
debugMsg = f"parsing targets list from '{conf.logFile}'"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _setMultipleTargets refactored with the following changes:

Comment on lines -305 to +318
errMsg = "specified HTTP request file '%s' " % requestFile
errMsg = f"specified HTTP request file '{requestFile}' "
errMsg += "does not exist"
raise SqlmapFilePathException(errMsg)

infoMsg = "parsing HTTP request from '%s'" % requestFile
infoMsg = f"parsing HTTP request from '{requestFile}'"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _setRequestFromFile refactored with the following changes:

@OakAtsume
Copy link
Copy Markdown

???

@OakAtsume
Copy link
Copy Markdown

???

This is definitely a scam! Please do not agree or sign up to any of these services!

@andrewluetgers
Copy link
Copy Markdown

Big phishing scam going on with GH right now I got hit by it and revoked access from the offending app. But they sent out the fake messages under my account and many others. https://github.com/orgs/community/discussions/109171

@OakAtsume
Copy link
Copy Markdown

Big phishing scam going on with GH right now I got hit by it and revoked access from the offending app. But they sent out the fake messages under my account and many others. https://github.com/orgs/community/discussions/109171

Real ballsy to target a site full of Developers, and Security researchers.

Repository owner deleted a comment from Jcillo507 Feb 23, 2024
Repository owner deleted a comment from Jcillo507 Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants