rapid7/metasploit-framework — pull request #3687 by jhart-r7 (2014-08-22 19:50:04+00:00)
Title: Fix a few minor bugs, add unit tests and clean up NAT-PMP modules

I was doing some more NAT-PMP research and discovered several problems with the NAT-PMP code/modules:

* Parsing of result codes and epochs was wrong, resulting in some missed results (corrected, added unit tests)
* Use UDPScanner for natpmp_external_address. It is now much faster with much less code duplication.
* Used more logical option names for the local/remote ports when using natpmp_map to map ports on a NAT-PMP device -- don't overload RPORT/LPORT
* Add a common mixin to further reduce NAT-PMP code duplication

I ran all three of the affected modules against a NAT-PMP device and confirmed that everything still works:

```
msf auxiliary(natpmp_external_address) > run

[+] 10.0.1.1:5351 -- external address 192.168.1.2
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

msf auxiliary(natpmp_portscan) > set PORTS 22-25,53,500,10000
PORTS => 22-25,53,500,10000
msf auxiliary(natpmp_portscan) > set PROTOCOL UDP
PROTOCOL => UDP
msf auxiliary(natpmp_portscan) > run

[+] External address of 10.0.1.1 is 192.168.1.2
[*] 192.168.1.2 - 53/udp open because of successful mapping with unmatched ports
[*] 192.168.1.2 - 500/udp open because of successful mapping with unmatched ports
[*] 192.168.1.2 - 10000/udp open because of successful mapping with unmatched ports
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf auxiliary(natpmp_portscan) > set PROTOCOL TCP
PROTOCOL => TCP
msf auxiliary(natpmp_portscan) > run

[+] External address of 10.0.1.1 is 192.168.1.2
[*] 192.168.1.2 - 53/tcp open because of successful mapping with unmatched ports
[*] 192.168.1.2 - 500/tcp open because of successful mapping with unmatched ports
[*] 192.168.1.2 - 10000/tcp open because of successful mapping with unmatched ports
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

msf auxiliary(natpmp_map) > set INTERNAL_PORT 4444
INTERNAL_PORT => 4444
msf auxiliary(natpmp_map) > set EXTERNAL_PORT 5555
EXTERNAL_PORT => 5555
msf auxiliary(natpmp_map) > run

[*] 192.168.1.2 5555/TCP -> 10.0.1.10 4444/TCP forwarded
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

```