scanner

package
v0.0.0-...-d7c6eb9 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Project constants

Logging

SSHServer(s) structs, methods and related functions.

Utility functions.

Index

Constants

View Source
const (
	// Flag usage descriptions
	TargetUsage  = "one or more comma-separated scanning `target`s"
	InputUsage   = "`input file` with one target address on each line"
	OutputUsage  = "store results in `output file`"
	LogUsage     = "store logs in `log file(s)`"
	VerboseUsage = "print logs to console"

	// Application constants for cli package
	AppUsage = `` /* 284-byte string literal not displayed */

	AppDescription = `` /* 540-byte string literal not displayed */

	// Scanning constants
	// Timeout
	Timeout = 5 * time.Second

	// Default SSH username and password
	DefaultUser     = "user"
	DefaultPassword = "password"

	// Logging
	// Log prefix - appears before every line in logs - note the space
	LogPrefix = "[*] "
	// LogFlag can be any combination of (join with |):
	// Ldate | Ltime | Lmircoseconds | Llongfile | Lshortfile | LUTC
	// See https://godoc.org/log#pkg-constants
	LogFlag = log.Ltime
)

Variables

This section is empty.

Functions

func ReadTargetFile

func ReadTargetFile(file string) ([]string, error)

ReadTargetFile opens a file and attempts to read targets from it. Returns a string slice of target addresses. Each target should on its own line and in the correct "host:port" format.

func RemoveDuplicates

func RemoveDuplicates(s []string) []string

RemoveDuplicates reads a []string and removes duplicates from the slice. There are more efficient ways of doing this but for our purpose this way is easier to read. We create a second map[string]bool, go through the addresses and check if the address is in the map, if so we continue. If not, we add it to the map. In the end, the new map contains only unique addresses and we convert it back to []string.

func SetupLogging

func SetupLogging(logwriters ...string) (*log.Logger, error)

SetupLogging will return a log.Logger object that can be used for logging. It will write the logs to all io.Writers designated in logs. If there are any errors, it will return nil and the appropriate error. Usage: SetupLogging("log1.txt") = only log to one file SetupLogging("log1.txt", "os.Stdout") = log to both os.Stdout and file SetupLogging("log1.txt", "log2.txt") = log to two files SetupLogging("os.Stdout") = only log to stdout SetupLogging("os.Stderr", "os.Stdout") = log to both os.Stdout and os.Stderr

func ToJSON

func ToJSON(s interface{}, prettyPrint bool) (string, error)

ToJSON converts input to JSON. If prettyPrint is set to True it will call MarshallIndent with 4 spaces. If your struct does not work here, make sure struct fields start with a capital letter. Otherwise they are not visible to the json package methods.

func WriteReport

func WriteReport(file string, servers SSHServers) error

WriteReport stores results to file. Preferably uses ToJSON. If it cannot, prints them as string with .

Types

type SSHServer

type SSHServer struct {
	Address    string            // host:port
	Host       string            // IP address
	Port       int               // port
	IsSSH      bool              // true if SSH is listening on host:port
	Banner     string            // banner text, if any
	Certs      []ssh.Certificate // server's certificates
	Hostname   string            // hostname
	PublicKeys []ssh.PublicKey   // server's public keys
}

Struct to hold server data

func NewSSHServer

func NewSSHServer(address string) (*SSHServer, error)

NewSSHServer returns a new SSHServer with address, host and port populated. Returns an error if address cannot be processed.

type SSHServers

type SSHServers []*SSHServer

SSHServers is a slice of *SSHServer

func (*SSHServers) Initialize

func (s *SSHServers) Initialize(addresses []string, logger *log.Logger)

Initialize converts the list of addresses to *SSHServer and stores the results in the SSHServers receiver.

func (*SSHServers) Process

func (s *SSHServers) Process(logger *log.Logger)

Process goes through all servers and populates them.

func (*SSHServers) String

func (s *SSHServers) String() string

String converts []*SSHServer to JSON. If it cannot convert to JSON, it will convert each member to string using fmt.Sprintf("%+v").

Jump to

Keyboard shortcuts

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