ftp

package
v0.16.10 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: BSD-3-Clause, GPL-3.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Decoder = &decoder.StreamDecoder{
	Type:        types.Type_NC_FTP,
	Name:        "FTP",
	Description: "File Transfer Protocol - control and data channels",
	PostInit: func(sd *decoder.StreamDecoder) error {
		var err error
		ftpLog, _, err = logging.InitZapLogger(
			decoderconfig.Instance.Out,
			"ftp",
			decoderconfig.Instance.Debug,
		)
		if err != nil {
			return err
		}

		initConnectionTracker()
		return nil
	},

	Specificity: core.SpecificityWeak,

	CanDecode: func(client, server []byte) bool {
		c, s := strings.ToUpper(string(client)), strings.ToUpper(string(server))
		if !strings.HasPrefix(s, "220 ") && !strings.HasPrefix(s, "220-") {
			for _, command := range []string{"CWD ", "CDUP\r\n", "PWD\r\n", "AUTH TLS\r\n"} {
				if strings.HasPrefix(c, command) {
					return true
				}
			}
			return false
		}
		for _, command := range []string{"EHLO ", "HELO ", "MAIL FROM:", "AUTH PLAIN", "AUTH LOGIN", "AUTH CRAM-MD5", "AUTH XOAUTH2"} {
			if strings.HasPrefix(c, command) || strings.Contains(c, "\r\n"+command) {
				return false
			}
		}
		line, _, _ := strings.Cut(s, "\r\n")
		if strings.Contains(line, "FTP") {
			return true
		}
		for _, command := range []string{"USER ", "PASS ", "RETR ", "STOR ", "PASV\r\n", "EPSV\r\n", "CWD ", "CDUP\r\n", "PWD\r\n", "QUIT\r\n", "AUTH TLS\r\n", "TYPE "} {
			if strings.HasPrefix(c, command) || strings.Contains(c, "\r\n"+command) {
				return true
			}
		}
		return false
	},
	DeInit: func(sd *decoder.StreamDecoder) error {
		if err := FinalizeDataConnections(); err != nil {
			return err
		}
		return ftpLog.Sync()
	},
	Factory: &ftpReader{},
	Typ:     core.TCP,
}

Decoder for FTP protocol analysis

Functions

func FinalizeDataConnections

func FinalizeDataConnections() error

FinalizeDataConnections runs after TCP readers drain and before File closes. Ambiguous windows are refused rather than choosing the first worker to arrive.

func ObserveDataConversation

func ObserveDataConversation(c *core.ConversationInfo)

ObserveDataConversation owns bounded copies until all control readers have finished. Capture time, never goroutine arrival order, determines association.

Types

type DataAssociation

type DataAssociation struct {
	ControlKey         string `json:"controlKey"`
	DataKey            string `json:"dataKey"`
	StartNs            int64  `json:"startNs,string"`
	EndNs              int64  `json:"endNs,string"`
	SHA256             string `json:"sha256"`
	ControlCommunityID string `json:"controlCommunityId"`
	DataCommunityID    string `json:"dataCommunityId"`
	Command            string `json:"command"`
	Filename           string `json:"filename"`
	CompleteReply      bool   `json:"completeReply"`
}

type DataHealth

type DataHealth struct {
	Version              int               `json:"version"`
	Status               string            `json:"status"`
	PendingBytes         int               `json:"peakRetainedBytes"`
	Candidates           int               `json:"candidates"`
	Rejected             int               `json:"rejectedByBudget"`
	Ambiguous            int               `json:"ambiguous"`
	Unmatched            int               `json:"unmatched"`
	UnmatchedTransfers   int               `json:"unmatchedTransfers"`
	UnsupportedEndpoints int               `json:"unsupportedEndpoints"`
	Failed               int               `json:"extractionErrors"`
	Associations         []DataAssociation `json:"associations"`
}

type FTPFileExtractor

type FTPFileExtractor struct{}

FTPFileExtractor implements file extraction for FTP DATA channel transfers

func (*FTPFileExtractor) DescribeFile

func (f *FTPFileExtractor) DescribeFile(handle *file.FileHandle) string

DescribeFile returns a human-readable description of the FTP file transfer

func (*FTPFileExtractor) ExtractFile

func (f *FTPFileExtractor) ExtractFile(conv *core.ConversationInfo, data []byte, metadata file.FileMetadata) error

ExtractFile performs FTP file extraction

func (*FTPFileExtractor) GetFileHandle

func (f *FTPFileExtractor) GetFileHandle(conv *core.ConversationInfo, isOrigin bool, depth int) string

GetFileHandle generates a unique identifier for an FTP file transfer

func (*FTPFileExtractor) ProtocolName

func (f *FTPFileExtractor) ProtocolName() string

ProtocolName returns the protocol name

Jump to

Keyboard shortcuts

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