Skip to content

Commit 0d6acad

Browse files
author
HD Moore
committed
Updates for PR rapid7#981 (cleanup)
1 parent 0bf5f63 commit 0d6acad

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

lib/rex/proto/addp.rb

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,25 @@ class ADDP
4242
CMD_CNT = 14
4343

4444

45-
46-
def self.mac2bin(mac)
47-
mac.split(":").map{|c| c.to_i(16) }.pack("C*")
48-
end
49-
50-
def self.bin2mac(bin)
51-
bin.unpack("C6").map{|x| "%.2x" % x }.join(":").upcase
52-
end
53-
5445
def self.encode_password(pwd="dbps")
5546
[pwd.length].pack("C") + pwd
5647
end
5748

5849
def self.request_config(magic, dmac="\xff\xff\xff\xff\xff\xff")
59-
mac = (dmac.length == 6) ? dmac : self.mac2bin(dmac)
50+
mac = (dmac.length == 6) ? dmac : Rex::Socket.eth_aton(dmac)
6051
req = magic + [ CMD_CONF_REQ, 6].pack("nn") + mac
6152
return req
6253
end
6354

6455
def self.request_config_all(dmac="\xff\xff\xff\xff\xff\xff")
65-
mac = (dmac.length == 6) ? dmac : self.mac2bin(dmac)
56+
mac = (dmac.length == 6) ? dmac : Rex::Socket.eth_aton(dmac)
6657
res = []
6758
MAGICS.each { |m| res << self.request_config(m, dmac) }
6859
return res
6960
end
7061

7162
def self.request_static_ip(magic, dmac, ip, mask, gw, pwd="dbps")
72-
mac = (dmac.length == 6) ? dmac : self.mac2bin(dmac)
63+
mac = (dmac.length == 6) ? dmac : Rex::Socket.eth_aton(dmac)
7364
buf =
7465
Rex::Socket.addr_aton(ip) +
7566
Rex::Socket.addr_aton(mask) +
@@ -82,7 +73,7 @@ def self.request_static_ip(magic, dmac, ip, mask, gw, pwd="dbps")
8273
end
8374

8475
def self.request_dhcp(magic, dmac, enabled, pwd="dbps")
85-
mac = (dmac.length == 6) ? dmac : self.mac2bin(dmac)
76+
mac = (dmac.length == 6) ? dmac : Rex::Socket.eth_aton(dmac)
8677
buf =
8778
[ enabled ? 1 : 0 ].pack("C") +
8879
mac +
@@ -93,7 +84,7 @@ def self.request_dhcp(magic, dmac, enabled, pwd="dbps")
9384
end
9485

9586
def self.request_reboot(magic, dmac, pwd="dbps")
96-
mac = (dmac.length == 6) ? dmac : self.mac2bin(dmac)
87+
mac = (dmac.length == 6) ? dmac : Rex::Socket.eth_aton(dmac)
9788
buf =
9889
mac +
9990
self.encode_password(pwd)
@@ -121,7 +112,7 @@ def self.decode_reply(data)
121112

122113
case i_type
123114
when 0x01
124-
res[:mac] = self.bin2mac(i_data)
115+
res[:mac] = Rex::Socket.eth_ntoa(i_data)
125116
when 0x02
126117
res[:ip] = Rex::Socket.addr_ntoa(i_data)
127118
when 0x03

lib/rex/socket.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,20 @@ def self.addr_iton(addr, v6=false)
455455
end
456456
end
457457

458+
#
459+
# Converts a colon-delimited MAC address into a 6-byte binary string
460+
#
461+
def self.eth_aton(mac)
462+
mac.split(":").map{|c| c.to_i(16) }.pack("C*")
463+
end
464+
465+
#
466+
# Converts a 6-byte binary string into a colon-delimited MAC address
467+
#
468+
def self.eth_ntoa(bin)
469+
bin.unpack("C6").map{|x| "%.2x" % x }.join(":").upcase
470+
end
471+
458472
#
459473
# Converts a CIDR subnet into an array (base, bcast)
460474
#

modules/auxiliary/scanner/scada/digi_addp_reboot.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def initialize
2424
'Version' => '$Revision$',
2525
'Description' => 'Reboot Digi International based equipment through the ADDP service',
2626
'Author' => 'hdm',
27-
'References' =>
27+
'References' =>
2828
[
2929
['URL', 'http://qbeukes.blogspot.com/2009/11/advanced-digi-discovery-protocol_21.html'],
3030
['URL', 'http://www.digi.com/wiki/developer/index.php/Advanced_Device_Discovery_Protocol_%28ADDP%29'],
@@ -144,7 +144,7 @@ def parse_reply(pkt)
144144
if @results[addr][:cmd] == Rex::Proto::ADDP::CMD_REBOOT_REP
145145
print_status("#{addr}:#{rport} Reboot Status: " + Rex::Proto::ADDP.reply_to_string(@results[addr]))
146146
end
147-
147+
148148
return unless @results[addr][:magic] and @results[addr][:mac]
149149
end
150150

modules/auxiliary/scanner/scada/digi_addp_version.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def initialize
2424
'Version' => '$Revision$',
2525
'Description' => 'Discover host information through the Digi International ADDP service',
2626
'Author' => 'hdm',
27-
'References' =>
27+
'References' =>
2828
[
2929
['URL', 'http://qbeukes.blogspot.com/2009/11/advanced-digi-discovery-protocol_21.html'],
3030
['URL', 'http://www.digi.com/wiki/developer/index.php/Advanced_Device_Discovery_Protocol_%28ADDP%29'],
@@ -119,7 +119,7 @@ def parse_reply(pkt)
119119

120120
@results[addr] ||= {}
121121
@results[addr] = Rex::Proto::ADDP.decode_reply(data)
122-
122+
123123
return unless @results[addr][:magic] and @results[addr][:mac]
124124

125125
inf = Rex::Proto::ADDP.reply_to_string(@results[addr])

0 commit comments

Comments
 (0)