ipp

package
v0.0.0-...-5d1382d Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: Apache-2.0, ISC Imports: 15 Imported by: 0

Documentation

Overview

Package ipp provides a zgrab2 module that scans for ipp. TODO: Describe module, the flags, the probe, the output, etc.

Index

Examples

Constants

View Source
const (
	ContentType         string = "application/ipp"
	VersionsSupported   string = "ipp-versions-supported"
	CupsVersion         string = "cups-version"
	PrinterURISupported string = "printer-uri-supported"
)

Variables

View Source
var (
	// ErrRedirLocalhost is returned when an HTTP redirect points to localhost,
	// unless FollowLocalhostRedirects is set.
	ErrRedirLocalhost = errors.New("Redirecting to localhost")

	// ErrTooManyRedirects is returned when the number of HTTP redirects exceeds
	// MaxRedirects.
	ErrTooManyRedirects = errors.New("Too many redirects")

	// TODO: Explain this error
	ErrVersionNotSupported = errors.New("IPP version not supported")

	Versions = []version{
		{Major: 2, Minor: 1},
		{Major: 2, Minor: 0},
		{Major: 1, Minor: 1},
		{Major: 1, Minor: 0},
	}

	AttributesCharset = []byte{
		0x47, 0x00, 0x12, 0x61, 0x74, 0x74, 0x72, 0x69,
		0x62, 0x75, 0x74, 0x65, 0x73, 0x2d, 0x63, 0x68,
		0x61, 0x72, 0x73, 0x65, 0x74,
	}
)

Functions

func AttributeByteString

func AttributeByteString(valueTag byte, name string, value string, target *bytes.Buffer) error

Writes an "attribute-with-one-value" with the provided "value-tag", "name", and "value" to provided buffer attribute-with-one-value encoding described at https://tools.ietf.org/html/rfc8010#section-3.1.4 Example (runnable from ipp_test.go):

Input: 0x47, "attributes-charset", "us-ascii"
Output: [71 0 18 97 116 116 114 105 98 117 116 101 115 45 99 104 97 114 115 101 116 0 8 117 115 45 97 115 99 105 105]

TODO: Switch output and Example function to use hex.Dump() TODO: Should return an error when fed an invalid valueTag

Example
var buf bytes.Buffer
if err := AttributeByteString(0x47, "attributes-charset", "us-ascii", &buf); err == nil {
	fmt.Println(buf.Bytes())
}
Output:

[71 0 18 97 116 116 114 105 98 117 116 101 115 45 99 104 97 114 115 101 116 0 8 117 115 45 97 115 99 105 105]

func ConvertURIToIPP

func ConvertURIToIPP(uriString string, tls bool) string

TODO: Eventually handle scheme-less urls, even though getHTTPURL will never construct one (we can use regex) TODO: RFC claims that literal IP addresses are not valid IPP uri's, but Wireshark IPP Capture example uses them (Source: https://wiki.wireshark.org/SampleCaptures?action=AttachFile&do=view&target=ipp.pcap)

Example
fmt.Println(ConvertURIToIPP("http://www.google.com:631/ipp", false))
fmt.Println(ConvertURIToIPP("https://www.google.com:631/ipp", true))
fmt.Println(ConvertURIToIPP("http://www.google.com/ipp", false))
fmt.Println(ConvertURIToIPP("https://www.google.com/ipp", true))
fmt.Println(ConvertURIToIPP("http://www.google.com:631", false))
fmt.Println(ConvertURIToIPP("https://www.google.com:631", true))
// TODO: Eventually test for scheme-less urls, but getHTTPURL will never construct one
//fmt.Println(ConvertURIToIPP("www.google.com:631/ipp", false))
//fmt.Println(ConvertURIToIPP("www.google.com:631/ipp", true))
Output:

func RegisterModule

func RegisterModule()

RegisterModule registers the zgrab2 module.

Types

type Attribute

type Attribute struct {
	Name     string  `json:"name,omitempty"`
	Values   []Value `json:"values,omitempty"`
	ValueTag byte    `json:"tag,omitempty"`
}

type Flags

type Flags struct {
	zgrab2.BaseFlags
	zgrab2.TLSFlags
	Verbose bool `long:"verbose" description:"More verbose logging, include debug fields in the scan results"`

	//FIXME: Borrowed from http module, determine whether this is all needed
	MaxSize      int    `long:"max-size" default:"256" description:"Max kilobytes to read in response to an IPP request"`
	MaxRedirects int    `long:"max-redirects" default:"0" description:"Max number of redirects to follow"`
	UserAgent    string `long:"user-agent" default:"Mozilla/5.0 zgrab/0.x" description:"Set a custom user agent"`
	TLSRetry     bool   `long:"ipps-retry" description:"If the initial request using TLS fails, reconnect and try using plaintext IPP."`

	// FollowLocalhostRedirects overrides the default behavior to return
	// ErrRedirLocalhost whenever a redirect points to localhost.
	FollowLocalhostRedirects bool `long:"follow-localhost-redirects" description:"Follow HTTP redirects to localhost"`

	// TODO: Maybe separately implement both an ipps connection and upgrade to https
	IPPSecure bool `long:"ipps" description:"Perform a TLS handshake immediately upon connecting."`
}

Flags holds the command-line configuration for the ipp scan module. Populated by the framework.

func (*Flags) Help

func (flags *Flags) Help() string

Help returns the module's help string.

func (*Flags) Validate

func (flags *Flags) Validate(args []string) error

Validate checks that the flags are valid. On success, returns nil. On failure, returns an error instance describing the error.

type Module

type Module struct {
}

Module implements the zgrab2.Module interface.

func (*Module) Description

func (module *Module) Description() string

Description returns an overview of this module.

func (*Module) NewFlags

func (module *Module) NewFlags() interface{}

NewFlags returns a default Flags object.

func (*Module) NewScanner

func (module *Module) NewScanner() zgrab2.Scanner

NewScanner returns a new Scanner instance.

type ScanResults

type ScanResults struct {
	//TODO: ?Include the request sent as well??
	Response     *http.Response `json:"response,omitempty" zgrab:"debug"`
	CUPSResponse *http.Response `json:"cups_response,omitempty" zgrab:"debug"`

	// RedirectResponseChain is non-empty if the scanner follows a redirect.
	// It contains all redirect responses prior to the final response.
	RedirectResponseChain []*http.Response `json:"redirect_response_chain,omitempty" zgrab:"debug"`

	MajorVersion  *int8  `json:"version_major,omitempty"`
	MinorVersion  *int8  `json:"version_minor,omitempty"`
	VersionString string `json:"version_string,omitempty"`
	CUPSVersion   string `json:"cups_version,omitempty"`

	Attributes           []*Attribute `json:"attributes,omitempty"`
	AttributeCUPSVersion string       `json:"attr_cups_version,omitempty"`
	AttributeIPPVersions []string     `json:"attr_ipp_versions,omitempty"`
	AttributePrinterURIs []string     `json:"attr_printer_uris,omitempty"`

	TLSLog *zgrab2.TLSLog `json:"tls,omitempty"`
}

TODO: Tag relevant results and exlain in comments ScanResults instances are returned by the module's Scan function.

type Scanner

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

Scanner implements the zgrab2.Scanner interface.

func (*Scanner) GetName

func (scanner *Scanner) GetName() string

GetName returns the Scanner name defined in the Flags.

func (*Scanner) GetTrigger

func (scanner *Scanner) GetTrigger() string

GetTrigger returns the Trigger defined in the Flags.

func (*Scanner) Grab

func (scanner *Scanner) Grab(scan *scan, target *zgrab2.ScanTarget, version *version) *zgrab2.ScanError

func (*Scanner) Init

func (scanner *Scanner) Init(flags zgrab2.ScanFlags) error

Init initializes the Scanner.

func (*Scanner) InitPerSender

func (scanner *Scanner) InitPerSender(senderID int) error

InitPerSender initializes the scanner for a given sender.

func (*Scanner) Protocol

func (scanner *Scanner) Protocol() string

Protocol returns the protocol identifier of the scan.

func (*Scanner) Scan

func (scanner *Scanner) Scan(target zgrab2.ScanTarget) (zgrab2.ScanStatus, interface{}, error)

Scan TODO: describe how scan operates in appropriate detail 1. Send a request (currently get-printer-attributes) 2. Take in that response & read out version numbers

type Value

type Value struct {
	Bytes []byte `json:"raw,omitempty"`
}

Jump to

Keyboard shortcuts

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