scope

package module
v0.0.0-...-b995af0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2025 License: MIT Imports: 6 Imported by: 1

README

scope

Simple library for managing scopes of hosts and IPv4 addresses, ideal for penetration testing tools and other network-related Go applications.

Installation

go get github.com/root4loot/scope@latest

Simple Usage

package main

import (
	"fmt"
	"github.com/root4loot/scope"
)

func main() {
	// Initialize a new scope instance
	sc := scope.NewScope()

	// Explicit scope mode: Only defined includes are in scope
	sc.AddInclude("example.com")
	sc.AddInclude("192.168.1.1")

	// Add excludes
	sc.AddExclude("example.com:8080")
	sc.AddExclude("http://192.168.1.1")

	// Check if a domain is in scope
	fmt.Println(sc.IsInScope("example.com"))       // Output: true
	fmt.Println(sc.IsInScope("example.com:8080"))  // Output: false

	// Check if an IP is in scope
	fmt.Println(sc.IsInScope("192.168.1.1"))        // Output: false
	fmt.Println(sc.IsInScope("10.0.0.1"))           // Output: true

	// Implicit scope mode: Everything is in scope unless explicitly excluded
	sc2 := scope.NewScope()
	sc2.AddExclude("blocked.com")
	fmt.Println(sc2.IsInScope("random.com"))       // Output: true
	fmt.Println(sc2.IsInScope("blocked.com"))     // Output: false

	// Get active scope
	activeScope := sc.GetScope()
	fmt.Printf("Active scope: %v\n", activeScope)
}
Scope Behavior
  • If no includes are defined, everything is in scope unless explicitly excluded.
  • If includes are defined, only those targets are in scope, and everything else is out of scope by default.
  • Exclusions always take priority over inclusions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope holds the include and exclude lists

func NewScope

func NewScope() *Scope

NewScope initializes and returns a new Scope instance

func (*Scope) AddExclude

func (s *Scope) AddExclude(definition string) error

AddExclude adds a new single exclude scope definition

func (*Scope) AddExcludes

func (s *Scope) AddExcludes(definitions []string) error

AddExcludes adds multiple exclude scope definitions from a slice

func (*Scope) AddInclude

func (s *Scope) AddInclude(definition string) error

AddInclude adds a new single include scope definition

func (*Scope) AddIncludes

func (s *Scope) AddIncludes(definitions []string) error

AddIncludes adds multiple include scope definitions from a slice

func (*Scope) GetExcludes

func (s *Scope) GetExcludes() []string

GetExcludes returns the exclude scope definitions as a slice of strings

func (*Scope) GetIncludes

func (s *Scope) GetIncludes() []string

GetIncludes returns the include scope definitions as a slice of strings

func (*Scope) GetScope

func (s *Scope) GetScope() []string

GetScope returns the active inclusions, removing any that are excluded

func (*Scope) IsExcluded

func (s *Scope) IsExcluded(target string) bool

IsExcluded checks if a given target is explicitly excluded

func (*Scope) IsExplicitScope

func (s *Scope) IsExplicitScope() bool

func (*Scope) IsInScope

func (s *Scope) IsInScope(target string) bool

IsInScope checks if a given URL or domain is in scope

type ScopeDefinition

type ScopeDefinition struct {
	Definition string
	// contains filtered or unexported fields
}

ScopeDefinition holds the original string and its compiled regex

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL