listener

package
v0.4.123 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: AGPL-3.0 Imports: 6 Imported by: 1 module, 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

Overview

Package listener implements TCP callback receivers (回连接收器) for red team operations: catch reverse-shell callbacks and OOB connections while the agent does other work, and record every session as evidence.

设计边界(刻意不做):

  • 不做交互式 shell 管理器(那是 C2 框架的事,Sliver/Mythic 是集成对象不是 竞争对象)。监听器负责「接住连接 + 留证据」;交互式操作由 agent 用 Bash 里的 nc/socat 自行完成。
  • 捕获有上限(每会话 64KB 预览),防止目标把监听器当数据泵灌爆内存。
  • 端口白名单默认 1024-65535(绑低端口需要 root,服务用户没有;真要 80/443 走 hostd 或端口转发)。

并发模型:每个 listener 一个 accept goroutine + 每连接一个读 goroutine; Manager.mu 保护 listeners map。Stop 优雅关闭(关 accept、关全部连接)。

Index

Constants

View Source
const (
	// MaxCapturePerSession 是单个会话捕获的字节上限(防灌爆)。
	MaxCapturePerSession = 64 * 1024
	// MaxSessionsPerListener 是每个监听器保留的会话上限。监听器按设计对公网开放,
	// 不限量的话一个扫描器就能把会话列表和 goroutine 堆到内存耗尽。
	MaxSessionsPerListener = 2000
	// MinPort/MaxPort 是允许绑定的端口范围。
	MinPort = 1024
	MaxPort = 65535
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Listener

type Listener struct {
	Name      string     `json:"name"`
	Port      int        `json:"port"`
	StartedAt time.Time  `json:"started_at"`
	Sessions  []*Session `json:"sessions"`
	// contains filtered or unexported fields
}

Listener 是一个运行中的回连接收器。

func (*Listener) Snapshot

func (l *Listener) Snapshot() []Session

Snapshot 返回会话列表的拷贝(按连接时间倒序,最新的在前)。

type Manager

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

Manager 管理全部监听器(进程级单例,由 server 持有)。

func NewManager

func NewManager() *Manager

NewManager 构造。

func (*Manager) Get

func (m *Manager) Get(name string) ([]Session, bool)

Get 返回一个监听器的会话快照。

func (*Manager) List

func (m *Manager) List() []*Listener

List 返回全部运行中的监听器(按名字排序)。

func (*Manager) Start

func (m *Manager) Start(name string, port int) (*Listener, error)

Start 起一个监听器。端口必须在 MinPort-MaxPort;同名已存在则报错。

func (*Manager) Stop

func (m *Manager) Stop(name string) ([]Session, error)

Stop 停一个监听器并返回它的最终会话快照。

type Session

type Session struct {
	ID          string    `json:"id"`
	Remote      string    `json:"remote"`
	ConnectedAt time.Time `json:"connected_at"`
	LastActive  time.Time `json:"last_active"`
	BytesIn     int64     `json:"bytes_in"`
	// Preview 是捕获的前 MaxCapturePerSession 字节(UTF-8 容错解码)。
	// 反弹 shell 的初始输出、OOB 请求行、banner 都在这里。
	Preview string `json:"preview"`
	Open    bool   `json:"open"`
	// contains filtered or unexported fields
}

Session 是一次回连的记录。

Jump to

Keyboard shortcuts

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