Module: Ronin::Payloads::Mixins::Network

Included in:
Shellcode::BindShellPayload, Shellcode::ReverseShellPayload
Defined in:
lib/ronin/payloads/mixins/network.rb

Overview

Base class for all reverse shell shellcode payloads.

Instance Method Summary collapse

Instance Method Details

#pack_ipv4(ip, negate: false) ⇒ String

Packs the IPv4 address in network byte-order.

Parameters:

  • ip (String)

    The IPv4 address to pack.

  • negate (Boolean) (defaults to: false)

    Inverts the bits of the IP address.

Returns:

  • (String)

    The packed IP address in network byte-order.

Raises:

  • (ArgumentError)

    The given IP address was not an IPv4 address.



48
49
50
51
52
53
54
55
56
57
# File 'lib/ronin/payloads/mixins/network.rb', line 48

def pack_ipv4(ip, negate: false)
  ipaddr = IPAddr.new(ip)

  unless ipaddr.ipv4?
    raise(ArgumentError,"IP must be an IPv4 address: #{ip.inspect}")
  end

  ipaddr = ~ipaddr if negate
  ipaddr.hton
end

#pack_ipv6(ip, negate: false) ⇒ String

Packs the IPv6 address in network byte-order.

Parameters:

  • ip (String)

    The IPv6 address to pack.

  • negate (Boolean) (defaults to: false)

    Inverts the bits of the IP address.

Returns:

  • (String)

    The packed IPv6 address in network byte-order.



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

def pack_ipv6(ip, negate: false)
  ipaddr = IPAddr.new(ip)

  unless ipaddr.ipv6?
    raise(ArgumentError,"IP must be an IPv6 address: #{ip.inspect}")
  end

  ipaddr = ~ipaddr if negate
  ipaddr.hton
end

#pack_port(port, negate: false) ⇒ String

Packs the port number in network byte-order.

Parameters:

  • port (Integer)

    The port number to pack.

  • negate (Boolean) (defaults to: false)

    Inverts the bits of the port number.

Returns:

  • (String)

    The packed port number in network byte-order.



94
95
96
97
# File 'lib/ronin/payloads/mixins/network.rb', line 94

def pack_port(port, negate: false)
  port = ~port if negate
  [port].pack('n')
end