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

Skip to content

Commit c0946ce

Browse files
committed
Minor refactoring
1 parent 75d1dab commit c0946ce

3 files changed

Lines changed: 52 additions & 13 deletions

File tree

lib/request/inject.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from lib.request.connect import Connect as Request
5050
from lib.request.direct import direct
5151
from lib.techniques.blind.inference import bisection
52+
from lib.techniques.dns.test import dnsTest
5253
from lib.techniques.dns.use import dnsUse
5354
from lib.techniques.error.use import errorUse
5455
from lib.techniques.union.use import unionUse
@@ -85,19 +86,7 @@ def __goDns(payload, expression):
8586

8687
if conf.dnsDomain and kb.dnsTest is not False:
8788
if kb.dnsTest is None:
88-
logger.info("testing for data retrieval through DNS channel")
89-
90-
randInt = randomInt()
91-
kb.dnsTest = dnsUse(payload, "SELECT %d%s" % (randInt, FROM_DUMMY_TABLE.get(Backend.getIdentifiedDbms(), ""))) == str(randInt)
92-
93-
if not kb.dnsTest:
94-
errMsg = "data retrieval through DNS channel failed. Turning off DNS exfiltration support"
95-
logger.error(errMsg)
96-
97-
conf.dnsDomain = None
98-
else:
99-
infoMsg = "data retrieval through DNS channel was successful"
100-
logger.info(infoMsg)
89+
dnsTest(payload)
10190

10291
if kb.dnsTest:
10392
value = dnsUse(payload, expression)

lib/techniques/dns/test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
$Id$
5+
6+
Copyright (c) 2006-2012 sqlmap developers (http://www.sqlmap.org/)
7+
See the file 'doc/COPYING' for copying permission
8+
"""
9+
10+
from lib.core.common import Backend
11+
from lib.core.common import randomInt
12+
from lib.core.data import conf
13+
from lib.core.data import kb
14+
from lib.core.data import logger
15+
from lib.core.settings import FROM_DUMMY_TABLE
16+
from lib.techniques.dns.use import dnsUse
17+
18+
19+
def dnsTest(payload):
20+
logger.info("testing for data retrieval through DNS channel")
21+
22+
randInt = randomInt()
23+
kb.dnsTest = dnsUse(payload, "SELECT %d%s" % (randInt, FROM_DUMMY_TABLE.get(Backend.getIdentifiedDbms(), ""))) == str(randInt)
24+
25+
if not kb.dnsTest:
26+
errMsg = "data retrieval through DNS channel failed. Turning off DNS exfiltration support"
27+
logger.error(errMsg)
28+
29+
conf.dnsDomain = None
30+
else:
31+
infoMsg = "data retrieval through DNS channel was successful"
32+
logger.info(infoMsg)

lib/techniques/dns/use.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,29 @@
3434
from lib.core.data import queries
3535
from lib.core.enums import DBMS
3636
from lib.core.enums import PAYLOAD
37+
from lib.core.settings import FROM_DUMMY_TABLE
3738
from lib.core.settings import MAX_DNS_LABEL
3839
from lib.core.settings import PARTIAL_VALUE_MARKER
3940
from lib.core.unescaper import unescaper
4041
from lib.request.connect import Connect as Request
4142

43+
44+
def dnsTest(payload):
45+
logger.info("testing for data retrieval through DNS channel")
46+
47+
randInt = randomInt()
48+
kb.dnsTest = dnsUse(payload, "SELECT %d%s" % (randInt, FROM_DUMMY_TABLE.get(Backend.getIdentifiedDbms(), ""))) == str(randInt)
49+
50+
if not kb.dnsTest:
51+
errMsg = "data retrieval through DNS channel failed. Turning off DNS exfiltration support"
52+
logger.error(errMsg)
53+
54+
conf.dnsDomain = None
55+
else:
56+
infoMsg = "data retrieval through DNS channel was successful"
57+
logger.info(infoMsg)
58+
59+
4260
def dnsUse(payload, expression):
4361
"""
4462
Retrieve the output of a SQL query taking advantage of the DNS

0 commit comments

Comments
 (0)