Skip to content
This repository was archived by the owner on Oct 22, 2020. It is now read-only.

Commit 3fe58dd

Browse files
committed
Fix broken namespaces and migrate entry point into new bin
1 parent c0f1f98 commit 3fe58dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+219
-297
lines changed

bin/wpxf

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,52 @@
11
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require 'wpxf'
5+
require 'wpxf/cli/console'
6+
require 'wpxf/cli/banner'
7+
8+
begin
9+
Slop.parse do |o|
10+
o.on '--version', 'print the version' do
11+
puts Wpxf.version
12+
exit
13+
end
14+
end
15+
rescue Slop::UnknownOption => e
16+
puts e.message
17+
exit
18+
end
19+
20+
console = Wpxf::Cli::Console.new
21+
console.check_cache
22+
console.clear
23+
24+
banner = Wpxf::Cli::Banner.new
25+
banner.display
26+
27+
Dir.chdir(Dir.tmpdir) do
28+
temp_directories = Dir.glob('wpxf_*')
29+
unless temp_directories.empty?
30+
print '[!] '.yellow
31+
puts "#{temp_directories.length} temporary files were found that "\
32+
'appear to no longer be needed.'
33+
print ' Would you like to remove these files? [y/n]: '
34+
temp_directories.each { |d| FileUtils.rm_r(d) } if gets.chomp =~ /^y$/i
35+
puts
36+
end
37+
end
38+
39+
found_env_var = false
40+
ENV.each do |name, value|
41+
next if name.casecmp('wpxf_env').zero?
42+
match = name.match(/^wpxf_(.+)/i)
43+
44+
if match
45+
console.gset match.captures[0], value
46+
found_env_var = true
47+
end
48+
end
49+
50+
puts if found_env_var
51+
console.start
52+
console.clear

env.rb

Lines changed: 0 additions & 61 deletions
This file was deleted.

lib/wpxf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ def self.change_stdout_sync(enabled)
4949
end
5050

5151
require_relative '../db/env'
52+
require 'wpxf/core'

lib/wpxf/cli/auto_complete.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def refresh_autocomplete_options
5151
def build_cmd_list
5252
cmds = {}
5353
permitted_commands.each { |c| cmds[c] = {} }
54-
Models::Module.each { |m| cmds['use'][m.path] = {} }
54+
Wpxf::Models::Module.each { |m| cmds['use'][m.path] = {} }
5555
cmds['show'] = {
5656
'options' => {},
5757
'advanced' => {},

lib/wpxf/cli/banner.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def format_colour(value)
2020
end
2121

2222
def auxiliary_count
23-
Models::Module.where(type: 'auxiliary').count
23+
Wpxf::Models::Module.where(type: 'auxiliary').count
2424
end
2525

2626
def exploit_count
27-
Models::Module.where(type: 'exploit').count
27+
Wpxf::Models::Module.where(type: 'exploit').count
2828
end
2929

3030
def format_data(value)

lib/wpxf/cli/context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def load_module(path)
1818
end
1919

2020
def reload
21-
load("#{@module_path}.rb")
21+
load("wpxf/modules/#{@module_path}.rb")
2222
load_module(@module_path)
2323
end
2424

lib/wpxf/cli/creds.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Cli
55
# A mixin to provide functions to interact with credentials stored in the database.
66
module Creds
77
def delete_credential(id)
8-
item = Models::Credential.first(
8+
item = Wpxf::Models::Credential.first(
99
id: id.to_i,
1010
workspace: active_workspace
1111
)
@@ -28,7 +28,7 @@ def list_credentials
2828
type: 'Type'
2929
)
3030

31-
Models::Credential.where(workspace: active_workspace).each do |cred|
31+
Wpxf::Models::Credential.where(workspace: active_workspace).each do |cred|
3232
rows.push(
3333
id: cred.id,
3434
host: "#{cred.host}:#{cred.port}",

lib/wpxf/cli/help.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def help
6565
end
6666

6767
def show_exploits
68-
modules = Models::Module.where(type: 'exploit')
68+
modules = Wpxf::Models::Module.where(type: 'exploit')
6969
.order(:path)
7070
.map { |m| { path: m.path, title: m.name } }
7171

@@ -74,7 +74,7 @@ def show_exploits
7474
end
7575

7676
def show_auxiliary
77-
modules = Models::Module.where(type: 'auxiliary')
77+
modules = Wpxf::Models::Module.where(type: 'auxiliary')
7878
.order(:path)
7979
.map { |m| { path: m.path, title: m.name } }
8080

lib/wpxf/cli/loot.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def build_loot_table
1818
type: 'Type'
1919
)
2020

21-
Models::LootItem.where(workspace: active_workspace).each do |item|
21+
Wpxf::Models::LootItem.where(workspace: active_workspace).each do |item|
2222
rows.push(
2323
id: item.id,
2424
host: "#{item.host}:#{item.port}",
@@ -39,7 +39,7 @@ def list_loot
3939
end
4040

4141
def find_loot_item(id)
42-
item = Models::LootItem.first(
42+
item = Wpxf::Models::LootItem.first(
4343
id: id.to_i,
4444
workspace: active_workspace
4545
)

lib/wpxf/cli/module_cache.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ module Cli
66
module ModuleCache
77
def initialize
88
super
9-
self.current_version_number = File.read(File.join(Wpxf.app_path, 'VERSION'))
9+
self.current_version_number = Wpxf.version
1010
end
1111

1212
def cache_valid?
13-
last_version_log = Models::Log.first(key: 'version')
13+
last_version_log = Wpxf::Models::Log.first(key: 'version')
1414
return false if last_version_log.nil?
1515

1616
current_version = Gem::Version.new(current_version_number)
@@ -24,7 +24,7 @@ def create_module_models(type)
2424
namespace.module_list.each do |mod|
2525
instance = mod[:class].new
2626

27-
Models::Module.create(
27+
Wpxf::Models::Module.create(
2828
path: mod[:name],
2929
name: instance.module_name,
3030
type: type,
@@ -34,8 +34,8 @@ def create_module_models(type)
3434
end
3535

3636
def refresh_version_log
37-
log = Models::Log.first(key: 'version')
38-
log = Models::Log.new if log.nil?
37+
log = Wpxf::Models::Log.first(key: 'version')
38+
log = Wpxf::Models::Log.new if log.nil?
3939
log.key = 'version'
4040
log.value = current_version_number
4141
log.save
@@ -44,7 +44,7 @@ def refresh_version_log
4444
def rebuild_cache
4545
print_warning 'Refreshing the module cache...'
4646

47-
Models::Module.truncate
47+
Wpxf::Models::Module.truncate
4848

4949
create_module_models 'exploit'
5050
create_module_models 'auxiliary'

lib/wpxf/cli/modules.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def module_name_from_class(klass)
5959
end
6060

6161
def search_modules(args)
62-
modules = Models::Module.where(Sequel.ilike(:name, "%#{args.join(' ')}%"))
62+
modules = Wpxf::Models::Module.where(Sequel.ilike(:name, "%#{args.join(' ')}%"))
6363
modules.map { |m| { path: m.path, title: m.name } }
6464
end
6565

lib/wpxf/cli/workspace.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Workspace
77
def initialize
88
super
99

10-
self.active_workspace = Models::Workspace.first(name: 'default')
10+
self.active_workspace = Wpxf::Models::Workspace.first(name: 'default')
1111
end
1212

1313
def workspace(*args)
@@ -24,16 +24,16 @@ def workspace(*args)
2424
end
2525

2626
def workspaces
27-
Models::Workspace.all
27+
Wpxf::Models::Workspace.all
2828
end
2929

3030
def add_workspace(name)
31-
unless Models::Workspace.where(name: name).count.zero?
31+
unless Wpxf::Models::Workspace.where(name: name).count.zero?
3232
return print_warning "#{name} already exists"
3333
end
3434

3535
begin
36-
Models::Workspace.create(name: name)
36+
Wpxf::Models::Workspace.create(name: name)
3737
return print_good "Added workspace: #{name}"
3838
rescue Sequel::ValidationFailed
3939
print_warning 'Workspace names may only contain 1-50 alphanumeric characters and underscores'
@@ -51,7 +51,7 @@ def list_workspaces
5151
end
5252

5353
def switch_workspace(name)
54-
next_workspace = Models::Workspace.first(name: name)
54+
next_workspace = Wpxf::Models::Workspace.first(name: name)
5555

5656
if next_workspace
5757
self.active_workspace = next_workspace
@@ -69,7 +69,7 @@ def delete_workspace(name)
6969
end
7070

7171
current_name = active_workspace.name
72-
Models::Workspace.where(name: name).destroy
72+
Wpxf::Models::Workspace.where(name: name).destroy
7373
print_good "Deleted workspace: #{name}"
7474
switch_workspace 'default' if name == current_name
7575
end

lib/wpxf/db/credentials.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ module Wpxf::Db::Credentials
88
# @param type [String] the type of string stored in the password field.
99
# @return [Models::Credential] the newly created {Models::Credential}.
1010
def store_credentials(username, password = '', type = 'plain')
11-
credential = Models::Credential.first(
11+
credential = Wpxf::Models::Credential.first(
1212
host: target_host,
1313
port: target_port,
1414
username: username,
1515
type: type,
1616
workspace: active_workspace
1717
)
1818

19-
credential = Models::Credential.new if credential.nil?
19+
credential = Wpxf::Models::Credential.new if credential.nil?
2020
credential.host = target_host
2121
credential.port = target_port
2222
credential.username = username

lib/wpxf/db/loot.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Wpxf::Db::Loot
77
# @param type [String] the type of loot acquired.
88
# @return [Models::LootItem] the newly created {Models::LootItem}.
99
def store_loot(path, notes = '', type = 'unknown')
10-
Models::LootItem.create(
10+
Wpxf::Models::LootItem.create(
1111
host: target_host,
1212
port: target_port,
1313
path: path,

lib/wpxf/modules.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def self.build_module_list(namespace, folder_name = '')
66
namespace.const_get(c).is_a? Class
77
end
88

9-
modules_directory = File.join(Wpxf.app_path, folder_name)
9+
modules_directory = File.join(Wpxf.app_path, 'lib', 'wpxf', folder_name)
1010

1111
modules.map do |m|
1212
klass = namespace.const_get(m)
@@ -19,7 +19,7 @@ def self.build_module_list(namespace, folder_name = '')
1919
end
2020

2121
def self.load_module(path)
22-
mod = Models::Module.first(path: path)
22+
mod = Wpxf::Models::Module.first(path: path)
2323
raise "\"#{path}\" is not a valid module" if mod.nil?
2424
Object.const_get(mod.class_name).new
2525
end

spec/lib/wpxf/cli/banner_spec.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
allow(subject).to receive(:puts)
1111

1212
(1..5).each do |i|
13-
Models::Module.create(
13+
Wpxf::Models::Module.create(
1414
path: "test#{i}/",
1515
name: "Test #{i}",
1616
class_name: "Test#{i}",
@@ -19,7 +19,7 @@
1919
end
2020

2121
(6..8).each do |i|
22-
Models::Module.create(
22+
Wpxf::Models::Module.create(
2323
path: "test#{i}/",
2424
name: "Test #{i}",
2525
class_name: "Test#{i}",
@@ -30,7 +30,7 @@
3030

3131
describe '#new' do
3232
it 'should initialise #raw_content with the content of `data/banners/default.txt`' do
33-
base_path = File.expand_path(File.join(__dir__, '..', '..', '..'))
33+
base_path = File.expand_path(File.join(__dir__, '..', '..', '..', '..'))
3434
banner_path = File.join(base_path, 'data', 'banners', 'default.txt')
3535
expected = File.read(banner_path)
3636

@@ -79,10 +79,7 @@
7979

8080
describe '#format_data' do
8181
it 'should replace {VERSION} with the current version of WPXF' do
82-
base_path = File.expand_path(File.join(__dir__, '..', '..', '..'))
83-
version_path = File.join(base_path, 'VERSION')
84-
expected = File.read(version_path).strip
85-
82+
expected = Wpxf.version
8683
expect(subject.format_data('V:{VERSION}')).to eql "V:#{expected}"
8784
end
8885

0 commit comments

Comments
 (0)