From 43de8247ac29fd2b523c33e88d4ce3fa3f381d82 Mon Sep 17 00:00:00 2001 From: Bernardo Damele Date: Wed, 27 Oct 2010 20:39:50 +0000 Subject: [PATCH] Code refactoring --- lib/core/common.py | 26 ++++++++++++++++++++++++++ lib/core/option.py | 44 ++++++++++---------------------------------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index f9164cee7..168e9d3e1 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -8,6 +8,7 @@ See the file 'doc/COPYING' for copying permission """ import codecs +import ctypes import inspect import os import random @@ -1531,3 +1532,28 @@ def beep(): else: dataToStdout('\a', True) + +def runningAsAdmin(): + isAdmin = False + + if PLATFORM in ( "posix", "mac" ): + isAdmin = os.geteuid() + + if isinstance(isAdmin, (int, float, long)) and isAdmin == 0: + isAdmin = True + elif IS_WIN: + isAdmin = ctypes.windll.shell32.IsUserAnAdmin() + + if isinstance(isAdmin, (int, float, long)) and isAdmin == 1: + isAdmin = True + else: + errMsg = "sqlmap is not able to check if you are running it " + errMsg += "as an administrator accout on this platform. " + errMsg += "sqlmap will assume that you are an administrator " + errMsg += "which is mandatory for the requested takeover attack " + errMsg += "to work properly" + logger.error(errMsg) + + isAdmin = True + + return isAdmin diff --git a/lib/core/option.py b/lib/core/option.py index 521d22143..df2f6f7e6 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -9,7 +9,6 @@ See the file 'doc/COPYING' for copying permission import codecs import cookielib -import ctypes import difflib import inspect import logging @@ -31,6 +30,7 @@ from lib.core.common import parseTargetDirect from lib.core.common import parseTargetUrl from lib.core.common import paths from lib.core.common import randomRange +from lib.core.common import runningAsAdmin from lib.core.common import sanitizeStr from lib.core.common import UnicodeRawConfigParser from lib.core.data import conf @@ -340,12 +340,10 @@ def __setMetasploit(): msfEnvPathExists = False if IS_WIN: - warnMsg = "Metasploit's msfconsole and msfcli are not supported " - warnMsg += "on the native Windows Ruby interpreter. Please " - warnMsg += "install Metasploit, Python interpreter and sqlmap on " - warnMsg += "Cygwin or use Linux in VMWare to use sqlmap takeover " - warnMsg += "out-of-band features. sqlmap will now continue " - warnMsg += "without calling any takeover feature" + warnMsg = "some sqlmap takeover functionalities are not yet " + warnMsg += "supported on Windows. Please use Linux in a virtual " + warnMsg += "machine for out-of-band features. sqlmap will now " + warnMsg += "carry on ignoring out-of-band switches" logger.warn(warnMsg) conf.osPwn = None @@ -355,35 +353,13 @@ def __setMetasploit(): return if conf.osSmb: - isAdmin = False - - if PLATFORM in ( "posix", "mac" ): - isAdmin = os.geteuid() - - if isinstance(isAdmin, (int, float, long)) and isAdmin == 0: - isAdmin = True - - elif IS_WIN: - isAdmin = ctypes.windll.shell32.IsUserAnAdmin() - - if isinstance(isAdmin, (int, float, long)) and isAdmin == 1: - isAdmin = True - - else: - warnMsg = "sqlmap is not able to check if you are running it " - warnMsg += "as an Administrator accout on this platform. " - warnMsg += "sqlmap will assume that you are an Administrator " - warnMsg += "which is mandatory for the SMB relay attack to " - warnMsg += "work properly" - logger.warn(warnMsg) - - isAdmin = True + isAdmin = runningAsAdmin() if isAdmin is not True: - errMsg = "you need to run sqlmap as an Administrator/root " - errMsg += "user if you want to perform a SMB relay attack " - errMsg += "because it will need to listen on a user-specified " - errMsg += "SMB TCP port for incoming connection attempts" + errMsg = "you need to run sqlmap as an administrator " + errMsg += "if you want to perform a SMB relay attack because " + errMsg += "it will need to listen on a user-specified SMB " + errMsg += "TCP port for incoming connection attempts" raise sqlmapMissingPrivileges, errMsg if conf.msfPath: