sniffer

package module
v0.0.0-...-0c0f49f Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2022 License: BSD-3-Clause Imports: 13 Imported by: 0

README

httpsniffer

A work-in-progress framework to build HTTP-based sniffers in an easy way. Just register your handlers and it handles everything for you as simple as creating an HTTP Server.

It builds on the battle-hardened gopacket, and it adds support for parsing HTTP requests and responses using net/http.

NOTE: the API is still under heavy development, therefore subject to substantial changes.

Quick Example

func main() {
    device := "eth0"
    port := 80
    sniffer := New(device, port)

    // you can register as many handlers you want
    // httpsniffer will chain the request through them in the order they were registered
    // the output of each handler will the input of the next handler
    sniffer.Register(func(txn *Transaction) (*Transaction, error) {
        fmt.Println(txn.Request)
        fmt.Println(txn.Response)
        return txn, nil
    })

    // starts the sniffing for HTTP request on device eth0 and port 80
    sniffer.Listen()
}

Documentation

Index

Constants

View Source
const (
	DefaultDevice = "en0"
	DefaultPort   = 80
	SnapLen       = 1600
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorHandler

type ErrorHandler func(*Transaction, error)

type HType

type HType int
const (
	Req HType = iota
	Res
	Uknown
)

type Listener

type Listener func(txn *Transaction) (*Transaction, error)

type Map

type Map struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMap

func NewMap() *Map

func (*Map) Add

func (m *Map) Add(key string, req *http.Request)

func (*Map) Delete

func (m *Map) Delete(key string)

func (*Map) Get

func (m *Map) Get(key string) (*http.Request, bool)

type Sniffer

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

func New

func New(device string, port int) *Sniffer

func (*Sniffer) Close

func (s *Sniffer) Close()

func (*Sniffer) Listen

func (s *Sniffer) Listen() error

func (*Sniffer) Register

func (s *Sniffer) Register(lsn Listener)

func (*Sniffer) SetErrorHandler

func (s *Sniffer) SetErrorHandler(eh ErrorHandler)

type Transaction

type Transaction struct {
	Request  *http.Request
	Response *http.Response
}

Jump to

Keyboard shortcuts

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