tarbit 1.0.0
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 +7 -0
- data/.gitignore +3 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +38 -0
- data/bin/tarbit +28 -0
- data/lib/tarbit/server.rb +51 -0
- data/lib/tarbit/statistic.rb +45 -0
- data/lib/tarbit/version.rb +5 -0
- data/lib/tarbit.rb +12 -0
- data/tarbit.gemspec +30 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5fdb81b5d9d98958d081c9fb3fdc25ec216bd0b9b8d1ceb1284eb3e898482d9a
|
4
|
+
data.tar.gz: 5ca27088bb0c658716d09edb4236227f2ef298654eb9c166b86ec4261ffb8462
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b47d842599e19cedeb839f73ae732d85bd9059cba24dae157651ca8dd4ca802154849086b2d62b37c8a726091b95481fca1828d71fd825dc0df021a753ae2509
|
7
|
+
data.tar.gz: 02632a2259b571ced4bccf13c6d051ea83e3e9381252a1d2025ccfc1301e818bf92ec3f7a7b1693737bcb14147e6f11381a3bf092678be13a4cfe3907ea27a0a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tarbit (1.0.0)
|
5
|
+
async-io
|
6
|
+
commander
|
7
|
+
gruff
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
async (1.24.2)
|
13
|
+
console (~> 1.0)
|
14
|
+
nio4r (~> 2.3)
|
15
|
+
timers (~> 4.1)
|
16
|
+
async-io (1.27.3)
|
17
|
+
async (~> 1.14)
|
18
|
+
commander (4.5.0)
|
19
|
+
highline (~> 2.0.0)
|
20
|
+
console (1.8.1)
|
21
|
+
gruff (0.7.0)
|
22
|
+
rmagick (~> 2.13, >= 2.13.4)
|
23
|
+
highline (2.0.3)
|
24
|
+
nio4r (2.5.2)
|
25
|
+
rmagick (2.16.0)
|
26
|
+
timers (4.3.0)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
tarbit!
|
33
|
+
|
34
|
+
RUBY VERSION
|
35
|
+
ruby 2.6.5p114
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
1.17.3
|
data/bin/tarbit
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'commander/import'
|
4
|
+
require 'tarbit'
|
5
|
+
|
6
|
+
# :name is optional, otherwise uses the basename of this executable
|
7
|
+
program :name, 'Tarbit - SSH Tarpit using Ruby'
|
8
|
+
program :version, Tarbit::VERSION
|
9
|
+
program :description, 'Stupid command that prints foo or bar.'
|
10
|
+
|
11
|
+
command :serve do |c|
|
12
|
+
c.syntax = 'apollo serve [options]'
|
13
|
+
c.description = 'Runs the apollo server'
|
14
|
+
c.option '--debug', nil, 'Runs the apollo server in debug mode'
|
15
|
+
c.option '--suffix STRING', String, 'Adds a suffix to bar'
|
16
|
+
c.action do |args, options|
|
17
|
+
puts "Starting tarbit ssh tarpit"
|
18
|
+
|
19
|
+
server = Tarbit::Server.new
|
20
|
+
statistic = Tarbit::Statistic.new(server, 10)
|
21
|
+
|
22
|
+
Async do |task|
|
23
|
+
statistic.watch
|
24
|
+
server.run
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'async/io'
|
4
|
+
require 'async/io/stream'
|
5
|
+
require 'async/reactor'
|
6
|
+
require 'async/io/host_endpoint'
|
7
|
+
require 'async/io/protocol/line'
|
8
|
+
require 'securerandom'
|
9
|
+
|
10
|
+
module Tarbit
|
11
|
+
class Server
|
12
|
+
attr_reader :connections
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@connections = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
endpoint = Async::IO::Endpoint.parse("tcp://localhost:1025")
|
20
|
+
|
21
|
+
Async do |task|
|
22
|
+
while true
|
23
|
+
task.sleep 1
|
24
|
+
Async.logger.info "Connection count: #{@connections.size}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Async do |task|
|
29
|
+
endpoint.accept do |peer|
|
30
|
+
stream = Async::IO::Stream.new(peer)
|
31
|
+
Async.logger.info "New connection: #{stream}"
|
32
|
+
|
33
|
+
@connections << {
|
34
|
+
created_at: Date.new,
|
35
|
+
id: SecureRandom.uuid
|
36
|
+
}
|
37
|
+
|
38
|
+
while true do
|
39
|
+
task.sleep 1
|
40
|
+
stream.write "#{rand(10)}\r\n"
|
41
|
+
end
|
42
|
+
rescue Async::TimeoutError => e
|
43
|
+
@connections.delete stream
|
44
|
+
Async.logger.info "Connection closed: #{stream}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'gruff'
|
2
|
+
require 'async'
|
3
|
+
|
4
|
+
module Tarbit
|
5
|
+
class Statistic
|
6
|
+
|
7
|
+
def initialize(server, interval)
|
8
|
+
@server = server
|
9
|
+
@interval = interval
|
10
|
+
@history = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def watch
|
14
|
+
Async do |task|
|
15
|
+
while true
|
16
|
+
task.sleep @interval
|
17
|
+
write_line_chart
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def write_line_chart
|
25
|
+
|
26
|
+
# Add point in time
|
27
|
+
@history << {
|
28
|
+
created_at: Date.new.strftime("%B %d, %Y"),
|
29
|
+
connections: @server.connections.clone # Cloning instead of referencing
|
30
|
+
}
|
31
|
+
|
32
|
+
g = Gruff::Line.new
|
33
|
+
g.title = 'History of connections over time'
|
34
|
+
|
35
|
+
labels = {}
|
36
|
+
@history.each_with_index{ |item, index| labels[index] = item.fetch(:created_at) }
|
37
|
+
g.labels = labels
|
38
|
+
|
39
|
+
g.data :Bots, @history.map {|point_in_time| point_in_time.fetch(:connections).size }
|
40
|
+
|
41
|
+
g.write('data/exciting.png')
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
data/lib/tarbit.rb
ADDED
data/tarbit.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "tarbit/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
|
7
|
+
s.name = 'tarbit'
|
8
|
+
s.version = Tarbit::VERSION
|
9
|
+
|
10
|
+
s.summary = "Summary"
|
11
|
+
s.description = "Description"
|
12
|
+
|
13
|
+
s.authors = ['Niklas Hanft']
|
14
|
+
s.email = 'hello@niklashanft.com'
|
15
|
+
s.homepage = 'https://github.com/nhh/apollo'
|
16
|
+
s.license = 'ISC'
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.executables << 'tarbit'
|
20
|
+
s.required_ruby_version = '~> 2.5'
|
21
|
+
s.require_path = 'lib'
|
22
|
+
|
23
|
+
# Dependencies
|
24
|
+
s.add_dependency 'async-io'
|
25
|
+
s.add_dependency 'commander'
|
26
|
+
s.add_dependency 'gruff'
|
27
|
+
|
28
|
+
# Development Dependencies
|
29
|
+
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tarbit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Niklas Hanft
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: async-io
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: commander
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: gruff
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Description
|
56
|
+
email: hello@niklashanft.com
|
57
|
+
executables:
|
58
|
+
- tarbit
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- bin/tarbit
|
66
|
+
- lib/tarbit.rb
|
67
|
+
- lib/tarbit/server.rb
|
68
|
+
- lib/tarbit/statistic.rb
|
69
|
+
- lib/tarbit/version.rb
|
70
|
+
- tarbit.gemspec
|
71
|
+
homepage: https://github.com/nhh/apollo
|
72
|
+
licenses:
|
73
|
+
- ISC
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '2.5'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubygems_version: 3.0.6
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Summary
|
94
|
+
test_files: []
|