-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
117 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# -*- coding: binary -*- | ||
|
||
module Msf | ||
module Exploit::Local::Ansible | ||
def initialize(info = {}) | ||
super | ||
|
||
register_advanced_options([ | ||
Msf::OptString.new('ANSIBLE', [true, 'Ansible executable location', '']), | ||
Msf::OptString.new('ANSIBLEPLAYBOOK', [true, 'Ansible-playbook executable location', '']), | ||
]) | ||
end | ||
|
||
# | ||
# Uses the ansible command to ping hosts, returns an array of hashes | ||
# | ||
# @param ansible_exe [String] The name location of the ansible executable | ||
# @param hosts [String] The host string to use, defaults to 'all' | ||
# @return [Array] containing a hash for each host. Each has consists of the | ||
# following parameters: host, status, ping, changed | ||
# | ||
def ping_hosts(ansible_exe = datastore['ANSIBLE'], hosts = 'all') | ||
results = cmd_exec("#{ansible_exe} #{hosts} -m ping -o") | ||
# here's a regex with test: https://rubular.com/r/FMHhWx8QlVnidA | ||
regex = /(\S+)\s+\|\s+([A-Z]+)\s+=>\s+({.+})$/ | ||
matches = results.scan(regex) | ||
|
||
hosts = [] | ||
matches.each do |match| | ||
match[2] = JSON.parse(match[2]) | ||
hosts << { 'host' => match[0], 'status' => match[1], 'ping' => match[2]['ping'], 'changed' => match[2]['changed'] } | ||
end | ||
hosts | ||
end | ||
|
||
# | ||
# Attempts to find the ansible-playbook executable. Verifies the | ||
# executable is executable by the user as well. Defaults to looking in | ||
# standard locations for Ubuntu and Docker: | ||
# ('/usr/local/bin/ansible-playbook', '/usr/bin/ansible-playbook') | ||
# | ||
# @param suggestion [String] The location of the ansible-playbook executable if | ||
# not in a standard location | ||
# @return [String, nil] The executable location or nil if not found | ||
# | ||
def ansible_playbook_exe(suggestion = datastore['ANSIBLEPLAYBOOK']) | ||
return @ansible_playbook if @ansible_playbook | ||
|
||
[suggestion, '/usr/local/bin/ansible-playbook', '/usr/bin/ansible-playbook'].each do |exec| | ||
next if exec.nil? || exec.empty? | ||
next unless executable?(exec) | ||
|
||
@ansible_playbook = exec | ||
end | ||
@ansible_playbook | ||
end | ||
|
||
# | ||
# Attempts to find the ansible executable. Verifies the | ||
# executable is executable by the user as well. Defaults to looking in | ||
# standard locations for Ubuntu and Docker: | ||
# ('/usr/local/bin/ansible') | ||
# | ||
# @param suggestion [String] The location of the ansible executable if | ||
# not in a standard location | ||
# @return [String, nil] The executable location or nil if not found | ||
# | ||
def ansible_exe(suggestion = datastore['ANSIBLE']) | ||
return @ansible if @ansible | ||
|
||
[suggestion, '/usr/local/bin/ansible'].each do |exec| | ||
next if exec.nil? || exec.empty? | ||
next unless executable?(exec) | ||
|
||
@ansible = exec | ||
end | ||
@ansible | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters