Skip to content

Commit

Permalink
lib spec progress
Browse files Browse the repository at this point in the history
  • Loading branch information
h00die committed Dec 5, 2024
1 parent cde6600 commit 9ccc0a3
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 12 deletions.
2 changes: 2 additions & 0 deletions lib/msf/core/post/linux/busy_box.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: binary -*-

require 'rex'

module Msf
class Post
module Linux
Expand Down
1 change: 1 addition & 0 deletions lib/msf/core/post/linux/priv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Post
module Linux
module Priv
include ::Msf::Post::Common
include ::Msf::Post::File

#
# Returns true if running as root, false if not.
Expand Down
2 changes: 2 additions & 0 deletions lib/msf/core/post/linux/process.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: binary -*-

require 'rex/post'

module Msf
class Post
module Linux
Expand Down
8 changes: 5 additions & 3 deletions lib/msf/core/post/linux/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,12 @@ def protected_symlinks?
#
def glibc_version
raise 'glibc is not installed' unless command_exists? 'ldd'
begin

cmd_exec('ldd --version').scan(/^ldd\s+\(.*\)\s+([\d.]+)/).flatten.first
rescue StandardError
raise 'Could not determine glibc version'
cmd_exec('ldd --version').scan(/^ldd\s+\(.*\)\s+([\d.]+)/).flatten.first
rescue StandardError
raise 'Could not determine glibc version'
end
end

#
Expand Down
4 changes: 1 addition & 3 deletions spec/lib/msf/core/post/linux/compile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,17 @@
it 'raises an error if the specified compiler is not available' do
allow(subject).to receive(:datastore).and_return({ 'COMPILE' => 'True', 'COMPILER' => 'gcc' })
allow(subject).to receive(:has_gcc?).and_return(false)
expect { subject.live_compile? }.to raise_error(Msf::Module::Failure::BadConfig, 'gcc is not installed. Set COMPILE False to upload a pre-compiled executable')
expect { subject.live_compile? }.to raise_error(RuntimeError, 'bad-config: gcc is not installed. Set COMPILE False to upload a pre-compiled executable.')
end
end

describe '#upload_and_compile' do
let(:source) { '/path/to/source.c' }
let(:destination) { '/tmp/source.c' }
let(:output) { '/tmp/output' }
let(:session) { double('session') }

before do
allow(subject).to receive(:get_compiler).and_return('gcc')
allow(subject).to receive(:session).and_return(session)
end

it 'uploads the source file and compiles it' do
Expand Down
9 changes: 6 additions & 3 deletions spec/lib/msf/core/post/linux/priv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
file_content = 'file content'

allow(subject).to receive(:read_file).with(origin_file).and_return(file_content)
expect(subject).to receive(:cmd_exec).with("echo '#{file_content}' > #{final_file}")
expect(subject).to receive(:cmd_exec).with("echo '#{file_content}' > '#{final_file}'")

subject.cp_cmd(origin_file, final_file)
end
Expand Down Expand Up @@ -83,7 +83,10 @@
file_content = "Hello\nWorld"
allow(subject).to receive(:read_file).with(file).and_return(file_content)

expect(subject.nchars_file(file)).to eq(10)
# agrees with wc
# $ echo -n "Hello\nWorld" | wc -m
# 12
expect(subject.nchars_file(file)).to eq(12)
end
end

Expand All @@ -93,7 +96,7 @@
file_content = "Hello World\nThis is a test"
allow(subject).to receive(:read_file).with(file).and_return(file_content)

expect(subject.nwords_file(file)).to eq(5)
expect(subject.nwords_file(file)).to eq(6)
end
end

Expand Down
3 changes: 2 additions & 1 deletion spec/lib/msf/core/post/linux/process_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
let(:length) { 64 }
let(:pid) { 1234 }
let(:memory_content) { 'memory content' }
let(:PROCESS_READ) {(1 << 0)}

it 'reads memory from the specified base address and length' do
expect(subject).to receive(:session)
expect(subject).to receive(:open).with(pid, PROCESS_READ).and_return(1)
expect(memory).to receive(:read).with(base_address, length).and_return(memory_content)

Expand All @@ -23,6 +23,7 @@
end

it 'uses the default pid if not specified' do
expect(subject).to receive(:session)
expect(subject).to receive(:open).with(0, PROCESS_READ).and_return(1)
expect(memory).to receive(:read).with(base_address, length).and_return(memory_content)

Expand Down
6 changes: 4 additions & 2 deletions spec/lib/msf/core/post/linux/system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@
end

it 'raises an error if unable to determine glibc version' do
allow(subject).to receive(:command_exists?).with('ldd').and_return(true)
allow(subject).to receive(:cmd_exec).with('ldd --version').and_raise(StandardError)
expect { subject.glibc_version }.to raise_error('Could not determine glibc version')
end
Expand All @@ -446,9 +447,10 @@

describe '#ips' do
it 'returns all IP addresses of the device' do
fib_trie_content = " +-- 192.168.1.1/32 host LOCAL\n"
# content from https://medium.com/@linuxadminhacks/find-the-names-of-the-network-interfaces-by-their-ips-4ef82326e49e
fib_trie_content = "Main:\n +-- 0.0.0.0/0 3 0 5\n +-- 192.168.1.0/24 2 0 2\n +-- 192.168.1.0/30 2 0 2\n |-- 192.168.1.3\n /32 host LOCAL"
allow(subject).to receive(:read_file).with('/proc/net/fib_trie').and_return(fib_trie_content)
expect(subject.ips).to eq(['192.168.1.1'])
expect(subject.ips).to eq(['192.168.1.3'])
end
end

Expand Down

0 comments on commit 9ccc0a3

Please sign in to comment.