From 707aeb73db15ab009b7f49028daa95cb0260bad0 Mon Sep 17 00:00:00 2001 From: david942j Date: Thu, 25 Oct 2018 06:48:35 -0700 Subject: [PATCH] Fix circular require --- lib/one_gadget/emulators/x86.rb | 4 ++-- lib/one_gadget/fetchers/amd64.rb | 3 +-- lib/one_gadget/gadget.rb | 2 +- lib/one_gadget/helper.rb | 9 --------- lib/one_gadget/logger.rb | 8 ++++++++ lib/one_gadget/update.rb | 2 +- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/one_gadget/emulators/x86.rb b/lib/one_gadget/emulators/x86.rb index 2d3cd71..8cdd8a8 100644 --- a/lib/one_gadget/emulators/x86.rb +++ b/lib/one_gadget/emulators/x86.rb @@ -46,8 +46,8 @@ module OneGadget false end - # Support instruction set. - # @return [Array] The support instructions. + # Supported instruction set. + # @return [Array] The supported instructions. def instructions [ Instruction.new('add', 2), diff --git a/lib/one_gadget/fetchers/amd64.rb b/lib/one_gadget/fetchers/amd64.rb index 32903e1..cad58ff 100644 --- a/lib/one_gadget/fetchers/amd64.rb +++ b/lib/one_gadget/fetchers/amd64.rb @@ -19,7 +19,7 @@ module OneGadget true end - cands + jmp_case_candidates # + sigaction_case_candidates + cands + jmp_case_candidates end # find gadgets in form: @@ -30,7 +30,6 @@ module OneGadget # ... # call execve def jmp_case_candidates - bin_sh_hex = str_offset('/bin/sh').to_s(16) `#{objdump_cmd}|egrep 'rdi.*# #{bin_sh_hex}' -A 3`.split('--').map do |cand| cand = cand.lines.map(&:strip).reject(&:empty?) jmp_at = cand.index { |c| c.include?('jmp') } diff --git a/lib/one_gadget/gadget.rb b/lib/one_gadget/gadget.rb index ac42417..45b3d60 100644 --- a/lib/one_gadget/gadget.rb +++ b/lib/one_gadget/gadget.rb @@ -60,7 +60,7 @@ module OneGadget return build_not_found if table.nil? # remote doesn't have this one either. # builds found in remote! Ask update gem and download remote gadgets. - OneGadget::Helper.ask_update(msg: 'The desired one-gadget can be found in lastest version!') + OneGadget::Logger.ask_update(msg: 'The desired one-gadget can be found in lastest version!') tmp_file = OneGadget::Helper.download_build(table) require tmp_file.path tmp_file.unlink diff --git a/lib/one_gadget/helper.rb b/lib/one_gadget/helper.rb index 1bd3cd6..6494971 100644 --- a/lib/one_gadget/helper.rb +++ b/lib/one_gadget/helper.rb @@ -6,7 +6,6 @@ require 'tempfile' require 'elftools' require 'one_gadget/error' -require 'one_gadget/logger' module OneGadget # Define some helpful methods here. @@ -184,14 +183,6 @@ module OneGadget nil end - # Show the message of ask user to update gem. - # @return [void] - def ask_update(msg: '') - name = 'one_gadget' - cmd = colorize("gem update #{name} && gem cleanup #{name}") - OneGadget::Logger.info(msg + "\n" + "Update with: $ #{cmd}" + "\n") - end - # Fetch the file archiecture of +file+. # @param [String] file The target ELF filename. # @return [Symbol] diff --git a/lib/one_gadget/logger.rb b/lib/one_gadget/logger.rb index 32a024c..4ddec84 100644 --- a/lib/one_gadget/logger.rb +++ b/lib/one_gadget/logger.rb @@ -31,6 +31,14 @@ module OneGadget [] end + # Show the message of ask user to update gem. + # @return [void] + def ask_update(msg: '') + name = 'one_gadget' + cmd = OneGadget::Helper.colorize("gem update #{name} && gem cleanup #{name}") + OneGadget::Logger.info(msg + "\n" + "Update with: $ #{cmd}" + "\n") + end + %i[info warn error].each do |sym| define_method(sym) do |msg| @logger.__send__(sym, msg) diff --git a/lib/one_gadget/update.rb b/lib/one_gadget/update.rb index 1dc750c..abbbf9a 100644 --- a/lib/one_gadget/update.rb +++ b/lib/one_gadget/update.rb @@ -29,7 +29,7 @@ module OneGadget # show update message msg = format('A newer version of OneGadget is available (%s --> %s).', OneGadget::VERSION, latest) - OneGadget::Helper.ask_update(msg: msg) + OneGadget::Logger.ask_update(msg: msg) end private