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

Skip to content

Commit 526aacb

Browse files
committed
code cleanup
1 parent 41ccf88 commit 526aacb

17 files changed

Lines changed: 38 additions & 55 deletions

File tree

extra/icmpsh/icmpsh_m.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def main(src, dst):
5757
# with the returned data
5858
try:
5959
sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
60-
except socket.error, e:
60+
except socket.error:
6161
sys.stderr.write('You need to run icmpsh master with administrator privileges\n')
6262
sys.exit(1)
6363

extra/shutils/duplicates.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
#!/usr/bin/env python
22

3+
34
"""
45
$Id$
56
67
Copyright (c) 2006-2011 sqlmap developers (http://www.sqlmap.org/)
78
See the file 'doc/COPYING' for copying permission
8-
"""
99
1010
# Removes duplicate entries in wordlist like files
1111
1212
import sys
1313
1414
if len(sys.argv) > 0:
1515
16-
items = list()
17-
f = open(sys.argv[1], 'r')
18-
19-
for item in f.readlines():
20-
item = item.strip()
21-
try:
22-
str.encode(item)
23-
if item in items:
24-
if item:
25-
print item
26-
else:
27-
items.append(item)
28-
29-
if not item:
30-
items.append('')
31-
except:
32-
pass
33-
f.close()
34-
35-
f = open(sys.argv[1], 'w+')
36-
f.writelines("\n".join(items))
37-
f.close()
16+
items = list()
17+
f = open(sys.argv[1], 'r')
18+
19+
for item in f.readlines():
20+
item = item.strip()
21+
try:
22+
str.encode(item)
23+
if item in items:
24+
if item:
25+
print item
26+
else:
27+
items.append(item)
28+
29+
if not item:
30+
items.append('')
31+
except:
32+
pass
33+
f.close()
34+
35+
f = open(sys.argv[1], 'w+')
36+
f.writelines("\n".join(items))

extra/socks/socks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646

4747
import socket
4848
import struct
49-
import sys
5049

5150
PROXY_TYPE_SOCKS4 = 1
5251
PROXY_TYPE_SOCKS5 = 2

lib/core/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ def forgeInbandQuery(self, query, position, count, comment, prefix, suffix, char
559559
inbandQuery = self.prefixQuery("UNION ALL SELECT ", prefix=prefix)
560560

561561
if limited:
562-
inbandQuery += ",".join(map(lambda x: char if x != position else '(SELECT %s)' % query, xrange(0, count)))
562+
inbandQuery += ",".join(char if _ != position else '(SELECT %s)' % query for _ in xrange(0, count))
563563
inbandQuery += FROM_TABLE.get(Backend.getIdentifiedDbms(), "")
564564
inbandQuery = self.suffixQuery(inbandQuery, comment, suffix)
565565

lib/core/common.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,15 +2346,12 @@ def findDynamicContent(firstPage, secondPage):
23462346
kb.dynamicMarkings = []
23472347

23482348
# Removing too small matching blocks
2349-
while block in blocks[:]:
2349+
for block in blocks[:]:
23502350
(_, _, length) = block
23512351

23522352
if length <= DYNAMICITY_MARK_LENGTH:
23532353
blocks.remove(block)
23542354

2355-
else:
2356-
i += 1
2357-
23582355
# Making of dynamic markings based on prefix/suffix principle
23592356
if len(blocks) > 0:
23602357
blocks.insert(0, None)
@@ -2965,7 +2962,7 @@ def safeCSValue(value):
29652962

29662963
if retVal and isinstance(retVal, basestring):
29672964
if not (retVal[0] == retVal[-1] == '"'):
2968-
if any(map(lambda x: x in retVal, (conf.csvDel, '"', '\n'))):
2965+
if any(_ in retVal for _ in (conf.csvDel, '"', '\n')):
29692966
retVal = '"%s"' % retVal.replace('"', '""')
29702967

29712968
return retVal
@@ -3124,7 +3121,7 @@ def geturl(self):
31243121
def getHostHeader(url):
31253122
retVal = urlparse.urlparse(url).netloc
31263123

3127-
if any(map(lambda x: retVal.endswith(':%d' % x), [80, 443])):
3124+
if any(retVal.endswith(':%d' % _) for _ in [80, 443]):
31283125
retVal = retVal.split(':')[0]
31293126

31303127
return retVal

lib/core/settings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
import logging
1111
import os
12-
import _socket
13-
import socket
1412
import subprocess
1513
import sys
1614

lib/request/comparison.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ def comparison(page, headers, code=None, getRatioValue=False, pageLength=None):
3232
if page is None and pageLength is None:
3333
return None
3434

35-
regExpResults = None
36-
3735
seqMatcher = getCurrentThreadData().seqMatcher
3836
seqMatcher.set_seq1(kb.pageTemplate)
3937

lib/request/connect.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ def getPage(**kwargs):
339339
return conn, None, None
340340

341341
# Get HTTP response
342-
page = conn.read() if page is None else page
342+
if page is None:
343+
page = conn.read()
344+
343345
code = redirecting or conn.code
344346
responseHeaders = conn.info()
345347
responseHeaders[URI_HTTP_HEADER] = conn.geturl()
@@ -486,7 +488,7 @@ def getPage(**kwargs):
486488
if "forcibly closed" in tbMsg:
487489
logger.critical(warnMsg)
488490
return None, None, None
489-
elif silent or (ignoreTimeout and any(map(lambda x: x in tbMsg, ["timed out", "IncompleteRead"]))):
491+
elif silent or (ignoreTimeout and any(_ in tbMsg for _ in ("timed out", "IncompleteRead"))):
490492
return None, None, None
491493
elif threadData.retriesCount < conf.retries and not kb.threadException and not conf.realTest:
492494
warnMsg += ", sqlmap is going to retry the request"

lib/techniques/blind/inference.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
102102

103103
showEta = conf.eta and isinstance(length, int)
104104
numThreads = min(conf.threads, length)
105-
threads = []
106105

107106
if showEta:
108107
progress = ProgressBar(maxValue=length)

lib/techniques/union/test.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def __orderByTest(cols):
161161

162162
return retVal
163163

164-
def __unionPosition(comment, place, parameter, value, prefix, suffix, count, where=PAYLOAD.WHERE.ORIGINAL):
164+
def __unionPosition(comment, place, parameter, prefix, suffix, count, where=PAYLOAD.WHERE.ORIGINAL):
165165
validPayload = None
166166
vector = None
167167

@@ -224,18 +224,18 @@ def __unionPosition(comment, place, parameter, value, prefix, suffix, count, whe
224224

225225
return validPayload, vector
226226

227-
def __unionConfirm(comment, place, parameter, value, prefix, suffix, count):
227+
def __unionConfirm(comment, place, parameter, prefix, suffix, count):
228228
validPayload = None
229229
vector = None
230230

231231
# Confirm the inband SQL injection and get the exact column
232232
# position which can be used to extract data
233-
validPayload, vector = __unionPosition(comment, place, parameter, value, prefix, suffix, count)
233+
validPayload, vector = __unionPosition(comment, place, parameter, prefix, suffix, count)
234234

235235
# Assure that the above function found the exploitable full inband
236236
# SQL injection position
237237
if not validPayload:
238-
validPayload, vector = __unionPosition(comment, place, parameter, value, prefix, suffix, count, where=PAYLOAD.WHERE.NEGATIVE)
238+
validPayload, vector = __unionPosition(comment, place, parameter, prefix, suffix, count, where=PAYLOAD.WHERE.NEGATIVE)
239239

240240
return validPayload, vector
241241

@@ -249,7 +249,6 @@ def __unionTestByCharBruteforce(comment, place, parameter, value, prefix, suffix
249249
validPayload = None
250250
vector = None
251251
query = agent.prefixQuery("UNION ALL SELECT %s" % kb.uChar)
252-
total = conf.uColsStop+1 - conf.uColsStart
253252

254253
# In case that user explicitly stated number of columns affected
255254
if conf.uColsStop == conf.uColsStart:
@@ -267,7 +266,7 @@ def __unionTestByCharBruteforce(comment, place, parameter, value, prefix, suffix
267266
if Backend.getIdentifiedDbms() in FROM_TABLE:
268267
query += FROM_TABLE[Backend.getIdentifiedDbms()]
269268

270-
validPayload, vector = __unionConfirm(comment, place, parameter, value, prefix, suffix, count)
269+
validPayload, vector = __unionConfirm(comment, place, parameter, prefix, suffix, count)
271270

272271
if not all([validPayload, vector]) and not all([conf.uChar, conf.dbms]):
273272
warnMsg = "if UNION based SQL injection is not detected, "

0 commit comments

Comments
 (0)