mirror of
https://github.com/40t/go-sniffer.git
synced 2025-08-08 21:19:31 +08:00
Init
This commit is contained in:
106
plugSrc/http/build/entry.go
Normal file
106
plugSrc/http/build/entry.go
Normal file
@@ -0,0 +1,106 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"github.com/google/gopacket"
|
||||
"io"
|
||||
"log"
|
||||
"strconv"
|
||||
"fmt"
|
||||
"os"
|
||||
"bufio"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
Port = 80
|
||||
Version = "0.1"
|
||||
)
|
||||
|
||||
const (
|
||||
CmdPort = "-p"
|
||||
)
|
||||
|
||||
type H struct {
|
||||
port int//端口
|
||||
version string//插件版本
|
||||
}
|
||||
|
||||
var hp *H
|
||||
|
||||
func NewInstance() *H {
|
||||
if hp == nil {
|
||||
hp = &H{
|
||||
port :Port,
|
||||
version:Version,
|
||||
}
|
||||
}
|
||||
return hp
|
||||
}
|
||||
|
||||
func (m *H) ResolveStream(net, transport gopacket.Flow, buf io.Reader) {
|
||||
|
||||
bio := bufio.NewReader(buf)
|
||||
for {
|
||||
req, err := http.ReadRequest(bio)
|
||||
|
||||
if err == io.EOF {
|
||||
return
|
||||
} else if err != nil {
|
||||
continue
|
||||
} else {
|
||||
|
||||
var msg = "["
|
||||
msg += req.Method
|
||||
msg += "] ["
|
||||
msg += req.Host + req.URL.String()
|
||||
msg += "] ["
|
||||
req.ParseForm()
|
||||
msg += req.Form.Encode()
|
||||
msg += "]"
|
||||
|
||||
log.Println(msg)
|
||||
|
||||
req.Body.Close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *H) BPFFilter() string {
|
||||
return "tcp and port "+strconv.Itoa(m.port);
|
||||
}
|
||||
|
||||
func (m *H) Version() string {
|
||||
return Version
|
||||
}
|
||||
|
||||
func (m *H) SetFlag(flg []string) {
|
||||
|
||||
c := len(flg)
|
||||
|
||||
if c == 0 {
|
||||
return
|
||||
}
|
||||
if c >> 1 == 0 {
|
||||
fmt.Println("http参数数量不正确!")
|
||||
os.Exit(1)
|
||||
}
|
||||
for i:=0;i<c;i=i+2 {
|
||||
key := flg[i]
|
||||
val := flg[i+1]
|
||||
|
||||
switch key {
|
||||
case CmdPort:
|
||||
port, err := strconv.Atoi(val);
|
||||
m.port = port
|
||||
if err != nil {
|
||||
panic("端口数不正确")
|
||||
}
|
||||
if port < 0 || port > 65535 {
|
||||
panic("参数不正确: 端口范围(0-65535)")
|
||||
}
|
||||
break
|
||||
default:
|
||||
panic("参数不正确")
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user