yptools 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/yptools/portscan/yp_portscan.rb +30 -45
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c49bfe04d254b19d13b80a1e9f5db8ffe4b5d44ec6008d304b6f867bee00e66b
|
4
|
+
data.tar.gz: 036e0974cc6ebe80b186c43f5ede5f39088d17847563391e7084f81c4d94a487
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a22f3e20325311844302d284987884261b4fc61e1de3cde94d5feb969a0653b843a09c270a6bedce162ecdf13d9f30d649723dbbec4da6a936c1c577bb398a32
|
7
|
+
data.tar.gz: 20daa32b7722a94e5e25c7b883e0ab6546698463a74256f73b6a4a770233295f24b2f7d504563db71c94d2738b0e045c76726db2352607ab68a3331fa8c60b41
|
@@ -1,50 +1,35 @@
|
|
1
|
+
require 'colored'
|
2
|
+
|
1
3
|
class YPPortScan
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
COMMON_PORTS = [21, 22, 23, 25, 53, 80, 81, 88, 110, 111, 135, 139, 143, 161, 389, 443, 445, 465, 514, 587, 631, 993, 995, 1080, 1194, 1433, 1521, 2049, 2082, 2083, 2181, 2222, 2375, 2376, 3389, 3690, 4443, 5432, 5900, 5984, 6379, 7001, 7002, 8080, 8081, 8086, 8443, 8888, 9090, 9200, 9300, 10000, 11211, 15672, 27017, 28017, 50000, 50070, 50075, 50090]
|
5
|
+
|
6
|
+
def self.portscan(address, range)
|
7
|
+
ip_address = address
|
8
|
+
if range.nil? || range.empty? || range == "-d" || range == "-default"
|
9
|
+
port_range = COMMON_PORTS
|
10
|
+
yp_log_doing "正在扫描 #{ip_address} 常用的端口"
|
11
|
+
else
|
12
|
+
temp_port_range = range.split("-").map(&:to_i)
|
13
|
+
yp_log_doing "正在扫描 #{ip_address} 的端口 #{temp_port_range.min} 到 #{temp_port_range.max}..."
|
14
|
+
port_range = temp_port_range.size == 1 ? [temp_port_range[0]] : (temp_port_range[0]..temp_port_range[1]).to_a
|
15
|
+
end
|
11
16
|
|
12
|
-
|
13
|
-
|
14
|
-
ip_address=#{port}
|
17
|
+
open_ports = []
|
18
|
+
closed_ports = []
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
(echo >/dev/tcp/${ip_address}/${port}) >/dev/null 2>&1 &
|
26
|
-
pid=$!
|
27
|
-
(
|
28
|
-
sleep ${timeout}
|
29
|
-
kill ${pid} >/dev/null 2>&1
|
30
|
-
) &
|
31
|
-
timer=$!
|
32
|
-
if wait ${pid} 2>/dev/null; then
|
33
|
-
echo "\\033[32m${port} 是开放的\\033[0m"
|
34
|
-
open_ports+=($port)
|
35
|
-
else
|
36
|
-
echo "\\033[31m${port} 是关闭的\\033[0m"
|
37
|
-
closed_ports+=($port)
|
38
|
-
fi
|
39
|
-
kill ${timer} >/dev/null 2>&1
|
40
|
-
done
|
41
|
-
|
42
|
-
allCount=$((${#open_ports[@]} + ${#closed_ports[@]}))
|
43
|
-
|
44
|
-
echo ${allCount} "个端口扫描完成。"
|
45
|
-
echo "共有 ${#open_ports[@]} 个端口是开放的,${#closed_ports[@]} 个端口是关闭的。"
|
46
|
-
echo "开放的端口: " "\\033[32m${open_ports[@]}\\033[0m"
|
47
|
-
)
|
48
|
-
system(script)
|
20
|
+
port_range.each do |port|
|
21
|
+
`nc -w 1 -z #{ip_address} #{port} 2>&1 | grep succeeded`
|
22
|
+
if $?.success?
|
23
|
+
yp_log_success "#{port} 是开放的"
|
24
|
+
open_ports << port
|
25
|
+
else
|
26
|
+
yp_log_fail "#{port} 是关闭的"
|
27
|
+
closed_ports << port
|
28
|
+
end
|
49
29
|
end
|
30
|
+
|
31
|
+
all_count = open_ports.size + closed_ports.size
|
32
|
+
yp_log_doing "共有 #{open_ports.size} 个端口是开放的,#{closed_ports.size} 个端口是关闭的。"
|
33
|
+
yp_log_success "#{all_count} 个端口扫描完成," + "开放的端口: #{open_ports}"
|
34
|
+
end
|
50
35
|
end
|