· 6 years ago · Mar 04, 2019, 06:52 PM
1'''Ambit, by applefrost <me.applefrost@gmail.com>.
2
3Ambit is a simple tool which exposes open ports on network connected machines.
4
5Usage
6 ambit [hosts:ports]
7
8Format
9 Ambit uses a cool format for specifying targets. Here's some examples.
10
11
12
13 Check one host for one port.
14
15 ambit 192.168.1.1:22
16
17
18
19 Check two host for two ports, using commas.
20
21 ambit 192.168.1.1,192.168.1.2:22,80
22
23
24
25 Check a range of hosts for a range of ports.
26
27 ambit 192.168.1.1-192.168.1.100:100-300
28
29
30
31 You can combine any of these formats.
32
33 ambit 192.168.1.1,192.168.1.5-192.168.1.200:20-23,80,8000,8080,500-1000
34
35
36
37 You can also have multiple groups.
38
39 ambit 192.168.1.1-192.168.1.2:9100,515,80 96.60.22.10:80,443,20-23'''
40
41
42
43from socket import *
44from sys import argv
45
46
47
48def addresses(start, end):
49 addresses = []
50 address = start
51
52 while (address != end):
53 addresses.append(address)
54
55 octets = [int(octet) for octet in address.split('.')]
56 octets[-1] += 1
57
58 for index in range(3, 1, -1):
59 if (octets[index] > 255):
60 octets[index] = 0
61 octets[index - 1] += 1
62
63 octets = [str(octet) for octet in octets]
64 address = '.'.join(octets)
65
66 return addresses
67
68
69
70def hosts(segments):
71 segments = segments.split(',')
72 hosts = []
73
74 for segment in segments:
75 if ('-' in segment):
76 scope = segment.split('-')
77 start = scope[0]
78 end = scope[1]
79 hosts += addresses(start, end)
80
81 else:
82 hosts.append(segment)
83
84 return hosts
85
86
87
88def ports(segments):
89 segments = segments.split(',')
90 ports = []
91
92 for segment in segments:
93 if ('-' in segment):
94 scope = segment.split('-')
95 start = int(scope[0])
96 end = int(scope[1])
97 ports += range(start, end)
98
99 else:
100 ports.append(int(segment))
101
102 return ports
103
104
105
106def check(host, port):
107 _socket = socket()
108 _socket.settimeout(0.1)
109
110 try:
111 _socket.connect((host, port))
112 return True
113
114 except:
115 return False
116
117
118
119def examine(hosts, ports):
120 for host in hosts:
121 print('\n[+] Checking ports on %s' % host)
122
123 for port in ports:
124 open = check(host, port)
125
126 if (open):
127 print('[+] %s, open' % port)
128
129# else:
130# print('[-] %s, closed' % port)
131
132
133
134def main():
135 if (len(argv) == 2):
136 targets = argv[1].split(':')
137
138 _hosts = hosts(targets[0])
139
140 _ports = ports(targets[1])
141
142 print('\n[+] Starting examination')
143
144 examine(_hosts, _ports)
145
146 else:
147 print(__doc__)
148
149
150
151main()