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

Skip to content

Commit 43de824

Browse files
committed
Code refactoring
1 parent 7715ba7 commit 43de824

2 files changed

Lines changed: 36 additions & 34 deletions

File tree

lib/core/common.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99

1010
import codecs
11+
import ctypes
1112
import inspect
1213
import os
1314
import random
@@ -1531,3 +1532,28 @@ def beep():
15311532

15321533
else:
15331534
dataToStdout('\a', True)
1535+
1536+
def runningAsAdmin():
1537+
isAdmin = False
1538+
1539+
if PLATFORM in ( "posix", "mac" ):
1540+
isAdmin = os.geteuid()
1541+
1542+
if isinstance(isAdmin, (int, float, long)) and isAdmin == 0:
1543+
isAdmin = True
1544+
elif IS_WIN:
1545+
isAdmin = ctypes.windll.shell32.IsUserAnAdmin()
1546+
1547+
if isinstance(isAdmin, (int, float, long)) and isAdmin == 1:
1548+
isAdmin = True
1549+
else:
1550+
errMsg = "sqlmap is not able to check if you are running it "
1551+
errMsg += "as an administrator accout on this platform. "
1552+
errMsg += "sqlmap will assume that you are an administrator "
1553+
errMsg += "which is mandatory for the requested takeover attack "
1554+
errMsg += "to work properly"
1555+
logger.error(errMsg)
1556+
1557+
isAdmin = True
1558+
1559+
return isAdmin

lib/core/option.py

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import codecs
1111
import cookielib
12-
import ctypes
1312
import difflib
1413
import inspect
1514
import logging
@@ -31,6 +30,7 @@
3130
from lib.core.common import parseTargetUrl
3231
from lib.core.common import paths
3332
from lib.core.common import randomRange
33+
from lib.core.common import runningAsAdmin
3434
from lib.core.common import sanitizeStr
3535
from lib.core.common import UnicodeRawConfigParser
3636
from lib.core.data import conf
@@ -340,12 +340,10 @@ def __setMetasploit():
340340
msfEnvPathExists = False
341341

342342
if IS_WIN:
343-
warnMsg = "Metasploit's msfconsole and msfcli are not supported "
344-
warnMsg += "on the native Windows Ruby interpreter. Please "
345-
warnMsg += "install Metasploit, Python interpreter and sqlmap on "
346-
warnMsg += "Cygwin or use Linux in VMWare to use sqlmap takeover "
347-
warnMsg += "out-of-band features. sqlmap will now continue "
348-
warnMsg += "without calling any takeover feature"
343+
warnMsg = "some sqlmap takeover functionalities are not yet "
344+
warnMsg += "supported on Windows. Please use Linux in a virtual "
345+
warnMsg += "machine for out-of-band features. sqlmap will now "
346+
warnMsg += "carry on ignoring out-of-band switches"
349347
logger.warn(warnMsg)
350348

351349
conf.osPwn = None
@@ -355,35 +353,13 @@ def __setMetasploit():
355353
return
356354

357355
if conf.osSmb:
358-
isAdmin = False
359-
360-
if PLATFORM in ( "posix", "mac" ):
361-
isAdmin = os.geteuid()
362-
363-
if isinstance(isAdmin, (int, float, long)) and isAdmin == 0:
364-
isAdmin = True
365-
366-
elif IS_WIN:
367-
isAdmin = ctypes.windll.shell32.IsUserAnAdmin()
368-
369-
if isinstance(isAdmin, (int, float, long)) and isAdmin == 1:
370-
isAdmin = True
371-
372-
else:
373-
warnMsg = "sqlmap is not able to check if you are running it "
374-
warnMsg += "as an Administrator accout on this platform. "
375-
warnMsg += "sqlmap will assume that you are an Administrator "
376-
warnMsg += "which is mandatory for the SMB relay attack to "
377-
warnMsg += "work properly"
378-
logger.warn(warnMsg)
379-
380-
isAdmin = True
356+
isAdmin = runningAsAdmin()
381357

382358
if isAdmin is not True:
383-
errMsg = "you need to run sqlmap as an Administrator/root "
384-
errMsg += "user if you want to perform a SMB relay attack "
385-
errMsg += "because it will need to listen on a user-specified "
386-
errMsg += "SMB TCP port for incoming connection attempts"
359+
errMsg = "you need to run sqlmap as an administrator "
360+
errMsg += "if you want to perform a SMB relay attack because "
361+
errMsg += "it will need to listen on a user-specified SMB "
362+
errMsg += "TCP port for incoming connection attempts"
387363
raise sqlmapMissingPrivileges, errMsg
388364

389365
if conf.msfPath:

0 commit comments

Comments
 (0)