Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/ipaddr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class IPAddr
# 192.168.255.255 = 192.168.65535 = 0xC0.0xA8FFFF = 3232301055
RE_IPV4ADDRLIKE = %r{
\A
(?:((?:0x?)?[\da-f]{1,3})\.)?
(?:((?:0x?)?[\da-f]{1,3})\.)?
(?:((?:0x?)?[\da-f]{1,3})\.)?
(?:((?:0x?)?[\da-f]{1,10}))
(?:((?:0x?)?[\da-f]+)\.)?
(?:((?:0x?)?[\da-f]+)\.)?
(?:((?:0x?)?[\da-f]+)\.)?
(?:((?:0x?)?[\da-f]+))
\z
}xi

Expand Down
36 changes: 36 additions & 0 deletions test/test_ipaddr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,42 @@ def test_s_new_aton_compatible
assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("4294967296") }
end

def test_s_ipfuscator_comatible
# https://vincentyiu.co.uk/red-team/cve-exploitation/ipfuscation
# https://github.com/vysecurity/IPFuscator
# Decimal
assert_equal "127.0.0.1", IPAddr.new("2130706433").to_s
# Hexadecimal
assert_equal "127.0.0.1", IPAddr.new("0x7f000001").to_s
# Octal:
assert_equal "127.0.0.1", IPAddr.new("017700000001").to_s

# Full Hex:
assert_equal "127.0.0.1", IPAddr.new("0x7f.0x0.0x0.0x1").to_s
# Full Oct
assert_equal "127.0.0.1", IPAddr.new("0177.0.0.01").to_s

# Random Padding:
# Hex:
assert_equal "127.0.0.1", IPAddr.new("0x000000000007f.0x000000000000000000000000000000.0x0000.0x0000000000000000000000001").to_s
# Oct:
assert_equal "127.0.0.1", IPAddr.new("00000000000000000000000177.000000000000000000.00000000000000000000000000000.000001").to_s

# Random base:
assert_equal "127.0.0.1", IPAddr.new("0x7f.0x0.0.01").to_s
assert_equal "127.0.0.1", IPAddr.new("0x7f.0x0.0x0.1").to_s
assert_equal "127.0.0.1", IPAddr.new("0177.0x0.0x0.0x1").to_s
assert_equal "127.0.0.1", IPAddr.new("0x7f.0.0.01").to_s
assert_equal "127.0.0.1", IPAddr.new("127.0x0.0.0x1").to_s

#Random base with random padding:
assert_equal "127.0.0.1", IPAddr.new("127.0x00000000.000000.000000000000000001").to_s
assert_equal "127.0.0.1", IPAddr.new("127.0x0000000000000.0x00000000000000000000000000000.0001").to_s
assert_equal "127.0.0.1", IPAddr.new("0000000000000000177.0x0000000000000000000000.0x00000000000000000000000000.1").to_s
assert_equal "127.0.0.1", IPAddr.new("0000000000000000000177.0.000000.1").to_s
assert_equal "127.0.0.1", IPAddr.new("127.0000000000000000000000.0x0000000000000000000.000000000000000000000000000001").to_s
end

def test_s_new_ntoh
addr = ''
IPAddr.new("1234:5678:9abc:def0:1234:5678:9abc:def0").hton.each_byte { |c|
Expand Down