netrat 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/netrat.rb +68 -0
  3. metadata +63 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 262e021e41fad2031842d697e6692a6111999fa948cc9c9a46e371fc76c7f3a4
4
+ data.tar.gz: 2048613b43498f19f21049a1d6ed6529772566a14c9bea9fef1769f565bbdb7a
5
+ SHA512:
6
+ metadata.gz: c0e5e84616cf5b88c36655476a344d166109164263244d5b8f4ad2b6a73342c6f567855ccb09ba354795723dfa43e446acef9b59fee4e9ea996921516d89473c
7
+ data.tar.gz: b1e565a4ffecea35b22e420c56de270e4bb01034a7c28b5cf6ae58ee7d6a784436eba39c39012934cbbfa231a67b4d3d3cb589f0015884207a7afb537e661517
@@ -0,0 +1,68 @@
1
+ require "socket"
2
+
3
+ class NetRat
4
+ attr_reader :ip
5
+ attr_reader :port
6
+ attr_reader :socket
7
+
8
+ def initialize(port, ip = nil)
9
+ @ip = ip
10
+ @port = port
11
+ @socket = nil
12
+ end
13
+
14
+ def listen(options = {})
15
+ options[:keepalive] ||= false
16
+
17
+ trap("SIGINT") do
18
+ puts
19
+ return
20
+ end
21
+
22
+ if (@ip.nil?)
23
+ server = TCPServer.new(@port)
24
+ server.listen(1)
25
+ @socket = server.accept
26
+ else
27
+ @socket = TCPSocket.open(@ip, @port)
28
+ end
29
+
30
+ loop do
31
+ if (IO.select([], [], [@socket, STDIN], 0))
32
+ server.close if (server)
33
+ @socket.close if (@socket)
34
+ return
35
+ end
36
+
37
+ begin
38
+ while(!(data = @socket.recv_nonblock(100)).empty?)
39
+ STDOUT.write(data);
40
+ end
41
+ break if (!options[:keepalive])
42
+ rescue Errno::ECONNRESET
43
+ break if (!options[:keepalive])
44
+ rescue Errno::EAGAIN
45
+ end
46
+
47
+ begin
48
+ while (!(data = STDIN.read_nonblock(100)).empty?)
49
+ @socket.write(data);
50
+ end
51
+ break if (!options[:keepalive])
52
+ rescue Errno::EAGAIN
53
+ rescue EOFError
54
+ break if (!options[:keepalive])
55
+ end
56
+
57
+ IO.select(
58
+ [@socket, STDIN],
59
+ [@socket, STDIN],
60
+ [@socket, STDIN]
61
+ )
62
+ end
63
+ ensure
64
+ server.close if (server)
65
+ @socket.close if (@socket)
66
+ end
67
+ alias :connect :listen
68
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: netrat
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Miles Whittaker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12.3'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 12.3.2
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '12.3'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 12.3.2
33
+ description: Very simple Ruby implementation of netcat.
34
+ email: mj@whitta.dev
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - lib/netrat.rb
40
+ homepage: https://gitlab.com/mjwhitta/netrat
41
+ licenses:
42
+ - GPL-3.0
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.0.4
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Very simple Ruby implementation of netcat
63
+ test_files: []