cmd

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddCmd = &cobra.Command{
	Use:   "add",
	Short: "Add items to scope",
	Long: `Add items to scope unless it has been excluded via scopius exclude. For example:

	cat customer-supplied.txt | scopious add

	scopious add -i internal 10.0.0.0/22
`,
	Run: func(cmd *cobra.Command, args []string) {
		scopeName, _ := cmd.Flags().GetString("scope")
		all, _ := cmd.Flags().GetBool("all")
		scope := scoperInstance.GetScope(scopeName)

		if len(args) > 0 {
			scope.Add(all, args...)
		} else {

			scanner := bufio.NewScanner(os.Stdin)
			for scanner.Scan() {
				scopeLine := scanner.Text()
				scope.Add(all, scopeLine)
			}

			if scanner.Err() != nil {
				log.Printf("STDIN scanner encountered an error: %s", scanner.Err())
			}
		}

		scoperInstance.Save()
	},
}

AddCmd represents the add command

View Source
var DomainsCmd = &cobra.Command{
	Use:   "domains",
	Short: "Print out in scope domains",
	Long: `Print out in scope domains. For example:

Print all domains in scope:
	scopious domains

Print in scope root domains:
	scopious domains -r
`,
	Run: func(cmd *cobra.Command, args []string) {
		scopeName, _ := cmd.Flags().GetString("scope")
		showRootDomains, _ := cmd.Flags().GetBool("root-domains")
		scope := scoperInstance.GetScope(scopeName)

		var domains []string

		if showRootDomains {
			domains = scope.RootDomains()
		} else {
			domains = scope.AllDomains()
		}

		for _, domain := range domains {
			fmt.Println(domain)
		}
	},
}

DomainsCmd represents the domains command

View Source
var ExcludeCmd = &cobra.Command{
	Use:   "exclude",
	Short: "Add an item to the exclude list",
	Long: `Add items to to the exclude list.

Sometimes not every subdomain underneath a domain or IP address
in a CIDR is in scope.

	scopious exclude admin.example.com
`,
	Run: func(cmd *cobra.Command, args []string) {
		shouldList, _ := cmd.Flags().GetBool("list")
		scopeName, _ := cmd.Flags().GetString("scope")
		scope := scoperInstance.GetScope(scopeName)

		if shouldList {
			for excluded, _ := range scope.Excludes {
				fmt.Println(excluded)
			}
			return
		}
		if len(args) > 0 {
			scope.AddExclude(args...)
		} else {

			scanner := bufio.NewScanner(os.Stdin)
			for scanner.Scan() {
				scopeLine := scanner.Text()
				scope.AddExclude(scopeLine)
			}

			if scanner.Err() != nil {
				log.Printf("STDIN scanner encountered an error: %s", scanner.Err())
			}
		}
		scoperInstance.Save()
	},
}

ExcludeCmd represents the block command

View Source
var ExpandCmd = &cobra.Command{
	Use:   "expand",
	Short: "Expand CIDRs",
	Long: `Expand CIDRs. For example:

	cat customer-supplied.txt | scopious expand

	scopious expand 10.0.0.0/22
`,
	Run: func(cmd *cobra.Command, args []string) {

		all, _ := cmd.Flags().GetBool("all")

		if len(args) > 0 {
			for _, scopeLine := range args {
				processScopeLine(scopeLine, all)
			}
		} else {

			scanner := bufio.NewScanner(os.Stdin)
			for scanner.Scan() {
				scopeLine := scanner.Text()
				processScopeLine(scopeLine, all)
			}

			if scanner.Err() != nil {
				log.Printf("STDIN scanner encountered an error: %s", scanner.Err())
			}
		}
	},
}
View Source
var IpsCmd = &cobra.Command{
	Use:   "ips",
	Short: "List IP addresses in scope",
	Long: `List IP addresses in scope.

Show in scope ips
	scopious ips

Expand CIDRs and remove excluded ips
	scopious ips -x
`,
	Run: func(cmd *cobra.Command, args []string) {
		scopeName, _ := cmd.Flags().GetString("scope")
		shouldExpand, _ := cmd.Flags().GetBool("expand")
		all, _ := cmd.Flags().GetBool("all")
		scope := scoperInstance.GetScope(scopeName)

		var scopeStrings []string
		if shouldExpand {
			scopeStrings = scope.AllExpanded(all)
			sort.Strings(scopeStrings)
		} else {
			scopeStrings = scope.AllIPs()
		}

		for _, ip := range scopeStrings {
			fmt.Println(ip)
		}
	},
}

IpsCmd represents the ips command

View Source
var PruneCmd = &cobra.Command{
	Use:   "prune",
	Short: "Prune excluded scope items from input",
	Long: `Prune excluded scope items from input

cat urls.txt | scopious prune
`,
	Run: func(cmd *cobra.Command, args []string) {
		scopeName, _ := cmd.Flags().GetString("scope")
		all, _ := cmd.Flags().GetBool("all")
		scope := scoperInstance.GetScope(scopeName)

		scopeToCheck := []string{}
		scanner := bufio.NewScanner(os.Stdin)
		for scanner.Scan() {
			scopeLine := scanner.Text()
			scopeToCheck = append(scopeToCheck, scopeLine)
		}

		if scanner.Err() != nil {
			log.Printf("STDIN scanner encountered an error: %s", scanner.Err())
		}
		prunedScope := scope.Prune(all, scopeToCheck...)

		for _, scopeLine := range prunedScope {
			fmt.Println(scopeLine)
		}
	},
}

PruneCmd represents the check command

View Source
var RootCmd = &cobra.Command{
	Use:   "scopious",
	Short: "Manage scope for your network based projects",
	Long: `Scoper can help you manage the scope of network projects by:

- Automatically detecting and separating IP addresses or domains
- Ensuring an item is in the scope of your engagement
- Keep track of multiple scope for your engagement

To use, simply supply your scope as arguments to scopious add

	scopious add example.com example.net 203.0.113.0/24
	cat scope.txt | scopious add

By default scope is stored in ./scope/external/. This scan be changed by specifying -s

	scopious add -s internal evil.corp internal.corpdev 10.0.0.1/24

You can exclude things from scope as well

	scope excluded admin.example.com 203.0.113.0/29

Scoper can validate items are in scope

	cat maybe-inscope.txt | scopious prune > inscope.txt

Need to view your scope data, scopious can show you all your scope in various ways

List in scope domains
	scopious domains

list in scope root domains
	scopious domains -r

list in scope ips
	scopious ips

expand cidrs and remove excluded things
	scopious ips -x

list excluded things
	scopious exclude -l




`,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		debug := viper.GetBool("debug")
		if debug {
			state.Debug = true
		}
		scopeDir := viper.GetString("scope-dir")
		scoperInstance = scopious.FromPath(scopeDir)
	},
}

RootCmd represents the base command when called without any subcommands

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func SetVersionInfo

func SetVersionInfo(versionStr, commitStr string)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳