Example #1
0
    def test_uri_expansion(self):
        """
        The target specification should match Nmap's capabilities.

        Example:
            10.1.2.3,[email protected],10.0.2-4,0-255,mail[01-5].example.com:1234
            [
               '10.1.2.3',
               '[email protected]', ...  '[email protected]',
               '10.0.2.0', ...  '10.0.2.255',
               '10.0.3.0', ...  '10.0.3.255',
               '10.0.4.0', ...  '10.0.4.255',
               'mail01.example.com:1234',
               'mail02.example.com:1234',
               'mail03.example.com:1234',
               'mail04.example.com:1234',
               'mail05.example.com:1234',
           ]
        """
        prov_exp = [
                # IPs
                ('10.1.2.3', ['10.1.2.3']),
                ('10.1.2.3:123', ['10.1.2.3:123']),
                ('10.2.3.4,example.com', ['10.2.3.4', 'example.com']),
                ('10.4.5.6-8', ['10.4.5.6', '10.4.5.7', '10.4.5.8']),
                ('10-11.1.2.3', ['10.1.2.3', '11.1.2.3']),
                ('10-11.1.2.3-5',['10.1.2.3', '10.1.2.4', '10.1.2.5', '11.1.2.3', '11.1.2.4', '11.1.2.5']),
                ('192.168.3-5,7.1', ['192.168.3.1', '192.168.4.1', '192.168.5.1', '192.168.7.1']),
                ('192.168.3-5,7.1:567', ['192.168.3.1:567', '192.168.4.1:567', '192.168.5.1:567', '192.168.7.1:567']),
                ('192.168.0.-', ['192.168.0.%d' % i for i in range(0,256)]),
                # URLs
                ('example.com', ['example.com']),
                ('example.com:789', ['example.com:789']),
                ('[email protected]', ['[email protected]']),
                ('mail[01-3].example.com', ['mail01.example.com', 'mail02.example.com', 'mail03.example.com']),
                ('mail[01-3].example.com:123', ['mail01.example.com:123', 'mail02.example.com:123', 'mail03.example.com:123']),
                ('ex-ample.com', ['ex-ample.com',]),
                ('[email protected]', ['[email protected]',]),
                # Combinations
                ('example.com,1.2.3.4', ['example.com', '1.2.3.4']),
                ('[email protected]:1234,[email protected]:1234', ['[email protected]:1234', '[email protected]:1234']),
                ('[email protected][11-13,17].com:1234,[email protected],5-7.3.4:1234', ['[email protected]:1234', '[email protected]:1234', '[email protected]:1234', '[email protected]:1234', '[email protected]:1234', '[email protected]:1234', '[email protected]:1234', '[email protected]:1234']),
                ('10.1.1.1,10.1.1.2', ['10.1.1.1', '10.1.1.2']),
                ('10.1.1.1,3,10.1.1.5', ['10.1.1.1', '10.1.1.3', '10.1.1.5']),
                ('10.1.1.1,3,10.1.1.5,[email protected][01-2].com,10-11.1.1.1-5', ['10.1.1.1', '10.1.1.3', '10.1.1.5', '[email protected]', '[email protected]', '10.1.1.1', '10.1.1.2', '10.1.1.3', '10.1.1.4', '10.1.1.5', '11.1.1.1', '11.1.1.2', '11.1.1.3', '11.1.1.4', '11.1.1.5']),
                ]

        for provided, expected in prov_exp:
            self.assertEqual(list(lib.uri_expansion(provided)),
                    expected)
Example #2
0
    def test_invalid_uri_expansion(self):
        """
        Invalid expansions should raise an Exception.
        """
        prov = [
                '10.1.2.3-2',
                '10.2',
                'example[2-1].com',
                '',
                None
                ]

        for provided in prov:
            gen = lib.uri_expansion(provided)
            self.assertRaises(ValueError, list, gen)