Giter Club home page Giter Club logo

ronin-core's Introduction

ronin-core

CI Code Climate Gem Version

Description

ronin-core is a core library providing common functionality for all ronin libraries.

ronin-core is part of the ronin-rb project, a toolkit for security research and development.

Features

  • Provides access to the XDG directories (~/.config/, ~/.cache/, ~/.local/share).
  • Allows querying ~/.gitconfig for common git settings.
  • Provides a common Command base class for all ronin libraries.
  • Provides a Shell and CommandShell base classes for writing interactive shells.
  • Provides a Params API for adding user configurable parameters to classes.
  • Has 85% documentation coverage.
  • Has 99% test coverage.

Requirements

Install

Gemfile

gem 'ronin-core', '~> 0.1'

gemspec

gem.add_depedency 'ronin-core', '~> 0.1'
dependencies:
  ronin-core: ~> 0.1

Examples

Params

class BaseClass

  include Ronin::Core::Params::Mixin

end
class MyModule < BaseClass

  param :str, desc: 'A basic string param'

  param :feature_flag, Boolean, desc: 'A boolean param'

  param :enum, Enum[:one, :two, :three],
               desc: 'An enum param'

  param :num1, Integer, desc: 'An integer param'

  param :num2, Integer, default: 42,
                       desc: 'A param with a default value'

  param :num3, Integer, default: ->{ rand(42) },
                        desc: 'A param with a dynamic default value'

  param :float, Float, 'Floating point param'

  param :url, URI, desc: 'URL param'

  param :pattern, Regexp, desc: 'Regular Expression param'

end

mod = MyModule.new(params: {num1: 1, enum: :two})
mod.params
# => {:num2=>42, :num3=>25, :num1=>1, :enum=>:two}

CLI

Define a main command for ronin-foo:

# lib/ronin/foo/cli.rb
require 'command_kit/commands'
require 'command_kit/commands/auto_load'

module Ronin
  module Foo
    class CLI

      include CommandKit::Commands
      include CommandKit::Commands::AutoLoad.new(
        dir:       "#{__dir__}/cli/commands",
        namespace: "#{self}::Commands"
      )

      command_name 'ronin-foo'

      command_aliases['ls'] = 'list'
      # ...

    end
  end
end

Add a bin/ronin-foo file (don't forget to chmod +x it) that invokes the main command:

#!/usr/bin/env ruby

root = File.expand_path(File.join(__dir__,'..'))
if File.file?(File.join(root,'Gemfile.lock'))
  Dir.chdir(root) do
    begin
      require 'bundler/setup'
    rescue LoadError => e
      warn e.message
      warn "Run `gem install bundler` to install Bundler"
      exit -1
    end
  end
end

require 'ronin/foo/cli'
Ronin::Foo::CLI.start

Define a common command class for all ronin-foo's commands:

# lib/ronin/foo/cli/command.rb
require 'ronin/core/cli/command'

module Ronin
  module Foo
    class CLI
      class Command < Core::CLI::Command

        man_dir File.join(__dir__,'..','..','..','..','man')

      end
    end
  end
end

Define a list sub-command under the ronin-foo main command:

# lib/ronin/foo/cli/commands/list.rb
require 'ronin/foo/cli/command'

module Ronin
  module Foo
    class CLI
      module Commands
        class List < Command

          usage '[options] [NAME]'

          argument :name, required: false,
                          desc:     'Optional name to list'

          description 'Lists all things'

          man_page 'ronin-foo-list.1'

          def run(name=nil)
            # ...
          end

        end
      end
    end
  end
end

Test it out:

$ ./bin/ronin-foo
Usage: ronin-foo [options] [COMMAND [ARGS...]]

Options:
    -h, --help                       Print help information

Arguments:
    [COMMAND]                        The command name to run
    [ARGS ...]                       Additional arguments for the command

Commands:
    help
    list, ls
$ ./bin/ronin-foo ls

CLI::CommandShell

Define a custom command shell:

class HTTPShell < Ronin::Core::CLI::CommandShell

  shell_name 'http'

  command :get, usage: 'PATH [HEADERS...]',
                summary: 'Sends a GET request'
  def get(path,*headers)
    # ...
  end

  command :post, usage: 'PATH DATA [HEADERS...]',
                 summary: 'Sends a POST request'
  def post(path,data,*headers)
    # ...
  end

end

Then start it:

HTTPShell.start
http> get /foo
...
http> post /foo var=bar
...

Development

  1. Fork It!
  2. Clone It!
  3. cd ronin-core/
  4. bundle install
  5. git checkout -b my_feature
  6. Code It!
  7. bundle exec rake spec
  8. git push origin my_feature

License

Copyright (c) 2021-2023 Hal Brodigan ([email protected])

ronin-core is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

ronin-core is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with ronin-core. If not, see https://www.gnu.org/licenses/.

ronin-core's People

Contributors

just1602 avatar postmodern avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

ronin-core's Issues

Add a `TipFile` class for parsing `tips.yml` files

Add a TipFile class for parsing the tips.yml file format. The TipFile class should provide a .parse or .load method, and a random method which returns a random Tip object. The YAML file format will look something like:

---
- text: |
    To do blah blah lbah:
    
      ruby_code_here
      
  tags: [tag1, tag2]
- text: ...
  tags: ...

Add a Tip class which represents an individual tip object (text: String, tags: Array<Sting>).

Add tab-completion support to Ronin::Core::CLI::Shell

Add tab-completion support to Ronin::Core::CLI::Shell. It should be possible to tab-complete command names, as well as additional arguments/options for a command.

fo<TAB><TAB>
foo
foot
food

foo --b<TAB><TAB>
--bytes

This can be accomplished using Reline.completion_proc = ->(line) { ...}. Each command should also have an optional array of known completion values.

command :foo, usage: '[options]', summary: '...', completion: %w[--bytes --count -c ...]

Add a Module Registry API

Add a "module registry" API that allows Classes to register themselves into a parent Module. It must allow requiring a Class from within a sub-directory (ex: exploits/). The loaded Class would then register itself into the parent Module with a given name. The parent Module would then allow accessing these classes via arbitrary String name.

Pseudo Code

module Ronin
  module Exploits
    include Ronin::Core::Registry.new(dir: `exploits`)
  end

  class Exploit
    def self.register(name)
      Exploits.register(name,self)
    end
  end
end
class SomeExploit < Ronin::Exploits::Exploit

  register 'some_exploit'

  # ...
end
Ronin::Exploits.load('some_exploit')
# => SomeExploit
Ronin::Exploits.registry['some_exploit']
# => SomeExploit

See Also

See Bundler::Audit::CLI::Formats for an example of the Module Registry pattern.

Add Ronin::Core::Shell

Add Ronin::Core::Shell and use the pure-Ruby reline library. This means that even if libreadline wasn't installed or the ruby wasn't built with libreadline support, we can still have Readline functionality.

Must also parse the input command line using Shellwords.shellwords to un-escape any double quoted Strings.

It must also support defining shell commands as methods, since the shell will likely also have some shared state that all commands interact with (ex: a @http variable). Commands will have a name, usage, and longer help text. Commands may also have one/two-letter aliases.

Command Pseudo Code

command 'foo', '[ARGS] ARG', <<HELP
The foo command bla bla bla

Bla bla bla

    foo --bar baz
    
HELP

def foo(args=[])
  # ...
end

Example Reline Code

require "reline"

prompt = 'prompt> '
use_history = true

begin
  while true
    text = Reline.readline(prompt, use_history)

    if text.nil?
      puts
      break
    end

    puts 'You entered:'
    puts text
  end
# If you want to exit, type Ctrl-C
rescue Interrupt
  puts '^C'
  exit 0
end

Release 0.1.3

Release 0.1.3 which includes an enhancement for ClassRegistry's load_class_from_file.

Add `Ronin::Core::Metadata::Description`

Add a Ronin::Core::Metadata::Description mixin that adds a description class method for adding a block of text describing the module.

Example

class Exploit

  include Ronin::Core::Metadata::Description
  
  description <<~DESC
    Bla bla bla
    
      $ command
      
    Blah blah blah
  DESC
  
end

Add a `Ronin::Core::System` module

Add a module for interacting with the system:

  • determine the OS
  • parse $PATH
  • determine if an executable is installed
  • determine if wget or curl is installed.
  • download files using wget or curl.

Add `Ronin::Core::Metadata::ModuleName`

Add a metadata mixin called Ronin::Core::Metadata::ModuleName so Exploits/Payloads/etc can define a module-name as well as register themselves with the Ronin::Core::ModuleRegistry.

Add a `Ronin::Core::CLI::TipCommand` base class

Add a Ronin::Core::CLI::TipCommand base class which other ronin-* libraries can extend to add their own tips command. It should support loading tips from a tips.yml file, printing a random tip, printing all tips, and filtering tips by tags.

Add `Ronin::Core::Params` API

Add a params API for defining configurable params in a class. Must support defining the param type (defaults to String), a default value, and a description. Support basic param types: String, Integer, Boolean, Float, Enum, URI.

Example Code

class BaseClass

  include Ronin::Core::Params::Mixin

end

class MyModule < BaseClass

  param :str, desc: 'A basic param'

  param :feature_flag, Boolean, desc: 'A boolean param'

  param :num1, Integer, desc: 'A param with a type'

  param :num2, Integer, default: 42,
                       desc: 'A param with a default value'

  param :num3, Integer, default: ->{ rand(42) },
                        desc: 'A param with a dynamic default value'

  param :enum, Enum[:one, :two, :three],
               desc: 'An enum param'

end

mod = MyModule.new(params: {num1: 1, enum: :two})
mod.params
# => {:num2=>42, :num3=>25, :num1=>1, :enum=>:two}

Add rubocop

Add rubocop to the repository.

  • Add the rubocop gem to the Gemfile.
  • Train rubocop on the existing code (rubocop --auto-gen-config) and try to fix as many 1-2 time syntax violations.
  • Add a rubocop task and add it to the CI.

Add `Ronin::Core::Metadata::References`

Add a Ronin::Core::Metadata::References mixin to allow adding reference URLs.

Examples

  include Ronin::Core::Metadata::References
  
  references {
    "Title Here" => "https://...",
    # ...
  }

Add `Ronin::Core::Metadata::Author`

Add a Ronin::Core::Metadata::Author mixin that adds a author class method for setting the license of a module.

Example

include Ronin::Core::Metadata::Author

author 'John Smith'

Add a lower-level `Params::Types::Map` type

Add a lower-level Params::Types::Map type, which Params::Types::Enum will inherit from. This type will allow defining an arbitrary mapping of String values to other Ruby objects:

param :arch, Map[
  'x86-64' => :x86_64,
  ...
], desc: 'The architecture to compile for'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.