caido 0.0.0.pre.dev → 0.1.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.
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Caido
4
+ # Instance class
5
+ class Instance
6
+ def example_helper
7
+ 'test'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Caido
4
+ # Instance class
5
+ class Instance
6
+ def automate_session(id)
7
+ query("query{
8
+ automateSession(id: \"#{id}\"){
9
+ id
10
+ name
11
+ raw
12
+ createdAt
13
+ }
14
+ }")['automateSession']
15
+ end
16
+
17
+ def automate_sessions
18
+ query('query{
19
+ automateSessions{
20
+ nodes{
21
+ id
22
+ name
23
+ raw
24
+ createdAt
25
+ }
26
+ }
27
+ }')['automateSessions']
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Caido
4
+ # Instance class
5
+ class Instance
6
+ def hosted_files
7
+ query('query {
8
+ hostedFiles {
9
+ id
10
+ name
11
+ createdAt
12
+ updatedAt
13
+ path
14
+ size
15
+ }
16
+ }')['hostedFiles']
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Caido
4
+ # Instance class
5
+ class Instance
6
+ def projects
7
+ query('query {
8
+ projects{
9
+ id
10
+ name
11
+ version
12
+ updatedAt
13
+ }
14
+ }')['projects']
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Caido
4
+ # Instance class
5
+ class Instance
6
+ def replay_collections
7
+ query('query {
8
+ replaySessionCollections{
9
+ nodes{
10
+ name
11
+ sessions{
12
+ name
13
+ id
14
+ }
15
+ }
16
+ }
17
+ }')['replaySessionCollections']['nodes']
18
+ end
19
+
20
+ def replay_session(id)
21
+ query("query{
22
+ replaySession(id: \"#{id}\"){
23
+ name
24
+ activeEntry{
25
+ request{
26
+ host
27
+ path
28
+ method
29
+ query
30
+ raw
31
+ isTls
32
+ fileExtension
33
+ source
34
+ port
35
+
36
+ }
37
+ }
38
+ }
39
+ }")['replaySession']
40
+ end
41
+
42
+ def all_replay
43
+ sessions_data = []
44
+ collections = query('query {
45
+ replaySessionCollections{
46
+ nodes{
47
+ name
48
+ sessions{
49
+ name
50
+ id
51
+ }
52
+ }
53
+ }
54
+ }')['replaySessionCollections']['nodes']
55
+
56
+ collections.each do |collection|
57
+ next unless collection
58
+
59
+ sessions = collection['sessions']
60
+
61
+ sessions.each do |session|
62
+ next unless session
63
+
64
+ sessions_data << query("query{
65
+ replaySession(id: \"#{session['id']}\"){
66
+ name
67
+ activeEntry{
68
+ request{
69
+ host
70
+ path
71
+ method
72
+ query
73
+ raw
74
+ isTls
75
+ fileExtension
76
+ source
77
+ port
78
+
79
+ }
80
+ }
81
+ }
82
+ }")['replaySession']
83
+ end
84
+ end
85
+
86
+ sessions_data
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Caido
4
+ # Instance class
5
+ class Instance
6
+ def version
7
+ query('{runtime{version}}')['runtime']['version']
8
+ end
9
+
10
+ def platform
11
+ query('{runtime{platform}}')['runtime']['platform']
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Caido
4
+ # Instance class
5
+ class Instance
6
+ def workflows
7
+ query('query{
8
+ workflows{
9
+ id
10
+ name
11
+ kind
12
+ enabled
13
+ global
14
+ definition
15
+ createdAt
16
+ updatedAt
17
+ }
18
+ }')['workflows']
19
+ end
20
+
21
+ def workflow(id)
22
+ query("query{
23
+ workflow(id: \"#{id}\"){
24
+ id
25
+ name
26
+ kind
27
+ enabled
28
+ global
29
+ definition
30
+ createdAt
31
+ updatedAt
32
+ }
33
+ }")['workflow']
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+ require 'json'
5
+
6
+ # Assuming this code is at the top level of instance.rb and helplers directory is at the same level
7
+ Dir[File.expand_path('helpers/*.rb', __dir__)].each { |file| require file }
8
+
9
+ module Caido
10
+ # Instance class
11
+ class Instance
12
+ attr_reader :graphql_url, :authorization
13
+
14
+ def initialize(*args)
15
+ set_defaults
16
+ process_arguments(args)
17
+ auth_from_env
18
+ end
19
+
20
+ private
21
+
22
+ def set_defaults
23
+ @graphql_url = 'http://localhost:8080/graphql'
24
+ @authorization = nil
25
+ end
26
+
27
+ def process_arguments(args)
28
+ case args.size
29
+ when 1
30
+ @graphql_url = args[0]
31
+ when 2
32
+ @graphql_url, authorization = args
33
+ @authorization = format_authorization(authorization)
34
+ when args.size > 2
35
+ raise ArgumentError, 'Too many arguments provided'
36
+ end
37
+ end
38
+
39
+ def format_authorization(auth)
40
+ auth.include?('Bearer ') ? auth : "Bearer #{auth}"
41
+ end
42
+
43
+ def auth_from_env
44
+ @auth_from_env ||= ENV.fetch('CAIDO_AUTH_TOKEN', 'Bearer ')
45
+ end
46
+
47
+ def query(query)
48
+ res = HTTParty.post(
49
+ graphql_url,
50
+ body: { query: }.to_json,
51
+ headers: {
52
+ 'Content-Type' => 'application/json',
53
+ 'Authorization' => authorization
54
+ }
55
+ )
56
+
57
+ obj = JSON.parse(res.body)
58
+ obj['data']
59
+ end
60
+ end
61
+ end
data/lib/caido/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Caido
4
- VERSION = "0.0.0.pre.dev"
4
+ VERSION = '0.1.0'
5
5
  end
data/lib/caido.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "caido/version"
3
+ require_relative 'caido/version'
4
+ require_relative 'caido/instance'
4
5
 
5
6
  module Caido
6
7
  class Error < StandardError; end
7
- # Your code goes here...
8
8
  end
metadata CHANGED
@@ -1,34 +1,76 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caido
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.pre.dev
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - HAHWUL
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-14 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Tuby implementation of Caido
11
+ date: 2024-06-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: graphql
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.22.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.22.0
41
+ description: |-
42
+ The caido-ruby library simplifies using Caido's API in Ruby applications.
43
+ Caido is lightweight web security auditing toolkit.
14
44
  email:
15
45
  - hahwul@gmail.com
16
46
  executables: []
17
47
  extensions: []
18
48
  extra_rdoc_files: []
19
49
  files:
50
+ - ".rubocop.yml"
20
51
  - LICENSE
21
52
  - README.md
22
53
  - Rakefile
23
54
  - caido.gemspec
55
+ - caido_introspection_schema.json
24
56
  - lib/caido.rb
57
+ - lib/caido/helpers/_example.rb
58
+ - lib/caido/helpers/automate.rb
59
+ - lib/caido/helpers/hosted_file.rb
60
+ - lib/caido/helpers/project.rb
61
+ - lib/caido/helpers/replay.rb
62
+ - lib/caido/helpers/runtime.rb
63
+ - lib/caido/helpers/workflow.rb
64
+ - lib/caido/instance.rb
25
65
  - lib/caido/version.rb
26
66
  - sig/caido.rbs
27
- homepage: https://github.com/caineers/caido-ruby
28
- licenses: []
67
+ homepage: https://rubygems.org/gems/caido
68
+ licenses:
69
+ - MIT
29
70
  metadata:
30
- homepage_uri: https://github.com/caineers/caido-ruby
71
+ homepage_uri: https://rubygems.org/gems/caido
31
72
  source_code_uri: https://github.com/caineers/caido-ruby
73
+ rubygems_mfa_required: 'true'
32
74
  post_install_message:
33
75
  rdoc_options: []
34
76
  require_paths:
@@ -37,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
37
79
  requirements:
38
80
  - - ">="
39
81
  - !ruby/object:Gem::Version
40
- version: 2.6.0
82
+ version: 3.1.0
41
83
  required_rubygems_version: !ruby/object:Gem::Requirement
42
84
  requirements:
43
85
  - - ">="
@@ -47,5 +89,5 @@ requirements: []
47
89
  rubygems_version: 3.5.3
48
90
  signing_key:
49
91
  specification_version: 4
50
- summary: Ruby implementation of Caido
92
+ summary: The caido-ruby library simplifies using Caido's API in Ruby applications.
51
93
  test_files: []