Skip to content

Commit b1c3563

Browse files
committed
PWN::Plugins::Assembly module - rely upon archs native objdump bins to convert opcodes to asm within #opcodes_to_asm method
1 parent 2a497f0 commit b1c3563

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ $ cd /opt/pwn
3737
$ ./install.sh
3838
$ ./install.sh ruby-gem
3939
$ pwn
40-
pwn[v0.5.30]:001 >>> PWN.help
40+
pwn[v0.5.31]:001 >>> PWN.help
4141
```
4242

4343
[![Installing the pwn Security Automation Framework](https://raw.githubusercontent.com/0dayInc/pwn/master/documentation/pwn_install.png)](https://youtu.be/G7iLUY4FzsI)
@@ -52,7 +52,7 @@ $ rvm use ruby-3.3.0@pwn
5252
$ gem uninstall --all --executables pwn
5353
$ gem install --verbose pwn
5454
$ pwn
55-
pwn[v0.5.30]:001 >>> PWN.help
55+
pwn[v0.5.31]:001 >>> PWN.help
5656
```
5757

5858
If you're using a multi-user install of RVM do:
@@ -62,7 +62,7 @@ $ rvm use ruby-3.3.0@pwn
6262
$ rvmsudo gem uninstall --all --executables pwn
6363
$ rvmsudo gem install --verbose pwn
6464
$ pwn
65-
pwn[v0.5.30]:001 >>> PWN.help
65+
pwn[v0.5.31]:001 >>> PWN.help
6666
```
6767

6868
PWN periodically upgrades to the latest version of Ruby which is reflected in `/opt/pwn/.ruby-version`. The easiest way to upgrade to the latest version of Ruby from a previous PWN installation is to run the following script:

lib/pwn/plugins/assembly.rb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ module Assembly
1919
arch = opts[:arch] ||= PWN::Plugins::DetectOS.arch
2020
endian = opts[:endian] ||= :little
2121

22+
raise "ERROR: opcodes parameter is required." if opcodes.nil?
23+
2224
case arch
23-
when 'i386', 'i686', 'x86'
24-
arch_obj = Metasm::Ia32.new(endian)
25-
when 'amd64', 'x86_64'
26-
arch_obj = Metasm::X86_64.new(endian)
25+
when 'amd64', 'i386', 'i686', 'x86', 'x86_64'
26+
arch = 'i386'
2727
when 'armv4l', 'armv4b', 'armv5l', 'armv5b', 'armv6l', 'armv6b', 'armv7b', 'armv7l', 'arm', 'armhf'
28-
arch_obj = Metasm::ARM.new(endian)
28+
arch = 'arm'
2929
when 'aarch64', 'arm64'
30-
arch_obj = Metasm::ARM64.new(endian)
30+
arch = 'aarch64'
3131
else
3232
raise "Unsupported architecture: #{arch}"
3333
end
@@ -41,9 +41,14 @@ module Assembly
4141
# If opcodes appear to be '909090' then convert to "\x90\x90\x90"
4242
opcodes = opcodes.chars.each_slice(2).map(&:join).map { |x| format('\x%02x', x.to_i(16)) }.join if opcodes.length.even?
4343

44-
Metasm::Shellcode.disassemble(arch_obj, opcodes).to_s
44+
pwn_asm_tmp = Tempfile.new('pwn_asm')
45+
File.binwrite(pwn_asm_tmp.path, opcodes)
46+
`objdump -D -b binary -m #{arch} -M intel --endian #{endian} #{pwn_asm_tmp.path}`
4547
rescue StandardError => e
4648
raise e
49+
ensure
50+
tmp_file = [pwn_asm_tmp.path]
51+
FileUtils.rm_f(tmp_file) if File.exist?(pwn_asm_tmp.path)
4752
end
4853

4954
# Supported Method Parameters::
@@ -58,6 +63,8 @@ module Assembly
5863
arch = opts[:arch] ||= PWN::Plugins::DetectOS.arch
5964
endian = opts[:endian] ||= :little
6065

66+
raise "ERROR: asm parameter is required." if asm.nil?
67+
6168
case arch
6269
when 'i386', 'i686', 'x86'
6370
arch_obj = Metasm::Ia32.new(endian)
@@ -71,6 +78,8 @@ module Assembly
7178
raise "Unsupported architecture: #{arch}"
7279
end
7380

81+
raise "ERROR: #{as_bin} not found. Choose a different arch parameter." unless File.exist?(as_bin)
82+
7483
Metasm::Shellcode.assemble(arch_obj, asm).encode_string.bytes.map { |b| format('\x%02x', b) }.join
7584
rescue StandardError => e
7685
raise e

lib/pwn/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module PWN
4-
VERSION = '0.5.30'
4+
VERSION = '0.5.31'
55
end

0 commit comments

Comments
 (0)