MyWaf

package module
v0.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 38 Imported by: 0

README

MyWaf

从 Golang 开始学安全开发!

对外开放的 API

1. 实例化 MyWaf,对流入流量过滤

  1. 详细使用方法可见 example

2. 对外暴露分析模块,可以直接调用

  1. 先实例化 MyWaf,然后调用其分析模块:
func Test_Analyze(t *testing.T) {
    request, err := http.NewRequest("GET", "http://localhost:8080/analyze?param1=value1&param2=cat%20/etc/passwd", nil)
    if err != nil {
    log.Fatalf("fail to create request, err is %v", err)
    }
    myWaf := New()
    err = myWaf.Analyze(nil, request)
    if err != nil {
    log.Printf("detect threat! err is %v", err)
    }
}

功能需求

1. 通用主题功能
  1. MyWaf 可以额外写成组件的形式,将 analyze 模块对外提供,这样 IDS 可以直接调用分析模块。
  2. 更换 Cache 组件,使用自己之前编写的 Cache
  3. TODO:IDS 上引入数据库,可以对事件进行相关操作,包括但不限于封锁 IP、加白等,往态势感知平台上靠拢
2. 具体业务更改
  1. CommonWebAttack 增加 URL Decode 和 HTML 实体编码
  2. CVE 模块中对 Path 的处理不够,得考虑路径穿越和大小写绕过等问题
  3. 原先 CVE 模块中判断是否命中是检查所有的请求参数是否完全对应。如果依旧使用全匹配,那么在写规则模板时就要考虑最小原则。
  4. 添加恶意命令检测,包括但不限于反弹 Shell,查看系统敏感文件,通用命令等。

Documentation

Overview

Package MyWaf ----------------------------- @author : EndlessShw @time : 2025/10/15 9:43 @Description : 分析请求模块,包含各个攻击类型的分析 -------------------------------------------

Package MyWaf ----------------------------- @author : EndlessShw @time : 2025/9/19 0:10 @Description : 存放一些上层/全局用到的参数 -------------------------------------------

Package MyWaf ----------------------------- @author : EndlessShw @time : 2025/9/20 16:15 @Description : 常见的错误常量 -------------------------------------------

Package MyWaf ----------------------------- @author : EndlessShw @time : 2025/11/1 17:07 @Description : 对接 Falcosidekick 的结构体以及方法 -------------------------------------------

Package MyWaf ----------------------------- @author : EndlessShw @time : 2025/9/18 14:50 @Description : 定义了“用于处理拦截”的 handler -------------------------------------------

Package MyWaf ----------------------------- @author : EndlessShw @time : 2025/9/19 14:51 @Description : 主类,主要负责实例创建和初始化、流入流量的预处理等 -------------------------------------------

Package MyWaf ----------------------------- @author : EndlessShw @time : 2025/9/22 23:07 @Description : 上层常用工具类 -------------------------------------------

Package MyWaf ----------------------------- @author : EndlessShw @time : 2025/9/19 0:23 @Description : 全局变量 -------------------------------------------

Package MyWaf ----------------------------- @author : EndlessShw @time : 2025/9/23 10:57 @Description : 将 yaml 文件中的 Custom 规则反序列化成结构体 -------------------------------------------

Index

Constants

View Source
const (
	XMyWafMsg = "X-My-Waf-Msg"

	// DefaultRespStatus 表示 RespHTMLResponse 默认适用的 HTTPStatus。
	DefaultRespStatus = http.StatusForbidden
	// DefaultRespHTMLResponse 中 ID、message 和 threat 根据分析时的结果填充
	DefaultRespHTMLResponse = `` /* 1198-byte string literal not displayed */

)

Variables

This section is empty.

Functions

This section is empty.

Types

type MyWaf

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

func New

func New(opts ...option.Options) *MyWaf

func (*MyWaf) Analyze

func (myWaf *MyWaf) Analyze(rw http.ResponseWriter, req *http.Request) error

func (*MyWaf) Handler

func (myWaf *MyWaf) Handler(normalHandler http.Handler) http.Handler

Handler 继承并返回 http.HandlerFunc,其中添加分析的功能 传入的 normalHandler 为正常业务的 Handler

func (*MyWaf) SetHandler

func (myWaf *MyWaf) SetHandler(handler http.Handler)

SetHandler 设置拒绝 Handler

Directories

Path Synopsis
Package main ----------------------------- @author : EndlessShw @time : 2025/9/14 14:43 @Description : 使用案例 -------------------------------------------
Package main ----------------------------- @author : EndlessShw @time : 2025/9/14 14:43 @Description : 使用案例 -------------------------------------------
internal
dsl
Package dsl ----------------------------- @author : EndlessShw @time : 2025/9/17 17:46 @Description : -------------------------------------------
Package dsl ----------------------------- @author : EndlessShw @time : 2025/9/17 17:46 @Description : -------------------------------------------
model
Package model ----------------------------- @author : EndlessShw @time : 2025/10/5 13:51 @Description : CVE 的对应实体类 -------------------------------------------
Package model ----------------------------- @author : EndlessShw @time : 2025/10/5 13:51 @Description : CVE 的对应实体类 -------------------------------------------
Package option ----------------------------- @author : EndlessShw @time : 2025/9/23 21:37 @Description : 存放 option 中的一些默认常量 -------------------------------------------
Package option ----------------------------- @author : EndlessShw @time : 2025/9/23 21:37 @Description : 存放 option 中的一些默认常量 -------------------------------------------
Package request ----------------------------- @author : EndlessShw @time : 2025/9/19 10:34 @Description : Rules.Element 指定的部分,其中 Method 类型过多,因此单独分开 -------------------------------------------
Package request ----------------------------- @author : EndlessShw @time : 2025/9/19 10:34 @Description : Rules.Element 指定的部分,其中 Method 类型过多,因此单独分开 -------------------------------------------
Package threat ----------------------------- @author : EndlessShw @time : 2025/9/15 22:02 @Description : Threat 中涉及的常量 -------------------------------------------
Package threat ----------------------------- @author : EndlessShw @time : 2025/9/15 22:02 @Description : Threat 中涉及的常量 -------------------------------------------

Jump to

Keyboard shortcuts

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