Code refactoring

This commit is contained in:
Bernardo Damele 2010-10-27 20:39:50 +00:00
parent 7715ba778b
commit 43de8247ac
2 changed files with 36 additions and 34 deletions

View File

@ -8,6 +8,7 @@ See the file 'doc/COPYING' for copying permission
""" """
import codecs import codecs
import ctypes
import inspect import inspect
import os import os
import random import random
@ -1531,3 +1532,28 @@ def beep():
else: else:
dataToStdout('\a', True) 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

View File

@ -9,7 +9,6 @@ See the file 'doc/COPYING' for copying permission
import codecs import codecs
import cookielib import cookielib
import ctypes
import difflib import difflib
import inspect import inspect
import logging import logging
@ -31,6 +30,7 @@ from lib.core.common import parseTargetDirect
from lib.core.common import parseTargetUrl from lib.core.common import parseTargetUrl
from lib.core.common import paths from lib.core.common import paths
from lib.core.common import randomRange from lib.core.common import randomRange
from lib.core.common import runningAsAdmin
from lib.core.common import sanitizeStr from lib.core.common import sanitizeStr
from lib.core.common import UnicodeRawConfigParser from lib.core.common import UnicodeRawConfigParser
from lib.core.data import conf from lib.core.data import conf
@ -340,12 +340,10 @@ def __setMetasploit():
msfEnvPathExists = False msfEnvPathExists = False
if IS_WIN: if IS_WIN:
warnMsg = "Metasploit's msfconsole and msfcli are not supported " warnMsg = "some sqlmap takeover functionalities are not yet "
warnMsg += "on the native Windows Ruby interpreter. Please " warnMsg += "supported on Windows. Please use Linux in a virtual "
warnMsg += "install Metasploit, Python interpreter and sqlmap on " warnMsg += "machine for out-of-band features. sqlmap will now "
warnMsg += "Cygwin or use Linux in VMWare to use sqlmap takeover " warnMsg += "carry on ignoring out-of-band switches"
warnMsg += "out-of-band features. sqlmap will now continue "
warnMsg += "without calling any takeover feature"
logger.warn(warnMsg) logger.warn(warnMsg)
conf.osPwn = None conf.osPwn = None
@ -355,35 +353,13 @@ def __setMetasploit():
return return
if conf.osSmb: if conf.osSmb:
isAdmin = False isAdmin = runningAsAdmin()
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
if isAdmin is not True: if isAdmin is not True:
errMsg = "you need to run sqlmap as an Administrator/root " errMsg = "you need to run sqlmap as an administrator "
errMsg += "user if you want to perform a SMB relay attack " errMsg += "if you want to perform a SMB relay attack because "
errMsg += "because it will need to listen on a user-specified " errMsg += "it will need to listen on a user-specified SMB "
errMsg += "SMB TCP port for incoming connection attempts" errMsg += "TCP port for incoming connection attempts"
raise sqlmapMissingPrivileges, errMsg raise sqlmapMissingPrivileges, errMsg
if conf.msfPath: if conf.msfPath: