Skip to content

Commit

Permalink
Merge branch 'feature/fix_2703' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
andresriancho committed Jun 4, 2014
2 parents 37264a8 + 3c78276 commit 806835d
Show file tree
Hide file tree
Showing 28 changed files with 707 additions and 744 deletions.
62 changes: 29 additions & 33 deletions w3af/core/controllers/dependency_check/dependency_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
print('http://www.pip-installer.org/en/latest/installing.html')
HAS_PIP = False
except AttributeError:
print('A very old version of pip was detected. We recommend you update your'
' your pip installation before continuing:')
print('A very old version of pip was detected. We recommend a pip update'
' before continuing:')
print(' sudo pip install --upgrade pip')
HAS_PIP = False
else:
Expand All @@ -46,18 +46,11 @@
generate_pip_install_non_git,
generate_pip_install_git)
from .helper_requirements_txt import generate_requirements_txt
from .platforms.current_platform import (SYSTEM_NAME,
PKG_MANAGER_CMD,
SYSTEM_PACKAGES,
PIP_CMD,
PIP_PACKAGES,
os_package_is_installed,
after_hook)
from .platforms.current_platform import get_current_platform
from .platforms.base_platform import CORE


def dependency_check(pip_packages=PIP_PACKAGES, system_packages=SYSTEM_PACKAGES,
system_name=SYSTEM_NAME, pkg_manager_cmd=PKG_MANAGER_CMD,
pip_cmd=PIP_CMD, exit_on_failure=True):
def dependency_check(dependency_set=CORE, exit_on_failure=True):
"""
This function verifies that the dependencies that are needed by the
framework core are met.
Expand All @@ -67,16 +60,19 @@ def dependency_check(pip_packages=PIP_PACKAGES, system_packages=SYSTEM_PACKAGES,
verify_python_version()

disable_warnings()


platform = get_current_platform()

#
# Check for missing python modules
#
failed_deps = []

pip_distributions = []
if HAS_PIP: pip_distributions = pip.get_installed_distributions()

if HAS_PIP:
pip_distributions = pip.get_installed_distributions()

for w3af_req in pip_packages:
for w3af_req in platform.PIP_PACKAGES[dependency_set]:
if HAS_PIP:
dependency_specs = w3af_req.package_name, w3af_req.package_version
for dist in pip_distributions:
Expand All @@ -91,31 +87,27 @@ def dependency_check(pip_packages=PIP_PACKAGES, system_packages=SYSTEM_PACKAGES,
if not lazy_load(w3af_req.module_name):
failed_deps.append(w3af_req)
except KeyboardInterrupt:
print 'User exit with Ctrl+C.'
print('User exit with Ctrl+C.')
sys.exit(-1)

#
# Check for missing operating system packages
#
missing_os_packages = []
for _, packages in system_packages.items():
for package in packages:
if not os_package_is_installed(package):
missing_os_packages.append(package)
for os_package in platform.SYSTEM_PACKAGES[dependency_set]:
if not platform.os_package_is_installed(os_package):
missing_os_packages.append(os_package)

os_packages = list(set(missing_os_packages))

if not HAS_PIP:
os_packages.extend(system_packages['PIP'])

# All installed?
if not failed_deps and not os_packages:
# False means: do not exit()
return False

generate_requirements_txt(failed_deps)
script_path = generate_helper_script(pkg_manager_cmd, os_packages,
pip_cmd, failed_deps)
script_path = generate_helper_script(platform.PKG_MANAGER_CMD, os_packages,
platform.PIP_CMD, failed_deps)

#
# Report the missing system packages
Expand All @@ -129,7 +121,8 @@ def dependency_check(pip_packages=PIP_PACKAGES, system_packages=SYSTEM_PACKAGES,
msg += 'On %s systems please install the following operating'\
' system packages before running the pip installer:\n'\
' %s %s\n'
print msg % (system_name, pkg_manager_cmd, missing_pkgs)
print(msg % (platform.SYSTEM_NAME, platform.PKG_MANAGER_CMD,
missing_pkgs))

#
# Report all missing python modules
Expand All @@ -138,7 +131,8 @@ def dependency_check(pip_packages=PIP_PACKAGES, system_packages=SYSTEM_PACKAGES,
msg = 'Your python installation needs the following modules'\
' to run w3af:\n'
msg += ' ' + ' '.join([fdep.module_name for fdep in failed_deps])
print msg, '\n'
print(msg)
print('\n')

#
# Report missing pip packages
Expand All @@ -150,20 +144,21 @@ def dependency_check(pip_packages=PIP_PACKAGES, system_packages=SYSTEM_PACKAGES,
' pip to install the remaining modules:\n'

if not_git_pkgs:
cmd = generate_pip_install_non_git(pip_cmd, not_git_pkgs)
cmd = generate_pip_install_non_git(platform.PIP_CMD, not_git_pkgs)
msg += ' %s\n' % cmd

if git_pkgs:
for missing_git_pkg in git_pkgs:
msg += ' %s\n' % generate_pip_install_git(pip_cmd, missing_git_pkg)
msg += ' %s\n' % generate_pip_install_git(platform.PIP_CMD,
missing_git_pkg)

print msg
print(msg)

msg = 'A script with these commands has been created for you at %s'
print msg % script_path
print(msg % script_path)

enable_warnings()
after_hook()
platform.after_hook()

if exit_on_failure:
sys.exit(1)
Expand All @@ -178,6 +173,7 @@ def disable_warnings():
# scapy raises an error if tcpdump is not found in PATH
logging.disable(logging.CRITICAL)


def enable_warnings():
# Enable warnings once again
warnings.resetwarnings()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
os_detection.py
platform.py
Copyright 2013 Andres Riancho
Copyright 2014 Andres Riancho
This file is part of w3af, http://w3af.org/ .
Expand All @@ -19,36 +19,28 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
import platform
from ..requirements import CORE_PIP_PACKAGES, GUI_PIP_PACKAGES, CORE, GUI


curr_platform = platform.system().lower()
distro = platform.dist()
class Platform(object):
"""
Simple base class for defining platforms/operating systems for dependency
checks.
"""
PIP_PACKAGES = {CORE: CORE_PIP_PACKAGES,
GUI: GUI_PIP_PACKAGES}

SYSTEM_PACKAGES = {CORE: [],
GUI: []}

def is_mac():
return 'darwin' in curr_platform or 'mac' in curr_platform
@staticmethod
def is_current_platform():
raise NotImplementedError

@staticmethod
def os_package_is_installed():
raise NotImplementedError

def is_linux():
return 'linux' in curr_platform


def is_fedora():
return 'fedora' in distro[0]


def is_centos():
return 'redhat' in distro[0]


def is_suse():
return 'SuSE' in distro[0]


def is_openbsd():
return 'openbsd' in curr_platform


def is_kali():
return 'debian' in distro and 'kali' in platform.release()
@staticmethod
def after_hook():
pass
36 changes: 21 additions & 15 deletions w3af/core/controllers/dependency_check/platforms/centos.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,29 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
from w3af.core.controllers.dependency_check.platforms.fedora import os_package_is_installed
import platform

SYSTEM_NAME = 'CentOS'
from .fedora import Fedora
from ..requirements import CORE, GUI

PKG_MANAGER_CMD = 'sudo yum install'

SYSTEM_PACKAGES = {
'PIP': ['python-pip'],
'C_BUILD': ['python-devel', 'python-setuptools',
'libsqlite3x-devel', 'gcc-c++', 'gcc', 'make'],
'GIT': ['git'],
'XML': ['libxml2-devel', 'libxslt-devel'],
'SSL': ['pyOpenSSL', 'openssl-devel', 'libcom_err-devel',
'libcom_err'],
}
PIP_CMD = 'pip-python'
class CentOS(Fedora):
SYSTEM_NAME = 'CentOS'
PKG_MANAGER_CMD = 'sudo yum install'
PIP_CMD = 'pip-python'

CORE_SYSTEM_PACKAGES = ['python-pip', 'python-devel', 'python-setuptools',
'libsqlite3x-devel', 'gcc-c++', 'gcc', 'make',
'git', 'libxml2-devel', 'libxslt-devel',
'pyOpenSSL', 'openssl-devel', 'libcom_err-devel',
'libcom_err']

def after_hook():
pass
GUI_SYSTEM_PACKAGES = CORE_SYSTEM_PACKAGES[:]
GUI_SYSTEM_PACKAGES.extend(['graphviz', 'gtksourceview2', 'pygtksourceview'])

SYSTEM_PACKAGES = {CORE: CORE_SYSTEM_PACKAGES,
GUI: GUI_SYSTEM_PACKAGES}

@staticmethod
def is_current_platform():
return 'redhat' in platform.dist()
Original file line number Diff line number Diff line change
Expand Up @@ -19,53 +19,24 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
from w3af.core.controllers.dependency_check.requirements import PIP_PACKAGES
from ..os_detection import is_mac, is_openbsd, is_fedora, is_centos, is_kali, is_suse
from .ubuntu import Ubuntu1204
from .centos import CentOS
from .fedora import Fedora
from .kali import Kali
from .mac import MacOSX
from .openbsd import OpenBSD5
from .suse import SuSE
from .default import DefaultPlatform

KNOWN_PLATFORMS = [Ubuntu1204, CentOS, Fedora, Kali, MacOSX, OpenBSD5, SuSE]

if is_mac():
from .mac import (SYSTEM_NAME, PKG_MANAGER_CMD,
SYSTEM_PACKAGES, PIP_CMD,
os_package_is_installed,
after_hook)
# Note that I'm overriding the previous import of PIP_PACKAGES, this allows
# us to have a different set of pip dependencies for Mac
#
# https://github.com/andresriancho/w3af/issues/485
from .mac import PIP_PACKAGES

elif is_openbsd():
from .openbsd import (SYSTEM_NAME, PKG_MANAGER_CMD,
SYSTEM_PACKAGES, PIP_CMD,
os_package_is_installed,
after_hook)

elif is_fedora():
from .fedora import (SYSTEM_NAME, PKG_MANAGER_CMD,
SYSTEM_PACKAGES, PIP_CMD,
os_package_is_installed,
after_hook)
def get_current_platform(known_platforms=KNOWN_PLATFORMS):
for known_platform in known_platforms:
if known_platform.is_current_platform():
return known_platform()
else:
return DefaultPlatform()

elif is_centos():
from .centos import (SYSTEM_NAME, PKG_MANAGER_CMD,
SYSTEM_PACKAGES, PIP_CMD,
os_package_is_installed,
after_hook)

elif is_kali():
from .kali import (SYSTEM_NAME, PKG_MANAGER_CMD,
SYSTEM_PACKAGES, PIP_CMD,
os_package_is_installed,
after_hook)

elif is_suse():
from .suse import (SYSTEM_NAME, PKG_MANAGER_CMD,
SYSTEM_PACKAGES, PIP_CMD,
os_package_is_installed,
after_hook)

else:
from .linux import (SYSTEM_NAME, PKG_MANAGER_CMD,
SYSTEM_PACKAGES, PIP_CMD,
os_package_is_installed,
after_hook)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
requirements.py
default.py
Copyright 2013 Andres Riancho
Copyright 2014 Andres Riancho
This file is part of w3af, http://w3af.org/ .
Expand All @@ -19,9 +19,23 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
from w3af.core.controllers.dependency_check.pip_dependency import PIPDependency
from w3af.core.controllers.dependency_check.requirements import PIP_PACKAGES
from .base_platform import Platform
from ..requirements import CORE, GUI

# I imported the information from the core, now I need to append the GUI
# requirements to those lists!
PIP_PACKAGES.extend([PIPDependency('xdot', 'xdot', '0.6'),])

class DefaultPlatform(Platform):
PIP_CMD = 'pip'

# Should never be used since we have an empty SYSTEM_PACKAGES
PKG_MANAGER_CMD = ''

SYSTEM_PACKAGES = {CORE: [],
GUI: []}

@staticmethod
def is_current_platform():
return True

@staticmethod
def os_package_is_installed():
return False
Loading

0 comments on commit 806835d

Please sign in to comment.