Sha256: 9e4359e1b45aa591991cd70706bca305b4857178bf502c1903634dff68807192

Contents?: true

Size: 1.7 KB

Versions: 721

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

require 'base64'

module PWN
  module Plugins
    # This plugin Base64 encodes/decodes AuthN credentials for passing to a ''Basic''
    # authorization HTTP header.
    module BasicAuth
      # Supported Method Parameters::
      # PWN::Plugins::BasicAuth.encode(
      #   username: 'optional username',
      #   password: 'optional password'
      # )

      public_class_method def self.encode(opts = {})
        basic_user = opts[:username].to_s.chomp unless opts[:username].nil?
        basic_pass = opts[:password].to_s.chomp unless opts[:password].nil?
        base64_str = "#{basic_user}:#{basic_pass}"
        @base64_encoded_auth = Base64.strict_encode64(base64_str).to_s.chomp
        @base64_encoded_auth
      rescue StandardError => e
        raise e
      end

      # Supported Method Parameters::
      # PWN::Plugins::BasicAuth.decode(
      #   base64_str: 'required base64 encoded string'
      # )

      public_class_method def self.decode(opts = {})
        base64_str = opts[:base64_str]
        @base64_decoded_auth = Base64.decode64(base64_str)
        @base64_decoded_auth
      rescue StandardError => e
        raise e
      end

      # Author(s):: 0day Inc. <request.pentest@0dayinc.com>

      public_class_method def self.authors
        "AUTHOR(S):
          0day Inc. <request.pentest@0dayinc.com>
        "
      end

      # Display Usage for this Module

      public_class_method def self.help
        puts "USAGE:
          #{self}.encode(
            username: 'optional username',
            password: 'optional password'
          )

          #{self}.decode(base64_str: 'base64 encoded string')

          #{self}.authors
        "
      end
    end
  end
end

Version data entries

721 entries across 721 versions & 1 rubygems

Version Path
pwn-0.5.104 lib/pwn/plugins/basic_auth.rb
pwn-0.5.103 lib/pwn/plugins/basic_auth.rb
pwn-0.5.102 lib/pwn/plugins/basic_auth.rb
pwn-0.5.101 lib/pwn/plugins/basic_auth.rb
pwn-0.5.100 lib/pwn/plugins/basic_auth.rb
pwn-0.5.99 lib/pwn/plugins/basic_auth.rb
pwn-0.5.98 lib/pwn/plugins/basic_auth.rb
pwn-0.5.97 lib/pwn/plugins/basic_auth.rb
pwn-0.5.96 lib/pwn/plugins/basic_auth.rb
pwn-0.5.95 lib/pwn/plugins/basic_auth.rb
pwn-0.5.94 lib/pwn/plugins/basic_auth.rb
pwn-0.5.93 lib/pwn/plugins/basic_auth.rb
pwn-0.5.92 lib/pwn/plugins/basic_auth.rb
pwn-0.5.91 lib/pwn/plugins/basic_auth.rb
pwn-0.5.90 lib/pwn/plugins/basic_auth.rb
pwn-0.5.89 lib/pwn/plugins/basic_auth.rb
pwn-0.5.88 lib/pwn/plugins/basic_auth.rb
pwn-0.5.87 lib/pwn/plugins/basic_auth.rb
pwn-0.5.86 lib/pwn/plugins/basic_auth.rb
pwn-0.5.85 lib/pwn/plugins/basic_auth.rb