Add Android POST API

bug/bundler_fix
wchen-r7 2015-08-24 18:37:25 -05:00
parent 4af86f210c
commit 3412f31f85
5 changed files with 149 additions and 0 deletions

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 uid =~ /^0$/
return true
else
return false
end
end
private
def get_id
cmd_exec('id')
end
end ; end ; end ; end

View File

@ -0,0 +1,39 @@
# -*- 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
public
# Returns system information from build.prop.
#
# @return [Hash] System information.
def get_sysinfo
sys_data = {}
build_prop = get_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
private
def get_build_prop
cmd_exec('cat /system/build.prop')
end
end ; end ; end ; end

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 root' do
it 'returns TrueClass' do
allow(subject).to receive(:cmd_exec).with('id').and_return(nonroot_id)
expect(subject.is_root?).to be_falsey
end
end
context 'when non root' do
it 'reeturns FalseClass' 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_sysinfo['ro.build.version.release']).to eq(expected_android_version)
end
end
end