Help us shape the future of Go! Take the 2026 Go Developer Survey

protocol

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package shell WebShell 流量协议层。

把「在目标 shell 上执行一条系统命令」这一逻辑请求按协议编译为 HTTP 报文规格 (方法/URL/Header/Body),并把响应体还原为命令输出原始字节。协议与模板配套:

plain    : 历史明文行为——密码参数(passParam,缺省 pass)+cmdParam 双参数,
           GET query 或 POST form
behinder : 冰蝎3式——AES-128-CBC(key=iv=md5(pass) 前 16 位),POST 二进制体,
           明文为 eval|<php 代码>;兼容投放给原版冰蝎3 PHP 马(解密后按 | 切分 eval 第二段)
godzilla : 哥斯拉式(PHP_XOR_BASE64 变形)——key=md5(pass) 前 16 位,
           请求为 base64(xor(php 代码, key)) 二进制体;响应为
           base64(xor( md5(key)[16:] + base64(输出) + md5(key)[:16], key ))

加密协议仅对 PHP 型 shell 提供(客户端执行体与 webshellgen 内置模板成对交付); 其他语言维持 plain。参数通道(param channel)只在 plain 协议下生效, 支持 body/query/cookie/header 四种 pass+cmdParam 投放位置。

Index

Constants

View Source
const DefaultPassParam = "pass"

DefaultPassParam plain 协议密码/token 参数名缺省值(与 cmd 的缺省 "cmd" 对称)。 历史马普遍约定 pass=密码;外部已有马(如 ?k=token&c=id 形态)按连接配置覆盖。

View Source
const MaxURLQueryChars = 7000

MaxURLQueryChars GET 参数串长度上限。Tomcat 等中间件默认 maxHttpHeaderSize 8KB, 超限直接 400(印尼演练实测:20KB 命令即触发)。超过阈值的大命令自动降级 POST form 投递——request.getParameter 系一句话马对 query/form 一视同仁 (zzsg/zzaceh 家族实测兼容),仅 query-only 的极简壳不受益,而它们对大命令 本来也无解,降级只会更好不会更坏。

Variables

This section is empty.

Functions

func ApplyResponseFilter

func ApplyResponseFilter(out, filter string) string

ApplyResponseFilter 输出后处理:filter 为空原样返回;否则按正则取第一处 匹配(有捕获组取组 1,无组取整段匹配);正则非法或无命中时返回原输出/空串。

func DeriveKey

func DeriveKey(password string) []byte

DeriveKey 由连接密码派生协议密钥:md5(pass) 十六进制串的前 16 个 ASCII 字节 (16 字节 = AES-128,同时充当 CBC IV / XOR 轮转 key,与冰蝎/哥斯拉同派生方式)。

func SupportsProtocol

func SupportsProtocol(p Protocol, shellType string) bool

SupportsProtocol 该 shell 语言是否有配套的协议执行体/模板。 加密协议当前仅内置 PHP 实现(behinder 兼容冰蝎3 PHP 马;godzilla 为自研哥斯拉式); plain 全语言支持。

func Unwrap

func Unwrap(p Protocol, password string, body []byte) []byte

Unwrap 把响应体按协议还原为命令输出的原始字节(未做字符集转换)。 plain 原样返回;behinder 原样返回(模板直接回显输出);godzilla 走 base64 → xor → 去前后 16 字节 → base64 四步还原。还原失败时回退原始体 (配合 response_filter 仍有机会取到输出)。

Types

type ParamChannel

type ParamChannel string

ParamChannel plain 协议下参数投放位置。

const (
	ParamBody   ParamChannel = "body"   // POST form(默认)
	ParamQuery  ParamChannel = "query"  // URL 查询串
	ParamCookie ParamChannel = "cookie" // Cookie 头
	ParamHeader ParamChannel = "header" // 自定义 Header(X- 前缀,pass 为值)
)

func NormalizeParamChannel

func NormalizeParamChannel(s string) (ParamChannel, error)

NormalizeParamChannel 归一化参数通道;空值默认 body,未知值报错。

type Protocol

type Protocol string

Protocol 流量协议标识。

const (
	Plain    Protocol = "plain"
	Behinder Protocol = "behinder"
	Godzilla Protocol = "godzilla"
)

func NormalizeProtocol

func NormalizeProtocol(s string) (Protocol, error)

NormalizeProtocol 归一化协议标识;空值默认 plain,未知值报错。

type Request

type Request struct {
	Method string
	URL    string
	Header http.Header
	Body   []byte // nil/空 = 无请求体(GET 语义)
}

Request 编译出的 HTTP 报文规格。

func Build

func Build(p Protocol, shellType, method, baseURL, password, cmdParam, command, channel, passParam string) (*Request, error)

Build 按协议把「执行 command」编译为 HTTP 报文规格。 plain 下 method 为 GET 时参数走 URL(或显式 channel),POST 时走 body; passParam 为密码/token 的参数名(空缺省 "pass"); 加密协议一律 POST 二进制体(method 参数仅 plain 消费)。

func (*Request) HTTPRequest

func (r *Request) HTTPRequest() (*http.Request, error)

HTTPRequest 把报文规格落地为 *http.Request(调用方补上下文)。

Jump to

Keyboard shortcuts

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