Land #5890, add Android post API

bug/bundler_fix
Brent Cook 2015-09-03 10:31:55 -05:00
commit e59db5077b
No known key found for this signature in database
GPG Key ID: 1FFAA0B24B708F96
7 changed files with 144 additions and 3 deletions

View File

@ -9,7 +9,7 @@ PATH
json
metasploit-concern (= 1.0.0)
metasploit-model (= 1.0.0)
metasploit-payloads (= 1.0.11)
metasploit-payloads (= 1.0.12)
msgpack
nokogiri
packetfu (= 1.1.9)
@ -123,7 +123,7 @@ GEM
activemodel (>= 4.0.9, < 4.1.0)
activesupport (>= 4.0.9, < 4.1.0)
railties (>= 4.0.9, < 4.1.0)
metasploit-payloads (1.0.11)
metasploit-payloads (1.0.12)
metasploit_data_models (1.2.5)
activerecord (>= 4.0.9, < 4.1.0)
activesupport (>= 4.0.9, < 4.1.0)

View File

@ -0,0 +1,8 @@
# -*- coding: binary -*-
module Msf::Post::Android
require 'msf/core/post/android/system'
require 'msf/core/post/android/priv'
end

View File

@ -0,0 +1,35 @@
# -*- coding: binary -*-
require 'msf/core/post/common'
require 'msf/core/post/file'
require 'msf/core/post/unix'
module Msf
class Post
module Android
module Priv
include Msf::Post::Common
public
# Returns whether we are running as root or not.
#
# @return [Boolean] TrueClass if as root, otherwise FalseClass.
def is_root?
id = cmd_exec('id')
uid = id.scan(/uid=(\d+)(.+)/).flatten.first
if /^0$/ === uid
return true
else
return false
end
end
private
def get_id
cmd_exec('id')
end
end ; end ; end ; end

View File

@ -0,0 +1,31 @@
# -*- coding: binary -*-
require 'msf/core/post/common'
require 'msf/core/post/file'
require 'msf/core/post/unix'
module Msf
class Post
module Android
module System
include Msf::Post::Common
include Msf::Post::File
# Returns system information from build.prop.
#
# @return [Hash] System information.
def get_build_prop
sys_data = {}
build_prop = cmd_exec('cat /system/build.prop')
return sys_data if build_prop.blank?
build_prop.scan(/(.+)=(.+)/i).collect {|e| Hash[*e]}.each do |setting|
sys_data.merge!(setting)
end
return sys_data
end
end ; end ; end ; end

View File

@ -61,7 +61,7 @@ Gem::Specification.new do |spec|
# are needed when there's no database
spec.add_runtime_dependency 'metasploit-model', '1.0.0'
# Needed for Meterpreter
spec.add_runtime_dependency 'metasploit-payloads', '1.0.11'
spec.add_runtime_dependency 'metasploit-payloads', '1.0.12'
# Needed by msfgui and other rpc components
spec.add_runtime_dependency 'msgpack'
# Needed by anemone crawler

View File

@ -0,0 +1,37 @@
# -*- coding: binary -*-
require 'msf/core/post/android/priv'
describe Msf::Post::Android::Priv do
subject do
mod = Module.new
mod.extend(described_class)
mod
end
let(:nonroot_id) do
%Q|uid=10043(u0_a43) gid=10043(u0_a43) groups=1006(camera),1015(sdcard_rw),1028(sdcard_r),3003(inet)|
end
let(:root_id) do
%Q|uid=0(0)|
end
describe '#is_root?' do
context 'when not root' do
it 'returns FalseClass' do
allow(subject).to receive(:cmd_exec).with('id').and_return(nonroot_id)
expect(subject.is_root?).to be_falsey
end
end
context 'when root' do
it 'returns TrueClass' do
allow(subject).to receive(:cmd_exec).with('id').and_return(root_id)
expect(subject.is_root?).to be_truthy
end
end
end
end

View File

@ -0,0 +1,30 @@
# -*- coding: binary -*-
require 'msf/core/post/android/system'
describe Msf::Post::Android::System do
subject do
mod = Module.new
mod.extend(described_class)
mod
end
let(:build_prop_output) do
%Q|ro.build.version.sdk=16
ro.build.version.release=4.1.1
|
end
describe '#get_sysinfo' do
let(:expected_android_version) do
'4.1.1'
end
it 'returns the android version' do
allow(subject).to receive(:cmd_exec).and_return(build_prop_output)
expect(subject.get_build_prop['ro.build.version.release']).to eq(expected_android_version)
end
end
end