Module: Ronin::Exploits::Mixins::NOPS

Included in:
SEH, StackOverflow
Defined in:
lib/ronin/exploits/mixins/nops.rb

Overview

Generates NOP buffers.

Examples

include Mixins::NOPS

arch :x86_64

def build
  buffer = ('A' * 1024) + nops(100) + payload
  # ...
end

Since:

  • 1.0.0

Constant Summary collapse

NOPS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Nop instructions for various architectures.

Since:

  • 1.0.0

{
  x86:    "\x90".b,            # nop
  x86_64: "\x90".b,            # nop
  arm:    "\x05P\xa0\xe1".b,   # mov r5, r5
  arm64:  "\xe5\x03\x05\xaa".b # mov x5, x5
  # TODO: mips
  # TODO: mips64
  # TODO: ppc
  # TODO: ppc64
}

Instance Method Summary collapse

Instance Method Details

#nopString

An individual NOP instruction for the target architecture of the exploit.

Returns:

  • (String)

    The NOP instruction String.

Raises:

  • (NotImplementedError)

    No NOP string was defined for the exploit's targeted architecture.

Since:

  • 1.0.0



93
94
95
96
97
# File 'lib/ronin/exploits/mixins/nops.rb', line 93

def nop
  NOPS.fetch(arch) do
    raise(NotImplementedError,"no NOP string is currently defined for the architecture: #{arch.inspect}")
  end
end

#nops(size) ⇒ String

Creates a buffer of NOPs.

Parameters:

  • size (Integer)

    The desired size of the nop buffer.

Returns:

  • (String)

    The NOPs buffer.

Raises:

  • (NotImplementedError)

    No NOP string was defined for the exploit's targeted architecture.

Since:

  • 1.0.0



113
114
115
116
117
# File 'lib/ronin/exploits/mixins/nops.rb', line 113

def nops(size)
  nop = self.nop

  return nop * (size / nop.bytesize)
end

#perform_validateObject

Validates that the exploit defined an arch method and that all required params are set.

Raises:

Since:

  • 1.0.0



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ronin/exploits/mixins/nops.rb', line 71

def perform_validate
  unless respond_to?(:arch)
    raise(ValidationError,"exploit #{self.class} did not include Ronin::Exploits::Metadata::Arch or Ronin::Exploits::Mixins::HasTargets")
  end

  unless arch
    raise(ValidationError,"exploit #{self.class} did not include define an architecture")
  end

  super()
end