Skip to content

Commit 150abc0

Browse files
committed
sqlmap 0.7-rc3: Reset takeover OOB features (if any of --os-pwn, --os-smbrelay or --os-bof is selected) when running under Windows because msfconsole and msfcli are not supported on the native Windows Ruby interpreter. Correctly handle fcntl to be imported only on systems different from Windows. Minor code refactoring.
1 parent 3bca0d4 commit 150abc0

File tree

5 files changed

+45
-21
lines changed

5 files changed

+45
-21
lines changed

lib/core/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from lib.core.data import queries
4444
from lib.core.data import temp
4545
from lib.core.exception import sqlmapFilePathException
46-
from lib.core.settings import PLATFORM
46+
from lib.core.settings import IS_WIN
4747
from lib.core.settings import SQL_STATEMENTS
4848
from lib.core.settings import VERSION_STRING
4949

@@ -832,7 +832,7 @@ def searchEnvPath(fileName):
832832
envPaths = os.environ["PATH"]
833833
result = None
834834

835-
if "darwin" not in PLATFORM and "win" in PLATFORM:
835+
if IS_WIN is True:
836836
envPaths = envPaths.split(";")
837837
else:
838838
envPaths = envPaths.split(":")

lib/core/option.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
from lib.core.optiondict import optDict
5656
from lib.core.settings import MSSQL_ALIASES
5757
from lib.core.settings import MYSQL_ALIASES
58+
from lib.core.settings import IS_WIN
5859
from lib.core.settings import PLATFORM
5960
from lib.core.settings import SITE
6061
from lib.core.settings import SUPPORTED_DBMS
@@ -267,6 +268,26 @@ def __setMetasploit():
267268
if not conf.osPwn and not conf.osSmb and not conf.osBof:
268269
return
269270

271+
debugMsg = "setting the takeover out-of-band functionality"
272+
logger.debug(debugMsg)
273+
274+
msfEnvPathExists = False
275+
276+
if IS_WIN is True:
277+
warnMsg = "Metasploit's msfconsole and msfcli are not supported "
278+
warnMsg += "on the native Windows Ruby interpreter. Please "
279+
warnMsg += "install Metasploit, Python interpreter and sqlmap on "
280+
warnMsg += "Cygwin or use Linux in VMWare to use sqlmap takeover "
281+
warnMsg += "out-of-band features. sqlmap will now continue "
282+
warnMsg += "without calling any takeover feature"
283+
logger.warn(warnMsg)
284+
285+
conf.osPwn = None
286+
conf.osSmb = None
287+
conf.osBof = None
288+
289+
return
290+
270291
if conf.osSmb:
271292
isAdmin = False
272293

@@ -276,7 +297,7 @@ def __setMetasploit():
276297
if isinstance(isAdmin, (int, float, long)) and isAdmin == 0:
277298
isAdmin = True
278299

279-
elif "win" in PLATFORM:
300+
elif IS_WIN is True:
280301
isAdmin = ctypes.windll.shell32.IsUserAnAdmin()
281302

282303
if isinstance(isAdmin, (int, float, long)) and isAdmin == 1:
@@ -292,18 +313,13 @@ def __setMetasploit():
292313

293314
isAdmin = True
294315

295-
if isAdmin != True:
296-
errMsg = "you need to run sqlmap as an administrator/root "
316+
if isAdmin is not True:
317+
errMsg = "you need to run sqlmap as an Administrator/root "
297318
errMsg += "user if you want to perform a SMB relay attack "
298319
errMsg += "because it will need to listen on a user-specified "
299320
errMsg += "SMB TCP port for incoming connection attempts"
300321
raise sqlmapMissingPrivileges, errMsg
301322

302-
debugMsg = "setting the out-of-band functionality"
303-
logger.debug(debugMsg)
304-
305-
msfEnvPathExists = False
306-
307323
if conf.msfPath:
308324
condition = os.path.exists(os.path.normpath(conf.msfPath))
309325
condition &= os.path.exists(os.path.normpath("%s/msfcli" % conf.msfPath))
@@ -337,7 +353,7 @@ def __setMetasploit():
337353

338354
envPaths = os.environ["PATH"]
339355

340-
if "darwin" not in PLATFORM and "win" in PLATFORM:
356+
if IS_WIN is True:
341357
envPaths = envPaths.split(";")
342358
else:
343359
envPaths = envPaths.split(":")

lib/core/readlineng.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import sys
3333

3434
from lib.core.data import logger
35+
from lib.core.settings import IS_WIN
3536
from lib.core.settings import PLATFORM
3637

3738

@@ -49,7 +50,7 @@
4950
except ImportError:
5051
haveReadline = False
5152

52-
if 'win' in PLATFORM and 'darwin' not in PLATFORM and haveReadline:
53+
if IS_WIN is True and haveReadline:
5354
try:
5455
_outputfile=_rl.GetOutputFile()
5556
except AttributeError:

lib/core/settings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525

2626

2727
import logging
28+
import subprocess
2829
import sys
2930

3031

3132
# sqlmap version and site
32-
VERSION = "0.7rc2"
33+
VERSION = "0.7rc3"
3334
VERSION_STRING = "sqlmap/%s" % VERSION
3435
SITE = "http://sqlmap.sourceforge.net"
3536

@@ -46,6 +47,7 @@
4647
LOGGER.setLevel(logging.WARN)
4748

4849
# System variables
50+
IS_WIN = subprocess.mswindows
4951
PLATFORM = sys.platform.lower()
5052
PYVERSION = sys.version.split()[0]
5153

lib/core/subprocessng.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,21 @@
2424

2525

2626

27-
import fcntl
2827
import errno
2928
import os
3029
import sys
3130
import time
3231

32+
from lib.core.settings import IS_WIN
3333

34-
if (sys.hexversion >> 16) >= 0x202:
35-
FCNTL = fcntl
36-
else:
37-
import FCNTL
34+
35+
if IS_WIN is not True:
36+
import fcntl
37+
38+
if (sys.hexversion >> 16) >= 0x202:
39+
FCNTL = fcntl
40+
else:
41+
import FCNTL
3842

3943

4044
def blockingReadFromFD(fd):
@@ -84,6 +88,7 @@ def setNonBlocking(fd):
8488
Make a file descriptor non-blocking
8589
"""
8690

87-
flags = fcntl.fcntl(fd, FCNTL.F_GETFL)
88-
flags = flags | os.O_NONBLOCK
89-
fcntl.fcntl(fd, FCNTL.F_SETFL, flags)
91+
if IS_WIN is not True:
92+
flags = fcntl.fcntl(fd, FCNTL.F_GETFL)
93+
flags = flags | os.O_NONBLOCK
94+
fcntl.fcntl(fd, FCNTL.F_SETFL, flags)

0 commit comments

Comments
 (0)