Module: Gauntlt::Support::PythonScriptHelper

Defined in:
lib/gauntlt/attack_adapters/support/python_script_helper.rb

Constant Summary collapse

DOWNLOAD_URLS =
{
  'sslyze' => 'https://github.com/iSECPartners/sslyze',
  'sqlmap' => 'https://github.com/sqlmapproject/sqlmap'
}

Instance Method Summary collapse

Instance Method Details

#ensure_python_script_installed(script_name, debug = false) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/gauntlt/attack_adapters/support/python_script_helper.rb', line 34

def ensure_python_script_installed(script_name, debug=false)
  python_script_installed?(script_name) || begin
    shell_variable_name = '$' + shell_variable_name_for(script_name)

    msg = <<-EOS
    #{script_name}.py not installed or #{shell_variable_name} not set!

    1. Download #{script_name} from: #{DOWNLOAD_URLS[script_name]}
    2. In your .zshrc or .bash_profile (or whatever), set #{shell_variable_name}

 export #{shell_variable_name.gsub('$', '')}=/path/to/#{script_name}.py

    3. Make sure you have python installed:

 $ which python


EOS

    if debug
      msg += <<-EOS
      python installed : #{python_installed?}
      script_exists? : #{script_exists?(script_name)}
      shell_variable_name: #{shell_variable_name_for(script_name)}
      path:   #{path_to_python_script(script_name)}
      path_via_echo: #{`echo #{'$'+shell_variable_name_for(script_name)}`}
EOS
    end

    raise msg

  end
end

#path_to_python_script(script_name) ⇒ Object


20
21
22
23
# File 'lib/gauntlt/attack_adapters/support/python_script_helper.rb', line 20

def path_to_python_script(script_name)
  shell_variable_name = shell_variable_name_for(script_name)
  ENV[shell_variable_name]
end

#python_installed?Boolean


12
13
14
# File 'lib/gauntlt/attack_adapters/support/python_script_helper.rb', line 12

def python_installed?
  cli_installed?('python')
end

#python_script_installed?(script_name) ⇒ Boolean


30
31
32
# File 'lib/gauntlt/attack_adapters/support/python_script_helper.rb', line 30

def python_script_installed?(script_name)
  python_installed? && script_exists?(script_name)
end

#script_exists?(script_name) ⇒ Boolean


25
26
27
28
# File 'lib/gauntlt/attack_adapters/support/python_script_helper.rb', line 25

def script_exists?(script_name)
  path = path_to_python_script(script_name)
  File.exists?(path) if path
end

#shell_variable_name_for(script_name) ⇒ Object


16
17
18
# File 'lib/gauntlt/attack_adapters/support/python_script_helper.rb', line 16

def shell_variable_name_for(script_name)
  script_name.upcase + '_PATH'
end