mirror of
https://github.com/40t/go-sniffer.git
synced 2025-08-21 22:31:00 +08:00
A: go.mod
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const InternalCmdPrefix = "--"
|
const InternalCmdPrefix = "--"
|
||||||
@@ -139,7 +139,3 @@ func (cm *Cmd) parsePlugCmd() {
|
|||||||
plugParams := os.Args[3:]
|
plugParams := os.Args[3:]
|
||||||
cm.plugHandle.SetOption(plugName, plugParams)
|
cm.plugHandle.SetOption(plugName, plugParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -2,13 +2,14 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/google/gopacket"
|
"github.com/google/gopacket"
|
||||||
"github.com/google/gopacket/layers"
|
"github.com/google/gopacket/layers"
|
||||||
"github.com/google/gopacket/pcap"
|
"github.com/google/gopacket/pcap"
|
||||||
"github.com/google/gopacket/tcpassembly"
|
"github.com/google/gopacket/tcpassembly"
|
||||||
"github.com/google/gopacket/tcpassembly/tcpreader"
|
"github.com/google/gopacket/tcpassembly/tcpreader"
|
||||||
"log"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Dispatch struct {
|
type Dispatch struct {
|
||||||
|
18
core/plug.go
18
core/plug.go
@@ -1,21 +1,21 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"fmt"
|
||||||
"plugin"
|
|
||||||
"github.com/google/gopacket"
|
|
||||||
"io"
|
"io"
|
||||||
mysql "github.com/40t/go-sniffer/plugSrc/mysql/build"
|
"io/ioutil"
|
||||||
redis "github.com/40t/go-sniffer/plugSrc/redis/build"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"plugin"
|
||||||
|
|
||||||
hp "github.com/40t/go-sniffer/plugSrc/http/build"
|
hp "github.com/40t/go-sniffer/plugSrc/http/build"
|
||||||
mongodb "github.com/40t/go-sniffer/plugSrc/mongodb/build"
|
mongodb "github.com/40t/go-sniffer/plugSrc/mongodb/build"
|
||||||
"path/filepath"
|
mysql "github.com/40t/go-sniffer/plugSrc/mysql/build"
|
||||||
"fmt"
|
redis "github.com/40t/go-sniffer/plugSrc/redis/build"
|
||||||
"path"
|
"github.com/google/gopacket"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Plug struct {
|
type Plug struct {
|
||||||
|
|
||||||
dir string
|
dir string
|
||||||
ResolveStream func(net gopacket.Flow, transport gopacket.Flow, r io.Reader)
|
ResolveStream func(net gopacket.Flow, transport gopacket.Flow, r io.Reader)
|
||||||
BPF string
|
BPF string
|
||||||
|
5
go.mod
Normal file
5
go.mod
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module github.com/40t/go-sniffer
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
||||||
|
require github.com/google/gopacket v1.1.17
|
9
go.sum
Normal file
9
go.sum
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
github.com/google/gopacket v1.1.17 h1:rMrlX2ZY2UbvT+sdz3+6J+pp2z+msCq9MxTU6ymxbBY=
|
||||||
|
github.com/google/gopacket v1.1.17/go.mod h1:UdDNZ1OO62aGYVnPhxT1U6aI7ukYtA/kB8vaU0diBUM=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67 h1:1Fzlr8kkDLQwqMP8GxrhptBLqZG/EDpiATneiZHY998=
|
||||||
|
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
@@ -1,14 +1,15 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/gopacket"
|
"bufio"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"bufio"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/google/gopacket"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -66,7 +67,7 @@ func (m *H) ResolveStream(net, transport gopacket.Flow, buf io.Reader) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *H) BPFFilter() string {
|
func (m *H) BPFFilter() string {
|
||||||
return "tcp and port "+strconv.Itoa(m.port);
|
return "tcp and port " + strconv.Itoa(m.port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *H) Version() string {
|
func (m *H) Version() string {
|
||||||
@@ -90,7 +91,7 @@ func (m *H) SetFlag(flg []string) {
|
|||||||
|
|
||||||
switch key {
|
switch key {
|
||||||
case CmdPort:
|
case CmdPort:
|
||||||
port, err := strconv.Atoi(val);
|
port, err := strconv.Atoi(val)
|
||||||
m.port = port
|
m.port = port
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("ERR : port")
|
panic("ERR : port")
|
||||||
|
@@ -4,9 +4,10 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/40t/go-sniffer/plugSrc/mongodb/build/internal/json"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/40t/go-sniffer/plugSrc/mongodb/build/internal/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UnmarshalJSON unmarshals a JSON value that may hold non-standard
|
// UnmarshalJSON unmarshals a JSON value that may hold non-standard
|
||||||
|
@@ -4,9 +4,10 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/google/gopacket"
|
|
||||||
"io"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/google/gopacket"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -26,7 +27,6 @@ type stream struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type packet struct {
|
type packet struct {
|
||||||
|
|
||||||
isClientFlow bool // client->server
|
isClientFlow bool // client->server
|
||||||
|
|
||||||
messageLength int
|
messageLength int
|
||||||
@@ -64,7 +64,7 @@ func (m *Mongodb) SetFlag(flg []string) {
|
|||||||
|
|
||||||
switch key {
|
switch key {
|
||||||
case CmdPort:
|
case CmdPort:
|
||||||
p, err := strconv.Atoi(val);
|
p, err := strconv.Atoi(val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("ERR : port")
|
panic("ERR : port")
|
||||||
}
|
}
|
||||||
@@ -80,7 +80,7 @@ func (m *Mongodb) SetFlag(flg []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mongodb) BPFFilter() string {
|
func (m *Mongodb) BPFFilter() string {
|
||||||
return "tcp and port "+strconv.Itoa(m.port);
|
return "tcp and port " + strconv.Itoa(m.port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mongodb) Version() string {
|
func (m *Mongodb) Version() string {
|
||||||
|
@@ -4,8 +4,9 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"io"
|
"io"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/40t/go-sniffer/plugSrc/mongodb/build/bson"
|
"github.com/40t/go-sniffer/plugSrc/mongodb/build/bson"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ func ReadString(r io.Reader) string {
|
|||||||
return string(result)
|
return string(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadBson2Json(r io.Reader) (string) {
|
func ReadBson2Json(r io.Reader) string {
|
||||||
|
|
||||||
// read len
|
// read len
|
||||||
docLen := ReadInt32(r)
|
docLen := ReadInt32(r)
|
||||||
@@ -83,4 +84,3 @@ func ReadBson2Json(r io.Reader) (string) {
|
|||||||
}
|
}
|
||||||
return string(jsonStr)
|
return string(jsonStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,18 +1,19 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/gopacket"
|
|
||||||
"io"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"fmt"
|
|
||||||
"encoding/binary"
|
"github.com/google/gopacket"
|
||||||
"strings"
|
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -41,6 +42,7 @@ type packet struct {
|
|||||||
|
|
||||||
var mysql *Mysql
|
var mysql *Mysql
|
||||||
var once sync.Once
|
var once sync.Once
|
||||||
|
|
||||||
func NewInstance() *Mysql {
|
func NewInstance() *Mysql {
|
||||||
|
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
@@ -86,7 +88,7 @@ func (m *Mysql) ResolveStream(net, transport gopacket.Flow, buf io.Reader) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mysql) BPFFilter() string {
|
func (m *Mysql) BPFFilter() string {
|
||||||
return "tcp and port "+strconv.Itoa(m.port);
|
return "tcp and port " + strconv.Itoa(m.port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mysql) Version() string {
|
func (m *Mysql) Version() string {
|
||||||
@@ -110,7 +112,7 @@ func (m *Mysql) SetFlag(flg []string) {
|
|||||||
|
|
||||||
switch key {
|
switch key {
|
||||||
case CmdPort:
|
case CmdPort:
|
||||||
port, err := strconv.Atoi(val);
|
port, err := strconv.Atoi(val)
|
||||||
m.port = port
|
m.port = port
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("ERR : port")
|
panic("ERR : port")
|
||||||
@@ -353,4 +355,3 @@ func (stm *stream) resolveClientPacket(payload []byte, seq int) {
|
|||||||
|
|
||||||
fmt.Println(GetNowStr(true) + msg)
|
fmt.Println(GetNowStr(true) + msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,10 +3,10 @@ package build
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
"errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Stmt struct {
|
type Stmt struct {
|
||||||
|
@@ -1,12 +1,13 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/gopacket"
|
|
||||||
"io"
|
|
||||||
"strings"
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/google/gopacket"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Redis struct {
|
type Redis struct {
|
||||||
@@ -74,9 +75,7 @@ func (red Redis) ResolveStream(net, transport gopacket.Flow, r io.Reader) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// SetOption
|
||||||
SetOption
|
|
||||||
*/
|
|
||||||
func (red *Redis) SetFlag(flg []string) {
|
func (red *Redis) SetFlag(flg []string) {
|
||||||
c := len(flg)
|
c := len(flg)
|
||||||
if c == 0 {
|
if c == 0 {
|
||||||
@@ -91,7 +90,7 @@ func (red *Redis) SetFlag(flg []string) {
|
|||||||
|
|
||||||
switch key {
|
switch key {
|
||||||
case CmdPort:
|
case CmdPort:
|
||||||
port, err := strconv.Atoi(val);
|
port, err := strconv.Atoi(val)
|
||||||
redis.port = port
|
redis.port = port
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("ERR : Port error")
|
panic("ERR : Port error")
|
||||||
@@ -106,17 +105,12 @@ func (red *Redis) SetFlag(flg []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// BPFFilter
|
||||||
BPFFilter
|
|
||||||
*/
|
|
||||||
func (red *Redis) BPFFilter() string {
|
func (red *Redis) BPFFilter() string {
|
||||||
return "tcp and port " + strconv.Itoa(redis.port)
|
return "tcp and port " + strconv.Itoa(redis.port)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Version
|
||||||
Version
|
|
||||||
*/
|
|
||||||
func (red *Redis) Version() string {
|
func (red *Redis) Version() string {
|
||||||
return red.version
|
return red.version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user