Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c25a20

Browse files
committed
Docstring update and smalldict update (merge with top1575)
1 parent 2b56bdf commit 4c25a20

4 files changed

Lines changed: 348 additions & 5 deletions

File tree

lib/core/common.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
from lib.core.settings import URLENCODE_CHAR_LIMIT
166166
from lib.core.settings import URLENCODE_FAILSAFE_CHARS
167167
from lib.core.settings import USER_AGENT_ALIASES
168+
from lib.core.settings import VERSION
168169
from lib.core.settings import VERSION_STRING
169170
from lib.core.settings import WEBSCARAB_SPLITTER
170171
from lib.core.threads import getCurrentThreadData
@@ -1165,6 +1166,9 @@ def getHeader(headers, key):
11651166
def checkFile(filename, raiseOnError=True):
11661167
"""
11671168
Checks for file existence and readability
1169+
1170+
>>> checkFile(__file__)
1171+
True
11681172
"""
11691173

11701174
valid = True
@@ -1647,6 +1651,9 @@ def parseUnionPage(page):
16471651
def parseFilePaths(page):
16481652
"""
16491653
Detects (possible) absolute system paths inside the provided page content
1654+
1655+
>>> _ = "/var/www/html/index.php"; parseFilePaths("<html>Error occurred at line 207 of: %s<br>Please contact your administrator</html>" % _); _ in kb.absFilePaths
1656+
True
16501657
"""
16511658

16521659
if page:
@@ -2039,6 +2046,9 @@ def parseXmlFile(xmlFile, handler):
20392046
def getSQLSnippet(dbms, sfile, **variables):
20402047
"""
20412048
Returns content of SQL snippet located inside 'procs/' directory
2049+
2050+
>>> 'RECONFIGURE' in getSQLSnippet(DBMS.MSSQL, "activate_sp_oacreate")
2051+
True
20422052
"""
20432053

20442054
if sfile.endswith('.sql') and os.path.exists(sfile):
@@ -2078,9 +2088,12 @@ def getSQLSnippet(dbms, sfile, **variables):
20782088

20792089
return retVal
20802090

2081-
def readCachedFileContent(filename, mode='rb'):
2091+
def readCachedFileContent(filename, mode="rb"):
20822092
"""
20832093
Cached reading of file content (avoiding multiple same file reading)
2094+
2095+
>>> "readCachedFileContent" in readCachedFileContent(__file__)
2096+
True
20842097
"""
20852098

20862099
if filename not in kb.cache.content:
@@ -2137,13 +2150,19 @@ def average(values):
21372150
def calculateDeltaSeconds(start):
21382151
"""
21392152
Returns elapsed time from start till now
2153+
2154+
>>> calculateDeltaSeconds(0) > 1151721660
2155+
True
21402156
"""
21412157

21422158
return time.time() - start
21432159

21442160
def initCommonOutputs():
21452161
"""
21462162
Initializes dictionary containing common output values used by "good samaritan" feature
2163+
2164+
>>> initCommonOutputs(); "information_schema" in kb.commonOutputs["Databases"]
2165+
True
21472166
"""
21482167

21492168
kb.commonOutputs = {}
@@ -3351,6 +3370,9 @@ def unhandledExceptionMessage():
33513370
def getLatestRevision():
33523371
"""
33533372
Retrieves latest revision from the offical repository
3373+
3374+
>>> getLatestRevision() == VERSION
3375+
True
33543376
"""
33553377

33563378
retVal = None
@@ -4149,6 +4171,9 @@ def checkSystemEncoding():
41494171
def evaluateCode(code, variables=None):
41504172
"""
41514173
Executes given python code given in a string form
4174+
4175+
>>> _ = {}; evaluateCode("a = 1; b = 2; c = a", _); _["c"]
4176+
1
41524177
"""
41534178

41544179
try:
@@ -4202,6 +4227,9 @@ def incrementCounter(technique):
42024227
def getCounter(technique):
42034228
"""
42044229
Returns query counter for a given technique
4230+
4231+
>>> resetCounter(PAYLOAD.TECHNIQUE.STACKED); incrementCounter(PAYLOAD.TECHNIQUE.STACKED); getCounter(PAYLOAD.TECHNIQUE.STACKED)
4232+
1
42054233
"""
42064234

42074235
return kb.counters.get(technique, 0)
@@ -4441,6 +4469,9 @@ def zeroDepthSearch(expression, value):
44414469
"""
44424470
Searches occurrences of value inside expression at 0-depth level
44434471
regarding the parentheses
4472+
4473+
>>> _ = "SELECT (SELECT id FROM users WHERE 2>1) AS result FROM DUAL"; _[zeroDepthSearch(_, "FROM")[0]:]
4474+
'FROM DUAL'
44444475
"""
44454476

44464477
retVal = []
@@ -4476,7 +4507,7 @@ def pollProcess(process, suppress_errors=False):
44764507
Checks for process status (prints . if still running)
44774508
"""
44784509

4479-
while True:
4510+
while process:
44804511
dataToStdout(".")
44814512
time.sleep(1)
44824513

@@ -4701,12 +4732,33 @@ def getSafeExString(ex, encoding=None):
47014732
return getUnicode(retVal or "", encoding=encoding).strip()
47024733

47034734
def safeVariableNaming(value):
4735+
"""
4736+
Returns escaped safe-representation of a given variable name that can be used in Python evaluated code
4737+
4738+
>>> safeVariableNaming("foo bar")
4739+
'foo__SAFE__20bar'
4740+
"""
4741+
47044742
return re.sub(r"[^\w]", lambda match: "%s%02x" % (SAFE_VARIABLE_MARKER, ord(match.group(0))), value)
47054743

47064744
def unsafeVariableNaming(value):
4745+
"""
4746+
Returns unescaped safe-representation of a given variable name
4747+
4748+
>>> unsafeVariableNaming("foo__SAFE__20bar")
4749+
'foo bar'
4750+
"""
4751+
47074752
return re.sub(r"%s([0-9a-f]{2})" % SAFE_VARIABLE_MARKER, lambda match: match.group(1).decode("hex"), value)
47084753

47094754
def firstNotNone(*args):
4755+
"""
4756+
Returns first not-None value from a given list of arguments
4757+
4758+
>>> firstNotNone(None, None, 1, 2, 3)
4759+
1
4760+
"""
4761+
47104762
retVal = None
47114763

47124764
for _ in args:

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from lib.core.enums import OS
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.2.9.10"
22+
VERSION = "1.2.9.11"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

txt/checksum.md5

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ c7443613a0a2505b1faec931cee2a6ef lib/controller/handler.py
3030
1e5532ede194ac9c083891c2f02bca93 lib/controller/__init__.py
3131
8eb0a5dbd79bd58fedac4c0cc344246b lib/core/agent.py
3232
fd8f239e259afaf5f24bcf34a0ad187f lib/core/bigarray.py
33-
6e73b39f7c51f75ae64a652dec69ab2f lib/core/common.py
33+
a69c59bec0b35442139d1c29f1b05797 lib/core/common.py
3434
0d082da16c388b3445e656e0760fb582 lib/core/convert.py
3535
9f87391b6a3395f7f50830b391264f27 lib/core/data.py
3636
72016ea5c994a711a262fd64572a0fcd lib/core/datatype.py
@@ -50,7 +50,7 @@ c8c386d644d57c659d74542f5f57f632 lib/core/patch.py
5050
0c3eef46bdbf87e29a3f95f90240d192 lib/core/replication.py
5151
a7db43859b61569b601b97f187dd31c5 lib/core/revision.py
5252
fcb74fcc9577523524659ec49e2e964b lib/core/session.py
53-
021d606c9405fd23d630108bf5c39853 lib/core/settings.py
53+
e595397f965c89ed29d9b4b89aada743 lib/core/settings.py
5454
dd68a9d02fccb4fa1428b20e15b0db5d lib/core/shell.py
5555
a7edc9250d13af36ac0108f259859c19 lib/core/subprocessng.py
5656
815d1cf27f0f8738d81531e73149867d lib/core/target.py

0 commit comments

Comments
 (0)