girl 9.1.1 → 9.1.2

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: 6178ab1062943992b8187decc04a6916c5aaee75aa23e259c3ba5edcdbde7c7d
4
- data.tar.gz: ff195a6fb415da6f045adc4678655acdc367b2f1c8894319f19309085fb3ee9b
3
+ metadata.gz: 673184bfb0785b65e56e4715c2b007481ae91d16620fbc11e3f6e12c50f511b5
4
+ data.tar.gz: 9a37c381bbf266cac12239b479214979202a8b715a1db0c5f443f8ecd3ca046a
5
5
  SHA512:
6
- metadata.gz: 4c102ea1026056ce877c50e895b10e7d054475406e8ee4e62aa4082f07270f6b89fc110cf0762a61e10c0d48d18017674b8c7d23e6e7873b8f0443ded5589a91
7
- data.tar.gz: 7201e5651a8443f7a2c115e9dfbb24d84ae13cd13263f2e754e3db2993e7478f2831d784e3ed098fae0bcb534e1f23e292a5123615aedb9a8a449080fcdf4acf
6
+ metadata.gz: d291af3cfc1ff8813e187062a55b93ad9f0c6a52f7bd14e19c4638becd98c96451da21146a167111c5da01d2f20b6fc31711143e71d82e82bf5cf68d8e420efb
7
+ data.tar.gz: 9a6e13e0f756afd3a024f7c7c386fd18e5978488bd1909fd69dbabffacd25e71d8d0c286920ec86665ed69766cee1464ba1d4a8fcab94055fdf82d405392d96b
data/lib/girl/proxy.rb CHANGED
@@ -23,9 +23,12 @@ module Girl
23
23
 
24
24
  conf = JSON.parse( IO.binread( config_path ), symbolize_names: true )
25
25
  puts "load #{ config_path } #{ conf.inspect }"
26
+ redir_host = conf[ :redir_host ]
26
27
  redir_port = conf[ :redir_port ]
27
28
  memd_port = conf[ :memd_port ]
29
+ relayd_host = conf[ :relayd_host ]
28
30
  relayd_port = conf[ :relayd_port ]
31
+ tspd_host = conf[ :tspd_host ]
29
32
  tspd_port = conf[ :tspd_port ]
30
33
  proxyd_host = conf[ :proxyd_host ]
31
34
  proxyd_port = conf[ :proxyd_port ]
@@ -55,7 +58,6 @@ module Girl
55
58
  h_src_underhalf = conf[ :h_src_underhalf ] # V
56
59
  h_dst_overflow = conf[ :h_dst_overflow ] # W
57
60
  h_dst_underhalf = conf[ :h_dst_underhalf ] # X
58
-
59
61
  expire_connecting = conf[ :expire_connecting ] # 连接多久没有建成关闭(秒)
60
62
  expire_long_after = conf[ :expire_long_after ] # 长连接多久没有新流量关闭(秒)
61
63
  expire_proxy_after = conf[ :expire_proxy_after ] # proxy多久没有收到流量重建(秒)
@@ -63,9 +65,12 @@ module Girl
63
65
  expire_short_after = conf[ :expire_short_after ] # 短连接创建多久后关闭(秒)
64
66
  is_debug = conf[ :is_debug ]
65
67
 
68
+ redir_host = redir_host ? redir_host.to_s : '0.0.0.0'
66
69
  redir_port = redir_port ? redir_port.to_i : 6666
67
70
  memd_port = memd_port ? memd_port.to_i : redir_port + 1
71
+ relayd_host = relayd_host ? relayd_host.to_s : '0.0.0.0'
68
72
  relayd_port = relayd_port ? relayd_port.to_i : redir_port + 2
73
+ tspd_host = tspd_host ? tspd_host.to_s : '0.0.0.0'
69
74
  tspd_port = tspd_port ? tspd_port.to_i : 7777
70
75
  raise "missing proxyd host" unless proxyd_host
71
76
  proxyd_port = proxyd_port ? proxyd_port.to_i : 6060
@@ -141,9 +146,12 @@ module Girl
141
146
  end
142
147
 
143
148
  worker = Girl::ProxyWorker.new(
149
+ redir_host,
144
150
  redir_port,
145
151
  memd_port,
152
+ relayd_host,
146
153
  relayd_port,
154
+ tspd_host,
147
155
  tspd_port,
148
156
  proxyd_host,
149
157
  proxyd_port,
@@ -3,9 +3,12 @@ module Girl
3
3
  include Dns
4
4
 
5
5
  def initialize(
6
+ redir_host,
6
7
  redir_port,
7
8
  memd_port,
9
+ relayd_host,
8
10
  relayd_port,
11
+ tspd_host,
9
12
  tspd_port,
10
13
  proxyd_host,
11
14
  proxyd_port,
@@ -103,12 +106,12 @@ module Girl
103
106
  @is_client_fastopen = is_client_fastopen
104
107
  @is_server_fastopen = is_server_fastopen
105
108
 
106
- new_a_redir( redir_port )
109
+ new_a_redir( redir_host, redir_port )
107
110
  new_a_infod( redir_port )
108
111
  new_a_memd( memd_port )
109
- new_a_relayd( relayd_port )
110
- new_a_rsvd( tspd_port )
111
- new_a_tspd( tspd_port )
112
+ new_a_relayd( relayd_host, relayd_port )
113
+ new_a_rsvd( tspd_host, tspd_port )
114
+ new_a_tspd( tspd_host, tspd_port )
112
115
  new_a_proxy
113
116
  end
114
117
 
@@ -710,14 +713,14 @@ module Girl
710
713
  domain = src_info[ :destination_domain ]
711
714
  port = src_info[ :destination_port ]
712
715
 
713
- if @local_ips.include?( ip ) && [ @redir_port, @tspd_port ].include?( port ) then
716
+ if @local_ips.include?( ip ) && [ @redir_port, @relayd_port, @tspd_port ].include?( port ) then
714
717
  puts "ignore #{ ip }:#{ port }"
715
718
  close_src( src )
716
719
  return
717
720
  end
718
721
 
719
- if [ domain, ip ].include?( @proxyd_host ) then
720
- # 访问远端,直连
722
+ if [ domain, ip ].include?( @proxyd_host ) && ![ 80, 443 ].include?( port ) then
723
+ # 访问远端非http端口,直连
721
724
  puts "direct #{ ip } #{ port }"
722
725
  new_a_dst( ip, src )
723
726
  return
@@ -847,12 +850,12 @@ module Girl
847
850
  end
848
851
 
849
852
  def new_a_infod( infod_port )
850
- infod_ip = '127.0.0.1'
851
- infod_addr = Socket.sockaddr_in( infod_port, infod_ip )
853
+ infod_host = '127.0.0.1'
854
+ infod_addr = Socket.sockaddr_in( infod_port, infod_host )
852
855
  infod = Socket.new( Socket::AF_INET, Socket::SOCK_DGRAM, 0 )
853
856
  infod.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1 ) if RUBY_PLATFORM.include?( 'linux' )
854
857
  infod.bind( infod_addr )
855
- puts "infod bind on #{ infod_ip } #{ infod_port }"
858
+ puts "infod bind on #{ infod_host } #{ infod_port }"
856
859
  add_read( infod, :infod )
857
860
  info = Socket.new( Socket::AF_INET, Socket::SOCK_DGRAM, 0 )
858
861
  @infod_addr = infod_addr
@@ -861,14 +864,14 @@ module Girl
861
864
  end
862
865
 
863
866
  def new_a_memd( memd_port )
864
- memd_ip = '127.0.0.1'
867
+ memd_host = '127.0.0.1'
865
868
  memd = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
866
869
  memd.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
867
870
  memd.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1 ) if RUBY_PLATFORM.include?( 'linux' )
868
871
  memd.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_FASTOPEN, 5 ) if @is_server_fastopen
869
- memd.bind( Socket.sockaddr_in( memd_port, memd_ip ) )
872
+ memd.bind( Socket.sockaddr_in( memd_port, memd_host ) )
870
873
  memd.listen( 5 )
871
- puts "memd listen on #{ memd_ip } #{ memd_port }"
874
+ puts "memd listen on #{ memd_host } #{ memd_port }"
872
875
  add_read( memd, :memd )
873
876
  end
874
877
 
@@ -944,32 +947,31 @@ module Girl
944
947
  proxy_info
945
948
  end
946
949
 
947
- def new_a_redir( redir_port )
948
- redir_ip = '0.0.0.0'
950
+ def new_a_redir( redir_host, redir_port )
949
951
  redir = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
950
952
  redir.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
951
953
  redir.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1 )
952
954
  redir.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1 ) if RUBY_PLATFORM.include?( 'linux' )
953
955
  redir.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_FASTOPEN, BACKLOG ) if @is_server_fastopen
954
- redir.bind( Socket.sockaddr_in( redir_port, redir_ip ) )
956
+ redir.bind( Socket.sockaddr_in( redir_port, redir_host ) )
955
957
  redir.listen( BACKLOG )
956
- puts "redir listen on #{ redir_ip } #{ redir_port }"
958
+ puts "redir listen on #{ redir_host } #{ redir_port }"
957
959
  add_read( redir, :redir )
958
960
  @redir_port = redir_port
959
961
  @redir_local_address = redir.local_address
960
962
  end
961
963
 
962
- def new_a_relayd( relayd_port )
963
- relayd_ip = '0.0.0.0'
964
+ def new_a_relayd( relayd_host, relayd_port )
964
965
  relayd = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
965
966
  relayd.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
966
967
  relayd.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1 )
967
968
  relayd.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1 ) if RUBY_PLATFORM.include?( 'linux' )
968
969
  relayd.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_FASTOPEN, BACKLOG ) if @is_server_fastopen
969
- relayd.bind( Socket.sockaddr_in( relayd_port, relayd_ip ) )
970
+ relayd.bind( Socket.sockaddr_in( relayd_port, relayd_host ) )
970
971
  relayd.listen( BACKLOG )
971
- puts "relayd listen on #{ relayd_ip } #{ relayd_port }"
972
+ puts "relayd listen on #{ relayd_host } #{ relayd_port }"
972
973
  add_read( relayd, :relayd )
974
+ @relayd_port = relayd_port
973
975
  end
974
976
 
975
977
  def new_a_rsv( data, addrinfo, domain, type )
@@ -994,27 +996,25 @@ module Girl
994
996
  add_read( rsv, :rsv )
995
997
  end
996
998
 
997
- def new_a_rsvd( rsvd_port )
998
- rsvd_ip = '0.0.0.0'
999
- rsvd_addr = Socket.sockaddr_in( rsvd_port, rsvd_ip )
999
+ def new_a_rsvd( rsvd_host, rsvd_port )
1000
+ rsvd_addr = Socket.sockaddr_in( rsvd_port, rsvd_host )
1000
1001
  rsvd = Socket.new( Socket::AF_INET, Socket::SOCK_DGRAM, 0 )
1001
1002
  rsvd.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1 ) if RUBY_PLATFORM.include?( 'linux' )
1002
1003
  rsvd.bind( rsvd_addr )
1003
- puts "rsvd bind on #{ rsvd_ip } #{ rsvd_port }"
1004
+ puts "rsvd bind on #{ rsvd_host } #{ rsvd_port }"
1004
1005
  add_read( rsvd, :rsvd )
1005
1006
  @rsvd = rsvd
1006
1007
  end
1007
1008
 
1008
- def new_a_tspd( tspd_port )
1009
- tspd_ip = '0.0.0.0'
1009
+ def new_a_tspd( tspd_host, tspd_port )
1010
1010
  tspd = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
1011
1011
  tspd.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
1012
1012
  tspd.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1 )
1013
1013
  tspd.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1 ) if RUBY_PLATFORM.include?( 'linux' )
1014
1014
  tspd.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_FASTOPEN, BACKLOG ) if @is_server_fastopen
1015
- tspd.bind( Socket.sockaddr_in( tspd_port, tspd_ip ) )
1015
+ tspd.bind( Socket.sockaddr_in( tspd_port, tspd_host ) )
1016
1016
  tspd.listen( BACKLOG )
1017
- puts "tspd listen on #{ tspd_ip } #{ tspd_port }"
1017
+ puts "tspd listen on #{ tspd_host } #{ tspd_port }"
1018
1018
  add_read( tspd, :tspd )
1019
1019
  @tspd_port = tspd_port
1020
1020
  end
@@ -1686,7 +1686,7 @@ module Girl
1686
1686
  def resolve_domain( domain, src )
1687
1687
  return if src.nil? || src.closed?
1688
1688
 
1689
- unless domain =~ /^[0-9a-zA-Z\-\.]{1,63}$/ then
1689
+ unless domain =~ /^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/ then
1690
1690
  # 忽略非法域名
1691
1691
  puts "ignore #{ domain }"
1692
1692
  close_src( src )
@@ -170,7 +170,7 @@ module Girl
170
170
  close_dst( dst )
171
171
  return
172
172
  end
173
-
173
+
174
174
  if !dst_info[ :overflowing ] && ( bytesize >= WBUFF_LIMIT ) then
175
175
  proxy = dst_info[ :proxy ]
176
176
  puts "add h_dst_overflow #{ im } #{ src_id } #{ domain }"
@@ -209,7 +209,7 @@ module Girl
209
209
  close_p2( p2 )
210
210
  return
211
211
  end
212
-
212
+
213
213
  if !p2_info[ :overflowing ] && ( bytesize >= WBUFF_LIMIT ) then
214
214
  proxy = im_info[ :proxy ]
215
215
  puts "add h_p2_overflow #{ im } #{ p2_id }"
@@ -641,12 +641,12 @@ module Girl
641
641
  end
642
642
 
643
643
  def new_a_infod( infod_port )
644
- infod_ip = '127.0.0.1'
645
- infod_addr = Socket.sockaddr_in( infod_port, infod_ip )
644
+ infod_host = '127.0.0.1'
645
+ infod_addr = Socket.sockaddr_in( infod_port, infod_host )
646
646
  infod = Socket.new( Socket::AF_INET, Socket::SOCK_DGRAM, 0 )
647
647
  infod.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1 ) if RUBY_PLATFORM.include?( 'linux' )
648
648
  infod.bind( infod_addr )
649
- puts "infod bind on #{ infod_ip } #{ infod_port }"
649
+ puts "infod bind on #{ infod_host } #{ infod_port }"
650
650
  add_read( infod, :infod )
651
651
  info = Socket.new( Socket::AF_INET, Socket::SOCK_DGRAM, 0 )
652
652
  @infod_addr = infod_addr
@@ -655,14 +655,14 @@ module Girl
655
655
  end
656
656
 
657
657
  def new_a_memd( memd_port )
658
- memd_ip = '127.0.0.1'
658
+ memd_host = '127.0.0.1'
659
659
  memd = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
660
660
  memd.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
661
661
  memd.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1 ) if RUBY_PLATFORM.include?( 'linux' )
662
662
  memd.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_FASTOPEN, 5 ) if @is_server_fastopen
663
- memd.bind( Socket.sockaddr_in( memd_port, memd_ip ) )
663
+ memd.bind( Socket.sockaddr_in( memd_port, memd_host ) )
664
664
  memd.listen( 5 )
665
- puts "memd listen on #{ memd_ip } #{ memd_port }"
665
+ puts "memd listen on #{ memd_host } #{ memd_port }"
666
666
  add_read( memd, :memd )
667
667
  end
668
668
 
@@ -715,14 +715,14 @@ module Girl
715
715
  end
716
716
 
717
717
  def new_a_proxyd( proxyd_port )
718
- proxyd_ip = '0.0.0.0'
718
+ proxyd_host = '0.0.0.0'
719
719
  proxyd = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
720
720
  proxyd.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
721
721
  proxyd.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, 1 ) if RUBY_PLATFORM.include?( 'linux' )
722
722
  proxyd.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_FASTOPEN, BACKLOG ) if @is_server_fastopen
723
- proxyd.bind( Socket.sockaddr_in( proxyd_port, proxyd_ip ) )
723
+ proxyd.bind( Socket.sockaddr_in( proxyd_port, proxyd_host ) )
724
724
  proxyd.listen( BACKLOG )
725
- puts "proxyd listen on #{ proxyd_ip } #{ proxyd_port }"
725
+ puts "proxyd listen on #{ proxyd_host } #{ proxyd_port }"
726
726
  add_read( proxyd, :proxyd )
727
727
  end
728
728
 
@@ -1120,7 +1120,7 @@ module Girl
1120
1120
  domain = domain_port[ 0...colon_idx ]
1121
1121
  port = domain_port[ ( colon_idx + 1 )..-1 ].to_i
1122
1122
 
1123
- if ( domain !~ /^[0-9a-zA-Z\-\.]{1,63}$/ ) || ( domain =~ /^((0\.\d{1,3}\.\d{1,3}\.\d{1,3})|(10\.\d{1,3}\.\d{1,3}\.\d{1,3})|(127\.\d{1,3}\.\d{1,3}\.\d{1,3})|(169\.254\.\d{1,3}\.\d{1,3})|(172\.((1[6-9])|(2\d)|(3[01]))\.\d{1,3}\.\d{1,3})|(192\.168\.\d{1,3}\.\d{1,3})|(255\.255\.255\.255)|(localhost))$/ ) then
1123
+ if ( domain !~ /^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/ ) || ( domain =~ /^((0\.\d{1,3}\.\d{1,3}\.\d{1,3})|(10\.\d{1,3}\.\d{1,3}\.\d{1,3})|(127\.\d{1,3}\.\d{1,3}\.\d{1,3})|(169\.254\.\d{1,3}\.\d{1,3})|(172\.((1[6-9])|(2\d)|(3[01]))\.\d{1,3}\.\d{1,3})|(192\.168\.\d{1,3}\.\d{1,3})|(255\.255\.255\.255)|(localhost))$/ ) then
1124
1124
  # 忽略非法域名,内网地址
1125
1125
  puts "ignore #{ domain }"
1126
1126
  return
@@ -1348,7 +1348,7 @@ module Girl
1348
1348
  data = data[ written..-1 ]
1349
1349
  p2_info[ :wbuff ] = data
1350
1350
  bytesize = p2_info[ :wbuff ].bytesize
1351
-
1351
+
1352
1352
  if p2_info[ :overflowing ] && ( bytesize < RESUME_BELOW ) then
1353
1353
  proxy = im_info[ :proxy ]
1354
1354
  p2_id = p2_info[ :p2_id ]
@@ -1396,7 +1396,7 @@ module Girl
1396
1396
  proxy_info[ :paused_dsts ].each{ | dst | add_read( dst ) }
1397
1397
  proxy_info[ :paused_dsts ].clear
1398
1398
  end
1399
-
1399
+
1400
1400
  if proxy_info[ :paused_p2s ].any? then
1401
1401
  puts "proxy underhalf resume p2s #{ im } #{ proxy_info[ :paused_p2s ].size }"
1402
1402
  proxy_info[ :paused_p2s ].each{ | p2 | add_read( p2 ) }
data/lib/girl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Girl
2
- VERSION = '9.1.1'.freeze
2
+ VERSION = '9.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: girl
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.1.1
4
+ version: 9.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - takafan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-07 00:00:00.000000000 Z
11
+ date: 2024-03-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: escape evil.
14
14
  email: